

function CheckForm()
{
	bgok = "#E5E7ED";		
	bgerr = "#B9C4E0";	
	FormHead = "===========\n----Form Error----\n===========\n"
	jsName = document.EmailSubmission.frmCampaignName.value;
	jsTelephone = document.EmailSubmission.frmCampaignTelephone.value;
	jsEmail = document.EmailSubmission.frmCampaignEmailAddress.value;
	/////////////////////////////////////////////////////////Added for changes in Coming Soon form//////////////////////////
	jsConfirmEmail=document.EmailSubmission.frmConfirmEmail.value;
	/////////////////////////////////////////////////////////Added for changes in Coming Soon form//////////////////////////
	
	if(jsName.length < 2)
	{
		raiseerror(document.EmailSubmission.frmCampaignName,"Please enter your name.")
		return false;
	}
    if(trim(jsEmail)=="")
	{
		raiseerror(document.EmailSubmission.frmCampaignEmailAddress,"Please enter your email address.")
		return false;
	}
	if(!CheckEmail(trim(jsEmail)))
	{
		raiseerror(document.EmailSubmission.frmCampaignEmailAddress,"Please enter your email address in the correct format.")
		return false;
	}

/////////////////////////////////////////////////////////Added for changes in Coming Soon form//////////////////////////
    if(trim(jsConfirmEmail)=="")
	{
		raiseerror(document.EmailSubmission.frmConfirmEmail,"Please confirm your email address.");
		return false;
	}        
	else if(trim(jsEmail.toUpperCase())!=trim(jsConfirmEmail.toUpperCase()))
	{
		raiseerror(document.EmailSubmission.frmConfirmEmail,"Please make sure the two email addresses match.");
		return false;
	}
	
/////////////////////////////////////////////////////////Added for changes in Coming Soon form//////////////////////////
    if(trim(jsTelephone)=="")
	{
		raiseerror(document.EmailSubmission.frmCampaignTelephone,"Please enter your phone number.");
		return false;
	}        	
	if(checkForNumber(trim(jsTelephone))==false)
	{
		raiseerror(document.EmailSubmission.frmCampaignTelephone,"Please check the phone number entered. The number entered is not valid.")
		return false;
	}
	else if(trim(jsTelephone).length < 11)
	{
	    raiseerror(document.EmailSubmission.frmCampaignTelephone,"Please check the phone number entered. The number entered is not valid.")
		return false;
	}
	
    if(trim(jsTelephone).length > 16)
    {
        document.EmailSubmission.action = "../";
	}
	else
	{
	    document.EmailSubmission.action = "../Extra/InsertBuyLater.asp";
	}
	document.EmailSubmission.submit();
}
function CheckEmail(toCheck)
    {
	//var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
	var objRegExp  = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/;
	
	//check for valid strEmail
	return objRegExp.test(toCheck);
    }
function raiseerror(frmobj,strerror)
	{
	FormHead = "===========\n----Form Error----\n===========\n"
	alert(FormHead + strerror)
	frmobj.focus();
	colorChg(frmobj, bgerr);
	}
function colorChg(FormItem, ItemColor)
	{
		if(FormItem.style) FormItem.style.backgroundColor = ItemColor;
	}

function trim(stringToTrim) 
    {
	    return stringToTrim.replace(/^\s+|\s+$/g,"");
    }

function checkForNumber(NumText)
   {
	lenNum = NumText.length;
	for(i=0; i<lenNum; i++)
	{

		if(NumText.charAt(i)<'0' || NumText.charAt(i)>'9')
		{

			return false;
			break;

		}
	}

	return true;
}
