﻿/************************************ JS-FUNCTIONS LANA BEGIN ************************************/
function validateSubmit()
{
    var f = document.forms[1];            
    var i;
    
    for (i = 0; i < f.elements.length; i++)
    {    
        if ( ! validateField(f.elements[i], true) )
        {         
            f.elements[i].style.backgroundColor = 'red';
            f.elements[i].style.color = 'white';
            f.elements[i].focus();
            f.elements[i].select();
            allowToLeave = false;
            return false;
        }
        else
        {
            f.elements[i].style.backgroundColor = 'white';
            f.elements[i].style.color = 'black';
        }
    }
  
    for (i = 0; i < f.elements.length; i++)
    {
        if ( typeof(f.elements[i].disabled) != "undefined" )
            f.elements[i].disabled = false;    
    }
  
    for (i = 0; i < f.elements.length; i++)
    {
        // We need to compare 6 different fields to make sure they are filled correcly
        // They are stored as pairs in elements - this means that the fields that should be compared
        // is placed next to each other in the array
        if(f.elements[i].name == "AR" || f.elements[i].name == "BR" || f.elements[i].name == "FR")
        {
            if(!validateFields(f.elements[i], f.elements[(i+1)], true))
            {                
                f.elements[i].style.backgroundColor = 'red';
                f.elements[(i+1)].style.backgroundColor = 'red';
                f.elements[i].focus();
                f.elements[i].select();
                allowToLeave = false;
                return false;
            }            
        }
    }
    
    // Validating the field "Antal funktionærer" (A1) against the sum of "Tidligere indberettet i XXXX" (FA_f) and "Skriv ændringen.... i XXXX" (FA) and "Antal for hvem lønvurderingen endnu ikke er afsluttet (FA_m)"  
    if (!validateFieldAgainstSum(f, "funktionærer", "A1", "FA_f", "FA", "FA_m"))
        return false;

    // Validating the field "Antal arbejdere" (A2) against the sum of "Tidligere indberettet i XXXX" (AA_f) and "Skriv ændringen.... i XXXX" (AA) and "Antal for hvem lønvurderingen endnu ikke er afsluttet (AA_m)"
    if (!validateFieldAgainstSum(f, "arbejdere", "A2", "AA_f", "AA", "AA_m"))
        return false;

    // Validating the field "Antal arbejdere, funktionærliggende" (A3) against the sum of "Tidligere indberettet i XXXX" (BA_f) and "Skriv ændringen.... i XXXX" (BA) and "Antal for hvem lønvurderingen endnu ikke er afsluttet (BA_m)"
    if (!validateFieldAgainstSum(f, "arbejdere (funktionærlignende)", "A3", "BA_f", "BA", "BA_m"))
        return false;

    return true;
}

// The function has 5 parameters, the first one is the objects in the form, the second is the id for the field to validate, the third, fourth and fifth is ids for the fields to validate against the second paramter
// If the value of objToValidate is less than the sum a confirm-box is show to the user
// If the user chooses to click "OK" he accepts the data, the function returns true and the page is submitted
// If the user chooses to click "Cancel" the function returns false and the submit is cancelled
function validateFieldAgainstSum(f, objToValidateLabelText, objToValidateName, obj1ToValidateAgainstName, obj2ToValidateAgainstName, obj3ToValidateAgainstName) {
  
    var sum = 0;
    var objToValidate;
    var obj1ToValidateAgainst;
    var obj2ToValidateAgainst;
    var obj3ToValidateAgainst;
    var isValid = true;

    for (i = 0; i < f.elements.length; i++)    
    {
        if (f.elements[i].name == objToValidateName) {
            objToValidate = f.elements[i];
        }
        else if (f.elements[i].name == obj1ToValidateAgainstName) {
            obj1ToValidateAgainst = f.elements[i];
            sum += parseInt(f.elements[i].value);
        }
        else if (f.elements[i].name == obj2ToValidateAgainstName) {
            obj2ToValidateAgainst = f.elements[i];
            sum += parseInt(f.elements[i].value);
        }
        else if (f.elements[i].name == obj3ToValidateAgainstName) {
            obj3ToValidateAgainst = f.elements[i];
            sum += parseInt(f.elements[i].value);
        }
    }    
    
    if (objToValidate.value < sum) {
        objToValidate.style.backgroundColor = 'red';
        obj1ToValidateAgainst.style.backgroundColor = 'red';
        obj2ToValidateAgainst.style.backgroundColor = 'red';
        obj3ToValidateAgainst.style.backgroundColor = 'red';

        var retVal = confirm("Du har indtastet et højere antal " + objToValidateLabelText + " end oplyst i totallinien (Tidligere indberettet i indeværende periode)! Er antallet korrekt?");
        if (!retVal) {
            allowToLeave = false;
            isValid = false;
        }
    }
    else {
        objToValidate.style.backgroundColor = 'white';
        obj1ToValidateAgainst.style.backgroundColor = 'white';
        obj2ToValidateAgainst.style.backgroundColor = 'white';
        obj3ToValidateAgainst.style.backgroundColor = 'white';
    }    

    return isValid;
}

