var product_array = new Array();
function addtoids(id)
{	
	if(document.getElementById("check"+id).checked==true)
	{
		product_array.push(id);	
		document.price.productids.value=product_array;
	}
	else
	{
		var prod_array=removeFromArray(id,product_array);
		product_array=prod_array;
	}
}
function submitdoc(totalrows)
{
	totalrows=decodeBase64(totalrows);
	var flag=0;
	var totalrowarray=totalrows.split(",");	
	for(var i=0;i<totalrowarray.length;i++)
	{
		if(document.getElementById("check"+totalrowarray[i]).checked==true)
			flag=1;		
	}
	if(flag==1)
	{
		document.price.action="cartaction.php";
		document.price.submit();
	}
	else
	{
		alert("Please select one product");
	}
}
/**** Tool ***/
function submittool(totalrows)
{
	var flag=0,flag2=0;
	var totalrowarray=totalrows.split(",");
	for(var i=0;i<totalrowarray.length;i++)
	{
		if(document.getElementById("check"+totalrowarray[i]).checked==true)
		{
			/*var totalunit=document.getElementById("unitrows"+totalrowarray[i]).value.split(",");
			for(var j=0;j<totalunit.length;j++)
			{	
				if(document.getElementById(totalunit[j]+"check"+totalrowarray[i]).checked==true)
				{
					flag2=1;
				}
			}
			if(flag2==0)
			{
				alert("Please select unit");
				return false;
			}*/
			flag=1;
		}
	}
	if(flag==1)
	{
		document.price.action="cartaction.php";
		document.price.submit();
	}
	else
	{
		alert("Please select one product");
	}
}
function removeFromArray(val, ar){
s = String(ar)
// remove if not first item (global search)
reRemove = new RegExp(","+val,"g")
s = s.replace(reRemove,"")
// remove if at start of array
reRemove = new RegExp("^"+val+",")
s = s.replace(reRemove,"")
// remove if only item
reRemove = new RegExp("^"+val+"$")
s = s.replace(reRemove,"")
return new Array(s)
}



/** View cart page *****/
    function remove()
    {   
        var name; 
        name=document.view_cart.removes;
        name.value='2';
        
        
        var flag
        flag=0;
             
       for (i=0;i<document.view_cart.elements.length;i++)
        {
                if(document.view_cart.elements[i].type=="checkbox")
                {
                    if(document.view_cart.elements[i].checked)
                    {
                      flag=1;
                    }
                }
                
        }  
           
            if(flag!=1)
            {
                alert("Select Appropriate checkbox");
                return false;
            }   
            
                document.view_cart.action="cartaction.php";
                document.view_cart.submit();
                
            }
            
            
            function Isvalid(sText)
            {
                var ValidChars = "0123456789";
                var IsNumber=true;
                var Char;
                
            
            for (i = 0; i < sText.length && IsNumber == true; i++) 
            { 
                     Char = sText.charAt(i); 
                    if (ValidChars.indexOf(Char) == -1) 
                    {
                       IsNumber = false;
                    }
            }
            
            
             return IsNumber;
            
            }
            
            
            
            
   function frsubmit()
        {
                var flag;
                var chk;
                var name;
                var test;
                name=document.view_cart.update;
                name.value='1';
                document.view_cart.action="cartaction.php";
                document.view_cart.submit();                
                
                } // frsubmit
            
            
            
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
         return true;

      }
function trim(str)
{
        return str.replace(/^\s+|\s+$/g, '');
}

var xmlHttp
//********************************************************* Normal sign-in  ************************************/
function checkavs(str,str1,str2)
{       
        document.getElementById("txtHint").innerHTML="<br><br><span class='text' style='color:red'>Please wait...</span><br><br>";       

        document.getElementById("loginregister").style.display="none"       
        document.getElementById("passworddiv").style.display="none"
        document.getElementById("billingshippingtext").style.display="none"

        var url="AVS.php?x_ship_to_city=" + str + "&x_ship_to_state=" + str1 + "&x_ship_to_zip=" + str2 
        xmlHttp=GetXmlHttpObject(stateChanged)
        xmlHttp.open("GET", url , true)
        xmlHttp.send(null)              
}


