// JavaScript Document
     $(document).ready(function() { //inicializo el objeto jquery
			  
   	 }) ;
	

    
	
	function comenzar(){
             
			   $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/declaracion/paso1.php", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							   
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success:  function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").html(html); //show th 
                                   $("#paso1").removeClass("paso1").addClass("paso1_on");
                                 }
								        
                });	  		 
	}
	function validar_paso1(){
	    
	  var ban=0;
	  if ($("#resulDecla").val()==-1){
	   	 ban=1;
	     $("#resulDeclaracion").show("highlight", {}, 1000);
	  }else{
	  		  $.each($(".check"), function() {
      		  if ((this.value!="")&&(this.value!=0)){
	    		$("#"+this.id).removeClass("check").addClass("requerido");
			  }else{
					 ban=1;
					 //$("#"+this.id).effect("shake", { times: 3 }, 300);
			  }
			  });
			 
			  $.each($(".requerido"), function() {
			  if ((this.value=="") || (this.value==0)){
				$("#"+this.id).removeClass("requerido").addClass("check");
				//$("#"+this.id).effect("shake", { times: 3 }, 300);
				ban=1;
			  }
			  }); 
	       }
      if (!ban) 
	    return true;
	  else{
         // $("#verificar").show("highlight", {}, 1000);
  		    return false;
	      }
	}
	
	function validar_paso2(){
	  var ban=0;
	   $.each($(".check_ingreso"), function() {
      if ((this.value!="")&&(this.value!=0)){
	    $("#"+this.id).removeClass("check_ingreso").addClass("requerido_ingreso");
	  }else{
	         ban=1;
	         $("#"+this.id).effect("highlight", { }, 1000);
	  }
	  });
	 
	  $.each($(".requerido_ingreso"), function() {
      if ((this.value=="") || (this.value==0)){
	    $("#"+this.id).removeClass("requerido_ingreso").addClass("check_ingreso");
	 	$("#"+this.id).effect("highlight", { }, 1000);
		ban=1;
	  }
	  }); 
	  $.each($(".check_actividad"), function() {
           if ((this.value!="") || (this.value!=0)){
	     $("#"+this.id).removeClass("check_actividad").addClass("requerido_actividad");
      	  
           }else{
	         ban=1;
	         $("#"+this.id).effect("highlight", { }, 1000);
	    }
	  
          });      
	  
          $.each($(".requerido_actividad"), function() {
           if ((this.value=="") || (this.value==0)){
	     $("#"+this.id).removeClass("requerido_actividad").addClass("check_actividad");
	      ban=1;
           }
          });      
	  if (!ban) 
	    return true;
	  else{
         // $("#verificar").show("highlight", {}, 1000);
  		    return false;
	      }
	
	}
	
	
	function continuar_paso1(){
           if (validar_paso1()){  
			  $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/declaracion/paso2.php", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success:  function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").html(html); //show th 
                                    $("#paso1").removeClass("paso1_on").addClass("paso1");
                                    $("#paso2").removeClass("paso2").addClass("paso2_on");
                                   calculoImpuesto();	
								 
								 }
								        
                });	  		 
		    
		   }
	}
	
	function continuar_paso2(){
           if (validar_paso2()){  
			  $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/declaracion/paso3.php", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       
							   $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success:  function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").html(html); //show th 
                                    $("#paso2").removeClass("paso2_on").addClass("paso2");
                                    $("#paso3").removeClass("paso3").addClass("paso3_on");
                                    $("#MensajeBlink").effect("pulsate",{times:1000},1200);
                                    
								 }
								        
                });	  		 
		    
		   }
	}
	
	
	
	function enviar(){
               	  validar_paso1();
	            
	}
	function volver(){
               	 $("#proceso").hide("slow");
				 $.ajax({ 
                     	method: "POST",
						dataType: "html",
                        data: $("#form1").serialize(),
						url: "aplicacion/declaracion/declaracion.php", 
                        beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").show("slow"); //animation  
									$("#proceso").html(html); //show th 
                                    $("#paso1").removeClass("paso1_on").addClass("paso1");
                                  }
					              
					   });	  		 
				  		 
    }
	
	function volver_paso2(){
               	 $("#proceso").hide("slow");
				 $.ajax({ 
                     	method: "POST",
						dataType: "html",
                        data: $("#form1").serialize(),
						url: "aplicacion/declaracion/paso1.php", 
                        beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").show("slow"); //animation  
									$("#proceso").html(html); //show th 
                                    $("#paso2").removeClass("paso2_on").addClass("paso2");
                                    $("#paso1").removeClass("paso1").addClass("paso1_on");
                                    checkDeclaraciones();
                                   
								 }
					              
					   });	  		 
				  		 
    }
	
	function volver_paso3(){
          if (document.getElementById("imprime").value==-1){
   			 $("#proceso").hide("slow");
				 $.ajax({ 
                     	method: "POST",
						dataType: "html",
                        data: $("#form1").serialize(),
						url: "aplicacion/declaracion/paso2.php", 
                        beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").show("slow"); //animation  
									$("#proceso").html(html); //show th 
                                    $("#paso2").removeClass("paso2").addClass("paso2_on");
                                    $("#paso3").removeClass("paso3_on").addClass("paso3");
                                     calculoImpuesto();  	
								  
								 }
					              
					   });	  		 
		 }else{
		         alert ("No es posible volver una vez generada la planilla "); 
			  
			  }
	}
	//funcion que llama el ajax que del paso para declarar un periodo ya presentado
	function volver_declarar(idPeriodo){
           if (validar_paso1()){  
			  $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/declaracion/paso2.php?idPeriodo="+idPeriodo+"", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success:  function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").html(html); //show th 
                                    $("#paso1").removeClass("paso1_on").addClass("paso1");
                                    $("#paso2").removeClass("paso2").addClass("paso2_on");
                                   calculoImpuesto();	
								 
								 }
								        
                });	  		 
		    
		   }
	}
	
	
	function calculoImpuesto(){
	  var num=1;
	 
	  $.each($(".requerido_ingreso"), function() {
           impuestoPagar(num); 
	   num++;
	  });
		
	}
	function checkDeclaraciones(val){
		        // #datosContribuyente
				if ($("#cuentaRenta").val() == 0) {
					
					
				$("#nombre").val("");
				$("#cedula").val("");
				$("#telefono1").val("");
				$("#denominacion").val("");
				$("#licencia").val("");
				$("#telefono2").val("");
				$("#domicilio").val("");
				$("#correo").val("");	
				$("#nombre_legal").val("");
				$("#cedula_legal").val("");
				$("#telefono1_legal").val("");
				$("#apellido_legal").val("");
				$("#telefono2_legal").val("");	
				$("#correo_legal").val("");
				$("#direccion").val("");					
					
				} 
				$.ajax({ 
                     	method: "POST",
                        data: $("#form1").serialize(),
						dataType: "html",
						url: "aplicacion/declaracion/declaracionaldia.php", 
                        beforeSend: function(){
						       $("#resulDeclaracion").removeClass("").addClass("mini_carga");
							 },
						complete: function(){
							     },
						success: function(html){ //so, if data is retrieved, store it in html 
                              	   $("#resulDeclaracion").html(html); //show th 
                                   $("#resulDeclaracion").removeClass("mini_carga").addClass("");
								   if ($("#resulDecla").val()==0)
								     if (val==0) // bandera para llamar esta funcion solo al seleccioanr el cuenta renta
								       datosCuentaRenta();
								   var valor=$("#periPendiente").val();
								   if ($("#periPendiente").val()==1)
								    $("#continuar1").show("fast");
								   else
								     $("#continuar1").hide("fast");     
								 }
					              
					   });	  		 
	}
	function reimprimirPlanilla(){
		$.ajax({ 
                     	method: "POST",
                        data: $("#form1").serialize(),
						dataType: "html",
						url: "aplicacion/declaracion/planilla/reimprimir_realizada.php", 
                        beforeSend: function(){
						      $("#resulDeclaracion").html(""); 
                        	  $("#resulDeclaracion").removeClass("").addClass("mini_carga");
						       
							 },
						complete: function(){
							     },
						success: function(html){ //so, if data is retrieved, store it in html 
                              	   $("#resulDeclaracion").html(html); //show th 
                                   
                              	   $("#resulDeclaracion").removeClass("mini_carga").addClass("");
								   if ($("#resulDecla").val()==0)
								     if (val==0) // bandera para llamar esta funcion solo al seleccioanr el cuenta renta
								       datosCuentaRenta();  
								 }
					              
					   });	  		 
		
		
	}
	function datosCuentaRenta(){
		        // #datosContribuyente
				$("#proceso").hide("slow"); 
				$.ajax({ 
                     	method: "POST",
                        data: $("#form1").serialize(),
						dataType: "html",
						url: "aplicacion/declaracion/datoscontribuyente.php", 
                        beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").show("slow"); //animation  
									$("#datosContribuyente").html(html); //show th 
                                  }
					              
					   });	  		 
	}
	
	function continuar_paso3(){
             if ( document.getElementById("imprime").value==1){
			  $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/declaracion/paso4.php", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       $("#proceso").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#proceso").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success:  function(html){ //so, if data is retrieved, store it in html 
                                    $("#proceso").html(html); //show th 
                                    $("#paso3").removeClass("paso3_on").addClass("paso3");
                                    $("#paso4").removeClass("paso4").addClass("paso4_on");
                                    
								 }
								        
                });	
			 }else{
				  alert ("Debe imprimir la planilla antes de continuar con el proceso"); 
			     }
			 
		    
	}
	
	function checkPass(){
	     $.ajax({ 
                 	    method: "POST",
						dataType: "html",
						url: "aplicacion/checkpass.php", 
                        data: $("#form1").serialize(),
						success:  function(html){ //so, if data is retrieved, store it in html 
                                	$("#msg2").html(html); //show th 
                                 }
								        
                });	
	}
	function checkPass2(){
	     $("#msg0").show("fast")
		 $.ajax({ 
                 	    method: "POST",
						dataType: "html",
						url: "aplicacion/checkpass.php", 
                        data: $("#form1").serialize(),
						success:  function(html){ //so, if data is retrieved, store it in html 
                                	$("#msg0").html(html); //show th 
                                 }
								        
                });	
	}	
	
	function validar_campo(camp,tip){
	switch (tip){
	case "text":
	       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido").addClass("check");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
		   }else{
	           	 $("#"+camp.id).removeClass("check").addClass("requerido");
		   }
	
	break;
	case "text_act":
	       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido_actividad").addClass("check_actividad");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
		   }else{
	           	 $("#"+camp.id).removeClass("check_actividad").addClass("requerido_actividad");
		   }
	
	break;
	
	case "text2":
	       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido_ingreso").addClass("check_ingreso");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
		   }else{
	           	 $("#"+camp.id).removeClass("check_ingreso").addClass("requerido_ingreso");
		   }
	
	break;
	case "email": 	
	     if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido").addClass("check");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
		 }else{
	            if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(camp.value)){
	     		 $("#"+camp.id).removeClass("check").addClass("requerido");
			     checkUnico(camp.value);
				}else{
				       $("#"+camp.id).removeClass("requerido").addClass("check");
	 	               //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	  	      	 }
		 }
		 break;
	case "email2": 	
	          if ($("#"+camp.id).val()==''){
				   $("#"+camp.id).removeClass("check").addClass("norequerido");
			  }else{
			          if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(camp.value)){
	     		           $("#"+camp.id).removeClass("check").addClass("norequerido");
			          }else{
				           $("#"+camp.id).removeClass("norequerido").addClass("check");
	 	      	           }
			       }
			  break;	 
    case "passP":		 
       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido").addClass("check");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	   }else{
	          if (camp.value.length >= 6){
				    $("#"+camp.id).removeClass("check").addClass("requerido");
			        checkPass2();
			  }else{
	                $("#msg0").replaceWith("<div id='msg0' style=\"color='#FF0000'\"> <a>Seis (6) caracteres como mínimo</a>");
            	    $("#msg0").effect("highlight", {}, 1000);
	  	            $("#"+camp.id).removeClass("requerido").addClass("check");
	 	            //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	  	            $("#"+camp.id).focus();
				   }
			       
	        }
	   break;
   case "pass":		 
       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido").addClass("check");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	   }else{
	          if (camp.value.length >= 6){
				    $("#"+camp.id).removeClass("check").addClass("requerido");
	                $("#msg").hide("fast");  		  
			  }else{
	                $("#msg").replaceWith("<div id='msg'> <a>Seis (6) caracteres como mínimo</a>");
            	    $("#msg").effect("highlight", {}, 1000);
	  	            $("#"+camp.id).removeClass("requerido").addClass("check");
	 	            //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	  	            $("#"+camp.id).focus();
				   }
			       
	        }
	   break;	   
   case "re_pass":		 
       if ((camp.value=="") || (camp.value==0)){
	     	$("#"+camp.id).removeClass("requerido").addClass("check");
	 	    //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	   }else{
	          if (camp.value.length >= 6){
				   $("#"+camp.id).removeClass("check").addClass("requerido");
			        $("#msg2").hide('slow');
	  	            if (camp.value == $("#pass0").val() ){
				       $("#"+camp.id).removeClass("check").addClass("requerido");
			           $("#msg2").hide();
					}else{
			               $("#msg2").replaceWith("<div id='msg2'> <a>La contraseña no coincide</a>");
            	    	   $("#msg2").effect("highlight", {}, 1000);
	  	            	   $("#"+camp.id).removeClass("requerido").addClass("check");
	 	                   //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	  	                 }
			  
			  }else{
	                $("#msg2").replaceWith("<div id='msg2'> <a>Seis (6) caracteres como mínimo</a>");
            	    $("#msg2").effect("highlight", {}, 1000);
	  	            $("#"+camp.id).removeClass("requerido").addClass("check");
	 	            //$("#"+camp.id).effect("shake", { times: 3 }, 300);
	  	            $("#"+camp.id).focus();
				   }
			       
	        }
	   break;
	   
	
   
   }
   
   
 }
   function cambiarPass(){
      if ($("#resul").val()==-1){ 
	    $("#pass1").removeClass("requerido").addClass("check");
        ban=1;	  
	  }else{
		    if ($("#resul").val()==1){ 
	   	      if ($("#pass0").val()==$("#re_pass0").val()){  
				 $("#resultado").hide("slow");
				 $.ajax({ 
                     	method: "POST",
						dataType: "html",
                        data: $("#form1").serialize(),
						url: "aplicacion/savepass.php", 
                        beforeSend: function(){
						       $("#resultado").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#pass_change2").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#pass_change2").show("slow"); //animation  
									$("#pass_change2").html(html); //show th 
                                   }
					              
					   });
			  }else{
				    validar_campo(document.form1.pass0,"pass");
					validar_campo(document.form1.re_pass0,"re_pass");
			       }
			      
			}
	  }
				  		 
    }
   function checkpass(){
	  $.ajax({ 
                method: "POST",
				dataType: "html",
                data: $("#form1").serialize(),
				url: "aplicacion/checkmail.php",
				beforeSend: function(){
						       $("#pass_change").hide("slow");
							   $("#carga").show("slow");
							  },
				complete: function(){
							        $("#pass_change2").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
                 success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#mensaje").show("slow"); //animation  
									$("#mensaje").html(html); //show th 
                                   }
					              
					   }); 
	   
   }
   
   function checkmail(){
	  $.ajax({ 
                method: "POST",
				dataType: "html",
                data: $("#form1").serialize(),
				url: "aplicacion/checkmail.php",
				beforeSend: function(){
						       $("#pass_change").hide("slow");
							  },
				complete: function(){
							        $("#pass_change2").show("slow"); //animation
								  },
                 success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#mensaje").show("slow"); //animation  
									$("#mensaje").html(html); //show th 
                                   }
					              
					   }); 
	   
   }
   
   function recuperarPass(){
   	  if ($("#resul").val()==-1){ 
	    $("#user").removeClass("requerido").addClass("check");
        ban=1;	  
	  }else{
		    if ($("#resul").val()==1){ 
	   	         
		    	$("#recuperarPass").hide("slow");
				 $.ajax({ 
                     	method: "POST",
						dataType: "html",
                        data: $("#form1").serialize(),
						url: "aplicacion/recupass.php", 
                        beforeSend: function(){
						       $("#recuperarPass").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#carga").hide("fast");   
								  },
						success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#resultado").html(html); //show th 
                                   }
					              
					   });
		    }
	  }
				  		 
    }
   function agregarCuentaRenta(num){
   	 	        // #datosContribuyente
			var i,ban=0;
			if ( $("#cedula").val()=="" ){
				$("#cedula").removeClass("requerido").addClass("check");
	 	        //$("#cedula").effect("shake", { times: 3 }, 300); 
	        }else{
				   
	        	   for(i=1;i<=5;i++){
			         if ($("#"+num+"cr"+i).val()==""){
			         ban=1;
			         $("#"+num+"cr"+i).removeClass("requerido_renta").addClass("check_renta");	
			         }else
			          $("#"+num+"cr"+i).removeClass("check_renta").addClass("requerido_renta");	
				   }
				   if (ban==0){
				     $("#nume").val(num);
				     $.ajax({ 
                       method: "POST",
                       data: $("#form1").serialize(),
					   dataType: "html",
					   url: "aplicacion/check_cuentarenta.php", 
                       beforeSend: function(){
						       $("#status"+num).val(666);
                               $("#m"+num).hide("slow");
					  	       $("#msj"+num).removeClass("").addClass("mini_carga");
					   },
					   complete: function(){
					           $("#m"+num).show("slow");
					  	       $("#msj"+num).removeClass("mini_carga").addClass("");
					           
					   },
					   success: function(html){ //so, if data is retrieved, store it in html 
                               $("#msj"+num).html(html); //show th 
                               
                       }
					              
				      });	  		 
			  	   }//fin bandera
				}
	       
	}
	

	
	//******************************************************************************
	function agregarRegistro(){
		var cant;
		cant=$("#cant_renta").val();	
	    var ban=0;
		for(i=1;i<=cant;i++){
          if ($("#status"+i).val()!=1){		  
	        ban=1;
		  }
	    }
	    $.each($(".check_renta"), function() {
      if ((this.value!="")&&(this.value!=0)){
	    $("#"+this.id).removeClass("check_renta").addClass("requerido_renta");
	  }else{
	         ban=1;
	        // $("#"+this.id).effect("shake", { times: 3 }, 300);
	  }
	  });
	 
	  $.each($(".requerido_renta"), function() {
      if (this.value==""){
	    $("#"+this.id).removeClass("requerido_renta").addClass("check_renta");
	 	//$("#"+this.id).effect("shake", { times: 3 }, 300);
		ban=1;
	  }
	  }); 
	    if (!ban){
		 	  $.ajax({ 
                     	method: "POST",
						dataType: "html",
						url: "aplicacion/cuentarenta/save_cuentarenta.php", 
                        data: $("#form1").serialize(),
						beforeSend: function(){
						       $("#CapaAsociarCuentas").hide("slow");
							   $("#carga").show("slow");
							  },
						complete: function(){
							        $("#CapaAsociarCuentas").show("slow"); //animation
								    $("#carga").hide("fast");   
								   },
						 success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#CapaAsociarCuentas").html(html); //show th 
                                 // $("#paso1").removeClass("paso1").addClass("paso1_on");
                                  }
								        
                });	  		 
		
		}
	}
   
   
   function vaciarPaso1(){
	   ($("#telefono1").val(''));
	   ($("#telefono2").val(''));
	   ($("#correo2").val(''));
	   ($("#telefono1_legal").val(''));
	   ($("#telefono2_legal").val(''));
	   ($("#direccion").val(''));
   }
   
   function inicio(){
	window.location.href='app.php';   
   }
   
   function popup(URL){
   window.open(URL,"ventana1","width=810,height=600,top=100,left=100,scrollbars=YES,resizable=NO,location=NO,menubar=NO,status=YES")
   }
   function eliminar_renta(){
    var num=$("#cant_renta").val();	 
    if (num>1){
       $("#cuentarenta"+num).remove();	 
       document.getElementById("cant_renta").value--;
	}
 }
 function mostrar_edoHTML(){
   		var idTributo=$("#cuentaRenta").val();
	     if (idTributo!=0){
	   	  $.ajax({ 
                method: "POST",
				dataType: "html",
                data: $("#form1").serialize(),
				url: "aplicacion/printHTML_edo.php?idTributo="+idTributo,
				beforeSend: function(){
						       $("#edoHTML").hide("slow");
							   $("#carga").show("slow");
							  },
				complete: function(){
							        $("#edoHTML").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
                 success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#edoHTML").show("slow"); //animation  
									$("#edoHTML").html(html); //show th 
                                   }
					              
					   }); 
	   
	     }else{
	      $("#edoHTML").hide("slow"); //animation  
	      $("#edoHTML").html("");
	     } 
	      //alert ("Debe seleccionar un Cuenta Renta");
   }
   function imprimir_edo(){
   	 var idTributo=$("#cuentaRenta").val();
     if (idTributo!=0)
   	  popup('aplicacion/consulta/maneiro/web/EstadoCuentaWeb.php?IdTributo='+idTributo+'&Usuario=web');
     else
      alert ("Debe seleccionar un Cuenta Renta");
   }
 function agregar_renta(){
  
  var num=$("#cant_renta").val();	 
  var aux=num;
  if (aux<=100){
  aux++;
  $("#cuentarenta"+num).after("<table id=\"cuentarenta"+aux+"\" height=\"20px\" width=\"450\"><tr><td width='240'><a>"+aux+". </a><input class='requerido_renta' size='2' maxlength='2' type='text' name='"+aux+"cr1' id='"+aux+"cr1' onkeypress='autoTab("+aux+",event);return acceptNum(event)'  onblur='validar_campo(this)' /> <input class='requerido_renta' size='1' maxlength='1' type='text' name='"+aux+"cr2' id='"+aux+"cr2' onkeypress='autoTab("+aux+",event);return acceptNum(event)' onblur='validar_campo(this)' /> <input class='requerido_renta' size='3' maxlength='3'  type='text' name='"+aux+"cr3' id='"+aux+"cr3'  /> <input class='requerido_renta' size='5' maxlength='5' type='text' name='"+aux+"cr4' id='"+aux+"cr4' onkeypress='autoTab("+aux+",event);return acceptNum(event)' onblur=' agregarCuentaRenta("+aux+")' /> <input class='requerido_renta' size='1' maxlength='1' type='text' name='"+aux+"cr5' id='"+aux+"cr5' onkeypress='autoTab("+aux+",event);return acceptNum(event)' onblur='agregarCuentaRenta("+aux+")' /></td><td width=\"\"><div class='' id='msj"+aux+"'> </div></td></tr></table>");
 document.getElementById("cant_renta").value++;
  }
 }
 function mostrar_edoHTML(){
   		var idTributo=$("#cuentaRenta").val();
	     if (idTributo!=0)
	   	  $.ajax({ 
                method: "POST",
				dataType: "html",
                data: $("#form1").serialize(),
				url: "aplicacion/printHTML_edo.php?idTributo="+idTributo,
				beforeSend: function(){
						       $("#edoHTML").hide("slow");
							   $("#carga").show("slow");
							  },
				complete: function(){
							        $("#edoHTML").show("slow"); //animation
								    $("#carga").hide("fast");   
								  },
                 success: function(html){ //so, if data is retrieved, store it in html 
                                    $("#edoHTML").show("slow"); //animation  
									$("#edoHTML").html(html); //show th 
                                   }
					              
					   }); 
	   
	     
   }
   function autoTab(num,evt){
	   var key = nav4 ? evt.which : evt.keyCode;		
        if (acceptNum(evt)){	   
	     $('#'+num+'cr1').autotab({ target: num+'cr2', format: 'numeric' });
		 $('#'+num+'cr2').autotab({ target: num+'cr3', format: 'numeric', previous: num+'cr1' });
		 $('#'+num+'cr3').autotab({ target: num+'cr4', previous: num+'cr2', format: 'numeric' });
		 $('#'+num+'cr4').autotab({ target: num+'cr5', previous: num+'cr3', format: 'numeric' });
		 $('#'+num+'cr5').autotab({ target: 'comentario', previous: num+'cr4', format: 'numeric' });
		}
   }
   function imprimir(){
	 $("#imprime").val(1);
   } 
   var nav4 = window.Event ? true : false;
   isOPERA = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
   isIE    = (document.all && !isOPERA)? true : false;
   isDOM   = (document.getElementById && !isIE && !isOPERA)? true : false;
   function acceptNum(evt){
	  // NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	  if (isDOM) whichCode = evt.which;
	     else if (isIE) whichCode = evt.keyCode; 
	  var key = whichCode; // Get key value from key code  	
	  return (key <= 13 || (key >= 48 && key <= 57));
   }
   function acceptString(evt){
	  // NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	  if (isDOM) whichCode = evt.which;
	     else if (isIE) whichCode = evt.keyCode; 
	  var key = whichCode; // Get key value from key code  		
	  if (key==8) return true;
	     patron =/[A-Za-zñÑáéíóÁÉÍÓ\s ]/;
	     charkey=String.fromCharCode(key);
	  return(patron.test(charkey));
   }
   function acceptDecimal(evt){
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
	if (isDOM) whichCode = evt.which;
	     else if (isIE) whichCode = evt.keyCode; 
	var key = whichCode; // Get key value from key code  	
	if ((key==8) || (key==46)) return true;
	patron =/[0-9]/;
	charkey=String.fromCharCode(key);
	return(patron.test(charkey));
   }


	
    
 //}

