jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { 
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function Login( void_login )
{
	if( void_login )
	{
		$("#login_form").fadeTo("fast", 0.9).fadeIn('slow');
		$("body").append('<div id="disabled-layer"></div>');
	}
	else
	{
	    $('#login_form').fadeOut('fast');
		$('#disabled-layer').remove();
	}
}
function doLogin(ev)
{
	
	var name, password;
	
	name = $('#login6').attr('value');
	password = $('#password').attr('value');
	
	
	if( typeof(name) == "undefined" || name === '' )
	{
		$('#login6').focus();
		alert('Вы не ввели имя пользователя!');
		return;
	}
	else if( typeof(password) == "undefined" || password === '' )
	{
		$('#password').focus();
		alert('Вы не ввели пароль!');
		return;
	}
	
	$(ev).attr('disabled','disabled');
	$('#border').append('<div style="display:none" id="lodinglog">Подождите ...</div>');
	$('#lodinglog').fadeIn('slow');
	
	$.post('/engine/ajax/login.php', {login_name:name, login_password:password}, function(response)
    {
		
		if( response == 'enter')
		{	
			setTimeout("window.location = '" + document.location + "'", 2000);
			$('#lodinglog').html('<font color="green">Доступ разрешен! Переадресация...</font>');
		}
		else if( response == 'error')
		{
			$('#lodinglog').html('<font color="red">Вы ввели неверный логин или пароль!</font>');
			$(ev).attr('disabled','');
		}
	});
}


$(function()
{
	$("#column div span").each(function()
	{
		if($(this).attr('tooltip') == 'gb')
		{
			var rel = $(this).attr('rel');
			var cookie_value = $.cookie('block['+rel+']');
			
			if(typeof(cookie_value) == 'undefined' || cookie_value == null ||  cookie_value == 1)
			{
				$('#' + rel).attr('style', 'display:block' );
				$(this).html( "<img src=\"/templates/"+ dle_skin  + "/dleimages/minus_fav.gif\" />" );
			}
			else if( cookie_value == 0 )
			{
				$(this).html( "<img src=\"/templates/"+ dle_skin  + "/dleimages/plus_fav.gif\" />" );
				$('#' + rel).attr('style', 'display:none' );
			}
		}
	});
});

function getblock( blockid, self ) 
{
	if ( document.getElementById(blockid).style.display == 'block' )
	{
		$.cookie('block['+blockid+']', 0);
		$('#' + blockid ).slideUp('fast');
		$(self).html( "<img src=\"/templates/"+ dle_skin  + "/dleimages/plus_fav.gif\" />" );
	}
	else
	{
		$.cookie('block['+blockid+']', 1);
		$('#' + blockid ).slideDown('fast');
		$(self).html( "<img src=\"/templates/"+ dle_skin  + "/dleimages/minus_fav.gif\" />" );
	}
}