// The function checks the value of obj1 and obj2 - if either of them are != from 0 we need to inform the user
function validateFields(obj1, obj2, showAlert)
{
    var valueFormat = 0;
    var valid = true;
            
    if(obj1.valueType == "Percent")
        valueFormat = "0,0";

    if(isFilled(obj1.value))
    {                
        if(showAlert)
        {
            // if obj1 is less or greater than valueFormat and obj2 equals 0
            if( (obj1.value < valueFormat || obj1.value > valueFormat) && obj2.value == 0)            
                valid = false;
            
            if(!valid)
                alert("\"For antal\" skal være forskellige fra 0, når der er indtastet en ændring!\nKlik OK for visning af årsagen (markeret med rødt)");
        }
    }
    
    return valid;
}

function validateField(obj, showAlert){
  var fieldType = obj.valueType;
  switch (fieldType){
    case "UnsignedInt":
      break;
    case "Date":
      break;
    case "Percent":
      if ( !isPercent(obj.value) && isFilled(obj.value) ){
       if ( showAlert ){
        alert("Der skal indtastes et tal med én decimal");
      }
        return false;
      }else if ( !checkRange(obj) ){
       if ( showAlert ){
        alert("Tallet skal ligge i intervallet fra " + obj.minValue + ".0 til " + obj.maxValue + ".0 ");
       }
        return false;
      }
      break;
    case "Integer":
      if ( !isInteger(obj.value) && isFilled(obj.value) )
      {            
            if ( showAlert )
            {
                // We check the names of the two fields "AR" and "BR" because we need to have a specific alert-text for the user for these two fields
                if(obj.name == "AR" || obj.name == "BR")
                    alert("Beløbet skal angives i øre. F.eks. kr 1,00 = 100 øre");
                else
                    alert("Der skal indtastes et heltal");
            }
            return false;            
      }
      else if ( !checkRange(obj) )
      {
            if ( showAlert )
            {
                alert("Tallet skal ligge i intervallet ( " + obj.minValue + " <=TAL<= " + obj.maxValue + " )");
            }
            return false;
      }      
    case "String":
      break;
    case "Double":
      if ( !isDouble(obj.value) && isFilled(obj.value) ){
        if ( showAlert ){
        alert("Indtast et kommatal");
      }
        return false;
      }else if ( !checkRange(obj) ){
        if ( showAlert ){
        alert("Tallet skal ligge i intervallet ( " + obj.minValue + " <=TAL<= " + obj.maxValue + " )");
      }
        return false;
      }
      break;
    default:
      if ( obj.type.toUpperCase() != "SUBMIT" && typeof(obj.valueType) != "undefined"){
        alert("Typen er ikke defineret: " + obj.valueType);
        return false;
      }
  }
  
  // check for radiobuttons - at least one of the radiobuttons with the same name must be selected
  // note that this is called more than once for each radiogroup which is unneccessary
   if ( obj.type.toUpperCase() == "RADIO")
   	{
   		radiobuttongroup = eval("document.forms[1]."+obj.name);
   		oneIsSelected = false;
   		for (i=0; i< radiobuttongroup.length; i++)
	   		{
	   			if (radiobuttongroup[i].checked)
	   				oneIsSelected = true;	
	   		}
	   		if (!oneIsSelected)
	   			{	   			    
	   				if ( showAlert )
        			alert("Du skal vælge en af mulighederne (Ja/Nej)");
        		return false;
        	}		
   	}  
   	
  return true;
}

