/**
 * @author nexum AG
 */

/* Ermitteln des Browsers und Einbung des passenden Stylesheets */
if (navigator.appName.indexOf("Explorer") != -1) {
	document.write('<link rel="stylesheet" type="text/css" href="/triathlon/style/triathlon_ie.css" media="screen"/>');
} else {
	if (navigator.appName.indexOf("Opera") != -1) {
		document.write('<link rel="stylesheet" type="text/css" href="/triathlon/style/triathlon_op.css" media="screen"/>');;
	}
}

/* LOKAL - Ermitteln des Browsers und Einbung des passenden Stylesheets */
/*if (navigator.appName.indexOf("Explorer") != -1) {
	document.write('<link rel="stylesheet" type="text/css" href="../style/triathlon_ie.css" media="screen"/>');
} else {
	if (navigator.appName.indexOf("Opera") != -1) {
		document.write('<link rel="stylesheet" type="text/css" href="../style/triathlon_op.css" media="screen"/>');;
	}
}*/




/* Navigationselement onMouserOver und onMouseOut */

function navMouseOver(number) {
	
	if (navigator.appName.indexOf("Explorer") != -1) {
		document.getElementById("nav_begin_" + number).style.backgroundPositionY = "-136px";
		document.getElementById("nav_middle_" + number).style.backgroundPositionY = "-136px";
		document.getElementById("nav_end_" + number).style.backgroundPositionY = "-136px";
		document.getElementById("nav_begin_" + number).style.backgroundColor = "#FFED00";
		document.getElementById("nav_middle_" + number).style.backgroundColor = "#FFED00";
		document.getElementById("nav_end_" + number).style.backgroundColor = "#FFED00";
		document.getElementById("nav_point_" + number).style.color = "#E31818";
	}
	else {
		document.getElementById("nav_begin_" + number).style.setProperty('background-position','-49px -136px',null);
		document.getElementById("nav_middle_" + number).style.setProperty('background-color','#FFED00',null);
		document.getElementById("nav_end_" + number).style.setProperty('background-position','-96px -136px',null);
		document.getElementById("nav_point_" + number).style.color = "#E31818";
	}
} 

function navMouseOut(number) {
	
	if (navigator.appName.indexOf("Explorer") != -1) {
		document.getElementById("nav_begin_" + number).style.backgroundPositionY = "-101px";
		document.getElementById("nav_middle_" + number).style.backgroundPositionY = "-101px";
		document.getElementById("nav_end_" + number).style.backgroundPositionY = "-101px";
		document.getElementById("nav_begin_" + number).style.backgroundColor = "#005187";
		document.getElementById("nav_middle_" + number).style.backgroundColor = "#005187";
		document.getElementById("nav_end_" + number).style.backgroundColor = "#005187";
		document.getElementById("nav_point_" + number).style.color = "#FFFFFF";
	}
	else {
		document.getElementById("nav_begin_" + number).style.setProperty('background-position','-49px -101px',null);
		document.getElementById("nav_middle_" + number).style.setProperty('background-color','#005187',null);
		document.getElementById("nav_end_" + number).style.setProperty('background-position','-96px -101px',null);
		document.getElementById("nav_point_" + number).style.color = "#FFFFFF";
	}
}


/* Chained Select mit Deaktivierung */

/* Optionsfeld hinzufügen */
function addOption(selectbox,text,value)
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

/* Wettbewerb */
function addCompetitionBasketball() {
	addOption(document.getElementById('DDLcompetition'), "NBA", "cb1");
	addOption(document.getElementById('DDLcompetition'), "Weltmeisterschaft", "cb2");
	addOption(document.getElementById('DDLcompetition'), "EU-Meisterschaft", "cb3");
	addOption(document.getElementById('DDLcompetition'), "DLL", "cb4");
}
function addCompetitionFussball() {
	addOption(document.getElementById('DDLcompetition'), "1. Bundesliga", "cf1");
	addOption(document.getElementById('DDLcompetition'), "2. Bundesliga", "cf2");
	addOption(document.getElementById('DDLcompetition'), "3. Bundesliga", "cf3");
	addOption(document.getElementById('DDLcompetition'), "UEFA Cup", "cf4");
	addOption(document.getElementById('DDLcompetition'), "Championslique", "cf5");
}
function addCompetitionHandball() {
	addOption(document.getElementById('DDLcompetition'), "Wettbewerb 1", "ch1");
	addOption(document.getElementById('DDLcompetition'), "Wettbewerb 2", "ch2");
}
function addCompetitionVolleyball() {
	addOption(document.getElementById('DDLcompetition'), "Wettbewerb 3", "cv1");
	addOption(document.getElementById('DDLcompetition'), "Wettbewerb 4", "cv2");
}
function addCompetitionAll() {
	addCompetitionBasketball();
	addCompetitionFussball();
	addCompetitionHandball();
	addCompetitionVolleyball();
}

