
var s = new Array();
var linkproductid = "";
var divpromo = "";
var superruperpromobool = true;
var HomeRedirect;
var LoginRedirect;
var OrdersRedirect;
var campaign = "";

$.ajaxSetup({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    data: "{}",
    dataType: "json"
});

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 getQueryString(key) {
    s = window.location.search.substring(1);
    arr = s.split("&");
    for (i = 0; i < arr.length; i++) {
        pair = arr[i].split("=");
        if (pair[0].toLowerCase() == key) { return pair[1]; }
    }
}

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);
}

function swfObjectCallback(e) {
    if (e.success)
        return;
    var hid = $('#' + e.id + '> input');
    var link = $('#' + e.id + '> a');
    var alt = link.text();
    var fallback = hid.val().split('|');
    link.empty().append('<img src="' + fallback[0] + '" alt="' + alt + ' height="' + fallback[2] + '" width="' + fallback[1] + '"/>');
}



function hideFloatingBanner() {
    $('#advert_table').hide();
}

function OnShoppingData(res) {

    var spanCount = $('#basketProductsCount');
    if (spanCount == null)
        return;
    spanCount.html(res.Quantity);

    var spanPrice = $('#basketTotalPrice');
    if (spanPrice == null)
        return;
    spanPrice.html(res.Price);
}
function UpdateMiniBasket() {
    var paramName = 'utm_source';
    var source = getQueryString(paramName);
    var fromCookie = getCookie(paramName);
    if (source != null && fromCookie == null) {
        var today = new Date();
        setCookie(paramName, source, (new Date(today.getTime() + (30 * 1000 * 60 * 60 * 24))).toGMTString(), '/', '', '');
        fromCookie = source;
    }

    $.ajax({
        url: "/Store/Services/StoreService.asmx/GetShoppingData",
        data: $.toJSON({ utm_source: fromCookie }),
        success: function (res) { OnShoppingData(res.d); }
    });
}

function ShowSubMenu(id) {
    node = $(".menuBig #" + id);
    node.append('<div class="lev2"></div>');
    node.find(' .lev2').html($("#submenu #_" + id).html());
    Show3LevelSubmenu();
}

function ShowSubMenu1(res, id) {
    $(".menuBig #" + id + ' .lev2').html(unescape(res));
    Show3LevelSubmenu();
}
function Show3LevelSubmenu() {
    $(".lev2 .point").hover(function () {
        $($(this).find(' .lev3')).show();
        return true;
    },

	    function () {
	        $(this).find(' .lev3').hide();
	        return true;
	    });

}

function GetSubMenu(id) {
    $.ajax({
        url: "/Store/Services/StoreService.asmx/LoadMainMenu",
        data: $.toJSON({ key: id }),
        success: function (res) { ShowSubMenu(res.d, id); }
    });
}

function openLayer(name) {
    $('#' + name).show();
}

function closeLayer(name) {
    $('#' + name).hide();
}


function openCloseLayer(name) {
    skn = document.getElementById(name).style;
    if (skn.display == "" || skn.display == "block") {
        skn.display = "none";
    } else {
        skn.display = "block";
    }
}

function switchId(nameOfId, numNumber, numOfEx) {
    for (i = 1; i < numNumber + 1; i++) {
        if (i != numOfEx) {
            if (document.getElementById(nameOfId + "_" + i) != null)
                document.getElementById(nameOfId + "_" + i).className = "inactive";
        } else {
            if (document.getElementById(nameOfId + "_" + i) != null)
                document.getElementById(nameOfId + "_" + i).className = "active";
        }
    }

}

function switchIdRubric(nameOfId, numNumber, numOfEx) {

    numNumber = numNumber * 10;
    for (i = numNumber + 1; i < numNumber + 4; i++) {
        if (i != numOfEx) {
            document.getElementById(nameOfId + "_" + i).className = "inactive";
        } else {
            document.getElementById(nameOfId + "_" + i).className = "active";
        }
    }
}

function switchLayer(nameOfId, numNumber, numOfEx) {
    var el;
    for (i = 0; i < numNumber + 1; i++) {
        if (document.getElementById(nameOfId + "_" + i) != null) {
            el = document.getElementById(nameOfId + "_" + i);
            if (el == null) continue;
            if (i != numOfEx) {
                el.style.display = "none";
            } else {
                el.style.display = "block";

            }
        }
    }
}



function switchLayerRubric(nameOfId, numNumber, numOfEx) {
    var el;
    numNumber = numNumber * 10;

    for (i = numNumber + 1; i < numNumber + 4; i++) {
        el = document.getElementById(nameOfId + "_" + i);
        if (el == null) continue;
        if (i != numOfEx) {
            el.style.display = "none";
        } else {
            el.style.display = "block";
        }
    }
}

function switchBrand(name) {
    var el1, el2;

    el1 = document.getElementById(name + "_AZ");
    el2 = document.getElementById(name + "_BrandRubric");

    if (el1.className == "inactive") {
        el2.className = "inactive";
        el1.className = "active";
    } else {
        el2.className = "active";
        el1.className = "inactive";
    }

}
function switchLayerBrand(name) {

    var el1, el2;

    el1 = document.getElementById(name + "_AZ").style;
    el2 = document.getElementById(name + "_BrandRubric").style;

    if (el1.display == "none") {
        el2.display = "none";
        el1.display = "block";
    } else {
        el2.display = "block";
        el1.display = "none";
    }
}

