
function setTableStyles(clase)
{
    
    $("." + clase + " table").css("font-family", "Tahoma");
    $("." + clase + " table td:even").css("font-weight", "normal");
    $("." + clase + " table td:odd").css("font-weight", "bold");
    $("." + clase + " table").css("border", "1px solid #F1ECEC");
    $("." + clase + " table tr").attr("height", "10px;");
    $("." + clase + " table tr:even").css("background-color", "#DAD8D8");
    $("." + clase + " table tr td").css("padding", "4px");
    

    $(".productRight table").css("font-family", "Tahoma");
    $(".productRight table td:even").css("font-weight", "normal");
    $(".productRight table td:odd").css("font-weight", "bold");
    $(".productRight table").css("border", "1px solid #F1ECEC");
    $(".productRight table tr").attr("height", "10px;");
    $(".productRight table tr:even").css("background-color", "#DAD8D8");
    $(".productRight table tr td").css("padding", "4px");
    
}

function loadContent(idContent) {

    $("#contentImage").html("<img src='" + $("#" + idContent).html() + "'>");
    var url = "/contentTextAjax.aspx?co=" + idContent ;

    $(".contentText").empty();

    $(".contentText").load(url,function(){ 
    $(".contentText table").css("font-family", "Tahoma");
    $(".contentText table td:even").css("font-weight", "normal");
    $(".contentText table td:odd").css("font-weight", "bold");
    $(".contentText table").css("border", "1px solid #F1ECEC");
    $(".contentText table tr").attr("height", "10px;");
    $(".contentText table tr:even").css("background-color", "#DAD8D8");
    $(".contentText table tr td").css("padding", "4px");

    changeTabPro(1);
    $("#tab_1").show();
    $(".contentTab #1").css("color", "#000000");
    $(".contentTab #1").css("font-weight", "bold");
    
});
    url = "/contentTitleAjax.aspx?co=" + idContent;
    

    $(".contentTitle h1").load(url);
}



function ShowCategory(idCatd, mode) {

    if (mode == 'true' ) {
        $(".subCategories .catHolder").hide(500);
    }

    if (mode == 'false') {
        //    $(".subCategories .catHolder .catHolder").hide(500);
        var number = $("#catId_" + idCatd).parents(".catHolder").length
        var selector = ".subCategories";
        for (i = 0; i <= number; i++) {
            selector = selector + " .catHolder";
        }

        $(selector).hide(500);
    }
    

    $(".leftMenuProSelected").removeClass("leftMenuProSelected");
    $("#catHolder_" + idCatd).toggle(500);
}

function encodeUTF8(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";

	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);

		if (c < 128) {
			utftext += String.fromCharCode(c);
		}
		else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		}
		else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}

	}

	return utftext;
}

			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=.)/;

    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));
}

function changeTabPro(idTab) {

    $(".contentTab #1").css("color", "#BBB9B9");
    $(".contentTab #1").css("font-weight", "normal");
    $(".contentTab #2").css("color", "#BBB9B9");
    $(".contentTab #2").css("font-weight", "normal");
    $(".contentTab #3").css("color", "#BBB9B9");
    $(".contentTab #3").css("font-weight", "normal");
    $(".contentTab #4").css("color", "#BBB9B9");
    $(".contentTab #4").css("font-weight", "normal");
    $(".contentTab #5").css("color", "#BBB9B9");
    $(".contentTab #5").css("font-weight", "normal");
    $(".contentTab #6").css("color", "#BBB9B9");
    $(".contentTab #6").css("font-weight", "normal");
    
    $("#tab_1").hide();
    $("#tab_2").hide();
    $("#tab_3").hide();
    $("#tab_4").hide();
    $("#tab_5").hide();
    $("#tab_6").hide();
    $("#tab_" + idTab.id).show();
    $(".contentTab #" + idTab.id).css("color", "#000000");
    $(".contentTab #" + idTab.id).css("font-weight", "bold");
}

$(document).ready(function () {

    try {
        $(".productHomeImageCarrousel").each(function () {
            if ($(this).children("p").html().indexOf("no_image") == "-1") {
                $(this).children("span").css("display", "none");
            }
            else {
                $(this).children("p").css("display", "none");
                //$(this).children("span").css("padding-top", "10px");
            }
        });
    }
    catch (e) {
    }
    

    $(".productHomeCarrousel").mouseenter(function () {
        $(".categoryGenericBottom").html($(this).attr("name"));
    });

    $(".productHomeCarrousel").mouseleave(function () {
        $(".categoryGenericBottom").html("");
    });

    changeTabPro(1);
    $("#tab_1").show();
    $(".contentTab #1").css("color", "#000000");
    $(".contentTab #1").css("font-weight", "bold");


    if ($(".productHomeButton").attr("code") == "") {
        $(".productHomeButton").css("display", "none");
    }

    if ($("#menuCarrousel li").length < 5) {
        $(".imageSlider .next").attr("src", "/images/nextOff.png");
        $(".imageSlider .prev").attr("src", "/images/prevOff.png");
        $(".categorySideHolder .jcarouselFooter").jCarouselLite({
            speed: 500,
            visible: 4,
            circular: false
        });
    }
    else {
        $(".categorySideHolder .jcarouselFooter").jCarouselLite({
            speed: 500,
            visible: 4,
            btnNext: ".imageSlider .next",
            btnPrev: ".imageSlider .prev",
            circular: false
        });
    }

    $(function () {
        $(".lightview").lightBox({});
    });

    $("#jCarousel").jCarouselLite({
        auto: 0,
        speed: 1000,
        visible: 3,
        btnNext: ".next",
        btnPrev: ".prev",
        easing: "linear"
    });

    setTableStyles("contentText");
    setTableStyles("productAttributes");

    $("#alergenos_holder").dialog({
        width: 800,
        height: 600,
        autoOpen: false,
        title: $("#alergenos_holder").attr("title"),
        modal: true
    });
    $(".alergenos").click(function () {
        $("#alergenos_holder").dialog("open");
        return false;
    });

    $(".categoryCenterHolderBottom").prepend($(".productHomeImage .productHomeCarrousel"));

    $(".categoryCenterHolderBottom .productHomeCarrousel").click(function () {
        var productCode = $(this).attr("code");
        var language = $(this).attr("l");
        var category = $(this).attr("c");

        //Nombre
        var url = "/get_product_name.aspx?p=" + productCode + "&l=" + language + "&c=" + category;

        $(".categoryCenterHolder").load(url, function () {
            $(".productHomeImage .productHomeCarrousel").css("display", "none"); ; setTableStyles("productAttributes");

            $("#alergenos_holder").dialog({
                width: 800,
                height: 600,
                autoOpen: false,
                title: $("#alergenos_holder").attr("title"),
                modal: true
            });
            $(".alergenos").click(function () {
                $("#alergenos_holder").dialog("open");
                return false;
            });

            if ($(".productHomeButton").attr("code") == "") {
                $(".productHomeButton").css("display", "none");
            }

        });

    });

});