function XmlHttp() {}
	XmlHttp.create = function () {
	try {
	if (window.XMLHttpRequest) {
	var req = new XMLHttpRequest();
	
	// some older versions of Moz did not support the readyState property
	// and the onreadystate event so we patch it!
	if (req.readyState == null) {
	req.readyState = 1;
	req.addEventListener("load", function () {
	req.readyState = 4;
	if (typeof req.onreadystatechange == "function")
	req.onreadystatechange();
	}, false);
	}
	
	return req;
	}
	if (window.ActiveXObject) {
	return new ActiveXObject(getControlPrefix() + ".XmlHttp");
	}
	}
	catch (ex) {}
	// fell through
	throw new Error("Your browser does not support XmlHttp objects");
};
function save_orden_vista(orden,vista,link){
	var xmlHttp = XmlHttp.create();
	xmlHttp.open("GET", "modorden.php?orden=" + orden + "&vista=" + vista, true);   // async
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			location.href=link; // no hay que hacer nada
		}
	};
	window.setTimeout(function () {
	  xmlHttp.send('');
	}, 10);
}
function addcarritoAJAX(id,cantidad,optionpos){
	if(optionpos != -1){ // -1 no tiene opciones, si tiene opciones es la pos del articulo
		eval("ilista = document.forms.formproduct"+optionpos+".sel0.selectedIndex;");
		eval("options = document.forms.formproduct"+optionpos+".sel0.options["+ilista+"].value;");
	} else {
		var options = '';
	}
	var xmlHttp = XmlHttp.create();
	xmlHttp.open("GET", "modcartajax.php?id=" + id + "&cantidad=" + cantidad + "&sel0=" + options, true);   // async
	xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4) {
			document.getElementById("CarritoDiv").innerHTML = xmlHttp.responseText;
		}
	};
	//document.getElementById("CarritoDiv").innerHTML = "<span class='txtrojo10'><b>Cargando...</b></span>";
	// llamada en otro hilo para permitir actualizar el interfaz
	window.setTimeout(function () {
	  xmlHttp.send('');
	}, 10);
}
function ocultaItems(){
          contenedores = document.getElementsByTagName('div')
          numContenedores = contenedores.length
          for(m=0; m < numContenedores; m++){
             if(contenedores[m].id.indexOf('opciones_') == 0)
             contenedores[m].style.display = 'none';
          }
}
function Paneles(id) 
{
	if ((document.getElementById(id)) == undefined) {
	} else {
		ocultaItems()
		var obj = document.getElementById(id).style;
		obj.display = obj.display == "block" ? "none" : "block";
  }
}
function Elige(valor, campo, index) {
	var showfield = eval("document.forms.formproduct"+ campo + ".showsel_0");
	showfield.value = valor.substring(0,14) + "..";
	
	var MiSelect = eval("document.forms.formproduct"+ campo + ".sel0");
	MiSelect.value = valor;
	MiSelect.selectedIndex = index;
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function OnPress(e, valor){
	var Ucode=e.keyCode? e.keyCode : e.charCode
	if (Ucode == 13) {
		document.searchform.submit();
	}
}
function comprobar_datos_y_enviar() { 
    var i; 
    var forma_de_envio; 
    for (i=0;i<document.cartmodify.fos.length;i++){ 
       if (document.cartmodify.fos[i].checked) 
          break; 
    }
    if(i==0){
		forma_de_envio = document.cartmodify.fos.value;
	}else{
		forma_de_envio = document.cartmodify.fos[i].value;
	}
	errors='';
	if(forma_de_envio==2 || forma_de_envio==3 || forma_de_envio==4  || forma_de_envio==6  || forma_de_envio==7) {
		if(document.cartmodify.telefono.value=='') { 
			errors ='Si elige ´envio urgente´, tiene que indicar su telefono para la confirmacion del pedido. Caso contrario no sera enviado.'; 
		}
	}
	if(document.cartmodify.subtotal.value==0) { 
		errors ='No tiene ningun producto en su carrito!'; 
	}
	if( document.cartmodify.nombre.value=='' || document.cartmodify.apellidos.value=='' || document.cartmodify.direccion.value=='' || document.cartmodify.cp.value=='' || document.cartmodify.localidad.value=='' || document.cartmodify.provincia.value=='' || document.cartmodify.telefono.value=='' || document.cartmodify.email.value=='') { 
		errors ='Todos los datos de contacto excepto el campo ´empresa´ son obligatorios.'; 
	}
	if (errors){ 
		alert(errors);
	}else{
		document.cartmodify.action = "pedido.php"; 
		document.cartmodify.submit();
	}
}
function act_carrito(id,accion) 
{
	document.cartmodify.accion.value = accion;
	document.cartmodify.aline.value = id;
	document.cartmodify.submit();
}
function act_pais() 
{
	document.cartmodify.accion.value = 'mod_pais'; 
	document.cartmodify.aline.value = document.cartmodify.pais.options[document.cartmodify.pais.selectedIndex].value; 
	document.cartmodify.submit();
}
function act_fos(fos) 
{
	document.cartmodify.accion.value = 'mod_fos'; 
	document.cartmodify.aline.value = fos; 
	destination = document.cartmodify.action + "#foslink"; 
	document.cartmodify.action = destination; 
	document.cartmodify.submit();
}
function act_fop(fop) 
{
	document.cartmodify.accion.value = 'mod_fop'; 
	document.cartmodify.aline.value = fop; 
	destination = document.cartmodify.action + "#foplink"; 
	document.cartmodify.action = destination; 
	document.cartmodify.submit();
}
function comprobar_nocertificado() { 
  respond=confirm('Los envíos NO CERTIFICADOS se envían por correo ordinario. En caso de extravío el cliente asumirá el total de la perdida, TIENDADE no se hará responsable de la incidencia, ya que este tipo de envio no queda registrado en correos. Si estas de acuerdo con las condiciones del envío ´no certificado´ confírmalo en el botón ´aceptar´, en caso contrario pulse ´cancelar´ y elija otra forma de envío. '); 
  if (respond==true) {
	act_fos(5);
  }else{
	act_fos(1);
  }
}
function comprobar_cookies() { 
	document.cookie = 'test=yes';
	errors='';  
	if(document.cookie == '') {
		errors ='Las cookies no estan activadas. El pago con tarjeta requiere la activación de las cookies. Las puedes activar en el Internet Explorer: Herramientas->opciones de internet->privacidad: Mueve el boton abajo de todo.';
	}else{   
		errors ='IMPORTANTE: El pago con PAYPAL requiere que se aceptan las cookies. Compruebe el estado de privacidad en el Internet Explorer: Herramientas->opciones de internet->privacidad: El boton tiene que estar abajo de todo.';
	}   
	if (errors) alert(errors);
}    