function switchCountry(name) {
    sknCountry = document.getElementById(name + "_country").style;
    sknFr = document.getElementById(name + "_fr").style;

    if (sknCountry.display == "none") {
        sknFr.display = "none";
        sknCountry.display = "block";
    } else {
        sknFr.display = "block";
        sknCountry.display = "none";
    }
}

function rollOverList(nameOfId, pClass) {
    document.getElementById(nameOfId).className = pClass;
}
function rollOutList(nameOfId, pClass) {
    document.getElementById(nameOfId).className = pClass;
}



function upProduct(qteNum, nameForm, maxProduct) {
    if (caddie_upQte(qteNum, nameForm, maxProduct))
        pageTracker._trackEvent('Product page', 'quantity', 'more', parseInt(qteNum));
}
function dwProduct(qteNum, nameForm, minProduct) {
    if (caddie_dwQte(qteNum, nameForm, minProduct))
        pageTracker._trackEvent('Product page', 'quantity', 'less', parseInt(qteNum));
}
function upListItem(qteNum, nameForm, maxProduct) {
    if (caddie_upQte(qteNum, nameForm, maxProduct))
        pageTracker._trackEvent('global', 'quantity', 'more', parseInt(qteNum));
}
function dwListItem(qteNum, nameForm, minProduct) {
    if (caddie_dwQte(qteNum, nameForm, minProduct))
        pageTracker._trackEvent('global', 'quantity', 'less', parseInt(qteNum));
}

function caddie_upQte(qteNum, nameForm, maxProduct) {

    var input = document.getElementById("qte" + qteNum);

    if (input.value == 99) {
        alert(maxProduct);
        return false;
    }
    input.value++;
    return true;
}


function caddie_dwQte(qteNum, nameForm, minProduct) {
    var input = document.getElementById("qte" + qteNum);
    if (input.value < 2) {
        alert(minProduct);
        return false;
    }
    input.value--;
    return true;

}




// UP et DOWN de la table price dans les liste
function liste_upQte(qteNum) {
    if (document.selectCompare["qte" + qteNum].value >= 99) {
        alert('<%=LangUtil.Localize(Resource.DiapoBin_MaxProduct) %>');
    } else {
        document.selectCompare["qte" + qteNum].value++;
    }

}


function liste_dwQte(qteNum) {
    if (document.selectCompare["qte" + qteNum].value < 2) {
        alert('<%=LangUtil.Localize(Resource.DiapoBin_MinProduct) %>');
        document.selectCompare["qte" + qteNum].value = 1;
    } else {
        document.selectCompare["qte" + qteNum].value--;
    }
}




// UP et DOWN du little caddie
function lbasket_upQte(qteNum) {
    document.form_labsket["qte" + qteNum].value++;
}


function lbasket_dwQte(qteNum) {
    if (document.form_labsket["qte" + qteNum].value == 1) {
        document.form_labsket["qte" + qteNum].value--;
        alert('Souhaitez-vous supprimer ce produit de votre panier ?');
    } else {
        document.form_labsket["qte" + qteNum].value--;
    }
}



function switchLabel() {
    if (document.getElementById('label_2').style.display == "none") {
        document.getElementById('label_1').style.display = "none";
        document.getElementById('label_2').style.display = "block";
    } else {
        document.getElementById('label_2').style.display = "none";
        document.getElementById('label_1').style.display = "block";
    }

    document.forms["form_compte"].add1.checked = true;
    document.forms["form_compte"].add2.checked = false;
}


function goToCompare(formName, page) {

    var numberCheck = 0;
    var choix = document.forms[formName].cases;

    for (i = 0; i < choix.length; i++) {
        if (choix[i].checked == true) {
            numberCheck++;
        }
    }

    if (numberCheck < 2) {
        alert('Vous devez choisir au moins 2 produits');
    } else {
        window.location.href = page;
    }
}


function galleryPhoto(DirOfImg) {

    document.images["zoom_big"].src = DirOfImg;

}



function caddie_openTr(trNum) {
    tr_name = document.getElementById("tr_open" + trNum).style;
    tr_class = document.getElementById("tr_" + trNum);

    if (tr_name.display == "none") {
        tr_name.display = "";
        document.getElementById("link_see" + trNum).innerHTML = "Masquer les accessoires";
        tr_class.className = 'lg_produit_opener';

    } else {
        tr_name.display = "none";
        document.getElementById("link_see" + trNum).innerHTML = "Voir les accessoires";
        tr_class.className = 'lg_produit';
    }
}



function list_openTr(trNum, infos) {
    tr_name = document.getElementById("tr_open" + trNum).style;
    tr_class = document.getElementById("tr_" + trNum);

    if (tr_name.display == "none") {
        tr_name.display = "";
        tr_class.className = 'lg_produit_on';

    } else {
        tr_name.display = "none";
        tr_class.className = 'lg_produit';
    }
}


function list_openRubricDescript() {
    tr_name = document.getElementById("RubricDescript").style;

    if (tr_name.display == "none") {
        tr_name.display = "";

    } else {
        tr_name.display = "none";
    }
}



