// JavaScript Document

function markAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
        }
    }
  document.getElementById('ver_ver').style.display='none';
  document.getElementById('ver_nover').style.display='block';
    return true;
}

function unMarkAllRows( container_id ) {
    var rows = document.getElementById(container_id).getElementsByTagName('tr');
    var unique_id;
    var checkbox;

    for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
    }
  document.getElementById('ver_ver').style.display='block';
  document.getElementById('ver_nover').style.display='none';
    return true;
}

//valida cita alcaldia
function validarcitalcaldia(form){
	for (i=0;i<document.form1.Ra1.length;i++){ 
       if (document.form1.Ra1[i].checked) 
          break; 
    }
	if(document.form1.Ra1[i].value=="1"){
		if(document.form1.Se5.value=="1"){
			if(document.form1.T1.value=="" || document.form1.T1.value.length!='8'){
    			alert('Debe especificar el numero del DNI');
    			document.form1.T1.focus();
    			return false;
			}
		}
		if(document.form1.Se5.value=="2"){
			if(document.form1.T1.value==""){
    			alert('Debe especificar el numero de la Libreta Militar');
    			document.form1.T1.focus();
    			return false;
			}
		}
		if(document.form1.Se5.value=="3"){
			if(document.form1.T1.value==""){
    			alert('Debe especificar el numero del Carnet de Extranjeria');
    			document.form1.T1.focus();
    			return false;
			}
		}	
		
		if(document.form1.T4.value==""){
    		alert('Debe especificar el nombre de la persona natural');
    		document.form1.T4.focus();
    		return false;
		}
		if(document.form1.T2.value==""){
    		alert('Debe especificar el apellido paterno de la persona natural');
    		document.form1.T2.focus();
    		return false;
		}
		if(document.form1.T3.value==""){
    		alert('Debe especificar el apellido materno de la persona natural');
    		document.form1.T3.focus();
    		return false;
		}

		//valida si telefono o email esta vacio
		if((document.form1.T13.value=="") && (document.form1.T14.value=="")){
    		alert('Debe registrar un numero de Telefono o Correo electrónico');
    		document.form1.T13.focus();
    		return false; }

		//si ingresa un numero debe completar los 7 digitos
		if(document.form1.T13.value.length>=1 && document.form1.T13.value.length<7){
		alert("Ingrese correctamente su número telefónico");
	    	document.form1.T13.focus();
    		return false; } 
		
		//validar correo
		var valor = document.form1.T14.value;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]*.[A-Za-z0-9_.]+[A-za-z]$/;
		if (valor.length > 0 ) {
	  		if (!filter.test(valor))
	 		{ 	alert("La dirección de email es incorrecta.");
				document.form1.T14.focus();
				return false;}
		}

	}
	if(document.form1.Ra1[i].value=="2"){
		if(document.form1.T12.value==""){
    		alert('Debe especificar una razon social');
    		document.form1.T12.focus();
    		return false;
		}
		if(document.form1.T11.value.length>='1' && document.form1.T11.value.length!='11'){
    		alert('Debe especificar el numero del RUC');
    		document.form1.T11.focus();
    		return false;
		}
		//valida si telefono o email esta vacio
		if((document.form1.T16.value=="") && (document.form1.T17.value=="")){
    		alert('Debe registrar un numero de Telefono o Correo electrónico');
    		document.form1.T16.focus();
    		return false; }

		//si ingresa un numero debe completar los 7 digitos
		if(document.form1.T16.value.length>=1 && document.form1.T16.value.length<7){
		alert("Ingrese correctamente su número telefónico");
    	document.form1.T13.focus();
    	return false; } 
		
		//validar correo
		var valor = document.form1.T17.value;
		var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]*.[A-Za-z0-9_.]+[A-za-z]$/;
		if (valor.length > 0 ) {
			if (!filter.test(valor))
		 	{	alert("La dirección de email es incorrecta.");
				document.form1.T17.focus();
				return false;}
		}

	}
	
	if(document.form1.T25.value==""){
			alert('Debe especificar la fecha y hora de la cita');
			document.form1.T25.focus();
			return false;
		} 
	
	if(document.form1.TA1.value==""){
			alert('Debe especificar las observaciones');
			document.form1.TA1.focus();
			return false;
		}	
	
	if(document.form1.TA1.value.length<15){
			alert('El asunto debe tener min. 15 caracteres');
			document.form1.TA1.focus();
			return false;}

 	if(confirm('Esta seguro de guardar los datos')) {
            document.form1.submit();
		}
}

function valisereform(form)
{	if(document.form1.sele_incdncia.value==0){
			alert('Debe especificar el Tipo de Incidencia');
			document.form1.sele_incdncia.focus();
			return false;
		}	
	
	if(document.form1.sele_sector.value==0){
			alert('Debe especificar el Sector');
			document.form1.sele_sector.focus();
			return false;
		}
	if(document.form1.sele_orga.value==0){
			alert('Debe especificar la organización');
			document.form1.sele_orga.focus();
			return false;
		}
		
	if(document.form1.txt_lugar.value==""){
			alert('Debe especificar el Lugar');
			document.form1.txt_lugar.focus();
			return false;
		}
	if(document.form1.txta_detalle.value==""){
			alert('Debe especificar el detalle');
			document.form1.txta_detalle.focus();
			return false;
		}	
	
	if(confirm('Esta seguro que desea enviar')) {
            document.form1.submit();
		}
}

function validarfirma(form){
 	//valida si ha seleccionado el servicio
	if(document.form1.sele_serv.value=="0"){
    	alert('Debe especificar el Servicio');
    	document.form1.sele_serv.focus();
    	return false;
	}
 	//valida si ha seleccionado el trámite
	if(document.form1.sele_tram.value=="0"){
			alert('Debe seleccionar el trámite');
			document.form1.sele_tram.focus();
			return false;
		}
	
	//Valida las respuestas en blancos de las preguntas
    var i; 
    var n = parseInt(document.form1.num_preg.value)+1; 
    var bError = false; 
 
    for (i = 1; i < n; i++){ 
    	bError = bError || (eval("document.form1.dato_" + i + ".value == ''")); 
		if (bError){ 
			alert("Debe ingresar el datos correspondiente"); 
      		eval("document.form1.dato_" + i + ".focus()"); 
      		return false; 
     	}	 
    } 
	
	var m=parseInt(document.form1.num_req.value);
	if(m==1){
	// Valida que un modelo ha sido seleccionado	
	rd_mdlo = document.getElementsByName("rd_mdlo");
	var seleccionado = false;
	for(var i=0; i<rd_mdlo.length; i++) 
	{	 if(rd_mdlo[i].checked) 
			{ seleccionado = true;
			  break; }
	  }
	
	if(!seleccionado) 
	{  alert('Debe seleccionar un Modelo');
		return false;}
	}
	
	window.open('../fir_digital.php','_blank', 'scrollbars=auto,width=415,height=190');
} 

function validafdigital(form)
{ if(document.form1.T1.value==""){
    	alert('Debe especificar el contribuyente');
    	document.form1.T1.focus();
    	return false;
	}
	
	if(document.form1.T2.value==""){
			alert('Debe especificar la contraseña');
			document.form1.T2.focus();
			return false;
		}
	
	document.form1.submit();
}