/*
Copyright 2004 Active Media Architects, Inc. - www.activema.com
Usage of these scripts is limited to their original intent as developed and deployed for Site Reign Merchant by Active Media Architects, Inc. Copying, selling or distributing of these scripts, in whole or in part, is strictly prohibited.
*/


	///////////////////////////////////////
	// Frame Buster
	///////////////////////////////////////

if (window != window.top)
  top.location.href = location.href;
  
  

	///////////////////////////////////////
	// Mouseovers
	///////////////////////////////////////


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];}
}

  

	///////////////////////////////////////
	// Row-Over Effect
	///////////////////////////////////////

	function mouseOverWhite(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	function mouseOutWhite(i) {
		i.style.backgroundColor='#FFFFFF';
	}
	
	function mouseOverGray(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	function mouseOutGray(i) {
		i.style.backgroundColor='#F2F2F2';
	}
	


	///////////////////////////////////////
	// On-Click-Pop-Center
	///////////////////////////////////////
	// Requires "onClick="NewWindow(this.href,'title','400','300','no');return false;"" in the A HREF tag
	// Example: <a href="doc.html" onClick="NewWindow(this.href,'title','400','300','no');return false;">LINK</a>

function NewWindow(mypage, myname, w, h, scroll) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,,toolbar=yes,menubar=yes'
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}




	///////////////////////////////////////
	// Auto-Select Field
	///////////////////////////////////////
	// Requires "onLoad=ready()" in the BODY tag
	// Example: <body onLoad=ready()>
	// Requires form name to match where it reads "form" in script
	// Example: <form name="form">
	// Requires form field name to match where it reads "field" in script
	// Example: <input name="field">

function ready(){document.form.field.focus();}



	///////////////////////////////////////
	// Form Validation
	///////////////////////////////////////


function validateTell(form) {
	return (
				 checkSelect(form.elements["to_email"],"V","","Please enter your Friend's E-mail Address.",false) &&
				 checkEmail(form.elements["to_email"],false) &&
				 checkSelect(form.elements["to_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["from_email"],"V","","Please enter Your E-mail Address.",false) &&
				 checkEmail(form.elements["from_email"],false) &&
				 checkSelect(form.elements["from_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["from_name"],"V","","Please enter Your Name.",false));
}
function validateTell2(form) {
	return (
				 checkSelect(form.elements["friend_email"],"V","","Please enter your Friend's E-mail Address.",false) &&
				 checkEmail(form.elements["friend_email"],false) &&
				 checkSelect(form.elements["friend_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["my_email"],"V","","Please enter Your E-mail Address.",false) &&
				 checkEmail(form.elements["my_email"],false) &&
				 checkSelect(form.elements["my_email"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please Enter Your Personalized Message.",false));
}
function validateContact(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["message"],"V","","Please provide us with your Message.",false));
}

function validateAffiliate(form) {
	return (
					checkSelect(form.elements["contact_firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["contact_lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["contact_email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["contact_email"],false) &&
				 checkSelect(form.elements["contact_email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["contact_phone"],"V","","Please provide us with your phone number.",false));
}
function validateEmailSignup(form) {
	return (
				 checkSelect(form.elements["firstname"],"V","","Please enter your First Name.",false) &&
				 checkSelect(form.elements["firstname"],"V","First Name","Please enter your real First Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","","Please enter your Last Name.",false) &&
				 checkSelect(form.elements["lastname"],"V","First Name","Please enter your real Last Name.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validateUnsub(form) {
	return (
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false));
}

function validateLogin(form) {
	return (
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["password"],"V","","Please enter your Password.",false));
}
function checkAdvSearch(form) {
	return (
				 checkSelect(form.elements["make"],"V","","Select a Make.",false) &&
				 checkSelect(form.elements["model"],"V","","Select a Model.",false) &&
				 checkSelect(form.elements["year"],"V","","Select a Year",false));
}


function validateNewLogin(form) {
	return (
				
				 checkSelect(form.elements["fullname"],"V","","Please enter your full name in New Account Information.",false) &&
				 checkSelect(form.elements["email"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["email"],false) &&
				 checkSelect(form.elements["email"],"V","joe@example.com","Please supply a valid E-mail Address.",false) &&
				 checkSelect(form.elements["password1"],"V","","Please create a Password.",false) &&
				 checkSelect(form.elements["password2"],"V","","Please confirm your Password.",false));
}

function validatePay(form) {
	return (
				 checkSelect(form.elements["cc_num"],"V","","You have chosen to pay by Credit Card. Please enter your Credit Card Number before continuing.",false) &&
				 checkSelect(form.elements["cc_expires_month"],"V","00","Please select the Month this credit card expires.",false) &&
				 checkSelect(form.elements["cc_expires_year"],"V","00","Please select the Year this credit card expires.",false) &&
				 checkSelect(form.elements["cc_id"],"V","","Please enter your credit card's 3-digit Identification Number.",false));
}

function validatePO(form)
{
	if (
		checkSelect(form.elements["po_number"],"V","","Please enter the PO Number.",false)
	) {
		//the PO was ok - check the shipping
		return validateShippingAddress(form);
	} else {
		//the PO was empty, return false
		return false;	
	}
	
}//end validatePO

function validateSignin(form) {
	return (
				 checkSelect(form.elements["loginemail"],"V","","Please enter your E-mail.",false) &&
				 checkEmail(form.elements["loginemail"],false) &&
				 checkSelect(form.elements["loginemail"],"V","joe@example.com","Please supply valid E-mail Address.",false) &&				 
				 checkSelect(form.elements["password"],"V","","Please enter your Password.",false));
}

function validateBillingAddress(form)
{
	if ( checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing Full Name.",false) &&
		 checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		 checkSelect(form.elements["billing_city"],"V","","Please enter the billing City.",false) && 
		 checkSelect(form.elements["billing_state"],"V","","Please enter the billing State/Prov.",false) && 
		 checkSelect(form.elements["billing_zip"],"V","","Please enter the billing ZIP.",false) && 
		 checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",false)) 
	
	{
		//All billing was ok - check shipping and return it
		
		if ( validateNewLogin(form) ) {
			return validateShippingAddress(form);
		} else {
			return false;
		}
		
	} else {
		//something was false
		return false;	
	}

}//end validateBillingAddress

function validateBillingAddress1(form)
{
	if (
		//checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing First Name.",false) &&
		//checkSelect(form.elements["billing_lastname"],"V","","Please enter the billing Last Name.",false) &&
		checkSelect(form.elements["billing_fullname"],"V","","Please enter the billing Full Name.",false) &&
		checkSelect(form.elements["billing_address"],"V","","Please enter the billing Address.",false) &&
		checkSelect(form.elements["billing_city"],"V","","Please enter the billing City.",false) && 
		checkSelect(form.elements["billing_state"],"V","","Please enter the billing State/Prov.",false) && 
		checkSelect(form.elements["billing_zip"],"V","","Please enter the billing ZIP.",false) && 
		checkSelect(form.elements["billing_phone"],"V","","Please enter the billing Phone.",false) 
		//checkSelect(form.elements["billing_country"],"V","","Please enter the billing Country.",false)
	) {
		//All billing was ok - check shipping and return it
		return validateShippingAddress(form);
		
	} else {
		//something was false
		return false;	
	}

}//end validateBillingAddress

function validateShippingAddress(form)
{
	return (
		/*checkSelect(form.elements["ship_firstname"],"V","","Please enter the shipping First Name.",false) &&
		checkSelect(form.elements["ship_lastname"],"V","","Please enter the shipping Last Name.",false) &&*/
		checkSelect(form.elements["ship_fullname"],"V","","Please enter the shipping full name.",false) &&
		checkSelect(form.elements["ship_phone"],"V","","Please enter the shipping Phone.",false) &&
		checkSelect(form.elements["ship_address"],"V","","Please enter the shipping Address.",false) &&
		checkSelect(form.elements["ship_city"],"V","","Please enter the shipping City.",false) && 
		checkSelect(form.elements["ship_state"],"V","","Please enter the shipping State/Prov.",false) && 
		checkSelect(form.elements["ship_zip"],"V","","Please enter the shipping ZIP.",false)
		//checkSelect(form.elements["ship_country"],"V","","Please enter the shipping Country.",false)
	);
}//end validateShippingAddress

function checkProfile(form)
{
	var arrElements = new Array("fullname","address", "city", "state", "zip");
	var len = arrElements.length;
	var i = 0;
	
	for ( i=0; i<len; i++ ) {
		if ( form.elements['billing_'+arrElements[i]].value != form.elements['hidden_billing_'+arrElements[i]].value ) {
			form.elements['profilecontrol'].value = 'change';	
		}
		
	}//for
	
	//alert(form.elements['profilecontrol'].value);
	
	//and one by hand
	if ( form.elements['cc_type'].value != form.elements['hidden_cc_type'].value ) {
		form.elements['profilecontrol'].value = 'change';
	}
	
	return validateBillingAddress(form);
	
}//end checkProfile

////////////////////////////////////////////////
// disabling and enabling shipping info fields
////////////////////////////////////////////////

function toggleFields(form)
{
	var toggle = form.elements['same_as_billing'];
	
	var arrShipFields = new Array('ship_fullname', 'ship_address', 'ship_city', 'ship_state', 'ship_zip', 'ship_phone');
	var fieldShipCount = arrShipFields.length;
	
	var arrBillFields = new Array('billing_fullname', 'billing_address', 'billing_city', 'billing_state', 'billing_zip', 'billing_phone');
	var fieldBillCount = arrBillFields.length;
	
	var i = 0;
	
	if (toggle.checked == false) {
		//Already checked, unset everything
		for ( i=0; i<fieldShipCount; i++) {
			form.elements[arrShipFields[i]].value = "";
		}//for	
	
	} else {
		//Not yet checked, copy the values from billing
		for ( i=0; i<fieldShipCount; i++) {
			form.elements[arrShipFields[i]].value = form.elements[arrBillFields[i]].value;
		}//for	
	}
	
}//end toggleFields

function toggleSaveProfile(elem) {
	var form = elem.form;
	
	//valid values are insert, donotupdate, and update
	if (elem.checked == true) {
		form.elements['profilecontrol'].value = 'insert';
				
	} else {
		form.elements['profilecontrol'].value = 'donotupdate';
		
	}
	
	//alert(form.elements['profilecontrol'].value);
	
}//end toggleSaveProfile

function checkField() {
	var frm = document.search_store;
	
	if ( (frm.p_keyword.value == "" ) || (frm.p_keyword.value == " " ) ) {
		
		alert("A Keyword is required to search");
		return false;			
	}
	
}


function checkEmailSignup() {

	var frm = document.emailSignup;
	
	if ( (frm.firstname.value == "" ) || (frm.firstname.value == " " ) ) {
		
		alert("First name is required");
		return false;			
	}
	
	if ( (frm.lastname.value == "" ) || (frm.lastname.value == " " ) ) {
		alert("Last name is required");
		return false;	
	}	
	
	if ( (frm.email.value == "") || (frm.email.value == " ") ) {
		
		alert("E-mail is required");
		return false;	
	}
	
	return true;
	
}


function LoginOptionCheck(myself) {

	frm = document.forms['new_login'];
	// if the new Customer item is checked
	var elem_pass_new = document.getElementById('newcustomerpassword');
	var elem_pass_old = document.getElementById('returningcustomerpassword');
	
	if ( myself.value == "new" ) {
		elem_pass_old.disabled = true;
		elem_pass_old.style.display = "none";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "";
			
//		frm.elements['password'].type = "text";
//		frm.elements['password'].value = "You will be asked later";
//		frm.elements['password'].disabled = true;
		frm.elements['action'].value = "account_new";
		
	} else {
	// else if the old customer item is checked
	
		elem_pass_old.disabled = false;
		elem_pass_old.style.display = "";
		elem_pass_new.disabled = true;
		elem_pass_new.style.display = "none";
		
//		frm.elements['password'].value = "";
//		frm.elements['password'].disabled = false;
//		alert(frm.elements['password'].type);
//		frm.elements['password'].type = "password";
		
		
        frm.elements['loginemail'].focus();
		frm.elements['action'].value = "account";
		
	}
	
	frm.elements['loginemail'].focus();
}
function focusLoginField() {
	if ( typeof(document.new_login) != "undefined" ) {
		document.new_login.loginemail.focus();
	}
}


function focusField() {
	if ( typeof(document.Send) != "undefined" ) {
		document.Send.emailto.focus();
	}
}

