function toggle(obj){
	objParent = obj.parentNode;
	objNext = objParent.nextSibling;
	cnt = 0;
	while(objNext.tagName!="DD"){
		if(cnt==5) break;
		cnt++;
		objNext = objNext.nextSibling;
	}
	objParent.className = (objParent.className=='collapse')? 'expand' : 'collapse';
	title = (objParent.className=='collapse')? 'Vis' : 'Skjul'
	objParent.setAttribute('TITLE', title);
	objNext.className = (objNext.className=='collapse')? 'expand' : 'collapse';
}

function selectOptions(n){
	arr_options = document.forms[0][n];
	for(i=0; i<arr_options.length; i++){
		arr_options[i].checked = true;
	}
}

function deselectOptions(n){
	arr_options = document.forms[0][n];
	for(i=0; i<arr_options.length; i++){
		arr_options[i].checked = false;
	}
}

function openWindowFreesize(pageUrl,paramWidth,paramHeight){
	var properties = "width="+paramWidth+",height="+paramHeight+",directories=0,left=" + ((screen.width-paramWidth)/2) + ",top=" + ((screen.height-paramHeight)/2) + ",location=0,toolbar=0,scrollbars=yes,menubar=no,resizable=no";
    var popupWindow = window.open(pageUrl, "popupWindow", properties);
    popupWindow.focus();
}

function openWindowEditor(pageUrl,paramWidth,paramHeight){
	var properties = "width="+paramWidth+",height="+paramHeight+",directories=0,left=" + ((screen.width-paramWidth)/2) + ",top=" + ((screen.height-paramHeight)/2) + ",location=0,toolbar=0,scrollbars=yes,menubar=no,resizable=yes,status=yes";
    var popupWindow = window.open(pageUrl, "popupEditorWindow", properties);
    popupWindow.focus();
}

function clickButtonViaEnter(evt, buttonid){
	evt = (evt)? evt : event;
	var target = (evt.target) ? evt.target : evt.srcElement;
	var charcode = (evt.charcode) ? evt.charcode : 
		((evt.which)? evt.which : evt.keyCode);
	if (charcode == 13 || charcode == 3) { // 3 is mac enter
	    document.getElementById(buttonid).focus();
		document.getElementById(buttonid).click();
		return false;
	}
	return true;
}

function doSearch(){
	var strParam = '?q=' + encodeURIComponent(document.getElementById("searchField").value);
	var strUrl = document.getElementById("resultPage").value;

	// Redirect to searchpage.
	document.location = strUrl + strParam;
	return true;
}

// this Object can give you methods to work on querystring in javascript
function QS(q) {
	if(q.length > 1) 
		this.q = q.substring(1,q.length);
	else 
		this.q = null;
	this.keyValuePairs = new Array();
	if (q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { 
		return this.keyValuePairs; 
	}
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0]== s)
				return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() {
		return this.keyValuePairs.length; 
	} 
	this.replaceValue = function(key,value) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0]== key) {
				this.keyValuePairs[j] = key+"="+value;
				return;
			}
		}
		this.keyValuePairs[this.keyValuePairs.length] = key+"="+value;
		return;
	}
	this.addValue = function(key,value) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0]== key) {
				this.keyValuePairs[j] = this.keyValuePairs[j]+value;
				return;
			}
		}
		this.keyValuePairs[this.keyValuePairs.length] = key+"="+value;
		return;
	}
	this.removeValuePart = function(key, value) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0]== key) {
			    re = new RegExp(value,"i");
			    var s = this.keyValuePairs[j].split("=")[1];
				this.keyValuePairs[j] = key+"="+s.replace(re,"");
				return;
			}
		}
	}
    this.removeValuePartToEnd = function(key, value) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0]== key) {
			    var s = this.keyValuePairs[j].split("=")[1];
			    var v = value.split("%20")[0];
			    re = new RegExp(v,"i");
				this.keyValuePairs[j] = key+"="+s.substring(0,s.search(re));
				return;
			}
		}
	}
	this.getQueryString = function() {
		var s = "?";
		for(var j=0; j < this.keyValuePairs.length; j++) {
			s+=this.keyValuePairs[j];
			if (j<(this.keyValuePairs.length-1)) s+="&";
		}
		return s;
	}
}

