

function muestraReloj()
{
// Compruebo si se puede ejecutar el script en el navegador del usuario
if (!document.layers && !document.all && !document.getElementById) return;
// Obtengo la hora actual y la divido en sus partes
var fechacompleta = new Date();
var horas = fechacompleta.getHours();
var minutos = fechacompleta.getMinutes();
var segundos = fechacompleta.getSeconds();
var mt = "AM";
// Pongo el formato 12 horas
if (horas > 12) {
mt = "PM";
horas = horas - 12;
}
if (horas == 0) horas = 12;
// Pongo minutos y segundos con dos dígitos
if (minutos <= 9) minutos = "0" + minutos;
if (segundos <= 9) segundos = "0" + segundos;
// En la variable 'cadenareloj' puedes cambiar los colores y el tipo de fuente
cadenareloj = "<font size='1' face='verdana' ><b>" + horas + ":" + minutos + ":" + segundos + " " + mt + "</b></font>";
// Escribo el reloj de una manera u otra, según el navegador del usuario
if (document.layers) {
document.layers.spanreloj.document.write(cadenareloj);
document.layers.spanreloj.document.close();
}
else if (document.all) spanreloj.innerHTML = cadenareloj;
else if (document.getElementById) document.getElementById("spanreloj").innerHTML = cadenareloj;
// Ejecuto la función con un intervalo de un segundo
setTimeout("muestraReloj()", 1000);
}

// Fin del script -->
var idioma;

