﻿//open more filter options0
function OpenMoreFilter(id) {
    Close_Popup();
    $('#' + id + '').css({ display: "block" });
}

$(document).ready(function () {
    if ($.browser.msie) {
        if (Number($.browser.version) < 7) {
            document.getElementById('modal').style.display = 'block';
            document.getElementById('fade').style.display = 'block';
        }
    }

    var e = document.getElementById("refreshed");
    if (e.value == "no") e.value = "yes";
    else { e.value = "no"; location.reload(); }

    $('.AddThis').show();


    $(".phones").click(function () {
        $(".phonesMoreLink").toggle("fast");
        $(this).toggleClass("show");
        $(this).toggleClass("open");
    });

    $(".notebooks").click(function () {
        $(".notebooksMoreLink").toggle("fast");
        $(this).toggleClass("show");
        $(this).toggleClass("open");
    });

    $(".accessories").click(function () {
        $(".accessoriesMoreLink").toggle("fast");
        $(this).toggleClass("show");
        $(this).toggleClass("open");
    });

    $(".gadgets").click(function () {
        $(".gadgetsMoreLink").toggle("fast");
        $(this).toggleClass("show");
        $(this).toggleClass("open");
    });



    $("div.payment2Button input").mouseover(function () {
        $("div.payment2Button input").attr("src", "../images/paymentButtonHover.png");
    });

    $("div.payment2Button input").mouseout(function () {
        $("div.payment2Button input").attr("src", "../images/paymentButton_old.png");
    });

    $("div.sendContactUs2 input").mouseover(function () {
        $("div.sendContactUs2 input").attr("src", "../images/submitButtonHover.png");
    });

    $("div.sendContactUs2 input").mouseout(function () {
        $("div.sendContactUs2 input").attr("src", "../images/submitButton_old.png");
    });




    //Exp Popup - Start

    $(".expBoxCenter a.expressBuy").mouseover(function () {
        $(".expPopup").css({ display: "block" });
    });

    $(".expBoxCenter a.expressBuy").mouseout(function () {
        $(".expPopup").css({ display: "none" });
    });


    $(".expBoxCenter2 a.expressBuy").mouseover(function () {
        $(".expPopup2").css({ display: "block" });
    });

    $(".expBoxCenter2 a.expressBuy").mouseout(function () {
        $(".expPopup2").css({ display: "none" });
    });

    // Exp Popup - End


    // Start - Market Popup

    $(".marketPopup").mouseover(function () {
        $(".marktingPopup").css({ display: "block" });
    });

    $(".marketPopup").mouseout(function () {
        $(".marktingPopup").css({ display: "none" });
    });

    $(".marketPopup2").mouseover(function () {
        $(".marktingPopup2").css({ display: "block" });
    });

    $(".marketPopup2").mouseout(function () {
        $(".marktingPopup2").css({ display: "none" });
    });

    // End - Market Popup




    //Popup

    $(".morePicItem a").click(function () {
        $(".popupPics").css({ display: "block" });
    });

    //Default Action
    $(".tab_content_popup").hide(); //Hide all content
    $("ul.tabs_popup li:first a").addClass("active").show(); //Activate first tab
    $(".tab_content_popup:first").show(); //Show first tab content

    //On MouseOver Event


    $("ul.tabs_popup li a").mouseover(function () {

        $("ul.tabs_popup li a").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content_popup").hide(); //Hide all tab content
        var activeTab = $(this).attr("rel"); //Find the rel attribute value to identify the active tab + content         
        $(activeTab).show(); //Fade in the active content, U can also change the: fadeIn() to show()
        return false;
    });

    //End Popup 

});


//Popup

function Close_PopupError() {
    $('.ErrorPopup').fadeOut('slow');
}

function Show_Popup(action, userid) {
    $('#popup').css('opacity', 0.20).fadeIn('fast');
    $('#window').fadeIn('fast');
}
function Close_PopupA() {
    $('#ErrorPopup').fadeOut('fast');
  //  $('#window').fadeOut('fast');
}
function Close_PopupB() {
    $('#ErrorPopup').fadeOut('fast');
   // $('#window').fadeOut('fast');
}

