// JavaScript Document
<!--
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_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_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 MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function request(jenk) { // Clone of VBScript's Response.Request() function
	var querystring = location.search.substring(1,location.search.length);	// Skip the "?"
	var x, tmp;

	if(!querystring =="") {
		var varArray = querystring.split("&");

		for(i=0; i<varArray.length; i++) {
			tmp = varArray[i].split("=");
			if(tmp[0] == jenk) {
				x = tmp[1];
				break;
			} // END if()
		} // END for()
	} // END if()
	return x;
} // END function request()

function thisPage() { // Returns the name of the page.  Example, for this page it would return "scriptLibrary.js"
	var x = "";
	var thisURL = window.location.href;
	var aryURL = thisURL.split("/");

	x = aryURL[(aryURL.length - 1)];

	// Don't include the querystring
	if(x.indexOf("?") > -1) {
		aryTemp = x.split("?");
		x = aryTemp[0];
	}
	return x;
} // END function thisPage()

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

function check_email(email) {
	var pattern = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/;
//	var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if(pattern.test(email))
		return 1;
	else
		return 0;
}

function processSubscribe(s_name, s_email) {
	var errorMsg = "";

	// Check for form errors
	if(s_name == "") errorMsg += "Please fill out all fields.\n";
	if(!check_email(s_email)) errorMsg += "Please enter a valid email address.\n";

	if(errorMsg == "") { // No errors
		return true;
	} else {
		alert(errorMsg);
		return false;
	}
}

function processUnsubscribe(email) {
	if(check_email(email)) {
		return true;
	} else {
		alert("Please enter a valid email address.");
		return false;
	}
}

function preloadNav() {
	MM_preloadImages(
	'images/txt_about_bjx_1.gif',
	'images/txt_collections_1.gif',
	'images/txt_contact_1.gif',
	'images/txt_customer_service_1.gif',
	'images/txt_policies_1.gif',
	'images/txt_press_1.gif',
	'images/txt_shopping_cart_1.gif');
}

function inArray(ary, jenk) {
	for(i=0; i<ary.length; i++) 
		if(ary[i] == jenk) 
			return true;

	return false;
}

function showhide(id) {
	var e = document.getElementById(id);
	if(e.style.display == 'none')
		e.style.display = 'block';
	else
		e.style.display = 'none';
}

function jenkCheckbox(jenk) { // Changes state of specified checkbox
	var z = document.getElementById(jenk);
	z.checked = (z.checked) ? false : true;
}

function jenkRadiobutton(jenk) { // Selects specified radio button if unchecked
	var z = document.getElementById(jenk);
	if(!z.checked) z.checked = true;
}

function textSubmit() { // Makes a link act as a submit button
	document.the_form.submit(); // NOTE: Form name MUST BE "the_form" because asshole javascript won't let you use a variable.
}


/* --- Features Functions --- */
function showFeatures(curFeats) { // Put X's next to appropriate features
	var aryCurFeats = curFeats.split(",");

	for(var f in features)
		if(inArray(aryCurFeats, features[f]))
			document.getElementById("x_" + features[f]).src = "images/x.gif";

}


function resetFeatures() { // Remove all X's from features
	for(var f in features) document.getElementById("x_" + features[f]).src = "images/spacer.gif";
}

function compareProcess(jenk) {
	if(!document.getElementById("comparebox_" + jenk).checked) { // it's not checked
		if(ct_comparison < 5) { // make sure count is below 5
			jenkCheckbox("comparebox_" + jenk);
			ct_comparison++;
			handleHidden(jenk);
		} else {
			alert("You can only compare a maximum of 5 items.");
		}
	} else { // it's checked
		jenkCheckbox("comparebox_" + jenk);
		ct_comparison--;
		if(ct_comparison < 0) ct_comparison = 0; // Rare event
		handleHidden(jenk);
	}

	// Handle hidden jenk
}

