/// <summary>
///		Summary description for common_functions.js.
/// </summary>
/// <history>
/// <change>08-03-2003 HEU oprettet standard funktionalitet til HJV.DK</change>
/// <change>19-03-2003 MALR Menuen ændret, således at det er muligt at have flere instanser på samme side</change>
/// <change>21-06-2003 PERA FoldudMenu 2 og 3 betyder at det foregående ikke skjules når nyt punkt foldes ud</change>
/// <change>21-06-2003 PERA FoldudMenu3 betyder listen vises med alle punkter foldet ud</change>
/// </history>

// Opretter script-del til at udskrive foldud-funktionalitet, kaldes med antalet af postings der skal vises...
	var imageRoot = "/Style%20Library/Creuna/Includes/Images/";		//sti til de to grafik filer
	var image1 = new Image(); image1.src = imageRoot+"foldud_closed.gif";
	var image2 = new Image(); image2.src = imageRoot+"foldud_open.gif";
	
	function FoldUdMenu(menuAntal, menuID)
	{
		this.antal = menuAntal;
		this.id = menuID;
		this.hideTheRest = true;
		this.q = new Array();
		for(i=1; i<=this.antal; i++) this.q[i]=0;
	}

	function FoldUdMenu2(menuAntal, menuID, hideTheRest)
	{
		this.antal = menuAntal;
		this.id = menuID;
		this.hideTheRest = hideTheRest;
		this.q = new Array();
		for(i=1; i<=this.antal; i++) this.q[i]=0;
	}
	
	function FoldUdMenu3(menuAntal, menuID, hideTheRest)
	{
		this.antal = menuAntal;
		this.id = menuID;
		this.hideTheRest = hideTheRest;
		this.q = new Array();
		for(i=1; i<=this.antal; i++) this.q[i]=1;
		showItAll(this);
	}
	
	function foldud(menu, i) {

		if(document.getElementById("foldudIndhold"+menu.id+i).style.display != "block") {
			if(document.all) document.all["foldudIndhold"+menu.id+i].style.display = "block";
			else if(document.getElementById) document.getElementById("foldudIndhold"+menu.id+i).style.display = "block";
			else return;
			for(r=1; r<=menu.antal; r++) { 
				if(i==r) menu.q[r] = 1; 
				else menu.q[r] = 0;
			}
			document['foldud'+menu.id+i].src = imageRoot+'foldud_open.gif';
		} else {
			document['foldud'+menu.id+i].src = imageRoot+'foldud_closed.gif';
			if(document.all) document.all["foldudIndhold"+menu.id+i].style.display = "none";
			else if(document.getElementById) document.getElementById("foldudIndhold"+menu.id+i).style.display = "none";
			else return;
			menu.q[i]=0;
			document['foldud'+menu.id+i].src = imageRoot+'foldud_closed.gif';
		}
	
	}

	function hideItAll(menu) {
		for(i=1; i<=menu.antal; i++) {
			document['foldud'+menu.id+i].src = imageRoot+'foldud_closed.gif';
			if(document.all) document.all["foldudIndhold"+menu.id+i].style.display = "none";
			else if(document.getElementById) document.getElementById('foldudIndhold'+menu.id+i).style.display = "none";
			else return;
		}
	}
	
	//slet
	function showItAll(menu) {
		for(i=1; i<=menu.antal; i++) {
			document['foldud'+menu.id+i].src = imageRoot+'foldud_open.gif';
			if(document.all) document.all["foldudIndhold"+menu.id+i].style.display = "block";
			else if(document.getElementById) document.getElementById('foldudIndhold'+menu.id+i).style.display = "block";
			else return;
		}
	}
	
	//Funktion til som skjuler elementer
	function doPrint()
	{
		if(window.print)
		{
			print();
		}
		else
		{
			alert('Din browser understøtter ikke automatisk udskrivning af siden. Klik istedet CTRL-P for at udskrive siden.');
		}
	}

//Script som reloader en frame- bruges til specialmoduler
function ReloadFrame() {
    //debugger;
	//alert('inde i reloadfram');
	if (document.getElementById('Module') != null)
	{
	   //alert('inde i frame null');

		//var iframe = document.getElementById('Module');
		//var src = iframe.src+ '&print=true'; //.substring(0, src.length-3);
		//var length = src.length;
		
		//iframe.src = src;
		//iframe.location = src;
		//alert(src)
	}
}
// Funktion til at fange et html element.
// Den sikrer at det også virker i fx firefox.
// Rico den 28. feb 2005
function GetId(id) {
	return (document.all)?document.all(id):document.getElementById(id);
}

// obj = det (inputfelt / textarea)'s id der skal tælles på
// span = id'et på det span tag der skal vise tælleren
// eks. onkeyup="Javascript: CharCount(this.id, 'charoutput', 20);"
function CharCount(obj, span, i) {
	var intLength = GetId(obj).value.length;
	var tmp = i - GetId(obj).value.length;

	if(intLength > i)
	{
		alert('Din besked er for lang, '+i+' tegn er tilladt.' );
		GetId(span).childNodes[0].nodeValue = 0;
		GetId(obj).value = GetId(obj).value.substr(0,1500);
		return;
	}

	GetId(span).childNodes[0].nodeValue = tmp;
}

$(document).ready(function() {
//Tilføjet af ekstern konsulent Oscar Eg Gensmann [oscar.gensmann@gmta.info]

// setting bold font on selected menuitems. Jquery is used since IE doesn't support child selector
$('#left-nav li.selected > a').css('font-weight','bold');
        
setTimeout(function() {

         // detecting if theres a bottom picture
         $('#BottomPicture').each(function(index) {

             if ($('.ms-consoleframe').size() == 0) {

                 //getting picture and removing it from DOM
                 var $bottomPic = $('#BottomPicture').remove();

                 // creating new container for bottom image inside the #top-nav
                 $('#top-nav').prepend('<div class="site-image-2" style="width:355px;position:absolute;top:-1px;left:500px;z-index:10000"></div>');

                 // injecting picture into new container
                 $('.site-image-2').html($bottomPic.html());

                  // Wrap switches and nav ul into a div for easy new placement
                 $('#PrimarySecondarySwitch, #nav').wrapAll('<div id="nav_ps_switch_padding"></div>');

                 // resetting old relative positioning
                 $('#PrimarySecondarySwitch').css({left:0});

                 // Placing switch and nav ul in new spot
                 $('#nav_ps_switch_padding').css({
                     position: 'relative',
                     left: 149,
                     width: 350,
                     overflow: 'hidden'
                 });

                 // moving content below new bottom picture downwards, the same amount as picture height (100px - some spacing)
                 $('#main-content div.split.right').css({
                     // removed height detection: marginTop: ($('.site-image-2 img').height() - 40)
					 marginTop: (100 - 40)
                 })

             }

         });

         //detecting frontpage and removing padding to make room for full width content
         $('div.split.right.noPadding .anonymousFrontPageContent').each(function(index) {
                 $(this).parents('div.split.right.noPadding').css({width:355});
                 $(this).parents('#main-content').css({width: 692});
                 $('div.split.left').css({width:323});
         });


     }, 100);

});




