
		/*
		 * Copyright (c) 2006 Wazap AG, Germany -- all rights reserved.
		 */
		 			var hdCatMenTimer = null;
					var curSearchCateg = 0;
					var searchCategs = new Array();
					var currentMode = null;
					var currentType = null;
					var development = false;

		/* Definition of SearchCategs */
    	
		var defaultSubmitCaption = "搜索";
		var sessionLanguage = "cn";
				
		
		searchCategs[searchCategs.length] = new searchCateg('网页','result',1,'#02294d','#77a6d2','web','/gamesearch.php?','web','/');

		
		searchCategs[searchCategs.length]= new searchCateg('游戏百科','games,gamepage,review,ratings,screenshots',1,'#324d02','#b1e115','catalog','/katalogsearch.php?','startcat','/katalog.php'); 
		

 		if (development){

		
		searchCategs[searchCategs.length] = new searchCateg('游戏攻略','cheats',1,'#af0c0c','cheats','/cheats?');

		
		searchCategs[searchCategs.length] = new searchCateg('游戏新闻','news',1,'#259c00','news','/news?');

		
		searchCategs[searchCategs.length] = new searchCateg('游戏下载','downloads',1,'#79009c','downloads','/downloads?');

		
		searchCategs[searchCategs.length] = new searchCateg('其它信息','articles',0,'#b18e01','articles','/artikel?');

		
		searchCategs[searchCategs.length] = new searchCateg('图片','result',0,'#000000','pictures','/result?');

		
		searchCategs[searchCategs.length] = new searchCateg('价格比较','result',0,'#605e54','price','/result?');

		
		searchCategs[searchCategs.length] = new searchCateg('分级','result',0,'#bc4c01','ratings','/result?');

		
		searchCategs[searchCategs.length] = new searchCateg('电子竞技','result',0,'#421e01','esports','/result?');

		}//end if development


		
		preLoadImages();

		/*
		 *SearchCateg object
		 */
		function searchCateg(caption, mode, forList,brdColor,bgColor,themeId,targetUrl,startMode,startUrl){
			this.caption = caption;
			this.mode = mode;
			this.borderColor = brdColor;
			this.bgColor = bgColor;
			this.themeId = themeId;
			this.targetUrl = targetUrl;
			this.forList = (forList==null)? 0:forList; // set true, if the Item should be shown above searchfield
			this.startMode = startMode;
			this.startUrl = startUrl;
		}

	   function getObj(id){return document.getElementById(id);}

		function buildSubmitForm(index,query){
			if(index==1){//footer
				document.write('<input class="fl ftq" type="text" id="ftInputField" name="query" value="' + query + '" />'); 
				document.write("<a href=\"javascript:clickTab(null,1)\"><span id=\"ftSubmit\" class=\"spnFtSubmit fl\">" + defaultSubmitCaption + "</span></a>");
			}else{
				document.write('<input class="fl hdq" type="text" id="hdInputField" name="query" value="' + query + '" />');
				document.write("<a href=\"javascript:clickTab(null,0)\"><span id=\"hdSubmit\" class=\"spnHdSubmit fl\">" + defaultSubmitCaption + "</span></a>");
			}
		}

		/*
		 * Build searchcategories for header/footer if javascript is active
		 * else see noscript in header.jspf
		 */
		function buildCatList(index){

			last4List = -1;
			x = searchCategs.length-1;
			while(last4List < 0 ){
				if(searchCategs[x].forList==1 || x==0)
					last4List = x;
				else
					x--;
			}

			listName = (index==1)? "ftCatList":"hdCatList";
			document.write("<ul id=\"" + listName +"\" class=\"cb\" >");

			for(i=0;i<searchCategs.length;i++){
				if(searchCategs[i].forList==1){
					tmpClass = (i == last4List)? "": "hdsep";
					document.write( "<li id=\"" + listName + "_" + i + "\" class=\"" + tmpClass + "\">");
					document.write("<a href=\"javascript:clickTab(" + i + "," + index + ")\" onmouseover=\"return winState()\" onmouseout=\"return winState()\">");
					document.write( searchCategs[i].caption);
					document.write("</a></li>");
				}
			}
			if(!development && (index == 0) && (sessionLanguage == "de"))
				document.write("<li class='comingSoon'><img id='hdsoon' src='/images/service2.gif'/></li>");

			document.write("</ul>");

			if(index==0){
				soon = getObj("hdsoon");
		 		if(soon){
		  			soon.onmouseover = function(){this.src = "/images/service_over.gif";}
  		  			soon.onmouseout = function(){ this.src = "/images/service2.gif";}
		 		}
			}
		}


		/*
		 * change selected SearchCateg
		 */
		function selectCat(catId,index){
		    if(catId==null) 	return;

	    	listName = (index==1)? "ftCatList":"hdCatList";
			catList=getObj(listName).getElementsByTagName("li");
			curItem = getObj(listName + "_" + curSearchCateg);
            isLastItem = (curItem==catList[catList.length-1])? true:false;

			// reset current selection
			if(curItem != null){
				curItem.className=(isLastItem)? "":" hdsep";
				curItem.style.backgroundImage = (isLastItem)? "none":"url(/images/hdCatListSeparator.gif)";
//				curItem.getElementsByTagName("a")[0].style.border="0px none";

                if(getObj("ftCatList_" + curSearchCateg))
					getObj("ftCatList_" + curSearchCateg).className=(isLastItem)? "":" hdsep";
			}

			// set new Selection
			curSearchCateg = (catId==null)? curSearchCateg:catId;
			element = getObj(listName + "_" + curSearchCateg);

			// Change searchbar style
			tid = searchCategs[curSearchCateg].themeId;
			myHdsb = getObj("hdsb");
			myHdsb.style.borderColor=searchCategs[curSearchCateg].borderColor;
			myHdsb.style.backgroundColor=searchCategs[curSearchCateg].bgColor;
			myHdsb.style.backgroundImage="url(/images/searchbar/" + tid + "_bg.gif)";

			//Change catlist style
			if(element != null){
				setSubmitCaption(defaultSubmitCaption, index);

				if(index==0){
					try{
						element.className = "selected ";
						element.style.backgroundImage = "url(/images/searchbar/" + tid + "_li.gif)";
						element.getElementsByTagName("a")[0].style.borderColor=searchCategs[curSearchCateg].borderColor;
						element.blur();
					}catch(ex){
						handleException(ex.message)
					}
				}
				else{
					element.className = (element==catList[catList.length-1])? "selected":"selected hdsep";
				}

			}else{
				/* if the selected category is not in the list, but in the dropdown change the caption of the submitbutton */
				setSubmitCaption(searchCategs[curSearchCateg].caption, index);
			}

		}

		function setSubmitCaption(caption,index){
			try{
				xSpnSubmit = getObj((index==0)? "hdSubmit":"ftSubmit");
				if(parseInt(xSpnSubmit.offsetWidth) < 125){
					xSpnSubmit.style.width = "115px";
				}

				wBefore = parseInt(xSpnSubmit.offsetWidth);
				xSpnSubmit.innerHTML = caption;
				wAfter = parseInt(xSpnSubmit.offsetWidth);
				//resizeQ(wBefore - wAfter, index);

			}catch(ex){
				handleException("setSubmitCaption:" + ex.message);
			}
		}

		/*
		 * 	resize the inputfield according to the submitbutton
		 */
		function resizeQ(diff, index){
			xQ = getObj((index==0)? "hdInputField":"ftInputField");
			offsetDiff = xQ.offsetWidth - parseInt(xQ.style.width);
			newSize = parseInt(xQ.offsetWidth) + diff - offsetDiff;
			xQ.style.width = newSize +"px";
		}


		/*
		 * fix highlight bug by setting width of each category
		 * this function is called, when the header is build for the first time
		 */
		function prepareCatList(mode,index){

			currentMode = mode;
			listId = (index==0)? "hdCatList":"ftCatList";
			catList=getObj(listId).getElementsByTagName("li");
			for(i=0;i<catList.length;i++){
			   if(catList[i].className != "comingSoon"){
				  catList[i].style.width = (catList[i].offsetWidth + 8) +"px";
				}
			   
			   if(i==0 && (navigator.userAgent.indexOf("MSIE")!=-1))
				   catList[i].style.marginLeft="0px";
			}
			//detect searchCategory by type/mode
			mode = mode? mode:'';
			for(i=0;i<searchCategs.length;i++)
				if(searchCategs[i].mode.indexOf(mode) > -1 || searchCategs[i].startMode == mode ){
					selectCat(i,index);
					return;
			    }
			selectCat(0,index);   // fall back to 'web'
		}

		/*
		 * Build output for DropDown SearchCategMenu
		 */
		function buildCatMenu(){
			if (!development) return;

			//button
			document.write("<a id=\"hdDropDown\" class=\"fl\"  href=\"javascript:void(0)\" onclick=\"showHdCatMenu()\"><img src=\"static/img/hdDropDown.gif\"/></a>");
			// div
			document.write("<div id=\"hdCatMenu\" onclick=\"hideHdCatMenu()\" onmouseover=\"hdCatMenuOver()\" onmouseout=\"hdCatMenuOut()\">");
			document.write("<ul>");

			// Build menuItems
			for(i=0;i<searchCategs.length;i++){
				document.write("<li><a href=\"javascript:submitForm(" + i + ",0)\">");
				document.write( searchCategs[i].caption);
				document.write("</a></li>");
			}
			document.write("</ul></div>");

			men = getObj("hdCatMenu");
			menUl = men.getElementsByTagName("ul")[0];

			 // platz schaffen fuer das dropdown image
		     xQ = document.getElementById("hdInputField");
		     hdDrpDwn = document.getElementById("hdDropDown");
		     xQ.style.width = xQ.offsetWidth + "px";
		     offsetDiff = - 24 - (xQ.offsetWidth - parseInt(xQ.style.width)) ;//24:size of dropdown image
		     resizeQ(offsetDiff, 0);
		}

		function showHdCatMenu(){
			catMen = getObj("hdCatMenu");
			if( catMen.style.display!="block"){
				reference = getObj("hdSubmit");
				if(catMen!= null){
					if(reference!=null){
						catMen.style.left = reference.offsetLeft +"px";
						catMen.style.top = reference.offsetTop + reference.offsetHeight +"px";
					}
				catMen.style.display="block"; // show menu
				}
			}else{
				catMen.style.display="none";
			}
		}

		function hideHdCatMenu(){
			catMen = getObj("hdCatMenu");
			catMen.style.display="none";
		}

		function hdCatMenuOut(){
			hdCatMenTimer = window.setTimeout('hideHdCatMenu()',500);
		}

		function hdCatMenuOver(){
			window.clearTimeout(hdCatMenTimer);
		}

		/*
		 * remove leading and following spaces from text
		 */
		function trim(value) {
			var temp = value;
			var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
			if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
			var obj = /  /g;
			while (temp.match(obj)) { temp = temp.replace(obj, " "); }
			return temp;
		}
		
		function clickTab(catId,index){
			toStartpage = (isEmptyQuery(index))? true:false ;

			curSearchCateg = (catId==null)? curSearchCateg:catId;
			cat = searchCategs[curSearchCateg];

			if(!toStartpage){
				submitForm(catId,index);
			}else{ // goto category's startpage
				f = (index==0)? getObj("hdForm"):getObj("ftForm");;
			 	f.action = cat.startUrl;
			 	f.submit();
			}
		}

		/*
		 * validate value of inputfield
		 */
		function isEmptyQuery(index){
			xQ = (index==0)? "hdInputField":"ftInputField";
			query = trim(getObj(xQ).value);
			return (query.length<1)? true:false;
		}

		/*
		 * submit form to the requested page
		 */
		function submitForm(catId,index){
			
				
			curSearchCateg = (catId==null)? curSearchCateg:catId;
			cat = searchCategs[curSearchCateg];
		 	f = (index==0)? getObj("hdForm"):getObj("ftForm");;
			f.action = cat.targetUrl;
			f.submit();
			return false;
		}

		function preLoadImages(){
		 var imageCache = new Array();
		   for(i=0;i<searchCategs;i++){
  		     tid = searchCategs[i].themeId;
		     cache = new Array();
		     cache[0] = new Image();
             cache[0].src = "/images/searchbar/" + tid + "_bg.gif";
		     cache[1] = new Image();
             cache[1].src = "/images/searchbar/" + tid + "_li.gif";
  	      	 imageCache[i] = cache;
		  }
		}

     function setFocus(){
      	var hdq = document.getElementById("hdInputField");
      	if (hdq) {
	      	if (hdq.value == '') {
	       		hdq.focus();
	       	}
	      }
     }

          
		