<!-- This file Contains all the function that are related to user section-->

	 function ValidateDeletePayment()
	{
	    var ch=0;
	    len = document.frmlist.elements.length;
		var i=0;
		for( i=0 ; i<len ; i++) 
		{
		
			if (document.frmlist.elements[i].name=='chk_id[]') 
				{
	
					if (document.frmlist.elements[i].checked==1)
						{
					
							ch = 1;
						}
				}
		}	
	
		if (ch == 1)
		{
			if(confirm('Confirm Delete'))
			{
				//document.frmlist.action="submit.php?mode=deletecrewcategory";
				//document.frmlist.submit();
				deletepayment();
			}
			else 
				return false;

		}
		else
		{
			alert("Please Select Order(s) to delete.");	
			return false;
		}
	}

 
function deletepayment()
 {
			var a_arry=new Array(); 
			 var checkLen=document.getElementsByName('chk_id[]').length;
			//alert(checkLen);
			var y=0;
		   for(i=0;i<checkLen;i++)
			 {	//alert(i); 
				if(document.all.frmlist.elements[i].checked==true) 
				 { 	    
								   var arry=document.all.frmlist.elements[i].value;
								  // alert(arry);
								   var x=arry.length;
								   //alert(x);
								   a_arry[y]=arry;
									   y++;
				  }
				
			 }
			 var arrycount=a_arry.length;
			 //alert(arrycount);
  //var url='display_company.php?DELETE='+DELETE+'&arrycount='+arrycount+'&a_arry='+a_arry;  
  			var xmlhttp1 = new cl_xmlHttpObject();				
			xmlhttp1.open("POST","delete_payment.php?arrycount="+arrycount+"&a_arry="+a_arry,true);
				xmlhttp1.onreadystatechange = function()
			{
				 if (xmlhttp1.readyState <4) {
	 
						 document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
						  //display_info(xmlhttp1.responseText);
	  
					  }
					  else if(xmlhttp1.readyState ==4)
							{
								if(xmlhttp1.status==200)
								{
									get_message(xmlhttp1.responseText)
									GetPaymentInfo();
									//display_info(xmlhttp1.responseText);
								}
								else
								{
								display_info("An Error Occured:"+ xmlhttp1.statusText);
								}
							}
			};
    	   xmlhttp1.send(null);  

 }

	
	function GetPaymentInfo(page,oid,pid)
	{
		var oid= oid;
		var page= page;
		var pid= pid;
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","order_list.php?page="+page+"&oid="+oid+"&pid="+pid,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	
	
	function MakePaymentstep1(oid,peid,val)
	{
		var oid= oid;
		var peid=peid;
		var val=val;
		//alert(val);
		//var page= page;
		//var pid= pid;
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","paymentstep1.php?oid="+oid+"&peid="+peid+"&val="+val,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	
	function MakePaymentstep2(oid,peid,val)
	{
		var oid= oid;
		var peid=peid;
		var val=val
		//alert(peid);
		var billingfirstname = document.getElementById("txtbillingfirstname").value;
		if(billingfirstname ==""){ alert("Enter Billing Firstname."); return false;}
		var billinglastname = document.getElementById("txtbillinglastname").value;
		if(billinglastname ==""){ alert("Enter Billing Lastname."); return false;}
		var billingcompany = document.getElementById("txtbillingcompany").value;
		if(billingcompany ==""){ alert("Enter Billing Company Name."); return false;}
		var billingaddress = document.getElementById("txtbillingaddress").value;
		if(billingaddress ==""){ alert("Enter Billing Address."); return false;}
		var billingCountry = document.getElementById("billingCountry").value;		
		var billingState = document.getElementById("billingState").value;
		var billingcity = document.getElementById("billingcity").value;
		if(billingcity ==""){ alert("Enter Billing City."); return false;}
		var billingzipcode = document.getElementById("txtbillingzipcode").value;
		if(billingzipcode ==""){ alert("Enter Billing Zipcode."); return false;}
		var billingphone = document.getElementById("txtbillingphone").value;
		if(billingphone ==""){ alert("Enter Billing Phone No."); return false;}
		var billingcellular = document.getElementById("txtbillingcellular").value;
		if(billingcellular ==""){ alert("Enter Billing Cellular No."); return false;}
		var billingemail = document.getElementById("txtbillingemail").value;
		if(billingemail ==""){alert("Enter Billing Email Address"); return false;}else{ if(!emailCheck1(billingemail))return false;}
		
		var shippingfirstname = document.getElementById("txtshippingfirstname").value;
		var shippinglastname = document.getElementById("txtshippinglastname").value;
		var shippingcompany = document.getElementById("txtshippingcompany").value;
		var shippingaddress = document.getElementById("txtshippingaddress").value;
		var shippingCountry = document.getElementById("shippingCountry").value;
		var shippingState = document.getElementById("shippingState").value;
		var shippingcity = document.getElementById("shippingcity").value;
		if(shippingcity ==""){ alert("Enter Shipping City."); return false;}
		var shippingzipcode = document.getElementById("txtshippingzipcode").value;
		var shippingphone = document.getElementById("txtshippingphone").value;
		var shippingcellular = document.getElementById("txtshippingcellular").value;
		var shippingemail = document.getElementById("txtshippingemail").value;
		if(shippingemail ==""){alert("Enter Shipping Email Address"); return false;}else{ if(!emailCheck1(shippingemail))return false;}
		
		var desc = document.getElementById("desc").value;
		
	    //alert("paymentstep2.php?oid="+oid+"&billingfirstname="+billingfirstname+"&billinglastname="+billinglastname+"&billingcompany="+billingcompany+"&billingaddress="+billingaddress+"&billingCountry="+billingCountry+"&billingState="+billingState+"&billingcity="+billingcity+"&billingzipcode="+billingzipcode+"&billingphone="+billingphone+"&billingcellular="+billingcellular+"&billingemail="+billingemail+"&shippingfirstname="+shippingfirstname+"&shippinglastname="+shippinglastname+"&shippingcompany="+shippingcompany+"&shippingaddress="+shippingaddress+"&shippingCountry="+shippingCountry+"&shippingState="+shippingState+"&shippingcity="+shippingcity+"&shippingzipcode="+shippingzipcode+"&shippingphone="+shippingphone+"&shippingcellular="+shippingcellular+"&shippingemail="+shippingemail+"&peid="+peid);
		
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("POST","paymentstep3.php?oid="+oid+"&billingfirstname="+billingfirstname+"&billinglastname="+billinglastname+"&billingcompany="+billingcompany+"&billingaddress="+billingaddress+"&billingCountry="+billingCountry+"&billingState="+billingState+"&billingcity="+billingcity+"&billingzipcode="+billingzipcode+"&billingphone="+billingphone+"&billingcellular="+billingcellular+"&billingemail="+billingemail+"&shippingfirstname="+shippingfirstname+"&shippinglastname="+shippinglastname+"&shippingcompany="+shippingcompany+"&shippingaddress="+shippingaddress+"&shippingCountry="+shippingCountry+"&shippingState="+shippingState+"&shippingcity="+shippingcity+"&shippingzipcode="+shippingzipcode+"&shippingphone="+shippingphone+"&shippingcellular="+shippingcellular+"&shippingemail="+shippingemail+"&peid="+peid+"&val="+val+"&desc="+desc,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	
	
	
	
	
	
	function GetPaymentReview(oid,peid,val)
	{
		var oid= oid;
		var peid= peid;
		var val=val;
		var realcost = document.getElementById("txtrealcost").value;
		var shippingcharges = document.getElementById("txtshippingcharges").value;
		var CardType = document.getElementById("CardType").value;
		var CardNumber = document.getElementById("CardNumber").value;
		var total = document.getElementById("txttotal").value;
	
		
		
		var billingfirstname = document.getElementById("txtbillingfirstname").value;
		var billinglastname = document.getElementById("txtbillinglastname").value;
		var billingcompany = document.getElementById("txtbillingcompany").value;
		var billingaddress = document.getElementById("txtbillingaddress").value;
		var billingCountry = document.getElementById("billingCountry").value;
		var billingState = document.getElementById("billingState").value;
		var billingcity = document.getElementById("billingcity").value;
		var billingzipcode = document.getElementById("txtbillingzipcode").value;
		var billingphone = document.getElementById("txtbillingphone").value;
		var billingcellular = document.getElementById("txtbillingcellular").value;
		var billingemail = document.getElementById("txtbillingemail").value;
		
		var shippingfirstname = document.getElementById("txtshippingfirstname").value;
		var shippinglastname = document.getElementById("txtshippinglastname").value;
		var shippingcompany = document.getElementById("txtshippingcompany").value;
		var shippingaddress = document.getElementById("txtshippingaddress").value;
		var shippingCountry = document.getElementById("shippingCountry").value;
		var shippingState = document.getElementById("shippingState").value;
		var shippingcity = document.getElementById("shippingcity").value;
		var shippingzipcode = document.getElementById("txtshippingzipcode").value;
		var shippingphone = document.getElementById("txtshippingphone").value;
		var shippingcellular = document.getElementById("txtshippingcellular").value;
		var shippingemail = document.getElementById("txtshippingemail").value;
		var desc = document.getElementById("txtdesc").value;
		
		
		
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","paymentstep3.php?oid="+oid+"&billingfirstname="+billingfirstname+"&billinglastname="+billinglastname+"&billingcompany="+billingcompany+"&billingaddress="+billingaddress+"&billingCountry="+billingCountry+"&billingState="+billingState+"&billingcity="+billingcity+"&billingzipcode="+billingzipcode+"&billingphone="+billingphone+"&billingcellular="+billingcellular+"&billingemail="+billingemail+"&shippingfirstname="+shippingfirstname+"&shippinglastname="+shippinglastname+"&shippingcompany="+shippingcompany+"&shippingaddress="+shippingaddress+"&shippingCountry="+shippingCountry+"&shippingState="+shippingState+"&shippingcity="+shippingcity+"&shippingzipcode="+shippingzipcode+"&shippingphone="+shippingphone+"&shippingcellular="+shippingcellular+"&shippingemail="+shippingemail+"&peid="+peid+"&val="+val+"&desc="+desc,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			 if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	
	
	

function EditPaymentInfo(paymentid)
	{   			
       	var paymentid= paymentid;
		var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","edit_payment.php?id="+paymentid,true);
        xmlhttp1.onreadystatechange = function()
    	{
    		 if (xmlhttp1.readyState <4) {
 
                     document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }







function UpdatePaymentInfo(oid,peid,val)
	{   
		//var sid = document.getElementById("txtcustomerid").value;		
       var xmlhttp1 = new cl_xmlHttpObject();
	  
			var oid= oid;
			var peid= peid;
			var val=val;
			
			
			var month=document.frmusers.month.value;
			var year=document.frmusers.year.value;
			//alert(val);
		var realcost = document.getElementById("txtrealcost").value;
		var shippingcharges = document.getElementById("txtshippingcharges").value;
		var CardType = document.getElementById("CardType").value;
		var CardNumber = document.getElementById("CardNumber").value;
		var total = document.getElementById("txttotal").value;
	
		
		
		var billingfirstname = document.getElementById("txtbillingfirstname").value;
		var billinglastname = document.getElementById("txtbillinglastname").value;
		var billingcompany = document.getElementById("txtbillingcompany").value;
		var billingaddress = document.getElementById("txtbillingaddress").value;
		var billingCountry = document.getElementById("billingCountry").value;
		var billingState = document.getElementById("billingState").value;
		var billingcity = document.getElementById("billingcity").value;
		var billingzipcode = document.getElementById("txtbillingzipcode").value;
		var billingphone = document.getElementById("txtbillingphone").value;
		var billingcellular = document.getElementById("txtbillingcellular").value;
		var billingemail = document.getElementById("txtbillingemail").value;
		
		var shippingfirstname = document.getElementById("txtshippingfirstname").value;
		var shippinglastname = document.getElementById("txtshippinglastname").value;
		var shippingcompany = document.getElementById("txtshippingcompany").value;
		var shippingaddress = document.getElementById("txtshippingaddress").value;
		var shippingCountry = document.getElementById("shippingCountry").value;
		var shippingState = document.getElementById("shippingState").value;
		var shippingcity = document.getElementById("shippingcity").value;
		var shippingzipcode = document.getElementById("txtshippingzipcode").value;
		var shippingphone = document.getElementById("txtshippingphone").value;
		var shippingcellular = document.getElementById("txtshippingcellular").value;
		var shippingemail = document.getElementById("txtshippingemail").value;
		var desc = document.getElementById("desc").value;
						
				xmlhttp1.open("POST","add_payment_submit.php?oid="+oid+"&realcost="+realcost+"&shippingcharges="+shippingcharges+"&CardType="+CardType+"&CardNumber="+CardNumber+"&total="+total+"&billingfirstname="+billingfirstname+"&billinglastname="+billinglastname+"&billingcompany="+billingcompany+"&billingaddress="+billingaddress+"&billingCountry="+billingCountry+"&billingState="+billingState+"&billingcity="+billingcity+"&billingzipcode="+billingzipcode+"&billingphone="+billingphone+"&billingcellular="+billingcellular+"&billingemail="+billingemail+"&shippingfirstname="+shippingfirstname+"&shippinglastname="+shippinglastname+"&shippingcompany="+shippingcompany+"&shippingaddress="+shippingaddress+"&shippingCountry="+shippingCountry+"&shippingState="+shippingState+"&shippingcity="+shippingcity+"&shippingzipcode="+shippingzipcode+"&shippingphone="+shippingphone+"&shippingcellular="+shippingcellular+"&shippingemail="+shippingemail+"&peid="+peid+"&val="+val+"&month="+month+"&year="+year+"&desc="+desc,true);
	
	
	
        xmlhttp1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

        xmlhttp1.onreadystatechange = function()
    	{
    		
			
			if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								get_message(xmlhttp1.responseText)
								PlaceOrdersInfo();
								//display_info(xmlhttp1.responseText);								
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
						
    	};

    xmlhttp1.send(null);
    }
	
	
	
	
	
	
	
function AddPaymentInfo()
	{   			
       	var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","edit_order.php",true);
        xmlhttp1.onreadystatechange = function()
    	{
    		
			if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
}
	

	
	function CallPaymentCancel()
	{  
		
		var xmlhttp1 = new cl_xmlHttpObject();				
		xmlhttp1.open("GET","paymentstep1.php",true);
        xmlhttp1.onreadystatechange = function()
    	{
    		if (xmlhttp1.readyState <4) {
 
                      document.getElementById('home_id').innerHTML = "<img src='images/working.gif'>Loading......";
					  //display_info(xmlhttp1.responseText);
  
                  }
				  else if(xmlhttp1.readyState ==4)
						{
							if(xmlhttp1.status==200)
							{
								clear_message();
								display_info(xmlhttp1.responseText);
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }


//==============Email==========

function emailCheck1 (emailStr)
			{
			
					var checkTLD=1;
					var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
					var emailPat=/^(.+)@(.+)$/;
					var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
					var validChars="\[^\\s" + specialChars + "\]";
					
					var quotedUser="(\"[^\"]*\")";
					
					var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
					
					var atom=validChars + '+';
					var word="(" + atom + "|" + quotedUser + ")";
					var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
					
					var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
					var matchArray=emailStr.match(emailPat);
					
					if (matchArray==null) {
					alert("Email address seems incorrect (check @ and .'s)");
					return false;
					//document.frmuser.txtemail.focus();
					
					}
					var user=matchArray[1];
					var domain=matchArray[2];
					
					// Start by checking that only basic ASCII characters are in the strings (0-127).
					
					for (i=0; i<user.length; i++) {
					if (user.charCodeAt(i)>127) {
					alert("Ths username contains invalid characters.");
					return false;
					//document.frmuser.txtemail.focus();
					
					   }
					}
					for (i=0; i<domain.length; i++) {
					if (domain.charCodeAt(i)>127) {
					alert("Ths domain name contains invalid characters.");
					return false;
					//document.frmuser.txtemail.focus();
					
					   }
					}
					
					// See if "user" is valid 
					
					if (user.match(userPat)==null) {
					
					// user is not valid
					
					alert("The username doesn't seem to be valid.");
					return false;
					//document.frmuser.txtemail.focus();
					
					}
					
				/*	 if the e-mail address is at an IP address (as opposed to a symbolic
					host name) make sure the IP address is valid. */
					
				var IPArray=domain.match(ipDomainPat);
					if (IPArray!=null) {
					
					// this is an IP address
					
					for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
					alert("Destination IP address is invalid!");
					return false;
					//document.frmuser.txtemail.focus();
					
					   }
					}
					return true;
					}
					
					// Domain is symbolic name.  Check if it's valid.
					 
					var atomPat=new RegExp("^" + atom + "$");
					var domArr=domain.split(".");
					var len=domArr.length;
					for (i=0;i<len;i++) {
					if (domArr[i].search(atomPat)==-1) {
					alert("The domain name does not seem to be valid.");
					return false;
					//document.frmuser.txtemail.focus();
					
					   }
					}
					
					/* domain name seems valid, but now make sure that it ends in a
					known top-level domain (like com, edu, gov) or a two-letter word,
					representing country (uk, nl), and that there's a hostname preceding 
					the domain or country. */
					
					if (checkTLD && domArr[domArr.length-1].length!=2 && 
					domArr[domArr.length-1].search(knownDomsPat)==-1) {
					alert("The address must end in a well-known domain or two letter " + "country.");
					return false;
					//document.frmuser.txtemail.focus();
					
					}
					
					// Make sure there's a host name preceding the domain.
					
					if (len<2) {
					alert("This address is missing a hostname!");
					return false;
					//document.frmuser.txtemail.focus();
					
					}
					
					// If we've gotten this far, everything's valid!
					return true;
			}