document.cookie = "idioma=es-AR";
//if (leerCookie("idioma") == null) {
//    idioma = navigator.language;
//    document.cookie = "idioma=" + idioma;
//    if (idioma == "es-AR") {
//        url = window.location.href.split("en.").join("es.");
//    }
//    if (idioma == "en-US") {
//        url = window.location.href.split("es.").join("en.");
//    } 
//}
function Load_Language()
{
        var q=window.location.href.split('.')[0].split('/');
        var a;
        var idiom;
        for ( a = 0; a < q.length ; a++)
        {
            try
            {
                idiom = q[a];
                idiom.substring(idiom.Length - 2, 2);
               // alert(idiom);
                switch (idiom)
                {
                    case "es":
                        idioma = "es-AR";
                        break;
                    case "en":
                        idioma = "en-US";
                        break;
                    default:
                        idioma = navigator.language;
                        break;
                }
                
            }
            catch (ex) {
                alert(ex);
            }
        }
        //alert(idiom);
        //alert(idioma);
    var url = window.location.href;

    var cookie_year = current_date.getFullYear() + 1;
    var cookie_month = current_date.getMonth();
    var cookie_day = current_date.getDate();
    //set_cookie("idioma", idioma, cookie_year, cookie_month, cookie_day);
    document.cookie = "idioma=" + idioma;
    if (idioma == "es-AR") {
        url = window.location.href.split("en.").join("es.");
    }
    if (idioma == "en-US") {
        url = window.location.href.split("es.").join("en.");
    }
}
// ********************** FUNCIONES GENERALES ********************** 
//GUARDAR UNA COOKIE
function setCookie(name, value) {
    document.cookie = name + "=" + value + "; path=/";  //+ ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
// LEE UNA COOKIE ESPECIFICA
function leerCookie(nombre) {
    var i;
    var a = document.cookie.split(";");
    var n, v;
    var pos;
    for (i = 0; i < a.length; i++) {
        pos = a[i].indexOf("=");
        n = a[i].substring(0, pos);
        // alert(n + ' - ' + nombre );
        if (trim(n) == nombre) {
            return unescape(a[i].substring(1 + pos, a[i].length));
        }
    }
    return null;
}
// ********************** FIN FUNCIONES GENERALES **********************

// ********************** FUNCIONES ESPECCIFICAS DE GESTIARIUM ********************** 
// PARSEA EL TEXTAREA DE TAGS Y GENERA LOS TAGS SEGUN LA CLASE ASIGNADA
function renderTags(tags, classTags) {

    var ts = tags.split(",");
    var texto = "";
    for (var iParam = 0; iParam < ts.length; iParam++) {
        //texto = texto + "<tr><td><a  style='font-weight: normal;' class='" + classTags + "'>" + ts[iParam] + "</a></td></tr>";
        texto = texto + "<a  style='font-weight: normal;' class='" + classTags + "'>" + trim(ts[iParam]) + "</a>";
        try {
            if (ts[0] == "")
                texto = "";
            if (ts[0] == ",")
                texto = "";
            if (ts[0] == ", ")
                texto = "";
            if (ts[0] == " ,")
                texto = "";
            if (ts[0] == " ")
                texto = "";
        }
        catch (ex)
        { }
    }

    //return "<table>"+texto+"</table>";
    return texto;
}


// GUARDA LA COOKIE DEL GESTO A COMPARAR O UNIFICAR 
// SE USA EN GESTOU.ASPX
function setItemToCompare(check) {
    if (check.checked) {
        setCookie(check.value, "yes");
    }
    else {
        setCookie(check.value, "no");
    }
}
// TRAE UNA LISTA DE LOS GESTOS SELECCIONADOS EN BASE A LAS COOKIES
function getItemsSel() {
    var ai;
    var result = "";
    var temp = "";
    var nombre = "";
    var i;
    var a = document.cookie.split(";");
    var n, v, q;
    var pos;
    for (i = 0; i < a.length; i++) {
        ai = a[i].trim();
        pos = ai.indexOf("=");
        nombre = ai.substring(1, pos);
        n = ai.substring(0, 1);
        if (n == "V") {
            q = unescape(ai.substring(1 + pos, ai.length));
            if (q == "yes") {
                temp = result;
                result = temp + nombre + ";";
            }
        }
    }
    result = result.substring(0, result.length - 1);
    return result;
}
//GUARDAR TOKEN
function GuardaToken(token) {
    var d = new Date();
    var min = d.getMinutes() + 15;
    var sec = d.getSeconds();
    var millisec = d.getMilliseconds();
    d.setMinutes(min, sec, millisec);
    //document.cookie = "userToken" + "=" + token + "; path=/; expires=" + d.toTimeString();
}
// DESLOGUEA AL USUARIO
function LogOutNow(comercio) {
    var d = new Date();
    //BORRO LAS COOKIES LOCALES
    setCookie("userToken", "");
    setCookie("userData", "");
    //BORRO LAS COOKIES EN CYBER
    //document.getElementById('ctl00_qframe').src = "http://www.cyberferia.com/shared/desloguear.aspx?id_com="+comercio+"&reload=true";
    // SI QUIERO QUE REFRESQUE EL SITIO CUANDO VUELVE DE CYBER DENTRO DE VERIFICA EN EL IFRAME CHICO CON url += "?reload=true"; 
    // TENGO QUE MANDAR A RECARGAR EL PADRE SI VIENE ESO EN LA QUERY *************** PENDIENTE
    //if (window.location.toString().indexOf("detalle.aspx")>0)
    //document.location.reload();
    //window.location = window.location.href;
    abre("http://www.cyberferia.com/shared/desloguear.aspx?id_com=" + comercio + "&reload=true");
    window.location = window.location.href;
}
// APAGA EL DIV DEL IFRAME DE LOGUEO
function ApagarLogueo2(token) {
    document.getElementById("loguear").style.display = "none";
    document.getElementById("Esperar").style.display = "block";
    //window.location = window.location;
    //alert("Vamos a actualizar la página por el estado de logueo:");
    if (token != "CANCEL") {
        GuardaToken(token);
        RemoveFilter("Loguear=now");
        //        alert(window.location);
        //            window.location = window.location;
    }
    else {
        window.location = "/";
     }
}
        
// CHEQUEAMOS EL ESTADO DE LOGUEO
function userlogged() {
    if (!leerCookie("userToken") == "") {
        return true;
    }
    else {
        return false;
    }
}
// PRENDEMOS EL DIV DE REPORTAR ABUSO
function showAbuseReport(idObject) {
    document.getElementById("AbuseReport").style.display = "none";
    return false;
}
function SetIframeSize(w, h) {
    document.getElementById("FrameR").height = h;
    document.getElementById("FrameR").width = w;
    return true;
}
function PrenderLogueo() {
    if (userlogged != true) {
        document.getElementById("loguear").style.display = "block";

    }
}

function switchDivs(div1, div2) {
    document.getElementById(div1).style.display = 'none';
    document.getElementById(div2).style.display = 'block';
}
function copylbl_Txt(div1, div2) {
    document.getElementById(div2).value = document.getElementById(div1).innerHTML;
}
function copyTxt_lbl(div1, div2) {
    document.getElementById(div2).innerHTML = document.getElementById(div1).value;
}
function RemoveFilter(flt) {
    var query = "";
    var url = "";
    query = eliminarParam(flt);
    if (query.length < 3)
        url = window.location.href.split("?")[0];
    else
        url = window.location.href.split("?")[0] + "?" + eliminarParam(flt);
    window.location = url;

}
function Buscar() {
    var newUrl = "/gestos.aspx/busqueda/" + document.getElementById("searcher").value + "/";
    window.location = newUrl;
}

function addTag(tag) {
    var tags = document.getElementById("ctl00_ContentPlaceHolder1_txtTags");
    if (tags.value == "") {
        tags.value = tag;
    }
    else {
        tags.value += ", " + tag;
    }
    document.getElementById('ListaTags').innerHTML = renderTags(document.getElementById('ctl00_ContentPlaceHolder1_txtTags').value, 'tag3');
}
// ********************** FUNCIONES ESPECCIFICAS MOVIMIENTO DE FOTOS **********************
function Atras() {
    var fila1 = document.getElementsByName("Fila1");
    var fila2 = document.getElementsByName("Fila2");
    var items1 = fila1.length;
    var items2 = fila2.length;
    for (var i = 0; i < items1; i++) {
        if (fila1.item(i).style.display == "block") {
            fila1.item(i - 1).style.display = "block";
            fila2.item(i - 1).style.display = "block";
            break;
        }
    }
    for (var i = items1; i > 0; i--) {
        if (fila1.item(i - 1).style.display == "block") {
            fila1.item(i - 1).style.display = "none";
            fila2.item(i - 1).style.display = "none";
            break;
        }
    }
}
function Avance() {
    var fila1 = document.getElementsByName("Fila1");
    var fila2 = document.getElementsByName("Fila2");
    var items1 = fila1.length;
    var items2 = fila2.length;
    for (var i = 0; i < items1; i++) {
        if (fila1.item(i).style.display == "block") {
            if (i < items1 - 4) {
                fila1.item(i).style.display = "none";
                fila2.item(i).style.display = "none";
            }
            break;
        }
    }
    for (var i = items1; i > 0; i--) {
        if (fila1.item(i - 1).style.display == "block") {
            if (i > 3) {
                fila1.item(i).style.display = "block";
                fila2.item(i).style.display = "block";
            }
            break;
        }
    }

    //document.getElementsByName("Icono0").item(0).style.display = "block"
}

// ********************** FIN FUNCIONES ESPECCIFICAS MOVIMIENTO DE FOTOS **********************

// ********************** FIN FUNCIONES ESPECCIFICAS DE GESTIARIUM ********************** 

/*Función para agregar la página a los favoritos del navegador*/
function AddParam(strParamName) {
    //var strParamName = "Loguear=now";
    var cadena = "";

    var strHref = window.location.href;
    var strQueryString = "";
    try {
        strQueryString = strHref.split('?')[1];
    }
    catch (err) {

    }
    if (strQueryString != null) {
        var aQueryString = "";
        aQueryString = strQueryString.split('&');

        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            var aParam = aQueryString[iParam];
            if (aParam != strParamName) {
                cadena = cadena + aParam + '&';
            }
        }
    }
    cadena = cadena + strParamName + "&";
    return strHref.split("?")[0] + "?" + cadena.substr(0, cadena.length - 1);
}
function Reload(strHref ) {
    var url = "";
    try {
        url = strHref.split("?")[0];
    }
    catch (err) {
        url = strHref;
    }
    return url;
}
function AddParamParent(strParamName) {
    //var strParamName = "Loguear=now";
    var cadena = "";
    var parentframe = parent.document.getElementById("ctl00_qframe");

    var strHref = parentframe.ownerDocument.location.href;
    var strQueryString = "";
    try {
        strQueryString = strHref.split('?')[1];
    }
    catch (err) {

    }
    if (strQueryString != null) {
        var aQueryString = "";
        aQueryString = strQueryString.split('&');

        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            var aParam = aQueryString[iParam];
            if (aParam != strParamName) {
                cadena = cadena + aParam + '&';
            }
        }
    }
    cadena = cadena + strParamName + "&";
    return strHref.split("?")[0] + "?" + cadena.substr(0, cadena.length - 1);
}
function mostrarSubirDefiniciones() {
    if (userlogged()) {
        document.getElementById('addDescr').style.display = 'block';

    }
    else {
        var url = AddParam("Loguear=now");
        window.location = url;
        return true;
    }
}
function mostrarShareaFriend() {
    if (userlogged()) {
        document.getElementById('send').style.display = 'block';
    }
    else {
        var url = AddParam("Loguear=now");
        window.location = url;
        return false;
    }
}

