    var sendReq = getXmlHttpRequestObject();
    //Gets the browser specific XmlHttpRequest Object
    function getXmlHttpRequestObject() {
        if (window.XMLHttpRequest) {
            return new XMLHttpRequest();
        } else if(window.ActiveXObject) {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } else {
            document.getElementById('status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.  Consider upgrading your browser.';
        }
    }



    //Send a message
    function borra_item_pedido(url, clean, id) {
        if (sendReq.readyState == 4 || sendReq.readyState == 0) {
            sendReq.open("POST", get_clean_url(url, 'ajax/borra_item_pedido/' + id, clean) , true);
            sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            sendReq.onreadystatechange = handle_borra_item_pedido; 
            var param = '';
            sendReq.send(param);
        }                            
    }


    function handle_borra_item_pedido() {
        if (sendReq.readyState == 4) {
            if (sendReq.responseText !== "") {
                respuesta = sendReq.responseText;
                if(respuesta.indexOf(',') != -1) {
                    temp = respuesta.split(',');
                    id = temp[0];
                    total = temp[1];
                    elementos = temp[2];
                } else {
                    return (true);
                }
                jQuery("#carrito_" + id).hide('fast');

                document.getElementById("elementos").innerHTML = "Elementos: " + elementos;
                document.getElementById("valor").innerHTML = "Valor: " + total + "&euro;";

                document.getElementById("total").innerHTML = "Total: " + total + "&euro;";
                if (total < 10) {
                    jQuery(".boton_comprar_si").hide();
                    jQuery(".boton_comprar").show();
                }
            }
        }
    }
    
    
    
        
    //Send a message
    function enviar_form_contacto(url, clean) {
        if (sendReq.readyState == 4 || sendReq.readyState == 0) {
            var nomb = My_URLEncode($("#form_nombre").val());
            var mail = My_URLEncode($("#form_mail").val());
            var telf = My_URLEncode($("#form_telefono").val());
            var comentario = My_URLEncode($("#form_comentario").val());

            if (nomb == "" || nomb[0] == "<") {
                alert ("debe introducir su nombre");
                return false;
            }
            if ((mail == "" || mail[0] == "<") && 
                (telf == "" || telf[0] == "<"))
            {
                alert ("debe introducir un email o un telefono de contacto");
                return false;
            }
            if (comentario == "" || comentario[0] == "<") {
                alert ("cual es su comentario ?");
                return false;
            }
            sendReq.open("POST", get_clean_url(url, 'ajax/enviar_form_contacto/' + nomb + '/' + mail + '/' + telf + '/' + comentario, clean), true);

            sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            sendReq.onreadystatechange = handle_enviar_form_contacto; 
            var param = '';
            sendReq.send(param);
            cursor_loading();
        }                            
    }
    function My_URLEncode(texto) {
        texto = texto.replace(/\//g, '[_]');

        return texto;
    }
    function handle_enviar_form_contacto() {
        if (sendReq.readyState == 4) {
            respuesta = sendReq.responseText;
            if (respuesta == "1") {
                document.getElementById("boton_enviar").innerHTML="Enviado correctamente";
            } else {
                alert ("algun problema en el envio, intentelo mas adelante");
            }
            cursor_default();
        }
    }





    function enviar_filtro_editorial(url, p0, p1, p2, clean) {
        if (sendReq.readyState == 4 || sendReq.readyState == 0) {
            var editorial_id = document.getElementById("editorial").value; 
            if (editorial_id === "0" ) {
                return false;
            }
            sendReq.open("POST", get_clean_url(url, 'ajax/enviar_filtro_editorial/' + p0 + '/' + p1 + '/' + p2 + '/' + editorial_id, clean), true);

            sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            sendReq.onreadystatechange = handle_enviar_filtro_editorial; 
            var param = '';
            sendReq.send(param);
            cursor_loading();
        }                            
    }
    function handle_enviar_filtro_editorial() {
        if (sendReq.readyState == 4) {
            respuesta = sendReq.responseText;
            if (respuesta != "") {
                document.getElementById("filtro_coleccion").innerHTML=respuesta;
            } else {
                alert ("algun problema en el envio, intentelo mas adelante");
            }
            cursor_default();
        }
    }
    
    
    
    
    
    





    function orden_subir_cliente(url, clean, aplicacion, div_id1) {
        var div_id2 = (div_id1 - 1);
        var origen = document.getElementById("span_cliente_" + aplicacion + "_" + div_id1).innerHTML;
        var destino = document.getElementById("span_cliente_" + aplicacion + "_" + div_id2).innerHTML;
        orden_cambia_cliente(url, clean, origen, destino, aplicacion, div_id1, div_id2);
    }
    function orden_bajar_cliente(url, clean, aplicacion, div_id1) {
        var div_id2 = (div_id1 + 1);
        var origen = document.getElementById("span_cliente_" + aplicacion + "_" + div_id1).innerHTML;
        var destino = document.getElementById("span_cliente_" + aplicacion + "_" + div_id2).innerHTML;
        orden_cambia_cliente(url, clean, origen, destino, aplicacion, div_id1, div_id2);
    }
    function orden_cambia_cliente(url, clean, uno, dos, aplicacion, div_id1, div_id2) {
        // hace llamada y configuramos retorno en
        if (sendReq.readyState == 4 || sendReq.readyState == 0) {
            sendReq.open("POST", get_clean_url(url, 'ajax/ordena_cliente/' + uno + '/' + dos + '/' + aplicacion + '/' + div_id1 + '/' + div_id2, clean) , true);
            sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            sendReq.onreadystatechange = handle_orden_cambia_cliente;
            var param = '';
            sendReq.send(param);
        }
    }        
    // cambiamos posiciones de clientes en divs de la pagina
    function handle_orden_cambia_cliente() {
        if (sendReq.readyState == 4) {
            respuesta = sendReq.responseText;
            if(respuesta.indexOf(',') != -1) {
                temp = respuesta.split(',');
                aplicacion    = temp[0];
                div_id1 = temp[1];
                div_id2 = temp[2];
            } else {
                return (true);
            }
    // cambio titulo
            var temp = document.getElementById("titulo_cliente_" + aplicacion + '_' + div_id1).innerHTML;
            document.getElementById("titulo_cliente_" + aplicacion + '_' + div_id1).innerHTML = document.getElementById("titulo_cliente_" + aplicacion + '_' + div_id2).innerHTML;
            document.getElementById("titulo_cliente_" + aplicacion + '_' + div_id2).innerHTML = temp;
    // cambio descripcion
            var temp = document.getElementById("descripcion_cliente_" + aplicacion + '_' + div_id1).innerHTML;
            document.getElementById("descripcion_cliente_" + aplicacion + '_' + div_id1).innerHTML = document.getElementById("descripcion_cliente_" + aplicacion + '_' + div_id2).innerHTML;
            document.getElementById("descripcion_cliente_" + aplicacion + '_' + div_id2).innerHTML = temp;
    // cambio clientes
            var temp = document.getElementById("imagenes_" + aplicacion + '_' + div_id1).innerHTML;
            document.getElementById("imagenes_" + aplicacion + '_' + div_id1).innerHTML = document.getElementById("imagenes_" + aplicacion + '_' + div_id2).innerHTML;
            document.getElementById("imagenes_" + aplicacion + '_' + div_id2).innerHTML = temp;
        }
    }
    


    
    
    
    function orden_subir_imagen(url, clean, cliente, div_id1) {
        var div_id2 = (div_id1 - 1);
        var origen = document.getElementById("span_imagen_" + cliente + "_" + div_id1).innerHTML;
        var destino = document.getElementById("span_imagen_" + cliente + "_" + div_id2).innerHTML;
        orden_cambia_imagen(url, clean, origen, destino, cliente, div_id1, div_id2);
    }
    function orden_bajar_imagen(url, clean, cliente, div_id1) {
        var div_id2 = (div_id1 + 1);
        var origen = document.getElementById("span_imagen_" + cliente + "_" + div_id1).innerHTML;
        var destino = document.getElementById("span_imagen_" + cliente + "_" + div_id2).innerHTML;
        orden_cambia_imagen(url, clean, origen, destino, cliente, div_id1, div_id2);
    }
    function orden_cambia_imagen(url, clean, uno, dos, cliente, div_id1, div_id2) {
        // hace llamada y configuramos retorno en
        if (sendReq.readyState == 4 || sendReq.readyState == 0) {
            sendReq.open("POST", get_clean_url(url, 'ajax/ordena_imagen/' + uno + '/' + dos + '/' + cliente + '/' + div_id1 + '/' + div_id2,clean) , true);
            sendReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            sendReq.onreadystatechange = handle_orden_cambia_imagen;
            var param = '';
            sendReq.send(param);
        }
    }        
    // cambiamos posiciones de clientes en divs de la pagina
    function handle_orden_cambia_imagen() {
        if (sendReq.readyState == 4) {
            respuesta = sendReq.responseText;
            if(respuesta.indexOf(',') != -1) {
                temp = respuesta.split(',');
                cliente = temp[0];
                div_id1 = temp[1];
                div_id2 = temp[2];
            } else {
                return (true);
            }
    // cambio imagen
            var temp = document.getElementById("imagen_" + cliente + "_" + div_id1).src;
            document.getElementById("imagen_" + cliente + "_" + div_id1).src = document.getElementById("imagen_" + cliente + "_" + div_id2).src;
            document.getElementById("imagen_" + cliente + "_" + div_id2).src = temp;
    // cambio alt de imagen
            var temp = document.getElementById("imagen_" + cliente + "_" + div_id1).alt;
            document.getElementById("imagen_" + cliente + "_" + div_id1).alt = document.getElementById("imagen_" + cliente + "_" + div_id2).alt;
            document.getElementById("imagen_" + cliente + "_" + div_id2).alt = temp;
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    

// JQUERY s    
jQuery(document).ready(function(){
    jQuery(".expand").bind("click", function(e){
      var abierta = jQuery("#abierta").html();
      var id = e.target.id;
      if ((abierta != "") && (abierta != id)) {
          jQuery("#expand_" + abierta).hide('fast');
      }
      jQuery("#expand_" + id).slideToggle('fast');
      if ($("#imagen_grande_" + id).length) {
          jQuery(".imagen_grande").hide();
          jQuery("#imagen_grande_" + id).show();
      }
      jQuery("#abierta").html(id);
    });
    jQuery(".capa_oculta_cierra").bind("click", function(e){
      var abierta = jQuery("#abierta").html();
      if (abierta > 0) {
          jQuery("#" + abierta + "_info").hide('slow');
          jQuery("#c_" + abierta + "_info").hide('slow');
          jQuery("#g_" + abierta).show('slow');
          jQuery("#abierta").html('');
      }
    });
 });    