function resizeListFour(pDiv1, pDiv2, pDiv3, pDiv4, pNumber) {
    $(document).ready(function () {
        var newClassName;
        for (i = 1; i < pNumber + 1; i++) {

            var detailDiv = $("#pdt_detail_" + i);
            if (!detailDiv.length) return;

            var nameTemp = detailDiv.attr('title');

            newClassName = "";
            if (i == pDiv1 || i == pDiv2 || i == pDiv3 || i == pDiv4) {
                newClassName = 'bloc_pdt_detail_left';
            } else {
                if (nameTemp == "kdo") {
                    newClassName = 'bloc_pdt_detail_kdo';
                } else {
                    newClassName = 'bloc_pdt_detail';
                }
            }

            detailDiv[0].className = newClassName;
        }

    });
}

function init_list(numNumber, pais) {


    if (document.all) {
        w = document.body.clientWidth + 17;
    } else {
        w = window.innerWidth;
    }


    if (w >= 1633) {
        resizeListFour(8, 16, '', '', numNumber);
    } else if (w >= 1431) {
        resizeListFour(7, 14, '', '', numNumber);
    } else if (w >= 1229) {
        resizeListFour(5, 10, 15, 20, numNumber);
    } else if (w < 1229) {
        resizeListFour(5, 10, 15, 20, numNumber);
    }


}


// positionner le panier et le zoom
function dimensionLayer(nLay) {

    $(document).ready(function () {

        $('#opac_layer').css({ left: 0 });
        $('#opac_layer').animate({ opacity: 0.5 }, 0);

        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var windowScroolTop = $(window).scrollTop();
        var divWidth = $('#' + nLay).width();
        var divHeight = $('#' + nLay).height();

        //		alert('windowWidth:'+windowWidth+' windowHeight:'+windowHeight+' windowScroolTop:'+windowScroolTop);

        var totalWidth = windowWidth / 2 - divWidth / 2;
        var totalHeight = windowHeight / 2 - divHeight / 2 + windowScroolTop;


        $('#' + nLay).css({ 'margin-left': totalWidth });
        $('#' + nLay).css({ 'margin-top': totalHeight });

        $('#opac_layer').width($(document).width());
        $('#opac_layer').height($(document).height());


    });
}

// positionner le little panier
function posLittleBasket() {

    openCloseLayer('little_basket');

    $(document).ready(function () {

        var windowWidth = $(window).width();
        var allWidth = $('#outils').width();
        var divWidth = $('#little_basket').width();

        if (document.all) {
            var totalWidth = allWidth - divWidth;
        } else {
            var totalWidth = allWidth - divWidth + 12;
        }

        $('#little_basket').css({ 'margin-left': totalWidth });


    });
}



function closeAllQte() {
    $(document).ready(function () {
        $('.diapo_qte').css('display', 'none');
        $('.diapo_qte_liste').css('display', 'none');
    });
}

function AddNegotiatedProductsToCart(storeUrl) {

    $('.negotiatedproduct_row').each(function () {
        var productID = $(this).find('.prd_id input').val();
        var quantity = parseInt($(this).find('.prd_qty').val());

        if (quantity > 0) {

            $.ajax({
                url: "/Store/Services/StoreService.asmx/AddToCart",
                data: $.toJSON({ productID: productID, quantity: quantity }),
                async: false
            });
        }
    });

    document.location = storeUrl + "/checkout";
}

function BuyProduct(productID, quantity, async) {
    var quantityserver;
    quantityserver = parseInt(quantity);

    $.ajax({
        url: "/Store/Services/StoreService.asmx/AddToCart",
        data: $.toJSON({ productID: productID, quantity: quantityserver }),
        async: async
    });
}

function OnLookupWithGarantie(productID, quantity, showWarranty) {
    if (quantity != 1 || !showWarranty) {
        OnLookup(productID, quantity);
        return;
    }
    BuyProduct(productID, quantity, true);
    $('#opac_layer').show();
    var popup = $('#popupGarantie');
    popup.appendTo($('#popup_container'));
    dimensionLayer('popupGarantie');
    popup.show();
}
function OnLookupPopup(productID, quantity) {
    OnLookup(productID, quantity);
    pageTracker._trackEvent('global', 'quantity', 'add');
}
function OnLookup(productID, quantity) {
    BuyProduct(productID, quantity, false);
    document.location = "/checkout";
}


function CampaignOnLookup(productID, CampaignName, quantity) {
    var quantityserver;
    quantityserver = parseInt(quantity);


    campaign = CampaignName.toLowerCase();
    if (campaign == 'siemens') campaign = 'gigaset'
    $.ajax({
        url: "/Store/Services/StoreService.asmx/AddToCartWithCampaign",
        data: $.toJSON({ productID: productID, quantity: quantityserver, CampaignName: campaign }),
        async: false
    });
    document.location = "/campaigns/" + campaign + "/checkout";
}

function AddLastSeen(Product_ID) {

    $.ajax({
        url: "/Store/Services/StoreService.asmx/AddLastSeenProduct",
        data: $.toJSON({ productID: Product_ID })
    });
}
function UpdateLastSeen() {
    $.ajax({
        url: "/Store/Services/StoreService.asmx/GetLastSeenData",
        data: "{}",
        success: function (res) { OnLastSeenUpdated(res.d); }
    });
}

function OnLastSeenUpdated(res) {

    var divLabel = $('#consulted_label');
    if (divLabel == null)
        return;
    if (res.Visible)
        divLabel.css({ 'display': 'block' });
    else
        divLabel.css({ 'display': 'none' });

    var spanLastSeen = $('#consulted_content');
    if (spanLastSeen == null)
        return;
    spanLastSeen.html(unescape(res.Html));

    $('#consulted_label').mouseenter(function () {
        $('#consulted_content').show();
        return true;
    });

    $('#consulted_label').mouseleave(function () {
        $('#consulted_content').hide();
        return true;
    });
}


