var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src = window.browseButtonSRC;
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

/*Nyelvvalaszto menu >=IE6 fix*/
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("lang_nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function init() {
	startList();
	initFileUploads();
	for(var i = 0; i < document.forms.length; i++) {
		document.forms[i].reset();
	}
	if(document.getElementById('timezones_added')) {document.getElementById('timezones_added').value = '';}
	
}
/*--------------------------------------------------*/


/*FORM CHECK*/
function check_login_form(email, password) {
	if (email.value == "") {
		alert(window.alertNoEmail);
		return false;
	} else if ((email.value.indexOf("@") < 1) || (email.value.indexOf(".") < 1)) {
		alert(window.alertInvalidEmail);
		return false;
	} else if (password.value == "") {
		alert(window.alertNoPassword);
		return false;
	} else {
		//this.submit();
		return true;
	}
}

function check_reg_form(email, password, password2, agreeterms) {
	if(!check_login_form(email, password)) {
		return false;
	}

	if(password.value != password2.value) {
		alert(window.alertPasswordMismatch);
		return false;
	}

	if(agreeterms.checked == false) {
		alert(window.alertHaveToAgreeTerms);
		return false;
	}

	return true;
}

function open_window(url, title) {
	window.open(url, title, 'status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=1');
	return false;
}

function open_layer(type, param1, param2) {
	hideSelectBoxes();
	var form_outer_div = document.getElementById('form_outer_div');
	switch(type) {
		case 'login' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/login_form.php', {
				onComplete:function(){
					focusLoginFormEmail();
					var login_form = document.getElementById('login');
					login_form.to.value = param1;
				}
			}); 
			break;
		}
		case 'reg' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/reg_form.php'); 
			break;
		}
		case 'chgemail' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/change_email_form.php');
			break;
		}
		case 'chgpwd' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/change_password_form.php');
			break;
		}
		case 'add_ad' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/add_classified.php', {
				onComplete:function(){
					initFileUploads();
				}
			});
			break;
		}
		case 'remove_ad' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/del_classified.php'); 
			break;
		}
		case 'cnfrm' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/comment_confirm_game.php', {
				onComplete:function(){
					var cg_form = document.getElementById('confirmGameForm');
					cg_form.game_id.value = param1;
				}
			}); 
			break;
		}
		case 'pics' : {
			if(param1) { var par = '?player_id=' + param1;}
			else { var par = '';}
			new Ajax.Updater('form_outer_div', '/layer_contents/player_pics.php' + par); 
			break;
		}
		case 'history' : {
			if(param1 && param2) {
				var par = '?rank_list_id=' + param1 + '&member_id=' + param2;
			} else {
				var par = '';
			}
			new Ajax.Updater('form_outer_div','/layer_contents/ranking_history.php' + par);
			break;
		}
		case 'unreg_tournament' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/unreg_tournament.php', {
				 onComplete:function(){
					 var cg_form = document.getElementById('unregtournament');
					 cg_form.tournament_id.value = param1;
				 }
			});
			break;
		}
		case 'reg_tournament' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/reg_tournament.php', {
				onComplete:function(){
					var cg_form = document.getElementById('regtournament');
					cg_form.tournament_id.value = param1;
				}
			});
			break;
		}
		case 'edit_result' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/edit_tournament_game.php?tournament_id=' + param1 + '&game_id=' + param2);
			break;
		}
		case 'tournament_org_pricing' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/prof_tournament_org_pricing.php');
			break;
		}
		case 'hp_tournament_org_pricing' : {
			new Ajax.Updater('form_outer_div', '/layer_contents/hobby_plus_tournament_org_pricing.php');
			break;
		}
	}

	var arrayPageScroll = getPageScroll();
	var arrayPageSize = getPageSize();
	Element.setHeight('overlay', arrayPageSize[1]);
	var container = new getObj('form_outer_div');
	container.style.top = arrayPageScroll[1] + 127 + 'px';
	//Element.setWidth('overlay', arrayPageSize[0]);
	
	var overlay = document.getElementById('overlay');
	overlay.onclick = function() { close_layer(); return false;}
	
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
	new Effect.Appear('form_outer_div', { duration: 0.2, from: 0.0, to: 1 });
	
	return false;
}

function close_layer() {
	
	new Effect.Fade('overlay', { duration: 0.2 });
	new Effect.Fade('form_outer_div', { duration: 0.2 });
	showSelectBoxes();
	return false;
}


