function template_printpage(page_id, popup_width) {
	var intWidth = parseInt(popup_width);
	var intHeight = 600;
	var intLeft = (screen.availWidth - intWidth - 10) / 2;
	var intTop  = (screen.availHeight - intHeight - 29) / 2;
	objWin = window.open("/includes/pages/module_print.asp?page_id=" + page_id, 'ViewPopup', 'left=' + intLeft + ',top=' + intTop + ',width=' + intWidth + ',height=' + intHeight + ',menubar=no,toolbar=no,location=no,status=yes,scrollbars=no,resizable=no');
}

function lightbox_maxwidth() {
	return document.documentElement.clientWidth;
}
function lightbox_maxheight() {
	return document.documentElement.clientHeight;
}
function lightbox_pictures()
{
	var elm_container = document.getElementById("t04_template_contentarea");
	if(elm_container) {
		var arr_elements = elm_container.getElementsByTagName("a");
		for(var i=0; i<arr_elements.length; i++){
			current_elm = arr_elements[i];
			current_rel = current_elm.getAttribute("rel");
			if(current_rel != null) {
				if(current_rel.indexOf("lightbox") == 0) {
					var this_id = current_elm.getAttribute("id");
					var this_img = "/files/gallery/" + this_id + "/" + (lightbox_maxwidth()-200) + "/" + (lightbox_maxheight()-200) + "/"
					this_img = this_img.replace("img_","")
					document.getElementById(this_id).href = this_img;					
				}
			}
		}
	}
}
function critical_message() {
	var msg = document.getElementById("critical_warning");
	if(msg) {
		$(msg).fadeOut(1000).fadeIn(1000)
		$(msg).animate({top: "50px"}, 1000);
		$(msg).animate({top: "0px"}, 750);
	}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function VideoCreate() {
	
	var VideoPlayer=getCookie("VideoPlayer");
	
	if (VideoPlayer==null || VideoPlayer=="")
	{
		setCookie("VideoPlayer","1",1);

		var VideoOverlay = $('<div id="VideoOverlay" style="position:fixed;left:0px;top:0px;background-color:#000000;opacity:0.7;filter:alpha(opacity=70);z-index:9998;" />').prependTo('body');
		VideoOverlay.css({'width':$(window).width(),'height':$(window).height()}).click(function() { VideoDone(); });
		
		var VideoBackground = $('<div id="VideoBackground" style="position:fixed;width:858px;height:auto;background-color:#FFFFFF;z-index:9999;text-align:center;" />').append('<a href="javascript:void(0);" class="VideoBack" onclick="VideoDone();" style="display:block;padding:6px 0 4px 0;">Gå videre til siden</a>').prependTo('body');
		VideoBackground.css({'left':($(window).width()-858)/2,'top':($(window).height()-498)/2});
		
		var VideoContainer = $('<div id="VideoContainer" style="margin:4px;width:850px;height:490px;" />').appendTo(VideoBackground);
		
		setTimeout(function() {
			VideoContainer.append('<iframe id="VideoPlay" width="850" height="490" src="http://www.youtube.com/embed/AKsIWFZwjUY?hd=1&autoplay=1" frameborder="0" allowfullscreen></iframe>');
		}, 500);
		
		setTimeout("VideoDone()", 84000);
	}
	
}

function VideoDone() {
	$('#VideoPlay').hide().remove();
	$('#VideoOverlay').remove();
	$('#VideoBackground').remove();
}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}
