/**
 * Отображение надписи в строке статуса
 * @param string
 * @return bool
 */
function showStatus(sMsg) {
    window.status = sMsg;
    return true;
}

/**
 * Positioning options window
 */
function moveOptionsWindow( window_name, h, w )
{
	// Scrolling offset
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

    if(document.all){
        availW = document.body.clientWidth;
        availH = document.body.clientHeight;
    }else{
        availW = innerWidth; availH = innerHeight;
    }

	h_scroll = y;
	h_window = availH;
	
	tmp1 = h_window - h;
	tmp1 = ( tmp1 > 0 ) ? tmp1 : 0;
	
	top_offset = tmp1/2 + h_scroll;  

	w1 = availW;
	w2 = 240;
	w3 = 600;
	
	w4 = (w1 - w3)/2 - w2;

	w = document.getElementById('r_' + window_name);
	w.style.position = 'absolute';
	w.style.top =  top_offset + "px";
	w.style.left = "-" + w4 + "px";

}

function setLanguage( lng )
{
	var cookie_value = readCookie("market");

	if ( cookie_value == null ) {
		cookie_value = "lang%3D"+lng;
	} else {
		cookie_value = cookie_value.replace(/lang%3D\w{2}/i, "lang%3D"+lng);
	}
	
	createCookie( "market", cookie_value, 6*30  );
	window.location.href = window.location.href.replace( /\/\w{2}\//i, "/"+lng+"/"  );
	
	return false; 
}
/* Функции для работы с куками */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function display_warning_message( msg )
{
	var cookie = readCookie('intim');
	if ( cookie == null ) {
		if ( !confirm( msg ) ) {
			window.location.href="/";
		} else {
			createCookie("intim",1,6*30);
		}				
	} 	
}

function show_define_region () {
	if (jQuery("#box_define_region").css("display")=="none") {
		jQuery("#box_define_region").slideDown("slow");
		createCookie( "setDefineRegion", "users", 6*30  );
	} else {
		jQuery("#box_define_region").slideUp("slow");
		createCookie( "setDefineRegion", "ip", 6*30  );
	}
}