var bodyOnloadArray = new Array();
var changeMenueTimeout;

function commonOnLoad(){
  var i = 0;
  for(i=0;i<bodyOnloadArray.length;i++){
    bodyOnloadArray[i]();
  }
}
var gameWindow;
function callGameApplet(gamename){
	callApplet('gameFrame.jsp?gameName=' + gamename + '&sessionID=' + sessionId);
}
function callApplet(param){
	if(param.indexOf("://")==-1){
		param = globalLoginProtocol+globalDomain+'/gaming/'+param;		
	}
	gameWindow = window.open(param, "gameFrame", "width=1012,height=762,top=0,left=0,status=no,resizable=no,scrollbars=yes");
	gameWindow.focus();
}
		/*******************************************************************************/
		/* Password securitybar  																											 */
		/* In the Registerform we have this bar to check the strongness of the password*/
		/* Values:  																																	 */
		/* strPass 			= Value of the Passwordfield 																	 */
		/* strId   			= ID of the bar-area 																					 */
		/* strClassname = StyleClassName of the bar-area 															 */
		/*******************************************************************************/
		
		function contains(strText, strPattern)
		{
		 for (i = 0; i < strText.length; i++)
		 {
		 if (strPattern.indexOf(strText.charAt(i)) > -1) return true;
		 }
		 return false;
		}
		
		function checkPass(strPass, strId, strClassname){
		 var s = false;
		 var l = false;
		 nCombinationCount = 0;
		
		 strToCheck = "0123456789";
		 if(strPass.length>=6 && contains(strPass, strToCheck)){
		 	 nCombinationCount=nCombinationCount+3;
			 
			 strToCheck = "abcdefghijklmnopqrstuvwxyz"; // überprüfen ob kleine Buchstaben vorkommen
			 if (contains(strPass, strToCheck)){
			 	s = true;
			 }
			 
			 strToCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // überprüfen ob grosse Buchstaben vorkommen
			 if (contains(strPass, strToCheck)){
			 	l = true;
			 }
			 
			 // mixed case
			 if(l && s)
			 	nCombinationCount=nCombinationCount+2;
			 
			 strToCheck = ",;:-_=+|//?^&!.@$£#*()%~<>{}[]";// übersprüfen ob Sonderzeichen vorkommen
			 if (contains(strPass, strToCheck)) 
			 	nCombinationCount=nCombinationCount+3;
			
			if(strPass.length>8)		
				nCombinationCount=nCombinationCount+2;

		 	oId = document.getElementById(strId);
		 	oId.className = strClassname + "-" + nCombinationCount;
		 	
		 }else{
		 	oId = document.getElementById(strId);
			oId.className = strClassname + "-0";
		 }
		
		}
		
		/********************************************************************************/
		/* Register ControllQuestion Switch  																					  */
		/* On a special Selection of the "Kontrollfrage" we switch to an normal 			  */
		/* Inputfield where we can enter our special Question. The second function 		  */
		/* switch back to the Kontrollfragen-Selektbox 																  */
		/********************************************************************************/
		function showControlQuestion(){
			if(document.register_a_form.j_question_sel.options[document.register_a_form.j_question_sel.selectedIndex].value == '-1'){
				document.getElementById("questionSel").style.display = "none";
				document.getElementById("questionText").style.display = "block";
	        }
		}
		function showQuestionList(){
			document.register_a_form.j_question_sel.selectedIndex = 0;
			document.getElementById("questionSel").style.display = "block";
			document.getElementById("questionText").style.display = "none";
		}
		
		
		/********************************************************************************/
		/* Toggle the ResultBlocks																							        */
		/* Parameter = divID = The ID of the whole Block    			  										*/
		/* Parameter = headerDivId = The ID of the HeaderBlock 		  										*/
		/* Parameter = linkDivId = The ID of the Link in the Headerblock								*/
		/********************************************************************************/	
		function ToggleResultBlocks(divID, headerDivId, linkDivId ) {
			 var e = document.getElementById(divID);
			 var a = document.getElementById(headerDivId);
			 var b = document.getElementById(linkDivId);
       if(e.style.display == 'block') {
          e.style.display = 'none';
          a.className = 'resultBlockHeaderInActive';
          b.className = 'resultBlockHeaderTextLinkInActive';
       } else {
          e.style.display = 'block';
          a.className = 'resultBlockHeaderActive';
          b.className = 'resultBlockHeaderTextLinkActive';
       }
    }
    
    /*******************************************************************************/
		/* showGameBoxFlyingTeaser										                                 */   
		/* show and hide a div which displays on mouseover/out a teaser  							 */
		/* Values:  																																	 */
		/* divId 					= Value of the div we will show/hide				  							 */
		/* displAttribute = Value of the displaystyle (block or none)									 */
		/*******************************************************************************/
		function showGameBoxFlyingTeaser(divId,displAttribute) {
			var currentID = document.getElementById(divId);
			if (currentID) {
				// here we hide / display the flyingTeaser
				eval("currentID.style.display='"+displAttribute+"';");
			}
		}
		/****************************************************************/
		/* EcardThumScroller                                            */
		/* Used in Tell-A-Friend - The Ecard Scroller									  */
		/* Parameter:                                                   */
		/*           direction  = back or forward                       */
		/*           imageWidth = Pixelwidth of one Image               */
		/* Info: A maximum of lenght for the Slider is given in the     */
		/*       object.css - #eCardSlider #imgBlock ul 			          */
		/****************************************************************/
		function EcardThumbScroller(direction,imageWidth) {
				
				var imgList 			 = document.getElementById('imgBlock');
				var numberOfImages = imgList.getElementsByTagName('li').length;
				var curPos 				 = parseInt(imgList.style.left,10);
				var maxLeftPos     = 0 - (numberOfImages * imageWidth);
				var stopLeftPos    = maxLeftPos + (imageWidth * 3);
				
				// Slide the Images to left
				if (direction == "left") {
						if (curPos > stopLeftPos || curPos == 0) {
							var a = curPos - imageWidth;
							imgList.style.left = a + "px";
						}
				}
				// Slide the Images to right
				if (direction == "right") {
						if (curPos < 0) {
						var b = curPos + imageWidth;
						imgList.style.left = b + "px";
					 }
				}
		}
		function AvatarThumbScroller(direction,imageWidth) {
				var imgList 			 = document.getElementById('imgBlock');
				var numberOfImages = imgList.getElementsByTagName('li').length/4;
				var curPos 				 = parseInt(imgList.style.left,10);
				var maxLeftPos     = 0 - (numberOfImages * imageWidth);
				var stopLeftPos    = maxLeftPos + (imageWidth);
				
				// Slide the Images to left
				if (direction == "left") {
						if (curPos > stopLeftPos || curPos == 0) {
							var a = curPos - imageWidth;
							imgList.style.left = a + "px";
						}
				}
				// Slide the Images to right
				if (direction == "right") {
						if (curPos < 0) {
						var b = curPos + imageWidth;
						imgList.style.left = b + "px";
					 }
				}
		}

 
