	
	// WILDCATMA -------------------------------------------------------------------------------------------------------------------------------- //
	// ajax.js ---------------------------------------------------------------------------------------------------------------------------------- //
	
	// Objeto ajax ------------------------------------------------------------------------------------------------------------------------------ //
	var obXHR;
	try {
		obXHR=new XMLHttpRequest();
	} catch(err) {
		try {
			obXHR=new ActiveXObject("Msxml2.XMLHTTP");
		} catch(err) {
			try {
				obXHR=new ActiveXObject("Microsoft.XMLHTTP");
			} catch(err) {
				obXHR=false;
			}
		}
	}

	function enter(e){ 
				
		var boton = document.getElementById('log_in').disabled=true;		
		var boton3 = document.getElementById('find');		
		var intKey = (window.Event) ? e.which : e.keyCode;
		  
		if (intKey == 13){
		    boton3.focus();

		}
	} 
	
	function loadin(){

		document.getElementById('closeorder').style.visibility = "hidden";
		document.getElementById("divresultorder").style.background = "url(../images/loading.gif)";
	}
	
	function muetramenu(code){
		
		var div = document.getElementById(code);
		
		obXHR.open("GET", "../php/ajaxOut.php?menu="+true+"&parent="+code);
		
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				div.innerHTML=obXHR.responseText;
		}
		obXHR.send(null); 
	}
	
	// Add to cart ------------------------------------------------------------------------------------------------------------------------------ //
	function addtocart(user, gama){
	
		var cant = document.getElementById("cantidad"+gama).value;
		var code = document.getElementById("code"+gama).value;
		var prod = document.getElementById("producto"+gama).value;
		
		// variables por definir...
		var precio = document.getElementById("respvp"+gama).value;
		var dto = 0;
		var iva = 0;
		
		var div = document.getElementById("resultado"+gama);
				
		obXHR.open("GET", "../php/ajaxOut.php?addtocart="+true+"&user="+user+"&producto="+prod+"&cantidad="+cant+"&precio="+precio+"&dto="+dto+"&iva="+iva);
		
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				div.innerHTML=obXHR.responseText;
		}
		obXHR.send(null); 
		
	}
	
	function restartAmount(gama){
		
		var div = document.getElementById('showamount'+gama);
		var div2 = document.getElementById('resultado'+gama);
		
		obXHR.open("GET", "../php/ajaxOut.php?restartAmount="+true+"&gama="+gama);
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				div.innerHTML=obXHR.responseText;
				div2.innerHTML='';
		}
		obXHR.send(null); 
		
	}
	
	// Delete row 2 order ----------------------------------------------------------------------------------------------------------------------- //
	function delRowOrder(order){
		obXHR.open("GET", "../php/ajaxOut.php?delRowOrder="+true+"&order="+order);
		
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				window.location.href=window.location.href;
		}
		obXHR.send(null); 
	}
	
	// Canvia cantitat -------------------------------------------------------------------------------------------------------------------------- //
	function setAmount(id){
		cant = document.getElementById("cantidad"+id).value;
		order = document.getElementById("order").value;
		div = document.getElementById("resImporte"+id);
			
		obXHR.open("GET", "../php/ajaxOut.php?setAmount="+true+"&order="+id+"&amount="+cant);
		
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200){
				div.innerHTML=obXHR.responseText;
				resetTotal(order);
				
			}
		}
		obXHR.send(null);
		
		
	}
	
	// Reset amount total ----------------------------------------------------------------------------------------------------------------------- //
	function resetTotal(id){
		div = document.getElementById("totalAmount");
		
		obXHR.open("GET", "../php/ajaxOut.php?resetTotal="+true+"&order="+id);
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				div.innerHTML=obXHR.responseText;
		}
		obXHR.send(null);
	}
	
	// Show pvp --------------------------------------------------------------------------------------------------------------------------------- //
	function showPvp(gama, user){
		
		var div = document.getElementById('respvp'+gama);
		var code = document.getElementById("producto"+gama).value;		
				
		obXHR.open("GET", "../php/ajaxOut.php?showPvp="+true+"&code="+code+"&user="+user);
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200){
				document.getElementById("respvp"+gama).value=obXHR.responseText;
				restartAmount(gama);			
			}
		}
		obXHR.send(null);
	}
	
	// Pasa a dos ------------------------------------------------------------------------------------------------------------------------------- //
	function pasaAdos(order){
		dir = document.getElementById("dir").value;
		
		if (dir != ''){
			obXHR.open("GET", "../php/ajaxOut.php?pasaAdos="+true+"&order="+order+"&dir="+dir);
		
			obXHR.onreadystatechange = function() {
				if (obXHR.readyState == 4 && obXHR.status == 200){
					window.location.href="pasodos.php?order="+order;
				}
			}
			obXHR.send(null);
		} else 
			alert("Es necesaria una direcci�n de envio");
	}
	
	// Pasa a tres ------------------------------------------------------------------------------------------------------------------------------ //
	function pasoAtres(order){
		ref = document.getElementById("ref").value;
		mail = document.getElementById("mail").value;
		coment = document.getElementById("comentario").value;

		if (mail != ''){
			obXHR.open("GET", "../php/ajaxOut.php?pasoAtres="+true+"&order="+order+"&ref="+ref+"&mail="+mail+"&coment="+coment);
		
			obXHR.onreadystatechange = function() {
				if (obXHR.readyState == 4 && obXHR.status == 200){
					window.location.href="closeorder.php?order="+order;
				}
			}
			obXHR.send(null);
		} else
			alert("Es necesario un E-mail de contacto.");
	}
	
	function showDocs(){

		value = document.getElementById("docs").value;
		div = document.getElementById("resultado");
		
		obXHR.open("GET", "php/ajaxOut.php?showDocs="+true+"&value="+value);
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200)
				div.innerHTML=obXHR.responseText;
		}
		obXHR.send(null);
	}

