$(function(){
	$('#errorLoginMessage').dialog({
		autoOpen: false,
		title: "Ошибка",
		show: 'slide',
		hide: 'slow',
		width: 400,
		modal: true,
		resizable: false,
		buttons: {
			"OK": function() {		
				$('#errorLoginMessage').dialog("close");
			}
		},
		closeOnEscape: false, 
		open: function(event, ui) { $('body').css('overflow-x','hidden'); $(".ui-dialog-titlebar-close").hide(); } 
	});
});

$(function(){
	$('#blockedMessage').dialog({
		autoOpen: false,
		title: "Предупреждение",
		show: 'slide',
		hide: 'slow',
		width: 400,
		modal: true,
		resizable: false,
		buttons: {
			"OK": function() {		
				$('#blockedMessage').dialog("close");
			}
		},
		closeOnEscape: false, 
		open: function(event, ui) { $('body').css('overflow-x','hidden'); $(".ui-dialog-titlebar-close").hide(); } 
	});
});

function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}
function showWrongLogin(needShow) { 
	if (needShow) {
		$('#errorLoginMessage').dialog('open');
	}	
}
function showBlocked(needShow) { 
	if (needShow) {
		$('#blockedMessage').dialog('open');
	}	
}
function needReloadPage(needReload) { 
	if (needReload) {
		var url = window.location.href; 
		var urlsplit = url.split("?"); 
		window.location=urlsplit[0];
	}	
}

function secondsToTime(secs)
{
	var hours = Math.floor(secs / (60 * 60));
	
	var divisor_for_minutes = secs % (60 * 60);
	var minutes = Math.floor(divisor_for_minutes / 60);

	var divisor_for_seconds = divisor_for_minutes % 60;
	var seconds = Math.ceil(divisor_for_seconds);
	
	var obj = {
		"h": hours,
		"m": minutes,
		"s": seconds
	};
	return obj;
}

/*
 * http://share42.com
 * Date: 09.04.2011
 * (c) 2011, Dimox
 */
function ConferZakladky() {
var u=location.href;
var t=document.title;
u=encodeURIComponent(u);
t=encodeURIComponent(t);
var s=new Array(
'"#" onclick="window.open(\'http://vkontakte.ru/share.php?url='+u+'\', \'_blank\', \'scrollbars=0, resizable=1, menubar=0, left=200, top=200, width=554, height=421, toolbar=0, status=0\');return false" title="Поделиться В Контакте"',
'"http://www.odnoklassniki.ru/dk?st.cmd=addShare&st._surl='+u+'&title='+t+'" title="Добавить в Одноклассники"','"http://www.facebook.com/sharer.php?u='+u+'&t='+t+'" title="Поделиться в Facebook"',
'"http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+u+'&title='+t+'" title="Сохранить закладку в Google"',
'"http://connect.mail.ru/share?url='+u+'&title='+t+'" title="Поделиться в Моем Мире@Mail.Ru"',
'"http://www.livejournal.com/update.bml?event='+u+'&subject='+t+'" title="Опубликовать в LiveJournal"',
'"http://www.liveinternet.ru/journal_post.php?action=n_add&cnurl='+u+'&cntitle='+t+'" title="Опубликовать в LiveInternet"',
'"http://zakladki.yandex.ru/newlink.xml?url='+u+'&name='+t+'" title="Добавить в Яндекс.Закладки"',
'"http://bobrdobr.ru/add.html?url='+u+'&title='+t+'" title="Забобрить"',
'"http://twitter.com/share?text='+t+'&url='+u+'" title="Добавить в Twitter"',
'"http://www.linkedin.com/shareArticle?mini=true&url='+u+'&title='+t+'" title="Добавить в Linkedin"',
'"http://www.myspace.com/Modules/PostTo/Pages/?u='+u+'&t='+t+'" title="Добавить в MySpace"',
'"http://memori.ru/link/?sm=1&u_data[url]='+u+'&u_data[name]='+t+'" title="Сохранить закладку в Memori.ru"',
'"http://www.friendfeed.com/share?title='+t+' - '+u+'" title="Добавить в FriendFeed"',
'"http://delicious.com/save?url='+u+'&title='+t+'" title="Сохранить закладку в Delicious"',
'"#" onclick="print();return false" title="Распечатать"');

this.init=function() {
	var html='';
	for(i=0;i<s.length;i++) {
		//if (i==14) continue;
		if (i==6 || i==12) {
			html+='<br class=nbsp><br class=pic>';
		}
		html+='<a href='+s[i]+' target="_blank"><img src="Pictures/Icons/blank.gif" width="16" height="16" style="border:0;padding:0;margin:0 4px 0 0;background:url(Pictures/Icons/icons.png) no-repeat -'+(i*16)+'px 0"/></a>';
	}
	document.write(html);
}	
}

function getDefaultWindowParams(windowWidth,windowHeight) {
	var myleft = (screen.width)?(screen.width-windowWidth)/2:100;
	var mytop = (screen.height)?(screen.height-windowHeight)/2 - 30:100;
	return "top="+mytop+",left="+myleft+",directories=no,location=no,menubar=no,status=no,toolbar=no,titlebar=no,scrollbars=yes,resizable=yes,width="+windowWidth+",height="+windowHeight;
}

function decode_utf8(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;

	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		}
		else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		}
		else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}