function calculateField(){
  var result = 0;
  var i;
  var obj;
  for ( i = 0; i < arguments.length-1; i++){
    obj = document.forms[1].elements[arguments[i]];
    if ( validateField(obj, false) && isFilled(obj.value) ){
      switch( obj.operator ){
        case "None":
          result = parseFloat(obj.value, 10);
        break;
        case "Add":
          result = result + parseFloat(obj.value, 10);
        break;
        case "Subtract" :
          result = result - parseFloat(obj.value, 10);
        break;
        case "Multiply":
          result = result * parseFloat(obj.value, 10);
        break;
        case "Divide":
          if ( obj.value != "0" ){
            result = result / parseFloat(obj.value, 10);
          }else{
            document.forms[1].elements[arguments[arguments.length-1]].value = "";
            return;
          }
        break;
      }
    }else{
      document.forms[1].elements[arguments[arguments.length-1]].value = "";
      return;
    }
  }
  document.forms[1].elements[arguments[arguments.length-1]].value = result;
}

function isDouble(val){
  var decimalchar = ",";
  exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
  m = val.match(exp);
  if (m == null){
    return false;
  }
  cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
  num = parseFloat(cleanInput);
  return (isNaN(num) ? false : true);
}

function isPercent(val){
  var decimalchar = ",";
  exp = new RegExp("^\\s*([-\\+])?(\\d+)?(\\" + decimalchar + "(\\d+))?\\s*$");
  m = val.match(exp);
  if (m == null){
    return false;
  }
  cleanInput = m[1] + (m[2].length>0 ? m[2] : "0") + "." + m[4];
  if ( m[4].length != 1 ){
    return false;
  }
  num = parseFloat(cleanInput);
  return (isNaN(num) ? false : true);
}

function isInteger(val){
  exp = /^\s*[-\+]?\d+\s*$/;
  if (val.match(exp) == null)
    return false;
  var num = parseInt(val, 10);
  return (isNaN(num) ? false : true);
}

function isFilled(val){
  return val=="" ? false: true;
}

function checkRange(obj){
  if ( obj.minValue == "" && obj.maxValue == ""){
    return true;
  }else if ( obj.minValue != "" && obj.maxValue != "" ){
    if ( parseFloat(obj.value,10) >= parseFloat(obj.minValue,10) && parseFloat(obj.value,10) <= parseFloat(obj.maxValue,10) ){
      return true;
    }else{
      return false;
    }
  }else if ( obj.minValue != "" ){
    if ( parseFloat(obj.value,10) >= parseFloat(obj.minValue,10) ){
      return true;
    }else{
      return false;
    }
  }else if ( obj.maxValue != "" ){
    if ( parseFloat(obj.value,10) <= parseFloat(obj.maxValue,10) ){
      return true;
    }else{
      return false;
    }
  }
  return true;
}

function SetFocusOnFirstElement(){
  var i;
  for (i =0; i < document.forms[1].elements.length; i++ ){
    if (document.forms[1].elements[i].type == "text"  && document.forms[1].elements[i].disabled == false){
      document.forms[1].elements[i].focus();
      document.forms[1].elements[i].select();
      break;
    }
  } 
}

// This function alerts the user that data will be lost if he chooses Ok
// Because we have implemented an allowToLeave-method on the page we need to
// add a try-catch to this function to avoid an error
// The error occurs if the user chooses Ok in this confirm-box and then chooses Cancel in the box
// that the allowToLeave-method creates. The reason is that this function try to send the user
// to another location but the allowToLeave-method dont
function RedirectAndWarnUserLeavingUnsavedPage() {

    var strText = "Data er ikke modtaget i DI. Du kan ikke genbruge en afvist indberetning.\n"
                    + "Status indikerer, at indberetningen ikke er godkendt og modtaget i DI.\n"
                    + "Indberetningen er først gyldig, når data er bekræftet, og du har modtaget en bekræftelsesmail.\n\n"
                    + "Kun godkendte indberetninger medtages i de offentliggjorte analyser.";

    var retVal = confirm(strText); 
       
    try {
        if (retVal)        
            location.href = "/indberetning/lana";
        }
    catch(e) {}
}