/* Saison */
function addSeasonCommon() {
	addOption(document.getElementById('DDLseason'), "Saison 2008", "ss08");
	addOption(document.getElementById('DDLseason'), "Saison 2007", "ss07");
	addOption(document.getElementById('DDLseason'), "Saison 2006", "ss06");
	addOption(document.getElementById('DDLseason'), "Saison 2005", "ss05");
}
function addSeasonEM() {
	addOption(document.getElementById('DDLseason'), "EM 2006", "em06");
	addOption(document.getElementById('DDLseason'), "EM 2002", "em02");
	addOption(document.getElementById('DDLseason'), "EM 1998", "em98");
	addOption(document.getElementById('DDLseason'), "EM 1994", "em94");
}
function addSeasonWM() {
	addOption(document.getElementById('DDLseason'), "WM 2006", "wm06");
	addOption(document.getElementById('DDLseason'), "WM 2002", "wm02");
	addOption(document.getElementById('DDLseason'), "WM 1998", "wm98");
	addOption(document.getElementById('DDLseason'), "WM 1994", "wm94");
}
function addSeasonAll() {
	addSeasonCommon();
	addSeasonEM();
	addSeasonWM();
}

/* Videotype */
function addVideotype() {
	addOption(document.getElementById('DDLvideotype'), "Spiel", "game");
	addOption(document.getElementById('DDLvideotype'), "Live", "live");
}

/* Titel / Teams */
function addTitleBasketball() {
	addOption(document.getElementById('DDLtitle'), "Team A - Team B", "tb1");
	addOption(document.getElementById('DDLtitle'), "Team C - Team D", "tb2");
	addOption(document.getElementById('DDLtitle'), "Team E - Team F", "tb3");
	addOption(document.getElementById('DDLtitle'), "Team G - Team H", "tb4");
}
function addTitleFussball() {
	addOption(document.getElementById('DDLtitle'), "Team A - Team B", "tf1");
	addOption(document.getElementById('DDLtitle'), "Team C - Team D", "tf2");
	addOption(document.getElementById('DDLtitle'), "Team E - Team F", "tf3");
	addOption(document.getElementById('DDLtitle'), "Team G - Team H", "tf4");
}
function addTitleHandball() {
	addOption(document.getElementById('DDLtitle'), "Team A - Team B", "th1");
	addOption(document.getElementById('DDLtitle'), "Team C - Team D", "th2");
	addOption(document.getElementById('DDLtitle'), "Team E - Team F", "th3");
	addOption(document.getElementById('DDLtitle'), "Team G - Team H", "th4");
}
function addTitleVolleyball() {
	addOption(document.getElementById('DDLtitle'), "Team A - Team B", "tv1");
	addOption(document.getElementById('DDLtitle'), "Team C - Team D", "tv2");
	addOption(document.getElementById('DDLtitle'), "Team E - Team F", "tv3");
	addOption(document.getElementById('DDLtitle'), "Team G - Team H", "tv4");
}
function addTitleAll() {
	addTitleBasketball();
	addTitleFussball();
	addTitleHandball();
	addTitleVolleyball;
}

// Auswertungen der Sportart
function getCompetition(sel) {
	
	var competitionCode = sel.options[sel.selectedIndex].value;
	
	if (competitionCode == "") {
		document.getElementById('DDLcompetition').disabled = true;
		document.getElementById('DDLseason').disabled = true;
		document.getElementById('DDLvideotype').disabled = true;
		document.getElementById('DDLtitle').disabled = true;
	}
	else {
	
		document.getElementById('DDLcompetition').disabled = false;
		document.getElementById('DDLcompetition').options.length = 2;
		
		// Alle
		if (competitionCode.length > 0 && competitionCode == "all") {
			addCompetitionAll();
		}
		// Basketball
		if (competitionCode.length > 0 && competitionCode == "basketball") {
			addCompetitionBasketball();
		}
		// Fussball
		if (competitionCode.length > 0 && competitionCode == "fussball") {
			addCompetitionFussball();
		}
		// Handball
		if (competitionCode.length > 0 && competitionCode == "handball") {
			addCompetitionHandball();
		}
		// Volleyball
		if (competitionCode.length > 0 && competitionCode == "volleyball") {
			addCompetitionVolleyball();
		}
	}
}