function browserabfrage() {
	if (document.layers) {
		browser = 'ns';
	} else {
		if ((navigator.userAgent.indexOf('MSIE') != -1) && !(navigator.userAgent.indexOf('Opera') != -1)) {
			if (navigator.platform == "Win32") {
				browser = 'ie'; 
			} else {
				browser = 'iemac';
			}
		}else{
			browser='ns6';
		}
	}
}

browserabfrage();

function showHideDetail(num) {			
	if (browser != "ns") {
		var id = ""+num;
		var tmpClassName = "none";
		var pfeil = "detailpfeil"+num;
		var trId = "tr"+num;
			
		if(document.getElementById(id).style.display=="none") {
			tmpClassName = "";
							
			eval("document."+pfeil+".src='/images/lottoResult_arrowUp.png'");
			document.getElementById(trId).className = "active";
		} else {
			eval("document."+pfeil+".src='/images/lottoResult_arrowDown.png'");
			document.getElementById(trId).className = "";
		}
		document.getElementById(id).style.display=tmpClassName;
	}
}		

function hideDetails(count) {
	if (browser != "ns") {
		for (var i=0; i<=count; i++) {
			var id =i;
			document.getElementById(id).style.display="none";
		}
	}
}			

function downloadFile(){
	if(document.downloadForm.extension[0].checked == true){
		document.downloadForm.action = document.downloadForm.filenameSel.options[document.downloadForm.filenameSel.selectedIndex].value+".xls";
		document.downloadForm.submit();
	}else if(document.downloadForm.extension[1].checked == true){
		document.downloadForm.action = document.downloadForm.filenameSel.options[document.downloadForm.filenameSel.selectedIndex].value+".csv";
		document.downloadForm.submit();
	}else 
		alert("Bitte eine Auswahl treffen");
}