function GoBackAndWarnUserLeavingUnsavedPage() {

    var strText = "Data er ikke modtaget i DI. Du kan ikke genbruge en afvist indberetning.\n"
                    + "Status indikerer, at indberetningen ikke er godkendt og modtaget i DI.\n"
                    + "Indberetningen er først gyldig, når data er bekræftet, og du har modtaget en bekræftelsesmail.\n\n"
                    + "Kun godkendte indberetninger medtages i de offentliggjorte analyser.";

    var retVal = confirm(strText);
    if (retVal)
        history.back();
}
/************************************ JS-FUNCTIONS LANA END ************************************/



function OpenCloseDiv(divName) {
    if (divName.style.display == "none") {
        divName.style.display = "block";
    }
    else {
        divName.style.display = "none";
    }
}

function ProcessDefaultOnLoad(onLoadFunctionNames)
{
	ProcessPNGImages();
	UpdateAccessibilityUI();
	for (var i=0; i < onLoadFunctionNames.length; i++)
	{
		var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
		eval(expr);
	}
	if (typeof(_spUseDefaultFocus)!="undefined")
		DefaultFocus();
}	


function toggleControlPanel(elementId)
{
    element = document.getElementById(elementId);

    if (element.className=="ControlsCollapsed")
	    {element.className="ControlsExpanded"}
    else
	    {element.className="ControlsCollapsed"}
}

function loadCustomJS()
{
    replaceAtSign();
    addConfirmToRemove();
}

function replaceAtSign()
{
    var images = document.getElementsByTagName('IMG');
    for (var i = images.length - 1; i >= 0; i--) {
        if (images[i].title == "atsign") {
            images[i].outerHTML = '@';
        }
    }
}

function IsInDesignMode() {
    if (document.getElementById("MSOLayout_InDesignMode").value == "1") return true;
    if (document.getElementById("MSOTlPn_SelectedWpId").value != "") return true;
    return false;
}


function addConfirmToRemove() {
    if (IsInDesignMode()) {
        var links = document.getElementsByTagName('A');
        for (var i = 0; i < links.length; i++) {
            if (links[i].onclick) {
                var onclick = links[i].onclick + "";
                var index = onclick.indexOf("MSOLayout_RemoveWebPart");

                if (index > 0) {
                    links[i].onclick = function() { if (confirm('Tryk OK for at fjerne denne')) { MSOLayout_RemoveWebPart(document.all[this.id.replace('_Close', '')]) } };
                }
            }
        }
    }
}



/* NEW FUNCTIONS - MRN */

// add a link to a linkplaceholder	
function addlink(url, hiddenFieldID) {
    someobject = '';
    openLinkPicker(url, hiddenFieldID, someobject)
}


// open the linkpicker and get a return value and force a postback
function openLinkPicker(url, hiddenFieldID, someobject) {
    features = 'unadorned: no; dialogHeight: 720px; dialogWidth: 520px;center: yes; status: no; resizable: no;';
    //window.open(url, someobject); return; // for testing
    theLink = window.showModalDialog(url, someobject, features);
    if (theLink == undefined)
    { return false; }

    if (theLink.Type == "internal") {
        valuestring = "internal¤" + theLink.text + "¤" + theLink.guid + "¤" + theLink.qs;
    }
    if (theLink.Type == "external") {
        valuestring = "external¤" + theLink.text + "¤" + theLink.href;
    }
    if (theLink.Type == "didk") {
        valuestring = "didk¤" + theLink.text + "¤" + theLink.href;
    }
    if (theLink.Type == "resource") {
        valuestring = "resource¤" + theLink.text + "¤" + theLink.href;
    }
    if (theLink.Type == "inquisite") {
        valuestring = "inquisite¤" + theLink.text + "¤" + theLink.InquisiteId;
    }

    hiddenField = document.getElementById(hiddenFieldID);
    hiddenField.value = valuestring;
    return true;
}







// denne funktion hører til MultipleLinkPlaceholder
// denne funktion håndterer åbningen af et modalt vindue til at 
// vælge et link, og tager en returværdi som bruges til at 
// populere et skjult felt som så kan læses af ASP.NET ved postback

// Function that adds bold tag to textarea
function addBold()
{
	var range = document.selection.createRange();
	var selectedText = range.text;
	if (selectedText != '')
	{
		range.text = '<b>' + selectedText + '</b>';
	}
}
	
