var peticion = false; 
var  testPasado = false; 
try { 
  peticion = new XMLHttpRequest(); 
  } catch (trymicrosoft) { 
  try { 
  peticion = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (othermicrosoft) { 
  try { 
  peticion = new ActiveXObject("Microsoft.XMLHTTP"); 
  } catch (failed) { 
  peticion = false; 
  } 
  } 
} 
if (!peticion) 
alert("¡ERROR AL INICIALIZAR AJAX!"); 
  
function compruebacupon (campocupon, url) { 
	var element =  document.getElementById('marco_cupon'); 
	var valordepende = document.getElementById(campocupon);
	var x = valordepende.value;
	var fragment_url = '/includes/ajax/apic.asp?clase=compruebacupon&id='+x; 
	element.innerHTML = '<img src="/img/general/loading.gif" />'; 
	//abrimos la url 
	peticion.open("GET", fragment_url); 
	peticion.onreadystatechange = function() { 
		if (peticion.readyState == 4) { 
		//escribimos la respuesta 
			if(unescape(peticion.responseText) == 'OK') {
				window.location = url;
			}
			else{
				element.innerHTML = '<input type="text" maxlenght="25" id="campo_cupon" name="cupon" class="campocupon" />';
				alert(unescape(peticion.responseText));
			}
		} 
	} 
   peticion.send(null); 
} 

function login_ajax(html_reemplazo, campo_email, campo_password, url){
	var element =  document.getElementById(html_reemplazo); 
	var valordepende = document.getElementById(campo_email);
	var valordepende1 = document.getElementById(campo_password);
	var x = valordepende.value;
	var y = valordepende1.value;
	var fragment_url = '/includes/ajax/login.asp?email='+x+'&pass='+y; 
	anterior=element.innerHTML;
	element.innerHTML = '<img src="/img/general/loading.gif" />'; 
	valordepende.disabled=true;
	valordepende1.disabled=true;
	peticion.open("GET", fragment_url); 
	peticion.onreadystatechange = function() { 
		if (peticion.readyState == 4) { 
		//escribimos la respuesta 
			if(unescape(peticion.responseText) == 'OK') {
				window.location = url;
			}
			else{
				element.innerHTML = anterior;
				alert(unescape(peticion.responseText));
				valordepende.disabled=false;
				valordepende1.disabled=false;
			}
		} 
	} 
   peticion.send(null); 
}

function cambiotransporte (combopaises, combocp, divdevolucion, sesion, simbolomoneda) { 
	jQuery("#"+divdevolucion).html('<img src="/img/general/cargando.gif" />');
	jQuery.get("/includes/ajax/apic.asp", {clase: "formasenvio", id: jQuery("#"+combopaises).val(), sesion: sesion, simbolo: simbolomoneda, cpdestino: jQuery('input[name="'+combocp+'"]').val()}, function(data){ 
		jQuery("#"+divdevolucion).html(data);
	});
} 

function validacamposcarro(){
}

function cambiopago (url, comboAnterior, element_id) { 
	//Obtenemos el contenido del div 
	//donde se cargaran los resultados 
	var element =  document.getElementById(element_id); 
	//Obtenemos el valor seleccionado del combo anterior 
	var valordepende = document.getElementById(comboAnterior) 
	var x = valordepende.value 
	//construimos la url definitiva 
	//pasando como parametro el valor seleccionado 
	if (url.indexOf('?')!=-1){
		var fragment_url = url+'&id='+x; 
	} else {
		var fragment_url = url+'?id='+x; 
	} 
	element.innerHTML = '<img src="/img/general/cargando.gif" />'; 
	//abrimos la url 
	peticion.open("GET", fragment_url); 
	peticion.onreadystatechange = function() { 
		if (peticion.readyState == 4) { 
			//escribimos la respuesta 
			element.innerHTML = unescape(peticion.responseText); 
		} 
	} 
   peticion.send(null); 
} 

function saldopositivo(saldo, mensaje, total){
	if(confirm(mensaje+"\n"+total+": "+saldo)){
		document.getElementById("saldocs").value="1";
		document.formcarro.submit();
	} else {
		document.formcarro.submit();
	}
}

function cambiadireccionenvio(Iden, sesion, simbolo){
	var element = document.getElementById(Iden); 
	var x = element.value;
	document.formcarro.flogin_pais.value=document.getElementById('authpais'+x).value;
	document.formcarro.flogin_contacto.value=document.getElementById('authcontacto'+x).value;
	document.formcarro.flogin_direccion.value=document.getElementById('authdireccion'+x).value;
	document.formcarro.flogin_poblacion.value=document.getElementById('authpoblacion'+x).value;
	document.formcarro.flogin_provincia.value=document.getElementById('authprovincia'+x).value;
	document.formcarro.flogin_cp.value=document.getElementById('authcp'+x).value;
	document.formcarro.flogin_telefono.value=document.getElementById('authtelefono'+x).value;
	cambiotransporte('carro_paises','flogin_cp','carro_ajax_envios',sesion,simbolo);
}













