// JavaScript Document
/**
* Valida un email es correcto
*/
function email(cad){
	
	if (Trim(cad)!="")
	{
		var miRegExp = new RegExp('^.+@.+[\.].{2,4}$');
		return miRegExp.test(cad);
	}
	else
	{
		return true;
	}
}

/**
* Valida un DNI
*/
function dni(cad){
	//var miRegExp = new RegExp('^[0-9]{5,8}[a-z]{0,1}$', 'i');
	//return miRegExp.test(cad);
	return true;
}

/*
* Elimina los espacios en blanco por la izqda.
*/
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;
}
			
/*
* Elimina los espacios en blanco por la dcha.
*/
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;
}
			
/*
 * Elimina los espacios en blanco por ambos lados
 */
function Trim(str){
	return RTrim(LTrim(str));
}

//FUNCION GENERAL QUE VALIDA FECHAS
function ValidarFecha(fecha)
{

	arrayFecha=Trim(fecha).split("-");
	if (arrayFecha.length!=3)
	{
	   return true;
	}
	else if ((isNaN(parseInt(arrayFecha[0])))||(isNaN(parseInt(arrayFecha[1])))||(isNaN(parseInt(arrayFecha[2]))))
	{
		return true;
	}
	//Definiremos una variable javascript tipo fecha con los datos que nos llegan para trabajar con mas comodidad este tipo de datos
	var fechaAuxiliar=new Date(Date.UTC(arrayFecha[2],arrayFecha[1]-1,arrayFecha[0]));
	

	//Javascript, si le introduces una fecha no valida por ejemplo el mes 13 te suma un mes al total, cambiando por aņo 
	//por lo cual vamos a comparar cada elemento introducido con cada elemento generado para ver si son iguales
				
	if ((fechaAuxiliar.getUTCDate()!=parseInt(arrayFecha[0],10))||((fechaAuxiliar.getUTCMonth()+1)!=arrayFecha[1])||(fechaAuxiliar.getUTCFullYear()!=arrayFecha[2]))
	{
	  return true;
	}
	return false;
}