

function emailExists(email)
{
 if(XMLHttpRequestObject)
  {
 		XMLHttpRequestObject.open("GET", "http://localhost/check_email.php?email="+email);
		XMLHttpRequestObject.onreadystatechange = function()
		{
		 if (XMLHttpRequestObject.readyState == 4 &&
		 				XMLHttpRequestObject.status == 200)
		 {
  	 	return (XMLHttpRequestObject.responseText);
		 }
    }
  XMLHttpRequestObject.send(null);
 }
 
}
function validateEmail(addr,id,man,db) {
if (addr == '' && man) {
   if (db) {
	 		document.getElementById(id).innerHTML="please enter your email address";
	 }
   return false;
}
if (addr == '') return true;
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db){
	 		document.getElementById(id).innerHTML="email address contains invalid characters";
	 }
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db){
	 		document.getElementById(id).innerHTML="email address contains non ascii characters";
	 }
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db){
	 		document.getElementById(id).innerHTML="email address must contain @";
	 }
   return false;
}
if (atPos == 0) {
   if (db){
	 		document.getElementById(id).innerHTML="email address must not start with @";
	 }
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db){
	 		document.getElementById(id).innerHTML="email addres must contain one @";
	 }
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) {
	 		document.getElementById(id).innerHTML="email address must contain a period in the domain name";
	 }
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) {
	 		document.getElementById(id).innerHTML="a period must not follow @";
	 }
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db){
	 		document.getElementById(id).innerHTML="a period must not imediately preceed @ ";
	 }
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) {
	 		document.getElementById(id).innerHTML="two periods must not be adjacent to each other";
	 }
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) {
	 		document.getElementById(id).innerHTML="invalid primary domain in the email address";
	 }
   return false;
}
/*if (emailExists(addr))
{
 	 if(db){
	 document.getElementById(id).innerHTML="email address already exists.";
	 }
	 return false;
}*/
document.getElementById(id).innerHTML="";

return true;
}


function isNumber(val)
{
 		if (isNaN(val))
		{
		 	 return false;
		 }
		 else
		 return true;
}


function is_Empty(prop,value,id,man,db)
{

 if ((value=="") && man)
 {
 		if(db){
					 document.getElementById(id).innerHTML="please enter a value for "+ prop;
			}
		return true;
		
 }
 				 document.getElementById(id).innerHTML="";
				 return false;
}

function checkSelect(select,othId)
{
	var selected=select.options[select.selectedIndex].text;
	if((selected=="Other")||(selected=="Others"))
	{
		document.getElementById(othId).style.display="block";
	}
	else
		document.getElementById(othId).style.display="none";

	return true;		
}

function toggle(e,id1,id2)
{
	
		document.getElementById(id1).disabled=!document.getElementById(id1).disabled;
		document.getElementById(id2).disabled=!document.getElementById(id2).disabled;
		if(!document.getElementById(id2).disabled)
			document.getElementById(id2).style.display="inline";
		else	
			document.getElementById(id2).style.display="none";
	
}

function validatePhone(no,id,man,db)
{
 	 if(no==""&& man){
	 		if (db){
	 			 document.getElementById(id).innerHTML="please enter your contact number";
	 			 }
   		return false;
	 }
 	 if (isNaN(no))
 	 {
	 		 if(db){
			 document.getElementById(id).innerHTML="only digits are allowed in the contact number";						
			 	}
			return false;
 	 	
 	 }
	 document.getElementById(id).innerHTML="";
	 return true;
 	 		
	
}
function checkPercentage(prop,value,id,man,db)
{
	if ((value=="") && man)
 		{
 		if(db){
					 document.getElementById(id).innerHTML="please enter a value for "+ prop;
			}
		return flase;
	}
	if(isNaN(value))
			{
				 document.getElementById(id).innerHTML="please enter a number between 0 and 100";
				 return false;
			}
			else
		if(!((value>=0) &&(value<=100)))	
			{
				 document.getElementById(id).innerHTML="please enter a number between 0 and 100";
				 return false;
			}
		
	document.getElementById(id).innerHTML="";
	return true; 
 }
