﻿// Title: njCommon.js
//Copyright (c) 2009 Norstedts Juridik AB. All right reserved.
//var acc = 0;
var _debug = null;
var G_id = "";
var changes = 0;
var orSearch = false;
var phraseSearches = "";
/*-----------------------------------------------------------------------------------------------------------------------
- doSitestat 
-----------------------------------------------------------------------------------------------------------------------*/
function doSs(ssType, ssValue, org) {
	var system = 'zeteo2';
	var statmsg="";
	switch(ssType) {
	case "content":
		statmsg = system + ".contents."  + ssValue;
		break;
	case "actions":
		statmsg = system + ".actions."  + ssValue + '&amp;ns_type=hidden';
		break;
	case "page":
		statmsg = system + ".page."  + ssValue;
		break;
	default:
		statmsg = system + "."  + ssValue;
		break;
	}
	debug("sitestat: http://se.sitestat.com/wkse/njse/s?" + statmsg);
	if(org == true) {
		sitestatorg("http://se.sitestat.com/wkse/njse/s?" + statmsg);
	} else {
		sitestat("http://se.sitestat.com/wkse/njse/s?" + statmsg);
	}
	return;
}
function headInject(injName, injType,doAfter) {
	if(injType == "s") {
		if(isdefined(doAfter)) {
			$.getScript(injName, function(data, textStatus){
			   eval(doAfter);
			});
		} else {
			$.getScript(injName);
		}
	} else {
		$('head').append('<link rel="stylesheet" href="' + injName + '.css" type="text/css" />');
	}
}
function resizeWindow() {
	var nav = 300;
	var con = 696;
	try {
		var ww = $(top).width();
	
		var space = (ww -nav-con) /2;
		top.mainFrame.document.getElementById('browseFrameset').cols = nav+space + 'px,*';
	} catch(ex) {}
}
function toogleToc() {
	
	var check = $("body").hasClass('center');
	if(check == true) {
		showToc();
	} else {
		hideToc();
	}
}
function showToc() {
	resizeWindow();
	$("body").removeClass('center');
	$("#docOptionsContainer").removeClass('w1005 m0Auto left');
	$("#docOptionsContainer").addClass('w696 pl5');
	$("#show-hide-toc").addClass('hidden');
}
function hideToc() {
	top.mainFrame.document.getElementById('browseFrameset').cols = '0%,*'
	var targetFrame= top.mainFrame.rightFrame.document;
	$("body",targetFrame).addClass('center');
	$("#show-hide-toc",targetFrame).removeClass('hidden');
	$("#docOptionsContainer",targetFrame).addClass('w1005 m0Auto left');
	$("#docOptionsContainer",targetFrame).removeClass('w696 pl5');	
}
function isBrowse() {
	var mf = top.mainFrame.location.toString();
	
	if(mf.indexOf("view=browse") > -1) {
		return true;
	} else {
		return false;
	}
}
function isMain() {
	var mf = top.mainFrame.location.toString();
	
	if(mf.indexOf("view=main") > -1) {
		return true;
	} else {
		return false;
	}
}
function isHome() {
	var mf = top.mainFrame.location.toString();
	
	if(mf.indexOf("view=home") > -1) {
		return true;
	} else {
		return false;
	}
}
function shomMsg(msgType, msgText) {
	var mf = top.mainFrame.location.toString();
	var targetFrame= top.mainFrame.document;
	var topFrame= top.topFrame.document;	
	$('html, body',targetFrame).animate({scrollTop:0});
	if(isBrowse()) {
		hideToc();
		targetFrame= top.mainFrame.rightFrame.document;
		tocFrame = top.mainFrame.leftFrame.document;
		$("#docFrame",targetFrame).addClass('hidden');
		$("#backgroundPopup",tocFrame).css({"opacity": "0.7"});
		$("#backgroundPopup",tocFrame).fadeIn("fast");
	}
	
	$("#backgroundPopup", topFrame).css({"opacity": "0.7"});
	$("#backgroundPopup", topFrame).fadeIn("fast");
	$("#backgroundPopup",targetFrame).css({"opacity": "0.7"});
	$("#backgroundPopup",targetFrame).fadeIn("fast");
	$("#msgText").html(msgText);
	if(msgType == "warning") {
		$("#popupAlert").addClass('warning');
		$("#popupAlert").removeClass('info');
	
	} else if(msgType =="information") {
		$("#popupAlert").addClass('info');
		$("#popupAlert").removeClass('warning');
	}
	$("#popupAlert",targetFrame).fadeIn("fast");
	$("#popupAlert",targetFrame).removeClass("hidden");



}
function showPopup(showWhat) {
	var mf = top.mainFrame.location.toString();
	var targetFrame= top.mainFrame.document;
	$('html, body',targetFrame).animate({scrollTop:0});
	if(isBrowse()) {
		hideToc();
		targetFrame= top.mainFrame.rightFrame.document;
		tocFrame = top.mainFrame.leftFrame.document;
		$("#docFrame",targetFrame).addClass('hidden');
		$("#backgroundPopup",tocFrame).css({"opacity": "0.7"});
		$("#backgroundPopup",tocFrame).fadeIn("fast");
	}
	
	$("#backgroundPopup").css({"opacity": "0.7"});
	$("#backgroundPopup").fadeIn("fast");
	$("#backgroundPopup",targetFrame).css({"opacity": "0.7"});
	$("#backgroundPopup",targetFrame).fadeIn("fast");
	if(showWhat == "popupQueries") {
		runGetSearches();
	} else if(showWhat == "popupFavorites") {
		runGetFavorites();

	}
	$("#"+showWhat,targetFrame).fadeIn("fast");
	$("#"+showWhat,targetFrame).removeClass("hidden");


}
function closePopups() {
	var topFrame= top.topFrame.document;	
	if($("#popupGoto").is(":visible")) {$("#popupGoto").fadeOut("fast");}
	if($("#popupFavorites").is(":visible")) {$("#popupFavorites").fadeOut("fast");}
	if($("#popupQueries").is(":visible")) {$("#popupQueries").fadeOut("fast");}
	if($("#popupAlert").is(":visible")) {$("#popupAlert").fadeOut("fast");}
	
	$("#backgroundPopup").fadeOut("fast");
	$("#backgroundPopup",topFrame).fadeOut("fast");
	if(isBrowse()) {
		showToc();
		tocFrame = top.mainFrame.leftFrame.document;
		debug('Nu skall vi visa content igen');
		docFrame = top.mainFrame.rightFrame.document;
		$("#docFrame",docFrame).removeClass('hidden');
		$("#docFrame").removeClass('hidden');
		$("#backgroundPopup",tocFrame).fadeOut("fast");
		
		
	}
}
function closeTopBackground() {
	try {
		var topFrame= top.topFrame.document;	
		$("#backgroundPopup",topFrame).fadeOut("fast");
	} catch(e) {
		try {
			tocFrame = top.mainFrame.leftFrame.document;
			$("#backgroundPopup",tocFrame).fadeOut("fast");

		} catch(e) {
			return false;
		}
	}
return true;
}
function closePopup(closeWhat) {
	closePopups();
	var topFrame= top.topFrame.document;
	if($("#popup"+closeWhat).is(":visible")) {
		$("#backgroundPopup").fadeOut("fast");
		$("#popup"+closeWhat).fadeOut("fast");
	}
	$("#backgroundPopup",topFrame).fadeOut("fast");
	if(isBrowse()) {
		showToc();
		docFrame = top.mainFrame.rightFrame.document;
		$("#docFrame",docFrame).removeClass('hidden');
		tocFrame = top.mainFrame.leftFrame.document;
		$("#backgroundPopup",tocFrame).fadeOut("fast");
		
	}
}

function setTopNav(thisPage) {
	
	try {
		topper = top.topFrame.document;
		$("body",topper).css({"opacity": "1.0"});
		if(thisPage == 'home') {
			$("#fieldsearch",topper).addClass('hidden') ;
			$("#fieldsearchHome",topper).removeClass('hidden') ;
		} else {
			$("#fieldsearch",topper).removeClass('hidden');
			$("#fieldsearchHome",topper).addClass('hidden') ;
		}
		$('#topmenu > ul > li',topper).each(function(index) {
			$(this).removeClass('active');
		});
		if(thisPage != "") {
			$("#"+thisPage,topper).addClass("active");
		}
	} catch(ex) {
		//	alert(ex);
	}
}
function jumpToGoto() {
	var mainf = top.mainFrame.document;
	$(mainf).scrollTo('#fieldSearch');
}
/**------------------------------------------------
* Check if a variable is defined
*-------------------------------------------------*/
function isdefined( variable) {
    if(typeof(variable) == "undefined") return false;
    if(variable == "undefined") return false;
    if(variable == "") return false;
    if(variable == null) return false;
	if(variable == "null") return false;
    if(variable == undefined) return false;
    return true;
}
function initApp() {
  var loc="";
    try{
      loc = window.frames["topFrame"].location.toString();
    } catch(ex) {
      loc = window.location.toString();	
    }
    sLoc = loc.split('/');
    if (sLoc.length > 2) {
      setCookie("zeteoserver",sLoc[2]);
      setCookie("webapp",sLoc[3]);	
    }
}

function genOnMouseOver(object){
  if (object.className != "buttonOut textDisabled") {
    object.className = "buttonOver text";
  }
}

