/* This functions opens an image in a popup window and automatically resizes
   the window according to the image dimensions */
function openImage(imageURL,imageTitle){
	defaultWidth  = 500;
	defaultHeight = 500;
	PositionX = 100;
	PositionY = 100;

	// Set autoclose true to have the window close automatically
	// Set autoclose false to allow multiple popup windows
	var AutoClose = false;

	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;

	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 type=\"text/css\">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["theimage"].width;');
		writeln('  window.innerHeight=document.images["theimage"].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()">');
		writeln('<img name="theimage" src='+imageURL+' style="display:block; cursor: pointer;" onclick="self.close()"></body></html>');
		close();		
	}
}

function openTipFriendWindow(strURL)
{ var strName="TipAFriend";
  var strFeatures="width=542,height=698,toolbar=no,locationbar=no,menubar=no,scrollbars=yes,directoriesbar=no,statusbar=no,resizable=no";
  name=window.open(strURL,strName,strFeatures);
}

function openCurrencyCalculator(strURL)
{ var strName="CurrencyCalculator";
  var strFeatures="width=522,height=250,toolbar=no,locationbar=no,menubar=no,scrollbars=no,directoriesbar=no,statusbar=no,resizable=no";
  name=window.open(strURL,strName,strFeatures);
}

function openGoogleMapsPopup(strURL)
{ 
  var strName="ShowOnMap";
  var strFeatures="width=783,height=540,toolbar=no,locationbar=no,menubar=no,scrollbars=yes,directoriesbar=no,statusbar=no,resizable=yes";
  name=window.open(strURL,strName,strFeatures);
}

function emailToVisitDenmark(link_initialer,link_tekst)
{ 
	// Function to write email adress w/o exposing email to spiders. 
	var b = "&#118&#105&#115&#105&#116&#100&#101&#110&#109&#097&#114&#107&#046&#100&#107"; at = "@"; 
	document.write('<a href="'+"mai"+"lto"+":"+link_initialer+at+b+'">'+link_tekst+'</a>');
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
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";
    }
}


/* This code enables flash in Internet Explorer without the "Click here to activate this control" */
function flashInIE(swf, width, height, name) {
	var txt = '<OBJECT id="'+name+'" codeBase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" height="'+height+'" width="'+width+'" align="middle" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" VIEWASTEXT>\n'+
				'<PARAM NAME="_cx" VALUE="16536">\n'+
				'<PARAM NAME="_cy" VALUE="4128">\n'+
				'<PARAM NAME="FlashVars" VALUE="">\n'+
				'<PARAM NAME="Movie" VALUE="'+swf+'">\n'+
				'<PARAM NAME="Src" VALUE="'+swf+'">\n'+
				'<PARAM NAME="WMode" VALUE="opaque">\n'+ 
				'<PARAM NAME="Play" VALUE="-1">\n'+
				'<PARAM NAME="Loop" VALUE="-1">\n'+
				'<PARAM NAME="Quality" VALUE="High">\n'+
				'<PARAM NAME="SAlign" VALUE="">\n'+
				'<PARAM NAME="Menu" VALUE="0">\n'+
				'<PARAM NAME="Base" VALUE="">\n'+
				'<PARAM NAME="AllowScriptAccess" VALUE="sameDomain">\n'+
				'<PARAM NAME="Scale" VALUE="ShowAll">\n'+
				'<PARAM NAME="DeviceFont" VALUE="0">\n'+
				'<PARAM NAME="EmbedMovie" VALUE="0">\n'+
				'<PARAM NAME="BGColor" VALUE="FFFFFF">\n'+
				'<PARAM NAME="SWRemote" VALUE="">\n'+
				'<PARAM NAME="MovieData" VALUE="">\n'+
				'<PARAM NAME="SeamlessTabbing" VALUE="1">\n'+
				'<embed src="'+swf+'" menu="false" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="netcompany_'+name+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>\n'+
			'</OBJECT>';
	document.write(txt);
}

function ShowLayer(id){
 document.getElementById(id).style.display = 'block';
}

function HideLayer(id){
 document.getElementById(id).style.display = 'none';
}

function Redirect(url){
 window.location = url;
}

function toggleVisibility(elem2Toggle)
{
	var theElem = document.getElementById(elem2Toggle);
	theElem.style.display = (theElem.style.display == 'block') ? 'none' : 'block';
}

function changeCursor(thisElem, cursorStyle)
{
	thisElem.style.cursor = cursorStyle;
}

/**
* Activated when clicking on "print page" on search result pages.
* The string warningStr is alertet if the number of search results exceeds the limit
*/
function showPrintWarning(nSearchResults, warningLimit, warningStr)
{
	if (nSearchResults > warningLimit)
	{
		alert(warningStr);
	}
}

function URLEncode(plaintext)
{
    plaintext = plaintext.replace(/\r\n/g,"\n");  
    var utftext = "";  

    for (var n = 0; n < plaintext.length; n++) {  

     var c = plaintext.charCodeAt(n);  

     if (c < 128) {  
         utftext += String.fromCharCode(c);  
     }  
     else if((c > 127) && (c < 2048)) {  
         utftext += String.fromCharCode((c >> 6) | 192);  
         utftext += String.fromCharCode((c & 63) | 128);  
     }  
     else {  
         utftext += String.fromCharCode((c >> 12) | 224);  
         utftext += String.fromCharCode(((c >> 6) & 63) | 128);  
         utftext += String.fromCharCode((c & 63) | 128);  
     }  

    }  

    return escape(utftext);
};

function URLDecode(encoded)
{
    var string = "";  
    var i = 0;  
    var c = c1 = c2 = 0;  

    while ( i < encoded.length ) {  

     c = encoded.charCodeAt(i);  

     if (c < 128) {  
         string += String.fromCharCode(c);  
         i++;  
     }  
     else if((c > 191) && (c < 224)) {  
         c2 = utftext.charCodeAt(i+1);  
         string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));  
         i += 2;  
     }  
     else {  
         c2 = utftext.charCodeAt(i+1);  
         c3 = utftext.charCodeAt(i+2);  
         string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));  
         i += 3;  
     }  

    }  

    return string;
};

