function AfficheHomePage()
{
if (document.all && document.getElementById)
 {
 document.write('<A HREF="#" onClick="HomePage(this);return(false);">Homepage</A>');
 }
}

function HomePage(url){
        if (navigator.userAgent.indexOf("MSIE")!=-1) {
                document.body.style.behavior='url(#default#homepage)';
                document.body.setHomePage(url);
        } else {
                alert('Sorry, not supported in this browser,  change this setting manually');
        }
}

function openPopup(url, width, height)
{
    window.open(url, '_blank', 'width='+width+',height='+height);
}


function changeQuickSearch(searchtype)
{
	for (x=0;x<6;x++) {
	document.links['l'+x].style.fontWeight = 'normal';
	}
	if (searchtype == "clubs") {
	document.qksearch['fields[]'].value = 'shortname';
	document.qksearch['searchtype'].value = "0";
	document.links['l0'].style.fontWeight = 'bold';
	}
	else if (searchtype == "stadiums") {
	document.qksearch['fields[]'].value = 'longname';
	document.qksearch['searchtype'].value = 1;
	document.links['l1'].style.fontWeight = 'bold';
	}
	else if (searchtype == "players") {
	document.qksearch['fields[]'].value = 'lastname';
	document.qksearch['searchtype'].value = 2;
	document.links['l2'].style.fontWeight = 'bold';
	}
	else if (searchtype == 'referees') {
	document.qksearch['fields[]'].value = 'lastname';
	document.qksearch['searchtype'].value = 3;
	document.links['l3'].style.fontWeight = 'bold';
	}
	else if (searchtype == 'coachs') {
	document.qksearch['fields[]'].value = 'lastname';
	document.qksearch['searchtype'].value = 4;
	document.links['l4'].style.fontWeight = 'bold';
	}
	else if (searchtype == 'news') {
	document.qksearch['fields[]'].value = 'title';
	document.qksearch['searchtype'].value = 5;
	document.links['l5'].style.fontWeight = 'bold';
	}
	else {
	document.qksearch['fields[]'].value = 'lastname';
	document.qksearch['searchtype'].value = 2;
	document.links['l1'].style.fontWeight = 'bold';
	}
	
}


function toggleElementVisibility(el)
{
    if (el.style.display != 'block') {
        showElement(el);
    } else {
        hideElement(el);
    }
}

function hideElement(el)
{
	el.style.display = 'none';
}

function showElement(el)
{
	el.style.display = 'block';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(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;
}




/** Magic Dropdowns **/

var magicdropdowns = new Array();
var magicdropdownButtonHandled = false;

function magicdropdownButtonClick(tag)
{
	magicdropdownButtonHandled = true;
	// TODO: hide other dropdowns

	// show requested dropdown
	el = magicdropdowns[tag];
	toggleElementVisibility(el);
}

function magicdropdownOptionClick(tag, optionValue, optionText)
{
	// change text
	var textEl = document.getElementById('magicdropdown-text-'+tag);
	textEl.innerHTML = optionText;
	textEl.style.color = '#000000';

	// TODO: change hidden form value to optionValue

	// hide dropdown
	hideElement(magicdropdowns[tag]);
}

function magicdropdownClickHandler(event)
{
	if (!magicdropdownButtonHandled) {
	// TODO: hide all dropdowns
	}

	magicdropdownButtonHandled = false;
}

function magicdropdownInit()
{
	document.onclick = magicdropdownClickHandler;
	magicdropdowns = new Array();
}

function magicdropdownRegister(tag)
{
	magicdropdowns[tag] = document.getElementById('magicdropdown-dropdown-'+tag);
}

