/************************* Validation of sign-in from *************************/
function verify1()
{
        if(document.registerform.loginusername.value == "")
        {
            alert("Please Enter Login ID!");
            document.registerform.loginusername.focus();
            return false;
        }
		/*if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.registerform.loginusername.value))
		{
			alert("Login name should be email address!");
			document.registerform.loginusername.focus();
			return false;
		}*/
        if(document.registerform.loginpassword.value == "")
        {
            alert("Please Enter Password!");
            document.registerform.loginpassword.focus();
            return false;
        }
}
function verify()
{

		if(document.registerform.username.value == "")
        {
            alert("Please Enter Login Email ID!");
            document.registerform.username.focus();
            return false;
        }    
		/*var lowercasepass=document.registerform.username.value;
		var Uppercasepass=document.registerform.username.value;	
		if(document.registerform.username.value!=lowercasepass.toLowerCase() && document.registerform.username.value!=Uppercasepass.toUpperCase())
		{
			alert("Please use ONLY Lower Case OR ONLY Upper Case Letters");
			document.registerform.username.focus();			
			return false;
		}*/
		if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.registerform.username.value))
		{
			alert("Login name should be email address!");
			document.registerform.username.focus();
			return false;
		}

		var	email = document.registerform.username.value;
		var x = xmlHttp_send_post("xmlHTTP_BE.php", "action=canUseEmail&email="+email);
		if(x != 1){
			alert("You can not use this email id as your Login Email ID.. \nPlease use different Email ID..");
			document.registerform.username.value="";
			document.registerform.email.value="";
			document.registerform.confirmpass.value="";
			document.registerform.username.focus();
			return false;
		}

		
/*      
		if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.registerform.email.value))
        {
            alert("Please enter valid email address!");
            document.registerform.username.value = "";
            document.registerform.username.focus();
            return false;
        }
*/
		if(document.registerform.email.value!=document.registerform.cemail.value)
        {
            alert("Please check your Confirmed Email, as it is Not the Same as the original Email!");
            document.registerform.cemail.value = "";
            document.registerform.cemail.focus();
            return false;
        }

        if(document.registerform.password.value == "")
        {
            alert("Please Enter Password!");
            document.registerform.password.focus();
            return false;
        }
		var lowercasepass=document.registerform.password.value;
		var Uppercasepass=document.registerform.password.value;	
		if(document.registerform.password.value!=lowercasepass.toLowerCase() && document.registerform.password.value!=Uppercasepass.toUpperCase())
		{
			alert("Password is case-sensitive");
			document.registerform.password.focus();			
			return false;
		}
        if(!new RegExp(/^\w[\w\.\-]+$/).test(document.registerform.password.value))
        {
			alert("Please enter valid Password!");
            document.registerform.password.value = "";
            document.registerform.password.focus();
            return false;
        }
        if(document.registerform.confirmpass.value != document.registerform.password.value)
        {
			alert("Confirm Password is not same as Password!");
            document.registerform.confirmpass.focus();
            return false;
        }                               
        if(document.registerform.firstname.value == "")
        {
            alert("Please Enter First Name!");
            document.registerform.firstname.focus();
            return false;
        }
		if(!CheckName(document.registerform.firstname, "First Name")) return false;
