﻿function toggle_visibility(id) {
var e = document.getElementById(id);
	if(e.style.display == 'block'){
		e.style.display = 'none';
	} else {
		e.style.display = 'block';
	}
}


function show(id) {
	if(document.getElementById){
		document.getElementById("map"+id).style.visibility = "visible";
	}else{
		if (ns4) document.layers["map"+id].visibility = "show"
		else document.all["map"+id].style.visibility = "visible"
	}
}
function hide(pos,maxpos) {
	var d;
	for (var i = 1; i <= maxpos; i++) {
		//alert(""+i+"-"+pos);
		if(document.getElementById){
			d = document.getElementById("map"+i);
			if(d) {
				d.style.visibility = "hidden";
			}
		}else{
			if (ns4) document.layers["map"+i].visibility = "hide"
			else document.all["map"+i].style.visibility = "hidden"
		}
	}
}

// toggle the stylesheets
function toggleFontsize() {
	var curr = getActiveStyleSheet();
	if (curr==null || curr=="default") 
		setActiveStyleSheet("text-plus");
	else
		setActiveStyleSheet("default");
}


// **** http://alistapart.com/stories/alternate/
function setActiveStyleSheet(title) {
	var title = title;
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
		if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	// alert(title);
}


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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 expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
// Clear form
// this function checks all elements within a container,
// and sets its height according to the bottommost positioned element.
function clearAbsolute(id) {
	d = document.getElementById(id);
	
	if (!d) return;
	var elms = (d.All) ? d.All : d.getElementsByTagName('*');
	//var tallest; //if we need to catch the tallest element
	var maxHeight = 0;
	for (var i = 1; i < elms.length; i++) {	
		var elm = elms[i];
		if ((elm.offsetTop + elm.offsetHeight) > maxHeight) {
			maxHeight = elm.offsetTop + elm.offsetHeight;
			//tallest = elm; //if we need to catch the tallest element
		}
	}
        
	d.style.height = (maxHeight + 40) + 'px'; //(d.offsetHeight +100)+"px";
}

// tip
function tip(gid){
	tipwin = window.open('/Home/TipVen/TipVen.aspx?gid=' + gid,'toptip','width=620,height=450,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes');
        tipwin.focus();
}
// validate
function validateComment(form) {
    
	var fieldNames  = new Array();
	fieldNames.push(new Array('name','Husk at udfylde Navn'));	
	fieldNames.push(new Array('message','Husk at udfylde Kommentar'));
	fieldNames.push(new Array('email','Husk at udfylde Email'));
	
	var errorMessage = '';
    for (var i = 0; i<fieldNames.length; i++) {
	    if(form.elements[fieldNames[i][0]].value=='')
		{
		  errorMessage += fieldNames[i][1] + '\r\n';
		}
    }
	if(errorMessage!='')
	{
	  alert(errorMessage);
	  return false;
	}
    return true;	
}

// search
function Search(inputfieldname,site)
{
   var Path;
   if(site=='en') {
      Path = '/English/Searchresults.aspx?q=';
   } else if(site == 'mp') { 
      Path = '/Soeg.aspx?q=';
   } else if(site == 'medlemsnet') {
	  Path = '/Soeg.aspx?q='
   } else {
      Path = '/Soeg/Soegeresultatsiden.aspx?q=';
   }
   if(site=='medlemsnet') {
	   var inp;
	   if(document.search[inputfieldname]) {
			inp = document.search[inputfieldname];
	   } else {
			inp = document.mainform[inputfieldname];
	   }
	   location.href= Path + encodeURIComponent(inp.value) + "&group=scSection";
   } else {
		location.href= Path + encodeURIComponent(document.mainform[inputfieldname].value) + "&group=scSection";
   }
   return false;
}

function redirectForm(path,fieldName) 
{
       var field = document.forms[0][fieldName];
       
	   var getData ="";
	   if(field)
	   {
	      switch(field.type)
		  {
		    case "text" : getData = field.value;
		    break;
			case  "select-one" : getData = field[field.selectedIndex].value;
			break;
			default : getData="unknown type";
		  }
	   }
       location.href =path +"?" + fieldName + "=" + encodeURI(getData);
       return false;
}

/* used to set fields from session in bogbutik */
function setField(field,value) {
	for(var i=0;i < document.mainform.elements.length;i++) {
		el = document.mainform.elements[i];
		if(el.name.substring(el.name.length - field.length) == field) {
			el.value = value;
			return;
		}
	}
	alert("Not found!");
}

/*
A fix for flickering CSS bg images on links in IE6. More info: mister-pixel.com
there is also an IIS fix available: www.aspnetresources.com/blog/cache_control_extensions.aspx
*/
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/* Used to show/hide a DIV tag with a specific ID. Used by Medlemsnet. */
function ReverseContentDisplay(id)
{
	if(id.length < 1) { return; }
	if(document.getElementById(id).style.display == "none") 
	{ 
	    document.getElementById(id).style.display = "block";
    }
	else
	{ 
	    document.getElementById(id).style.display = "none";
	}
}

