function setCompetitionList(elID){
	var sel = document.getElementById(elID);
	if (sel) {
		sel.options.length = 0;
		sel.options[sel.options.length] = new Option("-- Välj tävling --", "XX");
		for(a = 0; a < competition.length; a++) {
			sel.options[sel.options.length] = new Option(competition[a]["name"], a);
		}
	}
}
function setLeagueList(coID, elID){
	var sel = document.getElementById(elID);
	sel.options.length = 0;
	sel.options[sel.options.length] = new Option("-- Välj klass --", "XX");

	if(coID != "XX"){
		if(sel.disabled) sel.disabled = false;
		for(a = 0; a < league[coID].length; a++){
			sel.options[sel.options.length] = new Option(league[coID][a]["name"], league[coID][a]["ID"]);
		}
	}
	else {
		sel.disabled = true;
	}
}
var lName = "";
var lMail = "";
var lPhone1 = "";
var lPhone2 = "";
var lPhone3 = "";
function checkLeader(leader){
	if (leader == "new") {
		document.getElementById("leadercontainer").innerHTML = "\n" +
			"<label for=\"contact\">Namn:</label><input name=\"contact\" id=\"contact\"  value=\"" + lName + "\" type=\"text\" />\n" +
			"<br class=\"clear\" />\n" +
			"<label for=\"email\">E-post:</label><input name=\"email\" id=\"email\" value=\"" + lMail + "\" type=\"text\" />\n" +
			"<br class=\"clear\" />\n" +
			"<label for=\"phone1\">Telefon 1:</label><input name=\"phone1\" id=\"phone1\" value=\"" + lPhone1 + "\" type=\"text\" />\n" +
			"<br class=\"clear\" />\n" +
			"<label for=\"phone2\">Telefon 2:</label><input name=\"phone2\" id=\"phone2\" value=\"" + lPhone2 + "\" type=\"text\" />\n" +
			"<br class=\"clear\" />\n" +
			"<label for=\"phone3\">Telefon 3:</label><input name=\"phone3\" id=\"phone3\" value=\"" + lPhone3 + "\" type=\"text\" />\n" +
			"<br class=\"clear\" />\n";
	}
	else {
		if (document.getElementById("leadercontainer").innerHTML.length > 500) {
			lName = document.getElementById("contact").value;
			lMail = document.getElementById("email").value;
			lPhone1 = document.getElementById("phone1").value;
			lPhone2 = document.getElementById("phone2").value;
			lPhone3 = document.getElementById("phone3").value;
		}
		document.getElementById("leadercontainer").innerHTML = "";
	}
}
function goPage(page){
	document.location.href = page;
}
var popup;
function popUpPage(url){
	var leftPos = (screen.width - 550);
	var topPos = (screen.height - 700) / 2;
	popup = window.open(url,'thePopUp','toolbar=0,status=0,directories=0,scrollbars=1,resizable=0,menubar=0,location=0,width=520,height=450,left=' + leftPos + ',top=' + topPos);
	if (popup) {
		popup.focus();
		return popup;
	}
	return popup;
}

function convertEmails(){
	spans = document.getElementsByTagName("span");
	numSpans = spans.length;
	for(i = 0; i < numSpans; i++){
		if(spans[i]){
			if(spans[i].className == "epost") {
				var at = new RegExp("\\(snabel\-a\\)", "i");
				var punkt = new RegExp("\\(punkt\\)", "ig");
				var contact = spans[i].firstChild.data.split("|");

				if (contact.length == 1) {
					address = spans[i].firstChild.data.replace(at, "@").replace(punkt, ".");
					theLink = document.createElement("A");
					theLink.setAttribute("href", "mailto:" + address);
					theLink.className = "email";
					theLink.appendChild(document.createTextNode(address));
					spans[i].parentNode.replaceChild(theLink, spans[i]);
				}
				else if (contact.length == 2) {
					address = contact[1].replace(at, "@").replace(punkt, ".");
					theLink = document.createElement("A");
					theLink.setAttribute("href", "mailto:" + address);
					theLink.className = "email";
					theLink.appendChild(document.createTextNode(contact[0]));
					spans[i].parentNode.replaceChild(theLink, spans[i]);
				}
			}
		}
	}
}
function convertEmails2(){
	spans = document.getElementsByTagName("span");
	numSpans = spans.length;
	for(i = 0; i < numSpans; i++){
		if(spans[i]){
			if(spans[i].className == "epost") {
				var at = new RegExp("\\(snabel\-a\\)", "i");
				var punkt = new RegExp("\\(punkt\\)", "ig");
				var contact = spans[i].firstChild.data.split("|");
				if (contact.length == 2) {
					address = contact[1].replace(at, "@").replace(punkt, ".");
					//spans[i].parentNode.setAttribute("onclick", "document.location.href='mailto:" + address +"'");
					theLink = document.createElement("A");
					theLink.setAttribute("href", "mailto:" + address);
					theLink.setAttribute("onfocus", "this.blur();");
					theLink.className = "email";
					theLink.appendChild(document.createTextNode(contact[0]));
					spans[i].parentNode.replaceChild(theLink, spans[i]);
				}
			}
		}
	}
}

sfHover = function() {
	var ietbl = document.getElementById("IEtables");
	if (ietbl) {
		sfEls = ietbl.getElementsByTagName("TD");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}

/**
 *
 * @access public
 * @return void
 **/
var img_path = "./img/";
var img_closed = "listLevel.png";
var img_open = "listLevel_open.png";
function closeopen(img, id){
	var img_url = img.src.split('/');
	var teamlist = document.getElementById(id);
	if (img_url[img_url.length-1] == img_closed) {
		img.src = img_path + img_open;
		teamlist.style.display = "inline";
	}
	else {
		img.src = img_path + img_closed;
		teamlist.style.display = "none";
	}
}

function init() {
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	convertEmails();
}


function expandContract(_lmnt) {
	if (_lmnt.parentNode.className == "open") {
		_lmnt.parentNode.className = "closed";
		_lmnt.parentNode.firstChild.src = "img/plus.gif";
	}
	else {
		_lmnt.parentNode.className = "open";
		_lmnt.parentNode.firstChild.src = "img/minus.gif";
	}
}
