var jsvar_sub_page = 1;
var onmmev;
var eventlistenerid;

document.onmousemove = function(evt) { onmme = (typeof evt=='undefined') ? window.event : evt; }

function addFieldValue(field, v) { var f = gebn(field); f[0].value += (f[0].value!='' ? ', ' : '')+v.innerHTML }
function align_objects(a, b) { ae = gebi(a); bcr_a = ae.getBoundingClientRect(); bcr_b = gebi(b).getBoundingClientRect(); wr = gebi('wrapper').getBoundingClientRect(); ae.style.display = 'block'; ae.style.left = bcr_b.left-wr.left-ae.offsetWidth; ae.style.top = bcr_b.top + getYOffset() }
function gebi(id) { var obj=null; obj=document.getElementById(id); return obj;}
/* function gebi(id){ var obj=null; if (document.getElementById) obj=document.getElementById(id); else if (document.all) obj=document.all[id]; else if (document.layers) obj=document.layers[id]; return obj; } */
function gebn(n) { var obj=null; obj=document.getElementsByName(n); return obj; }
function hideListenedElement() { gebi(eventlistenerid).style.display = 'none'; }
function focus_element(id) { setTimeout('gebi(\''+id+'\').focus()', 250) }
function jump_to(page) { top.location.href=page }
function filter(v, targ) { with (document.filter) { target = targ!='' ? targ : 'tf'; ajax_button.click() }}
function filter_country(country_id) { with(document.filters) { ajax_button.value = 'country,'+country_id; ajax_button.click() }}
function fix_gb_position() { var wr = gebi('wrapper').getBoundingClientRect(); var bb = gebi('browse_button').getBoundingClientRect(); var bf = gebi('browse_field'); var md = gebi('maskbb').style; bf.style.display = 'block'; bf.style.left = bb.right-wr.left-bf.offsetWidth; bf.style.top=bb.top-2; md.left = bf.style.left; md.top = bb.top-2 }
function refresh_captcha(lang) { gebi('captcha').src = lang+'/visualconfirmation/'+Math.floor(Math.random()*1000000); }
/* function set_event_listener(id) { eventlistenerid = id; document.all ? document.attachEvent('onclick', checkClick) : document.addEventListener('click', checkClick, false); } */
function set_event_listener(receiver_id, target_id, event_name, function_name) { var arg; if (document.all) { fn = 'attachEvent'; arg = ''; } else { fn = 'addEventListener'; arg = ', false'; } if (target_id=='') target_id='document'; eventlistenerid = receiver_id; eval(target_id+'.'+fn+'(\''+event_name+'\', '+function_name+arg+');'); }
function sort_col(fn, targ) { with(document.sort) { ajax_button.value = 'sort,'+fn; ajax_button.click() }}
function switch_border(id, state) { var a = gebi(id); if (a==null || !can_switch_border) return; if (state && a.className.indexOf("border_focus")==-1) a.className += " border_focus"; else a.className = a.className.replace("border_focus", "") }
function switch_show(id, state) { var a = gebi(id); if (a==null) return; a.style.display = (state || (state==null && a.style.display=='none')) ? '' : 'none' }

/* function checkClick(e)
{
	e ? evt = e : evt = event;
	CSE = evt.target ? evt.target : evt.srcElement;

	if (gebi(eventlistenerid))
		if (!isChild(CSE, gebi(eventlistenerid)))
			gebi(eventlistenerid).style.display = 'none';
}

function isChild(s,d)
{
	while(s)
	{
		if (s==d) return true;
		s=s.parentNode;
	}
	return false;
} */

function Left(obj)
{
	var curleft = 0;
	var wrapper = gebi('wrapper').getBoundingClientRect();
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) curleft += obj.x;

	return curleft-wrapper.left;
}

function Top(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) curtop += obj.y;

	return curtop;
}

function getYOffset()
{
	if (typeof(window.pageYOffset)=='number') return window.pageYOffset
	else if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) return document.body.scrollTop;
	else return document.documentElement.scrollTop;
}

function addToFavorites(error_msg)
{
	var url = location.href;
	var title = document.title;

	if (error_msg=='') error_msg = "Your browser can't support this feature";

	if (window.sidebar) window.sidebar.addPanel(title, url, "");
	else if (window.external) window.external.AddFavorite(url, title);
	else if (window.opera && window.print) return true;
	else alert(error_msg);
}

function check_length(element, max_length, still2go_id)
{
	if (Number(max_length) < 1) return;
	if (isNaN(still2go_id)) still2go_id = 0;
	var still2go = document.getElementsByName('still2go');
	if (still2go_id > still2go.length) return;
	if (element.value.length > max_length) element.value = element.value.substr(0, max_length);
	if (still2go[still2go_id]) still2go[still2go_id].value = max_length - element.value.length;
}

function checkfile(fileName,fileTypes)
{
	if (!fileName) return;
	dots = fileName.split(".");
	fileType = "." + dots[dots.length-1];
	if (("."+fileTypes.join(".")).indexOf(fileType) == -1) return alert('{L_WRONG_FILETYPE}');
	else return true;
}

function show_sub_page(id)
{
	if (id==jsvar_sub_page) return;
	if (!jsvar_sub_page) jsvar_sub_page = 1;

	gebi('sub_page'+id).style.display = '';
	gebi('sub_page_button'+id).className = 'sub_page_button_current';
	gebi('sub_page'+jsvar_sub_page).style.display = 'none';
	gebi('sub_page_button'+jsvar_sub_page).className = 'sub_page_button';
	jsvar_sub_page = id;
}

function switch_ytvideo(ytcode) { gebi('ytplayer').src = 'http://www.youtube.com/embed/'+ytcode }

function table_toggle_rows(thisname)
{
	tr = document.getElementsByTagName('tr');

	for (i=0; i<tr.length; i++)
	{
		if (tr[i].getAttribute(thisname))
		{
			if (tr[i].className.indexOf("hidden")==-1) tr[i].className += " hidden";
			else tr[i].className = tr[i].className.replace("hidden", "");
		}
	}
}