// Auswertungen des Wettbewerbs
function getSeason(sel) {
	var seasonCode = sel.options[sel.selectedIndex].value;
	
	if (seasonCode == "") {
		document.getElementById('DDLseason').disabled = true;
		document.getElementById('DDLvideotype').disabled = true;
		document.getElementById('DDLtitle').disabled = true;
	}
	else {
	
		document.getElementById('DDLseason').disabled = false;
		document.getElementById('DDLseason').options.length = 2;
		
		// Alle
		if (seasonCode.length > 0 && seasonCode == "all") {
			addSeasonAll();
		}
		// Basketball
		if (seasonCode.length > 0 && seasonCode == "cb1") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cb2") {
			addSeasonWM();
		}
		if (seasonCode.length > 0 && seasonCode == "cb3") {
			addSeasonEM();
		}
		if (seasonCode.length > 0 && seasonCode == "cb4") {
			addSeasonCommon();
		}
		// Fussball
		if (seasonCode.length > 0 && seasonCode == "cf1") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cf2") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cf3") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cf4") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cf5") {
			addSeasonCommon();
		}
		// Handball
		if (seasonCode.length > 0 && seasonCode == "ch1") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "ch2") {
			addSeasonCommon();
		}
		// Volleyball
		if (seasonCode.length > 0 && seasonCode == "cv1") {
			addSeasonCommon();
		}
		if (seasonCode.length > 0 && seasonCode == "cv2") {
			addSeasonCommon();
		}
	}
}

// Auswertungen der Saison
function getVideotype(sel) {
	var videoCode = sel.options[sel.selectedIndex].value;
	
	if (videoCode == "") {
		document.getElementById('DDLvideotype').disabled = true;
		document.getElementById('DDLtitle').disabled = true;
	}
	else {
		document.getElementById('DDLvideotype').disabled = false;
		document.getElementById('DDLvideotype').options.length = 2;
		addVideotype();
	}
}

// Auswertungen des Videotyps
function getTitle(sel) {
	var titleCode = sel.options[sel.selectedIndex].value;
	
	if (titleCode == "") {
		document.getElementById('DDLtitle').disabled = true;
	}
	else {
		document.getElementById('DDLtitle').disabled = false;
		var finalCode = document.getElementById('DDLsportkind').value;

		// Alle
		if (finalCode.length > 0 && finalCode == "all") {
			addTitleAll();
		}
		// Basketball
		if (finalCode.length > 0 && finalCode == "basketball") {
			addTitleBasketball();
		}
		// Fussball
		if (finalCode.length > 0 && finalCode == "fussball") {
			addTitleFussball();
		}
		// Handball
		if (finalCode.length > 0 && finalCode == "handball") {
			addTitleHandball();
		}
		// Volleyball
		if (finalCode.length > 0 && finalCode == "volleyball") {
			addTitleVolleyball();
		}
	}
}



/* Funktion für den Tooltip auf der Archive-Seite */

tooltip = null;
 
document.onmousemove = updateTooltip;
 
function updateTooltip(e) {
  if (tooltip != null) {
  	if (navigator.appName.indexOf("Explorer") != -1 && parseInt(navigator.appVersion) < 7) {
		
		if(document.getElementById('search_success') != null) {
			x = (document.all) ? window.event.x + tooltip.offsetParent.scrollLeft : e.pageX;
		  	y = (document.all) ? window.event.y + tooltip.offsetParent.scrollTop : e.pageY;
		  	tooltip.style.left = (x + 400) + "px";
		  	tooltip.style.top = (y + 330) + "px";
		} else {
			x = (document.all) ? window.event.x + tooltip.offsetParent.scrollLeft : e.pageX;
		  	y = (document.all) ? window.event.y + tooltip.offsetParent.scrollTop : e.pageY;
		  	tooltip.style.left = (x + 320) + "px";
		  	tooltip.style.top = (y + 620) + "px";
		}
  	}
	else if (navigator.appName.indexOf("Explorer") != -1) {
		x = (document.all) ? window.event.x + tooltip.offsetParent.scrollLeft : e.pageX;
	  	y = (document.all) ? window.event.y + tooltip.offsetParent.scrollTop : e.pageY;
	  	tooltip.style.left = (x + 310) + "px";
	  	tooltip.style.top = (y + 550) + "px";
  	}
  	else {
	  	x = (document.all) ? window.event.x + tooltip.offsetParent.scrollLeft : e.pageX;
	  	y = (document.all) ? window.event.y + tooltip.offsetParent.scrollTop : e.pageY;
	  	tooltip.style.left = (x + 20) + "px";
	  	tooltip.style.top = (y + 20) + "px";
  	}
  }
}
 
