function showshipinfo()
{
	if(document.getElementById('chkship').checked)
	{
		document.getElementById('shipfname').value=document.getElementById('billfname').value;
		document.getElementById('shiplname').value=document.getElementById('billlname').value;
		document.getElementById('shipphone').value=document.getElementById('billphone').value;		
		document.getElementById('shipemailid').value=document.getElementById('billemailid').value;
		document.getElementById('shipaddress').value=document.getElementById('billaddress').value;
		document.getElementById('shipcountry').value=document.getElementById('billcountry').value;
		document.getElementById('shipstate').value=document.getElementById('billstate').value;
		document.getElementById('shipcity').value=document.getElementById('billcity').value;
		document.getElementById('shipzip').value=document.getElementById('billzip').value;


		document.getElementById('shipfname').disabled=true;
		document.getElementById('shiplname').disabled=true;
		document.getElementById('shipphone').disabled=true;	
		document.getElementById('shipemailid').disabled=true;
		document.getElementById('shipaddress').disabled=true;
		document.getElementById('shipcountry').disabled=true;
		document.getElementById('shipstate').disabled=true;
		document.getElementById('shipcity').disabled=true;
		document.getElementById('shipzip').disabled=true;
		return false;
	}
	else
	{
		document.getElementById('shipfname').value="";
		document.getElementById('shiplname').value="";
		document.getElementById('shipphone').value="";		
		document.getElementById('shipemailid').value="";
		document.getElementById('shipaddress').value="";
		document.getElementById('shipcountry').value="";
		document.getElementById('shipstate').value="";
		document.getElementById('shipcity').value="";
		document.getElementById('shipzip').value="";


		document.getElementById('shipfname').disabled=false;
		document.getElementById('shiplname').disabled=false;
		document.getElementById('shipphone').disabled=false;	
		document.getElementById('shipemailid').disabled=false;
		document.getElementById('shipaddress').disabled=false;
		document.getElementById('shipcountry').disabled=false;
		document.getElementById('shipstate').disabled=false;
		document.getElementById('shipcity').disabled=false;
		document.getElementById('shipzip').disabled=false;
		return false;
	}
	
}


function chkbillinfo()
{
	if(
		 RequiredField('billfname','Please Enter First Name')&&
		 MinCount('billfname',3,'Please Enter Minimum 3 Characters For First Name')&&
		 RequiredField('billlname','Please Enter Last Name')&&	
		 MinCount('billlname',1,'Please Enter Minimum 1 Character For Last Name')&&		 	
		 RequiredField('billaddress','Please Enter Address')&&
		 MinCount('billaddress',3,'Please Enter Minimum 3 Characters For Address')&&
		 RequiredField('billcity','Please Enter City')&& 
		 MinCount('billcity',3,'Please Enter Minimum 3 Characters For City')&&
		 RequiredField('billstate','Please Enter State/Province') &&
		 MinCount('billstate',2,'Please Enter Minimum 2 Characters For State')&&
		 RequiredField('billcountry','Please Enter Country')&&	
		 MinCount('billcountry',2,'Please Enter Minimum 2 Characters For Country')&&
		 RequiredField('billzip','Please Enter Zip/Postal Code')&& 
		 ZipCodeValidation('billzip')&&
		 RequiredField('billphone','Please Enter Phone Number')&&
		 RequiredField('billemailid','Please Enter Email Address')&&
		 EmailValidation('billemailid') &&
		 
		 
		
		 RequiredField('shipfname','Please Enter First Name')&&
		 MinCount('shipfname',3,'Please Enter Minimum 3 Characters For First Name')&&
		 RequiredField('shiplname','Please Enter Last Name')&&	
		 MinCount('shiplname',1,'Please Enter Minimum 1 Character For Last Name')&&		 
		 RequiredField('shipaddress','Please Enter Address')&&
		 MinCount('shipaddress',3,'Please Enter Minimum 3 Characters For Address')&&
		 RequiredField('shipcity','Please Enter City')&&  
		 MinCount('shipcity',3,'Please Enter Minimum 3 Characters For City')&&
		 RequiredField('shipstate','Please Enter State/Province') &&
		 MinCount('shipstate',2,'Please Enter Minimum 2 Characters For State')&&
		 RequiredField('shipcountry','Please Enter Country')&&
		 MinCount('shipcountry',2,'Please Enter Minimum 2 Characters For Country')&&
		 RequiredField('shipzip','Please Enter Zip/Postal Code')&& 
		 ZipCodeValidation('shipzip')&&
		 RequiredField('shipphone','Please Enter Phone Number')&&
		 RequiredField('shipemailid','Please Enter Email Address')&&
		 EmailValidation('shipemailid')	
		)
	{
			if(document.getElementById('chkship').checked)
			{
				if(((document.getElementById('shipfname').value=="")||(document.getElementById('shipfname').value==" "))&&
				((document.getElementById('shiplname').value=="")||(document.getElementById('shiplname').value==" "))&&
				((document.getElementById('shipemailid').value=="")||(document.getElementById('shipemailid').value==" "))&&
				((document.getElementById('shipphone').value=="")||(document.getElementById('shipphone').value==" "))&&
				((document.getElementById('shipaddress').value == "")||(document.getElementById('shipaddress').value == ""))&&
				((document.getElementById('shipcountry').value == "")||(document.getElementById('shipcountry').value == ""))&&
				((document.getElementById('shipcity').value == "")||(document.getElementById('shipcity').value == ""))&&
				((document.getElementById('shipstate').value == "")||(document.getElementById('shipstate').value == ""))&&
				((document.getElementById('shipzip').value=="")||(document.getElementById('shipzip').value==" ")))
				{
					alert("Shipping Information not matched with Billing Information");
					return false;
				}

				if((document.getElementById('shipfname').value!=document.getElementById('billfname').value)||
				(document.getElementById('shiplname').value!=document.getElementById('billlname').value)||
				(document.getElementById('shipemailid').value!=document.getElementById('billemailid').value)||
				(document.getElementById('shipphone').value!=document.getElementById('billphone').value)||
				(document.getElementById('shipaddress').value!=document.getElementById('billaddress').value)||
				(document.getElementById('shipcity').value!=document.getElementById('billcity').value)||
				(document.getElementById('shipstate').value!=document.getElementById('billstate').value)||
				(document.getElementById('shipzip').value!=document.getElementById('billzip').value)||
				(document.getElementById('shipcountry').value!=document.getElementById('billcountry').value))
				{
					alert("Shipping Information not matched with Billing Information");
					return false;
				}
			}
		
			
			document.form1.action="functions/insertb.php";
			//document.form1.submit();
	}
		else
			return false;
}