//****************************************************************************************


function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{       
        if(xmlHttp.responseText)
		// if(xmlHttp.responseText && document.getElementById("x_ship_to_country").value=="US")
		// 10/29/2007
       {
                document.getElementById("txtHint").innerHTML=xmlHttp.responseText;      

                document.getElementById("loginregister").style.display="block"               
                document.getElementById("passworddiv").style.display="block"
                document.getElementById("billingshippingtext").style.display="block"
                document.getElementById("sstatetd").style.color="red";
                document.getElementById("sziptd").style.color="red";
                document.getElementById("scitytd").style.color="red";
                document.getElementById("bziptd").style.color="red";
                document.getElementById("bstatetd").style.color="red";
                document.getElementById("bcitytd").style.color="red";           
        }
        else
        {         
         document.login.action="login.php?newuser=yes";
         document.login.submit();
        }
}
}

//********************************************************* Normal sign-in  ************************************/

/*********************** Update checking *******************************************************************/

function updatecheckavs(str,str1,str2)
{       
        document.getElementById("txtHint").innerHTML="<br><br><span class='normal-text' style='color:red'>Please wait...</span><br><br>";       
        document.getElementById("checkouttable").style.display="none"
        var url="AVS.php?x_ship_to_city=" + str + "&x_ship_to_state=" + str1 + "&x_ship_to_zip=" + str2
        xmlHttp=GetXmlHttpObject(stateChangedupdate)
        xmlHttp.open("GET", url , true)
        xmlHttp.send(null)              
}


//****************************************************************************************


function stateChangedupdate() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{       
        if(xmlHttp.responseText && document.getElementById("countryselect").value=="US")
        {
                document.getElementById("txtHint").innerHTML=xmlHttp.responseText;              
                document.getElementById("checkouttable").style.display="block"
                document.getElementById("sstatetd").style.color="red";
                document.getElementById("sziptd").style.color="red";
                document.getElementById("scitytd").style.color="red";
                document.getElementById("bziptd").style.color="red";
                document.getElementById("bstatetd").style.color="red";
                document.getElementById("bcitytd").style.color="red";           
        }
        else
        {
               document.checkout.action="login.php?update=1";
               document.checkout.submit();
        }
}
}

/*********************** Update checking *******************************************************************/
/*********************** User name checking ****************************************************************/
function userexist(str)
{
        var url="AVS.php?checkuser=" + str
        xmlHttp=GetXmlHttpObject(stateChangeduser)
        xmlHttp.open("GET", url , true)
        xmlHttp.send(null)              
}

function stateChangeduser() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{                       
        if(xmlHttp.responseText)
        {
                document.getElementById("userexist").style.display="block";             
        }
        else
        {                       

                document.getElementById("userexist").style.display="none";      
                                
                document.getElementById("passworddiv").style.display= "block";
                document.getElementById("passworddiv").style.visibility= "visible" ;

                document.getElementById("billingshippingtext").style.display="block";
                document.getElementById("billingshippingtext").style.visibility="visible";

                document.getElementById("passwordtext").style.display="block";
                document.getElementById("passwordtext").style.visibility="visible";

				document.getElementById("registration1").style.display="block";
                document.getElementById("registration1").style.visibility="visible";

				document.getElementById("registration").style.display="none";
                document.getElementById("registration").style.visibility="hidden";

                //document.getElementById("x_email").value=document.getElementById("new_username").value;	
				//10/29/2007

                document.getElementById("proceed").style.display="none";
                document.getElementById("proceed").style.visibility="hidden";
        }
}
}

/*********************** User name checking ****************************************************************/

/*********************** Coupon value ****************************************************************/


