// JavaScript Document
function Contactus_Validator()
{

 if (Contactus_Validator1()==true)
  document.Contactus11.submit();
 else
   return false; 		
 }

function Contactus_Validator1()
{
	
if(document.getElementById("fname").value=='')
    {
        alert("Please enter name") ;
		 document.getElementById("fname").focus();
        return false;
     }
	 if(document.getElementById("fname").value!="")
         {
						if(!isAlphabetic(document.getElementById("fname").value))
						{
				  				alert("Name cannot take values other than alphabets");
								document.getElementById("fname").focus();
								return false;
							}
							

			}
 	if(document.getElementById("phone").value=='')
		{
			alert("Please enter phone number") ;
			document.getElementById("phone").focus();
			return false;
		}
	if(!IsNumeric(document.getElementById("phone").value) )
      {
     		 alert("Phone number can accept only numeric values");
			 document.getElementById("phone").focus();
			 return false;
      }
    if(document.getElementById("phone").value!="")
	     {
		     if(!/^[0-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}$/.test(document.getElementById("phone").value))
		           {
			          alert("Please enter phone number in xxx-xxx-xxxx format") ;
			          document.getElementById("phone").focus();
			          return false;
		            }
		 }
 
		if(document.getElementById("email").value=='')
			{
				alert("Please enter email address") ;
				document.getElementById("email").focus();
				return false;
			}
    else
    {
        if(validatemail(document.getElementById("email").value)==false)
        {
		document.getElementById("email").focus();
            return false;
        }
    }
	if(document.getElementById("captcha").value=='')
	{
		
	
		 alert("Please enter black symbols");
		 document.getElementById("captcha").focus();
		 
		 return false;
	}
	
	return true;
	
	
	//alert();
						
	//return (true);
}
function validatemail(str)
{
    var filter = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/ ;
    if(filter.test(str))
        return true;
    else 
    {
        alert("Please enter valid email address");
        return false;
    }
}
function notspace(e)
{
	
	if((event.keyCode==32)&&(document.getElementById(e.id).value.length==0))
    {
		
				return false;
        
     }
}
function isAlphabetic(str)
	// returns true if str is alphabetic
	// that is only A-Z a-z or space
	// returns false otherwise
	// returns false if empty
	{
		var len= str.length;
		if (len==0)
		return false;
		//else
		var p=0;
		var ok= true;
		var ch= "";
		while (ok && p<len)
		{
		ch= str.charAt(p);
		if (  ('A'<=ch && ch<='Z')
		||('a'<=ch && ch<='z')
		||(ch==" ")
		)
		p++;
		else
		ok= false;
		}
		return ok;
	}
	function IsNumeric(str)
{
   var ValidChars = "0123456789-.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < str.length && IsNumber == true; i++) 
      { 
      Char = str.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

	
	
function Contactusnew_Validator()
{

		 if (Contactusnew_Validator1()==true)
	
		  document.Contactusnew1.submit();
		 else
		   return false; 		
 }

function Contactusnew_Validator1()
{
	if(document.getElementById("Name").value=='')
    {
        alert("Please enter name") ;
		 document.getElementById("Name").focus();
        return false;
     }
	 if(document.getElementById("Name").value!="")
         {
						if(!isAlphabetic(document.getElementById("Name").value))
						{
				  				alert("Name cannot take values other than alphabets");
								document.getElementById("Name").focus();
								return false;
							}
							

			}
 	if(document.getElementById("Phone").value=='')
		{
			alert("Please enter phone number") ;
			document.getElementById("Phone").focus();
			return false;
		}
		
		if(!IsNumeric(document.getElementById("Phone").value) )
      {
     		 alert("Phone number can accept only numeric values");
			  document.getElementById("Phone").focus();
			 return false;
      }
	  
    if(document.getElementById("Phone").value!="")
	     {
		     if(!/^[0-9]{1}[0-9]{2}-[0-9]{3}-[0-9]{4}$/.test(document.getElementById("Phone").value))
		           {
			          alert("Please enter phone number in xxx-xxx-xxxx format") ;
			          document.getElementById("Phone").focus();
			          return false;
		            }
		 }
 
		if(document.getElementById("Email").value=='')
			{
				alert("Please enter email address") ;
				document.getElementById("Email").focus();
				return false;
			}
    else
    {
        if(validatemail(document.getElementById("Email").value)==false)
        {
		document.getElementById("Email").focus();
            return false;
        }
    }
	
	
	//fot ArrestedInOther textbox
	
	if(document.getElementById("ArrestedInOther")!=null)
	if((!document.getElementById("ArrestedInOther").disabled) && (document.getElementById("ArrestedInOther").value==''))
	{

	  alert("Please enter County name");
	  document.getElementById("ArrestedInOther").focus();
	  return false;
	}
	
	if(document.getElementById("PreviousDUIdate")!=null)
	if((!document.getElementById("PreviousDUIdate").disabled) && (document.getElementById("PreviousDUIdate").value==""))
	{
	   
	  alert("Please enter prior DUI conviction");
	  document.getElementById("PreviousDUIdate").focus();
	  return false;
	}
	
	if(document.getElementById("ReasonStoppedOther")!=null)
	if((!document.getElementById("ReasonStoppedOther").disabled) && (document.getElementById("ReasonStoppedOther").value==""))
	{
	   
	  alert("Please enter reason");
	  document.getElementById("ReasonStoppedOther").focus();
	  return false;
	}
	
	if(document.getElementById("captcha").value=='')
	{
		
	
		 alert("Please enter black symbols");
		 document.getElementById("captcha").focus();
		 
		 return false;
	}

	
	return true;
	
	
	//alert();
						
	
}

function enableElement(e){
	if(e.name=="ArrestedCounty")
	document.getElementById("ArrestedInOther").disabled=true;
	if(e.name=="previousdui")
	document.getElementById("PreviousDUIdate").disabled=true;
	if(e.name=="ReasonStopped")
	document.getElementById("ReasonStoppedOther").disabled=true;
	}

function enableElement1(){
	
	document.getElementById("ArrestedInOther").disabled=false;
	//if(e.id=="ArrestedInOther"){
	//if(document.getElementById("ArrestedInOther").value=="")
	//{
		//alert("Enter the information");
		//document.getElementById("ArrestedInOther").focus();
		//return false;
	//}}

    }
	
function enableElement2(){
	
		document.getElementById("PreviousDUIdate").disabled=false;
	
}
	
	
	
function enableElement3(){
	
		document.getElementById("ReasonStoppedOther").disabled=false;
	

}
