function check_length(id, length) {
	if (document.getElementById(id).value.length > length) {
		document.getElementById(id).value = document.getElementById(id).value.substr(0, length);
	}
}
function calc(v, plan_id) {
	if (v <= parseInt(document.getElementById('max'+plan_id).value) && v >= parseInt(document.getElementById('min'+plan_id).value)) {
		document.getElementById('calc'+plan_id).innerHTML = '$ ' + (parseFloat(v)*(document.getElementById('percent'+plan_id).value/100/(document.getElementById('term'+plan_id).value*86400/(document.getElementById('periodicy'+plan_id).value*document.getElementById('periodicy_value'+plan_id).value)))*(document.getElementById('term'+plan_id).value*86400/(document.getElementById('periodicy'+plan_id).value*document.getElementById('periodicy_value'+plan_id).value))).toFixed(2); 
	}
	else document.getElementById('calc'+plan_id).innerHTML='$ 0';
}
var Signup = {
	CheckLogin: function(input_id) {
		var param = 'login='+encodeURI(input_id.value);
		
		new Ajax.Request(
			'/includes/inlines/check_login.php', 
			{
				method: 'post',
				parameters: param,
				onComplete: function(transport) {
					if (transport.responseText == 'OK') {
						input_id.focus();
						document.getElementById('span_'+input_id.name).innerHTML='<div style="color:red">Login is already used!</div>';
					}
					else {
						input_id.focus();
						document.getElementById('span_'+input_id.name).innerHTML='<div style="color:green">Login is free!</div>';
					}
				}
			}
		);
	}
};
var Chat = {
	Send: function(text) {
		$.post('/includes/inlines/chat.php', { text: $('#chat_input').val() }, function(data) {
  			$('#chat_text').html(data);
		});
		$('#chat_input').val('');
	},
	Refresh: function() {
		$.post('/includes/inlines/chat.php', function(data) {
  			$('#chat_text').html(data);
		});
	}
};