function mensaje (cadena)
{
	if (cadena != '')
	{
			alert (cadena);
	}
}

function abrir_link (lnk)
{
	window.location = "" + lnk + "";
}
function ordenar(campo)
{
	var campoOld=document.fm.ordenar.value;
	var tipoOrd=document.fm.ordenar_tipo.value;
	if(campoOld==campo && tipoOrd=="asc")
	{
		document.fm.ordenar_tipo.value="desc";
	}
	else
	{
		document.fm.ordenar.value=campo;
		document.fm.ordenar_tipo.value="asc";
	}
	document.fm.submit();
}

function obtener_hora()
{
	var fecha = new Date();
	var horas = fecha.getHours();
	var minutos = fecha.getMinutes();
	var segundos = fecha.getSeconds();
	
	var dn="AM";
	if (horas >= 12)
		dn="PM";
		
	if (horas > 12)
		horas=horas-12;

	if (horas == 0)
		horas = 12;
		
	if (minutos <= 9)
		minutos = "0" + minutos;
		
	if (segundos <= 9)
		segundos= "0" + segundos;
		


	var chora = " " + horas + ":" + minutos + ":" +segundos + " " + dn;

	if (document.all)
		document.all.reloj.innerHTML=chora;		
	else if (document.getElementById)
		document.getElementById("reloj").innerHTML=chora;
	//else
	//document.write(chora)
}

function iniciar_reloj ()
{
	if (document.all || document.getElementById)
		setInterval("obtener_hora()",1000);
}

function v_vacio(valor){
valor=trimAll(valor);
	var R=true;
		if (valor.length!=0){R=false;}
	return R;
}

function trimAll(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function valida_tamano(nombre,valor,obligatorio,tamano){
	valor=trimAll(valor);
	if (v_vacio(valor)){
		if(obligatorio){msj+='El campo '+nombre+' es obligatorio.\n';}
	}else
	{
		if(tamano)
		{
			if (valor.length!=tamano){msj+='El campo '+nombre+' debe tener '+tamano+' caracteres.\n';}
		}
	}
}


function valida_fecha(nombre,valor,obligatorio){
valor=trimAll(valor);
	if (v_vacio(valor)){
		if(obligatorio){msj+='El campo '+nombre+' es obligatorio.\n';}
	}else{
		valida_tamano (nombre,valor,10);
		if ((valor.substr(2,1) != "/") && (valor.substr(5,1) != "/")){      
			 msj+='El campo '+nombre+' debe tener formato dd/mm/aaaa.\n';
		}else
			{ 
			 a = valor.substr(6,4);
			 a2 = parseInt(a,10); 
			 m = valor.substr(3,2);
			 m2 = parseInt(m,10); 
			 d = valor.substr(0,2);
		  	 d2 = parseInt(d,10);
			 if((a < 1900) || (a > 2050) || (m < 1) || (m > 12) || (d < 1) || (d > 31) || (isNaN(a2)) || (isNaN(m2)) || (isNaN(d2))){
				   msj+='El campo '+nombre+' debe tener formato dd/mm/aaaa.\n';
			 }else
				{
				  if((a%4 != 0) && (m == 2) && (d > 28)){
					   msj+='El campo '+nombre+': el aņo no es bisiesto.\n';
				   }else
					{
						if ((((m == 4) || (m == 6) || (m == 9) || (m==11)) && (d>30)) || ((m==2) && (d>29))){
						 msj+='El campo '+nombre+' no es correcto.\n';
						}
					}  
				} 
			}
	} 
   	    			
}
function valida_email(email){
    regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    return regx.test(email);
}