/*
		if(document.registerform.country.selectedIndex == "0")
        {
            alert("Please Select your contry!");
            return false;
        }


		if((document.getElementById("shipotherstate").style.display=="none") && (document.registerform.state.selectedIndex == "0"))
        {
            alert("Please Select your state!");
            return false;
        }

		if((document.getElementById("shipotherstate1").style.display=="none") && (document.registerform.otherstate.value == ""))
        {
            alert("Please enter your state!");
            return false;
        }
*/
		
		/*if(document.registerform.lastname.value == "")
        {
            alert("Please Enter Last Name!");
            document.registerform.lastname.focus();
            return false;
        }*/


       /* if(!new RegExp(/^\w[\w\.\-]+$/).test(document.registerform.name.value))
        {
            alert("Please enter valid First name!");
            document.registerform.name.value = "";
            document.registerform.name.focus();
            return false;
        }     */
		
		if(document.registerform.referalcode.value!="")
        {
			var arr = document.registerform.referalcode.value.split("?");
			var reference_code = arr[parseInt(arr.length) -1];
			var value=xmlHttp_send_post("getprice.php", "action=check_referral_code&ref_code="+reference_code);
            if (value == "Invalid")
            {
				alert("Please enter a valid referral code if you have!");
				document.registerform.referalcode.value = "";
				document.registerform.referalcode.focus();
				return false;
            }
        }

        /*if(document.registerform.address.value == "")
        {
            alert("Please enter your Street 1!");
            document.registerform.address.focus();
            return false;
        }                       
        if(document.registerform.city.value == "")
        {
            alert("Please enter your City!");
            document.registerform.city.focus();
            return false;
        }
        if(document.registerform.state.value == "")
        {
            alert("Please enter your State!");
            document.registerform.state.focus();
            return false;
        }
        if(document.registerform.zip.value == "")
        {
            alert("Please enter your Zip Code!");
            document.registerform.zip.focus();
            return false;
        }       
        if(document.registerform.phone.value == "")
        {
            alert("Please enter Phone!");
            document.registerform.phone.focus();
            return false;
        }  
		if(document.registerform.country.value == "")
        {
            alert("Please enter Country!");
            document.registerform.country.focus();
            return false;
        }  */
		 if(document.registerform.number.value == "")
        {
            alert("Please Enter captcha number!");
            document.registerform.number.focus();
            return false;
        }    
		if(document.registerform.terms.checked == false)
		{
			alert("Please select terms and conditions!");
            document.registerform.terms.focus();
            return false;
		}

		document.registerform.actiontype.value="register";
		document.registerform.submit();
}

function billshipverify()
{
	 if(document.billship.billfirstname.value == "")
     {
		alert("Please enter billing first name!");
        document.billship.billfirstname.focus();
        return false;
     }
	 if(document.billship.billlastname.value == "")
     {
		alert("Please enter billing last name!");
        document.billship.billlastname.focus();
        return false;
     }
	 if(document.billship.billaddr1.value == "")
     {
		alert("Please enter billing address1!");
        document.billship.billaddr1.focus();
        return false;
     }	 
	 if(document.billship.billemail.value == "")
     {
		alert("Please enter billing email!");
        document.billship.billemail.focus();
        return false;
     }
	 if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.billship.billemail.value))
     {
		alert("Please enter valid email address!");
        document.billship.billemail.value = "";
        document.billship.billemail.focus();
        return false;
     }
	 if(document.billship.billemail.value != document.billship.cbillemail.value)
     {
		alert("Please check your Confirmed Email, as it is Not the Same as the original Email!");
        document.billship.cbillemail.focus();
        return false;
     }
	 if(document.billship.billphone.value == "")
     {
		alert("Please enter billing phone!");
        document.billship.billphone.focus();
        return false;
     }
	 if(document.billship.billcity.value == "")
     {
		alert("Please enter billing city!");
        document.billship.billcity.focus();
        return false;
     }
	 /*if((document.getElementById("billotherstate").style.display != 'none') && (document.billship.billstatetext.value == ""))
     {
		alert("Please enter billing state!");
        document.billship.billstatetext.focus();
        return false;
     }*/ 
	 if((document.getElementById("billotherstate").style.display == 'none') && (document.billship.billstate.value == ""))
     {
		alert("Please enter billing state!");
        document.billship.billstate.focus();
        return false;
     }
	 if(document.billship.billzip.value == "")
     {
		alert("Please enter billing zip!");
        document.billship.billzip.focus();
        return false;
     }	 
	 
	 /******* Shipping ****************/
	 if(document.billship.shipfirstname.value == "")
     {
		alert("Please enter shipping first name!");
        document.billship.shipfirstname.focus();
        return false;
     }
	  if(document.billship.shiplastname.value == "")
     {
		alert("Please enter shipping last name!");
        document.billship.shiplastname.focus();
        return false;
     }
	 if(document.billship.shipaddr1.value == "")
     {
		alert("Please enter shipping address1!");
        document.billship.shipaddr1.focus();
        return false;
     }	 
	 if(document.billship.shipemail.value == "")
     {
		alert("Please enter shipping email!");
        document.billship.shipemail.focus();
        return false;
     }
	 if(!new RegExp(/^\w[\w\-\.]+\@\w[\w\-]+(\.\w[\w\-]+)+$/).test(document.billship.shipemail.value))
     {
		alert("Please enter valid email address!");
        document.billship.shipemail.value = "";
        document.billship.shipemail.focus();
        return false;
     }
	  if(document.billship.shipemail.value != document.billship.cshipemail.value)
     {
		alert("Please check your Confirmed Email, as it is Not the Same as the original Email!");
        document.billship.cshipemail.focus();
        return false;
     }
	 if(document.billship.shipphone.value == "")
     {
		alert("Please enter shipping phone!");
        document.billship.shipphone.focus();
        return false;
     }
	 if(document.billship.shipcity.value == "")
     {
		alert("Please enter shipping city!");
        document.billship.shipcity.focus();
        return false;
     }
	 if((document.getElementById("shipotherstate").style.display != 'none') && (document.billship.shipstatetext.value == ""))
     {
		alert("Please enter shipping state!");
        document.billship.shipstatetext.focus();
        return false;
     }
	 if((document.getElementById("shipotherstate").style.display == 'none') && (document.billship.shipstate.value == ""))
     {
		alert("Please enter shipping state!");
        document.billship.shipstate.focus();
        return false;
     }
	 if(document.billship.shipzip.value == "")
     {
		alert("Please enter shipping zip!");
        document.billship.shipzip.focus();
        return false;
     }

	 if(document.billship.print_company.value == "" || document.billship.print_company.value == "0")
     {
		alert("Please select Printing Company!");
        return false;
     }
	 
	 return validAddress4Company();
}