function openTooltip(rowID) {
	document.getElementById(rowID).style.backgroundColor = "#F1F1F1";
	document.getElementById(rowID).style.color = "#01295a";
	
	if (navigator.appName.indexOf("Explorer") != -1) {
		document.getElementById(rowID).style.backgroundPositionY = "-18px";
	}
	else {
		
		var btClass = document.getElementById(rowID).getAttribute("class")
		
		if (btClass == "btBuy") {
			document.getElementById(rowID).style.setProperty('background-position','-329px -18px',null);
		} else {
			document.getElementById(rowID).style.setProperty('background-position','-409px -18px',null);
		}
	}
	
  	tooltip = document.getElementById("TT" + rowID);
	//tooltip.style.display = "block";
  	dojo.fadeIn({node:'TT' + rowID}).play();
	//opacity('TT' + rowID, 0, 100, 500);
}
 
function hideTooltip(rowID) {
	document.getElementById(rowID).style.backgroundColor = "#FFFFFF";
	document.getElementById(rowID).style.color = "#7D7D7D";
	
	if (navigator.appName.indexOf("Explorer") != -1) {
		document.getElementById(rowID).style.backgroundPositionY = "-51px";
	}
	else {
		var btClass = document.getElementById(rowID).getAttribute("class")
		
		if (btClass == "btBuy") {
			document.getElementById(rowID).style.setProperty('background-position','-329px -51px',null);
		} else {
			document.getElementById(rowID).style.setProperty('background-position','-409px -51px',null);
		}
	}
	
	opacity('TT' + rowID, 100, 0, 500);
	//tooltip.style.display = "none";
}

