function UPSpick(thecost,themethod)
{	
			upsmethod=themethod;
			upscost=thecost;
			document.checkout.ups_method.value=(upsmethod);
			document.checkout.ups_cost.value=(upscost);
			

			xship=(document.checkout.ups_cost.value*100);
			xextra=(document.checkout.xExtraSubTotalx.value*100);
			xtotal=((document.checkout.xTotalx.value)*100);
			xtotal=xtotal+xship;
			xthis=(0.00*100)
			document.checkout.ship.value="$"+(price_format((xship+xthis)/100));
			document.checkout.xshipx.value=(price_format((xship+xthis)/100));

			document.checkout.totalcharge.value="$"+(price_format((xtotal+xthis+xextra)/100));
			alert("Your shipping has been recalculated!");
}


function miniPop(url)
{
sealWin=window.open
(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=420,height=500');
self.name = "mainWin"; 
}

function validateForm(form)
{
// Check that required fields are not left blank

	 if (form.card_number.value == "")
	  {
        alert("Please enter a valid credit card number.");
		form.card_number.focus();
        form.card_number.select();
        return false;
      }
	 else if (form.cardname.value == "")
	  {
        alert("Please enter a valid card holders name.");
		form.cardname.focus();
        form.cardname.select();
        return false;
      }
	 else if (form.cardphone.value == "")
	  {
        alert("Please enter a valid card holders telephone number.");
		form.cardphone.focus();
        form.cardphone.select();
        return false;
      }
	 else if (form.cardemail.value == "")
	  {
        alert("Please enter a valid card holders email address.");
		form.cardemail.focus();
        form.cardemail.select();
        return false;
      }            
        return true;

}      

function writeTax()
{	
			document.write("<table>");
			document.write("<input type=text name=tax size=10 value=0 DISABLED READONLY > ");
			document.write("</table>");
}

function writeTotal()
{	
			document.write("<table>");
			document.write("<input type=text name=total size=10 value="+document.checkout.SubTotal.value+" DISABLED READONLY > ");
			document.write("</table>");
}


function writeTotalCharge()
{	
			xtotal=(document.checkout.xTotalx.value*100)
			xship=(document.checkout.xshipx.value*100)
			xextra=(document.checkout.xExtraSubTotalx.value*100)

			document.write("<table>");
			document.write("<input type=text name=totalcharge size=10 value="+"$"+(price_format((xtotal+xship+xextra)/100))+" DISABLED READONLY > ");
			document.write("</table>");
}

function TaxYes()
{	
	 if (document.checkout.xTaxx.value == "0")
		{

			xxtotal=(document.checkout.xTotalx.value*100)
			xxship=(document.checkout.xshipx.value*100)
			xxextra=(document.checkout.xExtraSubTotalx.value*100)
			xxtaxable=((xxtotal-xxship)/100)
			xxtaxable=((xxtotal)/100)
			xxtaxable=((xxtotal+xxship)/100)

			xtax=((document.checkout.xTotalx.value*8.25)/100)

			xtax=(document.checkout.Tax_Rate.value)

			xtax=((xxtaxable*xtax)/100)

			document.checkout.xTaxx.value=(price_format(xtax))
			document.checkout.tax.value="$"+(price_format(xtax))
			xtax=(document.checkout.xTaxx.value*100)
			xtotal=(document.checkout.xTotalx.value*100)

			document.checkout.total.value="$"+(price_format((xxtotal+xtax)/100));
			document.checkout.xTotalx.value=(price_format((xxtotal+xtax)/100));

			document.checkout.totalcharge.value="$"+(price_format((xxtotal+xtax+xxship+xxextra)/100));
		}
}


function TaxNo()
{	
	 if (document.checkout.tax.value != "0")
		{
			xtax=(document.checkout.xTaxx.value*100);
			xtotal=(document.checkout.xTotalx.value*100);
			xxship=(document.checkout.xshipx.value*100)	
			xxextra=(document.checkout.xExtraSubTotalx.value*100)		

			document.checkout.xTotalx.value=(price_format((xtotal-xtax)/100));
			document.checkout.total.value="$"+(price_format((xtotal-xtax)/100));

			document.checkout.totalcharge.value="$"+(price_format(((xtotal-xtax)+xxship+xxextra)/100));

			document.checkout.xTaxx.value=(0);
			document.checkout.tax.value=(0);
		}
}

function AutoAddress()
{	
	 if (document.checkout.xcheckboxx.value == 0)
		{
			document.checkout.shipname.value=(document.checkout.cardname.value);
			document.checkout.shipaddress.value=(document.checkout.cardaddress.value);
			document.checkout.shipcity.value=(document.checkout.cardcity.value);
			document.checkout.shipstate.value=(document.checkout.cardstate.value);
			document.checkout.shipzip.value=(document.checkout.cardzip.value);
			document.checkout.shipphone.value=(document.checkout.cardphone.value);
			document.checkout.shipemail.value=(document.checkout.cardemail.value);

			document.checkout.xcheckboxx.value=(1);
			alert("Shipping Address Has been Updated To Match Cardholders!");
		}
	 else if (document.checkout.xcheckboxx.value == 1)
		{
			document.checkout.shipname.value=("");
			document.checkout.shipaddress.value=("");
			document.checkout.shipcity.value=("");
			document.checkout.shipstate.value=("");
			document.checkout.shipzip.value=("");
			document.checkout.shipphone.value=("");
			document.checkout.shipemail.value=("");

			document.checkout.xcheckboxx.value=(0);
			alert("Shipping Address Has Been Cleared!");
		}
}

function ExShip()
{	
mf=document.checkout.ShipMethod.selectedIndex;
zc=mf
	 if (mf== 0)
		{
			xtax=(document.checkout.xTaxx.value*100)
			xship=(document.checkout.Ship_Stand.value*100);
			xextra=(document.checkout.xExtraSubTotalx.value*100);
			xtotal=((document.checkout.xTotalx.value)*100);
			xtotal=xtotal+xship;
			xthis=(0.00*100)
			document.checkout.ship.value="$"+(price_format((xship+xthis)/100));
			document.checkout.xshipx.value=(price_format((xship+xthis)/100));

			document.checkout.totalcharge.value="$"+(price_format((xtotal+xthis+xextra)/100));
			alert("Your shipping has been recalculated to STANDARD!");

		}
	 if (mf== 1)
		{
			xtax=(document.checkout.xTaxx.value*100)
			xship=(document.checkout.Ship_Stand.value*100);
			xextra=(document.checkout.xExtraSubTotalx.value*100);
			xtotal=((document.checkout.xTotalx.value)*100);
			xtotal=xtotal+xship;
			xthis=(14.00*100)
			document.checkout.ship.value="$"+(price_format((xship+xthis)/100));
			document.checkout.xshipx.value=(price_format((xship+xthis)/100));

			document.checkout.totalcharge.value="$"+(price_format((xtotal+xthis+xextra)/100));
			alert("Your shipping has been upgraded to EXPRESS!");

		}
	 if (mf== 2)
		{
			xtax=(document.checkout.xTaxx.value*100)
			xship=(document.checkout.Ship_Stand.value*100);
			xextra=(document.checkout.xExtraSubTotalx.value*100);
			xtotal=((document.checkout.xTotalx.value)*100);
			xtotal=xtotal+xship;
			xthis=(24.00*100)
			document.checkout.ship.value="$"+(price_format((xship+xthis)/100));
			document.checkout.xshipx.value=(price_format((xship+xthis)/100));

			document.checkout.totalcharge.value="$"+(price_format((xtotal+xthis+xextra)/100));
			alert("Your shipping has been upgraded to OVERNIGHT!");

		}
}

function price_format(tmpprice){
// get rid of the extra digits behind "."
   dot = tmpprice.toString().indexOf(".");
   if(dot!=-1)
      tmpprice=tmpprice.toString().substr(0,dot+4);
   tmpprice=Math.round(tmpprice*100)/100;
// add "0" if necessary
   dot = tmpprice.toString().indexOf(".");
   if(dot ==-1)
      tmpprice=tmpprice.toString()+".00";
   else if((tmpprice.toString().length-dot)==2)
      tmpprice=tmpprice.toString()+"0";
   return tmpprice;
}

function verify_ccard(inNumber, type)
{// returns 0 if valid, positive number if invalid.

        total = 1*0;
        tmp = 1*0;

        number = "";

	mystr=type;

	type=mystr
	type=inNumber;

	if(type.substr(0,1) == "5")
	{
		document.checkout.my_card_type.value="MC";
		type="MC";
	}
	else if(type.substr(0,1) == "4")
	{
		document.checkout.my_card_type.value="VISA";
		type="VISA";
	} 
	else if(type.substr(0,1) == "3")
	{
		document.checkout.my_card_type.value="AMEX";
		type="AMEX";
	} 
	else if(type.substr(0,4) == "6011")
	{
		document.checkout.my_card_type.value="DISC";
		type="DISC";
	} 

        // make sure there are only numbers in the string...
        for(i = 0; i < inNumber.length; i++)
        {
		if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9")
                {
                        number = number + inNumber.charAt(i);
                }
        }

        if(number.length < 13) return 10; // too short for anything

        first = "" + number.charAt(0);
        second = "" + number.charAt(1);
        third = "" + number.charAt(2);
        firstTwo = first + second;
        firstFour = firstTwo + third + number.charAt(3);

        if(type == "MC")
        {
                if(first != "5" || second < "1" || second > "5")
                        return 11;// invalid Mastercard prefix
                if(number.length != 16)
                        return 21;
        }
        else if(type == "VISA")
        {
                if(first != "4")
                        return 12;// invalid Visa prefix
                if(number.length != 13 && number.length != 16)
                        return 22;
        }
        else if(type == "AMEX")
        {
                if(first != "3" || (second != "4" && second != "7"))
                        return 13;// invalid American Express Prefix
                if(number.length != 15) 
                        return 23;
        }
        else if(type == "DISC")
        {
                        if(firstFour != "6011")
                                return 14;// invalid prefix.
                        if(number.length != 16)
                                return 24;
        }
        else if(type == "DCCB")
        {
                if(firstTwo != "36"
                        && firstTwo != "38"
                        && (firstTwo != "30" ||
                                (third < "0" || third > "5")))
                {
                        return 15;
                }
                if(number.length != 14)
                        return 25;
        }
        else if(type == "enRoute")
        {
                if(firstFour != "2014"
                        && firstFour != "2149")
                        return 16;// invalid enRoute card
                if(number.length != 15)
                        return 26;
		return 0; // no check sum calculation needed
        }
        else if(type == "JCB")
        {
                if(firstFour != "2131"
                        && firstFour != "1800"
                        && (first != "3") )
                        return 17;
                if(number.length != 16 && first =="3")
                        return 27;
                if(number.length != 15 && first != "3")
                        return 28;
        }
        // now check the credit card suffix and length vs. the type

    
         // do the check sum
        for(loc = number.length - 2; loc >= 0; loc -= 2)
        {
                total += 1 * number.charAt(loc +1);
                tmp = number.charAt(loc) * 2;
		if(tmp > 9) total += 1;
		total += tmp%10;
        }
	if(number.length % 2 > 0)
	total += 1 * number.charAt(0);


        return (total % 10);
}

function confirm()
{
        if((reason = verify_ccard(document.checkout.card_number.value, document.checkout.my_card_type.value)) == 0)
        {
                return true;
        }
        else
        {
                alert("Card Number Invalid.");
		return false;
        }
}


function IsReserved(sText,form)
	{
   var ValidChars = " 1234567890!@#$%^&*()_+-=[]\{}|;:,./<>?`~:,.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			{
			alert("No quotes or single quotes please. The following characters are not allowed to be used.   '    and    ''   ");
			form.focus();
			form.select();
			return false;
			}
		}
   return IsNumber;
   alert("true.");
   }

function ExtraAlert()
	{
		alert("An extra charge has been added to your order to meet our minimum purchase requirement. To remove this charge, simply place 1 or more additional items into your cart.");
	        return false;
	}

function PopUpClose(ref) 
	{
		window.opener.location = ref
		window.opener.focus();
		window.close();
	}

function help_window(myurl,name,windowwidth,windowheight)
{
	var l = (screen.width-windowwidth)/2;
	var t = (screen.height-windowheight)/2;
	var hwinfound = 0;
	
	var props = 'scrollBars=yes,resizable=no,toolbar=no,menubar=no,location=no,directories=no,width='+windowwidth+',height='+windowheight+',screenX='+l+',screenY='+l+',left='+l+',top='+t;
	promopopup=window.open(myurl, name, props);
	promopopup.focus();
}