function changetab(type)
{
	if (type==1)
	{
		document.getElementById("registertab").style.display="block";
		document.getElementById("logintab").style.display="none";
		document.registerform.username.focus();
	}
	else
	{
		document.getElementById("logintab").style.display="block";
		document.getElementById("registertab").style.display="none";
	}
}
function deleteartwork1(front,back,artwork_no){
	window.open("deletefile.php?ARTWORK_DIR="+back+"&artwork="+artwork_no);
	//location.href="deletefile.php?file="+front+"artwork="+artwork_no;
}

function Artwork_Remove(front,back,artwork_no){
	var ret = xmlHttp_send_post("xmlHTTP_BE.php","&ARTWORK_DIR="+back+"&artwork="+artwork_no);
	//prompt("R",ret);
	if(ret=="V")
		window.location.href=window.location.href;
	//location.href="deletefile.php?file="+front+"artwork="+artwork_no;
}


function download(front,back){
	window.open("download.php?image="+back);
	window.open("download.php?image="+front);
}
function details(artworkid)
{
	document.acountform.artworkid.value=artworkid;
	document.acountform.action="artwork-detail.php";
	document.acountform.submit();
}
function changeprice()
{
	var value=xmlHttp_send_post("getprice.php", "paper="+document.artworkdetail.paper.value+"&quantity="+document.artworkdetail.qunatity.value);
	values=value.split(",");
	document.artworkdetail.actualprice.value=values[0];
	document.artworkdetail.weight.value=values[1];
	document.getElementById("pricespan").innerHTML="$"+values[0];
}

function addtocart()
{

	if(isPriceSet != "FINISH"){ alert(isPriceSet);return;}


	if(document.artworkdetail.print_company.value == "0"){
		alert("Please select Printing company..");
		return;
	}

	if(document.artworkdetail.chkartwork.checked == false)
     {
		alert("You must first place a check mark ( v ) in the “I have Verified this Artwork”. \nPlease carefully look over your file as this is exactly how it will print out \nwith our printer, less the Water Marks of course. So this is your approval \nof the Artwork.");
        return false;
     }



	document.artworkdetail.action="class.frontside.php";
	document.artworkdetail.submit();	
}

function editaddress()
{
	location.href="billing-shipping.php";
}


function updatecart(artworkid)
{
	document.viewcart.artworkid.value=artworkid;
	document.viewcart.action="artwork-detail.php?updatecart=yes";
	document.viewcart.submit();
}
function removecart()
{
	flag=0;
             
    for (i=0;i<document.viewcart.elements.length;i++)
    {
		if(document.viewcart.elements[i].type=="checkbox")
        {
			if(document.viewcart.elements[i].checked)
				flag=1;
        }
	}  
           
    if(flag!=1)
    {
		alert("Select Appropriate checkbox");
        return false;
    }   
	document.viewcart.action="class.frontside.php?remove=yes";
	document.viewcart.submit();
}

