$(function(){
	$(":input[title]").each(function() {
		$(this).after("<img src='/images/info-icon.gif' width='11' height='11' align='absmiddle' style='margin-left: 5px;'>");
	});
	
	$(":input[title]").tooltip({
		position: ['center', 'right'],
		offset: [0, 5],
		effect: "fade",
		events: {
			def:     "mouseover,mouseout",
			input:   "focus mouseover,blur mouseout",
			widget:  "focus mouseover,blur mouseout",
			tooltip: "mouseover,mouseout"
		}		
	});
	
/*	$(":input[tooltip]").tooltip({
		position: ['center', 'right'], // place tooltip on the right edge
		offset: [-2, 10], // a little tweaking of the position
		effect: 'toggle', // use a simple show/hide effect
		opacity: 0.7 // custom opacity setting
	});*/
});

function toggle_popup(obj)
{
	if (!$(obj).length) return;
	
	var s = $("#" + $(obj).attr("popup_id")).css("display");
	$(".popup_block").hide();
	if (s == "none") $("#" + $(obj).attr("popup_id")).show();
	else $("#" + $(obj).attr("popup_id")).hide();
}

function select_adressbook()
{
	$("#recipients_sel_1 .popup_block").each(function() {
		var adressbooks_list = $(".adressbooks_list", $(this).parent());
		adressbooks_list.show();
		
		var txt = "";
		$("input[type='checkbox']:checked", this).each(function(i) {
			if (i) txt += ", ";
			txt += $(this).next().text();
		});

		adressbooks_list.text(txt);
		if (txt == "") adressbooks_list.hide();
	});
}

function calc(obj)
{
	if (!$(obj).length) return;
	
	var mess_count = 0;
	var cur_len = $(obj).val().length;

	if (!$(obj).val().match(/^[\x00-\x7F]*$/i))
	{
		var mess_maxlen = 335;
		var mess_len = cur_len > 70 ? 67 : 70
		var mess_type = "ru"
	}
	else
	{
		var mess_maxlen = 765;
		var mess_len = cur_len > 160 ? 153 : 160
		var mess_type = "en"
	}

	if (cur_len > mess_maxlen)
	{
		$(obj).val($(obj).val().substr(0, mess_maxlen));
		cur_len = mess_maxlen
	}

	mess_count = Math.ceil(cur_len / mess_len)

	$("#sms_type").text(mess_type)
	$("#count_symb").text(cur_len)
	$("#max_length").text(mess_maxlen)
	$("#count_sms").text(mess_count)
	$("#sms_len").text(mess_len)
}

function grow_up(obj)
{
	if (!$(obj).length) return;
	
	var max_lines = 10;
	var line_height = 15;

	var lines = $(obj).val().split("\n").length;
	if (lines >= max_lines)
	{
		$(obj).css("overflow", "auto");
		lines = max_lines;
	}
	else $(obj).css("overflow", "hidden");
	$(obj).css("height", 3 + lines * line_height);
	$(obj).focus();
}

/*
function translit_str(str) {
	var symb = {
		"[" : "(",
		"\\" : "/",
		"]" : ")",
		"^" : "*",
		"{" : "(",
		"|" : "I",
		"}" : ")",
		"~" : "-",
		"¸" : "e",
		"é" : "y",
		"þ" : "yu",
		"ü" : "'",
		"÷" : "ch",
		"ù" : "sch",
		"ö" : "c",
		"ó" : "u",
		"ê" : "k",
		"å" : "e",
		"í" : "n",
		"ã" : "g",
		"ø" : "sh",
		"ç" : "z",
		"õ" : "h",
		"ú" : "'",
		"ô" : "f",
		"û" : "i",
		"â" : "v",
		"à" : "a",
		"ï" : "p",
		"ð" : "r",
		"î" : "o",
		"ë" : "l",
		"ä" : "d",
		"æ" : "j",
		"ý" : "e",
		"ÿ" : "ya",
		"ñ" : "s",
		"ì" : "m",
		"è" : "i",
		"ò" : "t",
		"á" : "b",
		"¨" : "E",
		"É" : "Y",
		"Þ" : "YU",
		"×" : "CH",
		"Ü" : "'",
		"Ù" : "SCH",
		"Ö" : "C",
		"Ó" : "U",
		"Ê" : "K",
		"Å" : "E",
		"Í" : "N",
		"Ã" : "G",
		"Ø" : "SH",
		"Ç" : "Z",
		"Õ" : "H",
		"Ú" : "`",
		"Ô" : "F",
		"Û" : "I",
		"Â" : "V",
		"À" : "A",
		"Ï" : "P",
		"Ð" : "R",
		"Î" : "O",
		"Ë" : "L",
		"Ä" : "D",
		"Æ" : "J",
		"Ý" : "E",
		"ß" : "YA",
		"Ñ" : "S",
		"Ì" : "M",
		"È" : "I",
		"Ò" : "T",
		"Á" : "B",
		"‘" : "'",
		"’" : "'"
	}

	var res = '';
	for (var i = 0; i < str.length; i++)
	{
		var chr = str.charAt(i);
		if (symb[chr]) res += symb[chr];
		else res += chr.charCodeAt(0) > 127? '?': chr;
	}

	return res;
}
*/