function LoginOn(base, secureBase, redirOk, redirFail, sessionId) {

    var email = document.getElementById('tbxUserMail');
    var password = document.getElementById('tbxPassword');

    document.location = secureBase + "/securelogin?o=l&e=" + escape(email.value) + "&p=" + escape(password.value) + "&r=" + redirOk + "&f=" + redirFail + escape("?e=" + email.value) + "&b=" + base + "&s=false&sid=" + sessionId;
}


function UserSignOut(currentBase, NewBase, redirectTo) {
    //$('#UserLogIn').html( "<img alt='loading...' src='/imgs/progress.gif'  />");
    document.location = currentBase + '/securelogin?o=p&b=' + NewBase + '&r=' + redirectTo;
}


function UpdateUserLogIn() {

    $.ajax({
        url: "/Store/Services/StoreService.asmx/LoadLoginControl",
        data: "{}",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (res) {
            OnUserLogInUpdated(res.d);
        }
    });
}


function OnUserLogInUpdated(result) {
    if (result == null)
        return;
    if (document.getElementById('HomeUserLogIn') != null) {
        if (result.Display)
            document.getElementById('HomeUserLogIn').style.display = "none";
        else
            document.getElementById('HomeUserLogIn').style.display = "block";
    }
    if (document.getElementById('UserLogIn') != null) {
        if (result.Control == null)
            document.getElementById('UserLogIn').style.display = "none";
        else {
            document.getElementById('UserLogIn').style.display = "block";
            $('#UserLogIn').html(unescape(result.Control));
        }


    }
}

function AddGallPhotos(Product_ID) {

    if ($('#GallPhotos').html() == '') {
        $('#GallPhotos').html("<img alt='loading...' src='/imgs/progress.gif' />");
        $.ajax({
            url: "/Store/Services/TabsProduct.asmx/AddTabsGaleryProduct",
            data: $.toJSON({ productID: Product_ID }),
            success: function (res) { OnTabUpdated(res.d); }
        });
    }

}

function OnTabUpdated(result) {
    $('#GallPhotos').html(unescape(result));
}


function OnTabSimilarUpdated(result) {
    $('#SimilarProduct').html(unescape(result));
}

var similarProductsLoaded = false;
function AddSimilarProduct(Product_ID) {
    if (similarProductsLoaded) return;

    $('#SimilarProduct').html("<img alt='loading...' src='/imgs/progress.gif'  />");
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/AddTabsSimilarProduct",
        data: $.toJSON({ productID: Product_ID }),
        success: function (res) { OnTabSimilarUpdated(res.d); }
    });
    similarProductsLoaded = true;
}

var accessorProductsLoaded = false;
function AddAccessorProduct(Product_ID, productcampaign) {
    if (accessorProductsLoaded) return;

    accessorProductsLoaded = true;
    $('#AccessorProduct').html("<img alt='loading...' src='/imgs/progress.gif'  />");
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/AddTabsAccessorProduct",
        data: $.toJSON({ productID: Product_ID, productcampaign: productcampaign }),
        success: function (res) { OnTabAccessorUpdated(res.d); }
    });

}


function OnTabAccessorUpdated(result) {
    $('#AccessorProduct').html(unescape(result));
}


function PromoBlock(orderInList, OrderPromo, divfin) {
    this.orderInList = orderInList;
    this.OrderPromo = OrderPromo;
    this.divfin = divfin;
}

var arraypromoblock = new Array(24);
var orderInListPromo, OrderPromoPromo;


function AddPromoBlock(OrderPromo, Product_ID, orderInList, description, teaser, div) {

    if (superruperpromobool) {
        divpromo = div;
        orderInListPromo = orderInList;
        OrderPromoPromo = OrderPromo;


        var elem = orderInListPromo * 4 - OrderPromoPromo;

        if (arraypromoblock[elem] != null) {
            $('#' + divpromo).html(arraypromoblock[elem].divfin);
        }
        else {

            superruperpromobool = false;
            $('#' + divpromo).html("<br/><img alt='loading...' src='/imgs/progress.gif'  />");
            $.ajax({
                url: "/Store/Services/HomePage.asmx/AddPromoBlock",
                data: $.toJSON({
                    productID: Product_ID,
                    orderInList: orderInList,
                    description: escape(description),
                    teaser: teaser
                }),
                success: function (res) { OnPromoBlockUpdated(unescape(res.d)); }
            });
        }

    }

}

function OnPromoBlockUpdated(result) {
    if (!superruperpromobool) {
        superruperpromobool = true;
        $('#' + divpromo).html(result);
        var elem = orderInListPromo * 4 - OrderPromoPromo;
        arraypromoblock[elem] = new PromoBlock(orderInListPromo, OrderPromoPromo, result)
    }
}