function mostrarAddTags() {
    if (userlogged()) {
        document.getElementById('TagsDiv').style.display = 'block';
    }
    else {
        var url = AddParam("Loguear=now");
        window.location = url;
        return true;
    }
}
function testReload() {
    var url = "";
    if (document.location.toString().indexOf("reload=true") > 0) {
        var parentframe = parent.document.getElementById("ctl00_qframe");
        //parentframe.src = "/verifica.aspx";  //document.location.href.split("?")[0] + "?" + eliminarParam("reload=true");
        url = AddParamParent("reload=false");
        url = Reload(parentframe.ownerDocument.location.href);
        parentframe.ownerDocument.location = url; //.reload();
    }
}


function mostrarSubirFotosYVideos() {
    // alert('entro');
    if (userlogged()) {
        document.getElementById('addVideo').style.display = 'block';
        document.getElementById('addFoto').style.display = 'block';
        document.getElementById('uppFoto').style.display = 'block';
        document.getElementById('ctl00_ContentPlaceHolder1_txtFotoAdd').value = '';
        //     return false;
    }
    else {
        var url = AddParam("Loguear=now");
        window.location = url;
        return true;
    }
}



function ltrim(s) {
    return s.replace(/^\s+/, "");
}

function rtrim(s) {
    return s.replace(/\s+$/, "");
}

