function nuevoAjax()

{

    var xmlhttp=false;

    try{

        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");

    }catch(e){

        try{

            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

        }catch(E){

            if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();

        }

    }

    return xmlhttp;

}



function rellenaCuerpo(cadena,capa){

    var cuerpo=document.getElementById(capa);

    var ajax=nuevoAjax();

    ajax.open("GET",cadena,true);

    ajax.onreadystatechange=function(){

        if(ajax.readyState==0){

            cuerpo.innerHTML="<br><br>No se pudo llamar a la funcion";

        }

        if(ajax.readyState==1){

            cuerpo.innerHTML="<br><br><center><img src='images/mozilla_blu.gif' style='vertical-align:middle;'>&nbsp;cargando...</center>";

        }

        if (ajax.readyState==4){

                cuerpo.innerHTML=ajax.responseText;

        }

    }

    ajax.send(null);

}

function fillbody(cadena, capa){
    $("#"+capa).load(cadena);
}

function rellenaCuerpo2(cadena,capa){

    var cuerpo=document.getElementById(capa);

    var ajax=nuevoAjax();

    ajax.open("GET",cadena,true);

    ajax.onreadystatechange=function(){

        if(ajax.readyState==0){

            cuerpo.innerHTML="<br><br>No se pudo llamar a la funcion";

        }

        if(ajax.readyState==1){

            cuerpo.innerHTML="<br><br><center><img src='images/mozilla_blu.gif' style='vertical-align:middle;'>&nbsp;cargando...</center>";

        }

        if (ajax.readyState==4){

                cuerpo.parentNode.innerHTML=ajax.responseText;

        }

    }

    ajax.send(null);

}



function $(campo){

    return document.getElementById(campo);

}

function $F(campo){

    return document.getElementById(campo).value;

}









function validaRegistroAsistente(){



    if($F("txtNombres")==""){

        alert(" ERROR: INGRESE NOMBRE");

        $("txtNombres").focus();

        return false;

    }else{

        if(!validaTextoConEspacios($F("txtNombres"), "ERROR: NOMBRE NO VALIDO")){

            $("txtNombres").select();

            $("txtNombres").focus();

            return false;

        }

    }

    if($F("txtApellidoPaterno")==""){

        alert(" ERROR: INGRESE APELLIDO PATERNO");

        $("txtApellidoPaterno").focus();

        return false;

    }else{

        if(!validaTextoConEspacios($F("txtApellidoPaterno"), "ERROR:APELLIDO PATERNO NO VALIDO")){

            $("txtApellidoPaterno").select();

            $("txtApellidoPaterno").focus();

            return false;

        }

    }

    if($("lstDocumento").selectedIndex==0){

    	alert("ERROR: SELECCIONE EL TIPO DE DOCUMENTO");

    	$("lstDocumento").focus();

    	return false;

    }

    if($F("txtDocumento")==""){

    	alert("ERROR: INGRESE EL NUMERO DE DOCUMENTO");

    	$("txtDocumento").focus();

    	return false;

    }else if(!validaNumeros($F("txtDocumento"),"ERROR: INGRESE UN DOCUMENTO CORRECTO")){

    	$("txtDocumento").select();

    	$("txtDocumento").focus();

    	return false;

    }else if($F("txtDocumento").length<7){

    	alert("ERROR: INGRESE UN DOCUMENTO VALIDO");

    	$("txtDocumento").select();

    	$("txtDocumento").focus();

    	return false;

    }

    

    

    if($F("txtFijo").length!=0){

    	if(!validaNumeros($F("txtFijo"),"ERROR: INGRESE UN TELEFONO CORRECTO")){

    		$("txtFijo").select();

        	$("txtFijo").focus();

        	return false;

    	}else if($F("txtFijo").length<6){

    		alert("ERROR: INGRESE UN TELEFONO CORRECTO");

    		$("txtFijo").select();

        	$("txtFijo").focus();

        	return false;

    	}

    }

    

    if($F("txtCelular").length!=0){

    	if(!validaNumeros($F("txtCelular"),"ERROR: INGRESE UN TELEFONO CORRECTO")){

    		$("txtCelular").select();

        	$("txtCelular").focus();

        	return false;

    	}else if($F("txtCelular").length<9){

    		alert("ERROR: INGRESE UN TELEFONO CORRECTO");

    		$("txtCelular").select();

        	$("txtCelular").focus();

        	return false;

    	}

    }

    

    if($F("txtEmail")==0){

    	alert("ERROR: INGRESE CORREO ELECTRONICO");

    	$("txtEmail").focus();

    	return false;

    }else if(!validaCorreo($F("txtEmail"),"ERROR: INGRESE UN CORREO VALIDO")){

    	$("txtEmail").select();

    	$("txtEmail").focus();

    	return false;

    }

    	

    var isProcedencia="";

    var institucion="";

    

    if(document.getElementById("rbNo").checked){

		if($F("txtInstitucion").length==0){

			alert("ERROR: INGRESE INSTITUCION DE PROCEDENCIA");

			$("txtInstitucion").focus();

			return false;

		}else if(!(validaTextoConEspacios($F("txtInstitucion"),"ERROR: INGRESE INSTITUCION DE PROCEDENCIA CORRECTA"))){

			$("txtInstitucion").select();

			$("txtInstitucion").focus();

			return false;

		}else{

			isProcedencia="no";

			institucion=$F("txtInstitucion");	

		}

	}else{

		isProcedencia="si";

		institucion="UNIVERSIDAD INCA GARCILASO DE LA VEGA";

	}



    cadena="nombres="+$F("txtNombres")+

        "&apellidoPaterno="+$F("txtApellidoPaterno")+

        "&tipoDocumento="+$F("lstDocumento")+

        "&nroDocumento="+$F("txtDocumento")+

        "&email="+$F("txtEmail")+

        "&fijo="+$F("txtFijo")+

        "&celular="+$F("txtCelular")+

        "&carrera="+$F("txtCarrera")+

        "&publicidad="+$F("lstPublicidad")+

        "&institusion="+institucion+

        "&tipoEstudio="+$F("lstEstudio")+

        "&codPais="+$F("lstPais")+

		"&modalidadEstudio="+$F("txtModalidadEstudio")+

		"&procedencia="+isProcedencia;

    rellenaCuerpo("index2.php?opcion=MUESTRA_FORMULARIO_REGISTRO2&"+cadena,"cuerpo");



    return false;

    

    //    "&tipoAsistente="+$F("txtAsistente")+

    //+

    //    "&fechaIns="+$F("txtFecha")



}