function open_clublist(rootElement) {
	//var clubinfo_container = document.getElementById('clubinfo');
	//clubinfo_container.innerHTML = '';

	//var activeClub = document.getElementsByClassName('active_club');
	//for (var i = 0; i < activeClub.length; i++) { 
	//		activeClub[i].className = '';
	//}

	var targetSiblings = rootElement.parentNode.parentNode.getElementsByTagName('UL');
	for (var i = 0; i < targetSiblings.length; i++) { 
			targetSiblings[i].className = 'hide';
	}

	var targetUL = rootElement.nextSibling.nextSibling;
	targetUL.className = 'show';
	rootElement.blur();
	return false;
}

function update_club(e, club_id) {

	var activeClub = document.getElementsByClassName('active_club');
	for (var i = 0; i < activeClub.length; i++) { 
			activeClub[i].className = '';
	}
	
	
	var clubinfo_container = document.getElementById('clubinfo');
	clubinfo_container.innerHTML = '';
	//new Ajax.Updater('clubinfo', 'clubs/club_' + club_id + '.html');
	new Ajax.Updater('clubinfo', '/clubs/club_info.php?location_id=' + club_id);
	
	e.blur();
	e.className = 'active_club';
	return false;
}


function change_cities(country_id, display_choose_option) {
	
	//var url = 'cities/country_' + country_id + '.html';
	var url = '/cities.php?country_code=' + country_id;
    if(display_choose_option) {
		url = url + '&include_optional=true';
	}
	var updateSelect = function(t) {
		var textToSplit = t.responseText;
		var lists = textToSplit;
		var listitem;
		var lista;
		var j;
		listItem = lists.split ("|");
		lista = document.getElementById ('city');
		lista.options.length = 0; // lista t&#195;&#182;rl&#195;&#169;se
		for (j = 1; j < listItem.length; j++ )
		{
			valueLabelPair = listItem[j].split (";")
			lista.options[j-1] = new Option (valueLabelPair[0], valueLabelPair[1]);
		}
		lista.onchange();
	}
	
	new Ajax.Request(url, {onSuccess:updateSelect});
}

function change_currency(country_code) {
	var url = '/currency.php?country_code=' + country_code;
	var updateSpan = function(t) {
		var currency = t.responseText;
		var spanTags = document.getElementsByClassName('currency');
		for (i=0; i < spanTags.length; i++) {
			spanTags[i].innerHTML = currency;
		}
	}
	
	new Ajax.Request(url, {onSuccess:updateSpan});
}


function players_from_country(country_id, target_select) {
	
	//var url = 'players/country_' + country_id + '.html';
	var url = '/players.php?country_code=' + country_id;
	var updateSelect = function(t) {
		var textToSplit = t.responseText;
		var lists = textToSplit;
		var listitem;
		var lista;
		var j;
		listItem = lists.split ("|");
		lista = document.getElementById (target_select);
		lista.options.length = 0; // lista t&#195;&#182;rl&#195;&#169;se
		for (j = 1; j < listItem.length; j++ )
		{
			valueLabelPair = listItem[j].split (";")
			lista.options[j-1] = new Option (valueLabelPair[0], valueLabelPair[1]);
		}
	}
	
	new Ajax.Request(url, {onSuccess:updateSelect});
}

function clubs_from_city(city_id, target_select) {
	
	//var url = 'clublists/city_' + city_id + '.html';
	var url = '/clubs.php?city_id=' + city_id;
	
	var updateSelect = function(t) {
		var textToSplit = t.responseText;
		var lists = textToSplit;
		var listitem;
		var lista;
		var j;
		listItem = lists.split ("|");
		lista = document.getElementById (target_select);
		lista.options.length = 0; // lista t&#195;&#182;rl&#195;&#169;se
		for (j = 1; j < listItem.length; j++ )
		{
			valueLabelPair = listItem[j].split (";")
			lista.options[j-1] = new Option (valueLabelPair[0], valueLabelPair[1]);
		}
	}
	
	new Ajax.Request(url, {onSuccess:updateSelect});
}