function trim(s) {
    return rtrim(ltrim(s));
}



function agregarAFavoritos(url, titulo) {
    if (window.sidebar) {
        window.sidebar.addPanel(titulo, url, "");
    } else if (document.all) {
        window.external.AddFavorite(url, titulo);
    } else if (window.opera && window.print) {
        return true;
    }
}
function abre(pagina) {
    window.open(pagina, 'Formatos', 'resizable=no,menubar=no,location=no,toolbar=no,status=no,scrollbars=no,directories=no,width=1,height=1')
}
function mostrarDiv(id) {
    if (document.getElementById(id).style.display == "none") {
        document.getElementById(id).style.display = "block";
    } else {
        document.getElementById(id).style.display = "none";
    }
}
/* Obtener el valor de un parámetro determinado */

function getURLParam(strParamName) {
    var strReturn = "";
    var strHref = window.location.href;
    if (strHref.indexOf("?") > -1) {
        var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
        var aQueryString = strQueryString.split("&");
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1) {
                var aParam = aQueryString[iParam].split("=");
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}

/* Retorna todas las queries con su valor salvo el parámtetro enviado como argumento */
function eliminarParam(strParamName)//Mandar key=value para eliminar
{
    var cadena = "";
    var strHref = window.location.href;

    //var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var strQueryString = "";
    try {
        strQueryString = strHref.split('?')[1];
    }
    catch (err) { }

    var aQueryString = "";
    try {
        aQueryString = strQueryString.split("&");
    }
    catch (err2) { }

    for (var iParam = 0; iParam < aQueryString.length; iParam++) {
        var aParam = aQueryString[iParam];
        if (aParam != strParamName)
            cadena = cadena + aParam + "&";
    }

    return cadena.substr(0, cadena.length - 1);
}

/* elimina un parametro de un string enviado */
function eliminarP(strval, strParamName) {
    var cadena = "";
    var strHref = strval;

    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");

    for (var iParam = 0; iParam < aQueryString.length; iParam++) {
        var aParam = aQueryString[iParam].split("=");
        if (aParam[0] != strParamName)
            cadena = cadena + aQueryString[iParam] + "&";
    }

    return cadena.substr(0, cadena.length - 1);
}


/* redirige a la página actual agregando el query que crea a partir del Drop Down de orden */

function redirectDDPlus(obj) {
    var idxval = obj.options[obj.selectedIndex].value;
    var idx = idxval.split("=");
    var strHref = "";
    var strQueryString = "";
    if (idx[1] == "none") {
        strHref = window.location.href;
        strQueryString = strHref.split("?");
        strHref = strQueryString[0] + eliminarParam("orden");
    }
    else {
        strHref = window.location.href;
        strQueryString = strHref.split("?");
        strHref = strQueryString[0] + eliminarParam("orden") + "&" + obj.options[obj.selectedIndex].value;
    }

    window.location = eliminarP(strHref, "p");  //devuelve la url sin el parametro p que representa la pagina
}

function replace(texto, s1, s2) {
    return texto.split(s1).join(s2);
}




/* Redirige a la página actual excluyendo el parámetro del argumento */
function excluirParam(P) {
    var strHref = window.location.href;
    var strQueryString = strHref.split("?");
    strHref = strQueryString[0] + eliminarParam(P);

    window.location = eliminarP(strHref, "p");  //devuelve la url sin el parametro p que representa la pagina
}

/* Redirige a la misma página agregando el argumento pasado como parámetro */

function redirectPlus(strP) {
    var campos = strP.split("=");
    var strHref = window.location.href;
    var strQueryString = strHref.split("?");
    strHref = strQueryString[0] + eliminarParam(campos[0]) + "&" + strP;
    window.location = eliminarP(strHref, "p");  //devuelve la url sin el parametro p que representa la pagina
}

/* Realiza las acciones con los filtros dependiendo de su presencia o ausencia  */

function filtrar(strP) {
    // URL a la que voy a redirigir
    var strHref = window.location.href;

    var strQueryString = strHref.split("?");

    // Obtengo el array con el query enviado y su valor
    var campos = strP.split("=");

    // Me fijo si el query ya esta en la URL
    if (getURLParam(campos[0]) != "") {
        // Si esta y es un criterio distinto al criterio que se esta enviando, lo cambio por el nuevo
        if (getURLParam(campos[0]) != campos[1]) {

            strHref = strQueryString[0] + eliminarParam(campos[0]) + "&" + strP;
        }
        else
        // Si esta y es el mismo lo saco (elimino el filtro)
        {
            strHref = strQueryString[0] + eliminarParam(campos[0]);
        }
    }
    else
    // Si no esta en la URL, lo agrego
    {
        strHref = strQueryString[0] + eliminarParam(campos[0]) + "&" + strP;
    }

    // Redirijo a la URL armada
    //window.location = strHref;
    window.location = eliminarP(strHref, "p");  //devuelve la url sin el parametro p que representa la pagina
}


/* Muestra o esconde los divs de filtrado del panel de herramientas de filtrado */

function showhideDivPanel(id) {
    //setea lenguaje en dos letras
    var lengdos;
    var cook;

    cook = get_cookie("idioma")
    if (cook == "en-US") lengdos = "ES";
    else if (cook == "es-AR") lengdos = "ES";
    else lengdos = "ES";



    if (document.getElementById(id).style.display == "none") {
        document.getElementById(id).style.display = "block";
        if (id == "desplegaredit")
            document.getElementById("ctl00_ContentPlaceHolder1_img" + id).src = "/images/" + lengdos + "/filtro-editorial-.gif";
        if (id == "desplegartema")
            document.getElementById("ctl00_ContentPlaceHolder1_img" + id).src = "/images/" + lengdos + "/filtro-tema-.gif";
    } else {
        if (document.getElementById(id).style.display == "block") {
            document.getElementById(id).style.display = "none";
            if (id == "desplegaredit")
                document.getElementById("ctl00_ContentPlaceHolder1_img" + id).src = "/images/" + lengdos + "/filtro-editorial.gif";
            if (id == "desplegartema")
                document.getElementById("ctl00_ContentPlaceHolder1_img" + id).src = "/images/" + lengdos + "/filtro-tema.gif";
        }
    }
}


/*AJAX*/

var xmlhttpreq
function crearXMLHttpRequest() {
    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 comprarDesdeFicha(cod_articulo) {
    //alert('Acabas de comprar el articulo numero ' + id_articulo);
    xmlhttpreq = crearXMLHttpRequest();
    xmlhttpreq.open("POST", "/ajax_functions.aspx", true);
    xmlhttpreq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttpreq.send("cod_art=" + cod_articulo);
    xmlhttpreq.onreadystatechange = procesarEventos;
    xmlhttpreq.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    conexion1.send(null);
}

function procesarEventos() {
    if (xmlhttpreq.readyState == 4) //Listo
    {
        if (xmlhttpreq.status == 200) {
            var respuesta = xmlhttpreq.responseXML;
            document.getElementById('imagen_libro_compra').src = respuesta.getElementsByTagName("url_imagen_libro")[0].childNodes[0].data;
            document.getElementById('titulo_libro_compra').innerHTML = respuesta.getElementsByTagName("titulo_libro")[0].childNodes[0].data;
            document.getElementById('carrDPrecio').innerHTML = 'Precio: $  ' + respuesta.getElementsByTagName("precio_libro")[0].childNodes[0].data;
            compraDesdeFicha();
            setTimeout("compraDesdeFicha()", 5000);
        }
    }

}


function compraDesdeFicha(imagen, titulo, precio) {
    window.scrollTo(0, 0);
    document.getElementById('imagen_libro_compra').src = imagen; //respuesta.getElementsByTagName("url_imagen_libro")[0].childNodes[0].data;
    document.getElementById('titulo_libro_compra').innerHTML = titulo; //respuesta.getElementsByTagName("titulo_libro")[0].childNodes[0].data;
    document.getElementById('carrDPrecio2').innerHTML = ' $  ' + precio; //respuesta.getElementsByTagName("precio_libro")[0].childNodes[0].data;
    Effect.toggle('carritoDown', 'slide');
    document.getElementById("lienzo").className = 'lienzoCarritoDown';
    setTimeout("ret()", 5000);
}


function comprarLibro(codigo) {
    var mi_select;
    mi_select = document.getElementById("ctl00_ContentPlaceHolder1_select_cant");
    var cantidad;
    cantidad = mi_select.options[mi_select.selectedIndex].value;
    xmlhttpreq = crearXMLHttpRequest();

    xmlhttpreq.open("GET", "/ajax_functions.aspx?a=comprar&cod=" + codigo + "&cant=" + cantidad, true);
    xmlhttpreq.onreadystatechange = compra_ajax;
    xmlhttpreq.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttpreq.send(null);
}

var lang;
function inicializar_pagina() //funcion que se ejecuta en todas las paginas en el onload
{
    //si viene referido por algun asociado, guarda en cookie al asociado
    guardarAsociado();

    //actualiza el carrito
    xmlhttpreq = crearXMLHttpRequest();
    xmlhttpreq.open("GET", "/ajax_functions.aspx?a=actualizar", true);
    xmlhttpreq.onreadystatechange = compra_ajax;
    xmlhttpreq.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    xmlhttpreq.send(null);


    //muestra footsteps
    mostrar_footsteps("1");
    mostrar_footsteps("2");
    mostrar_footsteps("3");
    mostrar_footsteps("4");
    mostrar_footsteps("5");

    //guarda en footsteps
    do_footsteps()

    //toma el idioma actual y actualiza las imagenes a ese idioma
    if (get_cookie("idioma") != null) {
        if (get_cookie("idioma") == "en-US")
            lang = "ES";
        else
            lang = "ES";
    }
    else lang = "ES";
    changue_images_languajes(lang);
}



function changue_images_languajes(lan) {
    document.getElementById("banner-costos").src = "/images/" + lan + "/banner-envio.jpg";
    document.getElementById("bIzqTemas").className = "bIzqTemas_" + lan;
    document.getElementById("b-search").src = "/images/" + lan + "/b-search.jpg";
}

function preload_images_default() {
    //en esta parte hace el preload de las imagenes de la vidriera
    img_featured_a = new Image(); img_featured_a.src = "/images/" + lang + "/b-img_menu_1.gif";
    img_featured_d = new Image(); img_featured_d.src = "/images/" + lang + "/t-img_menu_1.gif";
    img_onsale_a = new Image(); img_onsale_a.src = "/images/" + lang + "/b-img_menu_2.gif";
    img_onsale_d = new Image(); img_onsale_d.src = "/images/" + lang + "/t-img_menu_2.gif";
    img_bestsellers_a = new Image(); img_bestsellers_a.src = "/images/" + lang + "/b-img_menu_3.gif";
    img_bestsellers_d = new Image(); img_bestsellers_d.src = "/images/" + lang + "/t-img_menu_3.gif";
}


function compra_ajax() {

    if (xmlhttpreq.readyState == 4) {
        if (xmlhttpreq.status == 200) {
            var respuesta;
            respuesta = xmlhttpreq.responseXML;
            var tareacompletada = respuesta.getElementsByTagName("tarea")[0].getAttribute("completada");
            if (tareacompletada == "true") {
                var display_carrito = respuesta.getElementsByTagName("carrito")[0].getAttribute("cantidad") + " items | $  ";
                display_carrito += respuesta.getElementsByTagName("carrito")[0].getAttribute("total");
                document.getElementById("ctl00_label_carrito").innerHTML = display_carrito;
            }
            else {
                alert("Surgió un error durante el proceso de actualizacion, será reparado a la brevedad.", "Error");
            }
        }
    }

}

function ret() {
    document.getElementById("lienzo").className = 'lienzo';
    Effect.toggle('carritoDown', 'slide');
}

/* COOKIES */



function get_cookie(cookie_name) {
    var results = document.cookie.match(cookie_name + '=(.*?)(;|$)');

    if (results)
        return (unescape(results[1]));
    else
        return null;
}

function delete_cookie(cookie_name) {
    var cookie_date = new Date();  // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function set_cookie(name, value, exp_y, exp_m, exp_d, domain) {
    var cookie_string = name + "=" + escape(value);

    if (exp_y) {
        var expires = new Date(exp_y, exp_m, exp_d);
        cookie_string += "; expires=" + expires.toGMTString();
    }



    if (domain)
        cookie_string += "; domain=" + escape(domain);
    cookie_string += "; path=/"

    document.cookie = cookie_string;
}

function cambiar_idioma(idioma) {
    var current_date = new Date;
    //var idioma;
//    if (!get_cookie("idioma")) //si no existe cookie designa por defecto ingles
//    {
var url=window.location.href;

        var cookie_year = current_date.getFullYear() + 1;
        var cookie_month = current_date.getMonth();
        var cookie_day = current_date.getDate();
        set_cookie("idioma", idioma , cookie_year, cookie_month, cookie_day);

if (idioma=="es-AR") {
    url = window.location.href.split("en.").join("es.");
}
if (idioma == "en-US") {
    url = window.location.href.split("es.").join("en.");
}
//idioma = "en-US";
//    }
//    else //si existe la cookie la cambia
//    {
//        idioma = get_cookie("idioma");
//        if (idioma == "es-AR")
//            idioma = "en-US";
//        else
//            idioma = "es-AR";

//        //delete_cookie("idioma");
//        set_cookie("idioma", idioma, current_date.getFullYear() + 1, current_date.getMonth(), current_date.getDate());


//    }
//    if (idioma == "en-US") window.location = window.location.href; //.split("/ES/").join("/ES/");
//    if (idioma == "es-AR") window.location = window.location.href; //.split("/EN/").join("/ES/");
        window.location = url;
        
        
}

/* FIN COOKIES */


/* javascript masterpage */

// los metodos para manejar cookies estan repetidos,
// con mas tiempo se deberian unificar...

// estos lo usa para guardar el vienede de los asociados
// los de arriba los usa para el cambio de idioma
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0)
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function set_Cookie(name, value, expires, options) {
    if (options === undefined) { options = {}; }
    if (expires) {
        var expires_date = new Date();
        expires_date.setDate(expires_date.getDate() + expires)
    }
    document.cookie = name + '=' + escape(value) +
((expires) ? ';expires=' + expires_date.toGMTString() : '') +
((options.path) ? ';path=' + options.path : '') +
((options.domain) ? ';domain=' + options.domain : '') +
((options.secure) ? ';secure' : '');
}

function GuardarCookie(nombre, valor, caducidad) {
    if (!caducidad)
        caducidad = Caduca(0)

    //crea la cookie: incluye el nombre, la caducidad y la ruta donde esta guardada
    //cada valor esta separado por ; y un espacio
    document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad + "; path=/"
}

function Caduca(dias) {
    var hoy = new Date()					//obtiene la fecha actual
    var msEnXDias = eval(dias) * 24 * 60 * 60 * 1000	//pasa los dias a mseg.

    hoy.setTime(hoy.getTime() + msEnXDias)			//fecha de caducidad: actual + caducidad
    return (hoy.toGMTString())
}

function BorrarCookie(nombre) {
    //para borrar la cookie, se le pone una fecha del pasado mediante Caduca(-1)
    document.cookie = nombre + "=; expires=" + Caduca(-1) + "; path=/"
}

/**
* Verifica si se recibe por qs el codigo de asociado
* y lo guarda en una cookie
*/

var vienede;

function parseParams(query) {
    var qsParm = new Array();
    var parms = query.split('&');
    for (var i = 0; i < parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0, pos);
            var val = parms[i].substring(pos + 1);
            qsParm[key] = val;
        }
    }
    return qsParm;
}