function AddRubricPromoBlock(OrderPromo, Product_ID, orderInList, div) {

    if (superruperpromobool) {

        divpromo = div;
        orderInListPromo = orderInList;
        OrderPromoPromo = OrderPromo;

        var elem = orderInListPromo * 4 - OrderPromoPromo;

        if (arraypromoblock[elem] != null) {
            $('#' + divpromo).html(arraypromoblock[elem].divfin);
        }
        else {

            superruperpromobool = false;
            $('#' + divpromo).html("<br/><img alt='loading...' src='/imgs/progress.gif'  />");

            $.ajax({
                url: "/Store/Services/HomePage.asmx/AddRubricPromoBlock",
                data: $.toJSON({
                    productID: Product_ID,
                    orderInList: orderInList
                }),
                success: function (res) { OnRubricPromoBlockUpdated(unescape(res.d)); }
            });

        }
    }

}



function OnRubricPromoBlockUpdated(result) {
    if (!superruperpromobool) {
        superruperpromobool = true;
        $('#' + divpromo).html(result);
        var elem = orderInListPromo * 4 - OrderPromoPromo;
        arraypromoblock[elem] = new PromoBlock(orderInListPromo, OrderPromoPromo, result)
    }
}

////////////////////////////Comparar





function compareProducts(compare, Compare_Alert, Compare_5Alert) {
    var productparams = "?id=";
    var condicion = "";
    var separator = "";

    var boxValues = [];
    var boxes = $('input:checkbox[name=compareBox]');
    for (var i = 0; i < boxes.length; i++) {
        if ($(boxes[i]).is(':checked'))
            boxValues.push($(boxes[i]).val());
    }


    productparams += boxValues.join("%2C");

    if (boxValues.length < 2)
        alert(Compare_Alert);
    else if (boxValues.length > 5)
        alert(Compare_5Alert);
    else
        document.location.href = compare + productparams;
}


function subscriptionFailed() {
    $('#mailcatalog').css("backgroundColor", "red").focus();
    $('#emailerror').show();
    $('#emailresult').hide();
}
function subscriptionSucceded() {
    $('#mailcatalog').css("backgroundColor", "white");
    $('#emailerror').hide();
    $('#emailresult').show();
    pageTracker._trackEvent('Home page', 'Newsletter subscription');
}
function isEmail(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return filter.test(email);
}
var newsHidden = true;
function newsToggle() {
    if (newsHidden)
        newsPopupOpen();
    else
        newsPopupClose();
}

function newsPopupSetup() {
	var code = getQueryString("promo");
	if (code == null) code = '';
	$.ajax({
		url: '/Store/Services/StoreService.asmx/GetPromoHtml',
		data: $.toJSON({ code: code }),
		success: function (res) {
			$('#newsPopupCont').html(unescape(res.d.html));
			if (screen.width > 1024) {
				$('#newsPopup').show();
				if (res.d.autoshow)
					newsShowPromo();
			}
		},
		fail: function () { $('#newserror').show(); }
	});
}

function newsShowPromo() {
	newsPopupOpen();
	window.setTimeout(function () {
		$('#newsPopup').fadeOut(200).fadeIn(200, function () {
			window.setTimeout(function () { newsPopupClose(); }, 3000);
		});
	}, 1000);

}

function newsPopupOpen() {
	
    $('#newsPopup').animate({ left: '-240px' }, 200, function () {
        $('#newsPopup .promoPopup').show();
        $('#newsPopup').animate({ left: '0px' }, 700);
       });
    newsHidden = false;
   }

function newsPopupClose() {
    $('#newsPopup').animate({ left: '-240px' }, 1000, function () {
        $('#newsPopup .promoPopup').hide();
        $('#newsPopup').animate({ left: '-220px' }, 200, function () {
            $('#newsresult').hide();
            $('#newserror').hide();
        });
    });
    newsHidden = true;

}
function newsSubscribe() {
    var email = $('#newsSubscribe').val();
    if (!isEmail(email))
        $('#newserror').show();
    else {
        $.ajax({
            url: '/Store/Services/HomePage.asmx/AddNewsLetter',
            data: $.toJSON({ txtmail: email }),
            success: function () {
                $('#newserror').fadeOut(300);
                $('#newsresult').fadeIn(500, function () {
                    window.setTimeout(function () { newsToggle(); }, 700);
                })

            },
            fail: function () { $('#newserror').show(); }
        });
    }
}
function ShowTab(id1, id2, count, order) {
    switchLayer(id1, count, order);
    switchId(id2, count, order);
}
function ShowHomeTab(count, order) {
    ShowTab('mask_contener', 'tabsid', count, order);
    pageTracker._trackEvent('Home page', 'home page tabs', 'tab ' + order);
}

function ShowProductMediaTab(count, order) {
    ShowTab('media', 'detail_tab', count, order);
    pageTracker._trackEvent('Product page', 'product page rich content tabs', 'tab ' + order);
}
function ShowProductTab(order) {
    $(document).ready(function () {
        ShowTab('detail', 'tabsid', 9, order);
        pageTracker._trackEvent('Product page', 'product page navigation tabs', 'tab ' + order);
    });
    $.scrollTo('div.fiche_tabs', 400);
    document.location.href = '#tab' + order;
}

function ShowReviews() {
    ShowProductTab(8);
}

function ShowAnchoredProductTab() {
    var url = document.location.toString();
    if (url.match('#')) { // the URL contains an anchor
        // click the navigation item corresponding to the anchor
        var i = url.split('#')[1].substring(3);
        ShowProductTab(i);
    }
}

function showDiscounts(count, order) {
    switchLayer('diapo_qte', count, order);
    pageTracker._trackEvent('global', 'quantity', 'show');
}


