/*the base image directory location*/
var base = "/images/";

/*********
pop up a new window
*********/
function openWindow(url,x,y,toolbar,scrollbars,resizable)
{
	new_x=x+20;
	new_y=y+20;
	var options = "toolbar=" + toolbar + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",width=" + new_x + ",height=" + new_y;
	newWindow=window.open(url,"WinOpen",options);
}

/*********
switch an image by changing the src name from 'off' to 'on' and vice versa
*********/
function toggleImage(obj)
{
	// The image is currently in the OFF state
	if (obj.src.indexOf('_off.') < 0)
	{
		obj.src = obj.src.replace('_on', '_off');
	}
	// The image is currently in the ON state
	else
	{
		obj.src = obj.src.replace('_off', '_on');
	}
}

/*********
switch an image with an ID
*********/
function switchImage(thisId,thisImageSlice)
{
	//is the text "_off" inside this btn?
	if (document.getElementById(thisId).src.indexOf('_off.') < 0)
	{
		thisImg=base+thisImageSlice+thisId+'_off.gif';
	}
	else
	{
		thisImg=base+thisImageSlice+thisId+'_on.gif';
	}
	//set the image
	document.getElementById(thisId).src=thisImg;
}

/*********
expand code for both browsers
*********/
function expandIt(whichEl){
	var browser=navigator.userAgent.toLowerCase();
	var pos=browser.indexOf("gecko");
	var myElement = document.getElementById(whichEl);
	//do for Gecko Browsers
	if (pos>=0) {
		if (myElement.style.visibility == 'visible') {
			myElement.style.visibility = 'hidden';
			myElement.style.position = 'absolute';
			}
		else {
			myElement.style.position = 'relative';
			myElement.style.visibility = 'visible';
			}
	//do for IE
	} else {
		myElement.style.display = (myElement.style.display == "none" ) ? "" : "none";
	}
}

/*********
toggle the text inside a form on/off
*********/
function toggleFormText(thisId, thisText)
{
	//alert(document.getElementById(thisId).value + ',' + thisText);
	if (document.getElementById(thisId).value == thisText)
	{
		document.getElementById(thisId).value='';
	}
	else if (document.getElementById(thisId).value == '')
	{
		document.getElementById(thisId).value=thisText;
	}
}

/************
toggleSelectMenus - This function hides all select menus on an html page. In IE the select box is always on top so this function counters that bug by
			   hiding the select boxes so drop down menus aren't trumped. Toggle needs to be either: 'hidden' or 'visible'.
************/
function toggleSelectMenus(toggle) {

	// Loop through all the forms on the page
	for (i=0; i < document.forms.length; i++) {

		// Loop through the form's fields
		for (j=0; j < document.forms[i].length; j++) {

			// Test whether form object is a drop down menu
			if (getFormType(document.forms[i].elements[j]) == 'select') {

				document.forms[i].elements[j].style.visibility = toggle;
			}
		}

	}
}

/************
getFormType - Returns a string name of the type of form object. The types are: select, radio, button, submit, hidden, textarea, text
************/
function getFormType(formObject)
{
	type = formObject.type;

	// Make the select type simpler, we don't care which kind of select as long as it's a select
	if ((formObject.type == 'select-one') || (formObject.type == 'select-multiple'))
		type = 'select';

	return type;
}

