/*
	Copyright 2003-2008 LigoMaster
*/
function get_by_id(id, doc)
{	if(doc==null) doc = document;
	if(doc.all) return doc.all.item(id);
	if(doc.getElementById) return doc.getElementById(id);
	return false;
}
function get_number(value)
{
	var x = ''+value;
	x = x.replace(',', '.');
	while(x.indexOf(' ') >= 0) { x = x.replace(' ', ''); }
	x = parseFloat(x);
	return isNaN(x) ? 0 : x;
}
function limited_text_check_len(id, init)
{
	var txt = get_by_id(id);
	var cnt = get_by_id(id+'_backcounter');
	var	len = get_by_id(id+'_maxlen');
	if (!txt || !cnt || !len) return;
	var maxlen = get_number(len.value);
	if (txt.value.length > maxlen)
	{
		txt.value = txt.value.substring(0, maxlen);
		if (init == null) txt.focus();
	}
	cnt.value = maxlen - txt.value.length;
}

function show_item(obj) { obj.style.visibility = 'visible'; }
function hide_item(obj) { obj.style.visibility = 'hidden'; }

function LanguageSwitcher(label)
{
	if (!document.LanguageSwitchers) document.LanguageSwitchers = new Array();
	this.id_key = document.LanguageSwitchers.length;
	document.LanguageSwitchers[this.id_key] = this;

	this.label = label;
	this.focusElement = '';
	this.listElement = '';
	this.timer = '';

	this.focusElement = document.getElementById(this.label+'_focus');
	this.listElement = document.getElementById(this.label+'_list');
	var aOptions = this.listElement.getElementsByTagName('dl')[0].getElementsByTagName('dt');
	for(var iOption = 0; iOption < aOptions.length; iOption++)
	{
		var oOption = aOptions[iOption];
		if(oOption.getAttribute('lang'))
		{
			oOption.lp = this;
			oOption.onmouseover = function() { this.style.backgroundColor = '#CCCCCC'; };
			oOption.onmouseout = function() { this.style.backgroundColor = 'transparent'; };
			oOption.onclick = function() { this.lp.select(this); };
		}
	}

	this.showList = function()
	{
		clearTimeout(this.timer);
		this.listElement.style.display="block";
		this.focusElement.focus();
	}

	this.hideList = function()
	{
		LP.timer = setTimeout('document.LanguageSwitchers['+this.id_key+'].listElement.style.display = "none";', 200);
	}

	this.select = function(selectedOption)
	{
		var sLocation = document.location.hostname;
		var sPath = document.location.pathname.substring(4);
		var sSearch = document.location.search;
		var sHash = document.location.hash;
		var sNewLocation = 'http://'+document.location.hostname+'/'+selectedOption.getAttribute('lang')+'/'+(sPath?sPath:'')+(sSearch?sSearch:'')+(sHash?sHash:'');
		document.location = sNewLocation;
	}
}