function chkcreditinfo()
{
	if(
		 RequiredField('billfname','Please Enter First Name')&&
		 MinCount('billfname',3,'Please Enter Minimum 3 Characters For First Name')&&
		 RequiredField('billlname','Please Enter Last Name')&&	
		 MinCount('billlname',1,'Please Enter Minimum 1 Character For Last Name')&&		 	
		 RequiredField('billaddress','Please Enter Address')&&
		 MinCount('billaddress',3,'Please Enter Minimum 3 Characters For Address')&&
		 RequiredField('billcity','Please Enter City')&& 
		 MinCount('billcity',3,'Please Enter Minimum 3 Characters For City')&&
		 RequiredField('billstate','Please Enter State/Province') &&
		 MinCount('billstate',2,'Please Enter Minimum 2 Characters For State')&&
		 RequiredField('billcountry','Please Enter Country')&&	
		 MinCount('billcountry',2,'Please Enter Minimum 2 Characters For Country')&&	 
		 RequiredField('billzip','Please Enter Zip/Postal Code')&& 
		 ZipCodeValidation('billzip')&&
		 RequiredField('billphone','Please Enter Phone Number')&&
		 RequiredField('billemailid','Please Enter Email Address')&&
		 EmailValidation('billemailid') &&
		 
		 
		
		 RequiredField('shipfname','Please Enter First Name')&&
		 MinCount('shipfname',3,'Please Enter Minimum 3 Characters For First Name')&&
		 RequiredField('shiplname','Please Enter Last Name')&&	
		 MinCount('shiplname',1,'Please Enter Minimum 1 Character For Last Name')&&		 
		 RequiredField('shipaddress','Please Enter Address')&&
		 MinCount('shipaddress',3,'Please Enter Minimum 3 Characters For Address')&&
		 RequiredField('shipcity','Please Enter City')&&  
		 MinCount('shipcity',3,'Please Enter Minimum 3 Characters For City')&&
		 RequiredField('shipstate','Please Enter State/Province') &&
		 MinCount('shipstate',2,'Please Enter Minimum 2 Characters For State')&&
		 RequiredField('shipcountry','Please Enter Country')&&
		 MinCount('shipcountry',2,'Please Enter Minimum 2 Characters For Country')&&
		 RequiredField('shipzip','Please Enter Zip/Postal Code')&& 
		 ZipCodeValidation('shipzip')&&
		 RequiredField('shipphone','Please Enter Phone Number')&&
		 RequiredField('shipemailid','Please Enter Email Address')&&
		 EmailValidation('shipemailid') &&

	     RequiredField('shipcctype','Please Select Credit Card Type')&&
		 RequiredField('shipccnumber','Please Enter Credit Card Number')&&
		 RequiredField('card_expiration_month','Please Select Month')&&
		 RequiredField('card_expiration_year','Please Select Year')&&
		 RequiredField('shipseccode','Please Enter Security Code')
		)
	{
			if(document.getElementById('chkship').checked)
			{
				if(((document.getElementById('shipfname').value=="")||(document.getElementById('shipfname').value==" "))&&
				((document.getElementById('shiplname').value=="")||(document.getElementById('shiplname').value==" "))&&
				((document.getElementById('shipemailid').value=="")||(document.getElementById('shipemailid').value==" "))&&
				((document.getElementById('shipphone').value=="")||(document.getElementById('shipphone').value==" "))&&
				((document.getElementById('shipaddress').value == "")||(document.getElementById('shipaddress').value == ""))&&
				((document.getElementById('shipcountry').value == "")||(document.getElementById('shipcountry').value == ""))&&
				((document.getElementById('shipcity').value == "")||(document.getElementById('shipcity').value == ""))&&
				((document.getElementById('shipstate').value == "")||(document.getElementById('shipstate').value == ""))&&
				((document.getElementById('shipzip').value=="")||(document.getElementById('shipzip').value==" ")))
				{
					alert("Shipping Information not matched with Billing Information");
					return false;
				}

				if((document.getElementById('shipfname').value!=document.getElementById('billfname').value)||
				(document.getElementById('shiplname').value!=document.getElementById('billlname').value)||
				(document.getElementById('shipemailid').value!=document.getElementById('billemailid').value)||
				(document.getElementById('shipphone').value!=document.getElementById('billphone').value)||
				(document.getElementById('shipaddress').value!=document.getElementById('billaddress').value)||
				(document.getElementById('shipcity').value!=document.getElementById('billcity').value)||
				(document.getElementById('shipstate').value!=document.getElementById('billstate').value)||
				(document.getElementById('shipzip').value!=document.getElementById('billzip').value)||
				(document.getElementById('shipcountry').value!=document.getElementById('billcountry').value))
				{
					alert("Shipping Information not matched with Billing Information");
					return false;
				}
			}
			document.form1.action="authorize/php_aim1.php";
			document.form1.submit();
	}
		else
			return false;
}



