/******************************************************************************
* javascript.js                                                               *
*******************************************************************************
* Invotech Solutions CMS		                                              *
* =========================================================================== *
* Software Version:           IS CMS 1.1                                      *
* Software by:                Invotech Solutions (http://www.invotech.se)	  *
* Copyright 2004-2007 by:     Invotech Solutions HB (http://www.invotech.se)  *
* Support:  				  kontakt@invotech.se	                          *
*******************************************************************************
* Detta program är reglerat av licensavtal av Invotech Solutions		      *
*                                                                             *
* Se "license.txt" för deltaljer om Invotech Solutions HB licensavtal.	      *
*																			  *
******************************************************************************/
//window.onerror=function(){return true;};
var ajaxObjects = new Array();
function calendar_nav2(str,element)
{
	document.getElementById('divLoaderFrame').style.visibility = 'visible';
	var ajaxqs = "";
	var ajaxIndex = ajaxObjects.length;	
	ajaxObjects[ajaxIndex] = new sack();
	var ajaxqs = "&ajax=true";

	if(element)
		ajaxObjects[ajaxIndex].element = element;
	
	ajaxObjects[ajaxIndex].onCompletion = function() { document.getElementById('divLoaderFrame').style.visibility = 'hidden';ajaxObjects[ajaxIndex].element.innerHTML = ajaxObjects[ajaxIndex].response; } ;	// Specify function that will be executed after file has been found
	
	ajaxObjects[ajaxIndex].requestFile = str + ajaxqs;	// Specifying which file to get
//alert(ajaxObjects[ajaxIndex].requestFile);
	ajaxObjects[ajaxIndex].runAJAX(); // Execute AJAX function
}

function openhelp(){
	var height = 400;
	var width = 550;
	var x = (screen.Height/2) - (height/2);
	var y = (screen.Width/2) - (width/2);
	var url="modules/search/help.php";
	newwindow = window.open(url,"","width="+width+",height="+height+",top="+x+",left="+y+",scrollbars=yes,resizable=no");
}

function getOffsetX(oNode)
{
	var iOffsetLeft = 0;

	while(oNode.offsetParent)
	{
		iOffsetLeft += oNode.offsetLeft;
		oNode = oNode.offsetParent;
	}

	iOffsetLeft += document.body.offsetLeft;

	return iOffsetLeft;
}

function getOffsetY(oNode)
{
	var iOffsetTop = 0;

	while(oNode.offsetParent)
	{
		//alert(oNode.type);
		iOffsetTop += oNode.offsetTop;
		oNode = oNode.offsetParent;
	}

	iOffsetTop += document.body.offsetTop;
	
	return iOffsetTop;
}

function mouseX(evt)
{
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	else return null;
}
function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	else return null;
}
	
function openlogin(lnkobj)
{
	alignedlayer_open(lnkobj,document.getElementById('divLoginFrame'));
	if(document.forms['frmLogin'].login_name)
		document.forms['frmLogin'].login_name.focus();
}
function closelogin()
{
	alignedlayer_close();
}

var linklayerobj = null;
function alignedlayer_open(linkobj,layerobj) // makes layer visible, puts it beside clicked link and makes sure it doesn't fall offscreen
{
	var parentwidth = (document.documentElement.offsetWidth ? document.documentElement.offsetWidth : document.body.offsetWidth);
	var parentheight = (document.documentElement.offsetHeight ? document.documentElement.offsetHeight : document.body.offsetHeight);
	x = getOffsetX(linkobj);
	y = getOffsetY(linkobj);
	var left = ((x+layerobj.offsetWidth) > parentwidth) ? (x - layerobj.offsetWidth) : x;
	var top = ((y+layerobj.offsetHeight) > parentheight) ? (y - layerobj.offsetHeight) : (y + linkobj.offsetHeight);
	layerobj.style.visibility = 'visible';
	layerobj.style.top = top+'px';
	layerobj.style.left = left+'px';
	linklayerobj = layerobj; // set global var used to hide layer later
}
function alignedlayer_close() // closes layer referenced by alignedlayer_open
{
	if(linklayerobj){
		linklayerobj.style.visibility = 'hidden';
		linklayerobj = null;
	}
}