function performDrillDownNavigation(s, qtype) {
	var qs = new QS(document.location.search);
	if (qs.getValue("q")=="") {
		if(qtype == 'adv'){
			qs.addValue("f",encodeURIComponent(" "+s.value));
		}
		else{
			qs.addValue("f",encodeURIComponent(" +"+s.value));
		}
	} else {
		if(qtype == 'adv'){
			qs.addValue("f",encodeURIComponent(" AND "+s.value));
		}
		else{
			qs.addValue("f",encodeURIComponent(" +"+s.value));
		}
		
	}
	
	/* Remove navX counter from query on new navigator choice */
	if (qs.getValue("navX")!="") {
		qs.removeValuePartToEnd("navX","");
	}
	
	document.location = qs.getQueryString();
	return true;
}

function removeDrillDownNavigator(drilltype, s, qtype) {
	var qs = new QS(document.location.search);
	if (drilltype == 'yes') {
		if (qs.getValue("q")=="") {
			if(qtype == 'adv'){
				qs.removeValuePartToEnd("f",encodeURIComponent(""+s));
			}
			else{
				qs.removeValuePartToEnd("f",encodeURIComponent("+"+s));
			}
		} else {
			if(qtype == 'adv'){
				qs.removeValuePartToEnd("f",encodeURIComponent("AND "+s));
			}
			else{
				qs.removeValuePartToEnd("f",encodeURIComponent("+"+s));
			}
		}
	} else {
		if (qs.getValue("q")=="") {
			if(qtype == 'adv'){
				qs.removeValuePart("f",encodeURIComponent(""+s));
			}
			else{
				qs.removeValuePart("f",encodeURIComponent("+"+s));
			}
		} else {
			if(qtype == 'adv'){
				qs.removeValuePart("f",encodeURIComponent("AND "+s));
			}
			else{
				qs.removeValuePart("f",encodeURIComponent("+"+s));
			}
			
		}
	}
	
	/* Remove navX counter from query on new navigator choice */
	if (qs.getValue("navX")!="") {
		qs.removeValuePartToEnd("navX","");
	}
	
	document.location = qs.getQueryString();
	return true;
}
/* */
function performCronoNavigation(s, qtype) {
	var control = document.getElementById('controlname');
	var doctype = document.getElementById(control.value + '_drop_documenttype');
	var months = document.getElementById(control.value + '_drop_months');
	var years = document.getElementById(control.value + '_drop_years');
	var q = "";
	if(years.value != "")
	{
		if(qtype == 'adv'){
			q+=years.value;		
		}
		else{
			q+=" +" + years.value;
		}
		
	}
	if(months.value != "")
	{
		if(q != "")
		{
			if(qtype == 'adv'){
				q+=" AND ";
			}
			else{
				q+=" +";
			}
		}
		else{
			if(qtype != 'adv'){
				q+=" +";	
			}
		}
		
		q+=months.value;

	}
	if(doctype.value != "")
	{
		if(q != "")
		{
			if(qtype == 'adv'){
				q+=" AND ";
			}
			else{
				q+=" +";
			}
		}
		else{
			if(qtype != 'adv'){
				q+=" +";	
			}
		}
		
		q+=doctype.value;

	}
	
	var qs = new QS(document.location.search);
	qs.replaceValue("f",encodeURIComponent(" "+q));
	
	/* Remove navX counter from query on new navigator choice */
	if (qs.getValue("navX")!="") {
		qs.removeValuePartToEnd("navX","");
	}
	
	document.location = qs.getQueryString();
	return true;

}

function performAlphaNavigation(s, qtype) {
var qs = new QS(document.location.search);
	if (qs.getValue("q")=="") {
		if(qtype == 'adv'){
			qs.replaceValue("f",encodeURIComponent(" "+s));
		}
		else{
			qs.replaceValue("f",encodeURIComponent(" +"+s));
		}
	} else {
		if(qtype == 'adv'){
			qs.replaceValue("f",encodeURIComponent(" AND "+s));
		}
		else{
			qs.replaceValue("f",encodeURIComponent(" +"+s));
		}
		
	}
	/* Remove navX counter from query on new alphabet choice */
	if (qs.getValue("navX")!="") {
		qs.removeValuePartToEnd("navX","");
	}
	document.location = qs.getQueryString();
	return true;
}

