//  version= ADO100910-1.RC1 
// JavaScript Document
//permitir la entrada solo de números
var nav4 = window.Event ? true : false;
function acceptNum(evt){	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
/*var key = nav4 ? evt.which : evt.keyCode;
	return (key <= 13 || (key >= 48 && key <= 57));
*/}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
	
function validar(valor) {
	valida = 0;
   for (x=0; x< document.form_c.length; x++)
  		{if (trim(document.form_c[x].value)=='' && document.form_c[x].name!= "ap_mat"){
			if(document.form_c[x].disabled==false){
			alert ('Escriba todos los datos solicitados');
			document.form_c[x].focus();
			return(true);}}
		}
	var v_entero = /^(?:\+|-)?\d+$/;
	var txt = window.document.getElementById('telefono').value;
	if( !v_entero.test(txt)) {
		valida = 1;
		window.document.getElementById('telefono').focus();
		alert("Por favor, ingrese solo números en teléfono.");
   		return (false);
	}
    if (!( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor) ) ){
		valida = 1;
		window.document.getElementById('email').focus();
		alert("La dirección de email es incorrecta.");
   		return (false);
	}
	if(window.document.getElementById('fecha_form')){
		fecha = valFecha(window.document.getElementById('fecha_form'));
		if (fecha == 1 ) {
			alert("Por favor, ingrese una fecha válida, ejemplo: 01/01/2009");
			window.document.getElementById('fecha_form').focus();
			valida = 1;
			return (false);
		}
	}
	if(window.document.getElementById('horario_form')){
		var er_fh = /^(0|00|1|01|2|02|3|03|4|04|5|05|6|06|7|07|8|08|9|09|10|11|12|13|14|15|16|17|18|19|20|21|22|23)\:([0-5]0|[0-5][1-9])/
    	if ( !(er_fh.test(window.document.getElementById('horario_form').value)) ) { 
			valida = 1;
			alert("Por favor, ingrese el formato de hora corractamente, ejemplo: 18:25");
			window.document.getElementById('horario_form').focus();
			return (false);
		}	
	}
	if(window.document.getElementById('tema').value == "") {
		valida = 1;
		alert ('Escriba todos los datos solicitados');
		window.document.getElementById('tema').focus();
		return (false);
	}
	if( valida == 0 ) {
		document.form_c.submit();
	}
 }

var anio = 0;

function esDigito(sChr){
	var sCod = sChr.charCodeAt(0);
	return ((sCod > 47) && (sCod < 58));
}
function valSep(oTxt){
	var bOk = false;
	bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
	bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
	return bOk;
}
function finMes(oTxt){
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	var nRes = 0;
	switch (nMes){
		case 1: nRes = 31; break;
		case 2: 
			if (anio % 4 == 0){
				nRes = 29; 
			} else {
				nRes = 28; 
			}
			break;
		case 3: nRes = 31; break;
		case 4: nRes = 30; break;
		case 5: nRes = 31; break;
		case 6: nRes = 30; break;
		case 7: nRes = 31; break;
		case 8: nRes = 31; break;
		case 9: nRes = 30; break;
		case 10: nRes = 31; break;
		case 11: nRes = 30; break;
		case 12: nRes = 31; break;
	}
	return nRes;
}
function valDia(oTxt){
	var bOk = false;
	var nDia = parseInt(oTxt.value.substr(0, 2), 10);
	bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
	return bOk;
}
function valMes(oTxt){
	var bOk = false;
	var nMes = parseInt(oTxt.value.substr(3, 2), 10);
	bOk = bOk || ((nMes >= 1) && (nMes <= 12));
	return bOk;
}
function valAno(oTxt){
	var bOk = true;
	var nAno = oTxt.value.substr(6);
	bOk = bOk && (nAno.length == 4);
	if (bOk){
		for (var i = 0; i < nAno.length; i++){
			bOk = bOk && esDigito(nAno.charAt(i));
		}
	}
	anio = nAno;
	return bOk;
}
function valFecha(oTxt){
	var bOk = true;
		bOk = bOk && (valAno(oTxt));
		bOk = bOk && (valMes(oTxt));
		bOk = bOk && (valDia(oTxt));
		bOk = bOk && (valSep(oTxt));
		if (!bOk){
			return 1;
		} else {
			return 0;	
		}
}














