function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateForm(type) {
	lErr=new Array(true);

	if (type == 'product') {
		lErr=validateStr(lErr, 'Quantity', document.product.qty.value, 1, 3);
		lErr=validateSel(lErr, 'Color', document.product.sku.options[document.product.sku.selectedIndex].value);
		lErr=validateSel(lErr, 'Size', document.product.size.options[document.product.size.selectedIndex].value);
	}
	else if (type == 'cart') {
		lErr=validateStr(lErr, 'Quantity', document.product.qty.value, 1, 3, 1, 1, 999);
	}
	else if (type == 'coupon') {
		lErr=validateStr(lErr, 'Coupon Code', document.coupon.code.value, 5, 15);
	}
	else if (type == 'status') {
		lErr=validateEmail(lErr, document.status.email.value);
		lErr=validateStr(lErr, 'Order Number', document.status.ordID.value, 7, 7);
	}
	else if (type == 'loginN') {
		lErr=validateEmail(lErr, document.loginN.email.value);
	}
	else if (type == 'loginR') {
		lErr=validateEmail(lErr, document.loginR.email.value);
		lErr=validateStr(lErr, 'Password', document.loginR.passwd.value, 6, 20);
	}
	else if (type == 'MOY') {
		lErr=validateStr(lErr, 'First Name', document.contest.fname.value, 2, 20);
		lErr=validateStr(lErr, 'Last Name', document.contest.lname.value, 2, 30);
		lErr=validateEmail(lErr, document.contest.email.value);
		lErr=validateStr(lErr, 'Zip', document.contest.zip.value, 5, 10);
		lErr=validateStr(lErr, 'Phone Area Code', document.contest.ph1.value, 3, 3);
		lErr=validateStr(lErr, 'Phone Exchange', document.contest.ph2.value, 3, 3);
		lErr=validateStr(lErr, 'Phone Station', document.contest.ph3.value, 4, 4);

		if (document.contest.agreement.checked == false) {
			lErr[0]=false;
			error="Click checkbox to verify that you are a U.S. resident over the age of 18 and you agree to the terms and conditions";
			lErr.push(error);
		}
	}
	else if (type == 'TAF') {
		lErr=validateEmail(lErr, document.tell.emailF.value);
		lErr=validateEmail(lErr, document.tell.emailT1.value);
		if (document.tell.emailT2.value != '') {
			lErr=validateEmail(lErr, document.tell.emailT2.value);
		}
		if (document.tell.emailT3.value != '') {
			lErr=validateEmail(lErr, document.tell.emailT3.value);
		}

		if (document.tell.agreement.checked == false) {
			lErr[0]=false;
			error="Click checkbox to verify that you are a U.S. resident over the age of 18 and you agree to the terms and conditions";
			lErr.push(error);
		}
	}
	else if (type == 'register') {
		lErr=validateEmail(lErr, document.register.email.value);
		lErr=validateStr(lErr, 'Password', document.register.passwd.value, 6, 12);
		lErr=validateStr(lErr, 'Password Confirmation', document.register.passwdcnf.value, 6, 12);

		if (document.register.passwd.value != document.register.passwdcnf.value) {
			lErr[0]=false;
			lErr.push("Passwords do not match");
		}

		lErr=validateStr(lErr, 'Billing First Name', document.register.fnameB.value, 2, 20);
		lErr=validateStr(lErr, 'Billing Last Name', document.register.lnameB.value, 2, 30);
		lErr=validateStr(lErr, 'Billing Address1', document.register.address1B.value, 2, 50);
		lErr=validateStr(lErr, 'Billing City', document.register.cityB.value, 2, 30);
		lErr=validateSel(lErr, 'Billing State', document.register.stateB.options[document.register.stateB.selectedIndex].value);
		lErr=validateStr(lErr, 'Billing Zip', document.register.zipB.value, 5, 10);
		lErr=validateSel(lErr, 'Billing Country', document.register.countryB.options[document.register.countryB.selectedIndex].value);
		lErr=validateStr(lErr, 'Billing Phone', document.register.phoneB.value, 10, 20);

		lErr=validateStr(lErr, 'Shipping First Name', document.register.fnameS.value, 2, 20);
		lErr=validateStr(lErr, 'Shipping Last Name', document.register.lnameS.value, 2, 30);
		lErr=validateStr(lErr, 'Shipping Address1', document.register.address1S.value, 2, 50);
		lErr=validateStr(lErr, 'Shipping City', document.register.cityS.value, 2, 30);
		lErr=validateSel(lErr, 'Shipping State', document.register.stateS.options[document.register.stateS.selectedIndex].value);
		lErr=validateStr(lErr, 'Shipping Zip', document.register.zipS.value, 5, 10);
		lErr=validateSel(lErr, 'Shipping Country', document.register.countryS.options[document.register.countryS.selectedIndex].value);
		lErr=validateStr(lErr, 'Shipping Phone', document.register.phoneS.value, 10, 20);
	}
	else if (type == 'billing') {
		lErr=validateStr(lErr, 'Billing First Name', document.billing.fnameB.value, 2, 20);
		lErr=validateStr(lErr, 'Billing Last Name', document.billing.lnameB.value, 2, 30);
		lErr=validateStr(lErr, 'Billing Address1', document.billing.address1B.value, 2, 50);
		lErr=validateStr(lErr, 'Billing City', document.billing.cityB.value, 2, 30);
		lErr=validateSel(lErr, 'Billing State', document.billing.stateB.options[document.billing.stateB.selectedIndex].value);
		lErr=validateStr(lErr, 'Billing Zip', document.billing.zipB.value, 5, 10);
		lErr=validateSel(lErr, 'Billing Country', document.billing.countryB.options[document.billing.countryB.selectedIndex].value);
		lErr=validateStr(lErr, 'Billing Phone', document.billing.phoneB.value, 10, 20);
		lErr=validateEmail(lErr, document.billing.email.value);
	}
	else if (type == 'shipping') {
		lErr=validateStr(lErr, 'Shipping First Name', document.shipping.fnameS.value, 2, 20);
		lErr=validateStr(lErr, 'Shipping Last Name', document.shipping.lnameS.value, 2, 30);
		lErr=validateStr(lErr, 'Shipping Address1', document.shipping.address1S.value, 2, 50);
		lErr=validateStr(lErr, 'Shipping City', document.shipping.cityS.value, 2, 30);
		lErr=validateSel(lErr, 'Shipping State', document.shipping.stateS.options[document.shipping.stateS.selectedIndex].value);
		lErr=validateStr(lErr, 'Shipping Zip', document.shipping.zipS.value, 5, 10);
		lErr=validateSel(lErr, 'Shipping Country', document.shipping.countryS.options[document.shipping.countryS.selectedIndex].value);
		lErr=validateStr(lErr, 'Shipping Phone', document.shipping.phoneS.value, 10, 20);
		lErr=validateSel(lErr, 'Shipping Option', document.shipping.shipOpt.options[document.shipping.shipOpt.selectedIndex].value);

		stateShip=document.shipping.stateS.options[document.shipping.stateS.selectedIndex].value;
		countryShip=document.shipping.countryS.options[document.shipping.countryS.selectedIndex].value;
		shipOpt=document.shipping.shipOpt.options[document.shipping.shipOpt.selectedIndex].value;

		if (stateShip != '' && countryShip != '') {
			if (countryShip == 'US' && stateShip == 'NU') {
				lErr[0]=false;
				error="Choose a US State";
				lErr.push(error);
			}
			else if (countryShip != 'US' && stateShip != 'NU') {
				lErr[0]=false;
				error="Choose a Non-US State";
				lErr.push(error);
			}
		}
				
		if (shipOpt != '' && countryShip != '') {
			if (countryShip == 'US' && (shipOpt != 1 && shipOpt != 2)) {
				lErr[0]=false;
				error="Choose a US Shipping Option";
				lErr.push(error);
			}
			else if (countryShip == 'CA' && shipOpt != 3) {
				lErr[0]=false;
				error="Choose Canadian Shipping option";
				lErr.push(error);
			}
			else if ((countryShip != 'US' && countryShip != 'CA') && shipOpt != 4) {
				lErr[0]=false;
				error="Choose International Shipping option";
				lErr.push(error);
			}
		}
	}
	else if (type == 'gift') {
		lErr=validateStr(lErr, 'From Name', document.gift.gcFrom.value, 1, 50);
		lErr=validateStr(lErr, 'To Name', document.gift.gcTo.value, 1, 50);
		lErr=validateStr(lErr, 'Msg', document.gift.gcMsg.value, 1, 50);
		lErr=validateRadio(lErr, 'Gift Card', document.gift.gcID);
	}
	else if (type == 'payment') {
		lErr=validateSel(lErr, 'Card Type', document.payment.ccType.options[document.payment.ccType.selectedIndex].value);
		lErr=validateStr(lErr, 'Card Number', document.payment.ccNum.value, 5, 16);
		lErr=validateSel(lErr, 'Expiration Month', document.payment.exprM.options[document.payment.exprM.selectedIndex].value);
		lErr=validateSel(lErr, 'Expiration Year', document.payment.exprY.options[document.payment.exprY.selectedIndex].value);
		lErr=validateStr(lErr, 'CID', document.payment.ccCID.value, 3, 4);

		ccType=document.payment.ccType.options[document.payment.ccType.selectedIndex].value;
		ccCID=document.payment.ccCID.value;

		if (ccType != '' && ccCID != '') {
			if (ccType == 'AMEX' && ccCID.length != 4) {
				lErr[0]=false;
				error="AMEX CID's = 4 digits";
				lErr.push(error);
			}
			else if (ccType != 'AMEX' && ccCID.length != 3) {
				lErr[0]=false;
				error=ccType + " CID's = 3 digits";
				lErr.push(error);
			}
		}
	}
	
	if (lErr[0] == true) {
		return true;
	}
	else {
		error="The following error(s) occurred:\n";
		for (i=1; i < lErr.length; i++) {
			error+="=> " + lErr[i] + "\n";
		}
		alert(error);
		return false;
	}
}

function copyBillToShip() {
	if (document.shipping.copy.checked == true) {
		document.shipping.fnameS.value=document.billing.fnameB.value;
		document.shipping.lnameS.value=document.billing.lnameB.value;
		document.shipping.address1S.value=document.billing.address1B.value;
		document.shipping.address2S.value=document.billing.address2B.value;
		document.shipping.cityS.value=document.billing.cityB.value;
		document.shipping.stateS.value=document.billing.stateB.value;
		document.shipping.zipS.value=document.billing.zipB.value;
		document.shipping.countryS.value=document.billing.countryB.value;
		document.shipping.phoneS.value=document.billing.phoneB.value;
	}
	else {
		document.shipping.fnameS.value='';
		document.shipping.lnameS.value='';
		document.shipping.address1S.value='';
		document.shipping.address2S.value='';
		document.shipping.cityS.value='';
		document.shipping.stateS.value='';
		document.shipping.zipS.value='';
		document.shipping.countryS.value='';
		document.shipping.phoneS.value='';
	}
}