function performProductTaxonomyFilterSearch(s) {
	var qs = new QS(document.location.search);
	if(s.value != "") {
	    qs.replaceValue("f",encodeURIComponent(" +("+s.value+")"));
	}
	else {
	    qs.replaceValue("f","");
	}
	qs.replaceValue("productname",encodeURIComponent(s.options[s.selectedIndex].text));
	document.location = qs.getQueryString();
	return true;
}

function performHistorySwitch(q, s) {
	document.location = q + '&his=' + s.value;
	return true;
}

function performDoSubSearch(s, qtype) {
	var qs = new QS(document.location.search);
	if(qtype == 'adv'){
		qs.addValue("f",encodeURIComponent(" AND " + s));
	}
	else {
		qs.addValue("f",encodeURIComponent(s));
	}
	qs.replaceValue("subsearch", encodeURIComponent("true"));
	qs.replaceValue("s", encodeURIComponent("fragmentsort"));
	/* Remove navX counter from query on new alphabet choice */
	if (qs.getValue("navX")!="") {
		qs.removeValuePartToEnd("navX","");
	}
	document.location = qs.getQueryString();
	return true;
}

function performSortSearch(s) {
	var qs = new QS(document.location.search);
	var sortItem = s.value.split("|")[0];
	var sortDirection = s.value.split("|")[1];
	qs.replaceValue("s",encodeURIComponent(sortItem));
	qs.replaceValue("sd",encodeURIComponent(sortDirection));
	document.location = qs.getQueryString();
	return true;
}

function performLanguageChange(lang) {
	var qs = new QS(document.location.search);
	qs.replaceValue("sc_lang",encodeURIComponent(""+lang));
	document.location = qs.getQueryString();
	return true;
}

function performAdvSimpleSwitch(adv, boxid){
	var query = document.getElementById(boxid);
	var qs = new QS(document.location.search);
	qs.replaceValue("adv",encodeURIComponent(adv));
	qs.replaceValue("q",encodeURIComponent(query.value));
	document.location = qs.getQueryString();
	return true;
}

var dtCh= "/";
var minYear=1700;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert(badday)
		return false
	}

return true
}

function CheckStartAndEndDate(startdate, enddate) {
	if(isDate(startdate) && isDate(enddate)){
		return true;
	}
	else{
		return false;
	}	
}

function resizepic(billede){
if (document.images[billede].width > 500)  {   
        var pixelL = 500;
        var langd = pixelL;
        var hojd = (document.images[billede].width) - pixelL;
        hojd = hojd/(document.images[billede].width);
        hojd = hojd * (document.images[billede].height); 
        hojd = (document.images[billede].height) - hojd;
       document.images[billede].width= langd;
       document.images[billede].height=hojd;
    } 
}

function doHighlight(bodyText, searchArray, highlightStartTag, highlightEndTag) 
{
 
  
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  
  var index = 1;
  var BodyTextNew = bodyText;

  for (var p = 0; p < searchArray.length; p++) {
	if((searchArray[p]!="") && (searchArray[p]!=null)) {
		searchTerm = searchArray[p];
		
  		var newText = "";
  		var i = -1;
  		var lcSearchTerm = searchTerm.toLowerCase();
  		var lcBodyText = BodyTextNew.toLowerCase();
  		
		while (BodyTextNew.length > 0) {
    		i = lcBodyText.indexOf(lcSearchTerm, i+1);
    		if (i < 0) {
      			newText += BodyTextNew;
      			BodyTextNew = "";
    		} else {
     		 // skip anything inside an HTML tag
      			if (BodyTextNew.lastIndexOf(">", i) >= BodyTextNew.lastIndexOf("<", i)) {
        		// skip anything inside a <script> block
        			if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
	  				// the highlightStartTag and highlightEndTag parameters are optional
  	 					var highlightStartTagToUse = "";
	  					var highlightEndTagToUse = "";
	  					if ((!highlightStartTag) || (!highlightEndTag)) {
   		 					highlightStartTagToUse = "<span id='highlighted_keyword_" + index.toString()  + "' onclick='this.focus();' onfocus='hilite(this)' onblur='delite(this)' style='background:#ffff66;color:#000000;cursor:hand;' TABINDEX=" + index + ">";
    		 				highlightEndTagToUse = "</span>";
  	  					}
	  					else {
							highlightStartTagToUse = highlightStartTag;
							highlightEndTagToUse = highlightEndTag;
	  					}
          				newText += BodyTextNew.substring(0, i) + highlightStartTagToUse + BodyTextNew.substr(i, searchTerm.length) + highlightEndTagToUse;
          				BodyTextNew = BodyTextNew.substr(i + searchTerm.length);
          				lcBodyText = BodyTextNew.toLowerCase();
          				i = -1;
	  					index = index + 1;
        			}
      			}
    		}
  		}
  	
	}
	else
	{
		newText = bodyText;
	}
	
	BodyTextNew = newText;
 
  }
  
  
  return BodyTextNew;
}

