/*********
verify cart configuration
*********/
function verifyCartConfig()
{
	//form variables
	submitBtnMessage='Saving... Please Wait';
	formName='formCartConfig'

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

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

	//check the email receipt bcc
	if (submitForm)
	{
		formElement="email_receipt_bcc";
		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 the email receipt from
	if (submitForm)
	{
		formElement="email_receipt_from";
		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 the purchase alert email
	if (submitForm)
	{
		formElement="purchase_alert_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)
	{
		// reset the confirmNavigation variable so that we no longer get the javascript popup
		confirmNavigation=false;
		disableForm(formName,submitBtnMessage);
	}
	//show the alert if submitForm is false
	else
	{
		viewHelp(formElement,formName,warningMessage);
		topMessage(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 coupon submission
*********/
function verifyPurchaseReport(formName)
{
	//form variables
	submitBtnMessage='Saving... Please Wait';

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


	//check the date start
	if (submitForm)
	{
		formElement = "date_start";
		thisDOM = eval('document.' + formName + '.' + formElement);
		//trim the value
		thisDOM.value = trim(thisDOM.value);
		returnAlert = validateDate(thisDOM.value);
		if (returnAlert.length!=0)
		{
			warningMessage=returnAlert;
			formFocus=formElement;
			submitForm=false;
		}
	}

	//check the start time
	if (submitForm)
	{
		formElement="time_start";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//trim the value
		thisDOM.value=trim(thisDOM.value);
		returnAlert=validateTime(thisDOM.value);
		if (returnAlert.length !=0)
		{
			warningMessage=returnAlert;
			formFocus=formElement;
			//reset the form element to the primary one because they are displayed in the same div
			formElement="date_start";
			submitForm=false;
		}
	}

	//check the date end
	if (submitForm)
	{
		formElement="date_end";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//trim the value
		thisDOM.value=trim(thisDOM.value);
		returnAlert=validateDate(thisDOM.value);
		if (returnAlert.length!=0)
		{
			warningMessage=returnAlert;
			formFocus=formElement;
			submitForm=false;
		}
	}
	//check the date end time
	if (submitForm)
	{
		formElement="time_end";
		thisDOM=eval('document.' + formName + '.' + formElement);
		//trim the value
		thisDOM.value=trim(thisDOM.value);
		//check for correct m/dd/yyyy format
		returnAlert=validateTime(thisDOM.value);
		if (returnAlert.length !=0)
		{
			warningMessage=returnAlert;
			formFocus=formElement;
			//reset the form element to the primary one because they are displayed in the same div
			formElement="date_expire";
			submitForm=false;
		}
	}

	// check that date_start+time_start < date_end+time_end
	if (submitForm)
	{
		// create Date() objects
		var arrayFieldnames=new Array("date_start","time_start","date_end","time_end");
		var arrayFormElements=new Array();
		// loop through arrayFieldnames and pull structures
		for(i=0;i <= arrayFieldnames.length;i++)
			arrayFormElements[i]=eval('document.' + formName + '.' + arrayFieldnames[i]);

		// parse dates and create date parts
		// Checks for the following valid date formats:
		// MM/DD/YYYY MM-DD-YYYY
		datePattern = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
		timePattern = /^(\d{1,2}):(\d{2})(\s?(AM|am|PM|pm))$/;
		// apply datePattern to dates/times and build full DateTime values
		// Start DateTime
		matchArray = arrayFormElements[0].value.match(datePattern);
		year=matchArray[4];
		month=matchArray[1];
		day=matchArray[3];
		matchArray = arrayFormElements[1].value.match(timePattern);
		hour=parseInt(matchArray[1]);
		ampm = matchArray[4];
		// check for 12am  and set to 0
		if ((ampm.indexOf('am') > -1) && (hour == 12))
		{
			hour=0;
		}
		//check for pm hours other than 12, and add 12
		if ((ampm.indexOf('pm') > -1) && (hour != 12))
		{
			hour=hour+12;
		}
		minute=matchArray[2];
		second=0;
		dateTimeStart=new Date(year,month,day,hour,minute,second);
		// End DateTime
		matchArray = arrayFormElements[2].value.match(datePattern);
		year=matchArray[4];
		month=matchArray[1];
		day=matchArray[3];
		matchArray = arrayFormElements[3].value.match(timePattern);
		hour=parseInt(matchArray[1]);
		ampm = matchArray[4];
		// check for 12am  and set to 0
		if ((ampm.indexOf('am') > -1) && (hour == 12))
		{
			hour=0;
		}
		//check for pm hours other than 12, and add 12
		if ((ampm.indexOf('pm') > -1) && (hour != 12))
		{
			hour=hour+12;
		}
		minute=matchArray[2];
		second=0;
		dateTimeEnd=new Date(year,month,day,hour,minute,second);
		// compare the dates
		returnAlert=validate2DateTimes(dateTimeStart,dateTimeEnd);
		if (returnAlert.length !=0)
		{
			warningMessage=returnAlert;
			formFocus="date_expire";
			//reset the form element to the primary one because they are displayed in the same div
			formElement="date_expire";
			submitForm=false;
		}
	}

	//disable the form if the form checks out
	if (submitForm)
	{
		//disableForm(formName,submitBtnMessage);
	}
	//show the alert if submitForm is false
	else
	{
		//form element help
		viewHelp(formElement,formName,warningMessage);
		topMessage(warningMessage);
	}

	//focus the form if necessary
	if (formFocus.length > 0)
	{
		//is this a category focus
		if (formFocus == 'categorySelection')
		{
			new Effect.ScrollTo ($('help_categories_id'),{queue: 'front'});
		}
		//form element focus
		else
		{
			thisDOM=eval('document.' + formName + '.' + formFocus);
			thisDOM.focus();
		}
	}


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

/*********
FRONT END FUNCTIONS
*********/

// show pay by check table
function showPayByCheck()
{
	// reset the credit card fields to blank
	$('name_on_card').value = "";
	$('card_number').value = "";
	$('cvc_number').value = "";

	// hide the credit card div
	if ($('paymentDivCreditCard').style.display != "none")
	{
		Effect.SlideUp('paymentDivCreditCard',{duration:0.5});
	}
	// show the check div
	if ($('paymentDivCheck').style.display == "none")
	{
		Effect.SlideDown('paymentDivCheck',{duration:0.5, delay: 0.7});
	}

	// reset the credit card fields to blank
}

// show pay by credit card table
function showPayByCreditCard()
{
	// reset the check fields to blank
	$('name_on_check').value = "";
	$('check_number').value = "";

	// hide the check div
	if ($('paymentDivCheck').style.display != "none")
	{
		Effect.SlideUp('paymentDivCheck',{duration:0.5});
	}
	// show the credit card div
	if ($('paymentDivCreditCard').style.display == "none")
	{
		Effect.SlideDown('paymentDivCreditCard',{duration:0.5, delay: 0.7});
	}
}

// show/hide shipping form
function showShippingAddress()
{
	// only run this if yes is selected on the shipping address option, and it's NOT currently showing
	if (($('shippingAddressDisplay').style.display == "none") && $('different_ship_address_yes').checked)
	{
		Effect.SlideDown('shippingAddressDisplay');
	}
	// only run this if yes is selected on the shipping address option, and it's NOT currently showing
	if (($('shippingAddressDisplay').style.display != "none") && $('different_ship_address_no').checked)
	{
		Effect.SlideUp('shippingAddressDisplay');
	}
}

// calculate the shipping options
function calculateShipping()
{
	displayElement = "shippingOptionsDisplay";

	// determine whether or not we're getting international shipping or not
	if ($('different_ship_address_yes').checked)
	{
		ccode = $('ship_country').value;
		address = $('ship_address_1').value;
		city = $('ship_city').value;
		state = $('ship_state').value;
		zip = $('ship_zip').value;
	}
	else
	{
		ccode = $('bill_country').value;
		address = $('bill_address_1').value;
		city = $('bill_city').value;
		state = $('bill_state').value;
		zip = $('bill_zip').value;
	}

	new Ajax.Request('/ajax/cart.sd?a=calculateShipping&ccode='+ccode+'&address='+address+'&city='+city+'&state='+state+'&zip='+zip, {
		method: 'get',
		// now submit the request
		onSuccess: function(transport) {
			if (transport.responseText.length == 0)
			{
				topMessage("An error has been encountered, please try again.");
			}
			else
			{
				// update the content
				$(displayElement).update(transport.responseText);
				// slide it down
				Effect.SlideDown(displayElement);
			}
		}
	})
}

// clear the shipping options when the country is changed
function clearShippingOptions()
{
	$('shippingOptionsDisplay').update('');
}

function showCVCBox()
{
	Effect.SlideDown('paymentCardCVCBox');
	new Draggable('paymentCardCVCBox');
}

function hideCVCBox()
{
	Effect.SlideUp('paymentCardCVCBox');
}

// confirm the payment input
function confirmPaymentDetails()
{
	submitForm = true;
	message = "";

	// if the credit card form is showing, check it
	if ($('paymentDivCreditCard').style.display != 'none')
	{
		// card_type
		if (submitForm)
		{
			typeSelected = false;
			// loop thru all the shipping radio buttons
			for (i=0; i < document.formPaymentDetails.elements.length; i++)
			{
				if (submitForm)
				{
					// do only the shipping classes
					if (document.formPaymentDetails.elements[i].type == 'radio' && document.formPaymentDetails.elements[i].name == 'card_type' && document.formPaymentDetails.elements[i].checked == true)
					{
						typeSelected = true;
					}
				}
			}
			// if shipping checked is still false, set the message
			if (!typeSelected)
			{
				message = "Please select your credit card type.";
				submitForm = false;
				formField = "";
			}
		}
		// name_on_card
		if (submitForm)
		{
			formField = 'name_on_card';
			$(formField).removeClassName('paymentDisplayAlert');
			if ($(formField).value.length == 0)
			{
				message = "Please type in the full name exactly as it appears on the credit card.";
				submitForm = false;
			}
		}
		// card_number
		if (submitForm)
		{
			formField = 'card_number';
			$(formField).removeClassName('paymentDisplayAlert');
			if ($(formField).value.length == 0)
			{
				message = "Please type in the number of your credit card.";
				submitForm = false;
			}
		}
		// cvc_number
		if (submitForm)
		{
			formField = 'cvc_number';
			$(formField).removeClassName('paymentDisplayAlert');
			if ($(formField).value.length == 0)
			{
				message = "Please type in the cvc number of your credit card.";
				submitForm = false;
			}
		}
		// expiration_month
		if (submitForm)
		{
			formField = 'expiration_month';
			$(formField).removeClassName('paymentDisplayAlert');
			if ($(formField).value == 0)
			{
				message = "Please select your credit card's expiration month.";
				submitForm = false;
			}
		}
		// expiration_year
		if (submitForm)
		{
			formField = 'expiration_year';
			$(formField).removeClassName('paymentDisplayAlert');
			if ($(formField).value == 0)
			{
				message = "Please select your credit card's expiration year.";
				submitForm = false;
			}
		}
	}

	// if the pay by check form is showing, check it
	if ($('paymentDivCheck'))
	{
		if ($('paymentDivCheck').style.display != 'none')
		{
			// check_number
			if (submitForm)
			{
				formField = 'check_number';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0 || /\D+/.test($(formField).value))
				{
					message = "Please type in the check number on your check using numbers only.";
					submitForm = false;
				}
			}
			// name_on_card
			if (submitForm)
			{
				formField = 'name_on_check';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the full name exactly as it appears on your check.";
					submitForm = false;
				}
			}
		}
	}


	// bill_name_first
	if (submitForm)
	{
		formField = 'bill_name_first';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's first name.";
			submitForm = false;
		}
	}
	// bill_name_last
	if (submitForm)
	{
		formField = 'bill_name_last';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's last name.";
			submitForm = false;
		}
	}
	// bill_email
	if (submitForm)
	{
		formField = 'bill_email';
		$(formField).removeClassName('paymentDisplayAlert');
		emailMessage = validateCartEmail($(formField).value);
		if (emailMessage.length > 0)
		{
			message = emailMessage;
			submitForm = false;
		}
	}
	// bill_address_1
	if (submitForm)
	{
		formField = 'bill_address_1';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's address.";
			submitForm = false;
		}
	}
	// bill_city
	if (submitForm)
	{
		formField = 'bill_city';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's city.";
			submitForm = false;
		}
	}
	// bill_state
	if (submitForm)
	{
		formField = 'bill_state';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please select the card holder's state.";
			submitForm = false;
		}
	}
	// bill_zip
	if (submitForm)
	{
		formField = 'bill_zip';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's zip/postal code";
			submitForm = false;
		}
	}
	// bill_country
	if (submitForm)
	{
		formField = 'bill_country';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please select the card holder's country.";
			submitForm = false;
		}
	}
	// bill_phone
	if (submitForm)
	{
		formField = 'bill_phone';
		$(formField).removeClassName('paymentDisplayAlert');
		if ($(formField).value.length == 0)
		{
			message = "Please type in the card holder's phone number";
			submitForm = false;
		}
	}

	// if the shipping option is there, let's see if it's checked
	if ($('different_ship_address_yes'))
	{
		// if $('different_ship_address').checked , then check all the shipping addresses, otherwise, don't worry about it since we're using the billing address.
		if ($('different_ship_address_yes').checked)
		{
			// ship_name_first
			if (submitForm)
			{
				formField = 'ship_name_first';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the shipping recipient's first name.";
					submitForm = false;
				}
			}
			// ship_name_last
			if (submitForm)
			{
				formField = 'ship_name_last';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the shipping recipient's last name.";
					submitForm = false;
				}
			}
			// ship_email
			if (submitForm)
			{
				formField = 'ship_email';
				$(formField).removeClassName('paymentDisplayAlert');
				emailMessage = validateCartEmail($(formField).value);
				if (emailMessage.length > 0)
				{
					message = emailMessage;
					submitForm = false;
				}
			}
			// ship_address_1
			if (submitForm)
			{
				formField = 'ship_address_1';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the shipping address.";
					submitForm = false;
				}
			}
			// ship_city
			if (submitForm)
			{
				formField = 'ship_city';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the city your order is shipping to.";
					submitForm = false;
				}
			}
			// ship_state
			if (submitForm)
			{
				formField = 'ship_state';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please select the state your order shipping to.";
					submitForm = false;
				}
			}
			// ship_zip
			if (submitForm)
			{
				formField = 'ship_zip';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please type in the shipping zip/postal code";
					submitForm = false;
				}
			}
			// ship_country
			if (submitForm)
			{
				formField = 'ship_country';
				$(formField).removeClassName('paymentDisplayAlert');
				if ($(formField).value.length == 0)
				{
					message = "Please select the country your order is shipping to.";
					submitForm = false;
				}
			}
		}

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

	if (message.length > 0)
	{
		alert(message);
		if (formField.length > 0)
		{
			$(formField).addClassName('paymentDisplayAlert');
			$(formField).focus();
			//new Effect.ScrollTo($(formField)); // for some reason this isn't working and is scrolling to the top of the page... why!?
		}
	}

	// confirm that the shipping cost matches the country selected.. or when they select a different country, reset the shipping disply to blank
	return submitForm;
}

// check to see if a coupon is valid
function checkCouponValidity()
{
	// get the coupon code entered
	displayElement = "couponConfirmationMessage";

	couponCode = $('coupon_code').value;

	new Ajax.Request('/ajax/cart.sd?a=checkCouponValidity&coupon='+couponCode, {
		method: 'get',
		// now submit the request
		onSuccess: function(transport) {
			if (transport.responseText.length == 0)
			{
				topMessage("An error has been encountered, please try again.");
			}
			else
			{
				// update the content
				$(displayElement).insert( { bottom: transport.responseText } )
				// slide it down
				//Effect.SlideDown(displayElement);
			}
		}
	})
}

/*********
validates an email address
*********/
function validateCartEmail(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);
			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 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 (make sure you use the '@' symbol).";
				}
			}
		}
		// call the validation function and return its result
		val=emailCheck(thisEmail);
		// if it returns val=no_submit, stop form
	}
	return returnMessage;
}

