﻿/* begin tangora tilføjelser januar 2008 */


/* ----------------------- makeNewsletterLinks takes all links on page 35 and makes them to window.open's  ---------------------- */

function newsLetterLink(){
	//alert ('hi');
	//alert(this.href);
	window.open(this.href,'newsletter','width=400, height=550, scrollbars=yes, menubar=no, status=no, directories=yes, location=no,toolbars=no');
	return false;
}

function makeNewsletterLinks(){
	var anchors = document.getElementById('indhold').getElementsByTagName('a');
	//alert (anchors.length);
	for (i=0; i<anchors.length; i++){
		anchors[i].onclick = newsLetterLink;
	}
}



/* ----------- checkVisitCookie (with setCookie & getCookie)  opens a window if it doesn't exist (first time visiter to site), and then writes a cookie that says that the user has opened the window before ----------- */


function setCookie(paramCookieName,paramCookieValue,paramExpiredays){
	var expiredate=new Date();
	expiredate.setDate(expiredate.getDate()+paramExpiredays);
	document.cookie=paramCookieName+ "=" +escape(paramCookieValue)+((paramExpiredays==null) ? "" : ";expires="+expiredate.toGMTString());
}

function getCookie(paramCookieName){
if (document.cookie.length>0){
  cookieStart=document.cookie.indexOf(paramCookieName + "=");
  if (cookieStart!=-1){ 
    cookieStart=cookieStart + paramCookieName.length+1; 
    cookieEnd=document.cookie.indexOf(";",cookieStart);
    if (cookieEnd==-1) cookieEnd=document.cookie.length;
    return unescape(document.cookie.substring(cookieStart,cookieEnd));
    } 
  }
return "";
}

function checkVisitCookie(url){
	visitCookie=getCookie('visitCookie');
	if(visitCookie!=null && visitCookie!=""){
		//do nothing
	} else {
		window.open(url,'subscribe','height=400,width=375');
		setCookie('visitCookie','1',365);
	}
}


/* ----------- checkCheck makes a pair of checkboxes work like a radio button - one must be filled out ----------- */

function checkCheckInit(){

/*Tangora.Events.AddHandler(document.getElementById('idcheckbox1'), 'onclick', checkCheck);Tangora.Events.AddHandler(document.getElementById('idcheckbox2'), 'onclick', checkCheck);*/
	var sendKnap = document.getElementById('sendKnap');
	sendKnap.oldClick = sendKnap.onclick;
	sendKnap.onclick = checkCheck;
}

function checkCheck(){
	var checkBox1 = document.forms.rediger39.getshtml;
	var checkBox2 = document.forms.rediger39.getstext;
	if ((checkBox1.checked == false)&&(checkBox2.checked == false)){
		alert ('Venligst vælg enten html eller text format');
	} else {
		this.oldClick();
	}
	
}


/* ----------- openSeasme, loadMe and resizeMe below handle blow up images ----------- */

function loadMe(){ //loads image in popup window
	var imgIDquery = location.search;
	var imgIDArray = imgIDquery.split('=');
	var imgIDresult = imgIDArray[1];
	document.write('<img id="largeImage" src="/media/'+imgIDresult+'" alt="" />');
}