function guardarAsociado() {
    var query = window.location.search.substring(1);
    var qs = parseParams(query);
    if (qs['vienede']) {
        vienede = qs['vienede'];
        if (getCookie("vienede") != vienede) {
            var current_date = new Date();
            //setCookie('vienede', qs['vienede'], 366);
            set_cookie('vienede', qs['vienede'], current_date.getFullYear() + 1, current_date.getMonth(), current_date.getDate());
            SendQueryAsoc();
        }
    }
}

function SendQueryAsoc() {
    var xmlhttpreq = crearXMLHttpRequest();
    var url = "/actualizaAsoc.aspx?vienede=" + vienede;
    if (xmlhttpreq != null) {
        xmlhttpreq.open("GET", url, true);
        xmlhttpreq.send(null);
    }
}

//-----------------------------------------------------

function menu_click(num1, num2, num3, idioma) {
    document.getElementById("vid_" + num1).style.display = "block";
    document.getElementById("vid_" + num2).style.display = "none";
    document.getElementById("vid_" + num3).style.display = "none";

    document.getElementById("div_menu_" + num1).className = 'hVidTit011';
    document.getElementById("div_menu_" + num2).className = 'hVidTit021';
    document.getElementById("div_menu_" + num3).className = 'hVidTit021';


    document.getElementById("img_menu_" + num1).src = "/images/" + idioma + "/b-img_menu_" + num1 + ".gif";
    document.getElementById("img_menu_" + num2).src = "/images/" + idioma + "/t-img_menu_" + num2 + ".gif";
    document.getElementById("img_menu_" + num3).src = "/images/" + idioma + "/t-img_menu_" + num3 + ".gif";


}
/* fin javascript masterpage */

