// JavaScript Document 

function SetSelected() {
	if (document.images && (preloadFlag == true) && (myPage != "") ) {
		var img;
		img = null;
		if (document.layers) {
			img = findElement(changeImages.myPage,0);
		}
		else {
			img = document.images[myPage];
		}
		if (img) {
			img.src = "/nav-images/" + myPage + "-up.gif";
		}
	}
}

function Body_OnLoad() {
	// preload nav rollover images
	// Alert( "About to call preloadImages()..." );
	preloadImages();
	
	// Now call to set the selected image in the rollovers
	SetSelected();

	// Now call any local init on load
	// Alert( "About to call My_Body_OnLoad()..." );
	My_Body_OnLoad();
}

function Body_OnUnLoad() {
	// Now call any local deinit on unload
	My_Body_OnUnLoad();
}


// this funtion validates the wholesale application form

function ValidateWholesaleApplication( form ) {
	
	var buttonName = form.submit.value;
	
	if ( ( form.ownerFirst.value == "" ) && ( form.ownerLast.value == "" )
		&& ( form.managerFirst.value == "" ) && ( form.managerLast.value == "" ) ) {
		alert("Please supply either an owner or manager name before hitting the '" + buttonName + "' button.");
		return false;
		
	} else if ( ( form.storephone.value == "" ) && ( form.mobilephone.value == "" ) ) {
		alert("Please supply either a store or mobile phone before hitting the '" + buttonName + "' button.");
		return false;
		
	} else if ( ( form.emailbilling.value == "" ) && ( form.emailshipping.value == "" ) ) {
		alert("Please supply either a Billing or Shipping email address before hitting the '" + buttonName + "' button.");
		return false;
		
	} else if ( ( form.emailbilling.value != "" ) && ! ( ValidateEmailAddress( form.emailbilling, "billing email", buttonName ) ) ) {
		return false;
		
	} else if ( ( form.emailshipping.value != "" ) && ! ( ValidateEmailAddress( form.emailshipping, "shipping email", buttonName ) ) ) {
		return false;
		
	} else {
		return true;
	}
}

// This fuction validates an email address field -- call it with something like
// form.emailbilling, "Billig Email", form.submit.value )

function ValidateEmailAddress( emailField, fieldName, buttonName ) {

	var atLocation = emailField.value.indexOf("@");
	var periodLocation = emailField.value.lastIndexOf(".");

	if ( emailField.value == "" ) {

		alert("Please supply a " + fieldName + " address before hitting the '" + buttonName + "' button.");
		return false;

	} else if ( emailField.value == "yourname@host.com" ) {

		alert("Please enter a valid " + fieldName + " address before hitting the '" + buttonName + "' button.");
		return false;

	} else if ( ( atLocation == -1 )
		|| ( periodLocation == -1 )
		|| ( atLocation > periodLocation ) ) {

		alert("The " + fieldName + " address does not appear to be a proper email address."
			+ " All email addresses have an '@' character and"
			+ " at least one '.' after the '@'." );
		return false;

	} else {
		return true;
	}
}