function loadParticipants(groupId) {
	var url = '/players/groupMembers.php?group_id=' + groupId;
	var updateMembers = function(t) {
		var memberData;
		var members = t.responseText;
		var listItems = members.split ("|");
		var selectElement = document.getElementById ("participants");
		selectElement.options.length = 0; // lista t&#195;&#182;rl&#195;&#169;se
		for (j = 0; j < listItems.length; j++ )
		{
			memberData = listItems[j+1].split (";")
			selectElement.options[j] = new Option (memberData[0], memberData[1]);
			if(memberData[2] == 0)
				selectElement.options[j].disabled = true;
			else if(memberData[3] == 1)
				selectElement.options[j].selected = true;
		}
	}
	
	new Ajax.Request(url, {onSuccess:updateMembers});
}

function deleteIMG(buttonId) {
	var idFromButtonId = buttonId.split('_');
	var imgID = idFromButtonId[1];	
	var hiddenCheckbox = document.getElementById('imgCheck_' + imgID);
	var divToFade = document.getElementById('imgContainer_' + imgID);	
	var button = document.getElementById(buttonId);
	var imagesToDelete = document.forms[1]['del_imgs'];
	var defaultIMG = document.getElementById('def_img_' + imgID);

	if (!hiddenCheckbox.checked) {
		hiddenCheckbox.checked = true;
		divToFade.className = 'faded';	
		button.value = window.stringRestore;
		imagesToDelete.value = imagesToDelete.value + '|' + imgID;
		if((defaultIMG) && (defaultIMG.checked == true)) {
			defaultIMG.checked = false;
			defaultIMG.disabled = true;
		} else if (defaultIMG) {
			defaultIMG.disabled = true;
		}
		return false;
	} else {
		hiddenCheckbox.checked = false;
		divToFade.className = '';
		button.value = window.stringDelete;
		imagesToDelete.value = imagesToDelete.value.replace('|' + imgID, '');
		if (defaultIMG) {
			defaultIMG.disabled = false;
		}
		return false;
	}
}

function swapCityInputs() {
	var cityInput = document.getElementById('city');
	var citySelect = document.getElementById('new_city');
	var cityController = document.forms[1]['is_new_city'];
	var cityButton = document.forms[1]['send_new_city'];
	
	var isClubToChange = document.getElementById('new_club') ? true : false;
	
	if(cityController.checked == false) {
		cityInput.className = cityInput.className + ' hide';
		citySelect.className = citySelect.className.replace('hide', '');
		cityController.checked = true;
		cityButton.value = window.stringBackToList;
		
		if(isClubToChange) {
			var clubController = document.forms[1]['is_new_club'];
			var clubButton = document.getElementById('send_new_club');
			if(clubController.checked == false) {
				swapClubInputs();
			}
			clubButton.className = clubButton.className + ' hide';
		}
		
	} else {
		citySelect.className = citySelect.className + ' hide';
		cityInput.className = cityInput.className.replace('hide', '');
		cityController.checked = false;
		cityButton.value = window.stringNewCity;
		if(isClubToChange) {
			var clubButton = document.getElementById('send_new_club');
			clubButton.className = clubButton.className.replace('hide', '');
		}
	}
	return false;
}

function swapClubInputs() {
	var clubInput = document.getElementById('location_id');
	var clubSelect = document.getElementById('new_club');
	var clubController = document.forms[1]['is_new_club'];
	var clubButton = document.forms[1]['send_new_club'];
	
	if(clubController.checked == false) {
		clubInput.className = clubInput.className + ' hide';
		clubSelect.className = clubSelect.className.replace('hide', '');
		clubController.checked = true;
		clubButton.value = window.stringBackToList;		
	} else {
		clubSelect.className = clubSelect.className + ' hide';
		clubInput.className = clubInput.className.replace('hide', '');
		clubController.checked = false;
		clubButton.value = window.stringNewClub;		
	}
	return false;
}

