
var _LABEL_CLOSE_FILTER = "Borrar filtro";


			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    = window.location.host;
    var sPath   = window.location.pathname;
    var sParams = window.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));
}


/*JQUERY SCRIPTS*/

$(document).ready(function() {

    //main list
    $(".tab_title").appendTo($("#tab_holder"));
    $(".tab_content").appendTo($("#tab_content_holder"));
    $("#tab_content_holder .tab_content:empty").each(function() {
        $(this).hide();
        $("#tab_holder .tab_title[target="+$(this).attr("id")+"]").hide();
    });
    
    $("#tab_holder .tab_title").click(function() {
        $("#tab_holder .tab_title").removeClass("selected");
        $(this).addClass("selected");
        $("#tab_content_holder .tab_content").hide();
        $("#tab_content_holder #"+$(this).attr("target")).show();
    });
        
    //secondary list
    $(".nav-2:empty").siblings(".nav-2-title").css("margin-bottom", 10).end().remove();
    $(".left_tabs .tabs div").click(function() {
        $(".left_tabs .tabs div").removeClass("selected");
        $(this).addClass("selected");
        $(".left_tabs .holder").hide();
        $(".left_tabs #"+$(this).attr("target")).show();
    });

    $("#left_categories li[code="+$("#current_category").text()+"]").children("a").addClass("selected");
    
    if ($("#left_categories .no_data").length > 0 || $("#current_category").text() == "0") {
        $("#left_categories .category_title").remove();
        $("#left_categories .category_description").remove();
        $("#left_categories").css("padding-top", "10px");
    }
    
    //filter tab
    if ($(".left_tabs #left_filter").is(":empty")) {
        $(".left_tabs .tabs div.filter").unbind("click").css({"color" : "#ccc", "cursor" : "default"});
    }
    else {
        $(".left_tabs .tabs div.filter").trigger("click");
    }
    
    //filter behaviour    
    $("#left_filter .filterItem").click(function() {
        if ($(this).hasClass("selected")) {
            $(this).removeClass("selected");
        }
        else {
            $(this).addClass("selected");
        }
        filterItems();
    });
    
    var xhrFilter;
    function filterItems(override) {
        if ($("#left_filter .selected").length == 0 && !override) {
            $("#category_filter_holder").empty();
            $("#category_list_holder").show();
            
            if (xhrFilter) xhrFilter.abort();
            stopLoadingFilter();
            
            return true;
        }
                
        var params = "";
        $(".filterHolder").each(function() {
            params += $(this).attr("field") + ":";
            $(this).children(".filterItem").each(function() {
                if ($(this).hasClass("selected")) {
                    params += $(this).attr("code") + ",";
                }
            });
            params = params.substr(0, params.length-1);
            params += "|";
        });
        params = params.substr(0, params.length-1);
        price = "";
        if ($(".filterHolderPrice .selected").length > 0) {
            price = "&price="+$(".filterHolderPrice .selected:eq(0)").attr("code");
        }
        category = "";
        $(".filterHolderCategory .selected").each(function() {
            category += $(this).attr("code")+",";
        });
        if (category != "") {
            category = category.substring(0, category.length-1);
        }
        else {
            category = $("#real_category").html();
        }
        
        params = "filter="+params+"&cat="+category+price;
                
        startLoadingFilter();
        
        if (xhrFilter) xhrFilter.abort();
        xhrFilter = $.ajax({
            url: "/list_e.aspx",
            data: params,
            cache: false,
            success: function(html){
                $("#category_filter_holder").empty().html(html);
                stopLoadingFilter();
                initFilter();                
            },
            error: function() {
                stopLoadingFilter();
            }
        });     
    }
    
    var $filterLoader;
    function startLoadingFilter() {
        if ($filterLoader) $filterLoader.remove();
        $filterLoader = $("<div></div>").addClass("filterLoader").css("opacity", 0).appendTo($(".center_wide")).fadeTo("fast", 0.85);
    }    
    function stopLoadingFilter() {
        $filterLoader.fadeOut("fast", function() {
            $(this).remove();
        });
    }
    
    function initFilter() {
        $("#category_filter_holder .filter_path").removeClass("hidden");
        if ($("#left_filter .selected").length == 0) {
            $("#category_filter_holder .filter_path").hide();
        }    
        $("<div class='close'>"+_LABEL_CLOSE_FILTER+"</div>").prependTo($("#category_filter_holder .category_title")).click(function() {
            $("#category_filter_holder").empty();
            $("#left_filter .filterItem").removeClass("selected");
            $("#category_list_holder").show();
        });
        $("#category_filter_holder .pagination a").each(function() {
            this.href = this.href.replace("list.aspx", "list_filter.aspx");
        });
        $("#category_filter_holder .pagination a").click(function() {
            captureFilterPagination(this);
            return false;
        });
        $("#category_list_holder").hide();
        
        //filter path
        $("#left_filter .filterHolderCategory").each(function() {
            filter_path = "";
            $(this).find(".selected").each(function() {
                filter_path += $(this).clone().find(".filterBox").remove().end().html()+" - ";
            });
            if (filter_path != "") {
                filter_path = filter_path.substring(0, filter_path.length-3);
                filter_path = "<p><img src='/images/delete.gif' class='unfilter' index='"+$("#left_filter .filterHolderIndex").index(this)+"'><span>"+$(this).prev(".filterTitle").html()+":</span> "+filter_path+"</p>";
                $("#category_filter_holder .filter_path").append(filter_path);
            }
        });
        $("#left_filter .filterHolder").each(function() {
            filter_path = "";
            $(this).find(".selected").each(function() {
                filter_path += $(this).clone().find(".filterBox").remove().end().html()+" - ";
            });
            if (filter_path != "") {
                filter_path = filter_path.substring(0, filter_path.length-3);
                filter_path = "<p><img src='/images/delete.gif' class='unfilter' index='"+$("#left_filter .filterHolderIndex").index(this)+"'><span>"+$(this).prev(".filterTitle").html()+":</span> "+filter_path+"</p>";
                $("#category_filter_holder .filter_path").append(filter_path);
            }
        });
        $("#left_filter .filterHolderPrice").each(function() {
            filter_path = "";
            $(this).find(".selected").each(function() {
                filter_path += $(this).clone().find(".filterBox").remove().end().html()+" - ";
            });
            if (filter_path != "") {
                filter_path = filter_path.substring(0, filter_path.length-3);
                filter_path = "<p><img src='/images/delete.gif' class='unfilter' index='"+$("#left_filter .filterHolderIndex").index(this)+"'><span>"+$(this).prev(".filterTitle").html()+":</span> "+filter_path+"</p>";
                $("#category_filter_holder .filter_path").append(filter_path);
            }
        });

        $("#category_filter_holder .filter_path .unfilter").click(function() {
            $("#left_filter .filterHolderIndex:eq("+$(this).attr("index")+") .selected").removeClass("selected");
            filterItems();
        });
    }
    
    function captureFilterPagination(anchor) {
        url = anchor.href.substring(0, anchor.href.indexOf("?"));
        parameters = anchor.href.substring(anchor.href.indexOf("?")+1, anchor.href.length);
        $.ajax({
            url: url,
            data: parameters,
            cache: false,
            success: function(html){
                $("#category_filter_holder").empty().html(html);
                initFilter();
            }
        });
    }
    
    //filter length items
    $(".filterHolderLength .filterItem").mouseenter(function() {
        $(this).prevAll().andSelf().css("background-position", "left -69px");
        $(this).nextAll().css("background-position", "left top");    
    });
    $(".filterHolderLength .filterItem").mouseleave(function() {
        $(".filterHolderLength .filterItem").css("background-position", "left top");
        $(".filterHolderLength .selected").prevAll().andSelf().css("background-position", "left -69px");    
    });
    $(".filterHolderLength .filterItem").unbind("click");
    $(".filterHolderLength .filterItem").click(function() {
        $(this).prevAll().andSelf().css("background-position", "left -69px");
        if ($(this).hasClass("selected")) {
            $(".filterHolderLength .filterItem").removeClass("selected");
            $(this).removeClass("selected");
        }
        else {
            $(".filterHolderLength .filterItem").removeClass("selected");
            $(this).addClass("selected");
        }
        filterItems();    
    });
    
    //filter diameter items
    $(".filterHolderDiameter .filterItem").mouseenter(function() {
        $(this).prevAll().andSelf().css("background-position", "left -69px");
        $(this).nextAll().css("background-position", "left top");    
    });
    $(".filterHolderDiameter .filterItem").mouseleave(function() {
        $(".filterHolderDiameter .filterItem").css("background-position", "left top");
        $(".filterHolderDiameter .selected").prevAll().andSelf().css("background-position", "left -69px");    
    });
    $(".filterHolderDiameter .filterItem").unbind("click");
    $(".filterHolderDiameter .filterItem").click(function() {
        $(this).prevAll().andSelf().css("background-position", "left -69px");
        if ($(this).hasClass("selected")) {
            $(".filterHolderDiameter .filterItem").removeClass("selected");
            $(this).removeClass("selected");
        }
        else {
            $(".filterHolderDiameter .filterItem").removeClass("selected");
            $(this).addClass("selected");
        }
        filterItems();    
    });
    
    //filter price items
    $(".filterHolderPrice .filterItem").unbind("click");
    $(".filterHolderPrice .filterItem").click(function() {
        if ($(this).hasClass("selected")) {
            $(".filterHolderPrice .filterItem").removeClass("selected");
            $(this).removeClass("selected");
        }
        else {
            $(".filterHolderPrice .filterItem").removeClass("selected");
            $(this).addClass("selected");
        }
        filterItems();
    });
    
    //filter item show all
    $(".cat_browsing_all a").click(function() {
        $("#left_filter .filterItem").removeClass("selected");
        filterItems(true);
        return false;
    });
    
    //product
    $(".small_images img[src*=no_image]").parent("a").remove();
    $(".images a").slimbox();
    
    //product thumbnails
    oldImageSRC = $(".images a:eq(0) img").attr("src");
    $(".small_images a").mouseover(function() {
        smallSRC = $(this).find("img").attr("src").replace("/small/", "/medium/").replace("/ps_", "/pm_").replace("&w=55", "&w=200").replace("&h=55", "&h=200");
        $(".images a:eq(0) img").attr("src", smallSRC);
    });
    $(".small_images a").mouseout(function() {
        $(".images a:eq(0) img").attr("src", oldImageSRC);
    });
    
});