function downloadFile(formName){
	if(formName == "downloadForm1"){
	 	if(document.downloadForm1Ext.extension[0].checked == true){
	 		document.downloadForm1Ext.action = document.downloadForm1.filenameSel.options[document.downloadForm1.filenameSel.selectedIndex].value+".xls";
	 		document.downloadForm1Ext.submit(); 
		 }else if(document.downloadForm1Ext.extension[1].checked == true){
	 	 	document.downloadForm1Ext.action = document.downloadForm1.filenameSel.options[document.downloadForm1.filenameSel.selectedIndex].value+".csv";
 			document.downloadForm1Ext.submit();		 
		 }else
			  alert("Bitte eine Auswahl treffen");
    }else if(formName == "downloadForm2"){
	 	if(document.downloadForm2Ext.extension[0].checked == true){
	 		  document.downloadForm2Ext.action = document.downloadForm2.filenameSel.options[document.downloadForm2.filenameSel.selectedIndex].value+".xls"; 
	 	 	  document.downloadForm2Ext.submit();
		 }else if(document.downloadForm2Ext.extension[1].checked == true){
	 		  document.downloadForm2Ext.action = document.downloadForm2.filenameSel.options[document.downloadForm2.filenameSel.selectedIndex].value+".csv"; 
	 	 	  document.downloadForm2Ext.submit();
		 }else
			  alert("Bitte eine Auswahl treffen");
    }

}

function changeMenueTo(index, countTopNavi, countSubNavi) {
	if(index==0) {
		changeMenueTimeout = setTimeout("processChangeMenueTo("+index+", "+countTopNavi+", "+countSubNavi+")",300);
	} else {
		stopClearingMenue();
		setMenueTimeout = setTimeout("processChangeMenueTo("+index+", "+countTopNavi+", "+countSubNavi+")",300);
		//processChangeMenueTo(index,countTopNavi, countSubNavi);
	}
}
function stopClearingMenue() {
	window.clearTimeout(changeMenueTimeout);
}
function stopSettingMenue() {
	window.clearTimeout(setMenueTimeout);
}
function processChangeMenueTo(index, countTopNavi, countSubNavi) {
	for(var i=1; i<=countTopNavi; i++) {
		var idStr = "topnav"+String(i);
		if(document.getElementById(idStr)!=null)
			document.getElementById(idStr).className="#";
		idStr = "subnav"+String(i);
		if(document.getElementById(idStr)!=null)
			document.getElementById(idStr).className="hide";
	}
	if(index>0) {
		document.getElementById("topnav"+index).className="hier";
		if(document.getElementById("subnav"+index)!=null)
			document.getElementById("subnav"+index).className="nohide";
		
		// change arrows left position
		if(document.getElementById("topnav"+index)!=null) {
			if(document.getElementById("arrow"+index)!=null) {
				var newLeft = Number(document.getElementById("topnav"+index).offsetLeft)+(Number(document.getElementById("topnav"+index).offsetWidth)/2) - 15;
				document.getElementById("arrow"+index).style.left = newLeft+'px';
			}
		}
	}
}


/* webgate */
function resizeFrame() {
	var f = document.getElementById('webgateFrame');
	var frameHeight = f.contentWindow.document.body.scrollHeight;
	if(Number(f.contentWindow.document.body.scrollHeight) != 'NaN') {
		if(Number(f.contentWindow.document.body.scrollHeight) < 625) {
			frameHeight = 625;
		}
	}
	f.style.height = frameHeight + "px";
}

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?"));
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}
