var rnd = Math.round(Math.random() * 1000000000);
params = 'rnd=' + rnd;
var d_login = new Ajax.Request(
	'http://bankir.ru/discussion/login/',
	{method: 'get', parameters: params, onSuccess: discuss_login}
);

function discuss_login(transport) {
	var response = transport.responseText.evalJSON();
	info = response.info[0];
	if ( info.is_login == 1 ) {
		$('discuss_form_1').hide();
		$('discuss_form_2').hide();
		$('discuss_form_3').show();
		$('discuss_username_logon').innerHTML = info.username;
	} else {
		$('discuss_form_1').show();
		$('discuss_form_2').hide();
		$('discuss_form_3').hide();
		
		bankir_username = _utf8_decode_ ( unescape(readCookie('bankir_username')) );
		if ( bankir_username == '' || bankir_username == 'null' ) {
			bankir_username = 'Гость';
		}
		$('id_username').value = bankir_username;
	}
}

function _utf8_decode_(utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if (c < 128) {
				s = String.fromCharCode(c);
				string += s == '+' ? ' ' : s;
				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;
	}
 