function Close_PopupImg() {
    $('.popupPics').css({ display: "none" });
}

function Close_Popup() {
    $('.morePopup').css({ display: "none" });
}



function AddUpgrad(obj, productId) {
    var itemPrice = $('#UpgradingPrice' + productId)[0].value;
    itemPrice = (itemPrice * 1)
    var total = $('#lblTotalUpgrading').html();
    total =Number(total);

    if (obj.checked) {
        $('#txtAdditionProducts')[0].value = $('#txtAdditionProducts')[0].value + "," + productId + ",";
        //$('#lblTotalUpgrading').html()
        total = total + Number(itemPrice);
        $('#lblTotalUpgrading').html(total.toFixed(2));
    }
    else {
        $('#txtAdditionProducts')[0].value = $('#txtAdditionProducts')[0].value.replace("," + productId + ",", "");
        total = (total * 1);
        total = total - Number(itemPrice);
        $('#lblTotalUpgrading').html(total.toFixed(2));
    }
    var sum = total + Number($('#productBasePrice')[0].value);
    sum = Number(sum)
    $('#total').html(sum.toFixed(2))
    $('#total2').html(sum.toFixed(2))


}


//Remove From Basket - Start
/*
$(document).ready(function() {
    $(".remove .move").click(function() {
        RemoveProduct(this);
    });
});
*/

function RemoveProduct(obj) {
    var answer = confirm("מוצר זה יוסר מסל הקניות");
    
    if (answer) {

        var productId = $(obj).parents(".remove").attr('rel');
        var url = siteUrl + "Handlers/RemoveFromBasket.ashx?" +
                 "productId=" + productId;


        var result = $.ajax({
            url: url,
            async: false
        }).responseText;
        var price = result.split("#")[0];
        if (price != "0")////remove  succeed--return is the price of the product
        {
            UpdateTopMenuBasketItems(totalItemInBasket, totalItemInBasket-1);
            totalItemInBasket--;            
            $(obj).parents(".remove").animate({ opacity: "hide" }, "fast");
            //update price
            var total = $('#lblBasketPrice').text();
            var removePrice = price;
             
            var newTotal = Number(total) - Number(removePrice)
            newTotal = newTotal.toFixed(2);
            newTotal = newTotal.replace(".00", "")
            $('#lblBasketPrice').html(newTotal)
            if (newTotal == 0) {
                $('#divBasketItem').hide();
                $('#divNoBasketItem').show();
            }

            RemoveProduct_WebTrend();

            var productFullName = result.split("#")[1];
            
            _gaq.push(['_trackEvent', 'Shopping Cart', 'Remove From Cart', productFullName, 1]);
            
        }
    }
}

function RemoveProduct_WebTrend() {
    if (webTrendsActive=="1")
        dcsMultiTrack('DCS.dcsuri', window.location, 'WT.ti', 'Product was deleted from cart', 'WT.tx_e', 'r');
}

function ContinueOrder_WebTrend() {
    if (webTrendsActive == "1")
        dcsMultiTrack('DCS.dcsuri', window.location, 'WT.ti', 'Checkout was started', 'WT.tx_e', 'r');
}

function Pay_WebTrend(totalPrice) {
    if (webTrendsActive == "1")
        dcsMultiTrack('DCS.dcsuri', window.location, 'WT.ti', 'Checkout was started', 'WT.si_n', 'checkout', 'WT.si_x', '2', 'WT.tx_e', 'p', 'WT.tx_s', $('#totalPrice').text());
}

                        
//Remove From Basket - End
function ExpressBuy(id, url) {
    AddExpressProduct(id, url);
}