function swapInputs(from, to, controller, button, type) {
	
	var toHide = document.getElementById(from);
	var toShow = document.getElementById(to);
	var controller = document.forms[1][controller];
	
	if(controller.checked == false) {
		
		toHide.className = toHide.className + ' hide';
		toShow.className = toShow.className.replace('hide', '');
		controller.checked = true;
		button.value = window.stringBackToList;
		
		if((type == 'city') && (document.getElementById('new_club'))) { //ha &#195;&#186;j v&#195;&#161;ros, akkor &#195;&#186;j a klub is
			var clubSelect = document.getElementById('location_id');
			var clubInput = document.getElementById('new_club');
			var clubCheckbox = document.forms[1]['is_new_club'];
			var clubButton = document.getElementById('send_new_club');

			clubSelect.className = clubSelect.className + ' hide';
			clubInput.className = clubInput.className.replace('hide', '');
			clubCheckbox.checked = true;
			clubButton.value = window.stringBackToList;
		}
		
	} else { // vissza
		toShow.className = toShow.className + ' hide';
		toHide.className = toHide.className.replace('hide', '');
		controller.checked = false;		
		if(type == 'city') {button.value = window.stringNewCity;}
		else if(type == 'club') {button.value = window.stringNewClub;}
		
		if((type == 'city') && (document.getElementById('new_club'))) {
			var clubSelect = document.getElementById('location_id');
			var clubInput = document.getElementById('new_club');
			var clubCheckbox = document.forms[1]['is_new_club'];
			var clubButton = document.getElementById('send_new_club');
			if(clubCheckbox.checked)
			clubInput.className = clubInput.className + ' hide';
			clubSelect.className = clubSelect.className.replace('hide', '');
			clubCheckbox.checked = false;
			clubButton.value = window.stringNewClub;
		}
	}
	
	return false;
}


function changeGraph(rankListOption) {
	var imgToChange = document.getElementById('graph');
	var ids = rankListOption.split ("|");
	if(ids[0] == -1) {
		imgToChange.src = '/chart/rank_change_small.php?player_id=' + ids[1];
	} else {
		imgToChange.src = '/chart/rank_change_small.php?rank_list_id=' + ids[0] + '&member_id=' + ids[1];
	}
	document.getElementById('graph_img_anchor').onclick = function() {
		return open_layer('history', ids[0], ids[1]);
	}
	return false;
}

function open_slider(num, value_1, value_2) {
	$('sliders').style.display = 'block';
	if(value_1 == null) {
		value_1 = 0.50;
	}
	init_slider('slider_1', value_1);
	
	if(num == 2) {
		if(value_2 == null) {
			value_2 = 0.50;
		}
		init_slider('slider_2', value_2);
	}

	var controller = document.forms[1]['is_rated'];
	var rating_activator = document.getElementById('rating_activator');
	rating_activator.style.display = 'none';
	controller.checked = true;
	return false;
}

function hide_slider() {
	$('sliders').style.display = 'none';
	var controller = document.forms[1]['is_rated'];
	var rating_activator = document.getElementById('rating_activator');
	rating_activator.style.display = 'block';
	controller.checked = false;
	return false;
}

function init_slider(block_id, preset_value) {
	var slide_num = block_id.split('_')[1];
	var s1 = new Control.Slider('slider_' + slide_num + '_handler','slider_' + slide_num + '_bg', {axis:'horizontal', minimum: 0, maximum:120, alignX: 0, alignY: 0, disabled: false});
	
	var value_holder = document.forms[1]['player_' + slide_num + '_rate'];
	 
	 s1.options.onChange = function(value){
		 compute_backgr(value);
	}
	s1.options.onSlide = function(value){
		 compute_backgr(value);
	}
	
	function compute_backgr(value) {
		$('current_value_' + slide_num).style.width = (($('slider_' + slide_num + '_bg').clientWidth - 2) * value).toFixed() + 'px';
		value_holder.value = (value*100).toFixed();
	}
	
	s1.setValue(preset_value);
}

function open_ranklist(rootElement, from) {
	//var activeRank = document.getElementsByClassName('open_close_image');
	//for (var i = 0; i < activeRank.length; i++) {
	//	activeRank[i].style.display = 'inline';
	//}
	if(from == 'button') {
		var targetUL = rootElement.nextSibling.nextSibling.nextSibling.nextSibling;
		var targetIMG = rootElement.childNodes[0];
	} else if (from == 'text'){
		var targetUL = rootElement.nextSibling.nextSibling;
		var targetIMG = rootElement.parentNode.childNodes[0].childNodes[0];
		//targetIMG.style.display='none';
	}
	
	if(targetUL.className == 'show' ) {
		targetIMG.src = '/images/ranklist_opener.gif';
		targetUL.className = 'hide';
	} else {
		targetIMG.src = '/images/ranklist_closer.gif';
		targetUL.className = 'show';
	}

	rootElement.blur();
	return false;
}