function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  var phraseindicatorindex = searchText.indexOf("\"");

  if(phraseindicatorindex > -1) {
  	treatAsPhrase = true;
  }
  else {
	treatAsPhrase = false;	
  }

  searchText = searchText.replace(/\"/g, "");
  searchText = searchText.replace(/\(/g, "");
  searchText = searchText.replace(/\)/g, "");
  searchText = searchText.replace(/\%/g, "");
  searchText = searchText.replace(/\+/g, "");
  searchText = searchText.replace(/\*/g, "");
  
  searchText = trim(searchText);

  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }


  var searchTermsfiltered= new Array();

  var newp = 0;
  for (var p = 0; p < searchArray.length; p++) {
   var searchword = searchArray[p];
   if(searchword != null && searchword != "" && searchword != undefined && searchword) { 
     searchTermsfiltered[newp] = searchword;
     newp++;
   }
  }

  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodytext = null;
  var rightdiv = null;
  
  var rightdiv = document.getElementById('fullviewHtmlContent');
 
  if(rightdiv)
  {
		bodytext = rightdiv.innerHTML;
  }
  
  bodytext = doHighlight(bodytext, searchTermsfiltered, highlightStartTag, highlightEndTag);
  
  rightdiv.innerHTML = bodytext;

  var initailelem = document.getElementById('highlighted_keyword_1');
  if(initailelem) {
  	initailelem.focus();
  }

  return true;
}

//Used for removing blanks from the start and the end of a string
function trim(val) {
    val = val.replace(/^\s+/, '');
    return val.replace(/\s+$/, '');
}


//Used for highlight
function hilite(obj) {
  obj.style.background = '#ffc160';
}
function delite(obj) {
  obj.style.background = '#ffff66';
}

var xmlHttp; 
var is_ie = (navigator.userAgent.indexOf('MSIE') >= 0) ? 1 : 0; 
var is_ie5 = (navigator.appVersion.indexOf("MSIE 5.5")!=-1) ? 1 : 0; 
var is_opera = ((navigator.userAgent.indexOf("Opera6")!=-1)||(navigator.userAgent.indexOf("Opera/6")!=-1)) ? 1 : 0; 
//netscape, safari, mozilla behave the same??? 
var is_netscape = (navigator.userAgent.indexOf('Netscape') >= 0) ? 1 : 0; 

function stateChangeHandler() 
{ 
    //readyState of 4 or 'complete' represents that data has been returned 
    if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){ 
        //Gather the results from the callback 
        var str = xmlHttp.responseText; 
    } 
} 

// XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url) { 
    xmlhttp.open('GET', url, true);
    var sessionid = document.getElementById('sessionid').value; 
    xmlhttp.setRequestHeader("Cookie", "ASP.NET_SessionId=" + sessionid);
    xmlhttp.send(null); 
} 

function GetXmlHttpObject(handler) { 
    var objXmlHttp = null;    //Holds the local xmlHTTP object instance 

    //Depending on the browser, try to create the xmlHttp object 
    if (is_ie){ 
        //The object to create depends on version of IE 
        //If it isn't ie5, then default to the Msxml2.XMLHTTP object 
        var strObjName = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; 
            
        //Attempt to create the object 
        try{ 
            objXmlHttp = new ActiveXObject(strObjName); 
            objXmlHttp.onreadystatechange = handler; 
        } 
        catch(e){ 
        //Object creation errored 
            alert('IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
            return; 
        } 
    } 
    else if (is_opera){ 
        //Opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.'); 
        return; 
    } 
    else{ 
        // Mozilla | Netscape | Safari 
        objXmlHttp = new XMLHttpRequest(); 
        objXmlHttp.onload = handler; 
        objXmlHttp.onerror = handler; 
    } 
        
    //Return the instantiated object 
    return objXmlHttp; 
} 

function UseValue(strVal){ 
    document.frmStuff.txtName.value = strVal; 
}

function activateNotes() {
	var qs = new QS(document.location.search);
	qs.replaceValue("notesActive","true");
	document.location = qs.getQueryString();
	return true;
}

function inActivateNotes() {
	var qs = new QS(document.location.search);
	qs.replaceValue("notesActive","false");
	document.location = qs.getQueryString();
	return true;
}

function getElementsByClass(searchClass,node,tag) { 
        var classElements = new Array(); 
        if ( node == null ) 
                node = document; 
        if ( tag == null ) 
                tag = '*'; 
        var els = node.getElementsByTagName(tag); 
        var elsLen = els.length; 
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); 
        for (i = 0, j = 0; i < elsLen; i++) { 
                if ( pattern.test(els[i].className) ) { 
                        classElements[j] = els[i]; 
                        j++; 
                } 
        } 
        return classElements; 
}

