var active = new Array();

function showdiv(obj) {
	if (!active[obj]) {
		document.getElementById(obj).style.display='block';
		active[obj] = 1;
	}
	else {
		document.getElementById(obj).style.display='none';
		active[obj] = 0;
	}
};

var maxlen = 115;
function check() {
	var str = document.forms.sms.msg.value;
	var len = str.length;
	if (len > maxlen) {
		document.forms.sms.msg.value = str.substring(0, maxlen);
	}
	str = document.forms.sms.msg.value;
	len = str.length;
	document.getElementById('lenout').innerHTML = (maxlen - len);
	document.forms.sms.msg.focus();
}

$(document).ready(function(){

	$('#titles').hide();
	$('label').each(function(){
		var id = '#' + $(this).attr('id') + '_title';
		if ($(id).length) {
		 $(this).append('<span class="question">?<\/span>');
		}
	});
	$(".question").mouseover(function() {
		 var id = '#' + $(this).parent('label').attr('id') + '_title .help';
		 var html = $(id).html();
		 $(this).parents("form").prepend('<div id="tooltip">'+html+'<\/div>');
		 $("#tooltip").show();
	});
	$(".question").mouseout(function() {
		$("#tooltip").hide();
		$("#tooltip").remove();
	});

	$(".stable td + td").addClass('td');

/*	$("#auth_type").change(function() {
		if ($(this).attr("checked"))
			$("#runa_label").hide('slow');
		else
			$("#runa_label").show('slow');
	});
	
/*
	var tooltip;
	$("label").mouseover(function() {
		if ($(this).children("acronym").length) {
			tooltip = $(this).children("acronym").attr("title");
			$(this).children("acronym").attr("title","");
			$(this).parents("form").prepend('<div id="tooltip">'+tooltip+'</div>');
			$("#tooltip").show();
		}
	});
	$("label").mouseout(function() {
		if ($(this).children("acronym").length) {
			$("#tooltip").hide();
			$(this).children("acronym").attr({ title: tooltip });
			$("#tooltip").remove();
		}
	});
*/
/*	$("label").hover(function(){
		$(this).next('.help').show();
		$(this).children("acronym").attr("title","");
	}, function(){
		$(this).next('.help').hide();
	});
*/

	$("#navigation_c .title_submenu").click(function(){
		$(this).next('.submenu').slideToggle();
		return false;
	});

	$("#navigation #leftmenu_body ul").accordion({autoheight: false,    active: true, 
    header: '.title_submenu', 
    navigation: true, 
    event: 'click'});

	
/*	$("#navigation .title_submenu").hover(function(){
		$(this).next('.submenu').slideDown();
		return false;
	}, function(){
		$(this).next('.submenu').slideUp();
		return false;
	});
	$("#navigation .submenu").hover(function(){
		$(this).next('.submenu').slideDown();
		return false;
	}, function(){
		$(this).next('.submenu').slideUp();
		return false;
	});
*/
	$("#link_archiv").click(function(){
		$("#sub_archiv").slideToggle();
		return false;
	});


	$(".category").click(function() {
		$(this).next().slideToggle();
		return false;
	});
	
	$(".switchcss").click(function(){
		var url_css = $("#css").attr('href');

		if (url_css.length == 40)
			lang = url_css.substr(38, 2);
		else
			lang = url_css.substr(44, 2);

		if (url_css=='/includes/themes/it/style_it_print.php?lang='+lang) {
			$("#css").attr('href', '/includes/themes/it/style_it.php?lang='+lang);
			$(".switchcss").text('Версия для печати');
			$(".screen").hide();
		}
		else {
			$("#css").attr('href', '/includes/themes/it/style_it_print.php?lang='+lang);
			$(".switchcss").text('Вернется в экранную версию');
			$(".screen").show();
		}
		return false;
	});
});