function select_text(campo)
{
var seleccionado=document.getElementById(campo);
seleccionado.focus();
seleccionado.select();
}

function nuevoAjax()
	{ 
		var xmlhttp=false; 
		try 
		{ 
			// No IE
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch(e)
		{ 
			try
			{ 
				// IE 
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
			} 
			catch(E) { xmlhttp=false; }
		}
		if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 
		return xmlhttp; 
	}


function quitar(numeroArticulo)
    {	    
			var ArticuloID = numeroArticulo;
	        var ajax1=nuevoAjax();
            ajax1.open("POST", '/Sys/quitaProdOrden.asp', true);
            ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax1.send("ArticuloID="+ArticuloID);            
			ajax1.onreadystatechange=function()
            { 
                if (ajax1.readyState==4)
                {
                    var respuesta=ajax1.responseText;
                    if(respuesta=="OK")
                    {
					location.reload();
					}
                    if(respuesta=="NO")
                    {
					alert("Existe un problema con su cotización, por favor llame por telefono");
					}
                }
			}
    }
	
	

function validaCantidad(campoCantidad,valor)
{
	var formDir=form1;
	var form=document.getElementById(formDir); //document.getElementById(minumero);
	var Cantidad=document.getElementById(campoCantidad);
	var CantidadValor=Cantidad.value;
	var valorOriginal = parseInt(valor);
	
	if (isNaN(CantidadValor) || CantidadValor==""){
	alert("Debe ingresar un número.")
	document.getElementById(campoCantidad).value = valorOriginal;
    return 0;
	}else{
	if (CantidadValor < 1){
	alert("Debe ingresar un número positivo")
	document.getElementById(campoCantidad).value = valorOriginal;
	return 0;
	}
	}

}

function agregaProducto(formid)
    {
	var formDir='form'+formid;
	var form=document.getElementById(formDir); //document.getElementById(minumero);
	var ArticuloID=form.ArticuloID.value;
	var Cantidad=form.Cantidad.value;
	
	divMensajeGal=document.getElementById('divMensajeGal'+formid);
	divTransparenteGal=document.getElementById('divTransparenteGal'+formid);
	
	if (isNaN(Cantidad) || Cantidad==""){
	alert("Debe ingresar la cantidad que desea.")
	document.getElementById(formDir).Cantidad.value = 1;
	divMensajeGal.innerHTML="Ingrese un número positivo por favor";
	return 0;
	}else{
	if (isNaN(Cantidad) || Cantidad<1){
	alert("Revise la cantidad por favor.")
	document.getElementById(formDir).Cantidad.value = 1;
	divMensajeGal.innerHTML="Revise la cantidad por favor";
	return 0;
	}
	}
	
			var texto="<img src='/Css/Site/loading.gif' alt='Enviando' style='float:left;'>Enviando...Por favor espere.";
			divMensajeGal.innerHTML=texto;
			divTransparenteGal.style.display="block";
    
	        var ajax=nuevoAjax();
            ajax.open("POST", '/Sys/agregaProdOrden.asp', true);
            ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            ajax.send("ArticuloID="+ArticuloID+"&Cantidad="+Cantidad);
            
            ajax.onreadystatechange=function()
            {
                if (ajax.readyState==4)
                {
                    var respuesta=ajax.responseText;
                    if(respuesta=="OK")
                    {
                    var texto="<div style='padding-top:0px;'><img src='/Css/Site/addd_cart.gif' style='float:left' alt='Agregado a Cotización'><a class='revisarcot' href='/Equipos_medicos.asp?accion=revisar-orden' style='height:auto;' alt='Revise su Cotización'>Ok, Revise su Cotización.</a></div>";
					
					divMensajeGal.innerHTML=texto;
					divTransparenteGal.style.display="block";
					}
                    if(respuesta=="EXISTE")
                    {
                    var texto="<div style='padding-top:0px;'><a class='revisarcot' href='/Equipos_medicos.asp?accion=revisar-orden' style='height:auto;' alt='Revisar Cotización'>Ya se encuentra en Cotización.</a></div>";
					divMensajeGal.innerHTML=texto;
					divTransparenteGal.style.display="block";
					}
                }
            }
    }