function resizeMe(){ //resizes window and image

		//sets image properties
		var theImage = document.getElementById('largeImage');
		var theImageHeight = theImage.height;
		var theImageWidth = theImage.width;
		var theImageRatio =  theImageWidth / theImageHeight;
		
		//gets screen properties
		var screenWidth = screen.width;
		var screenCenter = screen.width / 2;
		var screenHeight = screen.height;
		
		//resizes window and moves to center
		var centerAdjusted = 0;
		if (theImageHeight < screenHeight){
			window.resizeTo(theImageWidth,theImageHeight);
			centerAdjusted = (screenCenter - (theImageWidth / 2));
		} else {
			window.resizeTo((screenHeight*theImageRatio),screenHeight);
			centerAdjusted = (screenCenter - ((screenHeight*theImageRatio) / 2));
		}
		window.moveTo(centerAdjusted,0);
		
		//gets height and width of inner space of window, crossbrowser
		var theInnerWidth = 0, theInnerHeight = 0, theInnerHalfWidth = 0;
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			theInnerWidth = window.innerWidth;
			theInnerHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			theInnerWidth = document.documentElement.clientWidth;
			theInnerHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			theInnerWidth = document.body.clientWidth;
			theInnerHeight = document.body.clientHeight;
		}
		//half the width of the inner window
		theInnerHalfWidth = (theInnerWidth)/2;
		
		//resizes image
		if (Tangora.Browser.IE){
			theImage.style.msInterpolationMode='bicubic';
			theImage.width = theInnerWidth;
			theImage.height = theInnerHeight;
		} else { //not ie
			theImage.width = theInnerWidth;
			theImage.height = theInnerHeight;
			var theSource = 'media/' + theImage.src.substring(theImage.src.lastIndexOf('/'),theImage.src.length);
			theImage.src = "/img.aspx?path="+theSource+"&action=6&6param1="+theImage.width+"&6param2="+theImage.height;
			
		}
		
}


/* end tangora tilføjelser januar 2008 */





 function MovePagingElements(prevContId, nextContId, counterContId, pageId)
{
	this.PreviousContainer = null;
	this.NextContainer = null;
	this.CounterContainer = null;

	this.PreviousButton = null;
	this.NextButton = null;
	this.CounterText = null;

	this.Init = function()
	{
		mpe.PreviousContainer = document.getElementById(prevContId);
		mpe.NextContainer = document.getElementById(nextContId);
		mpe.CounterContainer = document.getElementById(counterContId);
		
		mpe.LoadElements();

		mpe.MoveElements();
	}

	this.LoadElements = function()
	{
		var counterText = document.getElementById("counterText" + pageId);
		var btnPrev = document.getElementById("pagingPrev" + pageId);
		var btnNext = document.getElementById("pagingNext" + pageId);

		if(btnPrev)
		{
			this.PreviousButton = btnPrev;
		}
		else
		{
			//var img = document.createElement("img");
			//img.id = "pagingPrev" + pageId;
			//img.src = "/media/forrige.gif";
			//img.alt = "";
			//this.PreviousButton = img;
		}

		if(btnNext)
		{
			this.NextButton = btnNext;
		}
		else
		{
			//var img = document.createElement("img");
			//img.id = "pagingNext" + pageId;
			//img.src = "/media/naeste.gif";
			//img.alt = "";
			//this.NextButton = img;
		}

		if(counterText)
		{
			this.CounterText = counterText;
		}
		else
		{
			var ct = document.createElement("span");
			ct.id = "counterText" + pageId;
			ct.innerHTML = "1/1";
			this.CounterText = ct;	
		}
	}

	this.MoveElements = function()
	{
		if(this.PreviousContainer && this.PreviousButton) this.PreviousContainer.appendChild(this.PreviousButton);
		if(this.NextContainer && this.NextButton) this.NextContainer.appendChild(this.NextButton);
		if(this.CounterContainer && this.CounterText) this.CounterContainer.appendChild(this.CounterText);
	}
}

function AlterDetailLinks()
{
	this.Links = new Array();
	
	this.Init = function()
	{
		adl.GetLinks();
		adl.AttachClickHandler();
	}

	this.GetLinks = function()
	{
		var divs = Tangora.DOM.GetCollectionByClassName("maincell","div","big")

		for(var i = 0; i < divs.length; i++)
		{
			var link = divs[i].getElementsByTagName("a")[0];

			if(link)
			{
				this.Links.push(link);
			}
		}
	}

	this.ClickHandler = function()
	{
		var w = window.open(this.href,"Detaljer","width=550,height=507,left=0,top=0");
		return false;
	}

	this.AttachClickHandler = function()
	{
		for(var i = 0; i < this.Links.length; i++)
		{
			this.Links[i].onclick = this.ClickHandler;
		}
	}
}