function showcreditinfo()
{
	if((document.getElementById('VisaCard').checked)||(document.getElementById('MasterCard').checked)||(document.getElementById('DiscoverCard').checked))
	{
		document.getElementById('creditinfo').style.display="block";
		document.getElementById('paywithpaypal').style.display="none";
		document.getElementById('creditbutton').style.display="block";
		document.getElementById('shipinfo').style.display="block";
		document.getElementById('paywithgoogle').style.display="none";
	}	
	if(document.getElementById('paypalcard').checked)
	{
		document.getElementById('creditinfo').style.display="none";
		document.getElementById('paywithpaypal').style.display="block";
		document.getElementById('creditbutton').style.display="none";
		document.getElementById('shipinfo').style.display="block";
		document.getElementById('paywithgoogle').style.display="none";
	}
	if(document.getElementById('googlecard').checked)
	{
		document.getElementById('creditinfo').style.display="none";
		document.getElementById('paywithpaypal').style.display="none";
		document.getElementById('paywithgoogle').style.display="block";
		document.getElementById('creditbutton').style.display="none";
		document.getElementById('shipinfo').style.display="none";
	}
}



function LTrim(str) {
for (var i=0; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i++);
return str.substring(i,str.length);
}
function RTrim(str) {
for (var i=str.length-1; ((str.charAt(i)<=" ")&&(str.charAt(i)!="")); i--);
return str.substring(0,i+1);
}
function Trim(str) {
return LTrim(RTrim(str));
}

function RequiredField(text,msg)
{
    if(Trim(document.getElementById(text).value)=="")
    {
        alert(msg);
        document.getElementById(text).focus();
        return false;
    } 
    else
    {
      return true;
    }   

}

function MinCount(text,long,msg) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (document.getElementById(text).value.length < maxlength)
	{		
		alert(msg);		
		document.getElementById(text).focus();
		return false;
	}		
	else
		return true;
}

function MinimumCount(text,long,msg) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (document.getElementById(text).value!="")
	{
		if (document.getElementById(text).value.length < maxlength)
		{		
			alert(msg);		
			document.getElementById(text).focus();
			return false;
		}	
		else
		{
		return true;
		}
	return false;
	}
	else
		return true;
	
}

function PhoneValidation(txtphoneID)
{
    if(Trim(document.getElementById(txtphoneID).value)!="")//For Phone validate
	{
	        //US Format
		   // regexp=/^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/;
	    regexp=/^\d{3}[- .]?\d{3}[- .]?\d{4}$/;
	    if(document.getElementById(txtphoneID).value.search(regexp)==-1)
	    {
		    document.getElementById(txtphoneID).value="";
		    alert('Phone Number Should be in Given Format: xxx-xxx-xxxx');
		    document.getElementById(txtphoneID).focus();
		    return false;
	    }
	    else
	      return true;
	 }
	 else
	    return true;

}

