/* SELECTOR DE IDIOMA */
$(document).ready(function() {
    $('#otherLanguage').click(function() {
        if ($("#espanol").css("display") == "block") {
            $("#selector").css("top", "0px");
            $(".idioma").css("display", "none");
        }
        else {
            $(".idioma").css("display", "block");
            var heightSelector = $("#selector").height();
            heightSelector -= $(this).height();

            // desplase.
            heightSelector -= 4;
        }

        $("#selector").css("top", "-" + heightSelector + "px");
    });


    $(".idioma").hover(
	  function() {
	      $(this).addClass("hoverselected");
	  },
	  function() {
	      $(this).removeClass("hoverselected");
	  }
	);

    $(".idioma").click(function() {
        window.location = $(this).children("a").attr("href");
    });

});





////////////////////////////// Tema de cookie

function setFavCookie(liststrt) {
    setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
}

function DeleteCookie() {
    setCookie('SaveFave', null, "", "/", "", "");
}

function setCookie(name, value, expires, path, domain, secure) {

    document.cookie = name + "=" + escape(value) +
            ((expires) ? "; expires=" + expires : "") +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            ((secure) ? "; secure" : "");

}

function getCookie(name) {
    var cookie = " " + document.cookie;
    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;
    if (cookie.length > 0) {
        offset = cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = cookie.indexOf(";", offset)
            if (end == -1) {
                end = cookie.length;
            }
            setStr = unescape(cookie.substring(offset, end));
        }
    }
    return (setStr);
}
/**********************/


var CUR_FOTO = 0;
function Carga_foto(ruta,nombre,idVestido) {
	var PeliculaObj = document.pn_imagen_coleccion;
	CUR_FOTO = idVestido;
	
	PeliculaObj.SetVariable("foto", ruta);
	try { PeliculaObj.SetVariable("nombre_vestido", unescape( nombre )); } 
	catch(e) {}
	hideShareMenu();
}


function AddCatalogoFav(idFoto) {
    var PeliculaObj = document.pn_catalogo;

    CUR_FOTO = idFoto;
    if (CUR_FOTO != 0 && CUR_FOTO != "0" && CUR_FOTO != "undefined") {
        PeliculaObj.SetVariable("addFav", "yes");
        PeliculaObj.SetVariable("idVestido", CUR_FOTO);
    }

    if (IS_AUTH) {
        WEBStore.GlobalScreen.InsertListFav(CUR_FOTO);
    }
    else {
        LoadCheckFavaritesUpdated(false, CUR_FOTO);
    }
}


function AddFav(isAut) {
    var PeliculaObj = document.pn_imagen_coleccion;

    if (CUR_FOTO != 0 && CUR_FOTO != "0" && CUR_FOTO != "undefined") {
        PeliculaObj.SetVariable("addFav", "yes");
        PeliculaObj.SetVariable("idVestido", CUR_FOTO);
    }

    if (isAut == "True") {
        WEBStore.GlobalScreen.InsertListFav(CUR_FOTO);
    }
    else {
        LoadCheckFavaritesUpdated(false, CUR_FOTO);
    }
}

function LoadCheckFavaritesUpdated(result, idVestido) {
    if (!result) {

        var ListFave = new Array();
        var liststrt = "";

        var list = getCookie('SaveFave');
        if (list != null) {
            ListFave = list.split(",");

            for (var i = 0; i < ListFave.length - 1; i++) {
                if (idVestido == ListFave[i]) ListFave.splice(i, 1);
            }

            for (var i = 0; i < ListFave.length - 1; i++) {
                liststrt = liststrt + ListFave[i] + ",";
            }

            liststrt = liststrt + idVestido + ",";
            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");

        }
        else {
            liststrt = idVestido + ",";
            setCookie('SaveFave', liststrt, "Mon, 01-Jan-2020 00:00:00 GMT", "/");
        }
    }

}


function Imprimir() {
    var PeliculaObj = document.pn_imagen_coleccion;	

    if (CUR_FOTO != 0 && CUR_FOTO != "0" && CUR_FOTO != "undefined") {
        PeliculaObj.SetVariable("imprimir", "yes");
        PeliculaObj.SetVariable("idVestido", CUR_FOTO);
    }
}

function descargarPdf(idioma) {
    var idiomaServices = "1";
    switch (idioma) {
        case 1:
            idiomaServices = "1";
            break;
        case 2:
        case 3:
            idiomaServices = "3";
            break;
        case 4:
        case 5:
            idiomaServices = "2";
            break;
        case 6:
            idiomaServices = "8";
            break;
			
        case 7:
            idiomaServices = "6";
            break;

        case 8:
            idiomaServices = "7";
            break;

        case 9:
            idiomaServices = "5";
            break;

        case 10:
            idiomaServices = "8";
            break;

        case 11:
            idiomaServices = "9";
            break;

        case 13:
            idiomaServices = "10";
            break;

    }

    if (CUR_FOTO != 0 && CUR_FOTO != "0" && CUR_FOTO != "undefined") {
        var w = window.open("http://webservices-test.pronovias.com/pdf.asp?idioma=" + idiomaServices + "&idvestido=" + CUR_FOTO + "&idVista=1&marca=2");
    }
}   