function ImageArchive()
{
	this.MainImage = null;
	this.Thumbnails = new Array();

	this.Init = function()
	{
		ia.MainImage = Tangora.DOM.GetFirstCollectionMember(document.getElementById("main"),"img");
		if(ia.MainImage.className.indexOf("imgborder") > -1) ia.MainImage.largeImgBorder = "1";
		ia.LoadThumbnails();
		ia.AttachClickHandlers();
	}

	this.LoadThumbnails = function()
	{
		var imgs = Tangora.DOM.GetCollection(document.getElementById("thumbnails"),"img");

		for(var i = 0; i < imgs.length; i++)
		{
			imgs[i].className += " thumbnail";
			this.Thumbnails.push(imgs[i]);
		}
	}

	this.ThumbClickHandler = function()
	{
		ia.MainImage.className = (this.className.indexOf("largeimgborder") > -1) ? "imgborder" : "";
		//this.className = (ia.MainImage.className.indexOf("imgborder") > -1) ? "imgborder" : "";

		var regexp = new RegExp(/\?path=(.+?)&/);
		var thumb = this.src.toString();
		var main = ia.MainImage.src.toString();

		var tlib = this.largeImgBorder;
		var mlib = ia.MainImage.largeImgBorder;
		
		//this.largeImgBorder = mlib;
		//ia.MainImage.largeImgBorder = tlib;

		if(!Tangora.Browser.IE || Tangora.Browser.IE && Tangora.Browser.Version.indexOf("7") == -1)
		{
			thumb = regexp.exec(thumb)[1];
			main = main.substring(main.lastIndexOf("/")+1,main.length);
			main = "/img.aspx?path=media/thumbs/" + main + "&action=6&6param2=50";
		}

		//this.src = main;
		ia.MainImage.src = thumb;

		//if(ia.MainImage.largeImgBorder == "1") ia.MainImage.className = "imgborder";
		//if(this.largeImgBorder == "1") ia.MainImage.className = "imgborder";

		return false;
	}

	this.MainClickHandler = function()
	{
		var source = this.src;

		if(source.indexOf("/img.aspx") > -1)
		{
			var reg = new RegExp(/\?path=(.+?)&/);
			source = reg.exec(source)[1];
		}
		
		source = source.substring(source.lastIndexOf("/")+1,source.length);

		var w = window.open("/page119.aspx?imgid=" + source,"largeimage","width=" + screen.width + ",height=" + screen.height + ",toolbars=no,resizeable=no");

		return false;
	}

	this.AttachClickHandlers = function()
	{
		this.MainImage.onclick = this.MainClickHandler;

		for(var i = 0; i < this.Thumbnails.length; i++)
		{
			this.Thumbnails[i].onclick = this.ThumbClickHandler;
		}
	}
}

 fixObjects=true;

function ShowPicture(strID, strFilename, strHeight, strAlt, strClass, largeImgBorder, orgWidth, orgHeight)
{
	
	var wi = 0;

	if(typeof(orgWidth) != "undefined" && typeof(orgHeight) != "undefined")
	{
		var ratio = orgHeight / strHeight;
		wi = Math.round(orgWidth / ratio,0);
	}

	var img = document.createElement("img");

	document.write("<span id='imgwrapper_" + strID + "' style='min-height: 1%;'></span>");
	document.getElementById("imgwrapper_" + strID).appendChild(img);

	img.id = strID;
	img.alt = (strAlt != "") ? strAlt : strFilename;
	img.className = "listimage";
	img.className += (strClass != "") ? " " + strClass : "";
	if(largeImgBorder) img.largeImgBorder = "1";

	img.style.height = strHeight + "px";
	img.height = strHeight;
	if(wi > 0)  img.style.width = wi + "px";
	
	if(Tangora.Browser.IE && Tangora.Browser.Version.indexOf("7") > -1)
	{	
		img.style.msInterpolationMode = "bicubic";
		img.src = "/media/" + strFilename;
	}
	else
	{
		img.src = "/img.aspx?path=media/" + strFilename + "&action=6&6param2=" + strHeight;
	}
}