// Function that adds bold tag to textarea
function addList()
{
	var range = document.selection.createRange();
	var selectedText = range.text;
	if (selectedText != '')
	{
		var li = '';
		arrText = selectedText.split('\n');
		for (var i=0; i<arrText.length; i++)
		{
			if (arrText[i].trim != '')
			{
				li = li + '<li>' + arrText[i].replace('\r','') + '</li>';
			}
		}
		range.text = '<ol class="DiShopProductDescriptionList">' + li + '</ol>';
	}
}
	
// edit an existing link in a linkplaceholder
// the URL is the dialog of the URL to be opened, EXCEPT in the case of editing a ressourcegallery item, in which case the url is ignored (and the actual URL then created below)
// this is not very elegant
function editlink(url, hiddenFieldID, listBoxID)
{
listBox = document.getElementById(listBoxID);
if (listBox.selectedIndex>-1)
        {
        listItem = listBox.options[listBox.selectedIndex];
        }
else
        {
       alert("You must select a link before you can edit it.");
       return false;
       }    

someobject = listItem.value;
// if this is a resourcegallerylink the type is "resourcegallery"
// there is a legacy format, where ressourcegallery links was saved as external links
// they will stay in this legacy format until they are edited someday
// the following condition checks for this and makes sure the resourcegallery dialog is opened even for links in legacy format
if (someobject.indexOf("resourcegallery¤")==0 
        || (someobject.indexOf("¤/NR/rdonlyres/") >= 0 && someobject.indexOf("external¤")==0))
    {
    // HACK! the filename is replaced, so we keep the path and the querystring
    // Since there are two possible filenames, we do two replaces but only one will actually take place
    url = url.replace("LinkSelectDlg.aspx","ResourceSelectDlg.aspx").replace("LinkDiDkSelectDlg.aspx","ResourceSelectDlg.aspx");
    }  
openLinkPicker(url, hiddenFieldID, someobject)
}
	
function handleReturnValueFromAttachmentGallery(strPhName, strURL, strDispText)
	{
	valuestring = "resourcegallery¤Link til billede¤"+strURL;
	hiddenField = document.getElementById(strPhName);
	hiddenField.value = valuestring;
	submitThis();
	}
						
						
// denne funktion hører til radeditoren
// åbner et vindue med en hjælpetekst som hører til et givet editor-felt
	function showAuthorHelp(key)
						{
						window.open('/Redaktør/helpPagePosting?key='+key,'Help','toolbar=no, width=400, height=400, scrollbars=yes');
						}
						
function toggleControlPanel(elementId)
{
element = document.getElementById(elementId);

if (element.className=="ControlsCollapsed")
	{element.className="ControlsExpanded"}
else
	{element.className="ControlsCollapsed"}
}