/* IE6 PNG FIX*/
/*var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
if (itsAllGood && navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	document.writeln('<style type="text/css">img, input.image { visibility:hidden; } </style>');
	window.attachEvent("onload", fixPNG);
}*/

function fixPNG() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7.0);
		//for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
	if (itsAllGood)
	{
		var imgs = document.getElementsByTagName('IMG');
		for(var i=0;i<imgs.length;i++)
		{
			var img = imgs[i];
			if (img.src.match(/\.png$/i) != null)
			{
				fnFixPng(img);
				img.attachEvent("onpropertychange", fnPropertyChanged);
			}
			img.style.visibility = "visible";
		}

		var nl = document.getElementsByTagName("INPUT");
		for (var i = nl.length - 1, e = null; (e = nl[i]); i--) {
			if (e.className && e.className.match(/\bimage\b/i) != null) {
				if (e.src.match(/\.png$/i) != null) {
					fnFixPng(e);
					e.attachEvent("onpropertychange", fnPropertyChanged);
				}
				e.style.visibility = "visible";
			}
		}
	}
}

function fnPropertyChanged() {
	if (window.event.propertyName == "src") {
		var el = window.event.srcElement;
		if (!el.src.match(/x\.gif$/i)) {
			el.filters.item(0).src = el.src;
			el.src = "images/x.gif";
		}
	}
}

function dbg(o) {
	var s = "";
	var i = 0;
	for (var p in o) {
		s += p + ": " + o[p] + "\n";
		if (++i % 10 == 0) {
			alert(s);
			s = "";
		}
	}
	alert(s);
}

function fnFixPng(img) {
	var src = img.src;
	img.style.width = img.width + "px";
	img.style.height = img.height + "px";
	img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
	img.src = "/images/transparentPixel.gif";
}
/* END IE6 PNG FIX*/

var shiftkeyispressed = false;
function catchKeyDown(evt)
{//alert('DOWN');
	var keyCode = evt.keyCode || evt.which;
	if ((keyCode == 18)) {
		shiftkeyispressed = true;
		return false;
	}
	return true;
}
function catchKeyUp(evt)
{
	var keyCode = evt.keyCode || evt.which;
	if ((keyCode == 18)) {
		shiftkeyispressed = false;
		return false;
	}
	return true;
}
function catchMouseDown(evt)
{//alert('DOWN');
	var keyCode = evt.button || evt.which;
	if ((keyCode == 2)) {
		shiftkeyispressed = true;
		return false;
	}
	return true;
}
function catchMouseUp(evt)
{//alert('DOWN');
	var keyCode = evt.button || evt.which;
	if ((keyCode == 2)) {
		shiftkeyispressed = false;
		return false;
	}
	return true;
}
function addEvent(obj, evType, fn, useCapture)
{
// General function for adding an event listener
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	}
	else {
		alert("handler could not be attached");
	}
}
function addKeyEvent()
{
// Specific function for this situation
	evtDown = (document.addEventListener) ? 'mousedown' : 'mousedown';
	addEvent(document,evtDown,catchMouseDown,false);
	evtDown = (document.addEventListener) ? 'mouseup' : 'mouseup';
	addEvent(document,evtDown,catchMouseUp,false);
	//evtDown = (document.addEventListener) ? 'keydown' : 'keydown';
	//addEvent(document,evtDown,catchKeyDown,false);
	//evtUp = (document.addEventListener) ? 'keyup' : 'keyup';
	//addEvent(document,evtUp,catchKeyUp,false);
}

function activateBtn(frm,txt,btn)
{
	// crude/stupid/etc
	if(typeof(frm) == 'object')
	{
		if(txt.value!='')
			btn.disabled=false;
		else
			btn.disabled=true;
	}
	else
	{
		/*if(typeof(document.forms['frmSearch0']) == 'object')
		{
			if(document.forms['frmSearch0'].txtSearch0.value!='')
				document.forms['frmSearch0'].btnSubmit0.disabled=false;
			else
				document.forms['frmSearch0'].btnSubmit0.disabled=true;
		}*/
		if(typeof(document.forms['frmSearch1']) == 'object')
		{
			if(document.forms['frmSearch1'].txtSearch1.value!='')
				document.forms['frmSearch1'].btnSubmit1.disabled=false;
			else
				document.forms['frmSearch1'].btnSubmit1.disabled=true;
		}
	}
}

