function pais(url,divi)
{
  var estado=document.getElementById('estado').value;
  document.getElementById('parroquia').value=-1; 
  document.getElementById('parroquia').disabled=true;
  if(estado=="-1")
  {
    alert("Debe seleccionar un estado");
  } 
  else
  {
    var  datos = "id_estado="+estado;
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  }
} 

function parroquia(url,divi)
{
  var municipio=document.getElementById('municipio').value; 
  document.getElementById('parroquia').disabled=false; 
  if(municipio=="-1") 
  {
    alert("Debe seleccionar un estado");
  } 
  else
  {
    var  datos = "id_municipio="+municipio;
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  }
}
 
function ir(fo)
{ 
  if(document.getElementById("usuario").value.length=="") 
	{ 
		alert("Debe Introducir su Usuario");
		document.getElementById("usuario").focus();
		return(false);
	}  
	else if(document.getElementById("clave").value.length=="")
	{  
	  alert("Debe Introducir su Clave");
	  document.getElementById("clave").focus();
	  return(false);
	} 
	else
	{ 
	  return(true); 
	}
} 

function guardar(url,divi)
{
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = document.getElementById('contacto').value;
	var allValid = true;
	
	
	for (i = 0; i < checkStr.length; i++) 
	 {
	    ch = checkStr.charAt(i);
	    for (j = 0; j < checkOK.length; j++)
	    if (ch == checkOK.charAt(j))
	    break;
	    if (j == checkOK.length) 
	    {
	    allValid = false;
  	    break;
	    }
	 }
	 
	 
  var tele=/^\d{4}-\d{7}$/;
  var re=/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*@([a-zA-Z0-9])+(.[a-zA-Z0-9])*(\.[a-zA-Z]{2,3})+$/
   
  var persona=document.getElementById('persona').value; 
  var rif=document.getElementById('rif').value;
  var zona_postal=document.getElementById('zona_postal').value;
  var nombre=document.getElementById('nombre').value;
  var direccion=document.getElementById('direccion').value;
  var telefono=document.getElementById('telefono').value;
  var celular=document.getElementById('celular').value; 
  var fax=document.getElementById('fax').value; 
  var fiscal=document.getElementById('fiscal').value; 
  var comercial=document.getElementById('comercial').value;
  var tiposervicio=document.getElementById('tiposervicio').value;
  var estado=document.getElementById('estado').value;
  var ciudad=document.getElementById('ciudad').value;
  var municipio=document.getElementById('municipio').value;
  var parroquia=document.getElementById('parroquia').value;
  
  var rifc=document.getElementById('rifc').value;
  var nombrec=document.getElementById('nombrec').value;
  var direccionc=document.getElementById('direccionc').value; 
  var telefonoc=document.getElementById('telefonoc').value; 
  var celularc=document.getElementById('celularc').value;
  var faxc=document.getElementById('faxc').value;
  
  var usuario=document.getElementById('correo').value;
  var correo=document.getElementById('correo').value;
  var pregunta=document.getElementById('pregunta').value;
  var respuesta=document.getElementById('respuesta').value; 
  var contacto=document.getElementById('contacto').value;
  var contact=document.getElementById('contact').value;  
     
  if(persona=="-1")
  {
    alert("Debe seleccionar el tipo de persona en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('persona').focus();
  } 
  else if(zona_postal!="" && isNaN(zona_postal)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en zona postal en la pesta\u00f1a Datos del Habilitado");
    	//document.getElementById('zona_postal').focus();
  }  
  else if(direccion=="") 
  {
    alert("Debe ingresar su Direcci\u00f3n en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('direccion').focus();
  }  
  else if(telefono=="")
  {
    alert("Debe ingresar el telefono en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('telefono').focus();
  }
  else if(!tele.test(telefono))
  {
    alert("El formato del telefono debe ser: codigo de area-numero de telefono, ejemplo 0212-9090493");
    //document.getElementById('telefono').focus();
  }
  else if(celular!="" && isNaN(celular)) 
  {
    alert("Debe ingresar s\u00f3lo n\u00fameros en el campo celular");
    //document.getElementById('celular').focus();
  }
  else if(fax!="" && isNaN(fax)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo fax");
    	//document.getElementById('fax').focus();
  } 
  else if(fiscal=="") 
  {
    alert("Debe ingresar su Direcci\u00f3n Fiscal en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('fiscal').focus();
  }  
  else if(comercial=="") 
  {
    alert("Debe ingresar su Nombre Comercial en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('comercial').focus();
  } 
  else if(tiposervicio=="-1") 
  {
    alert("Debe seleccionar el tipo de servicio");
  }
  //else if (!allValid) 
  //{
   //alert("Escriba sólo letras en el campo Nombre");
	  //document.getElementById('nombre').focus();
  //}
  else if(estado=="-1") 
  {
    alert("Debe seleccionar un Estado en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('estado').focus();
  } 
  else if(ciudad=="-1") 
  {
    alert("Debe seleccionar una Ciudad en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('ciudad').focus();
  }
  else if(municipio=="-1") 
  {
    alert("Debe seleccionar un Municipio en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('municipio').focus();
  }  
  else if(parroquia=="-1") 
  {
    alert("Debe seleccionar una Parroquia en la pesta\u00f1a Datos del Habilitado");
    //document.getElementById('parroquia').focus();
  }
  else if(direccionc=="") 
  {
    alert("Debe ingresar la direcci\u00f3n del contribuyente en la pesta\u00f1a Datos del Contribuyente");
    //document.getElementById('direccionc').focus();
  }
  else if(telefonoc=="")
  {
    alert("Debe ingresar el telefono del contribuyente en la pesta\u00f1a Datos del Contribuyente");
    //document.getElementById('telefonoc').focus();
  }
  else if(!tele.test(telefonoc)) 
  {
    alert("El formato del telefono debe ser: codigo de area-numero de telefono, ejemplo 0212-9090493");
    //document.getElementById('telefonoc').focus();
  }
  else if(celularc!="" && isNaN(celularc)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo celular en la pesta\u00f1a Datos del Contribuyente");
    	//document.getElementById('celularc').focus();
  }
  else if(faxc!="" && isNaN(faxc)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo fax en la pesta\u00f1a Datos del contribuyente");
    	//document.getElementById('faxc').focus();
  }
  else if(correo=="") 
  {
    alert("Debe ingresar su correo en la pesta\u00f1a Datos del Usuario");
    //document.getElementById('correo').focus();
  }
  else if(!re.test(correo)) 
  {
    alert("Direccion de correo invalida en la pesta\u00f1a Datos del Usuario");
    //document.getElementById('correo').focus();
  }
  else if(pregunta=="-1") 
  {
    alert("Debe seleccionar una Pregunta Secreta en la pesta\u00f1a Datos del Usuario");
    //document.getElementById('pregunta').focus();
  }
  else if(respuesta=="") 
  {
    alert("Debe ingresar su Respuesta en la pesta\u00f1a Datos del Usuario");
    //document.getElementById('respuesta').focus();
  }
  else if(contacto=="")
  {
    alert("Debe indicar alguna persona contacto");
  }
  else if(!allValid) 
  {
    alert("Escriba s\u00f3lo letras en el nombre de la persona contacto");
  }
  else if(contact=="")
  {
    alert("Debe ingresar un correo alternativo");
  }
  else if(!re.test(contact))
  {
    alert("Debe indicar una direcci\u00f3n de correo alternativo valido");
  }
  else
  {
    document.getElementById('registrar').disabled='true';
    var datos="persona="+persona+"&"+"rif="+rif+"&"+
              "zona_postal="+zona_postal+"&"+"nombre="+nombre+"&"+
              "direccion="+direccion+"&"+"telefono="+telefono+"&"+
              "celular="+celular+"&"+"fax="+fax+"&"+  
              "fiscal="+fiscal+"&"+"comercial="+comercial+"&"+"tiposervicio="+tiposervicio+"&"+
              "estado="+estado+"&"+"ciudad="+ciudad+"&"+"municipio="+municipio+"&"+
              "parroquia="+parroquia+"&"+"direccionc="+direccionc+"&"+"telefonoc="+telefonoc+"&"+
              "celularc="+celularc+"&"+"faxc="+faxc+"&"+"usuario="+usuario+"&"+"correo="+correo+"&"+
              "pregunta="+pregunta+"&"+"respuesta="+respuesta+"&"+"rifc="+rifc+"&"+"nombrec="+nombrec+"&"+
              "contacto="+contacto+"&"+"contact="+contact; 
               
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  }
   
}

function buscarrif(url,divi)
{
  var rif=document.getElementById('rif').value;
  var datos="rif="+rif;  
  var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
}

function buscarusuario(url,divi)
{
  var usuario=document.getElementById('usuario').value;
  var datos="usuario="+usuario;  
  var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
}

function buscarcorreo(url,divi)
{
  var correo=document.getElementById('correo').value;
  var datos="correo="+correo;  
  var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
}

function validarrespuesta(url,divi)
{
  var respuesta=document.getElementById('respuesta').value;
  var usuario=document.getElementById('usuario').value;
  
  if(respuesta=="")
  {
    alert("Introduzca su respuesta");
  }
  else
  {
    var datos="usuario="+usuario+"&"+"respuesta="+respuesta;   
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  }
}

function buscarPregunta(url,divi)
{

  var usuario=document.getElementById('usuario').value;
  
  if(usuario=="")
  {
    alert("Introduzca su usuario");
  }
  else
  {
    var datos="usuario="+usuario;   
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  }
}

function ocultar()
{
 
  if(document.getElementById('valida').checked)
  {
    document.getElementById('btnConfirmar').disabled=false; 
  }
  else
  {
	document.getElementById('btnConfirmar').disabled=true;
  } 
}

function regconfirmacion(url,divi,cadena) 
{
    var datos=cadena;   
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
}

var radio=0;
function cambia(valoracion)
{
	radio = valoracion.value;
	//alert(radio);
}

var radio2=0;
function cambiaPeriodo(valoracion)
{
	radio2 = valoracion.value;
	//alert(radio2);
}

function alicuotarecaudacion(url,divi) 
{
  var ano=document.getElementById('ano_gravable').value;
  var tipo=radio;
  var plani=document.getElementById('cod_planilla').value;
  //alert(tipo); 
  if(tipo!="" && ano!="-1")
  {
    var datos="ano="+ano+"&"+"tipo="+tipo+"&"+"plani="+plani;   
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  } 
}

function unidadtributaria(url,divi)
{
  var ano=document.getElementById('ano_gravable').value;
  var tipo=radio;
  var plani=document.getElementById('cod_planilla').value;
  //alert(tipo); 
  if(tipo!="" && ano!="-1")
  {
    var datos="ano="+ano+"&"+"tipo="+tipo+"&"+"plani="+plani;   
    var divi="#"+divi;
    $.ajax
    (
    {
  	   async:true,
  	   url: url,
  	   type: 'POST',
  	   dataType: 'html',
  	   data: datos,	
  	   cache: false,
  	   success: function(respuesta)
  	   {
        $(divi).html(respuesta);
  	   }
    }
    );
  } 
}

function validaTransmision()
{
	var valorHora=parseInt(document.getElementById('h_tran').value);
	var valorMin=parseInt(document.getElementById('m_tran').value);
	if (valorHora==24)
	{
		//document.frmPlanilla.m_tran[0].selected;
		document.getElementById('m_tran').value=0;
		document.getElementById('m_tran').disabled=true;
		valorMin=parseInt(document.getElementById('m_tran').value);
		
		//FALTA POSICIONAR EN 0
	}
	else
	{
		document.getElementById('m_tran').disabled=false;
	}
	if(valorHora!=0)
	{
	  document.getElementById('h_mretra').value=((valorHora*90)*20)/100;
	  document.getElementById('m_mretra').value=((valorMin*90)*20)/100;	
	}  	
}

function calculoAlicuotaRF24()
{
	validaTransmision();
	if(!radio2)
	{
     radio2=document.getElementById('valorperiodo').value;
   }  
	var ano=document.getElementById('ano_gravable').value;	
	
	var A=parseInt(document.getElementById('h_retra').value);
	var Amin=parseInt(document.getElementById('m_retra').value);
	 
	//if (Amin!="" && Amin!=0)
	//{
	//	A = A + (Amin / 60);
	//}
	//A = parseFloat(A);
	//alert (A);
 
	var B=parseInt(document.getElementById('h_mretra').value); //YA SE CALCULO EL VALOR
	
	var C=parseInt(document.getElementById('h_nacio').value);
	C=0;

	var D=0;
	ano=parseInt(ano);
	
	if (ano==2006)
	{
		 if ((radio2==3) || (radio2==4))
		 {
		 		D=607;	 	 
		 }
		 else
		 {
		 		D=270;
		 }
	}
	else
	{
		if (ano < 2006)
		{
				D=270;		
		}
		else
		{
				D=742;		
		}	
	}
	
	if ((ano!="-1") && (radio2!=""))
	{
		document.getElementById('h_mnacio').value=D;
		document.getElementById('m_mnacio').value=30;
		
		
		if (ano==2005)
		{
			if ((radio2==1) || (radio2==2))
			{	//CASO 1 la alicuota permanece igual
				alicuota=document.getElementById('alicuota').value=2.00;
			}
			else
			{
				if (A<=B) //CASO 2 
				{
				//la alicuota queda igual
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				else
				{
					alicuota=document.getElementById('alicuota').value=2.5;		
				}				
			}		
		}		
		
		if (ano==2006)
		{
			if ((radio2==1) || (radio2==2))
			{
				if (A<=B) //CASO 2 
				{
				//la alicuota queda igual
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				else
				{
					alicuota=document.getElementById('alicuota').value=2.5;		
				}				
			}
			else
			{
				if ((A<=B) && (C<=D))
				{
					//la alicuota queda igual
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				if ((A>B) && (C>D)) 
				{
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				if ((A>B) && (C<=D))
				{
					//la alicuota aumenta 2.5
					alicuota=document.getElementById('alicuota').value=2.5;		
				}
				if ((A<=B) && (C>D))
				{
					//la alicuota disminuye 0.5
					alicuota=document.getElementById('alicuota').value=1.5;		
				}				
			}
		}
		
		if (ano>2006 && ano<2011)
		{
				if ((A<=B) && (C<=D))
				{
					//la alicuota queda igual
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				if ((A>B) && (C>D)) 
				{
					alicuota=document.getElementById('alicuota').value=2.00;		
				}
				if ((A>B) && (C<=D))
				{
					//la alicuota aumenta 2.5
					alicuota=document.getElementById('alicuota').value=2.5;		
				}
				if ((A<=B) && (C>D))
				{
					//la alicuota disminuye 0.5
					alicuota=document.getElementById('alicuota').value=1.5;		
				}			
		}
		
		if (ano>2010)
		{
				if ((A<=B) && (C<=D))
				{
					//la alicuota queda igual
					alicuota=document.getElementById('alicuota').value=4.00;		
				}
				if ((A>B) && (C>D)) 
				{
					alicuota=document.getElementById('alicuota').value=4.00;		
				}
				if ((A>B) && (C<=D))
				{
					//la alicuota aumenta 2.5
					alicuota=document.getElementById('alicuota').value=4.5;		
				}
				if ((A<=B) && (C>D))
				{
					//la alicuota disminuye 0.5
					alicuota=document.getElementById('alicuota').value=3.5;		
				}			
		}
		
	}
}

function validaNum()
{
	var alicuota=document.getElementById('alicuota').value;
	  
  if (isNaN(alicuota))
  {
	 alert("Debe ingresar valores numéricos");	
	 document.getElementById('alicuota').value="0.00";
  } 
}

function tributo()
{
  var cargaNumerica=1;
  var planilla=document.getElementById('cod_planilla').value;

  document.getElementById('tributo_trasladar').value="0.00";
  document.getElementById('tributo_pagar').value="0.00";
  
  var ingresos=document.getElementById('ingresos').value;
  var alicuota=document.getElementById('alicuota').value;
  var pagado=document.getElementById('tributo_pagado').value;


  if (isNaN(pagado))
  {
  	 alert("Debe ingresar valores numéricos");	
	 document.getElementById('tributo_pagado').value="0.00";
	 cargaNumerica=0;
	 tributo();
  }
  
  if (isNaN(ingresos))
  {
	 alert("Debe ingresar valores numéricos");	
	 document.getElementById('ingresos').value="0.00";
	 document.getElementById('tributo_causado').value="0.00";
	 cargaNumerica=0;
	 tributo();
  } 
  
  if (planilla=="RF-006")
  {
    var certificado=document.getElementById('certificado').value;
    if (isNaN(certificado))
  	 {
  	 	alert("Debe ingresar valores numéricos");	
	 	document.getElementById('certificado').value="0.00";
	 	cargaNumerica=0;
	 	tributo();  		
  	}
  } 	

  if (planilla=="RF-017") 
  {
  		var UT=document.getElementById('UT').value;
  		var montoUT=document.getElementById('monto_ut').value;
  		if (isNaN(montoUT))
  		{
  	 		alert("Debe ingresar valores numéricos");	
	 		document.getElementById('monto_ut').value="0.00";
	 		cargaNumerica=0;
	 		tributo();  		
  		}
  }  
  
 //alert (pagado);
 
  if (cargaNumerica==1)
  {	
  //alert(ingresos+" y "+alicuota);
  
  		if (planilla=="RF-017")
  		{
    		if(ingresos!="" && alicuota!="")
    		{
	   		
	   		//INGRESOS BRUTOS * ALICUOTA = LIMITE MAX SEGUN INGRESOS
	   		//var cuenta=parseFloat((ingresos*alicuota)/100);
	   		var cuenta=Math.round(ingresos*alicuota);
	   		//var result=Math.round(cuenta*100)/100;     
	   		var result=Math.round(cuenta/100);     
      		//var resultado=Decimales(result,2);
      		var resultado=result;
      		document.getElementById('limite').value=resultado;
	
				//MONTO A PAGAR UT * UNIDAD TRIBUTARIA	= TRIBUTO CAUSADO SEGUN FORMULA			
				var cuenta2=parseFloat(montoUT*UT);
				//var result2=Math.round(cuenta2*100)/100;
				var result2=Math.round(cuenta2);
	      	//var resultado2=Decimales(result2,2);
	      	var resultado2=result2;
      		document.getElementById('tributo_causado').value=resultado2;
	
				
				if (parseFloat(resultado2) != 0)
				{
					//COMPARAR CUAL ES EL MENOR ENTRE LIMITE MAX Y TRIBUTO CAUSADO 
					//alert("ES DISTINTO DE CERO");
					//alert(radio);
										
					if (parseFloat(resultado) < parseFloat(resultado2) && parseFloat(resultado)!=0)
					{
						//var aux = parseFloat(cuenta-pagado);
						var aux = parseFloat(resultado-pagado);
					}
					else
					{
						//var aux = parseFloat(cuenta2-pagado);				
						var aux = parseFloat(resultado2-pagado);				
					}
					
					if (radio==3)
					{
						//var aux = parseFloat(cuenta2-pagado);	
						var aux = parseFloat(resultado2-pagado);	
					}
						//aux=Math.round(aux*100)/100;
						
	   				
	   				if (aux < 0)
	   				{
	 	  					aux=Math.abs(aux);
	 	  					aux=Math.round(aux); 
	 	  					//aux=Decimales(aux,2); 
	 	  					document.getElementById('tributo_trasladar').value=aux;	 
	   				}
	   				else
	   				{
	   					    aux=Math.round(aux);
	 	  					//aux=Decimales(aux,2); 
	 	  					document.getElementById('tributo_pagar').value=aux; 
	   				} 					
									
				}
				else		//CALCULOS NORMALES
				{
      			//var aux = parseFloat(cuenta-pagado);
      			var aux = parseFloat(resultado-pagado);
      			//aux=Math.round(aux*100)/100;	
      			
	   			if (aux < 0)
	   			{
	 	  				aux=Math.abs(aux); 
	 	  				aux=Math.round(aux);
	 	  				//aux=Decimales(aux,2); 
	 	  				document.getElementById('tributo_trasladar').value=aux;	 
	   			}
	   			else
	   			{
	   				    aux=Math.round(aux);
	 	  				//aux=Decimales(aux,2); 
	 	  				document.getElementById('tributo_pagar').value=aux; 
	   			} 				
				}	
	
   
    		}  		
  		
  		}
  		
  		if (planilla=="RF-024")
  		{
  			calculoAlicuotaRF24();
			
			alicuota=document.getElementById('alicuota').value;  			
  			
    		if(ingresos!="" && alicuota!="")
    		{
	   		//var cuenta=parseFloat((ingresos*alicuota)/100);
	   		var cuenta=Math.round(ingresos*alicuota);
	   		//var result=Math.round(cuenta*100)/100;
	   		var result=Math.round(cuenta/100);
	   		//alert (result);     
      		//var resultado=Decimales(result,2);
      		var resultado=result;
      
      		document.getElementById('tributo_causado').value=resultado;
	
      		//var aux = parseFloat(cuenta-pagado);	
      		var aux = parseFloat(resultado-pagado);	
	 	      //aux=Math.round(aux*100)/100;
	 	      
	   		if (aux < 0)
	   		{
	 	  			aux=Math.abs(aux);
	 	  			aux=Math.round(aux); 
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_trasladar').value=aux;	 
	   		}
	   		else
	   		{
	   			    aux=Math.round(aux); 
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_pagar').value=aux; 
	   		}    
    		}  		
  	
  		}
  		
  		 
		//CALCULOS PARA LAS PLANILLAS DISTINTAS A 024 y 017    
		if (planilla!="RF-024" && planilla!="RF-017")
		{
		   if(ingresos!="" && alicuota!="")
    		{
    	     if(planilla!="RF-006")
    	     {
	   		 //var cuenta=parseFloat((ingresos*alicuota)/100);
	   		 var cuenta=Math.round(ingresos*alicuota);
	   		 //var result=Math.round(cuenta*100)/100;
	   		 var result=Math.round(cuenta/100);
	   		 //var resultado=Decimales(result,2);
             var resultado=result;
             
      		 document.getElementById('tributo_causado').value=resultado;
	
      		 //var aux = parseFloat(cuenta-pagado);
      		 var aux = parseFloat(resultado-pagado);
      		    //aux=Math.round(aux*100)/100;
	 			
	   		 if (aux < 0)
	   		 {
                    aux=Math.abs(aux);
                    aux=Math.round(aux);
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_trasladar').value=aux;	 
	   		 }
	   		 else
	   		 {
	   		 	    aux=Math.round(aux);
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_pagar').value=aux; 
	   		 }
	   	  }
	   	  else
	   	  {
	   	     var cuenta=Math.round(ingresos*alicuota);
	   	     //var result=Math.round(cuenta*100)/100;
	   		 var result=Math.round(cuenta/100);
	   		 //var resultado=Decimales(result,2);
	   		 var resultado=result;
	   		      
      		 document.getElementById('tributo_causado').value=resultado;
	 
      		 //var aux = parseFloat(cuenta-pagado-certificado);	
      		 
      		 var aux = parseFloat(resultado-pagado-certificado);	
      		 
      		 //aux=Math.round(aux*100)/100;
	 			 
	   		 if (aux < 0)
	   		 {
	 	  		 	aux=Math.abs(aux);
	 	  		 	aux=Math.round(aux); 
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_trasladar').value=aux;	 
	   		 }
	   		 else
	   		 {
	   		 	    aux=Math.round(aux); 
	 	  			//aux=Decimales(aux,2); 
	 	  			document.getElementById('tributo_pagar').value=aux; 
	   		 }
	   	  }      
    		}
    		
    	}
        
        
  }
  
}

function Decimales(Numero, Decimales) 
{
	pot = Math.pow(10,Decimales);
	num = parseInt(Numero * pot) / pot;
	nume = num.toString().split('.');

	entero = nume[0];
	decima = nume[1]; 

	if (decima != undefined) 
	{
		fin = Decimales-decima.length; 
   }
	else 
	{
		decima = '';
		fin = Decimales; 
	}

	for(i=0;i<fin;i++)
	  decima+=String.fromCharCode(48); 

	num=entero+'.'+decima;
	return num;
}

function validaHora()
{
  var hora=document.getElementById('h_retra').value;


  if (isNaN(hora))
  {
  	 alert("Debe ingresar valores numéricos. Entre 1 y 2160");	
	 document.getElementById('h_retra').value="0";
  }
  else
  {
  		if (parseInt(hora) < 0)
  		{
  	 		alert("Debe ingresar valores Entre 1 y 2160");	
	 		document.getElementById('h_retra').value="0";  		
  		}
  		if (parseInt(hora) > 2160)
  		{
  	 		alert("Debe ingresar valores Entre 1 y 2160");	
	 		document.getElementById('h_retra').value="0";  		
  		}
  		
  }
}

function validaMinuto()
{
  var minuto=document.getElementById('m_retra').value;


  if (isNaN(minuto))
  {
  	 alert("Debe ingresar valores numéricos. Entre 0 y 59");	
	 document.getElementById('m_retra').value="0";
  }
  else
  {
  		if (parseInt(minuto) < 0)
  		{
  	 		alert("Debe ingresar valores Entre 0 y 59");	
	 		document.getElementById('m_retra').value="0";  		
  		}
  		if (parseInt(minuto) > 59)
  		{
  	 		alert("Debe ingresar valores Entre 0 y 59");	
	 		document.getElementById('m_retra').value="0";  		
  		}
  		
  }
}


function Decimales(Numero, Decimales) 
{
	pot = Math.pow(10,Decimales);
	num = parseInt(Numero * pot) / pot;
	nume = num.toString().split('.');

	entero = nume[0];
	decima = nume[1]; 

	if (decima != undefined) 
	{
		fin = Decimales-decima.length; 
   }
	else 
	{
		decima = '';
		fin = Decimales; 
	}

	for(i=0;i<fin;i++)
	  decima+=String.fromCharCode(48); 

	num=entero+'.'+decima;
	return num;
}

function validaHora()
{
  var hora=document.getElementById('h_retra').value;


  if (isNaN(hora))
  {
  	 alert("Debe ingresar valores numéricos. Entre 1 y 2160");	
	 document.getElementById('h_retra').value="0";
  }
  else
  {
  		if (parseInt(hora) < 0)
  		{
  	 		alert("Debe ingresar valores Entre 1 y 2160");	
	 		document.getElementById('h_retra').value="0";  		
  		}
  		if (parseInt(hora) > 2160)
  		{
  	 		alert("Debe ingresar valores Entre 1 y 2160");	
	 		document.getElementById('h_retra').value="0";  		
  		}
  		
  }
}

function validaMinuto()
{
  var minuto=document.getElementById('m_retra').value;


  if (isNaN(minuto))
  {
  	 alert("Debe ingresar valores numéricos. Entre 0 y 59");	
	 document.getElementById('m_retra').value="0";
  }
  else
  {
  		if (parseInt(minuto) < 0)
  		{
  	 		alert("Debe ingresar valores Entre 0 y 59");	
	 		document.getElementById('m_retra').value="0";  		
  		}
  		if (parseInt(minuto) > 59)
  		{
  	 		alert("Debe ingresar valores Entre 0 y 59");	
	 		document.getElementById('m_retra').value="0";  		
  		}
  		
  }
}

function autoprestadores(orden)
{
  var planilla=document.getElementById('cod_planilla').value;
  //if(planilla=="RF-017" && orden==3)  
  if(planilla=="RF-017")
  {  
	 if (orden==3)
	 {    
    	document.getElementById('ingresos').disabled=true;
    }
    else
    {
    	document.getElementById('ingresos').disabled=false;
    }  
    document.getElementById('ingresos').value="0.00"; 
    //document.getElementById('alicuota').value="0.00"; 
    document.getElementById('limite').value="0.00"; 
    document.getElementById('monto_ut').value="0.00";
    //document.getElementById('UT').value="0.00";
    
    document.getElementById('tributo_pagado').value="0.00";
    document.getElementById('tributo_trasladar').value="0.00";
    
    document.getElementById('tributo_causado').value="0.00";
    document.getElementById('tributo_pagar').value="0.00";   
  }
  else
  {
    document.getElementById('ingresos').disabled=false;
    
   // document.getElementById('monto_ut').value="0.00";
    //document.getElementById('tributo_causado').value="0.00";
    
   // document.getElementById('tributo_pagado').value="0.00";
    //document.getElementById('tributo_trasladar').value="0.00";
       
  }
}

function registrarplanilla(url,divi)
{

	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = document.getElementById('ciudad').value;
	var allValid = true;
	
	
	for (i = 0; i < checkStr.length; i++) 
	 {
	    ch = checkStr.charAt(i);
	    for (j = 0; j < checkOK.length; j++)
	    if (ch == checkOK.charAt(j))
	    break;
	    if (j == checkOK.length) 
	    {
	    allValid = false;
  	    break;
	    }
	 }



  var ciudad=document.getElementById('ciudad').value; 
  var ano_gravable=document.getElementById('ano_gravable').value;
  var ingresos=document.getElementById('ingresos').value;
  var tributo_pagado=document.getElementById('tributo_pagado').value;
  var direccion=document.getElementById('direccion').value;
  var rif=document.getElementById('rif').value;
  var rot=document.getElementById('rot').value;
  var comercial=document.getElementById('comercial').value;
    
  var frecuencia=0; 
  var cobertura=0;
  
  var h_retra=0;
  var m_retra=0;
  var h_tran=0;
  var m_tran=0;
  var monto_ut=0;
  
  var h_nacio=0;
  var m_nacio=0; 
  var h_mretra=0;
  var m_mretra=0; 
  var h_mnacio=0;
  var m_mnacio=0;
  var limite=0; 
  var ut=0;
  if(document.getElementById('declaracion').value)
  {
    var declaracion=document.getElementById('declaracion').value;
  }
  else
  {
    var declaracion=0;
  }  
  //alert(declaracion);
  var certificado=0;
  
  //variables fijas, que estan como solo lectura
  var numeroplanilla=document.getElementById('numeroplanilla').value; 
  var cod_planilla=document.getElementById('cod_planilla').value;
  var alicuota=document.getElementById('alicuota').value; 
  var tributo_causado=document.getElementById('tributo_causado').value; 
  var tributo_pagar=document.getElementById('tributo_pagar').value; 
  var tributo_trasladar=document.getElementById('tributo_trasladar').value;
  
  
  if(cod_planilla=="RF-024")
  {
    var frecuencia=document.getElementById('frecuencia').value; 
    var cobertura=document.getElementById('cobertura').value;
    var h_retra=document.getElementById('h_retra').value;
    var m_retra=document.getElementById('m_retra').value;
    var h_tran=document.getElementById('h_tran').value;
    var m_tran=document.getElementById('m_tran').value;
    
    var h_nacio=document.getElementById('h_nacio').value;
    var m_nacio=document.getElementById('m_nacio').value; 
    var h_mretra=document.getElementById('h_mretra').value;
    var m_mretra=document.getElementById('m_mretra').value;
    var h_mnacio=document.getElementById('h_mnacio').value;
    var m_mnacio=document.getElementById('m_mnacio').value;   
  }  
  if(cod_planilla=="RF-017")
  {
    var monto_ut=document.getElementById('monto_ut').value;
    var limite=document.getElementById('limite').value;
    var ut=document.getElementById('UT').value; 
    radio2=0; 
  } 
  if(cod_planilla=="RF-006")
  {
    var certificado=document.getElementById('certificado').value;
  } 
  
  if(ciudad=="")
  {
    alert('Debe Ingresar la Ciudad');
    document.getElementById('ciudad').focus();  
  }
  else if (!allValid) 
  {
   	alert("Escriba sólo letras en el campo Ciudad");
	  document.getElementById('ciudad').focus();
  }
  else if(radio=="")
  {
    alert('Debe Seleccionar el tipo de planilla');
  }
  else if(ano_gravable=="-1")
  {
    alert('Debe seleccionar el a\u00f1o gravable');
    document.getElementById('ano_gravable').focus(); 
  }
  else if(ingresos=="")
  {
    alert('Debe ingresar el ingreso');
    document.getElementById('ingresos').focus(); 
  }
  else if(radio2=="" && cod_planilla!="RF-017") 
  {
    alert('Debe Seleccionar el periodo tributario');
  }
  else if(monto_ut=="" && monto_ut!=0)
  {
    alert('Debe ingresar el monto');
    document.getElementById('monto_ut').focus(); 
  }
  else if(frecuencia=="" && frecuencia!=0)  
  {
    alert('Debe Ingresar la frecuencia');
    document.getElementById('frecuencia').focus(); 
  }
  else if(cobertura=="" && cobertura!=0) 
  {
    alert('Debe Ingresar la cobertura'); 
    document.getElementById('cobertura').focus(); 
  }
  else if(h_retra=="" && h_retra!=0) 
  {
    alert('Debe Seleccionar el tiempo de retransmisi\u00f3n de mensajes difundidos trimestralmente');
    document.getElementById('h_retra').focus(); 
  }
  else if(m_retra=="" && m_retra!=0) 
  {
    alert('Debe Seleccionar el tiempo de retransmisi\u00f3n de mensajes difundidos trimestralmente');
    document.getElementById('m_retra').focus(); 
  }
  else
  { 
    var datos="ciudad="+ciudad+"&"+"numeroplanilla="+numeroplanilla+"&"+
              "cod_planilla="+cod_planilla+"&"+"ano_gravable="+ano_gravable+"&"+
              "ingresos="+ingresos+"&"+"tributo_pagado="+tributo_pagado+"&"+
              "direccion="+direccion+"&"+"rif="+rif+"&"+"rot="+rot+"&"+
              "comercial="+comercial+"&"+"frecuencia="+frecuencia+"&"+
              "cobertura="+cobertura+"&"+"h_retra="+h_retra+"&"+"m_retra="+m_retra+"&"+
              "h_tran="+h_tran+"&"+"m_tran="+m_tran+"&"+"monto_ut="+monto_ut+"&"+
              "h_nacio="+h_nacio+"&"+"m_nacio="+m_nacio+"&"+"h_mretra="+h_mretra+"&"+
              "m_mretra="+m_mretra+"&"+"h_mnacio="+h_mnacio+"&"+"m_mnacio="+m_mnacio+"&"+
              "tipo_planilla="+radio+"&"+"periodo="+radio2+"&"+"alicuota="+alicuota+"&"+
              "tributo_causado="+tributo_causado+"&"+"limite="+limite+"&"+"ut="+ut+"&"+
              "tributo_pagar="+tributo_pagar+"&"+"declaracion="+declaracion+"&"+
              "tributo_trasladar="+tributo_trasladar+"&"+"certificado="+certificado;               
    radio=0;radio2=0;
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    );
  } 
}

function enviar(url,divi)
{
  var ciudad=document.getElementById('ciudad').value; 
  var ano_gravable=document.getElementById('ano_gravable').value;
  var ingresos=document.getElementById('ingresos').value;
  var tributo_pagado=document.getElementById('tributo_pagado').value;
  var direccion=document.getElementById('direccion').value;
  var rif=document.getElementById('rif').value;
  //var rot=document.getElementById('rot').value;
  var comercial=document.getElementById('comercial').value;
    
  //variables fijas, que estan como solo lectura
  var numeroplanilla=document.getElementById('numeroplanilla').value; 
  var cod_planilla=document.getElementById('cod_planilla').value;
  var alicuota=document.getElementById('alicuota').value; 
  var tributo_causado=document.getElementById('tributo_causado').value; 
  var tributo_pagar=document.getElementById('tributo_pagar').value; 
  var tributo_trasladar=document.getElementById('tributo_trasladar').value;
  
  
    var frecuencia=document.getElementById('frecuencia').value; 
    var cobertura=document.getElementById('cobertura').value;
    var h_retra=document.getElementById('h_retra').value;
    var m_retra=document.getElementById('m_retra').value;
    var h_tran=document.getElementById('h_tran').value;
    var m_tran=document.getElementById('m_tran').value;
    
    var h_nacio=document.getElementById('h_nacio').value;
    var m_nacio=document.getElementById('m_nacio').value; 
    var h_mretra=document.getElementById('h_mretra').value;
    var m_mretra=document.getElementById('m_mretra').value;
    var h_mnacio=document.getElementById('h_mnacio').value;
    var m_mnacio=document.getElementById('m_mnacio').value;   
  
    var monto_ut=document.getElementById('monto_ut').value;
    var limite=document.getElementById('limite').value;
    var ut=document.getElementById('ut').value; 
    var declaracion=document.getElementById('declaracion').value;
    var id_operador=document.getElementById('id_operador').value;
    var tipo_planilla=document.getElementById('tipo_planilla').value;
    var periodo=document.getElementById('periodo').value;
    var certificado=document.getElementById('certificado').value;
    //alert(declaracion);
  var datos="ciudad="+ciudad+"&"+"numeroplanilla="+numeroplanilla+"&"+
              "cod_planilla="+cod_planilla+"&"+"ano_gravable="+ano_gravable+"&"+
              "ingresos="+ingresos+"&"+"tributo_pagado="+tributo_pagado+"&"+
              "direccion="+direccion+"&"+"rif="+rif+"&"+
              "comercial="+comercial+"&"+"frecuencia="+frecuencia+"&"+
              "cobertura="+cobertura+"&"+"h_retra="+h_retra+"&"+"m_retra="+m_retra+"&"+
              "h_tran="+h_tran+"&"+"m_tran="+m_tran+"&"+"monto_ut="+monto_ut+"&"+
              "h_nacio="+h_nacio+"&"+"m_nacio="+m_nacio+"&"+"h_mretra="+h_mretra+"&"+
              "m_mretra="+m_mretra+"&"+"h_mnacio="+h_mnacio+"&"+"m_mnacio="+m_mnacio+"&"+
              "tipo_planilla="+tipo_planilla+"&"+"periodo="+periodo+"&"+"alicuota="+alicuota+"&"+
              "tributo_causado="+tributo_causado+"&"+"limite="+limite+"&"+"ut="+ut+"&"+
              "tributo_pagar="+tributo_pagar+"&"+"declaracion="+declaracion+"&"+
              "tributo_trasladar="+tributo_trasladar+"&"+"id_operador="+id_operador+"&"+"certificado="+certificado;                
    radio=0;radio2=0;
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    );
}

function consultarplanilla(url,divi)
{
  //var periodo=radio2;
  var ano_gravable=document.getElementById('ano_gravable').value;
  var id_operador=document.getElementById('id_operador').value;
  
  //if(periodo=="")
  //{
   // alert('Debe Seleccionar el periodo tributario');
  //}
  //else 
  if(ano_gravable=="-1")
  {
    alert('Debe seleccionar el a\u00f1o gravable');
    document.getElementById('ano_gravable').focus(); 
  } 
  else
  { 
    //var datos="periodo="+periodo+"&"+"ano_gravable="+ano_gravable+"&"+"id_operador="+id_operador;
    var datos="ano_gravable="+ano_gravable+"&"+"id_operador="+id_operador;
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    );
  }  
}

function pdf(id) 
{
  document.getElementById('id').value=id;
  document.expor.submit();
}

function actualizarplanilla(url,divi)
{
  //alert(document.frmPlanilla.tipo.length); 
  for(i=0;i<document.frmPlanilla.tipo.length;i++)
  {
    if(document.frmPlanilla.tipo[i].checked) 
    {  
      //alert("entre");   
      radio=document.frmPlanilla.tipo[i].value;
    }   
  }
    
  var id_declaracion=document.getElementById('id_declaracion_temp').value;
  var ciudad=document.getElementById('ciudad').value; 
  var ano_gravable=document.getElementById('ano_gravable').value;
  var ingresos=document.getElementById('ingresos').value;
  var tributo_pagado=document.getElementById('tributo_pagado').value;
  var direccion=document.getElementById('direccion').value;
  var rif=document.getElementById('rif').value;
  var rot=document.getElementById('rot').value;
  var comercial=document.getElementById('comercial').value;
    
  var frecuencia=0; 
  var cobertura=0;
  
  var h_retra=0;
  var m_retra=0;
  var h_tran=0;
  var m_tran=0;
  var monto_ut=0;
  
  var h_nacio=0;
  var m_nacio=0; 
  var h_mretra=0;
  var m_mretra=0; 
  var h_mnacio=0;
  var m_mnacio=0;
  var limite=0; 
  var ut=0;
  if(document.getElementById('declaracion').value)
  {
    var declaracion=document.getElementById('declaracion').value;
  }
  else
  {
    var declaracion=0;
  }  
  
  var certificado=0;
  
  //variables fijas, que estan como solo lectura
  var numeroplanilla=document.getElementById('numeroplanilla').value; 
  var cod_planilla=document.getElementById('cod_planilla').value;
  var alicuota=document.getElementById('alicuota').value; 
  var tributo_causado=document.getElementById('tributo_causado').value; 
  var tributo_pagar=document.getElementById('tributo_pagar').value; 
  var tributo_trasladar=document.getElementById('tributo_trasladar').value;
  
  if(cod_planilla!="RF-017")
  {
    for(i=0;i<document.frmPlanilla.periodo.length;i++)
    { 
      if(document.frmPlanilla.periodo[i].checked) 
      {  
        radio2=document.frmPlanilla.periodo[i].value;
      }   
    } 
  }
  
  
  if(cod_planilla=="RF-024")
  {
    var frecuencia=document.getElementById('frecuencia').value; 
    var cobertura=document.getElementById('cobertura').value;
    var h_retra=document.getElementById('h_retra').value;
    var m_retra=document.getElementById('m_retra').value;
    var h_tran=document.getElementById('h_tran').value;
    var m_tran=document.getElementById('m_tran').value;
    
    var h_nacio=document.getElementById('h_nacio').value;
    var m_nacio=document.getElementById('m_nacio').value; 
    var h_mretra=document.getElementById('h_mretra').value;
    var m_mretra=document.getElementById('m_mretra').value;
    var h_mnacio=document.getElementById('h_mnacio').value;
    var m_mnacio=document.getElementById('m_mnacio').value;   
  }  
  if(cod_planilla=="RF-017")
  {
    var monto_ut=document.getElementById('monto_ut').value;
    var limite=document.getElementById('limite').value;
    var ut=document.getElementById('UT').value; 
    radio2=0; 
  }  
  if(cod_planilla=="RF-006")
  {
    var certificado=document.getElementById('certificado').value;
  }
  
  if(ciudad=="")
  {
    alert('Debe Ingresar la Ciudad');
    document.getElementById('ciudad').focus();  
  }
  else if(radio=="")
  {
    alert('Debe Seleccionar el tipo de planilla');
  }
  else if(ano_gravable=="-1")
  {
    alert('Debe seleccionar el a\u00f1o gravable');
    document.getElementById('ano_gravable').focus(); 
  }
  else if(ingresos=="")
  {
    alert('Debe ingresar el ingreso');
    document.getElementById('ingresos').focus(); 
  }
  else if(radio2=="" && cod_planilla!="RF-017") 
  {
    alert('Debe Seleccionar el periodo tributario');
  }
  else if(monto_ut=="" && monto_ut!=0)
  {
    alert('Debe ingresar el monto');
    document.getElementById('monto_ut').focus(); 
  }
  else if(frecuencia=="" && frecuencia!=0)  
  {
    alert('Debe Ingresar la frecuencia');
    document.getElementById('frecuencia').focus(); 
  }
  else if(cobertura=="" && cobertura!=0) 
  {
    alert('Debe Ingresar la cobertura'); 
    document.getElementById('cobertura').focus(); 
  }
  else if(h_retra=="" && h_retra!=0) 
  {
    alert('Debe Seleccionar el tiempo de retransmisi\u00f3n de mensajes difundidos trimestralmente');
    document.getElementById('h_retra').focus(); 
  }
  else if(m_retra=="" && m_retra!=0) 
  {
    alert('Debe Seleccionar el tiempo de retransmisi\u00f3n de mensajes difundidos trimestralmente');
    document.getElementById('m_retra').focus(); 
  }
  else
  { 
    var datos="ciudad="+ciudad+"&"+"numeroplanilla="+numeroplanilla+"&"+
              "cod_planilla="+cod_planilla+"&"+"ano_gravable="+ano_gravable+"&"+
              "ingresos="+ingresos+"&"+"tributo_pagado="+tributo_pagado+"&"+
              "direccion="+direccion+"&"+"rif="+rif+"&"+"rot="+rot+"&"+
              "comercial="+comercial+"&"+"frecuencia="+frecuencia+"&"+
              "cobertura="+cobertura+"&"+"h_retra="+h_retra+"&"+"m_retra="+m_retra+"&"+
              "h_tran="+h_tran+"&"+"m_tran="+m_tran+"&"+"monto_ut="+monto_ut+"&"+
              "h_nacio="+h_nacio+"&"+"m_nacio="+m_nacio+"&"+"h_mretra="+h_mretra+"&"+
              "m_mretra="+m_mretra+"&"+"h_mnacio="+h_mnacio+"&"+"m_mnacio="+m_mnacio+"&"+
              "tipo_planilla="+radio+"&"+"periodo="+radio2+"&"+"alicuota="+alicuota+"&"+
              "tributo_causado="+tributo_causado+"&"+"limite="+limite+"&"+"ut="+ut+"&"+
              "tributo_pagar="+tributo_pagar+"&"+"declaracion="+declaracion+"&"+
              "tributo_trasladar="+tributo_trasladar+"&"+"id_declaracion="+id_declaracion+"&"+"certificado="+certificado;               
    radio=0;radio2=0;
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    );
  } 
}

function validarrif(formu)
{
  var formatoRIF = /^[JVG]\d{9}$/;
  var rif=document.getElementById('rif').value;
  var rifc=document.getElementById('rifc').value; 
  if(rif=="") 
  {
    alert("Debe ingresar el RIF del Habilitado");
    document.getElementById('rif').focus();
    return (false);
  } 
  else if(!formatoRIF.test(rif)) 
  { 
    alert("El formato del RIF debe ser V, J o G seguido de nueve digitos numericos. Ejemplo: V123456789 , J012345678");
    document.getElementById('rif').focus();
    return (false);
  }
  if(rifc=="") 
  {
    alert("Debe ingresar el RIF del Contribuyente");
    document.getElementById('rifc').focus();
    return (false);
  } 
  else if(!formatoRIF.test(rifc)) 
  { 
    alert("El formato del RIF debe ser V, J o G seguido de nueve digitos numericos. Ejemplo: V123456789 , J012345678");
    document.getElementById('rifc').focus();
    return (false);
  } 
  else
  {
    return (true);
  }  
}

function cambiarclave(url,divi) 
{
  var clave=document.getElementById('clave').value;
  var claven=document.getElementById('claven').value; 
  var clavenr=document.getElementById('clavenr').value;
  if(clave=="")
  {
    alert('Debe ingresar su clave anterior');
    document.getElementById('clave').focus();
  }
  else if(claven=="")
  {
    alert('Debe ingresar su nueva clave');
    document.getElementById('claven').focus();
  }
  else if(clavenr=="")
  {
    alert('Debe repetir su nueva clave');
    document.getElementById('clavenr').focus();
  }
  else if(claven!=clavenr)  
  { 
    alert('La nueva clave debe ser igual al campo de repetir clave');
  }
  else
  {
    var datos="clave="+clave+"&"+"claven="+claven+"&"+"clavenr="+clavenr;  
  
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    ); 
  }   
} 

function actudatos(url,divi)
{

   var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = document.getElementById('contacto').value;
	var allValid = true;
	
	
	for (i = 0; i < checkStr.length; i++) 
	 {
	    ch = checkStr.charAt(i);
	    for (j = 0; j < checkOK.length; j++)
	    if (ch == checkOK.charAt(j))
	    break;
	    if (j == checkOK.length) 
	    {
	    allValid = false;
  	    break;
	    }
	 }

  var tele=/^\d{4}-\d{7}$/;
  var re=/^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)*@([a-zA-Z0-9])+(.[a-zA-Z0-9])*(\.[a-zA-Z]{2,3})+$/

  var persona=document.getElementById('persona').value;
  var zona_postal=document.getElementById('zona_postal').value;
  var direccion=document.getElementById('direccion').value;
  var telefono=document.getElementById('telefono').value;
  var celular=document.getElementById('celular').value;
  var fax=document.getElementById('fax').value;
  var fiscal=document.getElementById('fiscal').value;
  var comercial=document.getElementById('comercial').value;
  var estado=document.getElementById('estado').value;
  var ciudad=document.getElementById('ciudad').value;
  var municipio=document.getElementById('municipio').value;
  var parroquia=document.getElementById('parroquia').value;
  
  var direccionc=document.getElementById('direccionc').value;
  var telefonoc=document.getElementById('telefonoc').value;
  var celularc=document.getElementById('celularc').value;
  var faxc=document.getElementById('faxc').value;
  
  var correo=document.getElementById('correo').value;
  var usuario=document.getElementById('correo').value;
  var pregunta=document.getElementById('pregunta').value;
  var respuesta=document.getElementById('respuesta').value;
  var contacto=document.getElementById('contacto').value;
  var contact=document.getElementById('contact').value;
  
  if(zona_postal!="" && isNaN(zona_postal)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en zona postal");
    	document.getElementById('zona_postal').focus();
  }  
  else if(direccion=="") 
  {
    alert("Debe ingresar la Direcci\u00f3n del Habilitado");
    document.getElementById('direccion').focus();
  }  
  else if(telefono=="")
  {
    alert("Debe ingresar el telefono del Habilitado");
    document.getElementById('telefono').focus();
  }
  else if(!tele.test(telefono))
  {
    alert("El formato del telefono debe ser: codigo de area-numero de telefono, ejemplo 0212-9090493");
    document.getElementById('telefono').focus();
  }
  else if(celular!="" && isNaN(celular)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo celular");
    	document.getElementById('celular').focus();
  }
  else if(fax!="" && isNaN(fax)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo fax");
    	document.getElementById('fax').focus();
  }  
  else if(fiscal=="") 
  {
    alert("Debe ingresar la Direcci\u00f3n Fiscal del Habilitado");
    document.getElementById('fiscal').focus();
  }  
  else if(comercial=="") 
  {
    alert("Debe ingresar el Nombre Comercial del Habilitado");
    document.getElementById('comercial').focus();
  }  
  else if(estado=="-1") 
  {
    alert("Debe seleccionar un Estado");
    document.getElementById('estado').focus();
  } 
  else if(ciudad=="-1") 
  {
    alert("Debe seleccionar una Ciudad");
    document.getElementById('ciudad').focus();
  }
  else if(municipio=="-1") 
  {
    alert("Debe seleccionar un Municipio");
    document.getElementById('municipio').focus();
  }  
  else if(parroquia=="-1") 
  {
    alert("Debe seleccionar una Parroquia");
    document.getElementById('parroquia').focus();
  }
  else if(direccionc=="") 
  {
    alert("Debe ingresar la direcci\u00f3n del contribuyente");
    document.getElementById('direccionc').focus();
  }
  else if(telefonoc=="")
  {
    alert("Debe ingresar el telefono del contribuyente");
    document.getElementById('telefonoc').focus();
  }
  else if(!tele.test(telefonoc)) 
  {
    alert("El formato del telefono debe ser: codigo de area-numero de telefono, ejemplo 0212-9090493");
    document.getElementById('telefonoc').focus();
  }
  else if(celularc!="" && isNaN(celularc)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo celular del contribuyente");
    	document.getElementById('celularc').focus();
  }
  else if(faxc!="" && isNaN(faxc)) 
  {
    	alert("Debe ingresar s\u00f3lo n\u00fameros en el campo fax del contribuyente");
    	document.getElementById('faxc').focus();
  }
  else if(correo=="") 
  {
    alert("Debe ingresar su correo");
    document.getElementById('correo').focus();
  }
  else if(!re.test(correo))  
  {
    alert("Direccion de correo invalida");
    document.getElementById('correo').focus();
  }
  else if(respuesta=="") 
  {
    alert("Debe ingresar su Respuesta");
    document.getElementById('respuesta').focus();
  }
  else if(contacto=="")
  {
    alert("Debe indicar alguna persona contacto");
  }
  else if(!allValid) 
  {
    alert("Escriba s\u00f3lo letras en el nombre de la persona contacto");
  }
  else if(contact=="")
  {
    alert("Debe ingresar un correo alternativo");
  }
  else if(!re.test(contact))
  {
    alert("Debe indicar una direcci\u00f3n de correo alternativo valido");
  }
  else
  {
    var datos="persona="+persona+"&"+"zona_postal="+zona_postal+"&"+"direccion="+direccion+"&"+
              "telefono="+telefono+"&"+"celular="+celular+"&"+"fax="+fax+"&"+"fiscal="+fiscal+"&"+
              "comercial="+comercial+"&"+"estado="+estado+"&"+"ciudad="+ciudad+"&"+"municipio="+municipio+"&"+
              "parroquia="+parroquia+"&"+"direccionc="+direccionc+"&"+"telefonoc="+telefonoc+"&"+
              "celularc="+celularc+"&"+"faxc="+faxc+"&"+"usuario="+usuario+"&"+"correo="+correo+"&"+
              "pregunta="+pregunta+"&"+"respuesta="+respuesta+"&"+"contacto="+contacto+"&"+"contact="+contact;  
  
    var divi="#"+divi;
    $.ajax
    (
    {
      async:true,
      url: url,
      type: 'POST',
      dataType: 'html',
      data: datos,	
      cache: false,
      success: function(respuesta)
      {
        $(divi).html(respuesta);
      }
    }
    ); 
  }   
}

function ojo()
{
  if(document.getElementById('sustitutiva').checked)
  {
    document.getElementById('declaracion').disabled=false;
  }
  else
  {
    document.getElementById('declaracion').disabled=true; 
  }
}