/*
Author: Rob Eberhardt, Slingshot Solutions - http://slingfive.com/
Description: fixes failings of modal/modeless dialogs
Fixes: form submission, link targets, cookies, window.opener, keyboard shortcuts, accelerator:true, 
	window.navigate(), window.location.assign(), window.location.reload(), window.location.replace()
Usage: simply call at/after window.onload fires, it automatically detects dialogs & fixes
Params: p_bEnableContextMenu as boolean (enables custom context menu to re-create IE context menu basics)
Not fixed:
	-dynamically setting document.title
	-"window.location = ..."
History:
	2004-09-30	changed form/link fix, uses dynamic BASE tag instead of element looping
	2004-03-10	1st public release

*/
function fixDialog(p_bEnableContextMenu){
	// just for dialogs, else quit
	try{
		if(dialogArguments==undefined){return}
	}catch(e){return}
	
	p_bEnableContextMenu = (p_bEnableContextMenu==true);	// ensure datatype


	// name window, so we can fix targeting
	if(window.name==''){window.name = "winDialog";}
		
	
	goToURL = function(p_strURL){
		var oLink = document.createElement("A");
		document.body.insertAdjacentElement('beforeEnd', oLink);
		with(oLink){
			href = p_strURL;
			target = window.name;
			click();
		}
	}
	

	// fix window.navigate()
	window.navigate = goToURL; 
	// fix window.location.assign()
	window.location.assign = goToURL; 
	// fix window.location.reload()
	window.location.reload = function(){window.navigate(window.location.href)}
	// fix window.location.replace() (SORTA!)
	window.location.replace = goToURL; 
	
		

	// if window object was passed to vArguments, hook up as window.opener
	// eg:  showModalDialog(sURL, window, sFeatures)
	var bWasPassedWindow = false;
	try{
		bWasPassedWindow = dialogArguments.location!=undefined;
	}catch(e){}


	if(bWasPassedWindow){
		// fix opener
		window.opener = dialogArguments;

		// fix cookies (make available in dialog) 	<--- seems to work fine without this too?
		document.cookie = dialogArguments.document.cookie;
	}



	// fix document stuff
	attachEvent("onload", function(){
	
		// fix form submissions and link openings
		// insert base tag with target (should be faster & work on dynamically created links)
		var oHead = document.getElementsByTagName("HEAD")[0];
		var oBase= document.createElement("BASE");
		oBase.target = window.name;
		oHead.insertAdjacentElement('AfterBegin', oBase);
		//alert(oHead.outerHTML);
		

/*		//	old form/link fix

		// fix form submission (don't open new window)
		var colForms = document.forms;
		for(var f=0; f<colForms.length; f++){
			if(!colForms[f].target || colForms[f].target==null || colForms[f].target==''){colForms[f].target = window.name;}
		}
		
		// fix link opening (don't open new window)
		var colLinks = document.links;
		for(var l=0; l<colLinks.length; l++){
			if(!colLinks[l].target || colLinks[l].target==null || colLinks[l].target==''){colLinks[l].target = window.name;}
		}
*/


		// fix U accelerator
		var colUtags = document.all.tags("U");
		for(var u=0; u<colUtags.length; u++){
			if(colUtags[u].style.accelerator){
				colUtags[u].style.textDecoration = 'none';
			}
		}

	});


	// fix keyboard stuff
	document.attachEvent("onkeydown", function(){
		switch(event.keyCode){
			case 27: {	// enable ESC to close dialog
				close();
				break;
			}

			case 18: {	// alt, recreating accelerator
				if(event.repeat){break}	// ignore if key is held down
				var colUtags = document.all.tags("U");
				for(var u=0; u<colUtags.length; u++){
					if(colUtags[u].style.accelerator){
						colUtags[u].style.textDecoration = (colUtags[u].style.textDecoration!='none') ? 'none': 'underline';	// toggle underline
					}
				}
				setTimeout("document.body.focus();", 200);	// fixes toggle (sorta)
				//event.returnValue = false;
				event.cancelBubble = true;
				//return false;
				break;
			}

			//==== fix reload ====
			case 116: {	// f5 
				window.location.reload();
				break;
			}
			case 82: {	// ctl-R
				if(event.ctrlKey){
				window.location.reload();
				}
				break;
			}

			//==== fix keyboard navigation (does Not work, history object is always empty..) ====
			case 8: {	// backspace
				history.back();
				break;
			}
			case 37: {	// alt-left arrow
				if(event.altKey){history.back();}
				break;
			}
			case 39: {	// alt-right arrow
				if(event.altKey){history.forward();} 
				break;
			}
		}
	});


	// enable basics of normal context (right-click) menu
	document.attachEvent("oncontextmenu", function(){
		if(p_bEnableContextMenu){

		
/*		TODO: somehow reenable normal context menu...
//		var oEvtClick = createEventObject();
		var oEvtClick = new Object();
		oEvtClick.button = 2;	// right-click
//		alert(oEvtClick.button);
		//document.body.fireEvent('onclick', oEvtClick);
		return;
*/

		
			var strMenuHTML = 
				'<html><body>' + 
				'<st'+'yle type="text/css">\r\n' +
				'BODY {background:buttonface;  padding:2px; font:x-small Tahoma, sans-serif; font-size:80%;}\r\n' +
				'A {padding:0 4px 0 4px; text-decoration:none; color:buttontext; WIDTH:115%; display:block; cursor:default;}\r\n' +
				'A:hover {background:highlight; color:highlighttext;}\r\n' +
				'</st'+'yle>\r\n' + 
				'<scr'+'ipt language="Javascript">\r\n' +
				'function reload(){parent.location=parent.location.href}\r\n' +
				'</scr'+'ipt>\r\n' +
				'<a href="#" onclick="parent.window.opener.external.AddFavorite(parent.document.location.href, parent.document.title)">Add To Favorites</a>\r\n' +
				'<a href="#" onclick="parent.location=\'view-source:\'+parent.document.location.href">View Source</a>\r\n' +
				'<a href="#" onclick="parent.print()">Print</a>\r\n' +
				'<a href="#" onclick="parent.location.reload()">Refresh</a>\r\n' +
				'</body></html>' +
				'';

			var oPop = window.createPopup();
			var oPopBody = oPop.document.body;
			oPopBody.style.cssText = 'border:2px threedhighlight outset;';
			oPopBody.innerHTML = strMenuHTML;
			//alert(oPopBody.innerHTML);
			oPop.show(event.clientX, event.clientY, 130, 75, document.body);
			return false;

		}
	})


}

