	
function el(id) {
	return document.getElementById(id)
}

function show(id) {
    return $('#'+id).slideDown();
}    

function hide(id) {
   return $('#'+id).fadeOut();
}    

function show_hide(id) {
	if ($('#'+id).css('display') == 'none')
		return $('#'+id).slideDown();
	
	return $('#'+id).fadeOut();
}	

function redirect(url) {
	window.location = url;
	return false;
}

function if_confirm(url) {
	if(confirm(text_are_you_sure))
		redirect(url);
}

function Submit(form) {
	f = document.forms[form];
	f.submit();
}

function Bookmark(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	} else if (window.external) { 
		window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) { 
		var a = document.createElement('A');
		if (!a) return false; //IF Opera 6
		a.setAttribute('rel','sidebar');
		a.setAttribute('href',url);
		a.setAttribute('title',title);
		a.click();
	}
}

function charcount(name,max) {
	memo = el('_form_' + name);
    counter = el(name + "__charcounter");
	
	msglen = memo.value.length;
	if (msglen > max) memo.value = memo.value.substring(0, max);
    counter.value = memo.value.length;
}

function clearmemo(name) {
	memo = el('_form_' + name);
	memo.value = '';
    counter = el(name + "__charcounter");
	counter.value = 0;
}

function SendGet(url) {
	redirect(url);
}

function show_message(message) {
	var scroll = getBodyScrollTop();
	sc = 50;
	sc = scroll;
	$("#message_block").css("right", "25px");
	$("#message_block").css("top", 25 + sc  + "px");
	$("#message_block").css("width", "210px");
	$("#message_block").css("height", "40px");
	
	$("#message_block").empty();
	$("#message_block").append(message);
	$("#message_block").show();
	setTimeout("$('#message_block').fadeOut('slow')", 2000);
}

function getClientCenterX() {
    return parseInt(getClientWidth()/2)+getBodyScrollLeft();
}

function getClientCenterY() {
    return parseInt(getClientHeight()/2)+getBodyScrollTop();
}

function getBodyScrollTop() {
  return self.pageYOffset || 
    (document.documentElement && document.documentElement.scrollTop) || 
    (document.body && document.body.scrollTop);
}

function getBodyScrollLeft() {
  return self.pageXOffset || 
    (document.documentElement && document.documentElement.scrollLeft) || 
    (document.body && document.body.scrollLeft);
}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function popup(link, width, height, resizable, scroll) {
    if (!window.focus) 
		return true;
	
	var href;
	if (typeof(link) == 'string')
   		href=link;
	else
   		href=link.href;
	if(!resizable) 
		resizable = 'yes';
	
	if(!scroll) 
		scroll = 'no';

	window.open(href, '', 'width='+width+',height='+height+',scrollbars='+scroll+',resizable='+resizable+',alwaysRaised=yes');
}

function Block(html, width, height) {
	
	$.blockUI(
		{ 
			message: html,
			css: { 
				top: '20%',
				padding: '15px', 
				backgroundColor: '#333333', 
				border: '1px solid #111111',
				color: '#f0ffff',
				cursor: 'default'
			}
		}
	); 
	 $('.blockOverlay').attr('title','Click to unblock').click($.unblockUI);
}

function selectfield(id) {
	show(id);
}

function CheckEmail() {
	formid = "_form_email";
	helpid = "_help_email";
	e = el(formid);
	if (e.value.length > 3) hide(helpid);
}

function CheckEmail_ajax(name) {
	formid = "_form_email";
	helpid = "_help_email";
	e = el(formid);
	$.post('ajax.php', {mode: "check_user_email", email: e.value}, CheckEmail_result);
}

function CheckEmail_result(result) {
	formid = "_form_email";
	helpid = "_help_email";
	
	if (result == 'ok') return hide(helpid);
	
	show(helpid);
	el(helpid).innerHTML = result;	
	el(helpid).className = "error_field";	
}

function CheckUser() {
	formid = "_form_name";
	helpid = "_help_name";
	e = el(formid);
	if (e.value.length > 3) hide(helpid);
}

function CheckUser_ajax(name) {
	formid = "_form_name";
	helpid = "_help_name";
	e = el(formid);
	return $.post('ajax.php', {mode: "check_user_name", name: e.value}, CheckUser_result);
}

function CheckUser_result(result) {
	formid = "_form_name";
	helpid = "_help_name";
	
	if (result == 'ok') return hide(helpid);
	
	show(helpid);
	el(helpid).innerHTML = result;	
	el(helpid).className = "error_field";	
	
	return true;
}