// Support for collapsing and expanding FAST navigator menus in Navigator.tree.aspx
function NavShowMore() {
    var more = document.getElementById("nav_show_more");
    more.style.display = "none";
    more.style.visibility = "hidden";

    var li = document.getElementsByName("nav_hidden");
    var len = li.length;
    for(var i = 0; i != len; ++i) {
        li[i].style.display = "";
        li[i].style.visibility = "visible";
    }

    var less = document.getElementById("nav_show_less");
    less.style.display = "";
    less.style.visibility = "visible";
}
function NavShowLess() {
    var less = document.getElementById("nav_show_less");
    less.style.display = "none";
    less.style.visibility = "hidden";

    var li = document.getElementsByName("nav_hidden");
    var len = li.length;
    for(var i = 0; i != len; ++i) {
        li[i].style.display = "none";
        li[i].style.visibility = "hidden";
    }

    var more = document.getElementById("nav_show_more");
    more.style.display = "";
    more.style.visibility = "visible";
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	var host = document.domain.substring(document.domain.indexOf(".")+1);
	document.cookie = name+"="+value+expires+"; path=/; domain=" + host;
}

function readCookie(name) {
    var host = document.domain.substring(document.domain.indexOf(".")+1);
    document.domain = host;
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteEditorDocument(confirmText) {
    if (confirm(confirmText)) {
        if ((""+document.location).indexOf("&deldoc=true") != -1) {
            window.location = document.location; // Flag already set
        } else {
            window.location = document.location + "&deldoc=true"; // Set flag
        }
    }
}
/*****************************************************************************
* createInternalLinkNodes()                                                  *
* The function is used for adding an extra empty <a> tag with i+id in front  *
* of all other empty <a> tags                                                *
* Since Firefox javascript engine updates the links  array at each iteration *
* (making it one bigger, in the middle every time we add an element), we     *
* first find the id's, and then add in another loop.                         *
*****************************************************************************/
function createInternalLinkNodes()
{
  var links = document.getElementsByTagName('a');
  var IDs = new Array();
  
  for(var i=0;i<links.length;i++)
  {
    var linkid = links[i].getAttribute('id');
    //IFSYS-2860: href are not empty after having notes permanently shown.
    //if(isNullOrEmpty(links[i].getAttribute('href')) && !isNullOrEmpty(linkid))
    //IFSYS-2855: Added check to exclude any anchor tags with href="#".
    if(!isNullOrEmpty(linkid) && (links[i].getAttribute('href') == null || links[i].getAttribute('href').substr(0,29) == 'javascript:openWindowFreesize'))
    {
        IDs[IDs.length] = linkid;
    }
  }
  
  for(var i=0;i<IDs.length;i++)
  {
    var thisid = IDs[i];
    //temporary fix, while schultz makes this javascript obsolete by placing the link nodes in html prerendering
    if (thisid.substr(0,1) != 'i' && document.getElementById('i' + thisid) == null){
      var oldlink = document.getElementById(IDs[i]);
      var newlink = document.createElement('a');
      newlink.id = 'i' + IDs[i];
        
      oldlink.parentNode.insertBefore(newlink, oldlink);
    }
  }
}

function isNullOrEmpty(obj)
{
    return ( obj==null || (''+obj).length==0 )
}

/*****************************************************************************
Method for scrolling messages
*****************************************************************************/
var speed=200;
var startPosition=0;
var scrollingRegion = 110;
    
function mainTextScroller(sourceid, targetid) 
{
    var mainMessage = document.getElementById(sourceid).value;
    var tempLoc=(scrollingRegion*3/mainMessage.length)+1;
    if (tempLoc<1) {tempLoc=1}
    var counter;
    for(counter=0;counter<=tempLoc;counter++)
        mainMessage+=mainMessage;
    document.getElementById(targetid).value = mainMessage.substring(startPosition,startPosition+scrollingRegion);
    startPosition++;
    if(startPosition>scrollingRegion) startPosition=0;
    setTimeout('mainTextScroller("' + sourceid + '","' + targetid + '")',speed); 
}

/*****************************************************************************
functions used for Navigation.Shortcut
*****************************************************************************/
var docUrl = "/ShowDoc.aspx";
var ajaxUrl = "/layouts/ShortCutSearch.aspx";

function findNextSibling(divObj){
	var sibling = divObj.nextSibling;
	while (sibling.nodeType !=1){
		sibling = sibling.nextSibling;
	}
	return sibling;
}

function firstSibling(node){
  var tempObj=node.parentNode.firstChild;
  while(tempObj.nodeType!=1 && tempObj.nextSibling!=null){
    tempObj=tempObj.nextSibling;
  }
  return (tempObj.nodeType==1)?tempObj:false;
}

function changeStyle(divObj,className){
	var sibling = findNextSibling(divObj);
	if (sibling.style.display == 'none'){
		divObj.className = className;
	}
	if (divObj.childNodes.length == 4){
		if (divObj.childNodes[3].style.display == 'none'){
			divObj.childNodes[3].style.display = 'block';
		} else if (sibling.style.display == 'none'){
			divObj.childNodes[3].style.display = 'none';
		} 
	} else if (divObj.childNodes.length == 9){
		if (divObj.childNodes[7].style.display == 'none'){
			divObj.childNodes[7].style.display = 'block';
		} else if (sibling.style.display == 'none'){
			divObj.childNodes[7].style.display = 'none';
		} 
	}
}

//This function is called with only 1 argument from Navigation.Shortcut, but 2 arguments from newsletter
function toggleShow(divObj, className, parentObj){
	var base;
	if(parentObj != null){
	    base = parentObj;
	} else {
	    base = divObj;
	}
	var sibling = findNextSibling(base);
	if (sibling.style.display == 'none'){
	    base.className = className + '_active';
		sibling.style.display = 'inline';
	} else {
	    base.className = className + '_mouseover';
		sibling.style.display = 'none';
	}
}

function openDoc(docId){
	var newwindow = window.open(docUrl+'?docid='+docId,'doc');
	if (window.focus) {newwindow.focus()}
	return false;
}

function SearchFQL(divObj, qstring, className){
    var shortcutsearchurl = ajaxUrl+qstring;
    var objXmlHttp = GetXmlHttpObject(function(){loadAjax(objXmlHttp, divObj, className);});
    xmlHttp_Get(objXmlHttp, shortcutsearchurl);
}

function loadAjax(objXmlHttp, divObj, className){
    if (objXmlHttp.readyState == 4 && objXmlHttp.status == 200)
    {
        divObj.nextSibling.innerHTML = '';
        divObj.nextSibling.innerHTML = objXmlHttp.responseText;
        divObj.onclick = function(){toggleShow(this, className);};
        toggleShow(divObj, className);
    }
}


/*****************************************************************************
functions used for Newsletter.Profile
*****************************************************************************/
var newsletteraction = "/layouts/NewsletterAction.aspx";
var createnewsletterprofile = "/layouts/CreateNewsletterProfile.aspx";

function newsselection(checkbox, profileguid, taxonomy, sitecoreitempath, product, title, isproducttaxonomy){
    var qstring = "?profileguid=" + profileguid + "&sitecoreitempath=" + sitecoreitempath + "&product=" + product + "&title=" + title;
    if(isproducttaxonomy){
        qstring += "&isproducttaxonomy=true";
    }
    if(checkbox.checked){
        qstring += "&tilmeld=" + taxonomy;
        if(!isproducttaxonomy){
            changeChildren(checkbox);
        }
        updateTilmeldtButton(checkbox);
    }
    else{
        qstring += "&frameld=" + taxonomy;
        if(!isproducttaxonomy){
            changeChildren(checkbox);
        }
        updateTilmeldtButton(checkbox);
    }

    var objXmlHttp = GetXmlHttpObject(function(){doNothing(objXmlHttp);});
    xmlHttp_Get(objXmlHttp, newsletteraction + qstring);
}

function changeChildren(checkbox)
{
    var cbs = findNextSibling(checkbox.parentNode.parentNode).getElementsByTagName('input');
    for(cb=0; cb<cbs.length; cb++){
        if(cbs[cb].type=='checkbox'){                
            cbs[cb].disabled = checkbox.checked;
            cbs[cb].checked = checkbox.checked;
        }
    }
}

function updateTilmeldtButton(checkbox)
{
    var l1checkbox = getLevelOneCB(checkbox);
    var tilmeldtDiv = firstSibling(l1checkbox.parentNode);
    
    if(checkbox.checked)
    {
        tilmeldtDiv.className = 'signedup';
    }
    else
    {
        if(!l1checkbox.checked)
        {
            var found = false;
            cbs = findNextSibling(l1checkbox.parentNode.parentNode.parentNode).getElementsByTagName('input');
            for(cb=0; cb<cbs.length; cb++){
                if(cbs[cb].type=='checkbox' && cbs[cb].checked){                
                    found = true;
                    break;
                }
            }
            if(!found){
                tilmeldtDiv.className = '';            
            }
        }
    }
}

function getLevelOneCB(checkbox)
{
    var index = checkbox.id.indexOf('-');
    if(index != -1){
        return document.getElementById(checkbox.id.substring(0, index));
    } else {
        return checkbox;
    }
}

function alertError(objXmlHttp){
    if (objXmlHttp.readyState == 4 && objXmlHttp.status == 200)
    {
        if(objXmlHttp.responseText != ''){
            alert(objXmlHttp.responseText);
        }
    }
}

function doNothing(objXmlHttp){
}

function createuser(){
    var email = document.getElementById('newsletteremail').value;
    var email2 = document.getElementById('newsletteremail2').value;
    
    var errorDiv = document.getElementById('newsletteremailerror');
    var signupDiv = document.getElementById('newsletteremailsignup'); 
    var signupCompleteDiv = document.getElementById('newsletteremailsignupcomplete');

    if(email.length > 0 && email == email2){  //add email validity check
        var curpage;
        if (location.href.indexOf('?') != -1){
            curpage = location.href.substring(0, location.href.indexOf('?'));
        }else{
            curpage = location.href;
        }
        var qstring = "?email=" + email + "&currentpage=" + curpage;
        
        var objXmlHttp = GetXmlHttpObject(function(){alertError(objXmlHttp);});
        xmlHttp_Get(objXmlHttp, createnewsletterprofile + qstring);
        errorDiv.style.display = 'none';
        signupDiv.style.display = 'none';
        signupCompleteDiv.style.display = 'block';
    }
    else{
        errorDiv.style.display = 'block';
        signupDiv.style.display = 'block';
        signupCompleteDiv.style.display = 'none';
    }
}

/* Tip a friend */
function tipAFriendGoToPage()
{
    var execute = true;
    var toAddress = document.getElementById('tipEmailReceiver').value;
    var fromAddress = document.getElementById('tipEmailSender').value;
    var comment = encodeURIComponent(document.getElementById('tipComment').value);
    var err_reciever = document.getElementById('tipErrEmailReceiver');
	var err_sender = document.getElementById('tipErrEmailSender');
	err_reciever.style.display = 'none';
    err_sender.style.display = 'none';
    
    //Error handling
    if(toAddress == '' || !checkEmail(toAddress)){
	    execute = false;
	    err_reciever.style.display = 'block';
	}
	if(fromAddress == '' || !checkEmail(fromAddress)){
	    execute = false;
	    err_sender.style.display = 'block';
	}
	
	if (execute){
	location.href = location.protocol + '//' + 
                    location.hostname + 
                    '/ShowDocTip.aspx' +
                    location.search + 
                    '&to=' + toAddress + 
                    '&from=' + fromAddress + 
                    '&comment=' + comment + 
                    '&link=' + encodeURIComponent(location.href);
    }else{
        return false;
    }
}

function tipAFriendShow(divid){
    var winHeight = document.documentElement.scrollHeight+'px';
	var pageHeight = document.documentElement.clientHeight+'px';
	if (winHeight > pageHeight){
		pageHeight = winHeight;
	}
	var pageWidth = document.body.scrollWidth+'px';
	var grayElement = document.getElementById('Grayout');
	grayElement.style.height = pageHeight;
	grayElement.style.width = pageWidth;
	grayElement.style.display = 'inline';
	document.getElementById('TipFriendContainer').style.display = 'inline';
	document.getElementById(divid).style.display = 'block';
}

function tipAFriendHide(divid){
	document.getElementById(divid).style.display = 'none';
	document.getElementById('Grayout').style.display = 'none';
}

window.onresize = function(event) {
	winWidth = document.body.scrollWidth;
	pageWidth = document.getElementById('layout').scrollWidth;
	if (winWidth > pageWidth){
		pageWidth = winWidth;
	}
	document.getElementById('Grayout').style.width = pageWidth+'px';
	var winHeight = document.documentElement.scrollHeight;
	var pageHeight = document.documentElement.clientHeight;
	if (winHeight > pageHeight){
		pageHeight = winHeight;
	}
	document.getElementById('Grayout').style.height = pageHeight+"px"; }


function checkEmail(email){
	var str = email;
	var filter = /^[^\s@]+@[^\s@]+\.[a-z]{2,6}$/i;

	// Check e-mail validity - return true or false
	if(filter.test(str)){
		return true;
	}else{
		return false;
	}
}

/* wide table fix */
function printTable(tableid, tabletitle){
	var menudiv = document.getElementById('menudiv_'+tableid);
	menudiv.style.display = 'none';
	var content = document.getElementById('container_'+tableid).innerHTML;
	var pwin = window.open('','print_content','width=100,height=100');
	pwin.document.open();
	pwin.document.write('<html><head><title>'+tabletitle+'</title></head><body onload="window.print()">'+content+'</body></html>');
	pwin.document.close();
	menudiv.style.display = 'block';
	setTimeout(function(){pwin.close();},1000);
}

function toggleLargeTable(tableid){
	var thistable = document.getElementById('table_'+tableid);
	var containerdiv = document.getElementById('container_'+tableid);
	var linkanchor = document.getElementById('link_'+tableid);
	if (containerdiv.style.overflow == 'hidden'){
		thistable.style.position = "absolute";
		containerdiv.style.overflow = 'visible';
		containerdiv.style.height = (thistable.offsetHeight+15)+"px";
		containerdiv.style.border = 'none';
		linkanchor.innerHTML = 'Skjul tabellen';
	} else {
		containerdiv.style.height = "300px";
		containerdiv.style.position = "absolute";
		containerdiv.style.position = "relative";
		containerdiv.style.overflow = 'hidden';
		containerdiv.style.borderRight = '1px dotted gray';
		containerdiv.style.borderBottom = '1px dotted gray';
		linkanchor.innerHTML = 'Vis hele tabellen';
	}
}

function tablecontainer(tableid, tabletitle){
	var thistable = document.getElementById('table_'+tableid);
	var containerdiv = document.getElementById('container_'+tableid);
	if (thistable.offsetWidth > 535){
		containerdiv.style.overflow = 'hidden';
		containerdiv.style.width = '515px';
		containerdiv.style.height = '300px';
		containerdiv.style.borderRight = '1px dotted gray';
		containerdiv.style.borderBottom = '1px dotted gray';
		thistable.style.backgroundColor = '#FFFFFF';
		containerdiv.style.padding = '5px';
		var newdiv = document.createElement('div');
		newdiv.id = 'menudiv_'+tableid;
		newdiv.innerHTML = '<a href="javascript:void(0);" id="link_'+tableid+'" onfocus="this.blur();" onclick="toggleLargeTable(\''+tableid+'\');">Vis hele tabellen</a> | '+
			'<a href="javascript:void(0);" onfocus="this.blur();" onclick="printTable(\''+tableid+'\', \''+tabletitle+'\');">Print hele tabellen</a>';
		containerdiv.parentNode.insertBefore(newdiv, containerdiv);
	}
}

function firstChildTable(div){
    if (div.hasChildNodes()){
        var children = div.childNodes;
        for (j = 0; j < children.length; j++){
            var child = children[j];
            if (child.nodeName == 'TABLE'){
                return child;
            }            
        }
    }
    
    return null;
}

function hidehportlet(){
    var tags = document.getElementById('fullviewHtmlContent').getElementsByTagName('*');
    for(var i=0; i<tags.length; i++)
    {
        if (tags[i].className == 'hportlet')
        {
            tags[i].style.display = 'none';
            break;
        }
    }
}