// JavaScript Document
var enProceso = false; // lo usamos para ver si hay un proceso activo
var http = getHTTPObject(); // Creamos el objeto XMLHttpRequest
var enProcesog = false; // lo usamos para ver si hay un proceso activo
var httpg = getHTTPObject(); // Creamos el objeto XMLHttpRequest
var objeto = null;
var tipo = ""
var aid = null;
function handleHttpResponse() {
	if (http.readyState == 4) {
		if (http.status == 200) {
			if (http.responseText.indexOf('invalid') == -1) {
			// Armamos un array, usando la coma para separar elementos
			results = http.responseText;
			if(tipo==1) // llenar lo de la factura
			{
				if(results == "<@>Producto NO encontrado<@><@>0<@><@><@><@><@><@><@>")
				{
					document.getElementById(objeto).value = "-";
					buscaPorNombre(1,"Producto NO Encontrado");
				}else{
					document.getElementById(objeto).value = results;
					document.getElementById("td"+g_c_f).innerHTML = "<label title='Haga click aqui para buscar por producto' class='chooseHand' onmouseover='showHelpCont(" +g_c_f+ ")' onmouseout='emptyHelpCont()' onclick=\"buscaPorNombre("+g_c_f+",'" + document.getElementById("txtallval"+g_c_f).value.toString().split("<@>")[1] + "')\">&nbsp;" + document.getElementById("txtallval"+g_c_f).value.toString().split("<@>")[1] + "</label>";
					document.getElementById("txtcant"+g_c_f).value = "1"
					document.getElementById("txtvalu"+g_c_f).value = parseFloat(document.getElementById("txtallval"+g_c_f).value.toString().split("<@>")[3]);
					document.getElementById("txtvalu"+g_c_f+"td").innerHTML = "$ " + redondear(parseFloat(document.getElementById("txtallval"+g_c_f).value.toString().split("<@>")[3])/1.12,2);
					var t = 1 * (parseFloat(document.getElementById("txtallval"+g_c_f).value.toString().split("<@>")[3])/1.12);
					document.getElementById("txtvalt"+g_c_f).value = redondear(t,2)
					document.getElementById("txtcant"+g_c_f).focus();
					document.getElementById("txtcant"+g_c_f).select();
				}
			}else if(tipo==3) // llenar lo de la factura
			{
				document.getElementById(objeto).innerHTML = results;
				
			}else if(tipo==4) // llenar lo de la factura
			{
				document.getElementById(objeto).innerHTML = results;
			}else
			{
				alert("Error desconocido");
			}
			enProceso = false;
			}
		}
	}
}

function getGeneral(objeto_contenedor,id_operacion, valor){
	if (!enProceso && http)
	{
		objeto = escape(objeto_contenedor.toString());
		tipo = parseInt(id_operacion.toString());
		var url = "_xfnv.asp?id=" + tipo + "&valor=" + valor;
		http.open("GET", url, true);
		http.onreadystatechange = handleHttpResponse;
		enProceso = true;
		http.send(null);
	}
}

function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) { xmlhttp = false; }
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) { xmlhttp = false; }
}
return xmlhttp;
}