function opacity(id, opacStart, opacEnd, millisec) {
    var speed = Math.round(millisec / 100);
    var timer = 0;

    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
			if (i == opacEnd)
				document.getElementById(id).style.display = "none";
        }
    } else if(opacStart < opacEnd) {
		document.getElementById(id).style.visibly = "hidden";
		document.getElementById(id).style.opacity = 0;
	    document.getElementById(id).style.MozOpacity = 0
	    document.getElementById(id).style.KhtmlOpacity = 0;
		document.getElementById(id).style.display = "block";
		document.getElementById(id).style.visibly = "visible";
        for(i = opacStart; i <= opacEnd; i++)
           {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 



/* Funktion für die Seitennummerierung des Suchergebnisses */

var success = "none";
var countResult = 0;
var displayNodesFrom;
var displayNodesTo;
var resultPerPage = 8;
var countPages = 0;

var pageLoad = null;

function createPageNumbers(){

	if (pageLoad == null) {

		success = document.getElementById('search_success').style.display;
		
		if (success != "none") {
			
			if (navigator.appName.indexOf("Explorer") != -1 || navigator.appName.indexOf("Explorer") != -1 && parseInt(navigator.appVersion) < 7) {

				countResult = document.getElementsByName('search_result').length;
				
				// erstellen der Seitenzahlen
				if ((countResult % resultPerPage) == 0) {
					countPages = countResult / resultPerPage;
				}
				else {
					countPages = Math.ceil(countResult / resultPerPage);
				}
				
				if (countPages > 1) {
				
					document.getElementById('search_page_navigation').style.display = "block";
					document.getElementById('search_page_navigation').innerHTML = "";
					
					for (i = 0; i < countPages; i++) {
					
						if (i == (countPages - 1)) {
							document.getElementById('search_page_navigation').innerHTML += "<button onclick=\"updatePageNumbers('"+(i+1)+"');\">" + (i + 1) + "</button>";
						}
						else {
							document.getElementById('search_page_navigation').innerHTML += "<button onclick=\"updatePageNumbers('"+(i+1)+"');\">" + (i + 1) + "</button> | ";
						}
					}
					
				}
				else {
					document.getElementById('search_page_navigation').style.display = "none";
				}
				document.getElementById('resultCounts').innerHTML = countResult + "&nbsp;";
				
			} else {
				countResult = document.getElementsByClassName('search_result').length;
				
				// erstellen der Seitenzahlen
				if ((countResult % resultPerPage) == 0) {
					countPages = countResult / resultPerPage;
				}
				else {
					countPages = Math.ceil(countResult / resultPerPage);
				}
				
				if (countPages > 1) {
				
					document.getElementById('search_page_navigation').style.display = "block";
					document.getElementById('search_page_navigation').innerHTML = "";
					
					for (i = 0; i < countPages; i++) {
					
						if (i == (countPages - 1)) {
							document.getElementById('search_page_navigation').innerHTML += "<button id=\"page"+(i+1)+"\" onclick=\"updatePageNumbers('"+(i+1)+"');\">" + (i + 1) + "</button>";
						}
						else {
							document.getElementById('search_page_navigation').innerHTML += "<button id=\"page"+(i+1)+"\" onclick=\"updatePageNumbers('"+(i+1)+"');\">" + (i + 1) + "</button> | ";
						}
					}
					
				}
				else {
					document.getElementById('search_page_navigation').style.display = "none";
				}
				
				document.getElementById('page1').style.color = "#000000";
				document.getElementById('page1').style.textDecoration = "none";
				
				document.getElementById('search_success').style.display = "block";
				document.getElementById('search_failure').style.display = "none";
			}
			
			updatePageNumbers('1');
			
		}
		else {
			document.getElementById('search_success').style.display = "none";
			document.getElementById('search_failure').style.display = "block";
			document.getElementById('search_page_navigation').style.display = "none";
		}
		
		document.getElementById('resultCounts').innerHTML = countResult;
		pageLoad = 1;
	}
}

function updatePageNumbers(pagenumber){

	var i = 1;
	
	// reset des Suchergebnisses
	for (i; i < (countResult +1); i++) {
		document.getElementById('search' + i).style.display = "none";
	}
	
	if (navigator.appName.indexOf("Explorer") != -1) {
	
		var j = 1;
		
		// reset der Suchergebnisseiten
		//for (j; j < (countPages + 1); j++) {
			//document.getElementById('page' + j).style.color = "#7E7E7E";
			//document.getElementById('page' + j).style.textDecoration = "underline";
		//}
		
		//document.getElementById('page' + pagenumber).style.textDecoration = "none";
		//document.getElementById('page' + pagenumber).style.color = "#000000";
		
		if (pagenumber == "1") {
			displayNodesFrom = 1;
			displayNodesTo = resultPerPage;
		}
		else {
			displayNodesFrom = ((pagenumber - 1) * resultPerPage) + 1;
			displayNodesTo = pagenumber * resultPerPage;
		}
		
		if (displayNodesTo > countResult) {
			for (displayNodesFrom; displayNodesFrom < (countResult + 1); displayNodesFrom++) {
				document.getElementById('search' + displayNodesFrom).style.display = "block";
			}
		}
		else {
			for (displayNodesFrom; displayNodesFrom < (displayNodesTo + 1); displayNodesFrom++) {
				document.getElementById('search' + displayNodesFrom).style.display = "block";
			}
		}
	} else {
		var j = 1;
		
		// reset der Suchergebnisseiten
		for (j; j < (countPages + 1); j++) {
			document.getElementById('page' + j).style.color = "#7E7E7E";
			document.getElementById('page' + j).style.textDecoration = "none";
		}
		
		document.getElementById('page' + pagenumber).style.color = "#000000";
		document.getElementById('page' + pagenumber).style.textDecoration = "none";
		
		if (pagenumber == "1") {
			displayNodesFrom = 1;
			displayNodesTo = resultPerPage;
		}
		else {
			displayNodesFrom = ((pagenumber - 1) * resultPerPage) + 1;
			displayNodesTo = pagenumber * resultPerPage;
		}
		
		if (displayNodesTo > countResult) {
			for (displayNodesFrom; displayNodesFrom < (countResult + 1); displayNodesFrom++) {
				document.getElementById('search' + displayNodesFrom).style.display = "block";
			}
		}
		else {
			for (displayNodesFrom; displayNodesFrom < (displayNodesTo + 1); displayNodesFrom++) {
				document.getElementById('search' + displayNodesFrom).style.display = "block";
			}
		}
	}
}