function GetXmlHttpObject(handler)
{ 
var objXmlHttp=null

if (navigator.userAgent.indexOf("Opera")>=0)
{
        objXmlHttp=new XMLHttpRequest()
        objXmlHttp.onload=handler
        objXmlHttp.onerror=handler
        return objXmlHttp
/*alert("This example doesn't work in Opera") 
return; */
}
if (navigator.userAgent.indexOf("MSIE")>=0)
{ 
var strName="Msxml2.XMLHTTP"
if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
{
strName="Microsoft.XMLHTTP"
} 
try
{ 
objXmlHttp=new ActiveXObject(strName)
objXmlHttp.onreadystatechange=handler 
return objXmlHttp
} 
catch(e)
{
alert("Error. Scripting for ActiveX might be disabled")
return
}
}
if (navigator.userAgent.indexOf("Mozilla")>=0)
{
objXmlHttp=new XMLHttpRequest()
objXmlHttp.onload=handler
objXmlHttp.onerror=handler
return objXmlHttp
}
}


/************************* Validation of sign-in from *************************/
function verify1()
        {

        if(document.login.username.value == "")
        {
            alert("Please Enter User Name!");
            document.login.username.focus();
            return false;
        }      
        if(document.login.password.value == "")
        {
            alert("Please Enter Password!");
            document.login.password.focus();
            return false;
        }
}
function verify(check)
{
        if(check==1)
        {
                        if(document.login.new_password.value == "")
                        {
                                alert("Please Enter Password!");
                                document.login.new_password.focus();
                                return false;
                        }
                        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.login.new_password.value))
                        {
                                alert("Please enter valid Password!");
                                document.login.new_password.value = "";
                                document.login.new_password.focus();
                                return false;
                        }
                        if(document.login.newv_password.value != document.login.new_password.value)
                        {
                                alert("Confirm Password is not same as Password!");
                                document.login.newv_password.focus();
                                return false;
                        }                       
        }               
        if(document.login.x_first_name.value == "")
        {
            alert("Please Enter First Name!");
            document.login.x_first_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.login.x_first_name.value))
        {
            alert("Please enter valid First name!");
            document.login.x_first_name.value = "";
            document.login.x_first_name.focus();
            return false;
        }
        if(document.login.x_last_name.value == "")
        {
            alert("Please Enter Last Name!");
            document.login.x_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.login.x_last_name.value))
        {
            alert("Please enter valid First name!");
            document.login.x_last_name.value = "";
            document.login.x_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.login.x_email.value))
        {
            alert("Please enter valid email address!");
            document.login.x_email.value = "";
            document.login.x_email.focus();
            return false;
        }
        if(document.login.x_address.value == "")
        {
            alert("Please enter your Street 1!");
            document.login.x_address.focus();
            return false;
        }                       
        if(document.login.x_city.value == "")
        {
            alert("Please enter your City!");
            document.login.x_city.focus();
            return false;
        }
        if(document.login.x_state.value == "")
        {
            alert("Please enter your State!");
            document.login.x_state.focus();
            return false;
        }
        if(document.login.x_zip.value == "")
        {
            alert("Please enter your Zip Code!");
            document.login.x_zip.focus();
            return false;
        }       
        if(document.login.x_phone.value == "")
        {
            alert("Please enter your Day Time Phone!");
            document.login.x_phone.focus();
            return false;
        }    
        if(document.login.x_ship_to_first_name.value == "")
        {
            alert("Please Enter Shipping First Name!");
            document.login.x_ship_to_first_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.login.x_ship_to_first_name.value))
        {
            alert("Please enter valid Shipping First name!");
            document.login.x_ship_to_first_name.value = "";
            document.login.x_ship_to_first_name.focus();
            return false;
        }
        if(document.login.x_ship_to_last_name.value == "")
        {
            alert("Please Enter Shipping Last Name!");
            document.login.x_ship_to_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.login.x_ship_to_last_name.value))
        {
            alert("Please enter valid Shipping First name!");
            document.login.x_ship_to_last_name.value = "";
            document.login.x_ship_to_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.login.x_ship_email.value))
        {
            alert("Please enter valid email address!");
            document.login.x_ship_email.value = "";
            document.login.x_ship_email.focus();
            return false;
        }
        if(document.login.x_ship_to_address.value == "")
        {
            alert("Please enter your Shipping Street 1!");
            document.login.x_ship_to_address.focus();
            return false;
        }    
        var str=new String(document.login.x_ship_to_address.value);
        /*if(str.indexOf("P.O.Box")!=-1 || str.indexOf("P.O.BOX")!=-1 || str.indexOf("P.O. BOX")!=-1 
			|| str.indexOf("p.o.box")!=-1 || str.indexOf("PO Box")!=-1 || str.indexOf("PO BOX")!=-1 
			|| str.indexOf("Po Box")!=-1 || str.indexOf("PO box")!=-1 || str.indexOf("po box")!=-1 
			|| str.indexOf("P.O.box")!=-1 || str.indexOf("p.o.Box")!=-1 || str.indexOf("BOX")!=-1)       
        {
            alert("P.O.Box is not allowed in Shipping Street 1!");
            document.login.x_ship_to_address.focus();
            return false;
        }   */    
        if(document.login.x_ship_to_city.value == "")
        {
            alert("Please enter your Shipping City!");
            document.login.x_ship_to_city.focus();
            return false;
        }
        if(document.login.x_ship_to_state.value == "")
        {
            alert("Please enter your Shipping State!");
            document.login.x_ship_to_state.focus();
            return false;
        }
        if(document.login.x_ship_to_zip.value == "")
        {
            alert("Please enter your Shipping Zip Code!");
            document.login.x_ship_to_zip.focus();
            return false;
        }       
        if(document.login.x_ship_to_phone.value == "")
        {
            alert("Please enter your Shipping Day Time Phone!");
            document.login.x_ship_to_phone.focus();
            return false;
        }               
        //        if(document.login.x_ship_to_country.value!="Canada")
                checkavs(document.login.x_ship_to_city.value,document.login.x_ship_to_state.value,document.login.x_ship_to_zip.value);
                
        }
