// JavaScript Document

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
 	var checkOK = "~`!#$%^&*()=+|\}{][',?";
  	var checkStr = str;
  	var allValid = true;
   
   var s=0;
		for (i = 0;  i < checkStr.length;  i++)
  		{
			ch = checkStr.charAt(i);
    			if (ch==dot)
    			{
    			s=s+1
    			if (s==1)
    			   var first_dot=i;
    			if (s==2)
    			   var second_dot=i;    
    			}
    			
    			for (j = 0;  j < checkOK.length;  j++)
		   			if (ch == checkOK.charAt(j))
       				    allValid = false;
       				
    				if (j == 54 )
    				{
      				allValid = false;
     				 break;
   					}
 		 }

		if (!allValid)
        {
        alert("Invalid E-mail ID")
        return false
        }
       	
		if (str.indexOf(at)==-1)
		{
		   alert("Invalid E-mail ID")
		   return false
		}
		if (s>3)
		{
		   alert("Invalid E-mail ID")
		   return false
		}


		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}
		//alert(str.indexOf(dot)+'+++'+ (str.length-2))
		if (str.indexOf(dot)>=(str.length-2))
		{
		  alert("Invalid E-mail ID")
		    return false
		}


		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		if (s>1)
		{
         	
          if (first_dot<str.indexOf(at))
          {
          
          if ((first_dot<str.indexOf(at)) && (second_dot>str.indexOf(at)))
		 	{
		     return true
		 	}
         	else
         	{
         	alert("wrongInvalid E-mail ID")
          	return false
         	}
		}}

 		 return true					
	}

		function validateform()
		{
			if (document.feedback.feedcom.value == "")
			{
				alert("Please Enter Your Message");
				return false;
			}
			
		
		}

function toggle_city()
{
	var city = document.getElementById('city');
	if(city.value=='Others')
	{
		document.getElementById('city').style.visibility="visible";
		document.getElementById('citynum').style.visibility="visible";
		document.getElementById('citynun_num').disabled=false;
		document.getElementById('city_num1').display=true;
		document.getElementById('city_num1').style.display=true;
	}
	else {
	document.getElementById('citynum').style.visibility="hidden";
	}
}
function toggle_country()
{
	var country = document.getElementById('country');
	if(country.value=='Others')
	{
		document.getElementById('country').style.visibility="visible";
		document.getElementById('countrynum').style.visibility="visible";
		document.getElementById('countrynun_num').disabled=false;
		document.getElementById('country_num1').display=true;
		document.getElementById('country_num1').style.display=true;
	}
	else {
	document.getElementById('countrynum').style.visibility="hidden";
	}
}
function validation()
{
if(document.contactus.companyname.value=="")
{
alert("Please enter your company name");
document.contactus.companyname.focus();
return false;
}
if(document.contactus.contactname.value=="")
{
alert("Please enter your  name");
document.contactus.contactname.focus();
return false;
}
if(document.contactus.address1.value=="")
{
alert("Please enter your  address");
document.contactus.address1.focus();
return false;
}
if(document.contactus.city.value=="0")
{
alert("Please select your  city");
document.contactus.city.focus();
return false;
}
if((document.contactus.city.value=='Others') &&(document.contactus.city_num1.value==""))
	       {
		      if(document.contactus.city_num1.value==""){
	       alert("Please Enter Your city")
	       document.contactus.city_num1.focus();
	       return false;
		   	       }
		   }
if(document.contactus.country.value=="0")
{
alert("Please select your  country");
document.contactus.country.focus();
return false;
}
if((document.contactus.country.value=='Others') &&(document.contactus.country_num1.value==""))
	       {
		      if(document.contactus.country_num1.value==""){
	       alert("Please Enter Your country")
	       document.contactus.country_num1.focus();
	       return false;
		   	       }
		   }
if(document.contactus.zipcode.value=="")
{
alert("Please enter your  zipcode");
document.contactus.zipcode.focus();
return false;
}

if(document.contactus.phno.value=="")
{
alert("Please enter your phone number");
document.contactus.phno.focus();
return false;
}
if(document.contactus.phno.value!="")
{
if(isNaN(document.contactus.phno.value))
	       {
	       alert("Fill  Phone No. & it should be numeric")
	       document.contactus.phno.focus();
	       return false;
	       }
}
if(document.contactus.altphno.value!="")
{
if(isNaN(document.contactus.altphno.value))
	       {
	       alert("Fill  Phone No. & it should be numeric")
	       document.contactus.altphno.focus();
	       return false;
	       }
}
var emailID=document.contactus.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
if (echeck(emailID.value)==false){
		//emailID.value=""
		emailID.select()
		return false
	}
 
if(document.contactus.comments.value=="")
{
alert("Please enter your Message");
document.contactus.comments.focus();
return false;
}
if(document.contactus.captcha.value=="")
{
alert("Please varify the code");
document.contactus.captcha.focus();
return false;
}	
return true;
}