/* footsteps */
var hoy = new Date;
function do_footsteps() {

    // si no existen las cookies las crea
    /*
    if (get_cookie("footsteps_1") == null) set_cookie("footsteps_1","",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate());
    if (get_cookie("footsteps_2") == null) set_cookie("footsteps_2","",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate());
    if (get_cookie("footsteps_3") == null) set_cookie("footsteps_3","",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    if (get_cookie("footsteps_4") == null) set_cookie("footsteps_4","",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    if (get_cookie("footsteps_5") == null) set_cookie("footsteps_5","",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    */
    if (get_cookie("footsteps_1") == null) set_cookie("footsteps_1", "null", hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate());
    if (get_cookie("footsteps_2") == null) set_cookie("footsteps_2", "null", hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate());
    if (get_cookie("footsteps_3") == null) set_cookie("footsteps_3", "null", hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate());
    if (get_cookie("footsteps_4") == null) set_cookie("footsteps_4", "null", hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate());
    if (get_cookie("footsteps_5") == null) set_cookie("footsteps_5", "null", hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate());

    // despues de validar que sea necesario crearlas
    var titulo;
    var vect;

    //diferentes casos de url
    if (procesaurl()) {
        vec = document.title.split("-");
        if (window.location.pathname == "/" || window.location.pathname == "/default.aspx") //si es la home
            titulo = "HOME LSF";
        else {
            if (window.location.pathname == "../resultados.aspx") {
                titulo = "Results for \"" + vec[0] + "\"";
            }
            else {
                titulo = vec[0];
            }
        }
        guardar_en_footsteps(window.location.href + "~" + titulo);
    }
}
/*
function procesaurl()
{
var urlactual;
var aux2;
var aux1;
var cookieanterior = get_cookie("footsteps_1").split("~");
    
if (window.location.href == cookieanterior[0])
return false;
else
{
if (window.location.pathname != "../resultados.aspx")
return true;
else
{
        
var nuevakey = get_parameter(window.location.href,"key");
var viejakey = get_parameter(cookieanterior[0],"key");
var nuevocrit = get_parameter(window.location.href,"criterio");
var viejocrit = get_parameter(cookieanterior[0],"criterio");
if (nuevakey == viejakey && nuevocrit == viejocrit)
return false;
else
return true;
}
}
return true;
}
*/
function get_parameter(url, par) {
    var aux = url.split("?");
    var aux2 = aux[1].split("&");
    var aux3;
    for (j = 0; j < j.length; j++) {
        aux3 = aux2[j].split("=");
        if (aux3[0] == par)
            return aux3[1];
    }
    return "";
}