//same as shipping val
  function fillship(form)
  {
    if(form.sameadd.checked != true)
    {
      form.x_ship_to_first_name.value="";
      form.x_ship_to_last_name.value="";      
      form.x_ship_to_address.value="";
      form.x_ship_to_address2.value="";
      form.x_ship_to_city.value="";      
           form.x_ship_email.value="";      
      form.x_ship_to_zip.value="";   
      form.x_ship_to_phone.value="";
      form.shipext.value="";
      form.x_ship_to_phone1.value="";
    }
    else
    {
      form.x_ship_to_first_name.value=form.x_first_name.value;
      form.x_ship_to_last_name.value=form.x_last_name.value;      
      form.x_ship_to_address.value=form.x_address.value;
      form.x_ship_to_address2.value=form.x_address2.value;
           form.x_ship_email.value=form.x_email.value;      
      form.x_ship_to_city.value=form.x_city.value;     
      form.x_ship_to_zip.value=form.x_zip.value;     
      form.x_ship_to_phone.value=form.x_phone.value;
          form.shipext.value=form.extension.value;
      form.x_ship_to_phone1.value=form.x_phone1.value;
      form.x_ship_to_state.value=form.x_state.value;
          form.x_ship_to_country.value=form.x_country.value;     
    }
  }
  function swap()
  {
      document.login.x_phone1.value=document.login.x_phone.value;
  }