function loadAjaxMaps(idTienda, lat, lng) {
    window.open('http://www.pronovias.com/googleMaps.asp?idTienda=' + idTienda + '&ie=1&lat=' + lat + '&lng=' + lng, '', 'width=410,height=460,scrollbars=false');
}

function openPolitica(pag) {
    window.open(pag, "legal", "width=400,height=500,scrollbars=1");
}

function AddScreen(Screen) {
    WEBStore.GlobalScreen.SetScreenResolution(Screen);

    // if (Screen == "1024") {
    //     window.location = '/selFullWindow.html';
    // }
    // else {
    if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)) {
        // window.location = window.location;
    }
    else {
        if (!$.browser.opera) {
            setTimeout("window.location = window.location;", 100);
        }
    }
    // }
}

$(document).ready(function() {
    if ($("div").is("#area_scroll")) {
        $('#area_scroll').jScrollPane({ scrollbarWidth: 20, scrollbarMargin: 10, showArrows: true });
    }
    if ($("div").is("#area_scroll_buscador")) {
        $('#area_scroll_buscador').jScrollPane({ scrollbarWidth: 20, scrollbarMargin: 10, showArrows: true });
    }
});

// FUNCION DE SHARE DE LA SECCION DE COLECCIONES

function setNuevoID(idFoto,nombre,idVestido) 
{
	var getFlashMovie = document.pn_share_vestido;
	 getFlashMovie.cambioParametros(idFoto,nombre,idVestido);
}



/* MENU IZQUIERDA */

function ocultaMenu(m) {
    if (m == "2012") {
        // imo, ocultar los menus 2010 y 2011
        var arrColecciones2012 = ["10001", "10002", "10003", "10004", "10005", "10006"];
        $.each(arrColecciones2012, function(index, value) {
            $("#menu_" + value).css("display", "none");
            // $("#menu_"+value).fadeOut(40*(index+1));
        });
    } else if (m == "2011") {
		// imo, ocultar los menus 2010 y 2011
		var arrColecciones2011 = [ "9002", "9003", "9004", "9005", "9006", "9007", "9008" ];
		$.each(arrColecciones2011, function(index, value) { 
			$("#menu_"+value).css("display", "none");
			// $("#menu_"+value).fadeOut(40*(index+1));
		});
	}
	else if (m=="2010") {
		var arrColecciones2010 = [ "35", "42", "404", "405"];
		$.each(arrColecciones2010, function(index, value) { 
			$("#menu_"+value).css("display", "none");
			// $("#menu_"+value).fadeOut(40*(index+1));
		});
	}
}

	function ensenaMenu(m) {
	    if (m == "2012") {
	        // imo, ocultar los menus 2010 y 2011
	        var arrColecciones2012 = ["10001", "10002", "10003", "10004", "10005", "10006"];
	        $.each(arrColecciones2012, function(index, value) {
	            $("#menu_" + value).css("display", "block");
	            $("#menu_" + value).slideDown(900);
	        });
	    }
	    else if (m == "2011") {
			// imo, ocultar los menus 2010 y 2011
			var arrColecciones2011 = [ "9002", "9003", "9004", "9005", "9006", "9007", "9008" ];
			$.each(arrColecciones2011, function(index, value) { 
				$("#menu_"+value).css("display", "block");
				$("#menu_"+value).slideDown(900);
			});
		}
		else if (m=="2010") {
			var arrColecciones2010 = [ "35", "42", "404", "405"];
			$.each(arrColecciones2010, function(index, value) { 
				// $("#menu_"+value).slideDown(900);
				$("#menu_"+value).css("display", "block");
			});
		}
	}

	
	$(document).ready(function() {
		// ocultamos los menús
		b2010Ocultado = true;
		if (!stayOnHome) {
			if($("#menu_32").attr("class")=="nivel2marcado") {
				ensenaMenu("2010");
				b2010Ocultado = false;
				// $("#breadcrumb").css("_top", "95%");
				// $("#breadcrumb").css("_top", "50px");
				// $("#breadcrumb").css("top", "96%");
				$("#breadcrumb").addClass("top96");
			}
			if($("#menu_9000").attr("class")=="nivel2marcado") {
				ensenaMenu("2011");
				$("#breadcrumb").addClass("top90");
			}

			if ($("#menu_10000").attr("class") == "nivel2marcado") {
			    ensenaMenu("2012");
			    $("#breadcrumb").addClass("top90");
			}
}
		
		// marcamos overs
		$("#menu_9000").hover(
			function () {
				$(this).addClass("menuover");
			}, 
			function () {
				$(this).removeClass("menuover");
			}
		);

			// marcamos overs
			$("#menu_10000").hover(
			function() {
			    $(this).addClass("menuover");
			},
			function() {
			    $(this).removeClass("menuover");
			}
		);

			/*
			$('#menu_9000').click(function() {
			ensenaMenu("2011");
			ocultaMenu("2010");
			});
			*/

		$("#menu_32").hover(
			function () {
				$(this).addClass("menuover");
			}, 
			function () {
				$(this).removeClass("menuover");
			}
		);

		/*
		$('#menu_32').click(function() {
			ensenaMenu("2010");
			ocultaMenu("2011");
		});		
		*/
	});