/*********
validates an email address
*********/
function validateEmail(thisEmail)
{
	//initiate returnMessage variable
	var returnMessage="";

	if(thisEmail == '')
	{
		// alert the user
		returnMessage = "Please type in a valid email address.";
	}
	else
	{
		// function to check email address vilidity
		function emailCheck(emailStr)
		{
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address.
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			/* The following string represents the range of characters allowed in a
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in john.doe@somewhere.com, john and doe are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat);
			//alert(emailStr);
			var checkMatch='-' + matchArray + '-';
			if (checkMatch == "-null-")
			{
			  /* Too many/few @'s or something; basically, this address doesn't
				 even fit the general mould of a valid e-mail address. */
				returnMessage = "The email address seems incorrect (check @ and .'s).";
			}
			else
			{
				var user=matchArray[1];
				var domain=matchArray[2];

				// See if "user" is valid
				if (user.match(userPat)==null)
				{
					// user is not valid
					returnMessage = "The email's username doesn't seem to be valid (before the @).";
				}

				/* if the e-mail address is at an IP address (as opposed to a symbolic
				   host name) make sure the IP address is valid. */
				var IPArray=domain.match(ipDomainPat)
				if (IPArray!=null) {
					// this is an IP address
					  for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							returnMessage = "The email's destination IP address is invalid.";
						}
					}
				}

				// Domain is symbolic name
				var domainArray=domain.match(domainPat)
				if (domainArray==null) {
					returnMessage = "The email's domain name doesn't seem to be valid (after the @).";
				}

				/* domain name seems valid, but now make sure that it ends in a
				   three-letter word (like com, edu, gov) or a two-letter word,
				   representing country (uk, nl), and that there's a hostname preceding
				   the domain or country. */

				/* Now we need to break up the domain to get a count of how many atoms
				   it consists of. */
				var atomPat=new RegExp(atom,"g")
				var domArr=domain.match(atomPat)
				var len=domArr.length
				if (domArr[domArr.length-1].length<2 ||
					domArr[domArr.length-1].length>4) {
				   // the address must end in a two letter or three letter word.
				   returnMessage = "The email must end in a four-letter domain, three-letter domain, or two letter country.";
				}

				// Make sure there's a host name preceding the domain.
				if (len < 2) {
				   returnMessage="This email is missing a hostname!";
				}
			}
		}
		// call the validation function and return its result
		val=emailCheck(thisEmail);
		// if it returns val=no_submit, stop form
	}
	return returnMessage;
}