function popupNewWindow(url) {
    window.open(url, '_blank', 'width=300, height=300, toolbar=0, location=0, directories=0, status=0, scrollbars=0', resizable = 'no', 'copyhistory=0, menuBar=0');
    return false;
}


//////////////////////////////////////////////////////// COD  CHAT /////////////////////////////////////////////////////////



var wv_vars = typeof (wv_vars) == "undefined" ? new Array() : wv_vars; wv_vars["ui_width"] = "430"; wv_vars["ui_height"] = "378"; wv_vars["ui_version"] = "UI0001"; wv_vars["ui_newwindow"] = "yes"; wv_vars["ui_accountid"] = "200106291793"; wv_vars["ui_host"] = "as00.estara.com"; wv_vars["ui_maxreferrer"] = 350; wv_vars["ui_window"] = null; wv_vars["ui_host_param"] = ""; if (typeof (eStara_startCobrowseGUINoFunc) == "undefined") { var eStara_startCobrowseGUINoFunc = 0; } wv_vars["ui_window"] = null; function webCall() { if (wv_vars["ui_window"] == null || wv_vars["ui_window"].closed) { var _1 = arguments; _1[_1.length++] = "calltype=webcall"; wv_vars["ui_window"] = wv_start(_1); } } function webCallBack() { var _2 = arguments; _2[_2.length++] = "calltype=webcallback"; wv_vars["ui_window"] = wv_start(_2); } function webVoicePop() { var _3 = arguments; _3[_3.length++] = "calltype=webvoicepop"; wv_start(_3); } function webSurveyPop() { var _4 = arguments; _4[_4.length++] = "calltype=websurveypop"; var _5 = wv_vars["ui_width"]; var _6 = wv_vars["ui_height"]; wv_vars["ui_width"] = 640; wv_vars["ui_height"] = 480; wv_vars["upload_only"] = 1; wv_start(_4); wv_vars["ui_width"] = _5; wv_vars["ui_height"] = _6; } function wv_checklinkstatus() { var _7 = "0"; for (var i = 0; i < arguments.length; i++) { var _9 = arguments[i].toString(); var _a = _9.indexOf("="); if (_a != -1) { var _b = (_9.substring(0, _a)).toLowerCase(); var _c = _9.substring(_a + 1, _9.length); switch (_b) { case "template": _7 = _c; break; } } } if ((typeof (wv_available_vars) != "undefined") && (typeof (wv_available_vars[_7]) != "undefined")) { return wv_available_vars[_7]; } else { return false; } } function wv_start(a) { var _e = navigator.userAgent.indexOf("MSIE") != -1; var _f = "webVoiceWindow"; if (_e) { _f = "_blank"; } var _10 = (window.location).toString(); var _11 = escape(_10); if (_11.length > wv_vars["ui_maxreferrer"]) { var _12 = _10.indexOf("?"); _10 = _12 > 0 ? _10.substring(0, _12) + "---TRUNCATED" : "UNAVAILABLE - URL IS TOO LONG"; _11 = escape(_10); if (_11.length > wv_vars["ui_maxreferrer"]) { _10 = "UNAVAILABLE - URL IS TOO LONG"; } } var _13 = typeof (document.title) != "undefined" ? document.title : "UNKNOWN"; if (escape(_13).toString().length > 255) { _13 = (document.title).toString().substring(0, 243) + "---TRUNCATED"; } var _14 = escape(_13); if (_14.length > 350) { _13 = "UNAVAILABLE - TITLE IS TOO LONG"; } var _15 = wv_vars["ui_newwindow"]; var _16 = wv_vars["ui_width"]; var _17 = wv_vars["ui_height"]; var _18 = wv_vars["ui_version"]; var _19 = wv_vars["ui_accountid"]; var _1a = ""; var _1b = ""; var _1c = ""; var _1d = ""; var _1e = (typeof (document.location.protocol) != "undefined" && document.location.protocol == "file:") ? "http" : ""; for (var i = 0; i < a.length; i++) { var _20 = a[i].toString(); var _21 = _20.indexOf("="); if (_21 != -1) { var _22 = (_20.substring(0, _21)).toLowerCase(); var _23 = _20.substring(_21 + 1, _20.length); switch (_22) { case "wndname": _f = _23; break; case "referrer": _10 = _23; break; case "pagetitle": _13 = _23; break; case "newwindow": _15 = _23; break; case "width": _16 = _23; break; case "height": _17 = _23; break; case "accountid": _19 = _23; break; case "wv_ui": _18 = _23; break; case "features": _1a = _23; break; case "baseurl": _1b = _23; break; case "protocol": _1e = _23; break; case "template": _1c = _23; _1d += "&" + _22 + "=" + escape(_23); break; case "ppwinname": if (_23 == "") { _23 = "PagePushWindow" + (new Date()).getTime() + Math.round(Math.random() * 1000000); this.name = _23; } default: _1d += "&" + _22 + "=" + escape(_23); break; } } else { alert("ERROR: Invalid argument passed to webXXX() function - Arg" + i + " is missing '=' sign : " + _20); return null; } } if (typeof (eStara_startCobrowseGUI) == "function") { eStara_startCobrowseGUI((wv_vars["upload_only"] == 1), _1c); } else { eStara_startCobrowseGUINoFunc = _1c; } for (var i = 1; i <= 10; i++) { eval("var eStara_assigned=(typeof(eStara_var" + i + ")!=\"undefined\"&&eStara_var" + i + "!=null)"); if (eStara_assigned) { eval("var eStara_tmp=\"&var" + i + "=\"+escape(eStara_var" + i + ");"); _1d += eStara_tmp; } } if (typeof (eStara_fsguid) != "undefined") { _1d += "&estara_fsguid=" + escape(eStara_fsguid); } if (_1e != "") { _1e += ":"; } if (_1b == "") { _1b = _1e + "//" + wv_vars["ui_host"] + "/UI/" + _18 + "/" + _18 + ".php"; } if (_1a == "") { _1a = "width=" + _16 + ",height=" + _17 + ",menubar=no,toolbar=no,directories=no,scrollbars=no,status=no,left=0,top=0,resizable=no"; } _1d = _1b + (_1b.indexOf("?") == -1 ? "?" : "&") + "donotcache=" + escape((new Date()).getTime()) + "&accountid=" + escape(_19) + "&referrer=" + escape(_10) + "&pagetitle=" + escape(_13) + wv_vars["ui_host_param"] + _1d; if ((typeof (wv_customurl) != "undefined") && (typeof (wv_customurl[_1c]) != "undefined") && (wv_customurl[_1c] != "")) { _1d = wv_customurl[_1c]; } if ((typeof (wv_customfeatures) != "undefined") && (typeof (wv_customfeatures[_1c]) != "undefined") && (wv_customfeatures[_1c] != "")) { _1a = wv_customfeatures[_1c]; } if (_15 != "yes") { window.location = _1d; } else { try { return window.open(_1d, _f, _1a); } catch (err) { } } return null; } function webChatPop() { var wv_argscopy = arguments; wv_argscopy[wv_argscopy.length++] = "wndname=eStaraChat_200106291793"; wv_argscopy[wv_argscopy.length++] = "calltype=webchatpop"; var prev_ui_width = wv_vars["ui_width"]; var prev_ui_height = wv_vars["ui_height"]; wv_vars["ui_width"] = 500; wv_vars["ui_height"] = 500; wv_start(wv_argscopy); wv_vars["ui_width"] = prev_ui_width; wv_vars["ui_height"] = prev_ui_height; }

