function check_get_mailing_list_info(theForm)
{
	if( is_email_valid(theForm.required_email.value) )
	{
		return true;
	}
	else
	{
		alert("The email address you provided is not valid.\n(eg. myemail@mydomain.com)\n\nPlease enter a valid email address");	
		theForm.required_email.focus();
		return false;
	}
}



// Validate the Mailing List Form
function check_mailing_list(theForm)
{
	var num_chars = 3;
	
	// Make sure they are adding themselves to something.
	if( theForm.isupdate.value == "0" )
	{
	
		if( !theForm.el.checked && !theForm.ml.checked )
		{
			alert("You must choose to be added to the Email List and/or the Snail Mail List\n\nCheck either Email List and/or Snail Mail List to add yourself to that mailing list.");
			theForm.el.focus();
			return false;
		}
	}
	
	var ret = check_req(theForm);
	if( !ret )
		return false;
	
		
	ret = is_email_valid(theForm.required_email.value);
	if( !ret )
	{
		alert("Your return email address is not valid (usually it is in the email@mydomain.com format).\nPlease enter your current email address in the field named \"Email\"");
		theForm.required_email.focus();
			
		return false;
	}
	
	// Check required snail mail fields....
	if( theForm.ml.checked )
	{
		for (i = 0; i < theForm.length; i ++) 
		{
			
			var tempobj = theForm.elements[i];
			if (tempobj.name.substring(0,num_chars) == "ml_") 
			{
					
				shortFieldName = tempobj.name.substring(num_chars).toUpperCase();
				shortFieldName = Replace(shortFieldName, "_", " ");
				if ( tempobj.value == '' ) 
				{
					alert("Please enter a value in the field named:\n" + shortFieldName);
					return false;  // STOP FORM SUBMIT HERE, NO NEED TO CONTINUE
		   		}
		   	}
			   	
		}
	}
	
	return true;
}


// Validate the Contact Form 
function check_contact_req(theForm)
{
	var ret = check_req(theForm);
	
	if( !ret )
		return false; // stop here.
		
	// otherwise check email..
	
	ret = is_email_valid(theForm.required_email.value);
	
	if( !ret )
	{
		alert("Your return email address is not valid (usually it is in the email@mydomain.com format).\nPlease enter your current email address in the field named \"Your Email\" so that the contact may respond.\n\nMessage Not Sent!!\n");
		theForm.required_email.focus();
		
		return false;
	}
	
	return true;
		
	
}

function check_send_email(theForm)
{
	var ret = check_req(theForm);
	var email_good = true;
	var arr;
	
	if( !ret )
		return false; // Stop form
		
	if( theForm.testonly.value == "1" )
	{
		// Check test email
		if( !is_email_valid(theForm.testemailaddr.value) )
		{
			alert("The email provided for the test email is not valid\nPlease provide a valid email address\n\nTest Not Sent");
			theForm.testemailaddr.focus();		
			return false;
		}
		
	}
	
	
	if( !confirm("Are you sure you want to send these mass emails?") )
		return false;
	
		
	// Everything is cool... Send....
	return true;
}


/**
* Check that required_ fields have 
* a value... 
**/

function check_req(which)
{
	var pass = true;
	var num_chars = 9;
	var lcase_name = "";
	var shortFieldName = "";
	
	for (i = 0; i < which.length; i ++) 
	{
		
		var tempobj = which.elements[i];
		if (tempobj.name.substring(0,num_chars) == "required_") 
		{
			
			shortFieldName = tempobj.name.substring(num_chars).toUpperCase();
			shortFieldName = Replace(shortFieldName, "_", " ");
			if ( tempobj.value == '' ) 
			{
				alert("Please enter a value in the field named:\n" + shortFieldName);
				return false;  // STOP FORM SUBMIT HERE, NO NEED TO CONTINUE
	   		}
	   	}
	   	
	}
	
	return true;
}

/**
* Email address validation functions...
**/