/************
verify Contest Form
************/
function verifyContestForm()
{
	//form variables
	submitBtnMessage='Saving... Please Wait';
	formName='formContest';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//check first name
	if (submitForm)
	{
		formElement="first_name";
		thisDOM=eval('document.' + formName + '.' + formElement);

		if (thisDOM.value == "")
		{
			warningMessage='Please type in your first name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check last name
	if (submitForm)
	{
		formElement="last_name";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your last name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check address
	if (submitForm)
	{
		formElement="address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your address.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check city
	if (submitForm)
	{
		formElement="city";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your city.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check state
	if (submitForm)
	{
		formElement="state";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your state.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check country
	if (submitForm)
	{
		formElement="country";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your country.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check zip
	if (submitForm)
	{
		formElement="zip";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your zip.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the email
	if (submitForm)
	{
		formElement="email";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check phone
	if (submitForm)
	{
		formElement="phone";
		thisDOM=eval('document.' + formName + '.' + formElement);
		var re = /\(?\d{3}\)?([-\/\.])\d{3}\1\d{4}/;
		OK = re.exec(thisDOM.value);
		if (!OK)
		{
				warningMessage='Please type in your phone number in the format 555-555-5555.';
				formFocus=formElement;
				submitForm=false;
		}
	}

	//check birth date
	if (submitForm)
	{
		formElement="age";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "" || thisDOM.value == "mm/dd/yyyy")
		{
			warningMessage='Please type in your birth date.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check birth date
	if (submitForm)
	{
		formElement="reference";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please select how you heard about this freakin\' promotion.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Contact Form
************/
function verifyContactForm()
{
	//form variables
	submitBtnMessage='Saving... Please Wait';
	formName='formContact';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//check name
	if (submitForm)
	{
		formElement="name";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the email
	if (submitForm)
	{
		formElement="email_address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}
	//check comment
	if (submitForm)
	{
		formElement="comments";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in a comment.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Newsletter
************/
function verifyNewsletterSubscribe()
{
	//form variables
	submitBtnMessage='Saving... Please Wait';
	formName='formNewsletterSubscribe';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//check name_first
	if (submitForm)
	{
		formElement="emma_member_name_first";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your first name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check name
	if (submitForm)
	{
		formElement="emma_member_name_last";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your last name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the email
	if (submitForm)
	{
		formElement="emma_member_email";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}


	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Send to a Friend
************/
function verifySendToAFriend()
{
	//form variables
	submitBtnMessage='Sending... Please Wait';
	formName='formSendToAFriend';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";
	toEmailFound=false;

	//check friends_emails
	if (submitForm)
	{
		formElement="to_email_1";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in an email address.';
			formFocus=formElement;
			submitForm=false;
		}
		// verify correctly formed email
		else
		{
			// set variable so next function knows a to_email has been found
			toEmailFound=true;
			//check the email address
			thisMessage=validateEmail(thisDOM.value);
			//if there is no message sent back, set the alert.
			if (thisMessage.length != 0)
			{
				warningMessage=thisMessage;
				formFocus=formElement;
				submitForm=false;
				toEmailFound=true;
			}
		}
	}

	//check the second email
	if (!toEmailFound)
	{
		formElement="to_email_2";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in an email address.';
			formFocus="to_email_1";
			submitForm=false;
		}
		// verify correctly formed email
		else
		{
			// set variable so next function knows a to_email has been found
			toEmailFound=true;
			//check the email address
			thisMessage=validateEmail(thisDOM.value);
			//if there is no message sent back, set the alert.
			if (thisMessage.length != 0)
			{
				warningMessage=thisMessage;
				formFocus=formElement;
				submitForm=false;
			}
		}
	}

	//check the third email
	if (!toEmailFound)
	{
		formElement="to_email_3";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in an email address.';
			formFocus="to_email_1";
			submitForm=false;
		}
		// verify correctly formed email
		else
		{
			//check the email address
			thisMessage=validateEmail(thisDOM.value);
			//if there is no message sent back, set the alert.
			if (thisMessage.length != 0)
			{
				warningMessage=thisMessage;
				formFocus=formElement;
				submitForm=false;
			}
		}
	}

	//check from name
	if (submitForm)
	{
		formElement="from_name";
		thisDOM=eval('document.' + formName + '.' + formElement);
		if (thisDOM.value == "")
		{
			warningMessage='Please type in your name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the email
	if (submitForm)
	{
		formElement="from_email";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Wholesale Form
************/
function verifyWholesaleForm()
{
	//form variables
	submitBtnMessage='Submitting Request... Please Wait';
	formName='formWholesale';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//check the title
	if (submitForm)
	{
		formElement="name";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your company name.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the email
	if (submitForm)
	{
		formElement="email_address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}

	//phone
	if (submitForm)
	{
		formElement="phone";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your phone number.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//address
	if (submitForm)
	{
		formElement="address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your address.';
			formFocus=formElement;
			submitForm=false;
		}
	}
	//city
	if (submitForm)
	{
		formElement="city";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your city.';
			formFocus=formElement;
			submitForm=false;
		}
	}
	//state
	if (submitForm)
	{
		formElement="state";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your state.';
			formFocus=formElement;
			submitForm=false;
		}
	}
	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
set the same shipping address
************/
function setSameShippingAddress()
{
	// address
	document.getElementById('ship_address').value=document.getElementById('bill_address').value;
	// city
	document.getElementById('ship_city').value=document.getElementById('bill_city').value;
	// zip
	document.getElementById('ship_zip').value=document.getElementById('bill_zip').value;
	// select the right state
	document.getElementById('ship_state').selectedIndex=document.getElementById('bill_state').selectedIndex;

	calculateTotal();
}

/************
set the shipping costs
************/
function setShippingCosts(thisCost, thisType)
{
	formName = 'formConfirm';
	formElement = "ship_select";

	thisDOM=eval('document.' + formName + '.' + formElement);
	thisFormDOM = eval('document.' + formName);
	for (i=0; i < thisFormDOM.elements.length; i++)
	{
		if (thisFormDOM.elements[i].type == 'radio' && thisFormDOM.elements[i].name == formElement && thisFormDOM.elements[i].checked == true)
		{
			document.getElementById('ship_cost').value = thisCost;
			document.getElementById('ship_type').value = thisType;
		}
	}
	confirmTotal();
}


/************
set number to 2 decimal places
************/
function numberToHundredths(thisNumber)
{
	thisNumberFix = Math.round(thisNumber*100).toString();
	// if the length of the tax amount is only 1 character (1-9 cents), then add a leading zero so it shows up properly.
	if (thisNumberFix.length < 2)
	{
		thisNumberFix = '0' + thisNumberFix;
	}
	thisNumberFix = thisNumberFix.substring(0,thisNumberFix.length-2)+'.'+
	thisNumberFix.substring(thisNumberFix.length-2,thisNumberFix.length);
	return thisNumberFix;
}

/************
calculate all the Totals - for the checkout page
************/
function calculateTotal()
{
	taxAmount=0;
	if (document.getElementById('ship_state').value == 'CA')
	{
			taxAmount=numberToHundredths(document.getElementById('bill_taxable_subtotal').value * .0975);
	}

	// set the tax form field
	document.getElementById('bill_tax').value=taxAmount;
	// show the tax
	if (taxAmount == 0)
	{
		taxAmount = "0.00";
	}

	document.getElementById('taxHTML').innerHTML=taxAmount;
	// get the subtotal
	subtotal=document.getElementById('bill_subtotal').value;
	// get the shipping cost
	//shipping=document.getElementById('ship_cost').value;
	// set the total

	total=parseFloat(taxAmount) + parseFloat(subtotal);

	// set the total field
	document.getElementById('bill_total').value=total;
	// show the total
	document.getElementById('totalHTML').innerHTML=numberToHundredths(total);
}

/************
confirm the Totals - for the confirmation page
************/
function confirmTotal()
{
	shipping = parseFloat(document.getElementById('ship_cost').value);
	total = parseFloat(document.getElementById('bill_total_original').value);
	total = total + shipping;
	// show the total
	document.getElementById('totalHTML').innerHTML = numberToHundredths(total);
	document.getElementById('shipCost').innerHTML = numberToHundredths(shipping);
}

/************
verify Shopping Cart Cart
************/
function verifyCart()
{
	//form variables
	submitBtnMessage = 'Submitting Request... Please Wait';
	formName = 'formQty';
	wholeNumber = /\D/;

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//check quanitities
	if (submitForm)
	{
		// Loop through all the items within the cart form (length -3 because there are always 2 submit buttons and a hidden field)
		for (i=0; i < (document.formQty.length-3) && submitForm; i++)
		{
			// get the item's quantity text field name
			formElement = document.formQty[i].name;

			thisDOM=eval('document.' + formName + '.' + formElement);

			// Quantity must be a whole number (no letters or special characters) that is 0 or greater
			if (wholeNumber.exec(thisDOM.value) || thisDOM.value < 0)
			{
				warningMessage='Quantity must be a whole, positive number without letters or special characters.';
				formFocus=formElement;
				submitForm=false;
			}
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
		thisDOM.select();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Checkout Form
************/
function verifyCheckoutForm()
{
	//form variables
	submitBtnMessage='Submitting Request... Please Wait';
	formName='formCheckout';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";

	//card type
	// Payment Type
	if (submitForm)
	{
		elementChecked = false;
		formElement="bill_cardtype";
		i = 0;
		thisDOM = eval('document.' +formName + '.' + formElement);

		// loop through each item and see if any of them are checked
		while (!elementChecked && (i < thisDOM.length))
		{
			if (thisDOM[i].checked)
			{
				elementChecked = true;
			}
			i++;
		}
		// if no element was checked, set message
		if (!elementChecked)
		{
			warningMessage='Please select your card type.';
			submitForm=false;
		}
	}

	// bill_name_first
	if (submitForm)
	{
		formElement="bill_name_first";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in the first name on your credit card.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	// bill_name_last
	if (submitForm)
	{
		formElement="bill_name_last";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in the last name on your credit card.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//cardNumber
	if (submitForm)
	{
		formElement="bill_cardnumber";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your credit card number.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_cvc
	if (submitForm)
	{
		formElement="bill_cvc";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your CVC (card verification number).';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_expiration_month
	if (submitForm)
	{
		formElement="bill_expiration_month";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please select the month your credit card expires.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_expiration_year
	if (submitForm)
	{
		formElement="bill_expiration_year";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please select the year your credit card expires.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_address
	if (submitForm)
	{
		formElement="bill_address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your billing address.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_city
	if (submitForm)
	{
		formElement="bill_city";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your billing city.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_state
	if (submitForm)
	{
		formElement="bill_state";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please select your billing state.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_zip
	if (submitForm)
	{
		formElement="bill_zip";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your billing zip.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//bill_phone
	if (submitForm)
	{
		formElement="bill_phone";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your billing phone number.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	// bill_email
	if (submitForm)
	{
		formElement="bill_email";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//check the email address
		thisMessage=validateEmail(thisDOM.value);
		//if there is no message sent back, set the alert.
		if (thisMessage.length != 0)
		{
			warningMessage=thisMessage;
			formFocus=formElement;
			submitForm=false;
		}
	}

	//ship_address
	if (submitForm)
	{
		formElement="ship_address";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your shipping address.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//ship_city
	if (submitForm)
	{
		formElement="ship_city";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your shipping city.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//shipState
	if (submitForm)
	{
		formElement="ship_state";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please select your shipping state.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//ship_zip
	if (submitForm)
	{
		formElement="ship_zip";
		thisDOM=eval('document.' + formName + '.' + formElement);
		// make sure this value has a non-space character in it.
		if (thisDOM.value.search(/\S/) == -1)
		{
			warningMessage='Please type in your shipping zip.';
			formFocus=formElement;
			submitForm=false;
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}

/************
verify Confirmation Form
************/
function verifyConfirmForm()
{
	//form variables
	submitBtnMessage = 'Submitting Request... Please Wait';
	formName = 'formConfirm';

	//initialize submitForm value
	submitForm=true;
	warningMessage="";
	formFocus="";
	shippingSelected = false;

	// confirm that a shipping cost is selected
	if (submitForm)
	{
		shippingChecked = false;
		if (document.formConfirm.ship_select)
		{
			// loop thru all the shipping radio buttons
			for (i=0; i < document.formConfirm.elements.length; i++)
			{
				if (submitForm)
				{
					// do only the shipping classes
					if (document.formConfirm.elements[i].type == 'radio' && document.formConfirm.elements[i].name == 'ship_select' && document.formConfirm.elements[i].checked == true)
					{
						shippingChecked = true;
					}
				}
			}
			// if shipping checked is still false, set the message
			if (!shippingChecked)
			{
				warningMessage = "Please select the shipping method for your products.";
				submitForm = false;
			}
		}
		// it doesn't exist, so make sure that we force them to calculate shipping
		else
		{
			warningMessage = "Please select the shipping method for your products.";
			submitForm = false;
			calculateShipping();
		}
	}

	//disable the form if the form checks out
	if (!submitForm)
	{
		alert(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		thisDOM=eval('document.' + formName + '.' + formFocus);
		thisDOM.focus();
	}

	//return the boolean value whether or not we should submit this form
	return submitForm;
}


// loop thru all links in the page, and disable them only if not media library
function disableAllLinks ()
{
	for (var i=0; i < document.links.length; i++)
	{
		document.links[i].onclick=function () { return false; };
		document.links[i].title="All links are disabled while previewing a document.";
	}
	return true;
}
// loop thru all forms in the page, and disable them
function disableAllFormElements ()
{
	for (var i=0; i < document.forms.length; i++)
	{
		for (var j=0; j < document.forms[i].length; j++)
		{
			document.forms[i].elements[j].disabled = true;
		}
		document.forms[i].onfocus = function () {return false; };
		document.forms[i].onclick = function () { return false; };
		document.forms[i].title="All forms are disabled while previewing a document.";
	}
	return true;
}
