// Código Javascript para Aplicación DimeHora.
function getXMLHTTPRequest() {
try {
req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    }
  }
}
return req;
}

var http = getXMLHTTPRequest();
var http2 = getXMLHTTPRequest();
var http3 = getXMLHTTPRequest();
var http4 = getXMLHTTPRequest();
var http5 = getXMLHTTPRequest();
var http6 = getXMLHTTPRequest();
var http7 = getXMLHTTPRequest();
var http8 = getXMLHTTPRequest();


function cambioTipos()
{
	sumar();
	Utilidad();
	Tipo1();
	Tipo2();
	Tipo3();
	Tipo4();
	Tipo5();
	Tipo6();
	Tipo7();
	Tipo8();
	}


function Tipo1() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	
  
  var val=document.up.activo.value;
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse1;
  http.send(null);
  sumar();
  Tipo3();
}

function useHttpResponse1() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo1').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.activo2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo1').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }

}

function Tipo2() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.pasivo.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http2.open("GET", modurl, true);
  http2.onreadystatechange = useHttpResponse2;
  http2.send(null);
    sumar();
  Tipo3();
}

function useHttpResponse2() {
   if (http2.readyState == 4) {
    if(http2.status == 200) {
       var timeValue = http2.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo2').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.pasivo2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo2').innerHTML ='Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function Tipo3() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.patrimonio.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http3.open("GET", modurl, true);
  http3.onreadystatechange = useHttpResponse3;
  http3.send(null);
  sumar();
}

function useHttpResponse3() {
   if (http3.readyState == 4) {
    if(http3.status == 200) {
       var timeValue = http3.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo3').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.patrimonio2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo3').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}


function Tipo4() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.ingreso.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http4.open("GET", modurl, true);
  http4.onreadystatechange = useHttpResponse4;
  http4.send(null);
  Utilidad();
  Tipo6();
}

function useHttpResponse4() {
   if (http4.readyState == 4) {
    if(http4.status == 200) {
       var timeValue = http4.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo4').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.ingreso2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo4').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function Tipo5() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.gasto.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http5.open("GET", modurl, true);
  http5.onreadystatechange = useHttpResponse5;
  http5.send(null);
  Utilidad();
  Tipo6();
}

function useHttpResponse5() {
   if (http5.readyState == 4) {
    if(http5.status == 200) {
       var timeValue = http5.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo5').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.gasto2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo5').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />';
  }
}

function Tipo6() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.utilidad.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http6.open("GET", modurl, true);
  http6.onreadystatechange = useHttpResponse6;
  http6.send(null);
  Utilidad();
}

function useHttpResponse6() {
   if (http6.readyState == 4) {
    if(http6.status == 200) {
       var timeValue = http6.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo6').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.utilidad2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo6').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function Tipo7() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.venta.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http7.open("GET", modurl, true);
  http7.onreadystatechange = useHttpResponse7;
  http7.send(null);
}

function useHttpResponse7() {
   if (http7.readyState == 4) {
    if(http7.status == 200) {
       var timeValue = http7.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo7').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.venta2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo7').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function Tipo8() {
  var myurl = 'buscarCambio.php';
  myRand = parseInt(Math.random()*999999999999999);
  var i 
    for (i=0;i<document.up.tipomoney.length;i++){ 
       if (document.up.tipomoney[i].checked) 
          break; 
    } 
  var tipo= document.up.tipomoney[i].value 
	  
  var val=document.up.productivo.value;
  
  var modurl = myurl+"?rand="+myRand+"&tipo="+tipo+"&val="+val;
  http8.open("GET", modurl, true);
  http8.onreadystatechange = useHttpResponse8;
  http8.send(null);
}

function useHttpResponse8() {
   if (http8.readyState == 4) {
    if(http8.status == 200) {
       var timeValue = http8.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo8').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
	   document.up.productivo2.value=timeValue.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('tipo8').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function sumar() {
var n1 = parseFloat(document.up.activo.value);

var n2 = parseFloat(document.up.pasivo.value);
document.up.patrimonio.value=n1-n2;

}

function Utilidad() {
var n1 = parseFloat(document.up.ingreso.value);

var n2 = parseFloat(document.up.gasto.value);
document.up.utilidad.value=n1-n2;

}

function GuardaArchivo() {
  var myurl = 'upload.php';
  myRand = parseInt(Math.random()*999999999999999);
  
  var modurl = myurl+"?rand="+myRand;
  http.open("POST", modurl, true);
  http.onreadystatechange = useHttpResponse18;
  http.send(null);
}

function useHttpResponse18() {
   if (http8.readyState == 4) {
    if(http8.status == 200) {
       var timeValue = http8.responseXML.getElementsByTagName("timenow")[0];
       document.getElementById('tipo18').innerHTML = timeValue.childNodes[0].nodeValue+' ufv.';
    }
  } else {
  document.getElementById('tipo18').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function BusquedaUPAcre() {
 
  var myurl = 'buscarUPAC.php';
  
  var nom=document.up.nombre.value;
  var nit=document.up.nit.value;
  var ci=document.up.ci.value;
  
  for (i=0;i<document.up.op.length;i++){
       if (document.up.op[i].checked)
          break;
    }
  var op = document.up.op[i].value ;
  
  myRand = parseInt(Math.random()*999999999999999);  
  //var usuario= document.frm_info.x_name.value;  
  var modurl = myurl+"?rand="+myRand+"&nom="+nom+"&nit="+nit+"&ci="+ci+"&op="+op;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponses;
  http.send(null);
  return false;

}

function useHttpResponses() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
	   var timeValue2 = http.responseXML.getElementsByTagName("timenow")[1];
	   var resultado1= timeValue.childNodes[0].nodeValue;
	   var resultado2= timeValue2.childNodes[0].nodeValue;

	   document.getElementById('capa').innerHTML = "";
	   
	   var capa = document.getElementById("capa");
	   
       var newlbl = document.createElement("p");
	   
	   if(resultado1=="nn")
		newlbl.innerHTML = "<b>No existen Datos</b>";
		else
		newlbl.innerHTML = "<br><a href='declaracion.php?cod="+resultado1+"' target='_blank'><img src='images/pdf.gif' width='25' height='20' border='0' />Unidad Productiva: <b>"+resultado2+"</b> </a> <br> .... ";
	
	
	capa.appendChild(newlbl);
	
    }
  } else {
  document.getElementById('capa').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />';
  }
  return false;
  
  }
  function dis1()
  {
	  document.up.nombre.disabled=false;
	  document.up.nit.disabled=true;
	  document.up.ci.disabled=true;
	  
	  document.up.nombre.value="";
	  document.up.nit.value="";
	  document.up.ci.value="";
  }
  
  function dis3()
  {
	  document.up.nombre.disabled=true;
	  document.up.nit.disabled=false;
	  document.up.ci.disabled=true;
	  
	  document.up.nombre.value="";
	  document.up.nit.value="";
	  document.up.ci.value="";
  }
  
  function dis2()
  {
	  document.up.nombre.disabled=true;
	  document.up.nit.disabled=true;
	  document.up.ci.disabled=false;
	  
	  document.up.nombre.value="";
	  document.up.nit.value="";
	  document.up.ci.value="";
  }
  
function EliminaVerificacion(vari) {
  var variable=vari;
 
  var myurl = 'EliminaVerificacion.php';
  
  myRand = parseInt(Math.random()*999999999999999);  
  var modurl = myurl+"?rand="+myRand+"&veri="+variable;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponsest;
  http.send(null);
  return false;
}

function useHttpResponsest() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
	   var resultado= timeValue.childNodes[0].nodeValue;
	   if(resultado=="error")
			alert('Error al eliminar el registro');
		else
			{
			alert('Se elimino correctamente el registro');
			location.reload();
			}
    }
  } else {
   //alert('Error');//document.getElementById('capa').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />';
  }
  return false;
  
  }
  
 function BuscaCIRep() {
	 
  var num_doc=dijit.byId('numero_doc').attr('value');
 
  var myurl = 'BuscaCI.php';
  
  myRand = parseInt(Math.random()*999999999999999);  
  var modurl = myurl+"?rand="+myRand+"&ci="+num_doc;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponse10;
  http.send(null);
  return false;
}

function useHttpResponse10() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
	   var timeValue2 = http.responseXML.getElementsByTagName("timenow")[1];
       document.getElementById('capa10').innerHTML = timeValue.childNodes[0].nodeValue;
	   document.up.cantrep.value=timeValue2.childNodes[0].nodeValue;
    }
  } else {
  document.getElementById('capa10').innerHTML = 'Cargando... <img src="images/ajax-loader.gif" width="15" height="15" />'
  }
}

function EliminaCer(cod_ceri) {
	var w=0;
	
	if (confirm("...ESTA SEGURO(A) DE ANULAR Y ELIMINAR? "))
	{
       w=1;
    }
	else
	w=0;
	
	  if(w==1)
	  {
  var myurl = 'eliminaCer.php';
  myRand = parseInt(Math.random()*999999999999999);  
  var cod_cer=cod_ceri;
  var modurl = myurl+"?rand="+myRand+"&cod_cer="+cod_cer;
  http.open("GET", modurl, true);
  http.onreadystatechange = useHttpResponsesCer;
  http.send(null);
	  }
	  return false;
}

function useHttpResponsesCer() {
   if (http.readyState == 4) {
    if(http.status == 200) {
       var timeValue = http.responseXML.getElementsByTagName("timenow")[0];
       //document.getElementById('capa').innerHTML = timeValue.childNodes[0].nodeValue;
	   var men=timeValue.childNodes[0].nodeValue;
	   alert(men);
	   location.reload();
    }}
  }