function shippingvalues()
{
	if(document.billship.same.checked==true)
	{
		document.billship.shipfirstname.value=document.billship.billfirstname.value;
		document.billship.shiplastname.value=document.billship.billlastname.value;
		document.billship.shipaddr1.value=document.billship.billaddr1.value;
		document.billship.shipaddr2.value=document.billship.billaddr2.value;
		document.billship.shipemail.value=document.billship.billemail.value;
		document.billship.cshipemail.value=document.billship.cbillemail.value;
		document.billship.shipphone.value=document.billship.billphone.value;
		document.billship.shipcity.value=document.billship.billcity.value;
		document.billship.shipzip.value=document.billship.billzip.value;
		document.billship.shipstatetext.value=document.billship.billstatetext.value;
		//document.billship.shipcountry.value=document.billship.billcountry.value;
		for (i=0;i<document.billship.shipcountry.options.length;i++)
				if (i == document.billship.billcountry.selectedIndex)
					document.billship.shipcountry.options[i].selected = true;
		//document.billship.shipstate.value=document.billship.billstate.value;

		statecombo(document.billship.shipcountry.value,'ship');
		for (i=0;i<document.billship.shipstate.options.length;i++)
				if (i == document.billship.billstate.selectedIndex)
					document.billship.shipstate.options[i].selected = true;
		//document.getElementById("shipotherstate1").style.display = document.getElementById("billotherstate1").style.display;
		//document.getElementById("shipotherstate").style.display = document.getElementById("billotherstate").style.display;

	}
	else
	{
		document.billship.shipfirstname.value="";
		document.billship.shiplastname.value="";
		document.billship.shipaddr1.value="";
		document.billship.shipaddr2.value="";
		document.billship.shipemail.value="";
		document.billship.cshipemail.value="";
		document.billship.shipphone.value="";
		document.billship.shipcity.value="";
		document.billship.shipzip.value="";
		//document.billship.shipstate.options[0].selected = true;
		//document.billship.shipcountry.options[0].selected = true;
	}
}

function updatevalues(subtotal)
{
	shippingdetails=document.payment.shippingvalue.value.split(",");	
	grandtotal=parseFloat(subtotal)-parseFloat(document.payment.coupon.value)+parseFloat(document.payment.tax.value)+parseFloat(shippingdetails[1]);
	document.payment.grandtotal.value=grandtotal.toFixed(2);
	/*if (document.payment.rushfee.checked==true)
	{
		grandtotal=parseFloat(grandtotal)+parseFloat(document.payment.rushfee.value);
		document.getElementById("rushfeeid").innerHTML="$"+document.payment.rushfee.value;
	}	
	else
		document.getElementById("rushfeeid").innerHTML="";
	*/
	grandtotal=parseFloat(grandtotal);
	//alert(parseFloat(document.payment.coupon.value))
	if (document.payment.graphicsfee.value>0)
		grandtotal=parseFloat(grandtotal)+parseFloat(document.payment.graphicsfee.value);

	document.getElementById("shippingspan").innerHTML=parseFloat(shippingdetails[1]).toFixed(2);
	document.getElementById("grandtotalid").innerHTML=grandtotal.toFixed(2);
	document.getElementById("grandtotal").value=grandtotal.toFixed(2);
}

