﻿// JScript File
function validateContactInfo(e, frmPage, txtName, txtEmailPhone, txtContactTime)
{
    var iKey;

    if (!e) {e = window.event;}
    iKey = e.keyCode;
    if (iKey == null) {iKey = e.which;}     //older firefox, opera
    
    //peform search only if key press is an enter
    if (iKey == 13)
    {    
        e.returnValue = false;      //cancel the event
        e.cancelBubble = true;      //cancel event bubbling to form submit
        if (e.stopPropagation) {e.stopPropagation();}
        validateContactFields(frmPage, txtName, txtEmailPhone, txtContactTime);
    }
    
    return false;
}

function validateContactFields(frmPage, txtName, txtEmailPhone, txtContactTime)
{

    if ((txtName == null) || (txtName == ""))
    {
		alert("Please supply your name.");
		return;
    }
    else
    {
        //check for restricted characters
        if (txtName.indexOf("<") > -1)
        {
            alert("The character sequence '<' is not allowed in your name.");
            return;
        }
        
        if (txtName.indexOf(">") > -1)
        {
            alert("The character sequence '>' is not allowed in your name.");
            return;
        }
    }

    if ((txtEmailPhone == null) || (txtEmailPhone == ""))
    {
		alert("Please supply an email address or a phone number that we can contact you at.");
		return;
    }
    else
    {
        //check for restricted characters
        if (txtEmailPhone.indexOf("<") > -1)
        {
            alert("The character sequence '<' is not allowed in the email/phone field.");
            return;
        }
        
        if (txtEmailPhone.indexOf(">") > -1)
        {
            alert("The character sequence '>' is not allowed in the email/phone field.");
            return;
        }
    }

/*
// this field isn't a required field anymore

    if ((txtContactTime == null) || (txtContactTime == ""))
    {
        alert("Please supply the best time to contact you.");
		return;
	}
	else
	{
		//check for restricted characters
        if (txtContactTime.indexOf("<") > -1)
        {
            alert("The character sequence '<' is not allowed in the best time field.");
            return;
        }
        
        if (txtContactTime.indexOf(">") > -1)
        {
            alert("The character sequence '>' is not allowed in the best time field.");
            return;
        }
    }
*/

    frmPage.submit();
}