function showVideo(type, file, url) {
    alert("type:" + type + ",file:" + file + ",url:" + url);
    if (type == 1) {
        switchId('detail_tab', 4, 2);
        switchLayer('media', 4, 2);
    } else {
        alert('open popup');
    }
}


function isFlash() {
    var shock = false;
    for (i = 0; i < navigator.mimeTypes.length; i++) {
        if (navigator.mimeTypes[i].type == "application/x-shockwave-flash")
            shock = true;
    }
    return shock;
}

function switchLink(nameOfId, numNumber, numOfEx) {
    for (i = 1; i < numNumber + 1; i++) {
        if (i != numOfEx) {
            if (document.getElementById(nameOfId + "_" + i) != null)
                document.getElementById(nameOfId + "_" + i).style.color = 'black';

        } else {
            if (document.getElementById(nameOfId + "_" + i) != null)
                document.getElementById(nameOfId + "_" + i).style.color = "red";

        }
    }

}


function list_openRubricIndexLinks() {
    tr_name = document.getElementById("indexlinksresult").style;

    if (tr_name.display == "none") {

        $('#indexlinksresult').html($('#indexlinkscontent').html());
        tr_name.display = "";

    } else {
        tr_name.display = "none";
    }
}


function showZoomLayer(param) {
    $('#opac_text > div').hide()
    $('.opac_close').show();
    $('#' + param).show();
    openLayer('opac_layer');
    openLayer('opac_text');
    dimensionLayer('opac_text');

}

function showZoomLayerCampaigns(param) {
    document.getElementById('LinkParam').href = param;
    openLayer('opac_layer_campaign');
    openLayer('opac_text_campaign');
    dimensionLayerCampaigns('opac_text_campaign');
}

function showZoomLayerCampaignsBasket() {
    openLayer('opac_layer_campaign_basket');
    openLayer('opac_text_campaign_basket');
    dimensionLayerCampaigns('opac_text_campaign_basket');

}

function dimensionLayerCampaigns(nLay) {

    $(document).ready(function () {

        $('#opac_layer_campaign').css({ left: 0 });
        $('#opac_layer_campaign').animate({ opacity: 0.5 }, 0);

        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var windowScroolTop = $(window).scrollTop();
        var divWidth = $('#' + nLay).width();
        var divHeight = $('#' + nLay).height();

        //		alert('windowWidth:'+windowWidth+' windowHeight:'+windowHeight+' windowScroolTop:'+windowScroolTop);

        var totalWidth = windowWidth / 2 - divWidth / 2;
        var totalHeight = windowHeight / 2 - divHeight / 2 + windowScroolTop;


        $('#' + nLay).css({ 'margin-left': totalWidth });
        $('#' + nLay).css({ 'margin-top': totalHeight });

        $('#opac_layer_campaign').width($(document).width());
        $('#opac_layer_campaign').height($(document).height());


    });
}

//------------------------------------------------
//Begin Couponing

function showZoomLayerCouponing(couponingType) {

    openLayer('opac_layer_couponing');
    openLayer('opac_text_couponing');

    BuildIFrame(couponingType);
    CustomizeZoomLayerSize();
}

