﻿var pos = 0;
	 var current_url = "";
	 var humanyTimeout;
	 var results = 0;
	 var last_ans;
	 var lastShow;
	 var hSajt = "http://secure2.humany.com/skelleftea/";

	 function hideResult() {
		document.getElementById('humanyTop').style.display = 'none';
		document.getElementById('humanyBottom').style.display = 'none';
		document.getElementById('search-hit-info-44').style.display = 'none';
		document.getElementById('section-56').style.display = 'none';
		document.getElementById('section-57').style.display = 'none';
		document.getElementById('section-88').style.display = 'none';
		document.getElementById('search-suggest-container').style.display = 'none';
	 }
	 function showResult(typ) {
		if (typeof typ == "undefined") {
			typ = lastShow;
		}
		document.getElementById('humanyTop').style.display = 'block';
		document.getElementById('humanyBottom').style.display = 'block';
		if (typ == "all") {
			document.getElementById('section-88').className = 'section-search-hits';
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-56').style.display = 'block';
			document.getElementById('section-88').style.display = 'block';
			document.getElementById('section-57').style.display = 'block';
		}
		else if (typ == "both") {
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-88').style.display = 'none';
			document.getElementById('section-56').style.display = 'block';
			document.getElementById('section-57').style.display = 'block';
		}
		else if (typ == "faq_vod") {
			document.getElementById('section-88').className = 'section-first section-search-hits';
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-56').style.display = 'none';
			document.getElementById('section-88').style.display = 'block';
			document.getElementById('section-57').style.display = 'block';
		}
		else if (typ == "link_vod") {
			document.getElementById('section-88').className = 'section-search-hits';
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-57').style.display = 'none';
			document.getElementById('section-56').style.display = 'block';
			document.getElementById('section-88').style.display = 'block';
		}
		else if (typ == "link") {
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-57').style.display = 'none';
			document.getElementById('section-88').style.display = 'none';
			document.getElementById('section-56').style.display = 'block';
		}
		else if (typ == "faq") {
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-56').style.display = 'none';
			document.getElementById('section-88').style.display = 'none';
			document.getElementById('section-57').style.display = 'block';
		}
		else if (typ == "vod") {
			document.getElementById('section-88').className = 'section-first section-search-hits';
			document.getElementById('search-hit-info-44').style.display = 'none';
			document.getElementById('section-56').style.display = 'none';
			document.getElementById('section-57').style.display = 'none';
			document.getElementById('section-88').style.display = 'block';
		}
		if(document.getElementById('sokord').value != "") document.getElementById('search-suggest-container').style.display = 'block';
	 }
	 function showAnswer() {
		document.getElementById('section-56').style.display = 'none';
		document.getElementById('section-57').style.display = 'none';
		document.getElementById('section-88').style.display = 'none';
		document.getElementById('search-hit-info-44').style.display = 'block';
		document.getElementById('humanyTop').style.display = 'block';
		document.getElementById('humanyBottom').style.display = 'block';
		if(document.getElementById('sokord').value != "") document.getElementById('search-suggest-container').style.display = 'block';
	 }
	 function getResult() {
		 var humanyinput = document.getElementById('sokord').value;
		 if(humanyinput != "") {
			humanyinput = humanyinput.replace(/\r\n/g, "");
			var headTag = document.getElementsByTagName("head").item(0); 
			var scriptTag = document.createElement("script"); 
			scriptTag.src = hSajt + "suggest_loadb.asp?entry=" + escape(humanyinput)
			headTag.appendChild(scriptTag);
		 }
		 else hideResult();
	 }
	 function humanyOpenFaq(id) {
		 humanyRegisterClick(id);
		 if (id == last_ans) {
			showAnswer();
		 }
		 else if (id != "") {
			var headTag = document.getElementsByTagName("head").item(0); 
			var scriptTag = document.createElement("script"); 
			scriptTag.src = hSajt + "suggest_loadb.asp?tq_id=" + id
			headTag.appendChild(scriptTag);
		 }
	 }
	 function OpenTQ(id) {
		 humanyRegisterClick(id);
		 if (id == last_ans) {
			showAnswer();
		 }
		 else if (id != "") {
			var headTag = document.getElementsByTagName("head").item(0); 
			var scriptTag = document.createElement("script"); 
			scriptTag.src = hSajt + "suggest_loadb.asp?tq_id=" + id
			headTag.appendChild(scriptTag);
		 }
	 }
	 function humanyPageL(page) {
		 var humanyinput = document.getElementById('sokord').value;
		 if(humanyinput != "") {
			 humanyinput = humanyinput.replace(/\r\n/g, "");
			 var headTag = document.getElementsByTagName("head").item(0); 
			 var scriptTag = document.createElement("script"); 
			 scriptTag.src = hSajt + "suggest_loadb.asp?entry=" + escape(humanyinput) + "&pageL=" + page;
			 headTag.appendChild(scriptTag);
		 }
	}
	function humanyPageF(page) {
		 var humanyinput = document.getElementById('sokord').value;
		 if(humanyinput != "") {
			 humanyinput = humanyinput.replace(/\r\n/g, "");
			 var headTag = document.getElementsByTagName("head").item(0); 
			 var scriptTag = document.createElement("script"); 
			 scriptTag.src = hSajt + "suggest_loadb.asp?entry=" + escape(humanyinput) + "&pageF=" + page;
			 headTag.appendChild(scriptTag);
		 }
	}
	function humanyPageV(page) {
		 var humanyinput = document.getElementById('sokord').value;
		 if(humanyinput != "") {
			 humanyinput = humanyinput.replace(/\r\n/g, "");
			 var headTag = document.getElementsByTagName("head").item(0); 
			 var scriptTag = document.createElement("script"); 
			 scriptTag.src = hSajt + "suggest_loadb.asp?entry=" + escape(humanyinput) + "&pageV=" + page;
			 headTag.appendChild(scriptTag);
		 }
	}
	function suggest() {
		 clearTimeout(humanyTimeout);
		 var humanyinput = document.getElementById('sokord').value;
		 humanyTimeout = setTimeout("getResult()",350);
		 return true;
	}
	 function humanyInit() {

		/*var headTag = document.getElementsByTagName("head").item(0); 
		var cssTag = document.createElement("link");
		cssTag.href = hSajt + "SearchSuggest.css";
		cssTag.rel = "stylesheet";
		cssTag.type = "text/css";
		headTag.appendChild(cssTag);*/

	 

		entryBottom = document.getElementById('sokord').offsetTop + document.getElementById('sokord').offsetHeight;
		//entryRight = (document.getElementById('viviannQuestion').offsetLeft + document.getElementById('viviannQuestion').offsetWidth;
		entryRight = document.getElementById('sokord').offsetLeft;
		//alert(document.getElementById('sokord').offsetParent.offsetLeft);
		var suggestTag = document.createElement("div");
		suggestTag.style.position = "relative";
		suggestTag.style.top = '-20px';
		//suggestTag.style.left = '40px';
		//suggestTag.style.top = '35px';
		suggestTag.style.left = '-10px'; //-160px
		//suggestTag.style.top = entryBottom + 'px';
		//suggestTag.style.left = entryRight + 'px';
		suggestTag.style.zIndex = '9999999';

		suggestTag.id = "search-suggest-container";
		suggestTag.style.display = "none";
		suggestTag.innerHTML = "<div class=\"search-suggest\" tabindex=\"-1\"><div id=\"humanyTop\" class=\"top\" style=\"display:none\"><img src=\"http://secure2.humany.com/skelleftea/Images/clear.gif\" /></div><div class=\"center\"><div class=\"section-first section-search-hits\" id=\"section-56\"></div><div class=\"section-first section-search-hits\" id=\"section-88\"></div><div class=\"section-search-hits\" id=\"section-57\"></div><div id=\"search-hit-info-44\" class=\"section-first section-search-hit-info section-hidden\"></div></div><div id=\"humanyBottom\" class=\"bottom\" style=\"display:none\"><img src=\"http://secure2.humany.com/skelleftea/Images/clear.gif\" /></div></div>"
		//document.body.appendChild(suggestTag);
		document.getElementById('topFunctions').appendChild(suggestTag);
		document.getElementById('sokord').onkeydown=function(){
			suggest();
		}
	 }
	 function humanyYes() {
		document.getElementById("humanyNo").checked=false;
	 }
	 function humanyNo() {
		document.getElementById("humanyYes").checked=false;
	 }
	 function humanyLog(tq_id) {
		 if(tq_id == "") return false;
		 var headTag = document.getElementsByTagName("head").item(0); 
		 var scriptTag = document.createElement("script"); 
		 scriptTag.src = hSajt + "log.asp?tq_id=" + tq_id;
		 //headTag.appendChild(scriptTag);
		 return true;
	 }
  	function humanyRegisterClick(id) {
   		if(id == "") return false;
   		var headTag = document.getElementsByTagName("head").item(0); 
   		var scriptTag = document.createElement("script"); 
   		scriptTag.src = "http://admin.humany.com/viasat_search/regClick.asp?id=" + escape(id);
   		//headTag.appendChild(scriptTag);
   		return true;
  	}

	function check(e){
		var target = (e && e.target) || (event && event.srcElement);
		var obj = document.getElementById('search-suggest-container');
		var obj2 = document.getElementById('sokord');
		checkParent(target)?obj.style.display='none':null;
		if(document.getElementById('sokord').value != "") {
			target==obj2?obj.style.display='block':null;
		}
	}
	function checkParent(t){
		while(t.parentNode){
		if(t==document.getElementById('search-suggest-container')){
		return false
		}
		t=t.parentNode
		}
		return true
		}
	document.onclick=check;

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
	addLoadEvent(humanyInit);
