function cerrar_aviso(){
	document.getElementById("bloquear").style.display="none";
}
function NuevoAjax(){
    var xmlhttp=false;
    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 cotizar(cod,precio,cant,stock){
	if(cant<=stock){
		document.getElementById("texto").innerHTML='<span class="texto_naranja"><strong>Agregando producto a la cotización...</strong></span><br /><br><img src="imagenes/progreso.gif" width="16" height="16" />';
		document.getElementById("bloquear").style.display="inline";
		if(cant=="" || cant==0){
			cant=1;	
		}
		var vars="&cod="+cod+"&precio="+precio+"&cant="+cant;
		var url = 'addCarrito.php';
		ajax=NuevoAjax(); 
		ajax.open("POST",url,true);
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(vars);
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				//Sucede cuando la consulta se realizó
				if(ajax.status==200){
					//Todo OK
					document.getElementById("texto").innerHTML='<span class="texto_naranja"><strong>Producto agregado a la cotización</strong></span><br /><br><a href="javascript:cerrar_aviso();" style="color:#F6941C;"><img src="imagenes/btnCerrar.png" border="0" /></a>';
					valor=ajax.responseText;
					if(valor!="Bs.0"){
						document.getElementById("btnVerCarrito").style.display='inline';
						document.getElementById("bsCarrito").style.display='inline';
					} else {
						document.getElementById("btnVerCarrito").style.display='none';
						document.getElementById("bsCarrito").style.display='none';
					}
					document.getElementById("bsCarrito").value=valor;
				} else if(ajax.status==404){
					//La pagina no existe
					//document.getEelementbyId("mensajes").innerHTML = "La página no existe";
					//aviso("pagina no encontrada","250","80");
				}else{
					//Mostramos el posible error
					//document.getEelementbyId("mensajes").innerHTML = "Error:".ajax.status; 
					//aviso("Error:"+ajax.status,"250","80");
				}
			}
		}
	} else {
		document.getElementById("texto").innerHTML='<span class="texto_naranja"><div  align="justitfy">La cantidad que deseas cotizar esta por encima de las disponibles en tienda, para mayor información comunícate con cualquiera de nuestros puntos de venta</div></span><br /><br><a href="javascript:cerrar_aviso();" style="color:#F6941C;"><img src="imagenes/btnCerrar.png" border="0" /></a>';
		document.getElementById("bloquear").style.display="inline";
	}
	return false; 
}
function delProd(cod,nom){
	msg="Estas seguro de querer eliminar de la cotización el producto "+nom;
	if(confirm(msg)){
		delProdConf(cod);	
	}
}
function delProdConf(cod){
	document.getElementById("texto").innerHTML='<span class="texto_naranja"><strong>Eliminando producto de la cotización...</strong></span><br /><br><img src="imagenes/progreso.gif" width="16" height="16" />';
	document.getElementById("bloquear").style.display="inline";
	var vars="&cod="+cod;
	var url = 'delProdCar.php';
    ajax=NuevoAjax(); 
    ajax.open("POST",url,true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(vars);
    ajax.onreadystatechange=function(){
		if(ajax.readyState==4){
            //Sucede cuando la consulta se realizó
		    if(ajax.status==200){
                //Todo OK
				document.location.reload();
            } else if(ajax.status==404){
                //La pagina no existe
                //document.getEelementbyId("mensajes").innerHTML = "La página no existe";
				//aviso("pagina no encontrada","250","80");
            }else{
                //Mostramos el posible error
                //document.getEelementbyId("mensajes").innerHTML = "Error:".ajax.status; 
				//aviso("Error:"+ajax.status,"250","80");
            }
        }
    }
	return false; 
}

function vaciar(){
	document.getElementById("texto").innerHTML='<span class="texto_naranja"><strong>Vaciando el carrito de cotizaciones...</strong></span><br /><br><img src="imagenes/progreso.gif" width="16" height="16" />';
	document.getElementById("bloquear").style.display="inline";
	var url = 'vaciarCarrito.php';
	vars="";
    ajax=NuevoAjax(); 
    ajax.open("POST",url,true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(vars);
    ajax.onreadystatechange=function(){
        if(ajax.readyState==4){
            //Sucede cuando la consulta se realizó
		    if(ajax.status==200){
                //Todo OK
				document.location.reload();
            } else if(ajax.status==404){
                //La pagina no existe
                //document.getEelementbyId("mensajes").innerHTML = "La página no existe";
				//aviso("pagina no encontrada","250","80");
            }else{
                //Mostramos el posible error
                //document.getEelementbyId("mensajes").innerHTML = "Error:".ajax.status; 
				//aviso("Error:"+ajax.status,"250","80");
            }
        }
    }
	return false;
}
/*function procCotizacion(){
	document.getElementById("texto").innerHTML='<span class="texto_naranja"><strong>Tu cotización esta siendo procesada...</strong></span><br /><br><img src="imagenes/progreso.gif" width="16" height="16" />';
	document.getElementById("bloquear").style.display="inline";
	var url = 'procCotizacion.php';
	vars="";
    ajax=NuevoAjax(); 
    ajax.open("POST",url,true);
	ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    ajax.send(vars);
    ajax.onreadystatechange=function(){
        if(ajax.readyState==4){
            //Sucede cuando la consulta se realizó
		    if(ajax.status==200){
                //Todo OK
				eval(ajax.responseText);
            } else if(ajax.status==404){
                //La pagina no existe
                //document.getEelementbyId("mensajes").innerHTML = "La página no existe";
				//aviso("pagina no encontrada","250","80");
            }else{
                //Mostramos el posible error
                //document.getEelementbyId("mensajes").innerHTML = "Error:".ajax.status; 
				//aviso("Error:"+ajax.status,"250","80");
            }
        }
    }
	return false;
}*/