function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//  window.alert( 'Width = ' + myWidth );
//  window.alert( 'Height = ' + myHeight );

	if(document.getElementById('menu_izquierdo_nuevo')){
		Nifty("div.bk_ECE9D8","normal");
	}
	
	return(myHeight);
}

 
function comprobarPass(pass,pass2){
		if (pass!=pass2){
			alert('La comprobación de la contraseña no coincide');
			return (false);}
		else return (true);
	} 
	
function ValidarFecha(Cadena){
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	// Cadena Año
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))
	// Cadena Día
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))

	// Valido el año
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
//        	alert('Año inválido')
		return false
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12 || Mes == "" ){
//		alert('Mes inválido')
		return false
	}
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
//		alert('Día inválido')
		return false
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
//			alert('Día inválido')
			return false
		}
	}
	
  //para que envie los datos, quitar las  2 lineas siguientes
 // alert("Fecha correcta.")
 	 return (true);	
}

function ValidarFormRegistro(){
 		i=0;
		texto='';

		txt=window.document.getElementById('nombre').value;
		txt=trim(txt);
		if (txt.length < 1 ) {
			i=1;
			texto+='Debes de poner un Nombre.\n';
        }
				
		txt=window.document.getElementById('ap_pat').value;
		txt=trim(txt);
		if (txt.length < 1 ) {
			i=1;
			texto+='Debes de poner un Apellido Paterno.\n';
        }

		if(window.document.getElementById('paisOt').checked){
			txt=window.document.getElementById('pais_nom').value;
			txt=trim(txt);
			if (txt.length < 1 ) {
				i=1;
				texto+='Debes escribir su país.\n';
	        }
		}
		
		else{
			txt=window.document.getElementById('id_estado').value;
			txt=trim(txt);
			if (txt.length < 1 ) {
				i=1;
				texto+='Debes seleccionar un estado.\n';
    	    }
			
			txt = parseInt(window.document.getElementById('cp').value);
		    if (isNaN(txt)) { 
        	    i=1;
				texto+='Debes de poner el Número del Código Postal (únicamente números).\n';
			}
		}

		txt=window.document.getElementById('sexo').value;
		txt=trim(txt);
		if (txt.length < 1 ) {
			i=1;
			texto+='Debes seleccionar su sexo.\n';
        }
				
//		comprobarPass(document.getElementById('pass').value,document.getElementById('rep_pass').value);

		txt=window.document.getElementById('dia').value+'-'+window.document.getElementById('mes').value+'-'+window.document.getElementById('anio').value;
		txt=trim(txt);
		if (ValidarFecha(txt)==false) {
			i=1;
			texto+='La fecha de nacimiento no es válida.\n';
        }

		var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
		//alfa = "ABCDEFGHIJKLMNÑOPQRSTUWXYZabcdefghijklmnñopqrstuvxyz";
		txt=document.getElementById('email').value;
		if( !b.test(txt)) {
			texto+='Debes de poner un Correo Electrónico Válido.\n';
			i=1;
		}
		
		if(window.document.getElementById('rec_sms').checked){
			txt=window.document.getElementById('cel').value;
			txt=trim(txt);
			txt = parseInt(window.document.getElementById('cel').value);
		    if (isNaN(txt)) { 
    	    	i=1;
				texto+='Debe escribir su teléfono para recibir mensajes SMS.\n';
			}
		}

		if(i==0){
			document.form_c.submit();
		}
		else {
			alert(texto);
		}
}


