﻿var OdarimPath = "";

var ShownImagesHash = new Object ();

function ShowImage(item) {
    document.getElementById(item).style.display = "";
    HideAllShownImages1();
    ShownImagesHash [item] = "1";
}

function HideImage(item) {
    document.getElementById(item).style.display = "none";
    ShownImagesHash[item] = "0";
    HideAllShownImages1();
}

function HideAllShownImages1() {
    for (var item in ShownImagesHash) {
        if (ShownImagesHash[item] == "1") {
            document.getElementById(item).style.display = "none";
            ShownImagesHash[item] = "0";
        }
    }
}

function PopupProduct(ProductID) {
    window.open (OdarimPath + "/product.aspx?popup=1&id=" + ProductID, "ProductPopup" + ProductID, "toolbar=no,scrollbars=yes,directories=no, status=no,menubar=no,resizable=yes, width=720, height=900");
}

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));
        }
    }

    if (setStr == null)
        setStr = "0";
    
    return (setStr);
}

function BasketAltert(ProductID, sum, cnt, ispm) {
    url = OdarimPath + "/basket/basketalert.aspx?id=" + ProductID;
    if (ispm)
        url = url + "&ispm=1";
        
    window.open(url, "BasketPopup", "toolbar=no,scrollbars=yes,directories=no, status=no,menubar=no,resizable=yes, width=720, height=470");

    var BasketSum = document.getElementById("BasketSum");
    if (BasketSum != null) {
        var sourceSum = parseInt(BasketSum.innerHTML.replace(" ", "").replace(String.fromCharCode(160), "").replace("&nbsp;", ""));
        var newSum = parseInt(sum.replace(" ", "").replace(String.fromCharCode(160), ""));

        BasketSum.innerHTML = sourceSum + newSum;
        if (BasketSum.innerHTML.length >= 4)
            BasketSum.innerHTML = BasketSum.innerHTML.substring(0, BasketSum.innerHTML.length - 3) + "&nbsp;" + BasketSum.innerHTML.substring(BasketSum.innerHTML.length - 3, BasketSum.innerHTML.length);
    }


    var BasketCnt = document.getElementById("BasketCnt");
    if (BasketCnt != null)
        BasketCnt.innerHTML = parseInt(BasketCnt.innerHTML) + parseInt (cnt.replace(" ", ""));
}

function KopilkaAltert(ProductID) {
    window.open(OdarimPath + "/Kopilka/Kopilkaalert.aspx?id=" + ProductID, "KopilkaPopup", "toolbar=no,scrollbars=yes,directories=no, status=no,menubar=no,resizable=yes, width=720, height=440");
}

var ImagesArray = new Array();
var ImageURLsArray = new Array();

function LoadImages() {
    for (i = 0; i < ImagesArray.length; i++) {
        document.getElementById(ImagesArray[i]).src = ImageURLsArray[i];
        ShownImagesHash [ImagesArray[i]] = "0";
    }
}

function OpenPackWin(controlid, buttonid, productid) {
    window.open(OdarimPath + '/selectpack.aspx?controlid=' + controlid + '&catid=411&ispacking=1&productid=' + productid + '&buttonid=' + buttonid, 'Win1' + controlid, 'width=800,toolbar=no,scrollbars=yes,directories=no, status=no,menubar=no,resizable=yes');
}

function SelectPack(controlid, val, buttonid) {
    window.opener.document.getElementById(controlid).value = val;
    window.opener.document.getElementById(buttonid).click();
    window.close();
}

function addBookmark() {
    url = location.href;
    title = document.title;

    //Gecko
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel(title, url, "");
    //IE4+ 
    else if (typeof window.external == "object") window.external.AddFavorite(url, title);
    //Opera7+ 
    else if (window.opera && document.createElement) {
        var a = document.createElement('A');
        if (!a) return false; //IF Opera 6 
        a.setAttribute('rel', 'sidebar');
        a.setAttribute('href', url);
        a.setAttribute('title', title);
        a.click();
    }
    else return false;

    return true;
}

function ShowProduct(TestDivID, ProductID) {
    //$("#" + TestDivID).load("/odarim/product.aspx?popup=1&id=" + ProductID);
    //$("#" + TestDivID).css("style", "");
}

function SendToFriend(ProductID) {
    window.open(OdarimPath + "/sendtofriend.aspx?ProductID=" + ProductID + "&ref=" + escape(document.location.href.replace("popup=1", "").replace("product.aspx", "productbig.aspx")), "SendToFriendPopup", "toolbar=no,scrollbars=yes,directories=no, status=no,menubar=no,resizable=yes, width=500, height=440");
}

function ChangeDeliveryUrgency(ddl, OrderID) {
    var row = $("#PaymentMethodRow" + OrderID).get(0);
    var DeliveryDateSpan1 = $("#DeliveryDateSpan1_" + OrderID).get(0)
    var DeliveryDateSpan2 = $("#DeliveryDateSpan2_" + OrderID).get(0)

    if (ddl.value == "4" || ddl.value == "6" || ddl.value == "5") {
        row.style.display = "none";
        DeliveryDateSpan1.style.display = "none";
        DeliveryDateSpan2.style.display = "none";
    }
    else {
        row.style.display = "";
        DeliveryDateSpan1.style.display = "";
        DeliveryDateSpan2.style.display = "";
    }
}

function SetDeliveryUrgency(ddlID, OrderID) {
    
    var ddl = $("#" + ddlID).get(0);

    ChangeDeliveryUrgency(ddl, OrderID);
}