function evenemang(id,key) {
var open_var = ("http://www.eventonline.se/anmalan.php?eid=" + id + "&key=" + key);
	SkrivUtWnd = window.open(open_var, "anmalan", "width=332,height=650,status=no,location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=no");
	SkrivUtWnd.focus();
	return;
}

function checkSIZE()
{

	if(document.getElementById)
	{	
		var eventscroll = document.getElementById('eventscroll');
		var myDiv = document.getElementById("myDiv");
	}
	else 
		if(document.all)
			{
				var eventscroll = document.getElementById('eventscroll');			
				var myDiv = document.all['myDiv'];
			}


	var temp = eventscroll.offsetHeight;
	if(temp > 400)
	{
		eventscroll.style.height = 400;
		eventscroll.style.overflow = 'auto';
	}
	
	var h = myDiv.offsetHeight + 43;
	var w = 763;
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
	
	w = w+60;
	h = h+47;
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
			w = w + 50;
			h = h + 18;
	 }
	}
	
	window.resizeTo(w,h); 
}

function DisableEnableLinks(xHow)
{
  DisableAllForms(xHow);
  objLinks = document.links;
  for(i=0;i<objLinks.length;i++){
    objLinks[i].disabled = xHow;
    //link with onclick
    if(objLinks[i].onclick && xHow){  
        objLinks[i].onclick = new Function("return false;" + objLinks[i].onclick.toString().getFuncBody());
    }
    //link without onclick
    else if(xHow){  
      objLinks[i].onclick = function(){return false;}
    }
    //remove return false with link without onclick
    else if(!xHow && objLinks[i].onclick.toString().indexOf("function(){return false;}") != -1){            
      objLinks[i].onclick = null;
    }
    //remove return false link with onclick
    else if(!xHow && objLinks[i].onclick.toString().indexOf("return false;") != -1){  
      strClick = objLinks[i].onclick.toString().getFuncBody().replace("return false;","")
      objLinks[i].onclick = new Function(strClick);
    }
  }

}

// START SEARCH HILIGHTER
/* New: Variable searchhi_string to keep track of words being searched. */
var searchhi_string = '';
var hlOn = new Array();
var classcount = 0;
/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
function togglehighlightWord(node,word)
{
	if(node.hlOn)
		unhighlightWord(node,word);
	else
		highlightWord(node,word)
}

function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className.indexOf("searchword") == -1) {
				// word has not already been highlighted!
				
		//alert('hlword:'+hlOn[tempWordVal]);
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword_"+hlOn[tempWordVal];
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function unhighlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlightWord(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className == "searchword") {
				prevSib = pn.previousSibling;
				nextSib = pn.nextSibling;
				nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
				prevSib.nodeValue = '';
				node.nodeValue = '';
			}
		}
	}
}

function unhighlightWord2(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlightWord2(node.childNodes[hi_cn],word);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className.indexOf("searchword") != -1) {
				prevSib = pn.previousSibling;
				nextSib = pn.nextSibling;
				nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
				prevSib.nodeValue = '';
				node.nodeValue = '';
			}
		}
	}
}

function unhighlight(node) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			unhighlight(node.childNodes[hi_cn]);
		}
	}

	// And do this node itself
	if (node.nodeType == 3) { // text node
		pn = node.parentNode;
		if(pn.className.indexOf("searchword") != -1) {
			prevSib = pn.previousSibling;
			nextSib = pn.nextSibling;
			nextSib.nodeValue = prevSib.nodeValue + node.nodeValue + nextSib.nodeValue;
			prevSib.nodeValue = '';
			node.nodeValue = '';
		}
	}
}