function proceed(state,billship,register)
{
        var user=1;
        if(register)
        {
                        if(document.login.new_username.value == "")
                        {
                                alert("Please Enter Email Address as Username!");
                                document.login.new_username.focus();
                                return false;
                        }
                        var str=new String(document.login.new_username.value);
                        var re=/^[\w\-@\.]+$/;
                        if(str.search(re)==-1)
                        {
                                alert("Please do not use invalid character in Email!");
                           document.login.new_username.focus();
                                return false;
                        }               
                        if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.login.new_username.value))
                        {
                                alert("Please enter valid email address!");
                                document.login.new_username.value = "";
                                document.login.new_username.focus();
                                return false;
                        }
                        user=userexist(document.login.new_username.value);                      
                        if(user==1)
                        {
                                document.login.new_username.value;
                                document.login.new_username.focus();
                                return false;
                        }
        }
        else
        {               // document.getElementById("billingshipping").style.display=billship ? "none" : "block";
                //document.getElementById("billingshipping").style.visibility=billship ? "hidden" : "visible";    

				document.getElementById("billingshippingtext").style.display="block";
                document.getElementById("billingshippingtext").style.visibility="visible";

                document.getElementById("loginregister").style.display=state ? "block" : "none";
                document.getElementById("loginregister").style.visibility=state ? "visible" : "hidden";                 

                document.getElementById("passwordtext").style.display="none";
                document.getElementById("passwordtext").style.visibility="hidden";         

                document.getElementById("proceed").style.display="none";
                document.getElementById("proceed").style.visibility="hidden";

				document.getElementById("registration").style.display="block";
                document.getElementById("registration").style.visibility="visible";

				document.getElementById("registration1").style.display="none";
                document.getElementById("registration1").style.visibility="hidden";

                document.getElementById("passworddiv").style.display= state ? "block" : "none";
                document.getElementById("passworddiv").style.visibility=state ? "visible" : "hidden";         
        }

        //document.getElementById("signinbar").className="nav-red";
       // document.getElementById("signintab").className="right-nav-tab";
        //document.getElementById("billtab").className="right-nav-tab-active";
}

function statecombo(country,type)
{
	if(type=="bill")
	{
        if(country=="CA")
        {
                document.getElementById("x_state").options.length=0;
                var canadastates=new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territory","Nova Scotia","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon Territory");
                document.getElementById("x_state").options[0]=new Option("Please Choose","");
                for(var i=0;i<canadastates.length;i++)
                {
					document.getElementById("x_state").options[i+1] = new Option(canadastates[i],canadastates[i]);
                }
        }
        if(country=="US")
        {
                document.getElementById("x_state").options.length=0;
                var canadastates=new Array("AL,Alabama","AK,Alaska","AZ,Arizona","AR,Arkansas","CA,California","CO,Colorado","CT,Connecticut","DE,Delaware","DC,District of Columbia","FL,Florida","GA,Georgia","HI,Hawaii"
                ,"ID,Idaho","IL,Illinois","IN,Indiana","IA,Iowa","KS,Kansas","KY,Kentucky","LA,Louisiana","ME,Maine","MD,Maryland","MA,Massachusetts","MI,Michigan","MN,Minnesota","MS,Mississippi","MO,Missouri","MT,Montana"
                ,"NE,Nebraska","NV,Nevada","NH,New Hampshire","NJ,New Jersey","NM,New Mexico","NY,New York","NC,North Carolina","ND,North Dakota","OH,Ohio","OK,Oklahoma","OR,Oregon","PA,Pennsylvania","RI,Rhode Island"
                ,"SC,South Carolina","SD,South Dakota","TN,Tennessee","TX,Texas","UT,Utah","VT,Vermont","VA,Virginia","WA,Washington","WV,West Virginia","WI,Wisconsin","WY,Wyoming");                
                document.getElementById("x_state").options[0]=new Option("Please Choose","");
                for(var i=0;i<canadastates.length;i++)
                {
                        var stateswithcode=canadastates[i].split(",");                        
                        document.getElementById("x_state").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);
                }
        }
	}
	if(type=="ship")
	{
        if(country=="CA")
        {
                document.getElementById("x_ship_to_state").options.length=0;               
                var canadastates=new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territory","Nova Scotia","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon Territory");
                document.getElementById("x_ship_to_state").options[0]=new Option("Please Choose","");                
                for(var i=0;i<canadastates.length;i++)
					document.getElementById("x_ship_to_state").options[i+1] = new Option(canadastates[i],canadastates[i]);                        
        }
        if(country=="US")
        {
                document.getElementById("x_ship_to_state").options.length=0;               
                var canadastates=new Array("AL,Alabama","AK,Alaska","AZ,Arizona","AR,Arkansas","CA,California","CO,Colorado","CT,Connecticut","DE,Delaware","DC,District of Columbia","FL,Florida","GA,Georgia","HI,Hawaii"
                ,"ID,Idaho","IL,Illinois","IN,Indiana","IA,Iowa","KS,Kansas","KY,Kentucky","LA,Louisiana","ME,Maine","MD,Maryland","MA,Massachusetts","MI,Michigan","MN,Minnesota","MS,Mississippi","MO,Missouri","MT,Montana"
                ,"NE,Nebraska","NV,Nevada","NH,New Hampshire","NJ,New Jersey","NM,New Mexico","NY,New York","NC,North Carolina","ND,North Dakota","OH,Ohio","OK,Oklahoma","OR,Oregon","PA,Pennsylvania","RI,Rhode Island"
                ,"SC,South Carolina","SD,South Dakota","TN,Tennessee","TX,Texas","UT,Utah","VT,Vermont","VA,Virginia","WA,Washington","WV,West Virginia","WI,Wisconsin","WY,Wyoming");
                document.getElementById("x_ship_to_state").options[0]=new Option("Please Choose","");               
                for(var i=0;i<canadastates.length;i++)
                {
					var stateswithcode=canadastates[i].split(",");
                    document.getElementById("x_ship_to_state").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);                        
                }
        }
	}
}
/************************* Validation of sign-in from *************************/

