/* suckerfish functions */

sfHover = function() {
	var sfEls = document.getElementById('TopMenu').getElementsByTagName('ul');
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].parentNode.onmouseover = function() {
			this.lastChild.className += ' pshover';
		}
		sfEls[i].parentNode.onmouseout = function() {
			this.lastChild.className = this.lastChild.className.replace(new RegExp(' pshover\\b'), '');
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/* hide the country and team select go button and sub menu, if we can (as then suckerfish will be working)

hideNonJS = function() {
	var bGo = document.getElementById('CountryTeamGo');
	if (bGo) bGo.style.display = 'none';
	bGo = document.getElementById('TeamGo');
	if (bGo) bGo.style.display = 'none';
	bGo = document.getElementById('CountryGo');
	if (bGo) bGo.style.display = 'none';
	var subEl = document.getElementById('SubMenu');
	if (subEl) subEl.style.display = 'none';
}
window.onload = hideNonJS; */


/* other functions */

function doFormReload() {
	var formObj = getObj('UserForm');
   	formObj.submit();
}

function doCountryChange(thisSel, urlParam) {
    var hrefString = document.location.href;
    var newParam = '/' + urlParam + '/' + thisSel.options[thisSel.selectedIndex].value;
    var paramSubStringStart = hrefString.indexOf('/' + urlParam + '/');
    if (paramSubStringStart > -1)	{
    	var newHrefString = hrefString.substring(0, paramSubStringStart) + newParam;
    	var paramSubStringEnd = hrefString.indexOf('/', paramSubStringStart + urlParam.length + 2);
    	if (paramSubStringEnd > -1)	{
    		newHrefString += hrefString.substr(paramSubStringEnd);
		}
    	document.location.href = newHrefString;
    } else {
    	document.location.href += newParam;
    }
}

function doCountryChangePreSEO(thisSel, urlParam) {
    var hrefArray = document.location.href.split('&');
    var isReplaced = false;
    for (var i in hrefArray)	{
    	if (hrefArray[i].substr(0, urlParam.length + 1) == urlParam + '=')	{
    		hrefArray[i] = urlParam + '=' + thisSel.options[thisSel.selectedIndex].value;
    		isReplaced = true;
    		break;
    	}
    }
    if (isReplaced)	{
    	document.location.href = hrefArray.join('&');
    } else {
    	document.location.href += '&' + urlParam + '=' + thisSel.options[thisSel.selectedIndex].value;
    }
}

function doLoadTeams(thisSel) {
	fTeam = document.getElementById('team_id');
	if (fTeam)	{
		fTeam.options.length=0;
		fTeam.options[0] = new Option (thisSel.options[thisSel.selectedIndex].value, 'testValue');
	}
}

function openWindow(theURL,winName,features) { //v2.0
    nw=window.open('http://www.footballfanscensus.com/' + theURL,winName,features);
    window.nw.moveTo(0,0);
}

function printPage() {
	window.print(); 
}

function doSelectedValue(valueField, selectField)	{
	var selObj = getObj(selectField);
	var valObj = getObj(valueField);
	valObj.value = selObj.options[selObj.selectedIndex].value;
}

function doFocus(fieldName)	{
	var fieldObj = getObj(fieldName);
	fieldObj.focus();
}

function getObj(objID) {
	var theObj = document.getElementById(objID);
	if (!theObj) return false;
	return theObj;
}