function AddExpressProduct(productId, redirectUrl) {
    var productsIdproductId = productId + "," + $('#txtAdditionProducts')[0].value;
    var url = siteUrl + "Handlers/AddToBasket.ashx?" +
                 "products=" + productsIdproductId +
                 "&campaignBId=" + campaignBId;

    $.getJSON(url,
        function (data) {

            $.each(data.TABLE[0].ROWS, function (i, item) {

                var pId = item.id;
                var price = item.price * 1;

                if (webTrendsActive == "1")
                    AddToBasket_WebTrend();

                var productFullName = item.Alias;  //"'" + item.Manufacturer + " " + item.Model + "'";
                

                _gaq.push(['_trackEvent', 'Express', 'Started', productFullName, 1]);

            });

            window.location = redirectUrl;
        });


        
        

}

function AddToBasket(productId) {
    //debugger;
     
    var productsIdproductId = productId + "," + $('#txtAdditionProducts')[0].value;
    var url = siteUrl + "Handlers/AddToBasket.ashx?" +
                 "products=" + productsIdproductId +
                 "&campaignBId=" + campaignBId;
     
    var total = $('#lblBasketPrice').text();
    total = Number(total);





    //window.open(url);
    $.getJSON(url,
        function (data) {
        

            $.each(data.TABLE[0].ROWS, function (i, item) {

                var pId = item.id;
                var price = item.price * 1;
                //  alert("pId" + pId);
                //                alert("price" + price);
                total = total + Number(price);

                var thHtml = '<tr style="font-weight: bold;" class="remove" rel="' + pId + '"><td>1</td>' +
                '<td  style="width:112px">' + item.name + '</td>' +
                '<td class="ltr"><nobr>₪ ' + item.price + '</nobr></td>' +
                '<td><a class="move" onclick="RemoveProduct(this)" >הסר</a></td></tr>';

                $('#tblBasket tr:last').after(thHtml);
                UpdateTopMenuBasketItems(totalItemInBasket, totalItemInBasket + 1);
                totalItemInBasket++;

                if (webTrendsActive == "1")
                    AddToBasket_WebTrend();



                var productFullName = item.Alias;  //"'" + item.Manufacturer + " " + item.Model + "'";

                _gaq.push(['_trackEvent', 'Shopping Cart', 'Add To Cart', productFullName, 1]);



            });



            if (total > 0) {
                if (total.toFixed(2) > 0)
                    $('#lblBasketPrice').html(total.toFixed(2));
                else
                    $('#lblBasketPrice').html(total);

                $('#divNoBasketItem').hide();
                $('#divBasketItem').show();
            }


            setTimeout("$('.remove').css('font-weight','normal')", 2000);


        });

        

        

}

//var total = $('#lblBasketPrice').html();
//total = total * 1;

//personalization

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function setCookie(c_name, value, expiredays, expireMinutes) {

    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    var toalMinutes = new Date().getMinutes() + expireMinutes
    exdate.setMinutes(toalMinutes);
    document.cookie = c_name + "=" + escape(value) +
((expiredays == null) ? "" : ";path=/;expires=" + exdate.toGMTString());
}

if (nsid == 89) //product page
{
    
    var p1 = getCookie("product1");
    var p2 = getCookie("product2");
    var p3 = getCookie("product3");
    var p4 = getCookie("product4");
    if (p1 != objid && p2 != objid &&
        p3 != objid && p4 != objid && objid > 0)//not already in the cookie and not an additinal product
    {
        p4 = p3;
        p3 = p2;
        p2 = p1;
        p1 = objid;
     
        setCookie("product1",p1, 100, 100);
        setCookie("product2", p2, 100, 100);
        setCookie("product3", p3, 100, 100);
        setCookie("product4", p4, 100, 100);  
    }
    
}
//end personalization


function UpdateTopMenuBasketItems(oldAmount,newAmount) {
    var text = $('#basketTopMenuLink').html();
    text = text.replace(oldAmount, newAmount);
    $('#basketTopMenuLink').html(text);
}

function imposeMaxLength(Object, MaxLen) {
    return (Object.value.length <= MaxLen);
}



function SearchProducts() {
    var sc = $('#sc')[0].value;
    if (sc.length < 1) {
        alert("לא הוזן ערך לחיפוש")
    }
    else {
        var url = siteUrl + 'SearchResults/' ;                  
        url = url + urlSuffix;         
        url = url + "?sc=" + escape(sc)

        window.location=url ;
         
    }
}



