
$(document).ready(function () {



    //$(".pageMiddle").css("z-index", "1");
    //$(".pageMiddle").css("position", "relative");


    $("#mySlides").cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 600000,
        next: '.hs_5_1_next',
        prev: '.hs_5_1_prev'
    });

    $(".footerLinks .footerLinks2 a:last").addClass("contact");

    //ie z-index issue
    function zIndexHack() {
        var zIndexNumber = 1000;
        jQuery("div").each(function () {
            if (zIndexNumber > 0) {
                jQuery(this).css("zIndex", zIndexNumber);
                zIndexNumber -= 10;
            }
        });
    }
    zIndexHack();
    $(".hs_5_1_prev").css("zIndex", "900");
    $(".hs_5_1_next").css("zIndex", "900");
    $(".categoryGenericMiddle").css("zIndex", "1");
    //ie z-index issue end


    $("#linkMedidas").fancybox({ 'frameWidth': 600 });
    $("a[rel=lightbox]").fancybox({ 'frameWidth': 800, 'overlayColor': '#fff' });

    //Para el Menu
    $(".categoryHeaderHolder ul:empty").remove();
    $(".categoryHeaderHolder a img").removeAttr("alt");
    $(".categoryHeaderHolder a img").removeAttr("title");
    $(".categoryHeaderHolder a").removeAttr("alt");
    $(".categoryHeaderHolder a").removeAttr("title");

$("#fancy_outer").css("zIndex", "9999");
    $("#fancy_inner").css("zIndex", "9999");
    $("#fancy_close").css("zIndex", "9999");
    $("#fancy_bg").css("zIndex", "9999");
    $("#fancy_content").css("zIndex", "9999");

    //Menu
    $("ul:empty").remove();
    $("#ulMenu").superfish();

    $("#aMoreImages").click(function () {

        $(".productRight a:first").trigger("click");



    });

    //Listados
    $(".paginationBarHolder a").live("click", function () { LoadList($(this).attr("href")); return false; });

    //Ficha
    $(".productHomeHolder").each(function () {
        var curCode = $(this).attr("productCode");
        $(this).tooltip({
            track: true,
            delay: 0,
            showURL: false,
            fade: 500,
            extraClass: "productHomeInfo",
            bodyHandler: function () { return $(".productHomeInfo[productCode=" + curCode + "]").html(); }

        });

    });

    $(".productHomeHolder a img").removeAttr("alt");
    $(".productHomeHolder a img").removeAttr("title");
    $(".productHomeHolder a").removeAttr("alt");
    $(".productHomeHolder a").removeAttr("title");


    //Ficha
   // $(".productConfig table tr").css("background-color", "#f6f6f6");
   // $(".productConfig table tr").css("height", "34px");
    
    
    

    //Address
    $("#aShip").click(function () {
        if ($("#presschangeship").is(":hidden")) { $("#changeaddressship").fadeOut(500, function () { $("#presschangeship").fadeIn(500) }); }
        else { $("#presschangeship").fadeOut(500, function () { $("#changeaddressship").fadeIn(500) }); }
    });


    $("#aInvoice").click(function () {
        if ($("#presschange").is(":hidden")) { $("#changeaddress").fadeOut(500, function () { $("#presschange").fadeIn(500) }); }
        else { $("#presschange").fadeOut(500, function () { $("#changeaddress").fadeIn(500) }); }
    });

});

//list.aspx?np=2&c=27&hc=4&s=1&om=&i=
function LoadList(sURL) {

    var sT = sURL.replace(/list.aspx/, "list_reduced.aspx");
    var sData = "";

    $.ajax({
            url: sT,
            data: sData,
            async: false,
            success: function(sHTML) {
                    
                    $(".categoryCenterHolder").fadeOut(500, function() {
                        $(".pageMiddle .centerHolder").html(sHTML);

                        $(".pageMiddle .centerHolder .productHomeHolder").each(function () { 
                            var curCode = $(this).attr("productCode") ;


                            $(".pageMiddle .centerHolder .productHomeHolder a img").removeAttr("alt");
                            $(".pageMiddle .centerHolder .productHomeHolder a img").removeAttr("title");
                            $(".pageMiddle .centerHolder .productHomeHolder a").removeAttr("alt");
                            $(".pageMiddle .centerHolder .productHomeHolder a").removeAttr("title");
                        	
                            $(this).tooltip({ 
			                    track: true, 
			                    delay: 0, 
			                    showURL: false, 
			                    fade: 500,
			                    extraClass: "productHomeInfo",
			                    bodyHandler: function() { return $(".productHomeInfo[productCode=" + curCode + "]").html(); } 

            		        });
            		    
                            $(".categoryCenterHolder").fadeIn(500);

                        });

                    });

    

                }
            });


}


