﻿function MuestraCargandoContenidos() {
    $('#mascaraLightBoxCargandoContenidos').fadeIn(800, "linear", function () {
        $('#capaLightBoxCargandoContenidos').fadeIn(800);
    });
}

function RedirigeCargando(url) {

    ididiomaDeLaPagina = getCookie('Idioma');

    if (ididiomaDeLaPagina != NaN && ididiomaDeLaPagina != null) {
        ididiomaDeLaPagina = ididiomaDeLaPagina.substring(7, 9);
    }

    if (ididiomaDeLaPagina == 1) //ingles
    {
        //$('#textoCargandoContenidos').html('Loading contents');
    }    

    MuestraCargandoContenidos();
    window.location.href = url;
}

function CargaProvincias(listaProvinciasInfo) {
    var nombrePaisMarcado = getCookie('idPaisM');
    $('#LabelPais').text(nombrePaisMarcado);
    alert(nombrePaisMarcado);
}

function AsignaBandasCorrectasSegunPagina() {
    //Valores por defecto
    $('#bandaSuperior').attr("src", "Images/bandaSuperiorGranate_1280x245.png");
    $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorGranate_1280x245.png')");
    //$('#bandaInferior').css("background-image", "url('Images/bandaInferiorGranate_1280x245.png')");

    if ((window.location.toString().indexOf("Colecciones.aspx") > 0) || (window.location.toString().indexOf("ColeccionesPorInstante.aspx") > 0) || (window.location.toString().indexOf("ProductosPorInspiracion.aspx") > 0) || (window.location.toString().indexOf("FichaProducto.aspx") > 0)) {
        $('#bandaSuperior').attr("src", "Images/bandaSuperiorGris_1280x245.png");
        $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorGris_1280x245.png')");
        //$('#bandaInferior').css("background-image", "url('Images/bandaInferiorGris_1280x245.png')");
    }
    else if (window.location.toString().indexOf("PuntosDeVenta.aspx") > 0) {
        $('#bandaSuperior').attr("src", "Images/bandaSuperiorDorada_1280x245.png");
        $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorDorada_1280x245.png')");
        //$('#bandaInferior').css("background-image", "url('Images/bandaInferiorDorada_1280x245.png')");
    }
    else if ((window.location.toString().indexOf("ServicioAlCliente.aspx") > 0) || (window.location.toString().indexOf("SAC_PostVenta.aspx") > 0) || (window.location.toString().indexOf("SAC_GarantiaMajorica.aspx") > 0) || (window.location.toString().indexOf("SAC_Cuidados.aspx") > 0) || (window.location.toString().indexOf("SAC_GarantiaMajorica.aspx") > 0) || (window.location.toString().indexOf("Legal.aspx") > 0)) {
        $('#bandaSuperior').attr("src", "Images/bandaSuperiorPlateada_1280x245.png");
        $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorPlateada_1280x245.png')");
        //$('#bandaInferior').css("background-image", "url('Images/bandaInferiorPlateada_1280x245.png')");
    }
    else if ((window.location.toString().indexOf("TiposDePerlas.aspx") > 0) || (window.location.toString().indexOf("MiCuenta.aspx") > 0)) {
        $('#bandaSuperior').attr("src", "Images/bandaSuperiorGranate_1280x245.jpg");
        $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorGranate_1280x245.jpg')");
        //$('#bandaInferior').css("background-image", "url('Images/bandaInferiorGranate_1280x245.jpg')");
    }
    else if ((window.location.toString().indexOf("Novedades.aspx") > 0) || (window.location.toString().indexOf("ColeccionCapricho.aspx") > 0) || (window.location.toString().indexOf("NovedadesNovedades.aspx") > 0)) {
        $('#bandaSuperior').attr("src", "Images/bandaSuperiorNovedades_1280x245.jpg");
        $('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorNovedades_1280x245.jpg')");
    }

}


