// JavaScript Document
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function validate_Old()
{
	if(form1.fname.value=="")
	{
		alert("Fill Name..");
		form1.fname.focus();
		return false;
	}
	if(form1.phone.value=="")
	{
		alert("Fill Phone..");
		form1.phone.focus();
		return false;
	}
	if(form1.email.value=="")
	{
		alert("Fill Email..");
		form1.email.focus();
		return false;
	}
	if(form1.subject.value=="")
	{
		alert("Fill Subject..");
		form1.subject.focus();
		return false;
	}
	if(form1.suggestions.value=="")
	{
		alert("Fill Suggestions..");
		form1.suggestions.focus();
		return false;
	}
	if(!IsNumeric(form1.phone.value))
	{
		alert("Fill only numerals in Phone No..");
		form1.phone.focus();
		return false;
	}
	if(!IsEmailValid(form1.email.value))
	{
		alert("Fill Valid Email ID..");
		form1.email.focus();
		return false;
	}
	return true;
}

function validate(){ check="";invalid="";
    if(window.document.form1.fname.value==""){
        check+="Name is manditory field!\n";
    }
    if(window.document.form1.phone.value==""){
        check+="Phone number is manditory field!\n";
    }
    if(window.document.form1.email.value==""){
        check+="Email is manditory field!\n";
    }
    if(window.document.form1.email.value!=""){
		if(!IsEmailValid(window.document.form1.email.value)){
        	invalid="Email is invalid!\n";
		}
    }
    if(window.document.form1.subject.value==""){
        check+="Subject is manditory field!\n";
    }
    if(window.document.form1.suggestions.value==""){
        check+="Must fill in a comment or suggestion!\n";
    }
    if(window.document.form1.strCAPTCHA.value==""){
    	check+="Security Code is manditory field!\n"
    }
    if(check!=""){
        alert("Missing Information:\n"+check);
        return false;
    }
    else if(invalid!=""){
        alert("Invalid Information:\n"+invalid);
        return false;
    }
    return true;
}

function IsEmailValid(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 E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    
		    return false
		 }

 		 return true					
	}