// JavaScript Document
function new_check()
{
	var a;
	a=document.news_letter;
	var email=a.news_email;
	if ((email.value==null)||(email.value=="")){

			alert("* Please Enter Email ID"); 

			email.focus();

			return false;

		}else{

			if (div_echeck(email.value)==false){

				email.value="";

				email.focus();

				return false

			}
		}
		return true;
	}

function isString(evt)
      {
       var keynum;
		  if(window.event) // IE
		    {
			   keynum = evt.keyCode;
		    }
		  else if(evt.which) // Netscape/Firefox/Opera
		    {
				  keynum =  evt.which;
		    }
 	     var charCode = (evt.which) ? evt.which : keynum
         if (charCode > 32 && (charCode < 65 || charCode > 90) &&(charCode < 97 || charCode > 122))
            return false;

         return true;
      }
	 
function isNumber(evt)
      {
		 var keynum;
		  if(window.event) // IE
		    {
		   keynum = evt.keyCode;
		    }
		  else if(evt.which) // Netscape/Firefox/Opera
		    {
				  keynum =  evt.which;
		    }
		  var charCode = (evt.which) ? evt.which : keynum
          if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;

      }

	function submitForm() 
	{
		var a;
		a=document.form1;
		var email=a.email;
		if ((email.value==null)||(email.value=="")){
			alert("Please Enter Email ID"); 
			email.focus();
			return false;
		}else{
			if (echeck(email.value)==false){
				email.value="";
				email.focus();
				return false
			}
		}
		if (a.password.value == ''){
			alert(" Please Enter Password"); 
			a.password.focus()
			return false
		}	
		if (a.con_pass.value == '')
		{
			alert("Please Enter Re Password"); 
			a.con_pass.focus();
			return false;
		}
		if(((a.con_pass.value != '') && (a.password.value != '')))
		{
			if(a.con_pass.value != a.password.value)
			{
				alert(" Password dosenot match!!"); 
				a.password.focus();
				return false;
			}
		}
		if(a.name.value == '') 
	     {
			alert(" Please Enter Your Name"); 
			a.name.focus();
			return false;
	     } 
		else
		{
			var DivName;
			DivName ="divName";
			if ((symbol_check(a.name.value,DivName)==false) || (isAlphabet(a.name) == false)){
				alert("Please Enter valid Data");
				a.name.value="";
				a.name.focus();
				return false
			}
		}
		if(a.cname.value == '') 
	     {
			alert("Please Enter Company Name");	
			a.cname.focus();
			return false;
	     } 
		else
		{
			var DivName;
			DivName ="divCompanyname";
			if ((symbol_check(a.cname.value,DivName)==false)){
				alert("Please Enter valid Data");
				a.cname.value="";
				a.cname.focus();
				return false
			}

		}

		if(a.office_address.value != '') 
	     {
			var DivName;
			DivName ="divOffice";
			if ((symbol_check(a.office_address.value,DivName)==false)){
				alert("Please Enter valid Data");
				a.office_address.value="";
				a.office_address.focus();
				return false
			}
		}

		if(a.city.value != '') 
	     {
			var DivName;
			DivName ="divCity";
			if ((symbol_check(a.city.value,DivName)==false) || (isAlphabet(a.city) == false)){
				alert("Please Enter valid Data");
				a.city.value="";
				a.city.focus();
				return false
			}
		}
		if(a.state.value != '') 
	     {
			var DivName;
			DivName ="divState";
			if ((symbol_check(a.state.value,DivName)==false) || (isAlphabet(a.state) == false)){
				alert("Please Enter valid Data");
				a.state.value="";
				a.state.focus();
				return false
			}
		}
		if(a.country.selectedIndex == 0) 
	    {
			alert("Please Select Country"); 
			a.country.focus();
			return false;
	    }
		if (a.phone.value == '') 
	    {
			alert("Please Enter Phone Number"); 
			a.phone.focus();
			return false;
	    }
	    else
	    {
		     var DivName;
			DivName ="divPhone";
			if ((symbol_check(a.phone.value,DivName)==false) || (isNumeric(a.phone) == false)){
				alert("Please Enter Numeric Data");
				a.phone.value="";
				a.phone.focus();
				return false
			}
	    }
		
		if(a.name_owner.value == '') 
	    {
			alert(" Please Enter Company Owner"); 
			a.name_owner.focus();
			return false;
	    }
		else
		{	
			var DivName;
			DivName ="divOwner";
			if ((symbol_check(a.name_owner.value,DivName)==false) || (isAlphabet(a.name_owner) == false)){
				alert("Please Enter Valid Data");
				a.name_owner.value="";
				a.name_owner.focus();
				return false
			}
		}
		if (a.company_year.value == '') 
	    {
			alert(" Please Enter Year of Establishment"); 
			a.company_year.focus();
			return false;
	    }
	    	    else
	    {
		     var DivName;
			DivName ="divCompanyYear";
			if ((symbol_check(a.company_year.value,DivName)==false) || (isNumeric(a.company_year) == false)){
				alert("Please Enter Numeric Data");
				a.company_year.value="";
				a.company_year.focus();
				return false
			}
	    }

		if (a.category.selectedIndex == 0)
		{
			alert(" Please Select Business Category"); 
			a.category.focus();
			return false;
		}

		if (a.category.selectedIndex == 1)
		{
			if (a.membership.selectedIndex == 0)
			{
				alert("Please Select Membership"); 
				a.membership.focus();
				return false;
			}
		}
		
		if(a.desc.value == '') 
		{
			alert("Please Enter Which You offer"); 
			a.desc.focus();
			return false;
		}
		else
		{	var DivName;
			DivName ="divDesc";
			if ((symbol_check(a.desc.value,DivName)==false) || (symbol_check1(a.desc.value,DivName)==false)){
				alert("Please Enter Valid Data");	
				//a.desc.value="";
				a.desc.focus();
				return false
			}
		}
		if(a.desc.value != '') 
		{
			if (a.desc.value.length >350) {
				alert("Your text exceed 350 characters"); 
				a.desc.focus();
				return false;
			}
		}
		if(a.website.value != '') 
	     {
			var DivName;
			DivName ="divWebsite";
			if (symbol_check(a.website.value,DivName)==false){
				a.website.value="http://";
				a.website.focus();
				return false
			}
		}
		
		if(document.getElementById('security_code').value == "") {
			alert("OOPs !! Please Enter Security Code");
			document.getElementById('security_code').focus();
			return false;
		}
	
		if(document.getElementById('cap_code').value != document.getElementById('security_code').value) {
			alert("Security Code Mismatch");
			document.getElementById('security_code').focus();
			return false;
		}	

		
		return true;	
	}