function BuildIFrame(couponingType) {

    var indexParams = couponingType.indexOf('?');
    var couponingLib;

    if (indexParams > 0)
        couponingLib = couponingType.substring(0, indexParams);
    else
        couponingLib = couponingType;

    var width;
    var height;

    switch (couponingLib.toUpperCase()) {
        case 'ADDPEPPER':
            width = 680; height = 580;
            break;
        case 'FREEQUOTE':
            width = 680; height = 620;
            break;
        case 'FREETRY':
            width = 680; height = 500;
            break;
        case 'TELECONFERENCE':
            width = 680; height = 470;
            break;
        case 'UNIFIEDCOMMUNICATIONS':
            width = 680; height = 620;
            break;
        case 'VOIP':
            width = 680; height = 470;
            break;
        case 'VOZTELECOM':
            width = 680; height = 500;
            break;
    }

    $('#iframeCouponing').attr({
        src: ('/Couponing/' + couponingType),
        width: (width + 'px'),
        height: (height + 'px')
    });
}

function CustomizeZoomLayerSize() {

    $(document).ready(function () {

        $('#opac_layer_couponing').css({ left: 0 });
        $('#opac_layer_couponing').animate({ opacity: 0.5 }, 0);

        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var windowScroolTop = $(window).scrollTop();

        var divWidth = $('#opac_text_couponing').width();
        var divHeight = $('#opac_text_couponing').height();

        var totalWidth = windowWidth / 2 - divWidth / 2;
        var totalHeight = windowHeight / 2 - divHeight / 2 + windowScroolTop;

        $('#opac_text_couponing').css({ 'margin-left': totalWidth });
        $('#opac_text_couponing').css({ 'margin-top': totalHeight });

        $('#opac_layer_couponing').width($(document).width());
        $('#opac_layer_couponing').height($(document).height());
    });
}

//End Couponing
//------------------------------------------------


function closehomebaner() {
    document.getElementById('TRHomeBanner').style.display = "none";
}

var bannertimer = null;
function setBannerHomeTime() {
    if (bannertimer == null)
        bannertimer = setTimeout('LoadHomeBanner()', 2500);
}

function LoadHomeBanner() {
    document.getElementById('DivBannerHome').style.display = "block";
    document.getElementById('imgClose').style.display = "block";
}

function GoToFilterResult(urlresult) {
    if (urlresult != null)
        window.location.href = urlresult;
}

function AddProductMessage(coments, worker, product, SKU, idTema, fileHash) {
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/AddProductMessage",
        data: $.toJSON({
            coments: coments,
            worker: worker,
            product: product,
            SKU: SKU,
            idTema: idTema,
            fileHash: fileHash
        }),
        async: false
    });
}

function SendProductMail(from, to, subject, body, fileHash) {
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/SendProductMail",
        data: $.toJSON({
            from: from,
            to: to,
            subject: subject,
            body: body,
            fileHash: fileHash
        }),
        async: false
    });
}

function DeleteProductMessage(idPk) {
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/DeleteProductMessage",
        data: $.toJSON({
            idPk: idPk
        }),
        async: false
    });
}

function GetProductMessages(SKU) {
    $('#ChatMesseges').html("<img alt='loading...' src='/imgs/progress.gif'  />");
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/GetProductMessages",
        data: $.toJSON({ reference: SKU }),
        success: function (res) { OnChatMessegesUpdated(res.d); }
    });
}

function OnChatMessegesUpdated(result) {
    $('#ChatMesseges').html(unescape(result.html));
    if (result.count > 0)
        $('#chat_table').tablesorter({ widgets: ['zebra'] });
}

function AddOnedirectTab(id, sku) {
    $.ajax({
        url: "/Store/Services/TabsProduct.asmx/GetOnedirectTab",
        data: $.toJSON({ reference: sku, id: id }),
        success: function (res) {
            if (res.d == null) {
                $('#tabsid_9').hide();
                return;
            }
            $('#tabsid_9').show();
            $('#tabsid_9_a').text(res.d);

            InitUploader();
            GetProductMessages(sku);
        }
    });

}

function InitUploader() {
    var upload = $('#upload');
    upload.uploadify({
        'uploader': '/imgs/uploadify.swf',
        'script': '/store/uploads/uploadify.ashx',
        'cancelImg': '/imgs/cancel.png',
        'buttonImg': '/imgs/browse.png',
        'buttonText': 'Attach file...',
        'queueID': 'uploadQueue',
        'multi': false,
        'wmode': 'transparent',
        'width': ($.browser.msie ? "94px" : "'94px'"),
        'height': ($.browser.msie ? "22px" : "'22px'"),
        onComplete: function (event, queueID, fileObj, response, data) {
            $('#customQueue').hide();
            PostMessage(response);
        },
        onCancel: function () {
            $('#customQueue').hide();
        },
        onSelect: function (event, queueID, fileObj) {
            $('#fileName').html(fileObj.name);
            $('#customQueue').show();
        }

    });
}


function DeleteMessage(idPk) {
    DeleteProductMessage(idPk);
    GetProductMessages('<%= SKU %>');
}

function watermark(name, text) {
    var watermark = text;
    if ($(name).val() == "") {
        $(name).val(watermark);
    }
    $(name).focus(function () {
        if (this.value == watermark) {
            this.value = "";
        }
    }).blur(function () {
        if (this.value == "") {
            this.value = watermark;
        }
    });
}
  