function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
        ref = ref.replace(/\/search\/web\//,'?search&q='); // Most WebCrawler searches
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
        qsa = qs.split('#');
        qs = qsa[0];
        qs = qs.replace(/(^|&)p=Q&ts=e&/,'&'); // Most Eurekster searches
        qs = qs.replace(/(^|&)query=/,'&q='); // Most Lycos searches
        qs = qs.replace(/(^|&)key=/,'&q='); // Most Walhello searches
        qs = qs.replace(/(^|&)keywords=/i,'&q='); // Most Overture searches
        qs = qs.replace(/(^|&)searchfor=/,'&q='); // Most Mysearch.com searches
        qs = qs.replace(/(^|&)qt=/,'&q='); // Most Acoona.com searches
        qs = qs.replace(/(^|&)s=/,'&q='); // Most Technirati GET searches
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p' || qsip[0] == 'w') { // q= for Google, p= for Yahoo, w= for Eurekster
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					highlightWord(document.getElementsByTagName("body")[0],words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					else searchhi_string = searchhi_string + ' "' + words[w] + '"';
                		}
			}

	        }
	}
}

// Everything form this point on is modified to allow for highlighting
// of terms found in the REQUEST URI
function localSearchHighlight(searchStr,wcnt) {
	if (!document.createElement) return;
        if (searchStr == '') return;
	if (searchStr.indexOf('?') == -1) qs = searchStr.substr(0);
	else qs = searchStr.substr(1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'h') { // don't make this q or p or will get ghost highlights
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			// Use this next line if you would like to force the script to always
			// search for phrases. See below as well!!!
			phrases = new Array(); phrases[0] = ''; phrases[1] = qsip[1].replace(/\+/g,' ');
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					//highlightWord(document.getElementsByTagName("body")[0],words[w]);
		if(hlOn[words[w].toLowerCase()]) {
			hlOn[words[w].toLowerCase()] = null;
			//classcount--;
			localSearchUnHighlight(searchStr);
		}
		else {
		//classcount++;			
		hlOn[words[w].toLowerCase()] = wcnt;
					highlightWord(document.getElementById("divContent"),words[w]);
					//highlightWord(document.getElementById("divSearchinfo"),words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					//else searchhi_string = searchhi_string + ' "' + words[w] + '"';
					// As before, use this next line if forcing phrase searching
					else searchhi_string = searchhi_string + ' ' + words[w];
		}
                		}
			}
	        }
	}
}

function localSearchUnHighlight(searchStr) {
	//hlOn[0] = null;
	
	if (!document.createElement) return;
        if (searchStr == '') return;
	if (searchStr.indexOf('?') == -1) qs = searchStr.substr(0);
	else qs = searchStr.substr(1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'h') { // don't make this q or p or will get ghost highlights
			// Trim leading and trailing spaces after unescaping
			qsip[1] = unescape(qsip[1]).replace(/^\s+|\s+$/g, "");
			if( qsip[1] == '' ) continue;
                        phrases = qsip[1].replace(/\+/g,' ').split(/\"/);
			// Use this next line if you would like to force the script to always
			// search for phrases. See below as well!!!
			phrases = new Array(); phrases[0] = ''; phrases[1] = qsip[1].replace(/\+/g,' ');
			for(p=0;p<phrases.length;p++) {
			        phrases[p] = unescape(phrases[p]).replace(/^\s+|\s+$/g, "");
				if( phrases[p] == '' ) continue;
				if( p % 2 == 0 ) words = phrases[p].replace(/([+,()]|%(29|28)|\W+(AND|OR)\W+)/g,' ').split(/\s+/);
				else { words=Array(1); words[0] = phrases[p]; }
	                	for (w=0;w<words.length;w++) {
					if( words[w] == '' ) continue;
					//highlightWord(document.getElementsByTagName("body")[0],words[w]);
					unhighlightWord2(document.getElementById("divContent"),words[w]);
					//highlightWord(document.getElementById("divSearchinfo"),words[w]);
					if( p % 2 == 0 ) searchhi_string = searchhi_string + ' ' + words[w];
					//else searchhi_string = searchhi_string + ' "' + words[w] + '"';
					// As before, use this next line if forcing phrase searching
					else searchhi_string = searchhi_string + ' ' + words[w];
                		}
			}
	        }
	}
}

