/*Archivo que contiene las validaciones típicas que se realizan
en los formularios */

//---------------------------------------------------------------------
/*funcion que valida si una variable se encuentra o no vacía */
function isEmpty(valor){
	return ((valor == null) || (valor.length == 0) || (Trim(valor) == ""));
}

//---------------------------------------------------------------------
/* funcion que quita los espacios en blanco a la izquierda del string*/
function LTrim(str){

	while(str.length > 0 && (str.charAt(0) == " " || str.charCodeAt(0) == 160)){
		str = str.substr(1,str.length)
	}
	return str;
}

//---------------------------------------------------------------------
/* funcion que quita los espacios en blanco a las derecha del string*/
function RTrim(str){

	while(str.length > 0 && (str.charAt(str.length-1) == " " || str.charCodeAt(str.length-1) == 160)){
		str = str.substr(0,str.length-1);
	}
	return str;
}
//---------------------------------------------------------------------
/* quita los espacios en blanco de un string*/
function Trim(theStr){

	theStr = RTrim(theStr);
	theStr = LTrim(theStr);

	return theStr ;
}

//---------------------------------------------------------------------
/* retorna false en caso que la url no sea valida */
function ValidaURL(url) {
	var re=/^((http|ftp)(s)?:\/\/)?\w+(\.\w+)*(-\w+)?\.([a-z]{2,3}|info|mobi|aero|asia|name)(:\d{2,5})?(\/)?((\/).+)?$/;
//con http		var re=/^(http|ftp)(s)?:\/\/\w+(\.\w+)*(-\w+)?\.([a-z]{2,3}|info|mobi|aero|asia|name)(:\d{2,5})?(\/)?((\/).+)?$/;
	return re.test(url);
}

//---------------------------------------------------------------------
/*retorna false, en caso que el valor enviado no sea numerico (entero)*/
function validaEntero(valor){
      //intento convertir a entero.
     //si era un entero no le afecta, si no lo era lo intenta convertir
     valor = parseInt(valor)

      //Compruebo si es un valor numérico
      if (isNaN(valor)) {
            //entonces (no es numero) devuelvo false, para emitir el mensaje correspondiente
            return false;
      }else{
            //En caso contrario (Si era un número) devuelvo true, para continuar la ejecucion
            return true;
      }
}

//---------------------------------------------------------------------
/*retorna dalse en caso que el valor ingresado en el email no sea del formato
aaa@aaa.dominio */
function validarMail(field)
{
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return false;}
  else {return true;}
  }
}

//---------------------------------------------------------------------
/*Verifica si se presiono la tecla enter*/
function enter(e,t){
 var k=null;
 (e.keyCode) ? k=e.keyCode : k=e.which;
 if(k==13) (!t) ? enviar() : t.focus();
}
function enviar(){
 document.forms[0].submit();
 return true;
}

