String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function anoBisiesto(year)
{
	return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

function esFecha(texto,campo)
{
	var conTexto=false;
	var datos=texto.split("-");

	if(datos.length!=3)
	{
		if(conTexto)
			return "El formato de la fecha en el campo '" + campo + "' es inválido.";
		return false;
	}
	ano=datos[0];
	mes=datos[1];
	dia=datos[2];

	switch(eval(mes))
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			var Dias=31;
			break;
		case 2:
			if(anoBisiesto(ano))
				var Dias=29
			else
				var Dias=28;
			break;
		default:
			var Dias=30;
	}

	var fechaActual=new Date();

	if(isNaN(Number(ano))||isNaN(Number(mes))||isNaN(Number(dia)))
	{
		if(conTexto)
			return "La informacion de la fecha en el campo '" + campo + "' es inválida.";
		return false;
	}
	if(eval(ano)<fechaActual.getYear())
	{
		if(conTexto)
			return "El año de la fecha en el campo '" + campo + "' es inválido.";
		return false;
	}
	if(eval(mes)>12||eval(mes)<1)
	{
		if(conTexto)
			return "El mes de la fecha en el campo '" + campo + "' es inválido.";
		return false;
	}
	if(eval(dia)>Dias||eval(dia)<1)
	{
		if(conTexto)
			return "El dia de la fecha en el campo '" + campo + "' es inválido.";
		return false;
	}

	if(conTexto)
		return "";
	return true;
}

function esFecha2(texto)
{

	var datos=texto.split("-");

	if(datos.length!=3)
		return false;
	ano=datos[0];
	mes=datos[1];
	dia=datos[2];

	switch(eval(mes))
	{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			var Dias=31;
			break;
		case 2:
			if(anoBisiesto(ano))
				var Dias=29
			else
				var Dias=28;
			break;
		default:
			var Dias=30;
	}

	var fechaActual=new Date();

	if(isNaN(Number(ano))||isNaN(Number(mes))||isNaN(Number(dia)))
		return false;
	if(eval(ano)<fechaActual.getYear())
		return false;
	if(eval(mes)>12||eval(mes)<1)
		return false;
	if(eval(dia)>Dias||eval(dia)<1)
		return false;

	return true;
}

function esHora(texto)
{
	var datos=texto.split(":");
	if(datos.length!=3)
		return false;
	hr=datos[0];
	mi=datos[1];
	se=datos[2];

	if(isNaN(Number(hr)))
		return false;
	if(isNaN(Number(mi)))
		return false;
	if(isNaN(Number(se)))
		return false;
	hr=eval(hr);
	mi=eval(mi);
	se=eval(se);

	if(hr<0||hr>23)
		return false;
	if(mi<0||mi>59)
		return false;
	if(se<0||se>59)
		return false;
	return true;
}

function validarFechaHora(texto)
{
	var datos=texto.split(" ");
	if(datos.length!=2)
		return false;
	if(!esFecha2(datos[0]))
		return false;
	if(!esHora(datos[1]))
		return false;
	return true;
}

function caracteresPermitidos(Caracteres,Texto)
{                       
	for(i=0;i<Texto.length;i++)
	{
		if(Caracteres.indexOf(Texto.substr(i,1)) == -1)
			return false;
	}
	return true;
}

function soloNumeros(valor)
{
	return caracteresPermitidos("0123456789",valor);
}

function esURL(url)
{
	/*
	if(!(/^http[s]?:\/\/\w+([\.-]?\w+)*(\.\w{2,3})+$/i.test(url)))
		return (false);
	return (true);

	*/

	return true;

	var re=/^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)( [a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$/;
	return re.test(url);

}

function esEmail(texto)
{
	var mailres = true;
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
		var punto = texto.lastIndexOf(".");
	for (var contador = 0 ; contador < texto.length ; contador++)
	{
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1)
		{
			mailres = false;
			break;
		}
	}
	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		return  true;
	return false;
}


function habilitarControl(control)
{
	habilitaControl(control);
}

function habilitaControl(control)
{
	var C=document.getElementById(control);
	C.disabled=false;
}
function deshabilitarControl(control)
{
	deshabilitaControl(control);
}
function deshabilitaControl(control)
{
	var C=document.getElementById(control);
	C.disabled=true;
}

function mostrarImagen(elemento)
{
	var im=document.getElementById(elemento);
	im.style.visibility="visible";
}

function ocultarImagen(elemento)
{
	var im=document.getElementById(elemento);
	im.style.visibility="hidden";
}

function toggle(elemento)
{

	var im=document.getElementById(elemento);
	if(im.style.visibility=="hidden")
	{
		im.style.visibility="visible";
	}
	else
	{
		im.style.visibility="hidden";
	}
}

function setPointer(theRow, thePointerColor)
{
    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        var theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        var theCells = theRow.cells;
    }
    else {
        return false;
    }
    var rowCellsCnt  = theCells.length;
    for (var c = 0; c < rowCellsCnt; c++) {
        theCells[c].style.backgroundColor = thePointerColor;
    }
    return true;
}


function envioLogin()
{
	var User=document.getElementById("txtUsuario");
	var Pass=document.getElementById("txtPassword");
	
	if(User.value.trim()=="")
	{
		alert("Capture su email.");
		return false;
	}

	if(Pass.value.trim()=="")
	{
		alert("Capture su contraseÃ±a.");
		return false;
	}


	var aleatorio=String(Math.round(Math.random()*100000));
	var Primera=String(hex_md5(Pass.value));
	Primera=Primera.concat(aleatorio);
	var Segunda=String(hex_md5(Primera));

	//mostrarMensaje("Enviando la informaci&oacute;n...");
	xajax_envioLoginUsuario(User.value.trim(),Segunda,aleatorio);
}


function cerrarSesion()
{
	xajax_cerrarSesion();
}