function procesaurl() {
    var urlactual;
    var aux2;
    var aux1;
    var cookieanterior2 = get_cookie("footsteps_1");

    if (cookieanterior2 == null || cookieanterior2 == "null") return true;
    var cookieanterior = cookieanterior2.split("~");

    if (window.location.href == cookieanterior[0])
        return false;
    else {
        if (window.location.pathname != "../resultados.aspx" && window.location.pathname != "/temas.aspx")
            return true;
        else {
            urlactual = window.location.href.split("?");
            if (urlactual[1] != null) {
                aux1 = urlactual[1].split("&");
                for (i = 0; i < aux1.length; i++) {
                    aux2 = aux1[i].split("=");
                    if (aux2[0] == "p") {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}


function guardar_en_footsteps(datos) {
    var aux;

    //desplaza
    aux = get_cookie("footsteps_4");
    set_cookie("footsteps_5", aux, hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate())
    aux = get_cookie("footsteps_3");
    set_cookie("footsteps_4", aux, hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate())
    aux = get_cookie("footsteps_2");
    set_cookie("footsteps_3", aux, hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate())
    aux = get_cookie("footsteps_1");
    set_cookie("footsteps_2", aux, hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate())

    //guarda
    set_cookie("footsteps_1", datos, hoy.getFullYear() + 1, hoy.getMonth(), hoy.getDate())
}

function mostrar_footsteps(num) {
    /*
    if (get_cookie("footsteps_1") == null) set_cookie("footsteps_1","null",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate());
    if (get_cookie("footsteps_2") == null) set_cookie("footsteps_2","null",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate());
    if (get_cookie("footsteps_3") == null) set_cookie("footsteps_3","null",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    if (get_cookie("footsteps_4") == null) set_cookie("footsteps_4","null",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    if (get_cookie("footsteps_5") == null) set_cookie("footsteps_5","null",hoy.getFullYear() + 1,hoy.getMonth(),hoy.getDate()); 
    */
    var aux;
    var vector;
    aux = get_cookie("footsteps_" + num);
    if (aux != null && aux != "" && aux != "undefined" && aux != "null") {
        vector = aux.split("~");
        document.getElementById("a_footsteps_" + num).href = vector[0];
        document.getElementById("a_footsteps_" + num).innerHTML = vector[1];
        document.getElementById("div_footsteps_" + num).style.display = "block";
        document.getElementById("ultVisHuellas").style.display = "none";
    }

    /* 
    document.getElementById("a_footsteps_1").href="http://www.google.com";
    document.getElementById("a_footsteps_1").innerHTML = "GOOGLE";
   
    document.getElementById("a_footsteps_2").href="http://www.yahoo.com.ar";
    document.getElementById("a_footsteps_2").innerHTML = "YAHOO";
   
    document.getElementById("a_footsteps_3").href="http://www.live.com.ar";
    document.getElementById("a_footsteps_3").innerHTML = "LIVE SEARCH";
    */
}
/* fin footsteps */