function statecombo1(country)
{
        if(country=="CA")
        {
                document.getElementById("x_state").options.length=0;
                var canadastates=new Array("Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland","Northwest Territory","Nova Scotia","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon Territory");      
                document.getElementById("x_state").options[0]=new Option("Please Choose","");
                for(var i=0;i<canadastates.length;i++)
                {
                        document.getElementById("x_state").options[i+1] = new Option(canadastates[i],canadastates[i]);
                }
        }
        if(country=="US")
        {
                document.getElementById("x_state").options.length=0;
                var canadastates=new Array("AL,Alabama","AK,Alaska","AZ,Arizona","AR,Arkansas","CA,California","CO,Colorado","CT,Connecticut","DE,Delaware","DC,District of Columbia","FL,Florida","GA,Georgia","HI,Hawaii"
                ,"ID,Idaho","IL,Illinois","IN,Indiana","IA,Iowa","KS,Kansas","KY,Kentucky","LA,Louisiana","ME,Maine","MD,Maryland","MA,Massachusetts","MI,Michigan","MN,Minnesota","MS,Mississippi","MO,Missouri","MT,Montana"
                ,"NE,Nebraska","NV,Nevada","NH,New Hampshire","NJ,New Jersey","NM,New Mexico","NY,New York","NC,North Carolina","ND,North Dakota","OH,Ohio","OK,Oklahoma","OR,Oregon","PA,Pennsylvania","RI,Rhode Island"
                ,"SC,South Carolina","SD,South Dakota","TN,Tennessee","TX,Texas","UT,Utah","VT,Vermont","VA,Virginia","WA,Washington","WV,West Virginia","WI,Wisconsin","WY,Wyoming");          
                document.getElementById("x_state").options[0]=new Option("Please Choose","");
                for(var i=0;i<canadastates.length;i++)
                {
                        var stateswithcode=canadastates[i].split(",");                  
                        document.getElementById("x_state").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);
                }
        }
}


/**************** Payment Form   ******/
function changeshiping(shipvalue,subtotal,tax,userid,weighttotal)
{               
        var shipval=shipvalue.split(",");       
        var grandtotal=parseFloat(subtotal)+parseFloat(shipval[1])+parseFloat(tax);
        document.getElementById("shippingvaluetext").innerHTML=shipval[1];      
        document.getElementById("grandtotal").innerHTML=grandtotal.toFixed(2);
        document.getElementById("grandtot").value=grandtotal.toFixed(2);
}