function div_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")

	 //  document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		return false

	}



	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		alert("Invalid E-mail ID")

	  // document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		return false

	}



	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		alert("Invalid E-mail ID")

//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

	  	return false

	}



	 if (str.indexOf(at,(lat+1))!=-1){

		alert("Invalid E-mail ID")

//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		return false

	 }



	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		alert("Invalid E-mail ID")

		return false

	 }



	 if (str.indexOf(dot,(lat+2))==-1){

	   //document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		alert("Invalid E-mail ID")

	     return false

	 }

	

	 if (str.indexOf(" ")!=-1){

	   	//document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 

		alert("Invalid E-mail ID")

	    	return false

	 }



	 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")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	   alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " 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")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	   alert("Invalid E-mail ID")
//	   document.getElementById('divEmail').innerHTML = " Invalid E-mail ID"; 
	    return false
	 }

	 return true					
	}
	var url = "checkSiteUserExist.php?email="; // The server-side script 
	var url1 = "checkSiteUserExist.php?pass="; // The server-side script 

	function handleHttpResponse() {    
		if (http.readyState == 4) { 
				  if(http.status==200) { 
					  var results=http.responseText;
					  if(results != ""){
							document.getElementById("email").value = "";
							document.getElementById("email").focus();
					  		alert(results); 
					  }
				  } 
		 } 
   } 

	function handleHttpResponse1() {
		if (http.readyState == 4) { 
				  if(http.status==200) { 
					  var results=http.responseText;
					  if(results != ""){
							document.getElementById("oldpassword").value = "";
							document.getElementById("oldpassword").focus();
					  } 
					  document.getElementById('divCMSPass').innerHTML = results; 
					  document.getElementById('divOldPassword').innerHTML = ""; 
				  
				  } 
		 } 
    } 
	function CheckSpace(name){
			if(name.indexOf(" ") < 0){
					return true;
			}else {
					alert("Email doesnot contain Space!");
					document.getElementById( "email" ).focus();
					return false;
			} 
	}
	function CheckCMSUserName() {  
	  var sId = document.getElementById("email").value; 
		var notSpace = CheckSpace(sId);
		if(notSpace == true){
			http.open("GET", url + escape(sId), true); 
			http.onreadystatechange = handleHttpResponse; 
			http.send(null); 
		}else {
			document.getElementById("email").value = "";
			document.getElementById("email").focus();	
		}		
   } 

	function CheckCMSPassword() {  
	
	  var sId = document.getElementById("oldpassword").value; 
		if(sId != ''){
			http.open("GET", url1 + escape(sId), true); 
			http.onreadystatechange = handleHttpResponse1; 
			http.send(null); 
		}else {
			document.getElementById("oldpassword").value = "";
			document.getElementById("oldpassword").focus();	
		}		
   } 

	function getHTTPObject() { 
	  var xmlhttp; 
	
	  if(window.XMLHttpRequest){ 
		xmlhttp = new XMLHttpRequest(); 
	  } 
	  else if (window.ActiveXObject){ 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		if (!xmlhttp){ 
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		} 
	} 
	  return xmlhttp; 
	} 
	var http = getHTTPObject(); // We create the HTTP Object 
	function symbol_check(str ,DivName)
	{
			var at = '@';
			if (str.indexOf(at)!=-1){
			return false;
		}
	}

	function symbol_check1(str ,DivName)
	{
			var at = 'www.';
			var http = 'http';
			var com  = '.com';
			if ((str.indexOf(at)!=-1) || (str.indexOf(http)!=-1) || (str.indexOf(com)!=-1)){
			return false;
		}
	}

function name_change()
	{
		if(document.getElementById('name').value != '')
		{
			document.getElementById('name_owner').value = document.getElementById('name').value;
		}
	}
	
function isAlphabet(elem){
	var alphaExp = /^[a-z  . A-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		return false;
	}
}
function isNumeric(elem){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		return false;
	}
}