function update_ranklist(e, type, id, selectedClassName, omitImgUpdate) {
	//if(!omitImgUpdate) {
		var activeRank = document.getElementsByClassName('open_close_image');
		for (var i = 0; i < activeRank.length; i++) {
			activeRank[i].style.display = 'inline';
		}
	//}

	if(e.parentNode.childNodes.length > 0 && e.parentNode.childNodes[0].childNodes.length > 0 && e.parentNode.childNodes[0].childNodes[0].className == 'open_close_image') {
		var targetIMG = e.parentNode.childNodes[0].childNodes[0];
		targetIMG.style.display='none';
	}

	var activeRank = document.getElementsByClassName('selected_all_players');
	for (var i = 0; i < activeRank.length; i++) {
		activeRank[i].className = '';
	}
	var activeRank = document.getElementsByClassName('selected_group');
	for (var i = 0; i < activeRank.length; i++) {
		activeRank[i].className = '';
	}
	var activeRank = document.getElementsByClassName('selected_country');
	for (var i = 0; i < activeRank.length; i++) {
		activeRank[i].className = '';
	}
	var activeRank = document.getElementsByClassName('selected_city');
	for (var i = 0; i < activeRank.length; i++) {
		activeRank[i].className = '';
	}

	var rank_container = document.getElementById('ranklist_data');
	rank_container.innerHTML = '';
	var url = '/ranking_list/squash-player_rankings.php?';
	if(type == 'country') {
		url += 'country=' + id;
	} else if(type == 'city') {
		url += 'city=' + id;
	} else if(type == 'group') {
		url += 'group=' + id;
	} else {
		url += 'whole_list=1';
	}
	new Ajax.Updater('ranklist_data', url);

	e.blur();
	e.className = selectedClassName;
	return false;
}

function add_timezone(id) {
	
	var timezones = document.forms[1]['timezones_added'].value;
	
	for(var i = 2; i <= 4; i++) {
		if(timezones.indexOf(i + '|') == -1) {
			var num = i;
			document.forms[1]['timezones_added'].value = document.forms[1]['timezones_added'].value + i +'|';
			i = 5;
		}
	}
	
	var inputs = document.getElementById('timezone' + num + '_input');
	var buttons = document.getElementById('timezone' + num + '_btns');
	var title = document.getElementById('timezone' + num + '_title');
	
//	if(document.forms[1]['timezones_added'].value.split('|').length == 4) {		
//		add_button.className = add_button.className.replace('show', 'hide');
		
//	} else {
//		add_button.className = add_button.className.replace('hide', 'show');
//	}
	buttons.className = buttons.className.replace(' hide', ' show');
	inputs.className = inputs.className.replace(' hide', ' show');
	title.className = title.className.replace('hide', 'show');

	return false;
}

function remove_timezone(id) {
	var inputs = document.getElementById('timezone' + id + '_input');
	var buttons = document.getElementById('timezone' + id + '_btns');
	var title = document.getElementById('timezone' + id + '_title');
	
	inputs.className = inputs.className.replace(' show', ' hide');
	buttons.className = inputs.className.replace(' show', ' hide');
	title.className = title.className.replace('show', 'hide');
	
	var timezones = document.forms[1]['timezones_added'].value;
	var timezones = timezones.replace(id + '|', '');
	document.forms[1]['timezones_added'].value = timezones;
	
	return false;
}

function open_block(e, button) {
	var target = document.getElementById(e);
	target.style.display = 'block';
	button.parentNode.className = 'open';
	button.onclick = function() {
		return close_block(e, button);
	};
	return false;
}

function close_block(e, button) {
	var target = document.getElementById(e);
	target.style.display = 'none';
	button.parentNode.className = 'closed';
	button.onclick = function() {
		return open_block(e, button);
	};
	return false;
}

Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});


function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function showSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

// ---------------------------------------------------

function hideSelectBoxes(){
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}

/* Multiple select add-remove items */

function OnTransferBtnClick(blnFromLeft){
	var LeftListBox = document.listForm.lstLeft;
	var RightListBox = document.listForm.lstRight;
	var ListItems = new Array();
	FromList = (blnFromLeft ? LeftListBox : RightListBox); 
	ToList = (blnFromLeft ? RightListBox : LeftListBox);
	for(var i=(FromList.options.length - 1);i>=0;i--)
		if(FromList.options[i].selected){
			ListItems[ListItems.length] = new Option(FromList.options[i].text, FromList.options[i].value);
			FromList.options[i] = null;
		} 
	for(var i=ListItems.length - 1;i>=0;i--)
		ToList.options[ToList.options.length] = ListItems[i];
} 
   