function DespliegaSubOpcionesDeSeccion(idSeccion) {
    var idSub = "#subrayado" + idSeccion;

    $(".subOpcionesMenuPrincipal").css("top", "85px");

    $(".opcionesPrincipalesDelMenu").css("color", "White");
    $('#'+idSeccion).css("color", "#a1989a");

    $(idSub).css("width", "1px");
    $(idSub).css("border-top-style", "solid");
    $(idSub).css("border-top-width", "1pt");
    $(idSub).css("border-top-color", "White");

    $(idSub).show();

    var anchoSubrayado = "60px";

    switch (idSeccion) {
        case 'Universo':
            anchoSubrayado = "60px";
            break
        case 'Colecciones':
            anchoSubrayado = "67px"; //82px
            break
        case 'Novedades':
            anchoSubrayado = "75px";
            break
        case 'EBoutique':
            anchoSubrayado = "70px";
            break
        case 'PuntosDeVenta':
            anchoSubrayado = "109px";
            break
        case 'ServicioAlCliente':
            anchoSubrayado = "115px";
            break
        case 'Prensa':
            anchoSubrayado = "53px";
            break
        case 'Contacto':
            anchoSubrayado = "68px";
            break
    }
    
    //Animación subopciones

    var idTablaSubOpciones = "#tablaSubOpciones" + idSeccion;

    //$(idTablaSubOpciones).animate({ top: "0px" }, 900);
    //Nuevo

    $("#tablaSubOpcionesUniverso").stop();
    $("#tablaSubOpcionesUniverso").animate({ opacity: 1 }, 50);
    $("#tablaSubOpcionesUniverso").end();

    $('#ServicioAlCliente').stop();
    $('#ServicioAlCliente').animate({ opacity: 1 }, 50);
    $('#ServicioAlCliente').end();

    $(idTablaSubOpciones).hide();
    $(idTablaSubOpciones).css("top", "0px");
    $(idTablaSubOpciones).fadeIn(1500).end();
    //fin de lo nuevo

    $(idSub).animate({ width: anchoSubrayado }, 500);
}

function SeleccionaNodoMenu() {
    var colorSeleccionado="#a1989a";

    if (window.location.toString().indexOf("Origen.aspx") > 0) {
        DespliegaSubOpcionesDeSeccion('Universo');
        $('#Universo').css("color", colorSeleccionado);
        $('#subOpcionUniverso_Origen').css("color", colorSeleccionado);
    }

    if (window.location.toString().indexOf("SavoirFaire.aspx") > 0) {
        DespliegaSubOpcionesDeSeccion('Universo');
        $('#Universo').css("color", colorSeleccionado);
        $('#subOpcionUniverso_SavoirFaire').css("color", colorSeleccionado);
    }

    if ((window.location.toString().indexOf("ElSecretoDeLaPerla.aspx") > 0) || (window.location.toString().indexOf("TiposDePerlas.aspx") > 0)) {
        DespliegaSubOpcionesDeSeccion('Universo');
        $('#Universo').css("color", colorSeleccionado);
        $('#subOpcionUniverso_ElSecretoDeLaPerla').css("color", colorSeleccionado);
    }

    if (window.location.toString().indexOf("MajoricaHoy.aspx") > 0) {
        DespliegaSubOpcionesDeSeccion('Universo');
        $('#Universo').css("color", colorSeleccionado);
        $('#subOpcionUniverso_MajoricaHoy').css("color", colorSeleccionado);
    }

    if (window.location.toString().indexOf("Evolucion.aspx") > 0) {
        DespliegaSubOpcionesDeSeccion('Universo');
        $('#Universo').css("color", colorSeleccionado);
        $('#subOpcionUniverso_Evolucion').css("color", colorSeleccionado);
    }

}

function DespliegaBandaSuperior() {
    $('#bandaSuperior').slideDown(2300, function () {
        // Animación completa
        //alert('terminado');
    });
}

function DespliegaBandaSuperiorSinAnimar() {
    //
    //$('#bandaSuperior').css('top', '0px');
    $('#bandaSuperior').show();
}


