function setNpP(num)
{
    setCookie('npp', num, '/', 24*7*3600);
    
    window.location.href = window.location.href.replace(/from\/[^\/]*\//, '');
}

function add_prod(cart, id)
{

}

function remove_prod(id)
{
    cart = getCookie('cart').split(':');
    cnew = new Array();
    for (i = 0; i < cart.length; i++) {
        arr = cart[i].split('#');
        if (arr[0] == id) continue;
        cnew.push(cart[i]);
    }
    setCookie('cart', cnew.join(':'), '/', 24*7*3600);
    window.location.reload();
    return false;
}

function change_num(id, obj)
{
    value = obj.value;
    cart = getCookie('cart').split(':');
    cnew = new Array();
    for (i = 0; i < cart.length; i++) {
        arr = cart[i].split('#');
        if (arr[0] == id) {
            if (value <= 0) continue;
            cart[i] = arr[0] + '#' + value;
        }
        cnew.push(cart[i]);
    }
    setCookie('cart', cnew.join(':'), '/', 24*7*3600);
    window.location.reload();
    return false;
}

function doCompare()
{
    $('compare_form').submit();
}

function deleteCompare(id)
{
    window.location.href = window.location.href.replace(id, '').replace('/,', '/').replace(',/', '/').replace(',,', ',');
    return false;
}

function add2cart(obj, id) {
	if (obj.title == 'в корзине') {
		delcart(obj, id);
	}
	else if (obj.title == 'в корзину') {
		addcart(obj, id);
	}
	else {
		;
	}
	return false;
}
function addcart(obj, id)
{
    cart = getCookie('cart');
    refresh = 0;
    if (cart) cart = cart.split(':'); else {
        cart = new Array();
        refresh = 1;
    }
    for (i = 0; i < cart.length; i++) {
        arr = cart[i].split('#');
        if (arr[0] == id) return false;
    }
    cart.push(id + '#4');
    setCookie('cart', cart.join(':'), '/', 24*7*3600);
    obj.firstChild.src = 'i/cart_in.gif';
    obj.firstChild.alt = 'в корзине';
    obj.title = 'в корзине';
	if ($('cart_cnt')) $('cart_cnt').innerHTML = cart.length;
    //if (refresh) window.location.reload();
    window.location.reload();
    return false;
}

function delcart(obj, id)
{
    cart = getCookie('cart');
    refresh = 0;
    if (cart) {
		cart = cart.split(':');
	}
	else {
        cart = new Array();
        refresh = 1;
    }
	newcart = new Array();
    for (i = 0; i < cart.length; i++) {
        arr = cart[i].split('#');
        if (arr[0] == id) continue;
		newcart.push(arr[0] + '#' + arr[1]);
    }
    setCookie('cart', newcart.join(':'), '/', 24*7*3600);
    obj.firstChild.src = 'i/cart.gif';
    obj.firstChild.alt = 'в корзину';
    obj.title = 'в корзину';
	if ($('cart_cnt')) $('cart_cnt').innerHTML = cart.length;
    if (refresh) window.location.reload();
    window.location.reload();
    return false;
}

function clear_cart()
{
    delCookie('cart', '/');
}

function showrim(id)
{
    window.open('/showrim/' + id + '/', 'showrim_win', 'width=1000, height=400, scrollbars=1');
}

win = 0;
function enlargeImg(src, title)
{
/*
    if (src.charAt(src.length - 1) == '/') {
        src = src.substr(0, src.length - 1);
    }
  */
    html = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
    html += "\n";
    html += "<html>\n";
    html += "<head>\n";
    html += "<title>" + title + "</title>\n";
    
    html += '<script language="JavaScript" type="text/javascript">';
    html += 'document.oncontextmenu = function(){return false;}';
    html += '</script>';
    
    html += "</head>\n";
    html += "\n";
    html += "<body leftmargin=\"0\" rightmargin=\"0\" topmargin=\"0\" bottommargin=\"0\" marginheight=\"0\" marginwidth=\"0\">\n";
    html += "<a href=\"#\" title=\"Закрыть\"><img border=\"0\" id=\"img_id\" src=\"/img/loading.gif\" onclick=\"window.close();\" alt=\"Закрыть\"></a>";
    html += "<script language=\"JavaScript\">\n";
    html += "var img = new Image();\n";
    html += "img.onload = function () {window.moveTo(0, 0); window.resizeTo(img.width + 10, img.height + 50);\n";
    html += "";
    html += "document.getElementById('img_id').src = '" + src + "';}\n";
    html += "img.src = '" + src + "';\n";
    
    html += "</script>\n";
    html += "</body>\n";
    html += "</html>";

    if(win){
        if(!win.closed) {
            win.close();
        }
    }
    win = window.open('', '', 'width=100, height=100, status = 1');

    win.document.write(html);
    win.document.close();
}