function couponcalculation()
{
	if(document.payment.couponcode.value == "")
    {
		alert("Please enter coupon code!");
        document.billship.couponcode.focus();
        return false;
    }	
	var value=xmlHttp_send_post("lib/couponvalue.php", "applied=true&couponcode="+document.payment.couponcode.value);
	if((value.search("Invalid")!= -1) || (value.search("Used")!= -1) || (value.search("Offer")!= -1))
        {
                if(value.search("Invalid")!= -1)
                {
                        var usedcoupon=value.split(",");
						alert("Invalid " + usedcoupon[1] + " Coupon Code");
                       // document.getElementById("couponerror").innerHTML='<b>Invalid ' + usedcoupon[1] + ' Coupon Code</b>';                     
                        return false;
                }
                if(value.search("Used")!= -1)
                {
                        var usedcoupon=value.split(",");
						alert("You have already used " + usedcoupon[1] + " Coupon Code");
                        //document.getElementById("couponerror").innerHTML='<b>You have already used ' + usedcoupon[1] + ' Coupon Code';                       
                        return false;
                }
                if(value.search("Offer")!= -1)
                {
                        var usedcoupon=value.split(",");
						alert("Validity of " + usedcoupon[1] + " Coupon code is finished.");
                        //document.getElementById("couponerror").innerHTML='<b>Validity of ' + usedcoupon[1] + ' Coupon code is finished.</b>';                    
                        return false;
                }
        }
        else
        {  
                document.getElementById("coponcodes").innerHTML='<b> Coupon Value </b>';      
				var grshipvalue=document.getElementById("shippingvalue").value.split(",");
				var tax=document.getElementById("tax").value;






				if(document.getElementById("designercharge").value!="")
					designercharge=document.getElementById("designercharge").value;
				else
					designercharge=0.00;			
				
				/*if(document.getElementById("rushfee").checked==true)
					rushfeevalue=35.00;
				else*/
					rushfeevalue=0.00;
				if(parseFloat(value)>document.getElementById("subtot").value)
					var subtotal=0.00;
                else
					var subtotal=document.getElementById("subtot").value-parseFloat(value);


				/* Tax Calculation modified on 3/24/2009 by Yogesh*/
				if (document.getElementById("tax_apply").value=="yes")
				{
					var tax_rate = document.getElementById("tax_rate").value;
					tax = parseFloat((subtotal * tax_rate)/100);
					tax = tax.toFixed(2);
					document.getElementById("tax").value=tax;
					document.getElementById("tax_val").innerHTML="$"+tax;
				}

				document.getElementById("disp_sub_tot").innerHTML = "$"+parseFloat(subtotal).toFixed(2);

				grandtotal=parseFloat(subtotal)+parseFloat(grshipvalue[1])+parseFloat(tax)+parseFloat(designercharge);
							   	//	+parseFloat(rushfeevalue)		//		alert(grandtotal);
				document.getElementById("grandtotalid").innerHTML=grandtotal.toFixed(2);
				document.getElementById("grandtotal").value=grandtotal.toFixed(2);    
				document.getElementById("couponid").innerHTML="- $"+ parseFloat(value).toFixed(2);
                document.getElementById("coupon").value=parseFloat(value);
		}          	
				
}