function setFrame(frame, radrotatorid) 
{
    var rotator = $find(radrotatorid);  
    var item = rotator.get_currentItem();  
    var index = item._index + 1;  
    if (frame == index) 
    {   
        return;   
    }  
      
    if (frame > index) 
    {  
        while (frame > index) 
        {  
            rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);  
            frame--;  
        }  
    } 
    else 
    {  
        while (frame < index) 
        {  
            rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Right);  
            frame++;  
        }
    }
}

function findPersonRedirect(id, url) {
    var oElement;
    if (oElement = document.getElementById(id)) {
        window.location = url + oElement.value;
    }
}

//<!-- (c) Netminers 2002-2005
//function nmtrack() {
//try{
//var cid = 'di';
//var nm_title = ''; // CMS could put page title here!
//var loc=new String(window.document.location);var loc2=loc;try{var toploc=new String(top.document.location);loc2=toploc.indexOf("nm_extag")!=-1?toploc:loc2;}catch(e){} if(nm_title=="")nm_title=document.title;
//var ref = ''; var c = document.cookie; 
//if( c.indexOf('nm_exref')!=-1 ){var ca = c.split(';');for( i = 0; i < c.length; i++ ){var item = new String(ca[i]);var idx = item.indexOf('nm_exref');if( idx!=-1 )ref = new String(item.substr( idx+9 ));}document.cookie='nm_exref=';}
//if( ref == '' ){ ref=document.referrer;try{ref=top.document.referrer;}catch(e){}}
//var ext=(loc2.indexOf('nm_extag=')!=-1?encodeURIComponent(loc2.substr(loc2.indexOf('nm_extag=')+9)):"");nm_title=encodeURIComponent(nm_title);loc=encodeURIComponent(loc);ref=encodeURIComponent(ref);ext=encodeURIComponent(ext);
//if(nm_title.length>250)nm_title=nm_title.slice(0,246)+'...';if(loc.length>800)loc=loc.slice(0,796)+'...';if(ref.length>800)ref=ref.slice(0,796)+'...';
//var script = document.createElement('SCRIPT');
//script.language = 'javascript';
//script.src = 'http'+(document.location.protocol=='https:'?'s':'')+'://'+cid+'.netminers.dk/tracker/dispatch.aspx?action=log'+'&n='+Math.random()+'&nav='+loc+'&cid='+cid+(ref.length>0?('&ref='+ref):'') +'&ti1='+nm_title+'&ext='+ext;
//document.getElementsByTagName('body')[0].appendChild( script );
//}catch(e){}
//}
//if( window.attachEvent ){window.attachEvent( 'onload', nmtrack );}else if( window.addEventListener ){window.addEventListener( 'load', nmtrack, true );}
//else {var oldonload = window.onload;if (typeof oldonload != 'function'){window.onload = nmtrack;}else{window.onload=function(){nmtrack();oldonload();}}}
////-->





var timeOn;

function hideObj(hiddenObj) {    
    
    if (hiddenObj.style.visibility == 'visible')        
        timeOn = setTimeout("document.getElementById('" + hiddenObj.id + "').style.visibility = 'hidden';timeOn=null;", 750);        
}

function showObj(parentObj, hiddenObj, offsetLeft, offsetTop) {
    var setLeft = parseInt(offsetLeft.toString().replace('px', ''));            
    var setTop = parseInt(hiddenObj.offsetHeight.toString().replace('px', ''));            

    var topmargin = getOffsetTop(parentObj, true);
    var leftmargin = getOffsetLeft(parentObj, true);            

    hiddenObj.style.left = leftmargin - setLeft;
    hiddenObj.style.top = topmargin - setTop - offsetTop;    

    if (timeOn != null) {                
        clearTimeout(timeOn);
    }
    
    if (hiddenObj.style.visibility == 'hidden')
        hiddenObj.style.visibility = 'visible';            
}       