function is_email_valid(strEmail)
{
	arr = strEmail.split("@");
			
	if( arr.length != 2 )
	{
		return false;
	}
	else if( !valid_domain( arr[1] ) )
	{
		return false;
	}
	else if( !valid_email_name(arr[0]) )
	{
		return false;
	}
		
	return true;
}

function valid_domain(strDomain)
{
	// These the only valid characters allowed in a domain name...
	// besides periods...
	var i = 0;
	//strDomain = strDomaun.toLowerCase();
	var arr = strDomain.split(".");
	
	if( arr.length < 2 )
	{
		return false;
	}
	
	for( i = 0; i < arr.length; i++ ) 
	{
		if( !valid_domain_field( arr[i] ) ) 
		{
			return false;
		}	
	}

	return true;
}

function valid_domain_field(strField)
{
	var valid = "abcdefghijklmnopqrstuvwxyx0124567890-";
	var i = 0, m = 0;
	var isValid = false;
	
	strField = strField.toLowerCase();
	
	if( strField == "" )
		return false; // if period get are together to at end or beginning, there will be blanks
		
	for( i = 0; i < strField.length; i++ )
	{
		isValid = false;
		for( m = 0; m < valid.length; m++ )
		{
			if( strField.charAt(i) == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}
		if( !isValid )
			return false;
	}
	
	return true;
}

function valid_email_name(strName)
{
	var valid = "abcdefghijklmnopqrstuvwxyz0123456789-_.";
	var isValid = false;
	var i = 0;
	var m = 0;
	var c;
	
	strName = strName.toLowerCase();
	
	if( strName == "" )
		return false; // Bad @ placement...
	
	for( i = 0; i < strName.length; i++ )
	{
		
		c = strName.charAt(i);
		isValid = false
		for( m = 0; m < valid.length; m++ )
		{
			if( c == valid.charAt(m) )
			{
				isValid = true;
				break;
			}
		}
	
		if( !isValid )
			return false;
		
	}
	return true;
}

/**
* String replacement function..
**/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;
	
	while( ( a = temp.indexOf(Find) ) > -1 )
	{
		temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}
function OnChangeShipSameAsOrd()
{
	// Disables Shipping fields if the "Shipping info is same as billing" checkbox is checked
	if (document.frmPayment.shipSameAsOrd.checked == true)
	{
		dControl = true
	}
	else
	{
		dControl = false
	}
	DisableControl(document.frmPayment.shipName, dControl)
	DisableControl(document.frmPayment.shipEmailAddress, dControl)
	DisableControl(document.frmPayment.shipPhoneNumber, dControl)
	DisableControl(document.frmPayment.shipAddress1, dControl)
	DisableControl(document.frmPayment.shipAddress2, dControl)
	DisableControl(document.frmPayment.shipCity, dControl)
	DisableControl(document.frmPayment.shipProvince, dControl)
	DisableControl(document.frmPayment.shipPostalCode, dControl)
	DisableControl(document.frmPayment.shipCountry, dControl)
}
function DisableControl(objName, dControl)
{
	// Disables a form object
	if (dControl == true)
	{
		objName.disabled = true
		objName.style.background = "E5E5E5"
	}
	else
	{
		objName.disabled = false
		objName.style.background = "FFFFFF"
	}
}

function autoSubmit(){
     document.form.submit();
} 

function checkrequired(which) {

var pass = true;
var num_chars = 9;

if (document.images) {

	for (i = 0; i < which.length; i ++) {
	var tempobj = which.elements[i];

		if (tempobj.name.substring(0,num_chars) == "required_") {
			if (((tempobj.type == "text" || tempobj.type == "textarea") &&
				tempobj.value == '') || (tempobj.type.toString().charAt(0) == "s" &&
				tempobj.selectedIndex == 0)) {
				pass = false;
				break;
      }
    }
  }
}

if (!pass) {
	shortFieldName = tempobj.name.substring(num_chars,30).toUpperCase();
	alert("Please enter a value in the " + shortFieldName + " field.");
	return false;
}
else
	return true;
}// end function