GIF89a php
Current File : /home/hencockfreshchic/public_html/admin.cpanel/js/saveDeal.js
function saveDeal(ops){
	var pname=$("#pname").val();
	var psr1=$("#psr1").val();
	var sprice=$("#sprice").val();
	var rprice=$("#rprice").val();
	var sdate=$("#sdate").val();
	var edate=$("#edate").val();

	if(pname=="")
	{
		alert("Invalid product name");
      $("#pname").focus();
      return false;
	}

	if(psr1=="")
	{
		alert("Invalid product serial");
      $("#psr1").focus();
      return false;
	}

	var regexp;
   regexp = /^[-+]?\d*\.?\d*$/;
   if (!regexp.test(sprice))
   {
      alert("Invalid sale price");
      $("#sprice").focus();
      return false;
   }
   if (sprice == "")
   {
      alert("Enter sale price");
      $("#sprice").focus();
      return false;
   }
   if (sprice.length < 1)
   {
      alert("Enter sale price");
      $("#sprice").focus();
      return false;
   }
   if (sprice.length > 8)
   {
      alert("Enter sale price");
      $("#sprice").focus();
      return false;
   }

   regexp = /^[-+]?\d*\.?\d*$/;
   if (!regexp.test(rprice))
   {
      alert("Invalid real price");
      $("#rprice").focus();
      return false;
   }
   if (rprice == "")
   {
      alert("Enter real price");
      $("#rprice").focus();
      return false;
   }
   if (rprice.length < 1)
   {
      alert("Enter real price");
      $("#rprice").focus();
      return false;
   }
   if (rprice.length > 8)
   {
      alert("Enter real price");
      $("#rprice").focus();
      return false;
   }

   if(sdate=="")
	{
		alert("Invalid start date");
      $("#sdate").focus();
      return false;
	}

	if(edate=="")
	{
		alert("Invalid end date");
      $("#edate").focus();
      return false;
	}

// check sale price is equal to real price
if(sprice==rprice)
{
	alert("Sale price and real price have same price | So deal can't possible. \n For Save deal you need to adjust sale price less than real price ");
      $("#sprice").focus();
      return false;
}

	if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        } else {          
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
  xmlhttp.onreadystatechange=function() 
   {
    if (this.readyState==4 && this.status==200) 
	{
      if(this.responseText==1)
      {		
      	if(ops=="1"){
      		alert("Deal has been created successfully");
      		window.location.href = ("hot_deals.php");
      	}
      	else
      	{
      		alert("Deal has been updated successfully");
      		window.location.href = ("hot_deals.php");
      	}
      }
      else if(this.responseText==2)
      {
      		alert("Deal already exist | First remove the first one or you can update the exist deal");
      		window.location.href = ("hot_deals.php");
      }
      else if(this.responseText==0)
      {
      		if(ops=="1"){
      		alert("Sorry !! Unable to save new hot deal | Please contact to developer"); 
      		}
      		else{
      			alert("Sorry !! Unable to update new hot deal | Please contact to developer"); 
      		}     		
      }
	}
  };
 if(ops=="1")
 {
  xmlhttp.open("GET","saveDeal.php?pname="+btoa(pname)+"&psr1="+psr1+"&sprice="+sprice+"&rprice="+rprice+"&sdate="+sdate+"&edate="+edate,true);
  xmlhttp.send();
}
else
{		
	var sr=$("#psr2").val();
	
	xmlhttp.open("GET","updateDeal.php?pname="+btoa(pname)+"&psr1="+psr1+"&sprice="+sprice+"&rprice="+rprice+"&sdate="+sdate+"&edate="+edate+"&sr="+sr,true);
  xmlhttp.send();
}

}