function validaRegistroRecibo() {

	

	if($("lstCentro").selectedIndex==0){

		alert("ERROR: SELECCIONE CENTRO DE RECAUDACION");

		$("lstCentro").focus();

		return false;

	}else if ($F("txtComprobante").length==0){

		alert("ERROR: INGRESE EL NUMERO DE COMPROBANTE");

		$("txtComprobante").focus();

		return false;

	}else if ($F("txtPago")==""){

		alert("ERROR: INGRESE LA FECHA DE PAGO DEL EVENTO");

		$("txtPago").focus();

		return false;

	}else if($("lstMonto").selectedIndex==0){

		alert("ERROR: INGRESE EL MONTO CANCELADO POR EL EVENTO");

		$("lstMonto").focus();

		return false;

	}else if($F("txtImagen").selectedIndex==0){

		alert("ERROR: SELECCIONE EL VOUCHER A SUBIR POR FAVOR");

		$("txtImagen").focus();

		return false;

	}

/*

   cadena="nombres="+$F("txtNombres")+

        "&apellidoPaterno="+$F("txtApellidoPaterno")+

        "&tipoDocumento="+$F("lstDocumento")+

        "&nroDocumento="+$F("txtDocumento")+

        "&email="+$F("txtEmail")+

        "&fijo="+$F("txtFijo")+

        "&celular="+$F("txtCelular")+

        "&carrera="+$F("txtCarrera")+

        "&publicidad="+$F("lstPublicidad")+

        "&institusion="+$F("txtProcedencia")+

        "&tipoEstudio="+$F("lstEstudio")+

        "&codPais="+$F("lstPais")+

        "&estado="+$F("txtEstado")+

        "&transaccion="+$F("txtComprobante")+

        "&centro="+$F("lstCentro")+

        "&evento=" +$F("lstEvento")+

        "&monto=" +$F("lstMonto")+

        "&fecha="+$F("txtPago")+

        "&recibo="+$F("txtImagen")+

        "&estadoFactura="+$F("lstFactura");

  */ 		

   		document.formulario.submit();

   		//rellenaCuerpo("index2.php?opcion=REGISTRAR_DATOS&"+cadena,"cuerpo");

        return false;

}





function validaTextoConEspacios(cadena, mensaje){

    var expRegular=/^[A-Za-zÑñÁÉÍÓÚáéíóú]{2}([A-Za-zÑñÁÉÍÓÚáéíóú\s])*$/;

    return retornarExpresion(expRegular, cadena, mensaje);

}

function validaNumeros(cadena, mensaje){

    var expRegular=/^([0-9]*$)/;

    return retornarExpresion(expRegular, cadena, mensaje);

}

