var sPleaseWait = "<table><tr><td bgcolor='#FFFFFF'><font color='#000000' size=3><b>Please Wait...</b></font></td></tr><tr><td><font size=1>The current page is loading...<br>This box will automatically close.</font></td></tr></table>";

function Warning(formItem) {
	if (!formItem.checked) {
		sLostItem = "<table width='195'><tr><td bgcolor='#FFFFFF' align='center'><font color='#000000' size=2><b>Item will be removed.</b></font></td></tr><tr><td align='center'><font size=1>Click 'REFRESH' button<br>to confirm removal.</font></td></tr></table>";
		$("#overDiv").fadeOut("fast", function () {$("#overDiv").fadeIn("normal");} );
		overlib(sLostItem, STICKY, FIXX, CenterXPos()-80, RELY, 130, WIDTH, 200);
	} else {
		$("#overDiv").fadeOut("normal");
	}
}

function CartLoad() { 
	if(Validate_Email(document.Orderform.x_Email)) {
		overlib(sPleaseWait, STICKY, FIXX, CenterXPos()-80, RELY, 130); 
		document.shoppingcart.CARTACTIONS.value='load'; 
		document.shoppingcart.submit();
	} else {
		sLoadItem = "<div id='tempmsg' style='cursor: pointer; cursor: hand;'><table width='195'><tr><td align='center'><font size=1>Cart contents are stored using Billing E-mail. Please enter Billing Email below and try again.</font></td></tr><tr><td bgcolor='#FFFFFF' align='center'><font color='#000000' size=2><b>* CLICK TO CLOSE *</b></font></td></tr></table></div>";
//		alert('Cart contents saved using Billing E-mail. Please enter Billing Email below and try again.'); 
		$("#overDiv").fadeOut("fast", function () {$("#overDiv").fadeIn("normal");} );
		overlib(sLoadItem, STICKY, OFFSETX, -350, OFFSETY, 310, WIDTH, 200);
		$("#tempmsg").click( function() {$("#overDiv").fadeOut("fast");} );
		document.Orderform.x_Email.focus();
	}
}