/********************** Checkout Page ****************************/
function checkoutverify()
        {
        if(document.checkout.x_first_name.value == "")
        {
            alert("Please Enter First Name!");
            document.checkout.x_first_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.checkout.x_first_name.value))
        {
            alert("Please enter valid First name!");
            document.checkout.x_first_name.value = "";
            document.checkout.x_first_name.focus();
            return false;
        }
        if(document.checkout.x_last_name.value == "")
        {
            alert("Please Enter Last Name!");
            document.checkout.x_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.checkout.x_last_name.value))
        {
            alert("Please enter valid First name!");
            document.checkout.x_last_name.value = "";
            document.checkout.x_last_name.focus();
            return false;
        }     
        if(document.checkout.x_address.value == "")
        {
            alert("Please enter your Street 1!");
            document.checkout.x_address.focus();
            return false;
        }  
		var str=new String(document.checkout.x_address.value);   
        if(str.indexOf("P.O.Box")!=-1 || str.indexOf("P.O.BOX")!=-1 || str.indexOf("p.o.box")!=-1 || str.indexOf("PO Box")!=-1 || str.indexOf("PO BOX")!=-1 || str.indexOf("Po Box")!=-1 || str.indexOf("PO box")!=-1 || str.indexOf("po box")!=-1 || str.indexOf("P.O.box")!=-1 || str.indexOf("p.o.Box")!=-1)
        {
            alert("P.O.Box is not allowed in address");
            document.checkout.x_address.focus();
            return false;
        }	
        if(document.checkout.x_city.value == "")
        {
            alert("Please enter your City!");
            document.checkout.x_city.focus();
            return false;
        }
        if(document.checkout.x_state.value == "")
        {
            alert("Please enter your State!");
            document.checkout.x_state.focus();
            return false;
        }
        if(document.checkout.x_zip.value == "")
        {
            alert("Please enter your Zip Code!");
            document.checkout.x_zip.focus();
            return false;
        }
        if(document.checkout.x_country.value == "")
        {
            alert("Please Select Country!");
            document.checkout.x_country.focus();
            return false;
        }
        if(document.checkout.x_email.value == "")
        {
            alert("Please enter email address!");
            document.checkout.x_email.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.checkout.x_email.value))
        {
            alert("Please enter valid email address!");
            document.checkout.x_email.value = "";
            document.checkout.x_email.focus();
            return false;
        }
        if(document.checkout.x_phone.value == "")
        {
            alert("Please enter your Day Time Phone!");
            document.checkout.x_phone.focus();
            return false;
        }    
        if(document.checkout.x_ship_to_first_name.value == "")
        {
            alert("Please Enter Shipping First Name!");
            document.checkout.x_ship_to_first_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.checkout.x_ship_to_first_name.value))
        {
            alert("Please enter valid Shipping First name!");
            document.checkout.x_ship_to_first_name.value = "";
            document.checkout.x_ship_to_first_name.focus();
            return false;
        }
        if(document.checkout.x_ship_to_last_name.value == "")
        {
            alert("Please Enter Shipping Last Name!");
            document.checkout.x_ship_to_last_name.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.checkout.x_ship_to_last_name.value))
        {
            alert("Please enter valid Shipping First name!");
            document.checkout.x_ship_to_last_name.value = "";
            document.checkout.x_ship_to_last_name.focus();
            return false;
        }   
        if(document.checkout.x_ship_to_address.value == "")
        {
            alert("Please enter your Shipping Street 1!");
            document.checkout.x_ship_to_address.focus();
            return false;
        }
        /*if(!new RegExp(/^PO\sBox$/).test(document.checkout.x_ship_to_address.value))
        {
            alert("PO Box is not allowed in address!");
            document.checkout.x_ship_to_address.focus();
            return false;
        }*/
        if(document.checkout.x_ship_to_city.value == "")
        {
            alert("Please enter your Shipping City!");
            document.checkout.x_ship_to_city.focus();
            return false;
        }
        if(document.checkout.x_ship_to_state.value == "")
        {
            alert("Please enter your Shipping State!");
            document.checkout.x_ship_to_state.focus();
            return false;
        }
        if(document.checkout.x_ship_to_zip.value == "")
        {
            alert("Please enter your Shipping Zip Code!");
            document.checkout.x_ship_to_zip.focus();
            return false;
        }	

        if(document.checkout.x_ship_to_country.value == "")
        {
            alert("Please Select Shipping Country!");
            document.checkout.x_ship_to_country.focus();
            return false;
        }
        if(document.checkout.x_ship_email.value == "")
        {
            alert("Please enter email Shipping address!");
            document.checkout.x_ship_email.focus();
            return false;
        }
        if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.checkout.x_ship_email.value))
        {
            alert("Please enter valid Shipping email address!");
            document.checkout.x_ship_email.value = "";
            document.checkout.x_ship_email.focus();
            return false;
        }
        if(document.checkout.x_ship_to_phone.value == "")
        {
            alert("Please enter your Shipping Day Time Phone!");
            document.checkout.x_ship_to_phone.focus();
            return false;
        } 
	
		/*document.checkout.action="login.php?update=1&<?php echo $_SERVER['QUERY_STRING']?>";
		document.checkout.submit();	*/
		updatecheckavs(document.checkout.x_ship_to_city.value,document.checkout.x_ship_to_state.value,document.checkout.x_ship_to_zip.value);			
        }

