function validateContactoData(frm)
{
if(document.frm.name.value.length==0||document.frm.name.value==null)
	{
	 alert("Nombre should not be blank");
	 document.frm.name.focus();
	 return false;
	}
	else if(document.frm.address.value.length==0||document.frm.address.value==null)
	{
	 alert("Dirección should not be blank");
	 document.frm.address.focus();
	 return false;
	}
	else if(document.frm.telephone1.value.length==0||document.frm.telephone1.value==null)
	{
	 alert("Teléfono should not be blank");
	 document.frm.telephone1.focus();
	 return false;
	}
	else if(!validateEmail(frm))
	{
		return false;
	}
	else if(!validatePhoneNumber(frm))
	{
		 return false;
	}
	
	
	return true;
}

function validatePhoneNumber(frm)
{
	 var phonenumber =document.frm.telephone1.value;
	 var phonenumber2 =document.frm.telephone2.value;
	
		 var validValues="0123456789-";
		 var ind;

		 for (i = 0;  i < phonenumber.length;  i++)
           {
              ch = phonenumber.charAt(i);
              if(validValues.indexOf(ch)== -1)
			   {
				  alert("Invalid Telephone Number");
				  document.frm.telephone1.focus();
				  return false;
			   }
			  
				   
			 
		   }

		for (i = 0;  i < phonenumber2.length;  i++)
           {
              ch = phonenumber2.charAt(i);
              if(validValues.indexOf(ch)== -1)
			   {
				  alert("Invalid Telephone Number");
				  document.frm.telephone2.focus();
				  return false;
			   }
			  
				   
			 
		   }

		   return true;
}

function validateEmail(frm)
{
	
  var addr=document.frm.email.value;
  var man=true;
  var db=true;
	if (addr == '' && man) {
		   if (db) alert('Email should not be blank');
		   document.frm.email.focus();
		   return false;
		}
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			  if (db) alert('Email Address is Invalid');
			  document.frm.email.focus();
			  return false;
		   }
		}
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
			  if (db) alert("Email Address is Invalid");
			  document.frm.email.focus();
			  return false;
		   }
		}

		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (atPos == 0) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (addr.indexOf('@', atPos + 1) > - 1) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (addr.indexOf('.', atPos) == -1) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (addr.indexOf('@.',0) != -1) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (addr.indexOf('.@',0) != -1){
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
		}
		else if (addr.indexOf('..',0) != -1) {
		   if (db) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   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) alert('Email Address is Invalid');
		   document.frm.email.focus();
		   return false;
         }
	
		return true;

}
