// utility function to retrieve an expiration date in proper
// format; pass three integer parameters for the number of days, hours,
// and minutes from now you want the cookie to expire (or negative
// values for a past date); all three parameters are required,
// so use zeros where appropriate
function getExpDate(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && 
        typeof hours == "number") {
        expDate.setDate(expDate.getDate( ) + parseInt(days));
        expDate.setHours(expDate.getHours( ) + parseInt(hours));
        expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
        return expDate.toGMTString( );
    }
}
   
// utility function called by getCookie( )
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}
   
// primary function to retrieve cookie by name
function getCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) {
            return getCookieVal(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
    }
    return "";
}
   
// store cookie value with optional details as needed
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
   
// remove the cookie by setting ancient expiration date
function deleteCookie(name,path,domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

// enable/disable  style sheet per cookie setting
function setSizeStyle() {
    if (document.getElementById) {
        var styleCookie = getCookie("fontSize");
        var styleIDs = ["largeStyle"];
        for (var i = 0; i < styleIDs.length; i++) {
            if (styleCookie == styleIDs[i]) {
                document.getElementById(styleIDs[i]).disabled = false;            
            } else {
                document.getElementById(styleIDs[i]).disabled = true;    
            }
        }
    }
}

   
// invoked by clicking on sizer icons
function changeSizeStyle(styleID) {
    setCookie("fontSize", styleID, getExpDate(180, 0, 0));
    setSizeStyle( );
}

function filterGalleries(df1,df2){
	var defaultFilter1Value = df1;
	var defaultFilter2Value = df2;
	
	var filter1 = "";
	if (document.getElementById("galleryfilter1menu")) {
		filter1 =	document.getElementById("galleryfilter1menu").innerHTML;
			if(filter1==defaultFilter1Value) {
				filter1="";
			}
	}
	
	var filter2 = "";
	if (document.getElementById("galleryfilter2menu")) {
		filter2 =	document.getElementById("galleryfilter2menu").innerHTML;
			if(filter2==defaultFilter2Value) {
			filter2="";
		}
	}
		
	var strUrl = '';
	var strParam1 = '?f1=' + encodeURIComponent(filter1);
	var strParam2 = '&f2=' + encodeURIComponent(filter2);
	
	document.location = strUrl + strParam1 + strParam2;
	
}

function doSearch(resultpage){
	var strUrl = resultpage;
	var strParam = '?search=' + encodeURIComponent(document.getElementById("search_phrase").value);
	document.location = strUrl + strParam;
}

function doSearchOther(resultpage)
{
	var chkBox = document.getElementById("english").checked;
	var strUrl = resultpage;
	if (chkBox == true)
	{
		var strParam = '?search=' + encodeURIComponent(document.getElementById("searchphrase").value) + '&foreign=1';
	}
	else
	{
		var strParam = '?search=' + encodeURIComponent(document.getElementById("searchphrase").value);
	}
	document.location = strUrl + strParam;
	
}

function doSimpleSearchByLanguage(resultpage, language)
{
	var strUrl = resultpage;
	var strParam = '?search=' + encodeURIComponent(document.getElementById("search_phrase").value);
	
	var langDK = "(language contains (da))";
	var langEN = "(language contains (en))";
	
	var langSelection = ' and ';
					
	if (language == "da")
		langSelection = langSelection + langDK;
	else if (language == "en")
		langSelection = langSelection + langEN;
	else 
		langSelection = langSelection + langDK;
				
	strParam = strParam + langSelection;
	
	document.location = strUrl + strParam + "&cleanSearchPhrase=" + encodeURIComponent(document.getElementById("search_phrase").value);
}

function doSearchByLanguage(resultpage, language)
{
	var cleanSearchPhrase = document.getElementById("searchphrase").value;	
	var strUrl = resultpage;
	
	var langDK = "(language contains (da))";
	var langEN = "(language contains (en))";
	
	var langSelection = ' and ';
	
	var strParam = '?search=' + encodeURIComponent(document.getElementById("searchphrase").value);           
				
	if (language == "da")
		langSelection = langSelection + langDK;
	else if (language == "en")
		langSelection = langSelection + langEN;
	else 
		langSelection = langSelection + langDK;
				
	strParam = strParam + langSelection + "&cleanSearchPhrase=" + encodeURIComponent(cleanSearchPhrase);
	
	document.location = strUrl + strParam;
}

function clickButtonViaEnter(btn, event){
	if (document.all){
		if (event.keyCode == 13){
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if (document.getElementById){
		if (event.which == 13){
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
	else if(document.layers){
		if(event.which == 13){
			event.returnValue=false;
			event.cancel = true;
			btn.click();
		}
	}
}
		
function openWindowFreesize(url,paramHeight,paramWidth){
	var properties = "directories=0,left=" + ((screen.width-paramWidth)/2) + ",top=" + ((screen.height-paramHeight)/2) + ",location=0,toolbar=0,scrollbars=yes,menubar=no,width="+paramWidth+",height="+paramHeight+",resizable=no";
    var virkPopupInternal = openPopup(url, "virkPopupInternal", properties);
    virkPopupInternal.focus();
}


/******************************************************************************
This function is used for launching the popup of extra article images
******************************************************************************/

// Set the horizontal and vertical position for the popup
PositionX = 50;
PositionY = 50;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 1024;
defaultHeight = 768;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4) {

	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	
	function popup(picture_url,imageTitle){
		var imageURL = fixScreenShotName(picture_url);
		if (isNN){imgWin=window.open('about:blank','',optNN);}
		if (isIE){imgWin=window.open('about:blank','',optIE);}
		with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(100,100);');
		writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		writeln('window.resizeTo(width,height);}');writeln('if (isNN){');
		writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="' + imageTitle + '";}');writeln('</sc'+'ript>');
		if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()" onclick="self.close()">');
		writeln('<img name="" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}

/******************************************************************************
This function is used for launching the popup of extra article images
******************************************************************************/
function fixScreenShotName(input) {
	var strResult = input.toString();
	var re = /\./;
	if (strResult.match(re)) {
		strResult = strResult.replace(/\./, ".");
	}
	return strResult;
}




/******************************************************************************
This function switch pictures on the frontpage
******************************************************************************/
function switchImage(number,src)
	{
	eval("document."+number+".src="+src+";");
	}
	
/******************************************************************************
This function is used for filtering in the news archieve
******************************************************************************/
function filterNewsArchieves(df1,df2,df3){
	var defaultFilter1Value = df1;
	var defaultFilter2Value = df2;
	var defaultFilter3Value = df3;
	
	var filter1 = "";
	if (document.getElementById("newsArchieveSubject")) {
		filter1 = document.getElementById("newsArchieveSubject").innerHTML;
			if(filter1==defaultFilter1Value) {
				filter1="";
			}
	}
	
	var filter2 = "";
	if (document.getElementById("newsArchieveYear")) {
		filter2 = document.getElementById("newsArchieveYear").innerHTML;
			/*if(filter2==defaultFilter2Value) {
			filter2="";
			}*/
	}
	
	var filter3 = "";
	if (document.getElementById("newsArchieveMonth")) {
		filter3 = document.getElementById("newsArchieveMonth").innerHTML;
			if(filter3==defaultFilter3Value) {
			filter3="";
		}
	}
		
	var strUrl = '';
	var strParam1 = '?fsubject=' + encodeURIComponent(filter1);
	var strParam2 = '&fyear=' + encodeURIComponent(filter2);
	var strParam3 = '&fmonth=' + encodeURIComponent(filter3);
	
	document.location = strUrl + strParam1 + strParam2 + strParam3;
	
}

/******************************************************************************
This function is used for finding performances 
******************************************************************************/
function findPerformances(resultpage){

	
	var strUrl = resultpage;
	var defaultQ1Value = document.getElementById("defaultKunstartValue").value;
	var defaultQ2Value = document.getElementById("defaultSceneValue").value;
	var defaultQ3Value = document.getElementById("defaultForestillingValue").value;
	
	var q1 = "";
	if (document.getElementById("DDKunstart")) {
		q1 = document.getElementById("DDKunstart").innerHTML;
			if(q1==defaultQ1Value) {
				q1="";
			}
	}
	
	var q2 = "";
	if (document.getElementById("DDScene")) {
		q2 = document.getElementById("DDScene").innerHTML;
			if(q2==defaultQ2Value) {
				q2="";
			}
	}
	
	var q3 = "";
	if (document.getElementById("DDForestilling")) {
		q3 = document.getElementById("DDForestilling").innerHTML;
			if(q3==defaultQ3Value) {
			q3="";
		}
	}
	
	var strParam1 = '?qkunstart=' + encodeURIComponent(q1);
	var strParam2 = '&qscene=' + encodeURIComponent(q2);
	var strParam3 = '&qforestilling=' + encodeURIComponent(q3);
	
	document.location = strUrl + strParam1 + strParam2 + strParam3;
}

/******************************************************************************
Auto redirect to other page
******************************************************************************/
function autoRedirect(page) {
    if (navigator.appName == "Microsoft Internet Explorer")
        document.write('');
	document.location.href = page;
}

/******************************************************************************
Auto redirect after a specified amount of milliseconds
******************************************************************************/

function delayedAutoRedirect(page, timeout)
{
    setTimeout("autoRedirect('" + page+ "');",timeout);
}

/******************************************************************************
Auto redirect after a specified amount of milliseconds
******************************************************************************/

function setCurrentCalendarMonth(monthInput)
{
	document.getElementById('currentSetMonthAsNumber').value = monthInput;
}


function setCurrentCalendarYear(yearInput)
{
	document.getElementById('currentSetYearAsNumber').value = yearInput;
}

/******************************************************************************
This function is used for filtering on the calendar page
******************************************************************************/
function filterCalendar(filterMonth,filterKunstart){
	var defaultFilter1Value = filterMonth;
	var defaultFilter2Value = filterKunstart;
	
	monthAsNumber = document.getElementById("currentSetMonthAsNumber").value;
	year = document.getElementById("currentSetYearAsNumber").value;
	
	var filter1 = "";
	if (document.getElementById("calendarMonth")) {
		filter1 = document.getElementById("calendarMonth").innerHTML;
			if(filter1==defaultFilter1Value) {
				filter1="";
			}
	}
	
	var filter2 = "";
	if (document.getElementById("calendarKunstart")) {
		filter2 = document.getElementById("calendarKunstart").innerHTML;
			if(filter2==defaultFilter2Value) {
			filter2="";
			}
	}
		

	var strUrl = '';
	var strParam1 = '';  
	var strParam2 = '';
	var strParam3 = '';
	var strParam4 = '';
	
	if (filter1!='')
		strParam1 = '?cmonth=' + encodeURIComponent(filter1);
	else
		strParam1 = '?';
	
	if (filter2!='')
		strParam2 = '&ckunstart=' + encodeURIComponent(filter2);
	
	if (monthAsNumber!='')
		strParam3 = '&cmno=' + monthAsNumber;
	if (year != '')
		strParam4 = '&cyear=' + year;
	
	document.location = strUrl + strParam1 + strParam2 + strParam3 + strParam4;
	
}


/******************************************************************************
Emneord/Oversigt A-Å
******************************************************************************/

function EmneordSearch(resultpage, letter, searchphrase)
{
	
	var strUrl = resultpage;
	var strParam = '?search=' + encodeURIComponent(searchphrase) + '&letter=' + encodeURIComponent(letter);
	document.location = strUrl + strParam;	
	
}

/******************************************************************************
Launch tip friend in eksternal vindue
******************************************************************************/

function LaunchTipFriend(itemid)
{
	var PositionX = 400;
	var PositionY = 400;
	var optIE='scrollbars=no,width=525,height=434,left='+PositionX+',top='+PositionY;
	var strUrl = "/service/SendTilVen.aspx"
	var strParam = "?itemid=" + encodeURIComponent(itemid);
	window.open(strUrl+strParam,'tipfriend',optIE);

}

/******************************************************************************
Writes out the Large style CSS reference.
In order to pass XHTML validation. 
******************************************************************************/
function WriteXSSLargeStyleTag()
{
		document.write("<style id='largeStyle' type='text/css' disabled='disabled'>@import url('/css/largeFont.css');</style>");
}
