function IsEmail(sMail)
{
	var iLastPos = sMail.length - 1;
	for (var iPos = 0; iPos <= iLastPos; iPos++)
	  if (sMail.charAt(iPos) < "!" || sMail.charAt(iPos) > "~")
		return false;
	  iPos = sMail.indexOf("@");
	  if (iPos < 1 || iLastPos == iPos || sMail.charAt(iLastPos) == "." || sMail.indexOf("@", iPos + 1) >= 0 || sMail.indexOf(".", iPos + 1) < iPos + 2)
		 return false;
	  return true;
}

var letras=' ABCÇDEFGHIJKLMNÑOPQRSTUVWXYZabcçdefghijklmnñopqrstuvwxyzàáÀÁéèÈÉíìÍÌïÏóòÓÒúùÚÙüÜ' 
var numeros='1234567890' 
var signos=',.:;@-\'' 
var signosmatematicos='+-=()*/' 
var caracteresespeciales='<>#$%&?¿' 

function chequeoCaracter(e,allow) { 
	var k; 
	k=document.all?parseInt(e.keyCode): parseInt(e.which); 
	return (allow.indexOf(String.fromCharCode(k))!=-1); 
} 

function LTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}

function RTrim(str)
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;       // Get length of string
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      	s = s.substring(0, i+1);
   }

   return s;
}
function Trim(str)
{
   return RTrim(LTrim(str));
}
function ValidaFecha (dia,mes,ano,oblig){
	Error=true;
	if (oblig==true){
		if (dia=="" || mes=="" || ano=="")
			Error=false;
	}
	if ((mes>12) || (dia>31))
			{Error=false;}
	if (((mes==4)||(mes==6)||(mes==9)||(mes==11)) && (dia==31)){
			Error=false;}
	if ((mes==2) && (dia>28)){
			Error=false;}
	resto=ano%4;
	
	if ((resto==0) && (mes==2) && (dia==29)){
			Error=true;}
	if (ano<1880)
		{Error=false;}
	return Error;
}

function validarDni(dni)
{

	if ((dni.length < 7) || (dni.length > 8) )
			return false;
	var txtDni = parseInt(dni.replace(".", ""));	
	if(isNaN((txtDni)) == false)
		return true;
	else
		return false;
}

function validarMail(nombre,mail,number){

	var arrayErrorFaltaNombre = new Array('Por favor, ingresa el nombre de tu primer amigo.\n','Por favor, ingresa el nombre de tu segundo amigo.\n','Por favor, ingresa el nombre de tu tercer amigo.\n','Por favor, ingresa el nombre de tu cuarto amigo.\n');
	var arrayErrorFaltaEmail = new Array('Por favor, ingresa el e-mail de tu primer amigo.\n', 'Por favor, ingresa el e-mail de tu segundo amigo.\n','Por favor, ingresa el e-mail de tu tercer amigo.\n','Por favor, ingresa el e-mail de tu cuarto amigo.\n');
	var arrayErrorEmail = new Array('Por favor, revisa el e-mail de tu primer amigo. Parece tener un formato no válido.\n','Por favor, revisa el e-mail de tu segundo amigo. Parece tener un formato no válido.\n','Por favor, revisa el e-mail de tu tercer amigo. Parece tener un formato no válido.\n','Por favor, revisa el e-mail de tu cuarto amigo. Parece tener un formato no válido.\n');
	
	var msg="";
	if (Trim(mail) != "" && Trim(nombre)==""){
		msg += arrayErrorFaltaNombre[number];
	}
	if (Trim(mail) == "" && Trim(nombre)!=""){
		msg += arrayErrorFaltaEmail[number];		
	}
	if (mail!=""){
		if (!(IsEmail(mail))){
			msg += arrayErrorEmail[number];
		}
	}
	return msg;
}
