// Функция, показывающая - скрывающия всплывающие слои.

	function displaySelector( item ) {

		var obj;
		obj = document.getElementById(item);

		if (obj.style.display != 'none') {

			obj.style.display = 'none';

		} else {

			$('div.popdivs').css('display','none');
			obj.style.display = 'block';

		}
	}

// Функция "Добавить в Избранное"

function add2Fav(url,title, link_name) {
    if (!url) url = location.href;
    if (!title) title = document.title;

    if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
        window.sidebar.addPanel (title, url, '');
    } else if (typeof window.external == 'object') {
        window.external.AddFavorite(url, title);
    } else if (window.opera && document.createElement) {
        document.getElementById(link_name).setAttribute('rel','sidebar');
        document.getElementById(link_name).setAttribute('href',url);
        document.getElementById(link_name).setAttribute('title',title);
      } else {
        return false;
    }
return true;
}


// Functions for ToolBar

var password = '';

$( function () {

	if ( $.cookie('ngsUserMail') ) {
		$('#login').val($.cookie('ngsUserMail'));
		$('#login-label').hide();
		$('#pass-label').hide();

	} else {

		if ( $('#login').val() == '' ) {
			$('#login-label').show();
		}

		if ( $('#pass').val() == '' ) {
			$('#pass-label').show();
		}
	}

	if ( $.cookie('ngsSearchMode')) {

		if ($.cookie('ngsSearchMode') == 1 || $.cookie('ngsSearchMode') == 2) {

			$('#mode').get(0).selectedIndex = $.cookie('ngsSearchMode');

		} else {

			$('#mode').get(0).selectedIndex = 0;
		}

	}


	$('#mailBlock').submit(mailLogin);

} );


function saveInCookie( name, value ) {

	$.cookie( name, value,  {path: '/', expires: 8640000} );
}

// переход в авторизацию почты

function mailLogin() {

	 var returnValue = true;

	 var login = trim($('#login').val());

	 var pass = trim($('#pass').val());

	 // сохранение email
	 saveInCookie('ngsUserMail', login);

	 if (login == '') {

	 	alert('Вы не указали логин');

	 	returnValue = false;
	 }

	 if (pass == '') {

	 	alert('Вы не указали пароль');

	 	returnValue = false;
	 }

	 return returnValue;
}

function clearInput( object ) {
	var prev = $(object).prev();
	if ( prev ) {
		$( prev ).hide();
	}
}

function lostFocus( object ) {
	var prev = $(object).prev();
	if ( !object.value && $('#login').val() == '' ) {
		$( prev ).show();
	}
}

trim = function (str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

ltrim = function (str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

rtrim = function (str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

/**
* Функция переключения вкладок с Прогнозами погоды.
* @param  		number - порядковый номер вкладки.
*/

function switchInsertsForecast( number, printHref) {

	var num = number - 1;

	$('div.forecast').css('display', 'none');

	$( $('div.forecast').get(num) ).css('display', 'block');

	$('div.insert').removeClass('current-insert');

	$( $('div.insert').get(num) ).addClass('current-insert');

	document.getElementById('p3Forecast').href = printHref;
	
	document.getElementById('p3Forecast2').href = printHref;
}

/**
* Функция, выделяющая текст в Textarea во всплывающем слое "Код Информера".
*/

function selectText() {

	$('textarea','#kod-informer').focus();
	$('textarea','#kod-informer').select();

}