function unHighlightAll()
{
	SmartHLUnload();
	unhighlight(document.getElementById("divContent"));
	//unhighlight(document.getElementById("divSearchinfo"));
	unhighlight(document.getElementsByTagName("body")[0]);
	document.getElementById('divSearchinfo').style.display = "none";
}

function SearchHighlight() {
	googleSearchHighlight();
	localSearchHighlight(location.search);

        // Trim any leading or trailing space
        // (this is an overkill way of getting rid of the leading
        //  space that always is present in searchhi_string)
        searchhi_string = searchhi_string.replace(/^\s+|\s+$/g, "");
	if(searchhi_string != '')
	{
        // In MSIE, sometimes the dynamic generation of the spans
        // for the highlighting takes the anchor out of focus.
        // Here, we put it back in focus.
        if( location.hash.length > 1 ) location.hash = location.hash;
		
		document.getElementById('divSearchinfo').style.display = "block";
		/*document.getElementById('divSearchinfo').style.position='relative';
		document.getElementById('divSearchinfo').style.left = (document.getElementById('divSearchinfo').offsetParent.offsetWidth - document.getElementById('divSearchinfo').offsetWidth) - 5 + 'px';
		document.getElementById('divSearchinfo').style.top = (document.getElementById('divSearchinfo').offsetTop - 10) + 'px';
		//document.getElementById('divSearchinfo').style.top = (document.getElementById('topspace').offsetTop + 30) + 'px';
		alert(document.getElementById('divSearchinfo').offsetParent.id);*/
	}
}

function toggleSearchbox()
{
	if(document.getElementById('divSearchinfo').style.display == "none")
		document.getElementById('divSearchinfo').style.display = "block";
	else
		document.getElementById('divSearchinfo').style.display = "none";
		return true;
}


function SmartHighlight()
{
	// This function is like SearchHighlight()
	// but it detects a page refresh and toggles highlighting
	// on each refresh. This gives a quick way to turn off
	// highlighting (and quickly turn it on after).

	var today = new Date();
	var now = today.getUTCSeconds();

	var cookie = document.cookie;
	var cookieArray = cookie.split('; ');

	// Get timestamp stored in cookie
	for (var loop=0; loop < cookieArray.length; loop++){
		var nameValue = cookieArray[loop].split("=");
		if (nameValue[0].toString() == 'SHTS'){
			var cookieTime = parseInt( nameValue[1] );
		}
		else if (nameValue[0].toString() == 'SHTSP'){
			var cookieName = nameValue[1];
		}
	}

	// If we got a cookie, the cookie is from this page,
	// and the cookie's time is very close to now, then
	// this must be a page refresh (or very similar)
	// so we don't want to highlight. (the 5 second threshold
	// may need to be adjusted for slower browsers/pages/etc.)
	if( cookieName &&
		cookieTime &&
		cookieName == escape(location.href) && 
		Math.abs(now - cookieTime) < 5 )
	{
		// Refresh detected, so don't highlight

		// Disable refresh detection for this run;
		// this is what allows us to toggle the highlighting
		// back *ON* on the next refresh
		searchhi_unl = 0;
	}
	else
	{
		// This is not a refresh, so highlight
		SearchHighlight();
	}

}

function SmartHLUnload()
{
	if( searchhi_unl > 0 )
	{
		// Turn refresh detection on so that if this
		// page gets quickly loaded, we know it's a refresh
		var today = new Date();
		var now = today.getUTCSeconds();
		document.cookie = 'SHTS=' + now + ';';
		document.cookie = 'SHTSP=' + escape(location.href) + ';';
	}
	else
	{
		// Refresh detection has been disabled
		document.cookie = 'SHTS=;';
		document.cookie = 'SHTSP=;';
	}
}

function NotRefreshHL() 
{
	// This is not a refresh. It's probably a submit
	// with the same search string, so disable refresh
	// detection on this go around.
	searchhi_unl = 0;
	return true;
}

// By default, turn refresh detection on
var searchhi_unl = 1;

// window.onload = SearchHighlight;
// window.onload = SmartHighlight;
// window.onunload = SmartHLUnload;

// END SEARCH HILIGHTER