function genOnMouseOut(object) {  
  if (object.className != "buttonOut textDisabled") {
    object.className = "buttonOut text";
  }
}
function doJidArt(art) {
	url = "http://www.nj.se/autologin/uname=" + uname + "&upassword=" + upw + "&service=/artjid/" + art;
	openExternalLink(url,"");
}
function gotoTopLocation(gotoName,par1,par2,par) {
  var page = "";
  page += '<FRAMESET ROWS="120,*" FRAMESPACING="0" FRAMEBORDER="0" border="0">\n';
  page += '	<FRAME SRC="template.htm?view=topframe" NAME="topFrame" ID="topFrame" FRAMEBORDER="0" SCROLLING="No" NORESIZE MARGINWIDTH="0" MARGINHEIGHT="0" BORDER="0">\n';
  page += " <FRAMESET cols='30%,*' framespacing='0' frameborder='0' bordercolor='#000000' border='0'>\n";
  page += "   <FRAME src='template.htm?view=contents&mode=$mode' name='leftFrame' id='leftFrame' scrolling='auto' marginheight='0' marginwidth='0' frameborder='0' border='0' bordercolor='#000000'>\n";
  page += "   <FRAME src='"+  par1 + "' name='rightFrame' id='rightFrame' scrolling='auto' marginheight='0' marginwidth='0' frameborder='0' border='0'>\n";
  page += "  </FRAMESET>\n";
  page += '</FRAMESET>\n';
  page += '<NOFRAMES>\n';
  page += '</NOFRAMES>\n';
}
/*------------------------------------------------------------
Function: gotoLocation
Sets location of a frame
------------------------------------------------------------*/
function gotoLocation(gotoName,par1,par2,par3,par4,par5) {
  //var furl = top.mainFrame.location.toString();
  showToc();
  var furl = eval(getFrame("mainFrame")).location.toString(); 
  
  var sfromURL = furl.split("/");
  startUrl = "/" + sfromURL[3] +"/";
//debug("GotoLocation gotoName="+gotoName + " par1="+par1+ " par2="+par2+ " par3="+par3+ " par4="+par4+ " par5="+par5);
	switch(gotoName) {
	case "E_SYNC_TO_TOC":
		eval(getFrame("mainFrame")).frames['leftFrame'].tocSyncToId(par1);
	break;
	case "E_SET_TOCDOC":
    if(par1 =="next") {
      par2 = par2 + 1;
    } else {
      par2 = par2 -1;
    }
    window.location.href = startUrl + "template.htm?view=document&doc_action=setHitDoc&doc_hit=" + par2;
	break;
	case "E_SET_HITTOCDOC":
    if (LCODoc.m_docContext != null) {
      window.location.href = startUrl + "template.htm?view=document&doc_action=setHitDoc&doc_context=" + LCODoc.m_docContext + "&doc_keytype=tocid&doc_key=" + tile.getElement();
    } else {
      window.location.href = startUrl + "template.htm?view=document&doc_action=setHitDoc&doc_keytype=tocid&doc_key=" + tile.getElement();
    }
  break;
	case "E_SET_HITDOC":
		if (LCODoc.m_docContext != null) {
      window.location.href = startUrl + "template.htm?view=document&doc_action=setHitDoc&doc_context=" + LCODoc.m_docContext + "&doc_hit=" + tile.getElement();
    } else {
      window.location.href = startUrl + "template.htm?view=document&doc_action=setHitDoc&doc_hit=" + tile.getElement();
    }
	break;
	case "E_SET_LEAFDOC":
		window.location.href = "template.htm?view=document&doc_action=setLeafDoc&doc_leaf=" + tile.getElement();
	break;
	case "E_SET_PDFDOC":
	
		var targetFrame = document.getElementById("docFrame");
    targetFrame.contentWindow.location.href = tile.getElement();
	break;	
	case "E_SET_HITTOCDO":
		windows.location="";
	break;	
	case "E_SET_HITTOCDO":
		windows.location="";
	break;		
	}

}	
/*------------------------------------------------------------
Function: getDocumentFromFrame
Part of propub
------------------------------------------------------------*/
function getDocumentFromFrame(frame)
{
	// Document logic for Internet Explorer
	if (frame.contentWindow)
	{
		return frame.contentWindow.document;
	}
	// Document logic for Mozilla
	else if (frame.contentDocument)
	{
		return frame.contentDocument;
	}
	else
	{
		return null;
	}
}
function getUniqueGCD(G_ContentDomains) {
	  var GCDS = G_ContentDomains.split(';')
		var UniqueGCD="";
		for (var i = 0; i< GCDS.length;i++) {
	    if (UniqueGCD.indexOf(GCDS[i]) < 0) {
	      if(UniqueGCD=="") {
	        UniqueGCD += GCDS[i];
	      } else { 
	        UniqueGCD += ";" + GCDS[i];
	      }
	    }
		}
		return UniqueGCD;

	}
/*------------------------------------------------------------
Function: removePartString
Remove a part of a string.

Arguments:
  remFrom - The string to remove from
  startStr - The start string
  endStr - the end string
  looper - NOT IMPLEMENTED
       
Revision History: 
 - NEW 2007-03-20 tlin2: Initial version.
------------------------------------------------------------*/
function removePartString(remFrom,startStr,endStr,looper) {
	var pos1 = 0;
	var pos2 = 0;
	var between = "";
	pos1 = remFrom.toLowerCase().indexOf(startStr.toLowerCase());
	if (pos1 == -1) return remFrom;
	pos2 = remFrom.toLowerCase().indexOf(endStr.toLowerCase(),pos1);
	if (pos2 == -1) return remFrom;
	between = remFrom.substring(pos1,pos2+ endStr.length);
	remFrom = remFrom.replace(between,"");
	return remFrom;
}
/*------------------------------------------------------------
Function: getPartString
Extract a part of a string

Arguments:
  remFrom - The string to get a part from
  startStr - The start string
  endStr - the end string
  incl - should the start and stop text be included
       
Revision History: 
 - UPD 2008-02-14 tlin2: Added incl
 - NEW 2007-03-20 tlin2: Initial version.
------------------------------------------------------------*/
function getPartString(remFrom,startStr,endStr,incl) {
	var pos1 = 0;
	var pos2 = 0;
	var between = "";
	pos1 = remFrom.toLowerCase().indexOf(startStr.toLowerCase());
	if (pos1 == -1) return null;
	
	pos2 = remFrom.toLowerCase().indexOf(endStr.toLowerCase(),pos1);
	if (pos2 == -1) return null;
	if(incl== "true") {
		between = remFrom.substring((pos1+ startStr.length),pos2 );
	} else {
		between = remFrom.substring(pos1,pos2+ endStr.length);
	}
	return between;
}

////XXXXXXXXXXXXXXXXXXXXXXXXXX

function getFrame(fName) {
	if(fName=="top") {
		return getSystemVar('top')
	} else {
		targetFrame = getSystemVar('top') + "." + fName
	}

	try {
		var targetFrameTest = eval(targetFrame).location.toString();
		return targetFrame;
  } catch(ex) {
    return getSystemVar('top');
    try {
      var targetFrame = eval("top." + fName).location.toString();
    } catch(ex) {
      return "top." + fName;
    }
      return "top." + fName;
	}
	return "top." + fName;
}
function getFrameName(fName) {
	if(fName=="top") {
		return getSystemVar('top')
	} else {
		targetFrame = getSystemVar('top') + "." + fName
	}

	return targetFrame;
}
function doGoogle() {
  searchFor = getCookie("searchFor");
  var loc = "http://www.google.com/cse?q=" + searchFor + "&cx=009364735960081272278%3Akrvz6tsihsw&ie=UTF-8";
  ext_link =  window.open(loc,"External_Link","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=800, height=600");
	ext_link .focus();
 // openExternalLink(loc);
}
function setLocation(fname,loc) {
  eval(getFrame(fname)).location = loc;
}
/*------------------------------------------------------------
Function: getUrlStart
Get the start of the url in the document loaded in the iframe
       
Revision History: 
 - NEW 2007-03-20 tlin2: Initial version.
------------------------------------------------------------*/
function getUrlStart() {
	return getSystemVar('webapp') + "/"; 
	/*
	var furl = eval(getFrame("mainFrame")).location.toString(); //top.mainFrame.
	
	var sfromURL = furl.split("/");
	//debug("/" + sfromURL[3] +"/");
	return "/" + sfromURL[3] +"/" ;
	*/
}
/*--------------------------------------------------------------------------------------------------------------------------
   Function: getWordsSubstr
	return a number of word in a string

   Arguments:
   totStr - string to extract from
   delim - delimiter that separated "words"
   startnum - what number to start from
   numberOfWords - Number of words to extract
----------------------------------------------------------------------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-11 tlin2: Initial version. 
--------------------------------------------------------------------------------------------------------------------------*/
function addToPhrase(addPhrase) {
	addPhrase = addPhrase.replace(new RegExp(':',"g"),' ');	
	if(phraseSearches == "") {
		phraseSearches = addPhrase;
	} else {
		phraseSearches += ";" + addPhrase;
	}
	//debug("NJCommon AddToPhrase " + phraseSearches + " addPhrase=" + addPhrase);
}
/*--------------------------------------------------------------------------------------------------------------------------
   Function: getWordsSubstr
	return a number of word in a string

   Arguments:
   totStr - string to extract from
   delim - delimiter that separated "words"
   startnum - what number to start from
   numberOfWords - Number of words to extract
----------------------------------------------------------------------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-11 tlin2: Initial version. 
--------------------------------------------------------------------------------------------------------------------------*/
function getWordsSubstr(totStr,delim,startnum,numberOfWords) {
	totStr = trim(totStr);
	var ret = "";
	var totStrS = totStr.split(delim);
	if(totStrS.length < startnum) return ret   // The start is bigger then the number of words in string
	if(totStrS.length <= startnum + numberOfWords) numberOfWords = totStrS.length -startnum ;
	for(var i=startnum;i<=startnum+numberOfWords-1;i++) {
		ret += totStrS[i] + delim;
	}
	return ret;
}
/*--------------------------------------------------------------------------------------------------------------------------
   Function: getWord
	return a specific word in a string

   Arguments:
   totStr - string to extract from
   delim - delimiter that separated "words"
   wordno - integer what wordnumber. If negative that the count is down right to left
----------------------------------------------------------------------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-01 tlin2: Initial version. 
--------------------------------------------------------------------------------------------------------------------------*/
function getWord(totStr,delim,wordno) {
	totStr = trim(totStr);
	var totStrS = totStr.split(delim);
	if (wordno < 0) {
		if (totStrS.length >= wordno) {
			var ret = totStrS[totStrS.length+wordno];
			return ret;
		}
	} else {
		if (totStrS.length >= wordno) {
			var ret = totStrS[wordno];
			return ret;
		}
	}
	return "";
}
/*--------------------------------------------------------------------------------------------------------------------------
   Function: removeWord
	Removes a number of words from a string

   Arguments:
   totStr - string to remove from
   delim - delimiter that separated "words"
   wordnum - integer number of word. 
   RightLeft - r or l. Indicated is word should be removed starting left or right. If omitted start from left
----------------------------------------------------------------------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-01 tlin2: Initial version. 
--------------------------------------------------------------------------------------------------------------------------*/
function removeWord(totStr,delim,wordnum,RightLeft) {
	var totStrS = totStr.split(delim);
	var ret = "";
	var i = 0;
	var startpos = 0;
	var slutpos = 0;
	if(wordnum >= totStrS.length) return "";
	
	if(RightLeft.toLowerCase() == 'r') {
		slutpos = totStrS.length - wordnum;
	} else {
		slutpos = totStrS.length;
		startpos = wordnum;
	}

	for(i=startpos;i != slutpos;i++) {
		ret += totStrS[i] + delim;
	}
	return ret;
}
/*------------------------------------------------------------
   Function: doDom
	Autologin to a news in domino

   Arguments:
   uname,upassword
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-01 tlin2: Initial version. 
------------------------------------------------------------*/
function doDom(uname,upassword,url) {
		if(url==null) url= getDomServer() + '/njab/sso.nsf/autoLogin?openform&success=/srl&failure=/srl&uname=' + uname + '&upassword=' + upassword;
		var w = 820;
		var h = 600;
		window_name= window.open(url,"","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width="+w+", height="+h);
		window_name.focus();
	}
