function echeck(str)
{

    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1)
    {
       alert("Invalid Email Address")
       return false;
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
       alert("Invalid Email Address");
       return false;
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
        alert("Invalid Email Address");
        return false;
    }

     if (str.indexOf(at,(lat+1))!=-1)
    {
        alert("Invalid Email Address");
        return false;
    }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
        alert("Invalid Email Address");
        return false;
    }

     if (str.indexOf(dot,(lat+2))==-1)
    {
        alert("Invalid Email Address");
        return false;
    }

     if (str.indexOf(" ")!=-1)
    {
        alert("Invalid Email Address");
        return false;
    }

return true;
}

function validate_required(field,alerttxt)
{
    with (field)
    {
        if (value==null||value=="")
            {alert(alerttxt);return false;}
        else {return true}
    }
}

//Validatephone('333-242-4444');
function validate_phone(Phone){

    var error =0;
    //var Phone='333-222-4444';
    var phone_arr = Phone.split("-");
    if(phone_arr[2]== undefined)
    {
        alert('Please enter the phone number in the following format: 713-594-9073')
        return false
    }

    if((isNaN(phone_arr[0])== true)||(isNaN(phone_arr[1])== true)||(isNaN(phone_arr[2])== true) )
    error=1;
    if((phone_arr[0].length!=3) || (phone_arr[1].length!=3)|| (phone_arr[2].length!=4) )
    error =1;

    if(error==1)
    {
        alert('Please enter the phone number in the following format: 713-594-9073')
        return false
    }
    else
    {
        return true;
    }
 }


function validate_signup(thisform)
{	
    with (thisform)
    {
        if (validate_required(thisform.email_signup,"Please provide your email!")==false)
        {
            thisform.email_signup.focus();
            return false;
        } else if (echeck(thisform.email_signup.value)==false)
        {
            thisform.email_signup.value="";
            thisform.email_signup.focus();
            return false;
        }
	
   }
		

}

function validate_contactus(thisform)
{
    with (thisform)
    {
        if (validate_required(thisform.name,"Please provide your name.")==false)
        {
            thisform.name.focus();
            return false;
        } else if (validate_required(thisform.address,"Please provide your address.")==false)
        {
            thisform.address.focus();
            return false;
        }  else if (validate_required(thisform.city,"Please provide your city.")==false)
        {
            thisform.city.focus();
            return false;
        }  else if (validate_required(thisform.state,"Please provide your state.")==false)
        {
            thisform.state.focus();
            return false;
        }  else if (validate_required(thisform.zip,"Please provide your zip code.")==false)
        {
            thisform.zip.focus();
            return false;
        }  else if (validate_required(thisform.phone2,"Please provide your phone number.")==false)
        {
            thisform.phone2.focus();
            return false;
        } else if (validate_phone(thisform.phone2.value)==false)
        {
            thisform.phone2.value="";
            thisform.phone2.focus();
            return false;
        }  else if (validate_required(thisform.email,"Please provide your email.")==false)
        {
            thisform.email.focus();
            return false;
        } else if (echeck(thisform.email.value)==false)
        {
            thisform.email.value="";
            thisform.email.focus();
            return false;
        }  else if (validate_required(thisform.howDidYouHearAboutUs,"Please indicate how you heard about us.")==false)
        {
            thisform.howDidYouHearAboutUs.focus();
            return false;
        }

   }


}