//same as shipping val
  function checkoutfillship(form)
  {
    if(form.sameadd.checked != true)
    {
      form.x_ship_to_first_name.value="";
      form.x_ship_to_last_name.value="";	 
      form.x_ship_to_company.value="";
      form.x_ship_to_address.value="";
      form.x_ship_to_address2.value="";
      form.x_ship_to_city.value="";      
      form.x_ship_to_zip.value="";   
      form.x_ship_email.value="";
      form.x_ship_to_phone.value="";
      form.x_ship_to_phone1.value="";
      form.x_ship_to_fax.value="";
    }
    else
    {
      form.x_ship_to_first_name.value=form.x_first_name.value;	 
      form.x_ship_to_last_name.value=form.x_last_name.value;
      form.x_ship_to_company.value=form.x_company.value;
      form.x_ship_to_address.value=form.x_address.value;
      form.x_ship_to_address2.value=form.x_address2.value;
      form.x_ship_to_city.value=form.x_city.value;     
      form.x_ship_to_zip.value=form.x_zip.value;     
      form.x_ship_email.value=form.x_email.value;
      form.x_ship_to_phone.value=form.x_phone.value;
      form.x_ship_to_phone1.value=form.x_phone1.value;
      form.x_ship_to_fax.value=form.x_fax.value;     

      if(form.x_ship_to_state[form.x_ship_to_state.selectedIndex].value=="Outside USA")
      {
        form.x_ship_to_state.value=form.x_state.value;
      }
      form.x_ship_to_state[form.x_ship_to_state.selectedIndex].value=form.x_state[form.x_state.selectedIndex].value;
      form.x_ship_to_state[form.x_ship_to_state.selectedIndex].text=form.x_state[form.x_state.selectedIndex].text;


      if(form.x_ship_to_country[form.x_ship_to_country.selectedIndex].value=="Outside USA")
      {
        form.x_ship_to_country.value=form.x_country.value;
      }
      form.x_ship_to_country[form.x_ship_to_country.selectedIndex].value=form.x_country[form.x_country.selectedIndex].value;
      form.x_ship_to_country[form.x_ship_to_country.selectedIndex].text=form.x_country[form.x_country.selectedIndex].text;


    }
  }
  function swap()
  {
      document.checkout.x_phone1.value=document.checkout.x_phone.value;
  }

function editdata()
{
	document.payment.action="checkout.php";
	document.payment.submit();
}