function OpenBasket()
{
        var h=screen.height-100;
        var tmp=Math.random();
        hand=window.open('/edit_basket.php?tmp='+tmp, "Корзина", 'top=0, left=0, height=500, width=780, status=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes');
        hand.focus();
}

function getCookie(name) {

    var cookieValue = document.cookie;

    var startPos = cookieValue.indexOf(" " + name + "=");

    if (startPos == -1) {

        startPos = cookieValue.indexOf(name + "=");

    }

    if (startPos == -1) {

        return "";

    }

    startPos = cookieValue.indexOf("=", startPos) + 1;

    var endPos = cookieValue.indexOf(";", startPos);

    if (endPos == -1) {

        endPos = cookieValue.length;

    }

    return unescape(cookieValue.substring(startPos, endPos));

}



function setCookie(name, value, path, monthBeforeExpire) {

    value = escape(value);

    var expires = "";

    if (monthBeforeExpire != 0) {

        var nowDate = new Date();

        nowDate.setHours(nowDate.getHours() + 2);

        expires = ";expires=" + nowDate.toGMTString();

    }

    if (path != "") {

        path = ";Path=" + path;

    }

    document.cookie = name + "=" + value + expires + path;

}



function addToBasket(id, color, price) {

    var basket = getCookie('basket');
    var colors = getCookie('colors');
    var len = 0;
    var pos = 0;
    var i = -1;
    var str = new String("");
    var sum = getCookie('sum');
//    var hlp;
//    var cb = ++document.all.cb.value;

//    var spn = document.all.b1;
//    spn.innerHTML = 'Товаров в корзине: '+cb+'.';
//    if (cb == 1) document.all.b2.style.display = '';

    if (basket != "") {
     basket = basket+'X'+id;
    }else{
     basket = id;
    }
    if (colors != "") {
     colors = colors+'X'+color;
    }else{
     colors = color;
    }
   if (sum == '') {sum = '0'};
   numsum = parseFloat(sum) + price;
// send result cookies...
    setCookie("basket", basket, "", 1);
    setCookie("colors", colors, "", 1);
    setCookie("sum", numsum, "", 1);
    str += basket;
    while (pos != -1) {
            pos = str.indexOf("X", i+1);
            len += 1;
            i = pos;
    }
    if (basket == ''){document.getElementById("ofor").style.display = 'none';}else{document.getElementById("ofor").style.display = '';}
    document.all.trash.innerHTML = '<td class="copyright1" id="trash">товаров в корзине: <b>'+len+'</b></td>';    document.all.trash_sum.innerHTML = '<td class="copyright1" id="trash_sum">на сумму <b>'+numsum+' руб.</b></td>';
    alert ('Товар добавлен в Вашу корзину.\n\nДобавьте в заказ все необходимые товары,\nдалее для оформления заказа воспользуйтесь пунктами правого меню.\n\nВсего товаров в Вашей корзине:  '+len+'\nНа сумму:  '+numsum+' руб.');
}

function ClearBasket(){
        var ThreeDays = 3*24*60*60*1000;
        var expDate = new Date();
        expDate.setTime (expDate.getTime()-ThreeDays);
        document.cookie = 'basket = ImOutofHere; expires='+expDate.toGMTString();
        document.cookie = 'tovar_type = ImOutofHere; expires='+expDate.toGMTString();
        document.all.trash.innerHTML = '<td colspan="2" class="rmtext" id="trash">ваша корзина пуста</td>';
        alert('Ваша корзина очищена!');
}
function ClearBasketL(){
        var ThreeDays = 3*24*60*60*1000;
        var expDate = new Date();
        expDate.setTime (expDate.getTime()-ThreeDays);
        document.cookie = 'basket = ImOutofHere; expires='+expDate.toGMTString();
        document.cookie = 'colors = ImOutofHere; expires='+expDate.toGMTString();
        document.cookie = 'sum = ImOutofHere; expires='+expDate.toGMTString();

}

function TrashStat(){
    var basket = getCookie('basket');
    var tovar_type = getCookie('tovar_type');
    var len = 0;
    var pos = 0;
    var i = -1;
    var str = new String("");

    if (basket!="") {
     str += basket;
     while (pos != -1) {
             pos = str.indexOf("X", i+1);
             len += 1;
             i = pos;
      }
     document.all.trash.innerHTML = '<td colspan="2" class="rmtext" id="trash">товаров в корзине: <b>'+len+'</b></td>';
    }else{
     document.all.trash.innerHTML = '<td colspan="2" class="rmtext" id="trash">ваша корзина пуста</td>';
    }
//        alert("test ok");

}