// JavaScript Document
function validate() { 

var var1 = document.getElementById('company'); 
var var4 = document.getElementById('first_name');
var var5 = document.getElementById('phone');
var var7 = document.getElementById('email'); 
var var11 = document.getElementById('zip');

//var message = false;

	if(var1.value == "") {
	
		alert("Please Enter Company Name");
		return false;
		//message = true;
	}
	else if(var4.value == "") {
	
		alert("Please Enter First Name");
      		return false;
			//message = true;
	}
	else if(isNaN(var5.value) || var5.value == "") {
		alert("Ony integers allowed in Phone.");
		return false;
	}
	else if (var7.value==null||var7.value==""){
		alert("Please Enter your Email ID.");
		return false;
	} 
	else if (echeck(var7.value)==true){
		return false;
	}	
	else if (var11.value==null||var11.value==""){
		alert("Please Enter your Zip Code.");
		return false;
	} 
	else 
	return true;
	
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 E-mail ID")
		  // message = true;
		  return true;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   //message = true;
		   return true;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    //message = true;
			return true;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		  //  message = true;
		  return true;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		   // message = true;
		   return true;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		  //  message = true;
		  return true;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		 //   message = true;
		 return true;
		 }

 						
	}	
	
/*	if(message == true) { 
		return false;
	} 
	else { 
		return true;
	}
	*/

}


// second validation 

function secondvalidate() { 

var var1 = document.getElementById('company'); 
var var3 = document.getElementById('first_name');
var var5 = document.getElementById('phone');
var var6 = document.getElementById('email');
var var9 = document.getElementById('00N20000002MUem'); // Event Postcode
var var10 = document.getElementById('00N20000002MUfe'); // Event State

//var message = false;

	if(var1.value == "") {
	
		alert("Please Enter Company Name");
		return false;
		//message = true;
	}
	else if(var3.value == "") {
	
		alert("Please Enter First Name");
      		return false;
			//message = true;
	}
	else if(isNaN(var5.value) || var5.value == "") {
		alert("Ony integers allowed in Phone.");
		return false;
	}
	else if (var6.value==null||var6.value==""){
		alert("Please Enter your Email ID.");
		return false;
	} 
	else if (echeck(var6.value)==true){
		return false;
	} 
	else if (var9.value==null||var9.value==""){
		alert("Please Enter Postcode.");
		return false;
	}
	
	else if (var10.value==0||var10.value==""){
		alert("Please Enter your State.");
		return false;
	} 
	else 
	return true;
	
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 E-mail ID")
		  // message = true;
		  return true;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID");
		   //message = true;
		   return true;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID");
		    //message = true;
			return true;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID");
		  //  message = true;
		  return true;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID");
		   // message = true;
		   return true;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID");
		  //  message = true;
		  return true;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID");
		 //   message = true;
		 return true;
		 }

 						
	}	
	
/*	if(message == true) { 
		return false;
	} 
	else { 
		return true;
	}
	*/

}