function validaCorreo(cadena,mensaje){

	var expRegular=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;

	return retornarExpresion(expRegular, cadena, mensaje);

}

function retornarExpresion(expRegular,cadena,mensaje){

    if(expRegular.test(cadena)){

        return true;

    }else{

        alert(mensaje);

        return false;

    }

}

function M(campo){

    return document.getElementById(campo);

}

function habilitaTextBox(){

	if(document.getElementById("rbNo").checked){

		M("txtInstitucion").className="inputText";

		M("txtInstitucion").disabled=false;

		M("txtInstitucion").select();

		M("txtInstitucion").focus();

	}else{

		document.getElementById("txtInstitucion").value="";

		M("txtInstitucion").className="inputText_deshabilitado";

		M("txtInstitucion").disabled=true;

	}

}



function llenaMontos(){

	/*

	if($("lstCentro").selectedIndex==0){

		$("lstMonto").selectedIndex=0;

		$("lstMonto").className="inputText_deshabilitado";

		$("lstMonto").disabled=true;

		$("lstCentro").focus;

	}else{

		$("lstMonto").disabled=false;

		$("lstMonto").className="inputText";

		rellenaCuerpo2("index2.php?opcion=LLENA_MONTOS&idCentro="+$F("lstCentro"),"dMonto");

	}

	*/

	

	if($("lstCentro").selectedIndex!=0){

		if($("lstModalidad").selectedIndex!=0){

			if($F("txtPago").length!=0){

				rellenaCuerpo2("index2.php?opcion=LLENA_MONTOS&idCentro="+$F("lstCentro")+"&descMonto="+$F("lstModalidad")+"&fechaPago="+$F("txtPago"),"dMonto");

			}

		}

	}

	return false;

}



function startUpload(){

	document.getElementById('f1_upload_process').style.visibility = 'visible';

	return true;

}



function stopUpload(success){

	var result = '';

		if (success == 1){

			alert("REGISTRADO CORRECTAMENTE");

	}

	else {

			alert("ERROR: NO SE PUDO SUBIR EL ARCHIVO");

	}

	document.getElementById('f1_upload_process').style.visibility = 'hidden';

	return true;

}





function resultadoUpload(estado, file) {

    if (estado == 1){

        var pagina="<table width=600 border=0 align=center class=claseTabla> "+

  		"	<tr>"+

  		"		<td><font size=2 class=titulo style=height:40px>Su registro al sistema se concreto con &eacute;xito<br />"+

  		"			</font><br>"+

  		"			<font  size=2 >En los pr&oacute;ximos minutos, se le enviar&aacute a su cuenta de correo, " +

  		"						   la confirmacion de su registro.</font>"+

  		"				<br>"+

  		"		</td>"+

  		"	</tr>"+

  		"	<tr>"+

  		"		<td><div align=center>"+

  		"			<p><em><font size=2>Cordialmente<br>Comision Organizadora<br>COMTEL 2011</font></em></p>"+

  		"			</div></td>"+

  		"	</tr>"+

  		"</table></td>"+

  		"</tr>"+

  		"</table>";

        document.getElementById('estadoRegistro').innerHTML=pagina;

    }

    if (estado == 0)

    	alert("ERROR: "+file);

        //var mensaje = 'Error ! - El Archivo no llego al servidor' + link;

}



function validaRegistroImagen(){

	if($("lstCentro").selectedIndex==0){

		alert("SELECCIONE CENTRO DE RECAUDACION");

		$("lstCentro").focus();

		return false;

	}

	if($("lstModalidad").selectedIndex==0){

		alert("SELECCIONE MODALIDAD DE PAGO");

		$("lstModalidad").focus();

		return false;

	}

	if($F("txtComprobante").length==0){

		alert("INGRESE NUMERO DE COMPROBANTE");

		$("txtComprobante").focus();

		return false;

	}else if(!validaNumeros($F("txtComprobante"), "ERROR: INGRESE SOLO NUMEROS")){

		$("txtComprobante").select();

		$("txtComprobante").focus();

		return false;

	}

	if($F("txtPago").length==0){

		alert("SELECCIONE POR FAVOR LA FECHA DE PAGO DE SU COMPROBANTE");

		$("txtPago").focus();

		return false;

	}

	if($F("txtImagen").length==0){

		alert("SELECCIONE LA IMAGEN DE SU VOUCHER POR FAVOR");

		$("txtImagen").focus();

		return false;

	}if ($F("lstMonto")=="0.00"){

		alert("ERROR: VERIFIQUE POR FAVOR QUE LOS DATOS INGRESADOS SEAN CORRECTOS, IMPORTE NO PUEDE SER 0.00");

		return false;

	}

	

	document.formulario.submit();

	

}