function statecombo(country,type)
{
	if(type=="bill")
	{
        if(country=="CA")
        {
				document.getElementById("billotherstate1").style.display="block";
				document.getElementById("billotherstate").style.display="none";
				//document.getElementById("shipotherstate1").style.display="block";
				//document.getElementById("shipotherstate").style.display="none";
                //document.getElementById("x_ship_to_state").options.length=0;
                document.getElementById("billstate").options.length=0;
                var canadastates=new Array("AB,Alberta","BC,British Columbia","MB,Manitoba","NB,New Brunswick","NL,Newfoundland","NT,Northwest Territory","NS,Nova Scotia","ON,Ontario","PE,Prince Edward Island","QC,Quebec","SK,Saskatchewan","YT,Yukon Territory");
                //document.getElementById("x_ship_to_state").options[0]=new Option("Please Choose","");
                document.getElementById("billstate").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]);
						var castateswithcode=canadastates[i].split(",");
                        document.getElementById("billstate").options[i+1] = new Option(castateswithcode[1],castateswithcode[0]);
                }
        }
		else
        if(country=="US")
        {
				document.getElementById("billotherstate1").style.display="block";
				document.getElementById("billotherstate").style.display="none";
				//document.getElementById("shipotherstate1").style.display="block";
				//document.getElementById("shipotherstate").style.display="none";
                //document.getElementById("x_ship_to_state").options.length=0;
                document.getElementById("billstate").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","");
                document.getElementById("billstate").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]);
                        document.getElementById("billstate").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);
                }
        }
		else
		{
			document.getElementById("billotherstate1").style.display="none";
			document.getElementById("billotherstate").style.display="block";
			//document.getElementById("shipotherstate1").style.display="none";
			//ocument.getElementById("shipotherstate").style.display="block";
		}
	}
	if(type=="ship")
	{
        if(country=="CA")
        {
				document.getElementById("shipotherstate1").style.display="block";
				document.getElementById("shipotherstate").style.display="none";
                document.getElementById("shipstate").options.length=0;               
                var canadastates=new Array("AB,Alberta","BC,British Columbia","MB,Manitoba","NB,New Brunswick","NL,Newfoundland","NT,Northwest Territory","NS,Nova Scotia","ON,Ontario","PE,Prince Edward Island","QC,Quebec","SK,Saskatchewan","YT,Yukon Territory");
                document.getElementById("shipstate").options[0]=new Option("Please Choose","");                
                for(var i=0;i<canadastates.length;i++)
				{
					var castateswithcode=canadastates[i].split(",");
					document.getElementById("shipstate").options[i+1] = new Option(castateswithcode[1],castateswithcode[0]);                        
				}
        }
		else
        if(country=="US")
        {
				document.getElementById("shipotherstate1").style.display="block";
				document.getElementById("shipotherstate").style.display="none";
                document.getElementById("shipstate").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("shipstate").options[0]=new Option("Please Choose","");               
                for(var i=0;i<canadastates.length;i++)
                {
					var stateswithcode=canadastates[i].split(",");
                    document.getElementById("shipstate").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);                        
                }
        }
		else
		{
			document.getElementById("shipotherstate1").style.display="none";
			document.getElementById("shipotherstate").style.display="block";
		}
	}
	if(type=="register")
	{
        if(country=="CA")
        {
				document.getElementById("shipotherstate1").style.display="block";
				document.getElementById("shipotherstate").style.display="none";
                //document.getElementById("x_ship_to_state").options.length=0;
                document.getElementById("state").options.length=0;
                var canadastates=new Array("AB,Alberta","BC,British Columbia","MB,Manitoba","NB,New Brunswick","NL,Newfoundland","NT,Northwest Territory","NS,Nova Scotia","ON,Ontario","PE,Prince Edward Island","QC,Quebec","SK,Saskatchewan","YT,Yukon Territory");
                //document.getElementById("x_ship_to_state").options[0]=new Option("Please Choose","");
                document.getElementById("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]);
						var castateswithcode=canadastates[i].split(",");
                        document.getElementById("state").options[i+1] = new Option(castateswithcode[1],castateswithcode[0]);
                }
        }
		else
        if(country=="US")
        {
				document.getElementById("shipotherstate1").style.display="block";
				document.getElementById("shipotherstate").style.display="none";
                //document.getElementById("x_ship_to_state").options.length=0;
                document.getElementById("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","");
                document.getElementById("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]);
                        document.getElementById("state").options[i+1] = new Option(stateswithcode[1],stateswithcode[0]);
                }
        }
		else
		{
			document.getElementById("shipotherstate").style.display="block";
			document.getElementById("shipotherstate1").style.display="none";
		}
	}
}


function getQuantity(){
	var reply=xmlHttp_send_post("getprice.php", "&action=getPaperQuantity&paper="+document.artworkdetail.paper.value);
	document.artworkdetail.qunatity.options.length=0;
	var quantities = reply.split("|");
	for (var i=0;i<quantities.length;i++)
	{
		document.artworkdetail.qunatity.options[i] = new Option(quantities[i],quantities[i]);
	}	
	changeprice();
}

function validAddress4Company(){
	var ship_country = document.billship.shipcountry.value;
	var print_country = document.billship.print_country.value;
	//prompt("R",ship_country+"="+print_country);return false;
	if((ship_country == "US" && print_country =="CA") || (ship_country == "CA" && print_country =="US") || (ship_country == print_country)) 
		return true;
	else{
		alert("You can not ship in the country other than the country of Printing Company you have selected");
		return false;
	}
}

function previewArtwork(target_dir){
	window.open("Editor/preview_artwork.php?artwork="+target_dir, 'Artwork', 'toolbar=0,scrollbars=1,width=' + (screen.width).toString()+',height=' + (screen.height).toString()+',location=0,statusbar=0,menubar=0,resizable=0,left=0,top=0,type=fullWindow,scrollbars=yes');
}


function new_Artwork(){
	var x = xmlHttp_send_post("Editor/translate.php", "action=NEW_ARTWORK");
		if(x==1){window.location.href="Editor/Card-Design.php";}
}