function DespliegaBandaInferior() {
    //$('#bandaInferior').slideDown(2300, function() {
        // Animación completa
    //});

    DespliegaMenuPrincipal();

}

function DespliegaMenuPrincipal() {
    var alto = $(window).height();

    //Para las pruebas del menu flotante
    //$('#bandaSuperior').attr("src", "Images/bandaSuperiorGranate_1280x245.png");
    //$('#menuPrincipalFlotante').css("background-image", "url('Images/bandaInferiorGranate_1280x245.png')");

    $('#menuPrincipalFlotante').css("height", "245px");

    $('#menuPrincipalFlotante').css("top", alto + "px");

    if (alto > 745) { //antes era 900
        $('#menuPrincipalFlotante').css("overflow", "visible");
        $('#celdaLinkMenuPrincipalFlotante').hide();
        $('#tablaOpcionesMenuPrincipalFlotante').css("padding-top", "10px");

        alto = (alto / 2) + 268;

        if (window.location.toString().indexOf("PuntosDeVenta.aspx") > 0) {
            $('#menuPrincipalFlotante').css("top", (518)+'px');
            $('#menuPrincipalFlotante').fadeIn(3000);
        }
        else {
            $('#menuPrincipalFlotante').css("top", (alto + 250) + 'px');
            $('#menuPrincipalFlotante').animate({ marginTop: '-250px' }, 3000);
        }



        //$('#menuPrincipalFlotante').animate({ top: "250px" }, 3000);
    }
    else {
        $('#celdaLinkMenuPrincipalFlotante').show();
        $('#menuPrincipalFlotante').css("overflow", "hidden");
        $('#menuPrincipalFlotante').css("height", "30px");
        $('body').css("overflow-y", "visible");
    }


    //Fin pruebas del menu flotante

//    $('#menuPrincipal').css("top", alto + "px");

//    if (alto > 900) {
//        $('#menuPrincipal').animate({ top: "260px" }, 3000);
//    }
//    else {
//        $('#menuPrincipal').animate({ top: "190px" }, 3000);
//    }
}

function DespliegaMenuPrincipalSinAnimar() {
    var alto = $(window).height();

    //Para las pruebas del menu flotante
    //$('#bandaSuperior').attr("src", "Images/bandaSuperiorGranate_1280x245.png");
    $('#menuPrincipalFlotante').css("height", "245px");

    $('#menuPrincipalFlotante').css("top", alto + "px");

    if (alto > 745) { //antes era 900
        $('#menuPrincipalFlotante').css("overflow", "visible");
        $('#celdaLinkMenuPrincipalFlotante').hide();
        $('#tablaOpcionesMenuPrincipalFlotante').css("padding-top", "10px");
        //$('#menuPrincipalFlotante').css("top", '250px');

        $('#menuPrincipalFlotante').css("top", "50%");
        $('#menuPrincipalFlotante').css("margin-top","268px");
        $('#menuPrincipalFlotante').show();
    }
    else {
        $('#celdaLinkMenuPrincipalFlotante').show();
        $('#menuPrincipalFlotante').css("overflow", "hidden");
        $('#menuPrincipalFlotante').css("height", "30px");
        $('body').css("overflow-y", "visible");
    }
}

function OnCargaFondosSlider(listaEstilos) {
    //Indice0: URLFondoSlider
    //Indice1: URLFondoOpcionesSlider
    //Indice2: URLFondoTipologiaSeleccionadaDesdeSlider

    $('#sliderColecciones').css("background-image", "url('" + listaEstilos[0].toString() + "')");
    $('#tablaTipologiasPorColeccion').css("background-image", "url('" + listaEstilos[1].toString() + "')");
    $('#tablaTipologiasPorColeccion').show();
    fondoTipologiaPorInspiracion = listaEstilos[2];
}

var fondos = new Array('FondoHome/FondoNegro.jpg', 'FondoHome/Principal_01.jpg', 'FondoHome/Principal_02.jpg', 'FondoHome/Principal_03.jpg', 'FondoHome/Principal_04.jpg');
var nSegundosFotoEstatica = 3;
var indiceCarrusel = 0;


