

// ============================================================ FUNCTIONS: IMAGE ============================================================
function newImage(arg) {
	if (document.images) {
		rslt 							= new Image();
		rslt.src 						= arg;
		
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2)
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
	}
}

var preloadFlag 						= false;

function preloadImages(oPath) {
	if (document.images) {
		sn_over			 				= newImage(oPath + "sn_over.gif");
		ssn_over			 			= newImage(oPath + "ssn_over.gif");
		nav_care_over					= newImage(oPath + "nav_care_over.gif");
		nav_options_over				= newImage(oPath + "nav_options_over.gif");
		nav_repairs_over				= newImage(oPath + "nav_repairs_over.gif");
		nav_prices_over					= newImage(oPath + "nav_prices_over.gif");
		nav_cart_over					= newImage(oPath + "nav_cart_over.gif");
		preloadFlag						= true;
	}
}


// ============================================================ FUNCTIONS: SIDE NAV ============================================================
function SN_swap(oTID, oLID, oView) {
	if (oView == 'over') {
		document.all[oTID].background	= 'assets/images/sn_over.gif';
		document.all[oLID].className	= 'linkSN_over';
	} else {
		document.all[oTID].background	= 'assets/images/sn_up.gif';
		document.all[oLID].className	= 'linkSN_up';
	}
}

function SSN_swap(oTID, oLID, oView) {
	if (oView == 'over') {
		document.all[oTID].background	= 'assets/images/ssn_over.gif';
		document.all[oLID].className	= 'linkSN_over';
	} else {
		document.all[oTID].background	= 'assets/images/ssn_up.gif';
		document.all[oLID].className	= 'linkSN_up';
	}
}

function SNT_click(oLID) {
	location.href 						= document.all[oLID].href
}


// ============================================================ FUNCTIONS: WINDOW ============================================================
function newWindow(oPage, oW, oH, oScroll){
	xpos 								= (screen.width) ? (screen.width - oW)/2 : 0;
	ypos 								= (screen.height) ? (screen.height - oH)/2 : 0;
	
	if (oScroll == 'Y')
		window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
	else
		window.open(oPage,"newWin","toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width="+oW+",height="+oH+",left="+xpos+",top="+ypos);
}


// ============================================================ FUNCTIONS: FORMS ============================================================
function ship_check(oBox, oForm) {
	if (oBox.checked == true) {
		oForm.ship_pname.selectedIndex		= oForm.pname.selectedIndex;
		oForm.ship_fname.value 				= oForm.fname.value;
		oForm.ship_mname.value 				= oForm.mname.value;
		oForm.ship_lname.value 				= oForm.lname.value;
		oForm.ship_address1.value 			= oForm.bill_address1.value;
		oForm.ship_address2.value 			= oForm.bill_address2.value;
		oForm.ship_city.value 				= oForm.bill_city.value;
		oForm.ship_state.selectedIndex		= oForm.bill_state.selectedIndex;
		oForm.ship_zip.value 				= oForm.bill_zip.value;
		oForm.ship_phone.value 				= oForm.bill_phone.value;
	}
}

function valLoginForm(oForm) {
	if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
		formError('Please enter a valid E-mail Address.', oForm.email)
		return;
	}
	if (oForm.password.value == ""){
		formError('Please enter your Password.', oForm.password)
		return;
	}
	
	oForm.submit();
}

function valCCForm(oForm) {
	if (oForm.cc_type.options[oForm.cc_type.selectedIndex].value == ""){
		formError('Please select your Card Type.', oForm.cc_type)
		return;
	}
	if (oForm.cc_number.value == ""){
		formError('Please enter your Card Number.', oForm.cc_number)
		return;
	}
	if (oForm.cc_expm.options[oForm.cc_expm.selectedIndex].value == ""){
		formError('Please select your Expiration Month.', oForm.cc_expm)
		return;
	}
	if (oForm.cc_expy.options[oForm.cc_expy.selectedIndex].value == ""){
		formError('Please select your Expiration Year.', oForm.cc_expy)
		return;
	}
	
	oForm.submit();
}

function valAccForm(oForm) {
	if (oForm.fname.value == ""){
		formError('Please enter your Billing First Name.', oForm.fname)
		return;
	}
	if (oForm.lname.value == ""){
		formError('Please enter your Billing Last Name.', oForm.lname)
		return;
	}
	if (oForm.bill_address1.value == ""){
		formError('Please enter your Billing Address.', oForm.bill_address1)
		return;
	}
	if (oForm.bill_city.value == ""){
		formError('Please enter your Billing City.', oForm.bill_city)
		return;
	}
	if (oForm.bill_state.options[oForm.bill_state.selectedIndex].value == ""){
		formError('Please select your Billing State.', oForm.bill_state)
		return;
	}
	if (oForm.bill_zip.value == ""){
		formError('Please enter your Billing Zip.', oForm.bill_zip)
		return;
	}
	if (oForm.bill_phone.value == ""){
		formError('Please enter your Billing Phone.', oForm.bill_phone)
		return;
	}
	if (oForm.ship_fname.value == ""){
		formError('Please enter your Shipping First Name.', oForm.ship_fname)
		return;
	}
	if (oForm.ship_lname.value == ""){
		formError('Please enter your Shipping Last Name.', oForm.ship_lname)
		return;
	}
	if (oForm.ship_address1.value == ""){
		formError('Please enter your Shipping Address.', oForm.ship_address1)
		return;
	}
	if (oForm.ship_city.value == ""){
		formError('Please enter your Shipping City.', oForm.ship_city)
		return;
	}
	if (oForm.ship_state.options[oForm.ship_state.selectedIndex].value == ""){
		formError('Please select your Shipping State.', oForm.ship_state)
		return;
	}
	if (oForm.ship_zip.value == ""){
		formError('Please enter your Shipping Zip.', oForm.ship_zip)
		return;
	}
	if (oForm.ship_phone.value == ""){
		formError('Please enter your Shipping Phone.', oForm.ship_phone)
		return;
	}
	if (oForm.email.value.search("@") == -1 || oForm.email.value.search("[.*]") == -1){
		formError('Please enter a valid E-mail Address.', oForm.email)
		return;
	}
	if (oForm.pass1.value == "" || oForm.pass1.value != oForm.pass2.value){
		formError('Please enter matching passwords.', oForm.pass1)
		return;
	}
	
	oForm.submit();
}

function formError(oMsg, oField) {
	alert(oMsg);
	oField.focus();
}

function processKey(f) {
    var keyvalue = window.event.keyCode;
    if (keyvalue==13) f.submit();
}

function addCart(oID) {
	var f = document.forms["product_form"];
	
	if (f.color) {
		if (f.color.options[f.color.selectedIndex].value == "") {
			alert('Please select a color.');
			f.color.focus();
			return;
		} else {
			var col = f.color.options[f.color.selectedIndex].value;
		}
	}
	
	if (f.size) {
		if (f.size.options[f.size.selectedIndex].value == "") {
			alert('Please select a size.');
			f.size.focus();
			return;
		} else {
			var siz = f.size.options[f.size.selectedIndex].value;
		}
	}
	
	location.href = '/shopping_cart.asp?actiontype=add&prod_idno='+oID+'&color='+col+'&size='+siz;
}