function handleHidden(jenk) {
	var x = document.getElementById("hidden_" + jenk);
	if(x.value == "0")
		x.value = "1";
	else
		x.value = "0";
}

function pageSubmit(pageno) {
	document.getElementById("p").value = pageno;	// Pass page number "p" through POST
	document.the_form.page_submit.value = "x";
	document.the_form.submit();
}
function compareNow() {
	document.the_form.page_submit.value = "compare_now";
	document.the_form.submit();
}

// Preloads
function doThis() {
	preloadNav();
}

/* --- END Features Functions --- */


var features = new Array("passport_wallet", "ipod", "change", "phone", "key", "notebook_13-inch", "books", "notebook_15-inch", "files_papers", "notebook_17-inch", "identification", "camera", "pens_pencils", "ear_buds", "hidden_pocket", "cords", "eyewear", "handheld_games", "food", "kindle", "shoes", "skateboard", "sports_equipment", "cap", "wet_dry", "prescription");

/*

function countryAdjustment(formpage) {
	var qString = "";

	if(formpage == "billinfo") {
		BillCountry				= document.billinfo.BillCountry.value;
		BillContactTitle		= document.billinfo.BillContactTitle.value;
		BillContactFirstName	= document.billinfo.BillContactFirstName.value;
		BillContactLastName		= document.billinfo.BillContactLastName.value;
		BillAddress				= document.billinfo.BillAddress.value;
		BillAddress2			= document.billinfo.BillAddress2.value;
		BillCity				= document.billinfo.BillCity.value;
		BillState				= document.billinfo.BillState.value;
		BillPostalCode			= document.billinfo.BillPostalCode.value;
		BillPhoneNumber			= document.billinfo.BillPhoneNumber.value;
		BillEmailAddress		= document.billinfo.BillEmailAddress.value;
		BillEmailAddress2		= document.billinfo.BillEmailAddress2.value;

		qString =
			"&BillCountry=" + BillCountry +
			"&BillContactTitle=" + BillContactTitle +
			"&BillContactFirstName=" + BillContactFirstName +
			"&BillContactLastName=" + BillContactLastName +
			"&BillAddress=" + BillAddress +
			"&BillAddress2=" + BillAddress2 +
			"&BillCity=" + BillCity +
			"&BillState=" + BillState +
			"&BillPostalCode=" + BillPostalCode +
			"&BillPhoneNumber=" + BillPhoneNumber +
			"&BillEmailAddress=" + BillEmailAddress +
			"&BillEmailAddress2=" + BillEmailAddress2;

		location.href = "cartBilling.php?CountryChange=1" + qString;

	} else if(formpage == "shipinfo") {

		// Handle dastardly radio buttons
		var rez = document.shipinfo.ShipResidential[0].checked;	// Residential Address
		var biz = document.shipinfo.ShipResidential[1].checked;	// Business Address

		if(rez == true) {
			ShipResidential = true;
		} else if(biz == true) {
			ShipResidential = false;
		} else {
			ShipResidential = true;	// Default
		}

		ShipCountry				= document.shipinfo.ShipCountry.value;
//		ShipResidential			= document.shipinfo.ShipResidential.value;
		ShipContactTitle		= document.shipinfo.ShipContactTitle.value;
		ShipContactFirstName	= document.shipinfo.ShipContactFirstName.value;
		ShipContactLastName		= document.shipinfo.ShipContactLastName.value;
		ShipAddress				= document.shipinfo.ShipAddress.value;
		ShipAddress2			= document.shipinfo.ShipAddress2.value;
		ShipCity				= document.shipinfo.ShipCity.value;
		ShipState				= document.shipinfo.ShipState.value;
		ShipPostalCode			= document.shipinfo.ShipPostalCode.value;
		ShipPhoneNumber			= document.shipinfo.ShipPhoneNumber.value;
//		ShipEmailAddress		= document.shipinfo.ShipEmailAddress.value;
//		ShipEmailAddress2		= document.shipinfo.ShipEmailAddress2.value;

		qString ="&ShipCountry=" + ShipCountry +
			"&ShipResidential=" + ShipResidential +
			"&ShipContactTitle=" + ShipContactTitle +
			"&ShipContactFirstName=" + ShipContactFirstName +
			"&ShipContactLastName=" + ShipContactLastName +
			"&ShipAddress=" + ShipAddress +
			"&ShipAddress2=" + ShipAddress2 +
			"&ShipCity=" + ShipCity +
			"&ShipState=" + ShipState +
			"&ShipPostalCode=" + ShipPostalCode +
			"&ShipPhoneNumber=" + ShipPhoneNumber;// +
//			"&ShipEmailAddress=" + ShipEmailAddress +
//			"&ShipEmailAddress2=" + ShipEmailAddress2;

		location.href = "cartShipping.php?CountryChange=1" + qString;

	} // END if(formpage == ...)

}


function countryChange(formpage) {
	var qString = "";

	if(formpage == "shipinfo") {
		ShipContactTitle		= shipinfo.getElementById('ShipContactTitle');
		ShipContactFirstName	= shipinfo.getElementById('ShipContactFirstName');
		ShipContactLastName		= shipinfo.getElementById('ShipContactLastName');
		ShipAddress				= shipinfo.getElementById('ShipAddress');
		ShipAddress2			= shipinfo.getElementById('ShipAddress2');
		ShipCity				= shipinfo.getElementById('ShipCity');
		ShipState				= shipinfo.getElementById('ShipState');
		ShipPostalCode			= shipinfo.getElementById('ShipPostalCode');
		ShipPhoneNumber			= shipinfo.getElementById('ShipPhoneNumber');
//		ShipEmailAddress		= shipinfo.getElementById('ShipEmailAddress');
//		ShipEmailAddress2		= shipinfo.getElementById('ShipEmailAddress2');

		qString = '&ShipContactTitle=' + ShipContactTitle + 
			'&ShipContactFirstName=' + ShipContactFirstName + 
			'&ShipContactLastName=' + ShipContactLastName + 
			'&ShipAddress=' + ShipAddress + 
			'&ShipAddress2=' + ShipAddress2 + 
			'&ShipCity=' + ShipCity + 
			'&ShipState=' + ShipState + 
			'&ShipPostalCode=' + ShipPostalCode + 
			'&ShipPhoneNumber=' + ShipPhoneNumber;

	} else if(formpage == "billinfo") {
		BillContactTitle		= billinfo.getElementById('BillContactTitle');
		BillContactFirstName	= billinfo.getElementById('BillContactFirstName');
		BillContactLastName		= billinfo.getElementById('BillContactLastName');
		BillAddress				= billinfo.getElementById('BillAddress');
		BillAddress2			= billinfo.getElementById('BillAddress2');
		BillCity				= billinfo.getElementById('BillCity');
		BillState				= billinfo.getElementById('BillState');
		BillPostalCode			= billinfo.getElementById('BillPostalCode');
		BillPhoneNumber			= billinfo.getElementById('BillPhoneNumber');
		BillEmailAddress		= billinfo.getElementById('BillEmailAddress');
		BillEmailAddress2		= billinfo.getElementById('BillEmailAddress2');

		qString = '&BillContactTitle=' + BillContactTitle + 
			'&BillContactFirstName=' + BillContactFirstName + 
			'&BillContactLastName=' + BillContactLastName + 
			'&BillAddress=' + BillAddress + 
			'&BillAddress2=' + BillAddress2 + 
			'&BillCity=' + BillCity + 
			'&BillState=' + BillState + 
			'&BillPostalCode=' + BillPostalCode + 
			'&BillPhoneNumber=' + BillPhoneNumber + 
			'&BillEmailAddress=' + BillEmailAddress + 
			'&BillEmailAddress2=' + BillEmailAddress2;
	}

	return qString;
}
*/
//-->