//Nuevo 19/10/2011 18:07 (Antonio Caballero)
jQuery.preloadImages = function () {
    var bImgLoaded = true;

    //alert('Dentro de la precarga:' + fondos.length);
    for (var i = 0; i < fondos.length; i++) {
        //alert(fondos[i].toString().trim());
        var img = jQuery('<img src="' + fondos[i].toString().trim() + '" />');
        if (img.complete == false)
            bImgLoaded = false;
    }
    return bImgLoaded;
};
//Fin de lo Nuevo 19/10/2011 18:07 (Antonio Caballero)


function OnCargaCarrusel(listadoFotos) {
    fondos = listadoFotos;
    nSegundosFotoEstatica = getCookie('nSegundosFotoEstatica');

    if (nSegundosFotoEstatica == 0)
        nSegundosFotoEstatica = 3;

    //Nuevo 19/10/2011 18:07 (Antonio Caballero)
    if ($.preloadImages(fondos)) {
        //alert('entro');
        PlayCarrusel();    
    } 
    //Fin de lo nuevo 19/10/2011 18:07 (Antonio Caballero
    
}

function PlayCarrusel() {
    CarruselFadeOutDeEncima();
}

function CarruselFadeOutDeEncima() {
    //alert('Fondo de índice ' + indiceCarrusel.toString() + ': ' + fondos[indiceCarrusel]);
    //alert('Fondo de índice ' + (indiceCarrusel + 1).toString() + ': ' + fondos[indiceCarrusel + 1]);

    $("#carruselFotoPorEncima").attr("src", fondos[indiceCarrusel]);
    $("#carruselFotoPorDebajo").attr("src", fondos[indiceCarrusel+1]);

    $("#carruselFotoPorEncima").fadeOut(3000, function () {
        var t = setTimeout("CarruselFadeInDeEncima()", nSegundosFotoEstatica * 1000);
    });
}

function CarruselFadeInDeEncima() {
    indiceCarrusel = indiceCarrusel + 2;

    if (indiceCarrusel > (fondos.length - 1)) {
        indiceCarrusel = 1;
    }

    $("#carruselFotoPorEncima").attr("src", fondos[indiceCarrusel]);

    $("#carruselFotoPorEncima").fadeIn(3000, function () {
        var t = setTimeout("CarruselFadeOutDeEncima()", nSegundosFotoEstatica * 1000);
    });
}

function getCookie(nombreCookie) {
    var start = document.cookie.indexOf(nombreCookie + "=");
    var len = start + nombreCookie.length + 1;
    if ((!start) && (nombreCookie != document.cookie.substring(0, nombreCookie.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(';', len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}


function ajusteBandas() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Para exploradores distintos al IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ en modo standard
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    document.cookie = "resolucionesW=" + myWidth + "; expires=Fri, 27 Jul 2011 02:47:11 UTC; path=/";
    document.cookie = "resolucionesH=" + myHeight + "; expires=Fri, 27 Jul 2011 02:47:11 UTC; path=/";


    if (myHeight < 1024) {
        document.getElementById("franjaSup").style.top = "-50px";
        document.getElementById("fondoNov").style.top = "95px";
        document.getElementById("franjaInf").style.bottom = "-170px";
        this.setStyle("overflow-x", "scroll");
    }
}


function VerificaEmail(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        return false
    }

    if (str.indexOf(" ") != -1) {
        return false
    }

    return true
}


function validarFecha(fecha) {

    var f = fecha;
   try{

    /* comprobamos que la fecha es válida */
       var d = new Date();
    /* la función tiene como entrada: año, mes, día */
       d.setFullYear(f.substring(6, 10),
           f.substring(3, 5) - 1,
           f.substring(0, 2));


    if (d.getMonth() != f.substring(3, 5) - 1 || d.getDate() != f.substring(0, 2)) {
        //alert("Fecha no válida.")
        return false;
    }

    }
catch (err) {
    alert(err);
      return false;
    }

    return true;
}