function getPrintCompanies(country){
	document.getElementById("company_list").options.length=0;
	document.getElementById("paper_list").options.length=0;
	document.getElementById("quantity_list").options.length=0;
	document.getElementById("paper_list").options[0]=new Option("{Select Paper Type}","0");
	document.getElementById("quantity_list").options[0]=new Option("{Select Quantity}","0");
	document.getElementById("pricespan").innerHTML="{Select paper/quantity below}";
	document.getElementById('print_country').value=country;
	if (country == "0"){
		document.getElementById("company_list").options[0]=new Option("{Select Printing Company}","0");
		return;
	}
	var reply=xmlHttp_send_post("xmlHTTP_BE.php", "action=getPrintCompanies&country="+country);
	//prompt("R",reply);
	document.getElementById("company_list").options[0]=new Option("{Select Printing Company}","0");
	var companies = reply.split("|");
	for (var i=0;i<companies.length;i++)
	{
		var details = companies[i].split("~");
		document.getElementById("company_list").options[i+1] = new Option(details[1]+" ("+details[2]+") ",details[0]);
	}

	isPriceSet = "Please select the printing company to proceed .. ";
}


function getPaperTypes(company){
	document.getElementById("paper_list").options.length=0;
	document.getElementById("quantity_list").options.length=0;
	document.getElementById("quantity_list").options[0]=new Option("{Select Quantity}","0");
	document.getElementById("pricespan").innerHTML="{Select paper/quantity below}";

	var country = document.getElementById('print_country').value;
	if (company == "0"){
		document.getElementById("paper_list").options[0]=new Option("{Select Paper Type}","0");
		return;
	}
	var reply=xmlHttp_send_post("xmlHTTP_BE.php", "action=getPaperTypes&company="+company);
	document.getElementById("paper_list").options[0]=new Option("{Select Paper Type}","0");
	var papers = reply.split("|");
	for (var i=0;i<papers.length;i++)
	{
		var details = papers[i].split("~");
		document.getElementById("paper_list").options[i+1] = new Option(details[1],details[1]);
	}

	isPriceSet = "Please select the paper type to proceed .. ";

}


function getCardQuantity(paper){
	document.getElementById("quantity_list").options.length=0;
	document.getElementById("pricespan").innerHTML="{Select paper/quantity below}";
	var country = document.getElementById('print_country').value;
	var company = document.getElementById('print_company').value;
	if (company == "0"){
		document.getElementById("quantity_list").options[0]=new Option("{Select Quantity}","0");
		return;
	}
	var reply=xmlHttp_send_post("xmlHTTP_BE.php", "action=getCardQuantity&company="+company+"&paper="+paper);
	document.getElementById("quantity_list").options[0]=new Option("{Select Quantity}","0");
	var quantities = reply.split("|");
	for (var i=0;i<quantities.length;i++)
	{
		var details = quantities[i].split("~");
		document.getElementById("quantity_list").options[i+1] = new Option(details[1],details[1]);
	}

	isPriceSet = "Please select the card quantity to proceed .. ";

}


function getPriceWeight(){
	objForm=document.artworkdetail;
	var country_id = objForm.country.value;
	var company_id = objForm.company.value;
	var paper = objForm.paper.value;
	var quantity = objForm.qunatity.value;
	var reply=xmlHttp_send_post("xmlHTTP_BE.php", "action=getPriceWeight&company="+company_id+"&paper="+paper+"&quantity="+quantity);
	var details = reply.split("|");
	document.artworkdetail.actualprice.value=details[0];
	document.artworkdetail.weight.value=details[1];
	document.getElementById("pricespan").innerHTML="$"+details[0];
	document.getElementById("pricespan").style.color="black";
	isPriceSet = "FINISH";
}




function applyPromotionalCode(){
	objForm=document.artworkdetail;
	var promo_code = objForm.promo_code.value;
	var reply=xmlHttp_send_post("xmlHTTP_BE.php", "action=applyPromotionalCode&promo_code="+promo_code);
	var chk = reply.split("!");
	if (chk[0] == "V")
	{
	document.artworkdetail.action = "artwork-detail.php";	
	document.artworkdetail.submit();	

	}else 
		alert(chk[1]);
}


function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode;
	 if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 96 || charCode > 105) && charCode != 37 && charCode != 39)
		return false;
 return true;
}


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function CheckName(cntrl,display)
{
	cntrl.value = cntrl.value.replace(/ /g,"-");
	if(!RegExp(/^[a-zA-Z]+([\w\-]*[a-zA-Z0-9])*$/).test(cntrl.value))
	{
		alert("Please enter alphanumeric value for "+display+"!");
		cntrl.focus();
		return false;
	}
	else
	{
		return true;
	}
}