function formatNum(expr,decplaces) {
	var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString();
	while (str.length <= decplaces) {str = "0" + str;} 
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function ShipInfoXfer(sObject,sWhereTo) {
	if (bNeverTouched && document.Orderform.OTHERADDRESS.checked==false){
		ShipLog(sObject,false,0);	
		eval("document.Orderform."+sWhereTo+".value=document.Orderform."+sObject+".value");
	}
	return(true);
}
function ShipInfoXfer2(sObject,sWhereTo) {
	var sValueForm=0
	eval("sValueForm=document.Orderform."+sWhereTo+".selectedIndex");
	if (document.Orderform.OTHERADDRESS.checked==false) {
		ShipLog(sObject,false,sValueForm);
		eval("document.Orderform."+sWhereTo+".selectedIndex=document.Orderform."+sObject+".selectedIndex");
	}
	return(true);
}
function ShipLog(sLogFormVar,bSetbool,nBlank) {

	if (bSetbool)
		bNeverTouched=false;
	if (nBlank==0) {
		eval("document.shoppingcart."+sLogFormVar+".value=document.Orderform."+sLogFormVar+".value");
	} else {
		eval("document.shoppingcart."+sLogFormVar+".value=nBlank");
	}
}

function ArbitrateAddress(xObject) {
	if (xObject.checked) {
		document.shoppingcart.OTHERADDRESS.value="ON";
		document.shoppingcart.country.value=document.Orderform.x_Ship_To_Country.selectedIndex;
	} else {
		document.shoppingcart.OTHERADDRESS.value="";
		document.shoppingcart.country.value=document.Orderform.x_Country.selectedIndex;
	}
}

function ClearShipAddress() {
	for (i=0;i<2;i++) {
		if (i==0) sObject=document.Orderform;
		if (i==1) sObject=document.shoppingcart;
		sObject.x_Ship_To_Last_Name.value="";
		sObject.x_Ship_To_Address.value="";
		sObject.x_Ship_To_City.value="";
		sObject.x_Ship_To_State.value="";
		sObject.x_Ship_To_Zip.value="";
		sObject.x_Ship_To_Country.selectedIndex=56;
	}
	return(true);
}

function ShipAddressEnableControl(bBoxStatus) {
	if (bBoxStatus) {
		bFormElementAction = false;
	} else {
		bFormElementAction = true;
	}
	document.Orderform.x_Ship_To_Last_Name.disabled	= bFormElementAction;
	document.Orderform.x_Ship_To_Address.disabled	= bFormElementAction;
	document.Orderform.x_Ship_To_City.disabled	= bFormElementAction;
	document.Orderform.x_Ship_To_State.disabled	= bFormElementAction;
	document.Orderform.x_Ship_To_Zip.disabled	= bFormElementAction;
	document.Orderform.x_Ship_To_Country.disabled	= bFormElementAction;
}

function CheckIt(oFormObject,sCustMsg,nSizeLimit) {
	if (oFormObject.value.length < nSizeLimit) {
		oFormObject.focus();
		alert(sCustMsg);
		return false;
	} else
		return true;
}

function ZipChange(oZipField) {
	if (document.Orderform.OTHERADDRESS.checked && oZipField.name=="x_Ship_To_Zip" && oZipField.value !="" && document.shoppingcart.x_ShippingOption.selectedIndex != 0)
		return true;
	if (oZipField.name=="x_Zip" && oZipField.value !="" && document.shoppingcart.x_ShippingOption.selectedIndex != 0)
		return true;
	return false;
}

function Validate_Email(strng) {
	//var emailFilter=/^.+@.+\..{2,3}$/;
	var emailFilter=/^(\w|[-])+(\.(\w|[-])+)*@((\[([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\])|((([a-zA-Z0-9])+(([-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([-])+([a-zA-Z0-9])+)*))$/;
	var strEmail=strng.value;
	if (strEmail=="" || !(emailFilter.test(strEmail))) { 
		return false;
	}
	return true;
}

function ZipPopAction(objPopInput) {
	if (objPopInput.value.length>4) {
		if (document.Orderform.OTHERADDRESS.checked){
			document.Orderform.x_Ship_To_Zip.value=objPopInput.value;
			ShipLog('x_Ship_To_Zip',true,0);
			if (ZipChange(document.Orderform.x_Ship_To_Zip)) {
				document.shoppingcart.submit();
			}
		} else {
			document.Orderform.x_Zip.value=objPopInput.value;
			ShipInfoXfer('x_Zip','x_Ship_To_Zip');
			if (ZipChange(document.Orderform.x_Zip)) {
				document.shoppingcart.submit();
			}
		} 
		$("#overDiv").fadeOut("fast"); 
		document.shoppingcart.x_ShippingOption.focus();
	} else {
		document.Orderform.x_Ship_To_Zip.focus(); 
	}
}

function CheckZip() {
	sNoZip = "<table width='215'><tr><td bgcolor='#FFFFFF' align='center'><font color='#000000' size=2><b>*Enter Postal Code*</b></font></td></tr><tr><td align='center'><font size=1>To calculate shipping costs, please enter your shipping postal code:<br>"+
						"<input name='tempzip' id='tempzip' size='10' value='' onChange='ZipPopAction(this);'>"+
						"&nbsp;<img src='http://e-shirt.com/images/go_butt21x21.gif' width='21' height='21' onClick=\"$('#overDiv').fadeOut('fast');\" style='position:relative; top:5px; display:inline; cursor: pointer; cursor: hand;' /> </font></td></tr></table>";
	if (document.Orderform.OTHERADDRESS.checked) {
		if (document.Orderform.x_Ship_To_Zip.value.length < 5) {
			$("#overDiv").fadeOut("fast", function () {$("#overDiv").fadeIn("normal");} );
			overlib(sNoZip, STICKY, OFFSETX, -300, OFFSETY, -50, WIDTH, 220);
			$("#tempzip").focus();
			//overlib(sNoZip, STICKY, FIXX, CenterXPos()-80, RELY, 130, WIDTH, 220);
			//CheckIt(document.Orderform.x_Ship_To_Zip,"Before selecting a shipping method, please enter the Zip Code.",5);
			return false;
		} else {
			return true;
		}
	} else {
		if (document.Orderform.x_Zip.value.length < 5) {
			$("#overDiv").fadeOut("fast", function () {$("#overDiv").fadeIn("normal");} );
			overlib(sNoZip, STICKY, OFFSETX, -300, OFFSETY, -50, WIDTH, 220);
			$("#tempzip").focus();
			//CheckIt(document.Orderform.x_Zip,"Before selecting a shipping method, please enter the Zip Code.",5);
			return false;
		} else {
			return true;
		}


	}
	return true;	
}

function CountryList(sSelected) {
	var sSelectCountry="";
	var sSelectedCountry="";
	if (sSelected=="")
		sSelected="USA";
	var sList1="Australia,Austria,Bahamas,Belgium,Bermuda,Canada,Cape Verde,Cayman Islands,China,Denmark,England,Espana,Fiji,Finland,France,";
	var sList2="Germany,Gibraltar,Great Britain,Greenland,Greenland,Hong Kong,Hungary,Iceland,Iceland,Ireland,Israel,Italy,Jamaica,Japan,Jordan,";
	var sList3="Korea (South),Kuwait,Liechtenstein,Luxembourg,Mexico,Monaco,Mongolia,Netherlands,New Zealand,Northern Ireland,Norway,";
	var sList4="Panama,Philippines,Poland,Portugal,Puerto Rico,Russia,Russian Federation,Scotland,Scotland,South Africa,Spain,Sweden,Switzerland,";
	var sList5="Taiwan,Turkey,USA,Ukraine,United Arab Emirates,United Kingdom,Vatican City,Virgin Islands (British),Virgin Islands (U.S.),Wales";
	var sList=sList1+sList2+sList3+sList4+sList5;
	aCountryArray=sList.split(",");
	for (var ijk in aCountryArray) {
		if (sSelected==aCountryArray[ijk])
			sSelectedCountry=" selected";
		else
			sSelectedCountry="";
		sSelectCountry=sSelectCountry+"<option"+sSelectedCountry+"> "+aCountryArray[ijk]+"</option>";
	}
	return sSelectCountry;	
}

function CenterXPos() {
	if(is.ns4 || is.ns6) {
		available_width = (window.innerWidth / 2) + window.pageXOffset;
	} else if(is.ie4 || is.ie5 || is.ieX) {
		available_width = (document.compatMode=="CSS1Compat")?document.documentElement.clientWidth : document.body.clientWidth;
		nscrollLeft = (document.compatMode=="CSS1Compat")?document.documentElement.scrollLeft : document.body.scrollLeft;
    	available_width = (available_width / 2) + nscrollLeft;
	} else {
		available_width=document.body.offsetWidth;
    }
	return (available_width - 20);
}

function goToURL(sURL) {
	location=sURL;
}