function openWindowExt( href, width, height, window_name, center, menu_bar, location, status )
{
    window_name = window_name || href;
    center = center || true;
    menu_bar = menu_bar || false;
    location = location || false;
    status = status || false;
    
    menu_bar = menu_bar ? 'yes' : 'no';
    location = location ? 'yes' : 'no';
    status = status ? 'yes' : 'no';
    
    var leftop = '';
    if( center ){
        var left = ( screen.width  - width ) * 0.5;
        var top  = ( screen.height - height ) * 0.5;
        leftop = ",left=" + left + ",top=" + top;
    }
    
    var params = "width=" + width + ",height=" + height + ",menubar=" + menu_bar + ",location=" + location + ",resizable=yes,scrollbars=yes,status=" + status + leftop;
    var win = window.open( href, window_name, params );
    win.focus();
}

function openWindow( href, width, height, window_name )
{
    openWindowExt( href, width, height, window_name, true, false, false, false );
}

function openWindow_MenuBar( href, width, height, window_name )
{
    openWindowExt( href, width, height, window_name, false, true, true, true );
}

function toggle(elm)
{
    if( $(elm).is(':visible') ){
        $(elm).hide(100);
    } else {
        $(elm).show(100);
    }
}

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 setCookie (name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

var g_timoutId = null;
function AppendToCart(aid)
{
    clearTimeout( g_timoutId );
    g_timoutId = setTimeout( 
        function () {
            $.getJSON(
                'cart.php?p_info='+aid, 
                function(ret){
                    $('#minicart').html( ret.minicart );
                    if( !ret.enought ){
                        $('#p_enought').html('<b class="warning_color">нет</b>');
                    }
                }
            );
        },
        400
    );
}

function AppendToCartEx(aid, count)
{
    $.getJSON( 'cart.php',
                { 'p_info':aid, 'p_append':aid, 'p_count':count }, 
                function(ret){
                    $('#minicart').html( ret.minicart );
                    if( !ret.enought ){
                        $('#p_enought').html('<b class="warning_color">нет</b>');
                    }
                }
            );
}