function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}


function showHideContPlayers() {
	if(document.getElementById('cancelled').checked) {
		document.getElementById('contPlayerFieldset').style.display="inline";
	} else {
		document.getElementById('contPlayerFieldset').style.display="none";
	}
}

// Statistics functions
function statSearchPlayer() {
	document.body.style.cursor="wait";
	document.getElementById('player_stat_players_found').innerHTML='';
	document.getElementById('player_stat_choose_other_player').innerHTML='';
	document.getElementById('player_stat_statistics').innerHTML='';
	var playerName = document.getElementById('player_name').value;
	var url = '/statistics/playersPopulatePlayersFound.php?player=' + playerName;
	new Ajax.Updater('player_stat_players_found', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});
	return false;
}

function statSearchOtherPlayers() {
	document.body.style.cursor="wait";
	document.getElementById('player_stat_choose_other_player').innerHTML='';
	document.getElementById('player_stat_statistics').innerHTML='';
	var selected =  document.getElementById('player_name_matches').value;
	var ids = selected.split('_');
	var url = '/statistics/playersPopulateOtherPlayers.php?player_id=' + ids[0] + '&rank_list_id=' + ids[1];
	new Ajax.Updater('player_stat_choose_other_player', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});
	return false;
}

function statShowPlayerStatistics(pid, rlid) {
	document.body.style.cursor="wait";
	document.getElementById('player_stat_statistics').innerHTML='';

	ListBox = document.getElementById('lstRight');
	var strChosenItems = "";
	var url = '/statistics/playersStatistics.php?rank_list_id=' + rlid + '&player_ids[]=' + pid;
	for(var i=0;i<ListBox.options.length;i++) 
		url = url + "&player_ids[]=" + ListBox.options[i].value;

	new Ajax.Updater('player_stat_statistics', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});

	return false;
}

function statShowGroupStatistics() {
	document.body.style.cursor="wait";
	document.getElementById('group_stat_statistics').innerHTML='';

	ListBox = document.getElementById('lstRight');
	var strChosenItems = "";
	var url = '/statistics/playersStatistics.php?group_id=' + document.getElementById('stat_group').value;
	new Ajax.Updater('group_stat_statistics', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});

	return false;
}


function statShowRankingList(rlid) {
	document.body.style.cursor="wait";
	var url = '/statistics/rankinglistStatistics.php?rank_list_id=' + rlid;
	new Ajax.Updater('stat_rankinglist', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});
	return false;
}

function addClubToStatList(locationId, locationName) {
	var targetSelect = document.getElementById('stat_selected_clubs');
	var contains = false;
	for(i = 0; i < targetSelect.options.length; i++) {
		if(targetSelect.options[i].value == locationId) {
			contains = true;
			break;
		}
	}
	if(!contains)
		targetSelect.options[targetSelect.options.length] = new Option(locationName, locationId);

	return false;
}

function removeSelectStatClub() {
	var targetSelect = document.getElementById('stat_selected_clubs');
	for (var i = 0; i < targetSelect.options.length; i++) { 
		if(targetSelect.options[i].selected)
			targetSelect.options[i] = null;
	}

	return false;
}

function statShowClubStatistics() {
	document.body.style.cursor="wait";
	var openTags = document.getElementsByClassName('show');
	for (var i = 0; i < openTags.length; i++) { 
		openTags[i].className = 'hide';
	}

	document.getElementById('stat_selected_clubs_statistics').innerHTML='';
	var clubList = document.getElementById('stat_selected_clubs');
	var strChosenItems = "";
	var url = '/statistics/clubsStatistics.php?';
	var first = true;
	for(var i=0; i<clubList.options.length; i++) {
		if(!first)
			url = url + "&";
		else
			first = false;

		url = url + "location_ids[]=" + clubList.options[i].value;
	}

	new Ajax.Updater('stat_selected_clubs_statistics', url, {
		onComplete:function(){
			document.body.style.cursor="default";
		},
		onException:function(){
			document.body.style.cursor="default";
		}
	});
	return false;
}

function focusLoginFormEmail() {
	document.popupLoginForm.email.focus();
	return false;
}

