// JavaScript Document

function deleteshopcart()
 {
	  var a_arry=new Array(); 
	  //var checkLen=document.getElementsByName('chk_id[]').length;
	  var checkLen = document.shopcart.elements.length;
		//alert(checkLen);
	  var y=0;
	  var browserName=navigator.appName; 
 
		 if (browserName=="Microsoft Internet Explorer")
		 {
			  for(i=0;i<checkLen;i++)
			 {	//alert(i); 
				if(document.all.shopcart.elements[i].checked==true) 
				 { 	    
								   var arry=document.all.shopcart.elements[i].value;
								  // alert(arry);
								   var x=arry.length;
								   //alert(x);
								   a_arry[y]=arry;
									   y++;
				  }
				
			 }
		  
		 }
		 else
		  {
    		 
		
		   for(i=0; i<checkLen; i++)
			 {	 
//				var a=document.getElementsByName('chk_id[]').checked;
				//alert(document.shopcart.checkbox[i].name);
				if(document.shopcart.elements[i].type="checkbox")
				 { //alert('hi');
					if(document.shopcart.elements[i].checked==true) 
				 	{ 	    
								   var arry=document.shopcart.elements[i].value;
							    //alert(arry); 
								   var x=arry.length;											
								   a_arry[y]=arry;
									   y++;
				  	}
				
				 }
			 } 
		  }
			 var arrycount=a_arry.length;
  //var url='display_company.php?DELETE='+DELETE+'&arrycount='+arrycount+'&a_arry='+a_arry;  
  			var xmlhttp1 = new cl_xmlHttpObject();	
			//alert("delete_shopcart.php?arrycount="+arrycount+"&a_arry="+a_arry); 
			xmlhttp1.open("POST","delete_shopcart.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)
									 //GetAdminContent(page,2);
									 GetShopDetails();
									//display_info(xmlhttp1.responseText);
								}
								else
								{
								display_info("An Error Occured:"+ xmlhttp1.statusText);
								}
							}
			};
    	   xmlhttp1.send(null);  

 }







 function ValidateDeleteShopcart()
	{   clear_message();
	    var ch=0;
	    len = document.shopcart.elements.length;
		var i=0;
		for( i=0 ; i<len ; i++) 
		{
		  	if (document.shopcart.elements[i].name=='chk_id[]') 
				{
	
					if (document.shopcart.elements[i].checked==1)
						{
					
							ch = 1;
						}
				}
		}
	
		if (ch == 1)
		{
			if(confirm('Confirm Delete'))
			{
				//document.frmlist.action="submit.php?mode=deletecrewcategory";
				//document.frmlist.submit();
				deleteshopcart();
			}
			else 
				return false;

		}
		else
		{
			alert("Please Select Product(s) to delete.");	
			return false;
		}
	}





 

function GetProduct(id)
	{
		var id= id;		
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","shopcart.php?id="+id,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 Add_shoptcart()
	{   			
       	
		var xmlhttp1 = new cl_xmlHttpObject();	
		var prod_id = document.getElementById("prod_id").value;
		var desc = document.getElementById("desc").value;
		var prod_price = document.getElementById("Price").value;
		
			
		xmlhttp1.open("GET","submit_shopcart.php?prod_id="+prod_id+"&prod_price="+prod_price,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);
								GetShopDetails();
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};

    xmlhttp1.send(null);
    }


	function GetShopDetails(id)
	{
				
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","shopcart_details.php?id="+id,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 GetShopDetails1()
	{
		
		//var sid = document.getElementById("txtcustomerid").value;
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","shopcart_details.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);
	}
	//////////Check All//////////////////

function CheckAll(chk)
{
	
for (var i=0;i < document.shopcart.elements.length;i++)
	{	
		var e = document.shopcart.elements[i];
		if (e.type == "checkbox")
		{
			e.checked = chk.checked;
		}
	}
}