// offsetTop and offsetLeft corrections
// note: IE5 Mac will not include page margins in calculations.
function getOffsetTop(element, deep) {
    return getOffsetProperty(element, 'Top', deep);
}

function getOffsetLeft(element, deep) {
    return getOffsetProperty(element, 'Left', deep);
}

function getOffsetProperty(element, property, deep) {
    var offsetValue = 0;
    offsetProperty = 'offset' + property;

    do {
        offsetValue += element[offsetProperty];
        element = element.offsetParent;
    } while (deep == true && element != document.body && element != null);
    return offsetValue;
}



/************************************ JS-FUNCTIONS EncyclopediaTOC START ************************************/

    var displayedTOCs = 0;
    var totalTOCs = 2; // must be dynamic set i code
    var idToc = 'idToc'
    var idArrow = 'idArrow';

    function showall() {
        for (i = 0; i < totalTOCs; i++) {
            var ele = document.getElementById(idToc + i);
            ele.style.display = "block";
            ele = document.getElementById(idArrow + i);
            ele.className = 'title expanded';
        }
        displayedTOCs = totalTOCs;
        document.getElementById('showalltoc').style.display = 'none';
        document.getElementById('hidealltoc').style.display = 'inline';
    }

    function hideall() {
        for (i = 0; i < totalTOCs; i++) {
            var ele = document.getElementById(idToc + i);
            ele.style.display = "none";
            ele = document.getElementById(idArrow + i);
            ele.className = 'title collapsed';
        }
        displayedTOCs = 0;
        document.getElementById('showalltoc').style.display = 'inline';
        document.getElementById('hidealltoc').style.display = 'none';
    }
    function showHideElement(elementNum) {
        //alert(elementNum); 

        if (document.getElementById(idToc + elementNum).style.display == 'none') {
            document.getElementById(idToc + elementNum).style.display = 'block';
            document.getElementById(idArrow + elementNum).className = 'title expanded';
            displayedTOCs++;
        }
        else {
            document.getElementById(idToc + elementNum).style.display = 'none';
            document.getElementById(idArrow + elementNum).className = 'title collapsed';
            displayedTOCs--;
        }
        if (displayedTOCs == totalTOCs) {
            document.getElementById('showalltoc').style.display = 'none';
            document.getElementById('hidealltoc').style.display = 'inline';

        }
        else if (displayedTOCs == 0) {
            document.getElementById('showalltoc').style.display = 'inline';
            document.getElementById('hidealltoc').style.display = 'none';

        }
        else {
            document.getElementById('showalltoc').style.display = 'inline';
            document.getElementById('hidealltoc').style.display = 'inline';


        }

    }

/************************************ JS-FUNCTIONS EncyclopediaTOC END ************************************/


function openHelp(helpword)
{
    window.open('/_layouts/HelpWindow.aspx?word='+helpword,'NY4','width=400,height=200,left=350,top=350,scrollbars=yes');
}

/************************************ JS-FUNCTIONS AreaBoxTwo  ************************************/
function showHideRightContentList(obj, id1, id2) {
    if (!(obj.value == '0' || obj.value == '1')) {
        txt = obj.options[obj.selectedIndex].value;
    }
    else {
        txt = obj.value;
    }

    if (txt.match('0')) {
        document.getElementById(id2).style.display = 'none';
        document.getElementById(id1).style.display = 'block';
    }
    if (txt.match('1')) {
        document.getElementById(id1).style.display = 'none';
        document.getElementById(id2).style.display = 'block';
    }
}


/************************************ JS-FUNCTIONS AreaBoxTwo  END ************************************/
function ShowHideByElementId(showid, hideid) 
{   
    //alert(showid);
    //alert(hideid);
    
    //Div to hide
    document.getElementById(hideid).style.display = 'none';
    document.getElementById(showid).style.display = 'block';
    //alert(showid);
}


/************************************ JS-FUNCTIONS Generel texbox extension************************************/
function evaluate_textboxvalue(obj, defaultvalue, method) {
    if (obj.value == '' && method == 'blur') {
        obj.value = defaultvalue;
    }
    if (obj.value.toLowerCase() == defaultvalue.toLowerCase() && method == 'focus') {
        obj.value = '';
    }
}

function clear_field(field, defaultvalue) {
    var fieldobj = document.getElementById(field);
    if (fieldobj.value == defaultvalue) {
        fieldobj.value = '';
    }
}
