function nuevoAjax(xmlhttp){

   try {
       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
   catch (e) {
       try {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (E) {
          xmlhttp = false;
      }
   }
   if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
   }
   return xmlhttp
}

function cargarContenido(pagina,destino,enfoque,enfoque1){
   var contenedor;
   var ajax;
   
      //alert(pagina);
   
   contenedor = document.getElementById(destino);
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
         contenedor.innerHTML = ajax.responseText;
		 if(enfoque)
		 {
			document.getElementById(enfoque).focus();
			document.getElementById(enfoque1).focus();
		 }
      }
   }
   ajax.send(null);
}

function cargarContenidoConRetorno(pagina,destino,enfoque,enfoque1,enfoque2){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   contenedor = document.getElementById(destino);
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) 
	  {
		 if (ajax.responseText!=0)
		 {
         	contenedor.innerHTML = ajax.responseText;
			 if(enfoque)
			 {
				document.getElementById(enfoque).focus();
				document.getElementById(enfoque1).focus();
				document.getElementById(enfoque2).focus();
			 }
		 }
      }
   }
   ajax.send(null);
}

function verify() {
	msg = "ESTA SEGURO DE CERRAR SESION A ESTE USUARIO?, LA ACCION ES IRREVERSIBLE";
	return confirm(msg);
} 

function verify_borrar() {
	msg = "ESTA SEGURO DE BORRAR ESTE REGISTRO?, LA ACCION ES IRREVERSIBLE";
	return confirm(msg);
} 

function verify_borrar_pedido() {
	msg = "ESTA SEGURO DE BORRAR PEDIDO?, LA ACCION ES IRREVERSIBLE";
	return confirm(msg);
} 

function MsjCerrarInventario() {
	msg = "ESTA ACCION ES IRREVERSIBLE, ESTA SEGURO DE CONTINUAR?";
	return confirm(msg);
} 

function MsjCancelarDocumento() {
	msg = "ESTA A PUNTO DE CANCELAR UN DOCUMENTO, ESTA SEGURO DE CONTINUAR?";
	return confirm(msg);
} 

function MsjCrearPedido() {
	msg = "ESTA A PUNTO DE CREAR UN PEDIDO, ESTA SEGURO DE CONTINUAR?";
	return confirm(msg);
} 

function cargarContenidoParaImprimir(pagina)
{
	var ventana = window.open(pagina,'',''); 
}

function recalculoDocumentoProductos(pagina){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
		  //alert(ajax.responseText);
		  var resultados =ajax.responseText.split("|");
		  document.getElementById('cantidad').value = resultados[0];
		  document.getElementById('costo').value = resultados[1];
		  document.getElementById('importe').value = resultados[2];
      }
   }
   ajax.send(null);
}

function recalculoDocumentoProductosDescuento(pagina){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
		  //alert(ajax.responseText);
		  var resultados =ajax.responseText.split("|");
		  document.getElementById('cantidad').value = resultados[0];
		  document.getElementById('costo').value = resultados[1];
		  document.getElementById('importe').value = resultados[2];
		  document.getElementById('descuento').value = resultados[3];
      }
   }
   ajax.send(null);
}

function recalculoDocumentoProductosVentas(pagina){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
		  //alert(ajax.responseText);
		  var resultados =ajax.responseText.split("|");
		  document.getElementById('cantidad').value = resultados[0];
		  document.getElementById('precio').value = resultados[1];
		  document.getElementById('importe').value = resultados[2];
		  document.getElementById('preciosiniva').value = resultados[3];
		  document.getElementById('descuento').value = resultados[4];
      }
   }
   ajax.send(null);
}

function recalculoExtensionFichaCredito(pagina){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
		  //alert(ajax.responseText);
		  var resultados =ajax.responseText.split("|");
		  document.getElementById('limite').value = resultados[0];
		  document.getElementById('creditodisponible').value = resultados[1];
      }
   }
   ajax.send(null);
}

function recalculoDocumentoCXC(pagina){
   var contenedor;
   var ajax;
   
   //alert(pagina);
   
   ajax = nuevoAjax(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
		  //alert(ajax.responseText);
		  var resultados =ajax.responseText.split("|");
		  document.getElementById('importe').value = resultados[0];
      }
   }
   ajax.send(null);
}