function EmailValidation(text)
{
	if(Trim(document.getElementById(text).value)!="")
	{ 
		regexp=/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
		if(document.getElementById(text).value.search(regexp)==-1)
		{
			document.getElementById(text).value="";
			alert('Please Enter Valid Email Address');
			document.getElementById(text).focus();
			return false;
		}
		else
			return true;
	}
	else 
		return true;
}

function CheckDropdown(drpdown,msg)
{
	
  if((document.getElementById(drpdown).value=="Select")||(document.getElementById(drpdown).value==""))
  {
    alert(msg);
    document.getElementById(drpdown).focus();
    return false;
  }
  else
   return true;
}

function ZipCodeValidation(text)
{
	if(Trim(document.getElementById(text).value)!="")
	{		
	  regexp=/^[a-zA-Z 0-9]{4,10}$/;
	  if(document.getElementById(text).value.search(regexp)==-1)
	  {
	  document.getElementById(text).value="";
			alert('Zip/Postal Code should be between 4 to 10 characters only');
		document.getElementById(text).focus();
			return false;
	  }
	  else
		  return true;
	 }
	 else
		 return true;

}

//for check space
function checkspace(text)
{          
          var str=text.value;
          var first=str.substring(0,1);
          var second=str.substring(0,1);
          var val='false';
          if(first==' ')
          {
                val='true';
                if(val=='true')
                {
                   if(second==' ')
                   {
                     val='true';
                     alert('Please Enter Valid Information');
                     text.value = "";
                   }
                }
          }
		 
}

function OnlyAlphabets(text)
{

	var regexp=/^[a-zA-Z- ]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please enter only letters a-z');
			if(text.value.search(regexp)==-1)
			text.value="";
		}	

}

function NumbersOnly(text)
{
	if(text.value.length==0)
		return;
/*if(text.value==0)
{
		alert('Invalid Number');
		text.value='';
		return false;
}  */  		

	var regexp=/^[0-9]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please enter only numbers 0-9');
			if(text.value.search(regexp)==-1)
			text.value="";
		}	
}

function OnlyAlphaNumerics(text)
{
	if(text.value==0)
		{
			alert('Invalid Zip/Postal Code');
			text.value='';
			return false;
		}
	var regexp=/^[a-zA-Z0-9 ]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please enter only letters a-z and numbers 0-9');
			if(text.value.search(regexp)==-1)
			text.value="";
		}	

}

function chkqtyNumbersOnly(text)
{
	if(text.value.length==0)
		return;
if(text.value==0)
{
		alert('Invalid Number');
		text.value='';
		return false;
}    		

	var regexp=/^[0-9]*$/;
	if(text.value.search(regexp)==-1)
		{
			text.value = text.value.substring(0,(text.value.length-1));
			alert('Please enter only numbers 0-9');
			if(text.value.search(regexp)==-1)
			text.value="";
			return false;
		}	
}

function qtyupdate()
{
	var price=document.getElementById('price').value;
	var total=document.getElementById('total').value;
	var qty=document.getElementById('label3').value;	
	
		
	 if(document.getElementById('label3').value==0)
		{			
	    alert('Please enter valid Information');
		document.getElementById('label3').value="1";
		var quantity="1";
		document.getElementById('tprice')=price*quantity;
		document.getElementById('gtotal')=price+(price*qty);
		document.getElementById('label3').focus();
		return false;
		} 

	if(document.getElementById('label3').value!="")
	{		
		regexp=/^[0-9]{1,2}$/;
	  if(document.getElementById('label3').value.search(regexp)==-1)
	  {
	    document.getElementById('label3').value="1";
		document.getElementById('tprice')=price*qty;
		document.getElementById('gtotal')=price+(price*qty);
	    alert('Please enter only numbers 0-9');
		document.getElementById('label3').focus();
		return false;
	  }	  
	 
	}

	


	

	document.form1.action="viewcart.php?action=update";
	document.form1.submit();
}

function chkformore()
{
	document.location="products.php";
}

function chkcountry()
{
	var val=form1.shipcountry.options[form1.shipcountry.options.selectedIndex].value; 
	self.location='billing.php?cid=' + val ;
}

function chkgooglechkout()
{
	var cid=document.getElementById('countryid').value;
	document.form1.action="cartdemo.php?cid=" + cid;
}

function chkshipprice()
{
	document.getElementById('shipppingprice').innerHTML="<b>Shipping</b> : $"+document.getElementById('shipprice').value;
}