/*------------------------------------------------------------
   Function: goFav
	Open a saved search or favorite

   Arguments:
   fav - location to the search or favorite
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-01 tlin2: Initial version. 
------------------------------------------------------------*/	
function goFav(fav) {
	deleteCookie('sortBy');
   //clearNavigatorCookie();
   parent.mainFrame.location=fav;
}

/*------------------------------------------------------------
   Function: toProperCase
	Set propercase on a string. Eq first char in every word is
	set to uppercase and the rest to lowercase

   Arguments:
   astring - string to transform
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-01 tlin2: Initial version. 
------------------------------------------------------------*/	
function toProperCase(astring) {
	if (!astring) return '';
	return astring.charAt(0).toUpperCase() + astring.substring(1,astring.length).toLowerCase();
}
/*------------------------------------------------------------
   Function: debug
	Open a debug window and write a msg in that window.
	only works in firefox and on devserver
	
   Arguments:
   msg - string to write in debug window
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-03-01 tlin2: Initial version. 
------------------------------------------------------------*/
function debug(msg) {
	var d = new Date();
	curr_hour = d.getHours();
	curr_min = d.getMinutes();

	curr_sec = d.getSeconds();
	curr_msec = d.getMilliseconds();
	msg = curr_hour + ":" + curr_min + ":" + curr_sec + ":" + curr_msec + "--" + msg;

	//if(navigator.appName == "Netscape") {
		var server = window.location.toString();
		if(server.indexOf('zeteodts.wksc.local:8080')!=-1 || server.indexOf('localhost')!=-1) {
			var username = getCookie("username");
			//if(username == "Thomas Lindqvist" || username == "Jenny Hannula" || username.indexOf("Pri")!=-1) {
			if(username == "Thomas Lindqvist" || username.indexOf("Pri")!=-1) {
				if((_debug == null) || (_debug.closed)) {
					_debug = window.open("","debug","width=1000,height=600,resizable=yes, toolbar=yes, status=yes, menubar=yes, scrollbars=yes");
					_debug.document.open("text/plain");
				}
				_debug.document.writeln(msg + '<br>');
			}
		}
	//}
}
/*------------------------------------------------------------
   Function: checkQuery
	Checks if the user has enter a correct search syntax
	Returns a errorText or "" if ok

   Arguments:
   aQuery - the query string
--------------------------------------------------------------    
  Revision History:
   - FIX 2007-11-20 uber1: Removed quotes in aQuery, after the phrase test, to eliminate faulty errortext when ending quote is encountered
                          (ending quotes are caught in inner-most if-tests).
   - NEW 2007-03-21 tlin2: Initial version. 
------------------------------------------------------------*/
function checkQuery(aQuery) {
	var errorText="";
	// check phrase
	if(aQuery.indexOf('"') != -1) {
		sQuery = aQuery.split('"');
		if(sQuery.length%2 != 1) errorText += ERRORPHRASE;
	}
	aQuery = aQuery.replace(/"/g,'');
	// check truncation
	
	if(aQuery.indexOf('*') != -1) {
		sQuery = aQuery.split(' ');
		for(j=0;j<sQuery.length;j++) {
			if(sQuery[j].indexOf('*') != -1) {
				sChecker = sQuery[j].split('*');
				for(i=0;i<sChecker.length;i++) {
					//debug("truncation=" + sChecker[i]);
					if(sChecker[i].length<4) {
						if(sChecker[i].length>0) {
							errorText += ERRORTRUNC;
							return errorText;
						}
					}
				}
			}
		}
	}
	
	return errorText;
}
/*------------------------------------------------------------
   Function: translateQuery
   
	To make our work easier we change the query to lower letters.
	This is a unicode string, so national letters will be preserved.
	It may be a phrase search, so we split it into a table
	using quotation mark as separators...

   Arguments:
   aSveQuery - the query string
--------------------------------------------------------------    
  Revision History: 
   - UPD 2007-12-05 tlin2: added OCH Och AND And
   - UPD 2007-11-15 TLin2: Added addToPhrase.
   - NEW 2001-07-07 WJ: Initial version. 
------------------------------------------------------------*/
function doTranslate1(sveQuery) {
	debug("doTranslate1=" + sveQuery+ "-");
	if(trim(sveQuery.toLowerCase())=="og") return "";
	if(trim(sveQuery.toLowerCase())=="or") return "";	
	if(trim(sveQuery.toLowerCase())=="och") return "";
	if(trim(sveQuery.toLowerCase())=="and") return "";
	if(trim(sveQuery.toLowerCase())=="eller") return "";	
	if(trim(sveQuery.toLowerCase())=="not") return "";	
	if(trim(sveQuery.toLowerCase())=="inte") return "";		
	if(trim(sveQuery.toLowerCase())=="icke") return "";		
	sveQuery = sveQuery.replace( new RegExp(' icke ',"g"),'inte ');
//	sveQuery = sveQuery.replace(new RegExp(' inte ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' INTE ',"g"),' inte ');	
	sveQuery = sveQuery.replace(new RegExp(' och ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' OCH ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' Och ',"g"),' ');	
	sveQuery = sveQuery.replace(new RegExp(' og ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' Og ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' OG ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' And ',"g"),' ');	
	sveQuery = sveQuery.replace(new RegExp(' AND ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' and ',"g"),' ');
	sveQuery = sveQuery.replace(new RegExp(' eller ',"g"),' xyz_or_abc_or_orm ');
	sveQuery = sveQuery.replace(new RegExp(' ELLER ',"g"),' xyz_or_abc_or_orm ');
	sveQuery = sveQuery.replace(new RegExp(' or ',"g"),' xyz_or_abc_or_orm ');
	sveQuery = sveQuery.replace(new RegExp(' OR ',"g"),' xyz_or_abc_or_orm ');
	sveQuery = sveQuery.replace(new RegExp(' not ',"g"),' inte ');
	sveQuery = sveQuery.replace(new RegExp(' NOT ',"g"),' inte ');
	sveQuery = sveQuery.replace(new RegExp("'","g"),'"');
	debug("doTranslate1 END= " + sveQuery);
	return sveQuery;
}
function translateQuery2(sveQuery) {
	orSearch = false;   // set the or/eller to false. Used in do Search
	phraseSearches = "";  // used in highlight
	//debug("NJCommon Kolla efter :" + sveQuery);
	if(sveQuery.indexOf(':') != -1) {
		var phraseFix = doTranslate1(sveQuery);
		var phraseFixS = phraseFix.toLowerCase().split(' ');
		for (var a = 0; a < phraseFixS.length; a += 1)
		{
			addToPhrase(phraseFixS[a]);
		}
	}
	
	if(sveQuery.indexOf('"') != -1) {
		//debug("NJCommon Det finns dubbelfnutt");
		var result = sveQuery.toLowerCase().split('"');
		changes++;
	// ... and assume that every odd row will be a phrase
		
		for (var a = 0; a < result.length; a += 1)
		{
			//if(a == 2) a = 1;
		  if (trim(result[a]) != "") {
		   // result[a] = doTranslate1(result[a]);
		    addToPhrase(result[a]);
		  }
		}
		sveQuery = result.join('"').toLowerCase();
	} else {
		sveQuery = doTranslate1(sveQuery);
	}
	
	// check if there is a : or - or / in the text
	if(sveQuery.indexOf(':') != -1 || sveQuery.indexOf('-') != -1 || sveQuery.indexOf('/') != -1) {
		sQuery = sveQuery.split(' ');
		for (var a = 0; a < sQuery.length; a++) {
			if(sQuery[a].indexOf('"') == -1) {
				if(sQuery[a].indexOf(':') != -1 ) 
					sQuery[a] = '"' + sQuery[a].replace(new RegExp('"',"g"),'').replace(":",' ') + '"' ;
				if(sQuery[a].indexOf('-') != -1) 
					sQuery[a] = '"' + sQuery[a].replace(new RegExp('"',"g"),'') + '"';
				if(sQuery[a].indexOf('/') != -1) 
					sQuery[a] = '"' + sQuery[a].replace(new RegExp('"',"g"),'') + '"';
				if(sQuery[a].indexOf('.') != -1) 
					sQuery[a] = '"' + sQuery[a].replace(new RegExp('"',"g"),'') + '"';				
			 }
		}
		sveQuery = sQuery.join(' ');
	}
	// Check if there is any or in the query
	if(sveQuery.indexOf(" xyz_or_abc_or_orm ") > -1) {
		orSearch = true;
	}
//	sveQuery = sveQuery.replace(new RegExp('"',"g"),'');	
	sveQuery = sveQuery.replace(new RegExp(':',"g"),' ');		
	sveQuery = sveQuery.replace(new RegExp('/',"g"),' ');
	debug("sveQuery:"+sveQuery);
	return sveQuery;
	
}
function doPhrase(aVal , aSign) {
	if(aVal.indexOf(aSign) != -1) {
		changes++;
		sQuery = aVal.split(' ');
		for (var a = 0; a < sQuery.length; a++) {
			if(sQuery[a].indexOf(aSign) != -1 && sQuery[a].substring(0,1) != '"') 
				sQuery[a] = '"' + sQuery[a] + '"';
		}
		return sQuery.join(' ')
	}
	return aVal;
}
function TranslateAndOrNot(sveQuery) {
	if(sveQuery.indexOf(' och ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' och ',"g"),' AND ');
		changes++;
	}
	if(sveQuery.indexOf(' eller ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' eller ',"g"),' OR ');
		changes++;
	}
	if(sveQuery.indexOf(' icke ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' icke ',"g"),' ANDNOT ');
		changes++;
	}
	if(sveQuery.indexOf(' inte ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' inte ',"g"),' ANDNOT ');
		changes++;
	}
	if(sveQuery.indexOf(' ikke ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' ikke ',"g"),' ANDNOT ');
		changes++;
	}	
	if(sveQuery.indexOf(' not ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' not ',"g"),' ANDNOT ');
		changes++;
	}
	if(sveQuery.indexOf(' and ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' and ',"g"),' AND ');
		changes++;
	}
	if(sveQuery.indexOf(' or ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' or ',"g"),' OR ');
		changes++;
	}
	if(sveQuery.indexOf(' og ') != -1) {
		sveQuery = sveQuery.replace(new RegExp(' og ',"g"),' AND ');
		changes++;
	}
return sveQuery;
	
}
function addIt(addTo,addThis,delim) {
	if(addTo =="")
		return addThis;
	else
		return addTo + delim + addThis;
}
function translateQuery(aSveQuery)
{
	changes = 0;
	var sveQuery = new String(aSveQuery.toLowerCase());
	
	

	var query = "";
	for (var i = 0; i < sveQuery.length; i++) {
		if (sveQuery.charCodeAt(i) == 8221)
			query += '"';
		else
			query += sveQuery.charAt(i);
	}
	
	if(query.indexOf('"') != -1) {
		var result = query.toLowerCase().split('"');
		changes++;
	// ... and assume that every odd row will be a phrase
		for (var a = 0; a < result.length; a += 2)
		{
			result[a] = TranslateAndOrNot(result[a]);
		}
		sveQuery = result.join('"').toLowerCase();
	} else {
		sveQuery = TranslateAndOrNot(sveQuery);
		var result = sveQuery.split(' ');
		var newResult = "";
		var result1 ="";
		var oldResult1 ="";
		var lastIsAND = false;
		for (var a = 0; a < result.length; a += 1)
		{
			result1 = trim(result[a]);
			if(result1 != "") {
				if(result1 != "OR" && result1 != "AND" && result1 != "ANDNOT") {
					if(lastIsAND== true) {
						oldResult = result1;
						lastIsAND = false;
					}else {
						oldResult = " OR " + result1
					}
				} else {
					lastIsAND = true;
					oldResult = " " + result1 + " ";
				}
				if(newResult == "")
					newResult = result1;
				else
					newResult += oldResult
			}
		}
		if(newResult.indexOf(' AND ') != -1) {
			result = newResult.split(' ');
			var pos="";
			for (var i = 0; i<result.length; i++) {
				if(result[i] == "AND") {
					pos += i + ',';
				}
			}
			poses = pos.split(',');
			
			for (var j = 0; j<poses.length-1; j++) {
				result = newResult.split(' ');
				newResult = "";
				startpos = poses[j]-1;
				stoppos =  startpos+2;
				for (var i = 0; i<result.length; i++) {
					if(i == startpos){
						if(trim(result[i]).substr(0,1) != "(")
							newResult = addIt(newResult,"(" + result[i],' ');
						else
							newResult = addIt(newResult,result[i],' ');
					} else if(i == stoppos){
						if(trim(result[i]).substr(-1,1) != ")")
							newResult = addIt(newResult,result[i]+ ")",' ');
						else
							newResult = addIt(newResult,result[i],' ');
					} else
						newResult = addIt(newResult,result[i],' ');
				}
			}
			
		}
		sveQuery = newResult;
	}
	
	
	// check if there is a : or - or / in the text
	if(sveQuery.indexOf(':') != -1 || sveQuery.indexOf('-') != -1 || sveQuery.indexOf('/') != -1) {
		changes++;
		sQuery = sveQuery.split(' ');
		for (var a = 0; a < sQuery.length; a++) {
			if(sQuery[a].indexOf(':') != -1 && sQuery[a].substring(0,1) != '"') 
				sQuery[a] = '"' + sQuery[a].replace(":",unescape("%A4")) + '"';
			if(sQuery[a].indexOf('-') != -1 && sQuery[a].substring(0,1) != '"') 
				sQuery[a] = '"' + sQuery[a].replace("-",unescape("%A4")) + '"';
			if(sQuery[a].indexOf('/') != -1 && sQuery[a].substring(0,1) != '"') 
				sQuery[a] = '"' + sQuery[a].replace("/",unescape("%A4")) + '"';								
		}
		sveQuery = sQuery.join(' ')
	}
	sveQuery = doPhrase(sveQuery,"-");
	sveQuery = doPhrase(sveQuery,",");
	sveQuery = doPhrase(sveQuery,".");
	sveQuery = doPhrase(sveQuery,"/");
	if(changes != 0){
		return "(" + sveQuery + ")";
	} else {
		return aSveQuery;
	}
}
/*------------------------------------------------------------
   Function: objectExist
  	Checks if a object exist in the document
  	Returns true or null

   Arguments:
   Id - Id of element
   Tag - type of element
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/
function objectExist(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o) {
    if (Tag) {
      if (o.tagName.toLowerCase() == Tag.toLowerCase()){
        return o;
      }
    } else {
      return o;
    }
  }
  return null;
}
/*------------------------------------------------------------
   Function: checkCD
  	Checks if the user has the right to see a document
  	Returns true or false

   Arguments:
   docCD - content domain for the document
   userCD - content domain for the user
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-05-25 tlin2: Initial version. 
------------------------------------------------------------*/
function checkCCD(docCD,userCD) {
  if(docCD==CDWEB) return true;

  var sDocCD = docCD.split(";");
  var sUserCD = userCD.split(";");
  var aUserCD = "";
  for(var i=0;i<sUserCD.length;i++) {
    aUserCD = sUserCD[i];
    for(var j=0;j<sDocCD.length;j++) {
      aDocCD = sDocCD[j];
      if (aUserCD == aDocCD) return true;
    }
  }
  return false;
}
/*------------------------------------------------------------
   Function: checkCD
  	Checks if the user has the right to see a document
  	Returns the a href

   Arguments:
   urltype1 - http or internal
   urltype - external or internal
   ccd - content domain for the document
   thetitle - title of the document
   nr - number in the resultlist
   itype - documenttype
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/
function checkCD(urltype1, urltype, ccd, thetitle,nr,itype) {
	var gcd = getCookie("_ContentDomains");
	//debug(urltype1 + ',' + urltype + ',' + ccd+ ',' + thetitle+ ',' +nr+ ',' +itype+ ',' +gcd);
	//debug('');
	var tEnd = '</tr></table>';
	var imgStart = '<table><tr><td><img src="'
	var imgStop  = '" valign="absmiddle" border="0">&nbsp;</td>'
	var imgSrc = '';
	// Deside img to show	
	switch(itype) {
	case Forf:
		imgSrc = imgStart + ForfGifSmall + imgStop;
	break;
	case Avg:
		imgSrc = imgStart + AvgGifSmall + imgStop;
	break;
	case Fora:
		imgSrc = imgStart + ForaGifSmall + imgStop;
	break;
	case Kom:
		imgSrc = imgStart + KomGifSmall + imgStop;
	break;
	case Myn:
		imgSrc = imgStart + MynGifSmall + imgStop;
	break;
	case Art:
		imgSrc = imgStart + ArtGifSmall + imgStop;
	break;
	case EU:
		imgSrc = imgStart + EUGifSmall + imgStop;
	break;
	case Ovr:
		imgSrc = imgStart + OvrGifSmall + imgStop;
	break;
	}

	//----- Build the a href
	if(urltype1 == "http") {
		var theUrl = '<td><A HREF="';
		theUrl +="javascript:openExternalLink('"
		theUrl +=urltype;
		theUrl +="');";
		theUrl +='" class="resultHitlist">';
	} else {
		theUrl = "<td><A HREF='template.htm?view=browse&doc_action=setHitDoc&doc_hit=" + nr + "'>";
	}
	theUrl = imgSrc + theUrl + thetitle +  "</A></td>" +tEnd;
	debug(theUrl);
	//---------- Check if the content domains in the document match the users content domains
	if(ccd==CDWEB) return theUrl;
	var sccd = ccd.split(";");
		for(var i=0;i<=sccd.length;i++) {
			if (gcd.indexOf(sccd[i]) != -1) return theUrl;
		}	
	//---- dont match. Send back the key
	theUrl = imgStart + KeyGif + imgStop + '<td><A HREF="#" class="noaccess" onclick="alert';
	theUrl += "('" + NOACCESS + " " + ccd + "')";
	theUrl += '";>' + thetitle + "</A></td>" + tEnd;
	return theUrl
	
}

/*------------------------------------------------------------
   Function: setListBoxValue
  	select a value in a listbox

   Arguments:
   lbName - name of listbox
   lbValue - value to select
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-03-07 tlin2: Initial version. 
------------------------------------------------------------*/
function setListBoxValue(lbName, lbValue) {
	var checkerText="";
	var checkerValue ="";
	if(byId(lbName) != false) {
		
		var lbx = byId(lbName).length;
		for (x = 0; x <lbx;x++) {
				checkerText = byId(lbName).options[x].text;
				checkerValue = byId(lbName).options[x].value;

				if(checkerText == "") checkerText = byId(lbName).options[x].text;
				if(checkerValue == "") checkerValue = byId(lbName).options[x].value;
if(lbName == 'avgTargetType31') debug('checkerText =' + checkerText + " checkerValue=" +checkerValue + ' lbValue=' +lbValue);				
				if(checkerText == lbValue) {
					byId(lbName).options[x].selected = true; 
				} else if(checkerValue == lbValue) {
					byId(lbName).options[x].selected = true; 
				}
		}
	}
}
/*------------------------------------------------------------
   Function: addToLog --------------- NOT IN USE   -----------------
  	Add a entry to a specific log

   Arguments:
   action - Type of search if present
   msg - Message to log
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-12-18 tlin2: Initial version. 
------------------------------------------------------------*/
function getNoResp(){
}
function addToLog(logFile, action,msg) {
	if (action =="docOpen") {
		loadXMLDoc('session.htm?action=addToLog&key=' + logFile + msg );
	}else if(action =="") {
		loadXMLDoc('session.htm?action=addToLog&key=' + logFile + '&value=' + msg );
	} else {
		loadXMLDoc('session.htm?action=addToLog&key=' + logFile + '&value=<searchlogEntry><searchAction>' + action + '</searchAction><search>' + msg +'</search></searchlogEntry>');
	}	
}

/*------------------------------------------------------------
   Function: get / setCookie
  	get and set information in a cookie

   Arguments:
   sString - String to trim
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/  
function getSessResp() {
	try{
		var result = resultXML.getElementsByTagName('result')[0].firstChild.nodeValue ;
	} catch(ex) {
		return "";
	}
}

function getSessionKeyToId(name, id) {
	G_id = id;
	//loadXMLDoc('session.htm?action=getFromSession&key=' + name, ajaxGenResponse, false,'id',getSessResp,id);
	loadXMLDoc('session.htm?action=getFromSession&key=' + name, getSessResp);
}
function setSessionKey(name, value) {
	loadXMLDoc('session.htm?action=addToSession&key=' + name + '&value=' + value, ajaxGenResponse, false,'genSessResp');
}

function setCookie (name, value, expire, path) {
  setZeteoCookie(name, value, expire, path);
}

function setBrowserCookie (name, value, expire, path, esc) {
  document.cookie = name + "=" + escape(value) +
                    ((!expire) ? "" : ("; expires=" + expire.toGMTString())) +
                    "; path=" + ((!path) ? "/" : path);
}

function setZeteoCookie (name, value, expire, path) {
  var groupName = getCookieGroupName(name);
  var newCookieValue = name + "::" + value; //+
                    //((!expire) ? "" : ("| expires::" + expire.toGMTString())) +
                    //"| path::" + ((!path) ? "/" : path);

  var currGroupVal = getBrowserCookie(groupName);
  var newBrowserVal = "";
    
  if (currGroupVal != "")
  {
    var currGroupValues = currGroupVal.split("¤");
    for (var a = 0; a < currGroupValues.length; a += 1) {
      var nameVal = currGroupValues[a].split("::");
      if (nameVal[0] != name) {
        if (newBrowserVal.length > 0)
          newBrowserVal += "¤";
        newBrowserVal += currGroupValues[a];
      }
    }
    if (value && value.length > 0) {
      if (newBrowserVal.length > 0)
        newBrowserVal += "¤";
      newBrowserVal += newCookieValue;
    }
  }
  else
  {
    if (value && value.length > 0) {
      newBrowserVal += newCookieValue;
    }
  }

  if (newBrowserVal.length > 0) {
    setBrowserCookie(groupName, newBrowserVal, expire, path);
    //setBrowserCookie(name, value, expire, path);
  }
  else {
    deleteBrowserCookie(groupName, path);
    //deleteBrowserCookie(name, path);
  }
}

function cookieEnabled() {
  setCookie("cookieTest","ok");
  if (getCookie("cookieTest")=="ok") 
    {
      return true;
    }
    else
    {
    //alert("Your browser need to accept cookies ");
    eval(getFrame("mainFrame")).location.href = "template.htm?view=error&error=cookieenabled";   
      return false; 
    }
}

function getCookie (name) {
  return getZeteoCookie(name);
}

function getBrowserCookie(name) {
  var value='', search=name+"=";
  if (document.cookie.length > 0) {
    var offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      var end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      value = unescape(document.cookie.substring(offset, end));
    }
  }
  return value;
}

function getZeteoCookie (name) {
  var result = "";
  var groupName = getCookieGroupName(name);
  var currGroupVal = getBrowserCookie(groupName);
    
  if (currGroupVal != "")
  {
    var currGroupValues = currGroupVal.split("¤");
    for (var a = 0; a < currGroupValues.length; a += 1) {
      var nameVal = currGroupValues[a].split("::");
      if (nameVal[0] == name)
      {
        result = nameVal[1];
        break;
      }
    }
  }
  
  if (result == "")
    result = getBrowserCookie(name);

  return result;
}

function deleteCookie(name, path)
{
  deleteZeteoCookie(name, path);
}

function deleteBrowserCookie(name, path)
{
  if (getCookie(name)) {
    document.cookie = name + "=" +
                    "; path=" + ((!path) ? "/" : path) +
                    "; expires=" + new Date(0).toGMTString();
  }
}

function deleteZeteoCookie(name, path)
{
  setZeteoCookie(name, "", null, path);
}

function getCookieVal (offset) { 
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

function getCookieGroupName(name) {
  return "cookie" + name.substring(0,1).toUpperCase();
}

/*------------------------------------------------------------
   Function: Trim
  Trims a string.

   Arguments:
   sString - String to trim
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/  
function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
		{sString = sString.substring(1, sString.length);}
	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{sString = sString.substring(0,sString.length-1);}
	return sString;
}

function trim(sString)
{
	if (sString == null) return sString;
	if (sString == "") return sString;
	while (sString.substring(0,1) == ' ' ||sString.substring(0,1) == '20%')
		{sString = sString.substring(1, sString.length);}
	while (sString.substring(sString.length-1, sString.length) == ' ')
		{sString = sString.substring(0,sString.length-1);}
	return sString;
}
/*------------------------------------------------------------
   Function: showHelp
  Show the help in a new window

   Arguments:
   helpId - What help id should be showed
   showLang - What language to show the help in
--------------------------------------------------------------    
  Revision History: 
   - UPD 2007-05-15 tlin2: Changed the url to the prod url. Also added if on dev server then use dev help.
   - UPD 2007-04-18 Uber1: Changed Braveheart in the url to Zeteo.
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/ 
function getDomServer() {
	var ret = 'http://www.nj.se';
	var server = window.location.toString();
	if(server.indexOf('zeteodts.wksc.local:8080')!=-1) 
		return 'http://zeteodts.wksc.local:8080';
	else if(server.indexOf('zeteodts.wksc.local:8090')!=-1) 
		return 'http://zeteodts.wksc.local:8090';
	else
		return ret;
}
function showHelp(helpId,showLang) {
	showLang =getSystemVar('helpLang');
	var w = 820;
	var h = 600;
	var server = window.location.toString();
	
	// Skall alltid gå mot prod  var url = getDomServer() + '/njab/wcl.nsf/avd/zeteo?OpenDocument&lang=' + showLang + '&art=' + helpId;;
	var url = 'http://www.nj.se/njab/wcl.nsf/avd/zeteo?OpenDocument&lang=' + showLang + '&art=' + helpId;;
	window_name= window.open(url,"Help_system","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width="+w+", height="+h);
	window_name.focus();
	
}
/*------------------------------------------------------------
   Function: openExternalLink
  open a url in an new window. Used from the resultlist

   Arguments:
   theUrl - What url that should be opened
--------------------------------------------------------------    
  Revision History: 
   - UPD 2010-06.10 tlin2: Added check against https:// adresses to
   - UPD 2009-02-11 tlin2: Added check if there is a http adress. If so dont add template.htm.....
   - UPD 2007-11-07 uber1: Using view=popup-styled url (with 'theUrl' as src-param), in order to catch the request in CustomLoggerService
   - NEW 2007-02-20 tlin2: Initial version. 
------------------------------------------------------------*/ 
function openExternalLink(theUrl,logParms, w,h) { if(logParms==null) logParms = "";
	if(w==null) w = 800;
	if(h==null) h = 600;
	var ppUrl = "";
	//debug("theUrl=" + theUrl);
	if (theUrl.indexOf("http://") == 0 || theUrl.indexOf("https://") == 0) {
		ppUrl = theUrl;
	} else {
		if (theUrl.indexOf("www.nj.se") > 0) {
		  ppUrl = "template.htm?view=popup&src=" + escape(theUrl) + logParms;
		} else {
		  ppUrl = "template.htm?view=popup&src=" + theUrl + logParms;
		}
	}
	ext_link =  window.open(ppUrl,"External_Link","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width="+w+", height="+h);
	ext_link .focus();
}

/*------------------------------------------------------------
   Function: openIframeLink
  Open the iframe document in a window

   Arguments:
   theUrl - What url that should be opened
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-02-22 tlin2: Initial version. 
------------------------------------------------------------*/ 
function openIframeLink(theUrl) {
	var w = 800;
	var h = 600;
	OpenWindow=window.open("", "External_Link","toolbar=yes, location=yes, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width="+w+", height="+h);
	OpenWindow.document.write("<HEAD>")
	OpenWindow.document.write("<TITLE>Norstedts Juridik R&auml;ttsdatabaser</TITLE>")
	OpenWindow.document.write('<META http-equiv="Content-Type" content="text/html; charset=utf-8">')
        OpenWindow.document.write('<LINK type="text/css" rel="stylesheet" href="common.css">')
        //OpenWindow.document.write('<LINK type="text/css" rel="stylesheet" href="prinsSaveCommon.css">')
        OpenWindow.document.write('<SCRIPT language="JavaScript" type="text/javascript" src="include/printSaveDocument.js"></SCRIPT>')
        OpenWindow.document.write('<SCRIPT language="JavaScript" type="text/javascript" src="include/njCommon.js"></SCRIPT>')
        //OpenWindow.document.write('<SCRIPT language="JavaScript" type="text/javascript" src="include/navigation.js"></SCRIPT>')
	OpenWindow.document.write('</HEAD>')
 
	//OpenWindow.document.write('<BODY onload="initPrintSaveDoc();">')
	OpenWindow.document.write('<BODY>')
	OpenWindow.document.write('<IFRAME id="docFrame" name="docFrame" frameborder="0" src="' + theUrl + '" width="100%" height="100%"></IFRAME>')
	OpenWindow.document.write(document.getElementById("hFooter").innerHTML);
	OpenWindow.document.write("</BODY>")
	OpenWindow.document.write("</HTML>")
	
	OpenWindow.document.close()
	self.name="main"
	/*
	var bodyElms = docFrame.document.getElementsByTagName("body");
  	if (bodyElms.length > 0) {
    		bodyElm = bodyElms.item(0);
    		
    		var htmlElms = OpenWindow.document.getElementsByTagName("html");
	  	if (htmlElms.length > 0) {
	    		htmlElm = htmlElms.item(0);
	    		htmlElm.appendChild(bodyElm.cloneNode(true));
	  	}
  	}
  	*/
}
/*------------------------------------------------------------
   Function: sortSearch
  Sort the resultlist

   Arguments:
   sortBy - How should the resultlist be sorted
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/ 
function sortSearch(sortBy) {
	var sortIT;
	setCookie('sortBy',sortBy);
	if(sortBy =="") {
		sortIT = "template.htm?view=hitlist&s_action=RefineSearch&s_pageNum=1&s_sort=null";
        	
	} else {
		sortIT = "template.htm?view=hitlist&s_action=RefineSearch&s_pageNum=1&s_sort=" + sortBy;
	}
//	parent.mainFrame.location=sortIT;
	eval(getFrame("mainFrame")).location=sortIT;
}
function setSortSearch() {
	var sortBy = getCookie('sortBy');
	setListBoxValue('sortby', sortBy) 
	
}
/*------------------------------------------------------------
   Function: isEnterKeySimple
  Function that check what key is pressed

   Arguments:
   event - what key that is pressed
--------------------------------------------------------------    
  Revision History: 
   - UPD 2007-03-21 tlin2: Added check against extSource
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/
var inIsEnterKeySimple = false;
function isEnterKeySimple(event)
{
	if (inIsEnterKeySimple) return;
	inIsEnterKeySimple = true;
	var keycode = 0;
	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (event)
	{
		keycode = event.which;
	}
	if(keycode == 13)
	{
		doSearch(byId('searchText'),byId('extSource'));
	    //return true;
	}
	setTimeout("inIsEnterKeySimple = false", 100);
    return false;
}
function isEnterKey(event)
{
	var keycode = 0;
	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (event)
	{
		keycode = event.which;
	}
	if(keycode == 13)
	{
		return true;
	}
    return false;
}
/*------------------------------------------------------------
   Function: isEnterKeyAdvanced
  Function that check what key is pressed

   Arguments:
   event - what key that is pressed
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 
------------------------------------------------------------*/
function isEnterKeyAdvanced(event)
{
	var keycode = 0;
	if (window.event)
	{
		keycode = window.event.keyCode;
	}
	else if (event)
	{
		keycode = event.which;
	}

	if(keycode == 13)
	{
		runAdvSearch();
	    //return true;
	}
    return false;
}
/*------------------------------------------------------------
   Function: printDiv
  Print the conten in a div.

   Arguments:
   divName - name of the div to print
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-29 tlin2: Initial version. 

------------------------------------------------------------*/  
function printThis(frameName){
	var fr = eval(getFrame("mainFrame"));
	fr.focus();
	fr.print();
}
function printDiv(divName)
{
	var a = window.open('','','width=200,height=200');
	a.document.open("text/html");
	a.document.write('<HTML>');
	a.document.write('<HEAD>');
   a.document.write('<TITLE>' + PRINTHEADER + '</TITLE>');
   a.document.write('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">');
   a.document.write('<LINK HREF="common.css" REL="stylesheet" TYPE="text/css">');
   a.document.write('<SCRIPT language="JavaScript" type="text/javascript" src="include/njCommon.js"></SCRIPT>');
	a.document.write('</HEAD>');
	a.document.write('<BODY>');
	a.document.write(document.getElementById(divName).innerHTML);
	a.document.write('</BODY>');
	a.document.write('</HTML>')
	a.document.close();
	a.print();
	a.close();
}


/*------------------------------------------------------------
   Function: clearField
   Clear a field if the content is equal to checkText argument.

   Arguments:
   fieldName - name to check   
   checkText - text to check 
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-26 tlin2: Initial version. 

------------------------------------------------------------*/  
function clearField(fieldName,checkText) {
	//debug("clearField:" + fieldName + $("#"+fieldName).val;
	var apa = $("#" + fieldName).val();
	debug(apa);
	//debug("clearField:" + fieldName + " " + byId(fieldName).value);
	if(byId(fieldName).value == checkText) {
		byId(fieldName).value = "";
	}
}
/*------------------------------------------------------------
   Function: setSelectedIndex
   Set a value in a listbox.

   Arguments:
   selObj - name of listbox   
   selNumber - number of value to set
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-26 tlin2: Initial version. 

------------------------------------------------------------*/  
function setSelectedIndex(selObj, selNumber) {
	byId(selObj).selectedIndex = selNumber;
}

/*------------------------------------------------------------
   Function: getSelectedIndexes
   Get the selected value from a listbox.
   Works with single or multiselected listboxes

   Arguments:
   selObj - name of listbox   
--------------------------------------------------------------    
  Revision History: 
   - NEW 2007-01-26 tlin2: Initial version. 

------------------------------------------------------------*/  
function getSelectedIndexes(selObj) {
	if (selObj.type == 'select-one') {
		return new Array(selObj.selectedIndex);
	} else {
		var indexes = new Array();
		for (var i = 0; i < selObj.options.length; i++) {
			if (selObj.options[i].selected) {
				indexes.push(i);
			}
		}
	return indexes;
	}
}
/*------------------------------------------------------------
   Function: doSearch
   Perform a search. Used in the main,simple search and 
   hitlist dialog
   
   Arguments:
   value - what to search for
--------------------------------------------------------------    
Revision History: 
	- UPD 2008-01-07 tlin2:	Added log capacity
	- UPD 2007-11-15 tlin2: Added phraseSearches cookie setting
	- UPD 2007-05-10 tlin2: Changed handling of contentdomains
	- UPD 2007-03-07 tlin2: Added cookie handling
  - NEW 2007-01-25 tlin2: Initial version. 
------------------------------------------------------------*/  
function setExtSource(checker) {
	isChecked= true;
	try {
		isChecked = checker.checked;
	} catch(ex){
		isChecked= false;
	}

	if(getSystemVar('country') != "dk") { 
		if(isChecked==true) {
			setCookie("extSource","checked");
		}else {
			setCookie("extSource","unchecked");
		}
	}
}
function doSearch(aVal, aChecker){
  var searchFor = aVal.value;
  var aCheck="";
  try {
    aCheck = aChecker.value
  } catch(ex) {
    aCheck=getCookie("extSource");
  }
  if(searchFor == DEF_SEARCH_TEXT) searchFor = "";
	if(searchFor == "") return alert(NOVALUE);

  var searchString = retSearch(searchFor, aCheck,"");
  if(searchString == "") return alert(NOVALUE);
//  debug(getFrame("mainFrame"));
  debug("DOSEARCH searchString="+searchString);
  eval(getFrame("mainFrame")).location.href = searchString;

}

function retSearch(searchFor, aCheck,extraParams, field, sortfield){
	searchFor = searchFor.replace(new RegExp("'","g"),'"');
	if (!field || field==undefined || field=="undefined")
		field = null;
	if (!sortfield || sortfield==undefined || sortfield=="undefined")
		sortfield = "";
	
  deleteCookie('phraseSearches');
  deleteCookie('selectedNav');
  deleteCookie('navInfo');
  deleteCookie('navDate');
  deleteCookie('navSource');
  //clearAdvCookie();
	
	var mithQuery="";
	mithQuery += "&type=simple&runType=manual";
  isChecked= getCookie("extSource");
  if (aCheck == "checked") isChecked = "checked";

	//---------------------------------------------------- 
  // save the searchstring in cookies 
  //---------------------------------------------------- 
  setCookie('simpleSearchValue',searchFor);
  setCookie('searchFor',searchFor);
  setCookie('searchedFor',searchFor);
	
  var queries = new Array();
  var queriesInc = new Array();
  var qIx = -1;
  var searchString = "template.htm?view=hitlist&s_action=newSearch&s_pageNum=1&s_searchParam=view|" + SEARCHVIEW;	
  	  
	//---------------------------------------------------- 
	// Add to query in Mithrandir
	//---------------------------------------------------- 	
	if(field == "anchors") {
		mithQuery += "&anchorValue="+	encodeURI(searchFor.replace( new RegExp('"','g'),'#'));;
	} else {
		mithQuery += "&all="+	encodeURI(searchFor.replace( new RegExp('"','g'),'#'));
	}
	//---------------------------------------------------- 
	// Check if the query has some strange syntax
	//---------------------------------------------------- 	
  var errorText=checkQuery(searchFor);
  if(errorText != "") {return alert(errorText);}

	//---------------------------------------------------- 
	//translate the query to right syntax	
	//---------------------------------------------------- 
  searchFor = translateQuery2(searchFor);
    
  if(trim(searchFor) == "") return "";
  if(phraseSearches != "") setCookie('phraseSearches',phraseSearches);
  if (orSearch == true) {
    var result = searchFor.split(" xyz_or_abc_or_orm ");
    var unionName = "";
    for (var a=0; a<result.length; a+=1){
      searchString += "&s_filter=simple|or" + a + "|true|null|" + result[a] + "|all|true";
      unionName += "|or" + a;
    }
    qIx ++
    queries[qIx]= "unionFor";
    queriesInc[qIx]= "|AND|";
    searchString += "&s_unionFilter=union|" + queries[qIx] +"|true" + unionName;
  } else {
    if(field == "anchors") {
    	qIx ++;
        queries[qIx]= "searchFor";
        queriesInc[qIx]= "|AND|";
    	searchString += "&s_filter=simple|" + queries[qIx] + "|true|" + field + "|" + searchFor.toLowerCase() + "|phrase|true";
    } else {	
    	if(searchFor.indexOf('"')!= -1) {
    		var searchForS = searchFor.split('"');
    		for (var i = 0; i < searchForS.length; i++){
    			if(trim(searchForS[i]) != "") {
        			qIx ++;
        		    queries[qIx]= "searchFor" + i;
        		    queriesInc[qIx]= "|AND|";
					if ((i % 2) == 0) {
						searchString += "&s_filter=simple|" + queries[qIx] + "|true|" + field + "|" + searchForS[i].toLowerCase() + "|all|true";
					} else {
						searchString += "&s_filter=simple|" + queries[qIx] + "|true|" + field + '|"' + searchForS[i].toLowerCase() + '"|all|true';
					}
    		    }
            };	
    	} else {
    		qIx ++;
    	    queries[qIx]= "searchFor";
    	    queriesInc[qIx]= "|AND|";
    		searchString += "&s_filter=simple|" + queries[qIx] + "|true|" + field + "|" + searchFor.toLowerCase() + "|all|true";
    	}
    }
  }

	//---------------------------------------------------- 
	//Handle content domains
	//---------------------------------------------------- 	
  var gcd = getCookie("G_ContentDomains");
  gcd = gcd.replace(new RegExp(';;',"g"),';');
  gcd = trim(gcd.replace(new RegExp(';',"g"),' '));	
  gcd = gcd.replace(new RegExp('  ',"g"),' ');
  gcd = gcd + ' ' +CDWEB;
	//---------------------------------------------------- 
	//if checked add web crawled material
	//---------------------------------------------------- 
  if (isChecked != "checked"){
      gcd = gcd.replace(' '+CDWEB,'');
      qIx ++;
      queries[qIx]= "extSource";
      searchString += "&s_filter=simple|" + queries[qIx] + "|true|contentpart|" + CDWEB +"|any|true"
      queriesInc[qIx]= "|ANDNOT|";
      mithQuery += "&extSource=false";
	} else {
		mithQuery += "&extSource=true";
	}

	//---------------------------------------------------- 
	// only the material that the user has access to
	//---------------------------------------------------- 	
	if(gcd!="") {
    qIx ++;
    queries[qIx]= "contentsec";
    queriesInc[qIx]= "|AND|";
    searchString += "&s_filter=simple|" + queries[qIx] + "|true|contentdomains|" + gcd + "|any|true"
  }  
  //------------------------------------------------------------------------ 
	// Check if there is any extra search paramaters that should be processed
	//------------------------------------------------------------------------
	if(extraParams != "" && typeof extraParams != "undefined") { 	
    //debug("extraParams="+extraParams);
    var restrictTo = getURL(extraParams,"restrictTo");
    var restrictValue = getURL(extraParams,"restrictValue");
    if(restrictTo != "" && restrictValue != "") {
      qIx ++;
      queries[qIx]= "restrict";
      queriesInc[qIx]= "|AND|";
      if(restrictTo == "informationtype") {
        searchString += "&s_filter=simple|" + queries[qIx] + "|true|informationtype|" + restrictValue + "|any|true"	
      } else {
        searchString += "&s_filter=simple|" + queries[qIx] + "|true|topics|" + restrictValue + "|any|true"	
      }
      mithQuery += "&restrictTo="+encodeURI(restrictTo);
      mithQuery += "&restrictValue="+encodeURI(restrictValue); 
    }
  }
	//---------------------------------------------------- 
	// build the searchstring
	//---------------------------------------------------- 
	searchString += "&s_compositeFilter=composite|comquery|true|";
	for(var ix=0;ix<qIx+1;ix++) {
		searchString += queries[ix]+ queriesInc[ix] ;
	}
	searchString += "&s_complex=navigator|lemmatization&s_filterAsTerms=comquery";
	deleteCookie('sortBy');
	
	//---------------------------------------------------- 
	// Add current search to server
	//---------------------------------------------------- 
	if (mithQuery!="") addSetting("addSearch",mithQuery);
	if(sortfield != "") searchString += '&s_sort=' + sortfield + '|true';
	debug('searchString='+searchString);
	return searchString;
}

function fixSwedish(fromStr) {
	var toStr = fromStr;
	toStr = toStr.replace(new RegExp('å',"g"),'&#229;');
	toStr = toStr.replace(new RegExp('ä',"g"),'&#228;');
	toStr = toStr.replace(new RegExp('ö',"g"),'&#246;');
	toStr = toStr.replace(new RegExp('Å',"g"),'&#197;');
	toStr = toStr.replace(new RegExp('Ä',"g"),'&#196;');
	toStr = toStr.replace(new RegExp('Ö',"g"),'&#214;');
	return toStr;
}
function unXML(fromStr)  {
	if(fromStr == null) return "";
	var toStr = fromStr;
	toStr = toStr.replace(new RegExp('&amp;',"g"),'&');
	toStr = toStr.replace(new RegExp('&Aring;',"g"),'Å');
	toStr = toStr.replace(new RegExp('&aring;',"g"),'å');
	toStr = toStr.replace(new RegExp('&auml;',"g"),'ä');
	toStr = toStr.replace(new RegExp('&Auml;',"g"),'Ä');
	toStr = toStr.replace(new RegExp('&ouml;',"g"),'ö');
	toStr = toStr.replace(new RegExp('&Ouml;',"g"),'Ö');
	toStr = toStr.replace(new RegExp('&AElig;',"g"),'Æ');
	toStr = toStr.replace(new RegExp('&Oslash;',"g"),'Ø');
	toStr = toStr.replace(new RegExp('&aelig;',"g"),'æ');
	toStr = toStr.replace(new RegExp('&oslash;',"g"),'ø');
	toStr = toStr.replace(new RegExp('&eacute;',"g"),'é');
	toStr = toStr.replace(new RegExp('&sect;',"g"),'§');

	toStr = toStr.replace(new RegExp('&#150;',"g"),'-');
	toStr = toStr.replace(new RegExp('&#8221;',"g"),'”');
	return toStr;
}
function unHMTLNum(fromStr) {
	if(fromStr == null) return "";
	var toStr = fromStr;
	toStr = toStr.replace(new RegExp('&#32;',"g"),' ');
	toStr = toStr.replace(new RegExp('&#33;',"g"),'!');
	toStr = toStr.replace(new RegExp('&#35;',"g"),'#');
	toStr = toStr.replace(new RegExp('&#36;',"g"),"$");
	toStr = toStr.replace(new RegExp('&#39;',"g"),"'");
	toStr = toStr.replace(new RegExp('&#40;',"g"),'(');
	toStr = toStr.replace(new RegExp('&#41;',"g"),')');
	toStr = toStr.replace(new RegExp('&#42;',"g"),'*');
	toStr = toStr.replace(new RegExp('&#43;',"g"),'+');
	toStr = toStr.replace(new RegExp('&#44;',"g"),',');
	toStr = toStr.replace(new RegExp('&#45;',"g"),'-');
	toStr = toStr.replace(new RegExp('&#46;',"g"),'.');
	toStr = toStr.replace(new RegExp('&#47;',"g"),'/');
	toStr = toStr.replace(new RegExp('&#48;',"g"),'0');
	toStr = toStr.replace(new RegExp('&#49;',"g"),'1');
	toStr = toStr.replace(new RegExp('&#50;',"g"),'2');
	toStr = toStr.replace(new RegExp('&#51;',"g"),'3');
	toStr = toStr.replace(new RegExp('&#52;',"g"),'4');
	toStr = toStr.replace(new RegExp('&#53;',"g"),'5');
	toStr = toStr.replace(new RegExp('&#54;',"g"),'6');
	toStr = toStr.replace(new RegExp('&#55;',"g"),'7');
	toStr = toStr.replace(new RegExp('&#56;',"g"),'8');
	toStr = toStr.replace(new RegExp('&#57;',"g"),'9');
	toStr = toStr.replace(new RegExp('&#58;',"g"),':');
	toStr = toStr.replace(new RegExp('&#64;',"g"),'@');
	toStr = toStr.replace(new RegExp('&#95;',"g"),'_');
	toStr = toStr.replace(new RegExp('&#229;',"g"),'å');
	toStr = toStr.replace(new RegExp('&#228;',"g"),'ä');
	toStr = toStr.replace(new RegExp('&#246;',"g"),'ö');
	toStr = toStr.replace(new RegExp('&#197;',"g"),'Å');
	toStr = toStr.replace(new RegExp('&#196;',"g"),'Ä');
	toStr = toStr.replace(new RegExp('&#198;',"g"),'Æ');
	toStr = toStr.replace(new RegExp('&#214;',"g"),'Ö');  
	toStr = toStr.replace(new RegExp('&#216;',"g"),'Ø');
	toStr = toStr.replace(new RegExp('&#230;',"g"),'æ');
	toStr = toStr.replace(new RegExp('&#248;',"g"),'ø');
	toStr = toStr.replace(new RegExp('&#195;&#184;',"g"),'ø');
	toStr = toStr.replace(new RegExp('&#195;&#152;',"g"),'Ø');
	toStr = toStr.replace(new RegExp('&#195;&#165;',"g"),'å');
	toStr = toStr.replace(new RegExp('&#195;&#133;',"g"),'Å');	
	toStr = toStr.replace(new RegExp('&#195;&#164;',"g"),'ä');
	toStr = toStr.replace(new RegExp('&#195;&#132;',"g"),'Ä');	
	toStr = toStr.replace(new RegExp('&#195;&#182;',"g"),'ö');
	toStr = toStr.replace(new RegExp('&#195;&#150;',"g"),'Ö');	
	toStr = toStr.replace(new RegExp('&#195;&#166;',"g"),'æ');
	
	return toStr;
}
function createAnchorValue(id) {
	if(id=="") return "";
	id = id.replace(new RegExp(":","g"), "q");
	id = id.replace(new RegExp("/","g"), "q");
	id = id.replace(new RegExp("\\.","g"), "q");
	id = id.replace(new RegExp("-","g"), "q"); 
	id = id.replace(new RegExp("$","g"), "");
	id = trim(id);
	var searchFor = '_lopnr';
	var idS = id.split(searchFor);
	if(idS.length > 0) {
		id = idS[0];
	} 
	if(id.substr(0,1).toLowerCase() != "x") id = "x" + id;
	if(id.substr(id.length-1,1).toLowerCase() != "x") id += "x" ;
	return id;
}
function removeXanchor(id) {
	id = createAnchorValue(id);
	if(id.substr(0,1).toLowerCase() == "x") id = id.substr(1,id.length-1);
	if(id.substr(id.length-1,1).toLowerCase() == "x") id = id.substr(0,id.length-1);
	return id;
}
function gotoPersistent(id) {
	var theUrl='';
	id = id.replace(new RegExp(':',"g"), "q");
	id = id.replace(new RegExp('/',"g"), "q")
	theUrl = "template.htm?view=ghitlist&s_action=newSearch&s_pageNum=1&s_context=ghitlist&s_searchParam=view|" + SEARCHVIEW
  theUrl += "&s_filter=simple|jmpquery|true|persistentid|x" + escape(id) + "x|phrase|true"
  theUrl += "&s_compositeFilter=composite|comquery|true|jmpquery|and";
  theUrl += "&s_complex=navigator|lemmatization&s_filterAsTerms=comquery";
  theUrl += "&fn=goto&errortype=gotoerror1";
  top.mainFrame.location = theUrl;
}
/*------------------------------------------------------------
   Function: byId
   shortcommand for getting a id from a document if exist
   
   Arguments:
   id - name of id
--------------------------------------------------------------    
  Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/  
function byId(id) {
    return document.getElementById ? document.getElementById(id) : false;
}
/*------------------------------------------------------------
   Function: showParts
   Show a id
   
   Arguments:
   elem - name of id
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/  
function showParts(elem){
	elem.style.display="";
}
/*------------------------------------------------------------
   Function: hideParts
   Hide a id
   
   Arguments:
   elem - name of id
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function hideParts(elem){
	elem.style.display="none";
}
/*------------------------------------------------------------
   Function: visibleParts
   Show a id if exist
   
   Arguments:
   elem - name of id
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function visibleParts(elem){
	if(!elem){return;}
	showParts(elem);
	elem.style.visibility="visible";
}
/*------------------------------------------------------------
   Function: blockParts
   hide a id if exist
   
   Arguments:
   elem - name of id
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function blockParts(elem){
	if(!elem){return;}
	  elem.style.visibility="hidden";
	  hideParts(elem);
}
/*------------------------------------------------------------
   Function: getURLParam
   Extract a Param from the Url
   
   Arguments:
   strParamName - name of param
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("&") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
    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;
}
function getURL(strHref, strParamName){
  var strReturn = "";
  var urlName;
  var urlValue;
  if ( strHref.indexOf("&") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("&")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      var aParam = aQueryString[iParam].split("=");
      urlName  =  aParam[0];
      urlValue =  aParam[1];
      if(urlName == strParamName.toLowerCase()) {
        strReturn = urlValue;
        break;
      }
    }
  }
  return strReturn;
}
/*------------------------------------------------------------
   Function: Left
   Extract a part of a string from the Left
   
   Arguments:
   str - String
   n - number of character
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version.  

------------------------------------------------------------*/
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
/*------------------------------------------------------------
   Function: Right
   Extract a part of a string from the Right
   
   Arguments:
   str - String
   n - number of character
--------------------------------------------------------------    
Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
/*------------------------------------------------------------
   Function: initGoto
   Init the goto dialog 
--------------------------------------------------------------    
 Revision History: 
   - NEW 2006-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function initGoto() {
    var errorMsg = getURLParam("error");
    var setfieldvalue = getURLParam("setfieldsrc");
    if (setfieldvalue != "") document.getElementById("fieldtypeid").value = setfieldvalue;
    if (errorMsg != "") {
    	document.getElementById("errorMsg").innerHTML=errorMsg;
    }	
}
/*------------------------------------------------------------
   Function: replaceSC
   Replace strange char. NOT IN USE
   
   Arguments:
   theString - String that shuld be checked
--------------------------------------------------------------    
 Revision History: 
   - NEW 2007-01-20 tlin2: Initial version. 

------------------------------------------------------------*/
function replaceSC(theString) {
	/*
	theString = replace(theString,"¢,'&Auml;');	
 	theString = replace(theString,"?&Aring;');
 	theString = replace(theString,"?,'&Ouml;');
	theString = replace(theString,"?'&auml;');	
 	theString = replace(theString,"?'&aring;');
 	theString = replace(theString,"?&ouml;'); 	
 	theString = replace(theString,"§",'&sect;'); 
 	*/
/* 	
	theString = replace(theString,'§,unescape("%C4"));	
 	theString = replace(theString,'?nescape("%C5"));
 	theString = replace(theString,'?,unescape("%C6"));
	theString = replace(theString,'?unescape("%E4"));	
 	theString = replace(theString,'?unescape("%E5"));
 	theString = replace(theString,'?nescape("%E6")); 	
 	theString = replace(theString,'§',unescape("%A7"));  	
*/
 	return theString;	 	
}
/*------------------------------------------------------------
   Function: replace
   Replace a token in a string
   
   Arguments:
      s - string to be processed
      t - token to be found and removed
      u - token to be inserted
      return - returns new String
--------------------------------------------------------------    
 Revision History: 
   - NEW 2007-12-15 tlin2: Initial version. 

------------------------------------------------------------*/
function replace(s, t, u) {
	try {
	  i = s.indexOf(t);
	  r = "";
	  if (i == -1) return s;
	  r += s.substring(0,i) + u;
	  if ( i + t.length < s.length)
	    r += replace(s.substring(i + t.length, s.length), t, u);
	  return r;
	} catch(ex) {
		return s;
	}
}
/*------------------------------------------------------------
   Function: clearNavigatorCookie
  	Clear the information in the cookie regarding
  	navigators
--------------------------------------------------------------    
  Revision History: 
  - NEW 2007-04-26 tlin2: Initial version. 

------------------------------------------------------------*/ 
function clearNavigatorCookie() {
	deleteCookie('navInfo');
  deleteCookie('navDate');
  deleteCookie('navSource');  
}
/*------------------------------------------------------------
   Function: clearAdvCookie
  	Clear the information in the cookie when the user clicks
  	on advanced search in the topmenu
--------------------------------------------------------------    
  Revision History:
  - UPD 2010-05-17 tlin2: Added deleteCookie's 
  - UPD 2007-12-03 uber1: Commented away the deletion of 'simpleSearchValue' cookie, in order to not affecting simple search.
  - UPD 2007-06-12 tlin2: Added remove of navigator cookies
  - NEW 2007-02-28 tlin2: Initial version. 

------------------------------------------------------------*/ 
function clearAdvCookie() {
	deleteCookie('advSearchFor');
	deleteCookie('advcontentsec0');
	deleteCookie('advcontentsec1');
	deleteCookie('advdateFrom');
	deleteCookie('advdateTo');
	deleteCookie('extSource');
	deleteCookie('advmaterialtype1');
	deleteCookie('advinformationtype');
	deleteCookie('advforStatus0');
	deleteCookie('advforStatus1');
	deleteCookie('advforStatus2');
	deleteCookie('advforArea');
	deleteCookie('advavgSourceValue');
	deleteCookie('advavgSourceOpt1Sub');
	deleteCookie('advavgTargetType');
	deleteCookie('advavgSourceOpt2Sub');
	deleteCookie('advavgSourceOpt3Sub');
	deleteCookie('avgSourceOpt3Sub2Sub');
	deleteCookie('advavgSourceOpt4Sub');
	deleteCookie('advavgSourceOpt5Sub');
	deleteCookie('advavgSourceOpt6Sub');
	deleteCookie('advavgSourceOpt7Sub');
	deleteCookie('advavgSourceOpt8Sub');
	deleteCookie('advavgSourceOpt9Sub');
	deleteCookie('advavgSourceOpt10Sub');
	deleteCookie('advavgSourceOpt11Sub');
	deleteCookie('advavgSourceOpt12Sub');
	deleteCookie('advavgSourceOpt13Sub');
	deleteCookie('avdforSource');
  deleteCookie('avdlagSource');
  deleteCookie('avdmynSource');
  deleteCookie('avdartSourceOpt');
	deleteCookie('avdeuSourceOpt');		
	deleteCookie('searchFor');	
	deleteCookie('advNot');
	deleteCookie('advPhrase');
	deleteCookie('advAny');
	deleteCookie('advProx');
	deleteCookie('proxnum');
	deleteCookie('searchFor');
  deleteCookie('searchedFor');
  deleteCookie('navInfo');
  deleteCookie('navDate');
  deleteCookie('navSource');  
}
/*------------------------------------------------------------
   Function: clearSimpleCookie
  	Clear the information in the cookie when the user clicks
  	on home/simple search in the menu
--------------------------------------------------------------    
  Revision History: 
  - NEW 2007-03-26 tlin2: Initial version. 

------------------------------------------------------------*/ 
function clearSimpleCookie() {
	deleteCookie('searchFor');	
	deleteCookie('simpleSearchValue');	
}

/*----------------------------------------------------------------------------------------------------
Function: normalizeQuery
   Used to replace special chars to non-special charcombinations prior to goto- and link query submission
------------------------------------------------------------------------------------------------------
Revision History:
 - NEW 2007-03-26 uber1: Initial version.
----------------------------------------------------------------------------------------------------*/	
function normalizeQuery(aQuery)
{
  var result = aQuery;

  result = result.replace(new RegExp(unescape("%C5"),"g"), "AA");
  result = result.replace(new RegExp(unescape("%C4"),"g"), "AE");
  result = result.replace(new RegExp(unescape("%D6"),"g"), "OE");
  result = result.replace(new RegExp(unescape("%E5"),"g"), "aa");
  result = result.replace(new RegExp(unescape("%E4"),"g"), "ae");
  result = result.replace(new RegExp(unescape("%F6"),"g"), "oe");
  result = result.replace(new RegExp(unescape("%A7"),"g"), "p");
  
  return result;
}
/*----------------------------------------------------------------------------------------------------
Function: isFrame
   Check if a specific frame is current
------------------------------------------------------------------------------------------------------
Revision History:
 - NEW 2009-11-20 tlin2: Initial version.
----------------------------------------------------------------------------------------------------*/	
function isFrame(frameName) {
	try {
		switch(frameName.toLowerCase()) {
			case "mainframe":
				var mainframeloc = eval(getFrame("mainFrame")).location;
				return true;
			case "rightframe":
				var mainframeloc = eval(getFrame("mainFrame")).rightFrame.location;
				return true;        
			case "leftframe":
				var mainframeloc = eval(getFrame("mainFrame")).leftFrame.location;
				return true;
			default:
				return false;
		}
    } catch(ex) {
    	debug('catch isFrame ' + frameName);
    	return false;
     }
  }
/*----------------------------------------------------------------------------------------------------
Function: denormalizeQuery
   Used to reverse a previous call to normalizeQuery. Useful when displaying the aQuery value.
------------------------------------------------------------------------------------------------------
Revision History:
 - NEW 2007-04-16 uber1: Initial version.
----------------------------------------------------------------------------------------------------*/	
function denormalizeQuery(aQuery)
{
  var result = aQuery;

  result = result.replace("AA", unescape("%C5"));
  result = result.replace("AE", unescape("%C4"));
  result = result.replace("OE", unescape("%D6"));
  result = result.replace("aa", unescape("%E5"));
  result = result.replace("ae", unescape("%E4"));
  result = result.replace("oe", unescape("%F6"));
  result = result.replace(" p", " " + unescape("%A7"));

  return result;
}
function toNordicSign(aQuery) {
	  var result = aQuery;

	  result = result.replace("%E5", 'å');
	  result = result.replace("%E4", 'ä');
	  result = result.replace("%F6", 'ö');
	  result = result.replace("%C5", 'Å');
	  result = result.replace("%C4", 'Ä');
	  result = result.replace("%D6", 'Ö');
	  result = result.replace("%C6", 'Æ');
	  result = result.replace("%E6", 'æ');
	  result = result.replace("%F8", 'ø');
	  result = result.replace("%D8", 'Ø');   
	  return result;
}
/*----------------------------------------------------------------------------------------------------
Function: getSystemVar
   Used to get system environment variables
   
Arguments:
      what - what information to return.

------------------------------------------------------------------------------------------------------
Revision History:
 - NEW 2009-09-09 tlin2: Initial version.
----------------------------------------------------------------------------------------------------*/	
function getSystemVar(what) {
	var country = getCookie('appCountry');
	
	switch(what.toString().toLowerCase()) {
	case 'zeteoserver':
		return getCookie('zeteoserver');
		break;
		
	case 'gotourl':
		return 'http://' + getCookie('zeteoserver') + getSystemVar('webApp') + '/template.htm?view=dogoto&ref=';
		break;
		
	case 'topgotourl':
		if(country == 'se') {
			return "/"+ getCookie('webapp') +  getCookie('topgotourl');
		} else {
			return getCookie('portal') + trim(getCookie('topgotourl'));
		}
		break;
		
	case 'webapp':
		var wa = getCookie('webapp');
		return wa=="" ? "" : "/" + wa;
		break;
		
	case 'country':
		return country;
		break;
		
	case 'portal':
		if (country =="se") {
			return "http://" + getCookie('portal');
		} else {
			return getCookie('portal');
		}
		break;
		
	case 'top': 
		return country=="se" ? "top" : "top.mainZeteo";
		break;
		
	case 'helplang':
		return getCookie('helpLang');
		break;

	case 'navappname':
		return(navigator.appName);
		break;
	case 'navappversion':
		return(parseFloat(navigator.appVersion));
		break;
	case 'navappcodename':
		return(navigator.appCodeName);
		break;
	case 'navappminorversion':
		return(navigator.appMinorVersion);
		break;
	case 'navcpuclass':
		return(navigator.cpuClass);
		break;
	case 'navmimetypesmimetypes':
		return(navigator.mimeTypes);
		break;
	case 'navplatform':
		return(navigator.platform);
		break;
	case 'navplugins':
		return(navigator.plugins);
		break;
	case 'navsystemlanguage':
		return(navigator.systemLanguage);
		break;		
	case 'navuseragent':
		return(navigator.userAgent);
		break;
	case 'navuserlanguage':
		return(navigator.userLanguage);
		break;		
	case 'navuserprofile':
		return(navigator.userProfile);

	}
}