////////////Payment Details information of Customer////////
function checkOut()
	{
	
		/*if(document.shopcart,txtqut.value =="0")
		  {
			  alert("Shopping cart can not be blank.");
			  return false;
		  }*/
       var xmlhttp1 = new cl_xmlHttpObject();
    	xmlhttp1.open("get","Shopcart_Userdetails.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 MakePaymentstep_shopcart()
	{
		var billingfirstname = document.getElementById("txtbillingfirstname").value;
		if(billingfirstname ==""){ alert("Firstname can not be blank."); document.getElementById("txtbillingfirstname").focus(); return false;}
		var billinglastname = document.getElementById("txtbillinglastname").value;
		if(billinglastname ==""){ 
		 alert("Lastname can not be blank.");
		 document.getElementById("txtbillinglastname").focus();
		 return false;}
		var billingcompany = document.getElementById("txtbillingcompany").value;
		if(billingcompany ==""){ 
		alert("Company Name can not be blank.");
		document.getElementById("txtbillingcompany").focus();
		return false;}
		var billingaddress = document.getElementById("txtbillingaddress").value;
		if(billingaddress ==""){
			alert("Address can not be blank.");
			document.getElementById("txtbillingaddress").focus();
			return false;}
		var billingCountry = document.getElementById("billingCountry").value;		
		var billingState = document.getElementById("billingState").value;
		var billingcity = document.getElementById("billingcity").value;
		if(billingcity ==""){
			alert("City can not be blank.");
			document.getElementById("billingcity").focus();
			return false;}
		var billingzipcode = document.getElementById("txtbillingzipcode").value;
		if(billingzipcode ==""){
			alert("Zipcode can not be blank.");
			document.getElementById("txtbillingzipcode").focus();
			return false;}
		var billingphone = document.getElementById("txtbillingphone").value;
		if(billingphone ==""){
			alert("Phone No can not be blank.");
			document.getElementById("txtbillingphone").focus();
			return false;}
		var billingcellular = document.getElementById("txtbillingcellular").value;
		if(billingcellular ==""){
			alert("Cellular No can not be blank.");
			document.getElementById("txtbillingcellular").focus();
			return false;}
		var billingemail = document.getElementById("txtbillingemail").value;
		if(billingemail ==""){
			alert("Email Address can not be blank");
			document.getElementById("txtbillingemail").focus();
			return false;}else{ if(!emailCheck1(billingemail))return false;}
		
		var desc = document.getElementById("desc").value;
		var CardNumber = document.getElementById('CardNumber').value;
        var CardType = document.getElementById('CardType').value;
		var month=document.getElementById('month').value;
		var year=document.getElementById('year').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","confirm_shopcart.php?billingfirstname="+billingfirstname+"&billinglastname="+billinglastname+"&billingcompany="+billingcompany+"&billingaddress="+billingaddress+"&billingCountry="+billingCountry+"&billingState="+billingState+"&billingcity="+billingcity+"&billingzipcode="+billingzipcode+"&billingphone="+billingphone+"&billingcellular="+billingcellular+"&billingemail="+billingemail+"&desc="+desc+"&CardNumber="+CardNumber+"&CardType="+CardType+"&month="+month+"&year="+year,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 CheckCreditCard() {
  myCardNo = document.getElementById('CardNumber').value;
  myCardType = document.getElementById('CardType').value;
  if (checkCreditCard (myCardNo,myCardType)) {
    //alert ("Credit card has a valid format")
		var m=document.getElementById('month').value;
		var y=document.getElementById('year').value;
		
	if(!parseInt(m) || !parseInt(y) )
	  {
	   alert("Exspiry date can not be blank.");
	   return false;
	  }	
	MakePaymentstep_shopcart();
  } 
  else {alert (ccErrors[ccErrorNo])};
}



function confirm_cart()
	{   
		//var sid = document.getElementById("txtcustomerid").value;		
       var xmlhttp1 = new cl_xmlHttpObject();
	  
		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 desc = document.getElementById("desc").value;
			
		var month=document.getElementById('month').value;
		var year=document.getElementById('year').value;
		var CardType = document.getElementById("CardType").value;
		var CardNumber = document.getElementById("CardNumber").value;
		var total = document.getElementById("total").value;
		var shop_cart_session = document.getElementById("shop_cart_session").value;
		
				//alert("add_payment_submit.php?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+"&month="+month+"&year="+year+"&desc="+desc+"&shop_cart_session="+shop_cart_session);		
				//return false;
				xmlhttp1.open("POST","add_shopingcart_submit.php?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+"&month="+month+"&year="+year+"&desc="+desc+"&shop_cart_session="+shop_cart_session,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);
								GetHomeContent1();
								//PlaceOrdersInfo();
								//display_info(xmlhttp1.responseText);								
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
						
    	};

    xmlhttp1.send(null);
    }
///Update Shpping cart////////

	
/*	function UpdateCart()	
	{
		//var t=document.shopcart.up_prod_price[].value;
		alert(t); return false;
		var checkLen = document.shopcart.elements.length;
		//alert(checkLen);
		var y=0;
		   for(i=0; i<checkLen; i++)
			 {	 
//				var a=document.getElementsByName('chk_id[]').checked;
				//alert(document.shopcart.checkbox[i].name);
				if(document.shopcart.elements[i].type="checkbox")
				 { //alert('hi');
					if(document.shopcart.elements[i].checked==true) 
				 	{ 	    
						var arry=document.shopcart.elements[i].value;
							//alert(arry); 
						var x=arry.length;											
						  a_arry[y]=arry;
						   y++;
				  	}
				
				 }
				 
				 
			 } 
			 var arrycount=a_arry.length;
       var xmlhttp1 = new cl_xmlHttpObject();
    	//xmlhttp1.open("get","update_shopcart.php?chk_id="+a_arry+"&txtdispqty="+,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);
								//get_message("Shopping cart has been successfully updated.");
								//GetShopDetails();
							}
							else
							{
							display_info("An Error Occured:"+ xmlhttp1.statusText);
							}
						}
    	};
    xmlhttp1.send(null);
	}
	
	*/
	
	function check_register()
	 {
		if(confirm("Are you register user."))
		{
			alert("Please login");
			GetHomeContent();
		}else
		{
			EditUserInfo1_shopcart();
		}
	 }
	 
	 
	 
	 
function EditUserInfo1_shopcart()
	{  
	   clear_message();		
       
		var xmlhttp1 = new cl_xmlHttpObject();	
		var shop="shop";
		var mode ='Add';					
		xmlhttp1.open("GET","register.php?mode="+mode+"&shop="+shop,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);
    }
	