function OnReadyStateChangeRegisterShopGenericLog() { }
			
			function RegisterSessionLog(){
				var ajax;
				if (window.XMLHttpRequest) 
					ajax = new XMLHttpRequest();
				else
					ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
				ajax.onreadystatechange = OnReadyStateChangeRegisterShopGenericLog;	
				var sURL;
				var sQuery;
				sURL="/tools/register_shop_session_log.aspx";
				var d = new Date();
				var curr_msec = d.getMilliseconds()
				sQuery="rnd=" + curr_msec;
				ajax.open("POST", sURL, false);
				ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				ajax.send(sQuery); 
				ajax = null;
			}
			
			
			

function OnReadyStateChangeRegisterShopGenericLog() { }

function RegisterShopGenericLog(affiliate,shop,customer,type,code,p1,p2,p3){

var ajax;
if (window.XMLHttpRequest) 
        ajax = new XMLHttpRequest();
else
	ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	
ajax.onreadystatechange = OnReadyStateChangeRegisterShopGenericLog;	

var sURL;
var sQuery;

sURL="/tools/register_shop_generic_log.aspx";
sQuery = "affiliate=" + affiliate;
sQuery+="&shop=" + shop;
sQuery+="&customer=" + customer;
sQuery+="&type=" + type;
sQuery+="&code=" + code;
sQuery+="&p1=" + p1;
sQuery+="&p2=" + p2;
sQuery+="&p3=" + p3;
var d = new Date();
var curr_msec = d.getMilliseconds()
sQuery+="&rnd=" + curr_msec;
ajax.open("POST", sURL, false);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send(sQuery); 

ajax = null;

}

function ShowPriceShipMethod(oCombo,url)
{
	document.location.href='/product.aspx'+url+'&cship='+oCombo.options[oCombo.selectedIndex].value;
}


function SearchSearchIt() {
	if (document.getElementById('txtSpSearch').value.length > 2) {
		sDummy = new String(document.getElementById('txtSpSearch').value);
		oRegExp = new RegExp(' ', 'g');
		
		document.location.href = 'list.aspx?search=' + sDummy.replace(oRegExp, '+');
	}
}

function EmailCheck(sEmail) {
	var at = "@";
	var dot = ".";
	var lat = sEmail.indexOf(at);
	var lstr = sEmail.length;
	var ldot = sEmail.indexOf(dot);

	if (sEmail.indexOf(at)==-1) { return false; }
	if (sEmail.indexOf(at)==-1 || sEmail.indexOf(at)==0 || sEmail.indexOf(at)==lstr) { return false; }
	if (sEmail.indexOf(dot)==-1 || sEmail.indexOf(dot)==0 || sEmail.indexOf(dot)==lstr) { return false; }
	if (sEmail.indexOf(at,(lat+1))!=-1) { return false; }
	if (sEmail.substring(lat-1,lat)==dot || sEmail.substring(lat+1,lat+2)==dot) { return false; }
	if (sEmail.indexOf(dot,(lat+2))==-1) { return false; }
	if (sEmail.indexOf(" ")!=-1) { return false; }

 	return true;
}


//JFS 22-09-2008
function changelanguage(ai_ilanguage){

    var sURL    = document.location.host;
    var sPath   = document.location.pathname;
    var sParams = document.location.search;

    var sMatchStr  =/(\&l=.)/;
    var sMatchStr2 =/(\?l=.)/;

    //alert(sURL);
    //alert(sPath);
    //alert(sParams);

    sParams = sParams.replace(sMatchStr, '');
    sParams = sParams.replace(sMatchStr2, '?');

    if(sParams == '') { 
        document.location.href = 'http://' + sURL + sPath + '?l=' + ai_ilanguage;
    } else {
        document.location.href = 'http://' + sURL + sPath + sParams + '&l=' + ai_ilanguage;
    }

}



function SelectCategory(ai_icategory, ai_ilevel){
	if (ai_ilevel>1)
		document.location.href='/list.aspx?c='+ai_icategory+'&md=2';
	else	
		document.location.href='/category.aspx?c='+ai_icategory;
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function IsThereCookies(){
testValue=Math.floor(1000*Math.random());
SetCookie('AreCookiesEnabled',testValue);
return (testValue==ReadCookie('AreCookiesEnabled')); 
}


function showVariantContent(type, field, index, at) {
window.open('/show_variant_content.aspx?type='+type+'&field='+field+'&index='+index+'&at='+at, 'suscriber_legal_notice', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=400,height=250,left=' + ((screen.width -400) / 2) + ',top=' + ((screen.height -250) / 2));
}

function ValidatorBefore() {
    if (document.all){
    var i;
    for (i = 0; i < Page_Validators.length; i++) {
        ValidatorValidate(Page_Validators[i]);
    }
    ValidatorUpdateIsValid();    
    Page_BlockSubmit = !Page_IsValid;
    return Page_IsValid;
    }
    else return true;
}


function showPopUp(url) {
    window.open(url, "content_pop_up", "toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=755,height=550,left=" + ((screen.width - 755) / 2) + ",top=" + ((screen.height - 550) / 2));
}

