﻿var ns6=document.getElementById&&!document.all;
var eventObj = (document.all) ? "window.event.srcElement" : "event.target";
if (ns6) document.captureEvents(Event.KEYDOWN);


function getKey(evt, inputID) {

    if (evt && ns6)
		typedKey=evt.which;
	else
		typedKey=event.keyCode;    


	if (typedKey == 13) {
			

		if(document.all) {
			window.event.cancelBubble='true';
		    window.event.returnValue = false;
		} else {
			evt.stopPropagation();
		    evt.preventDefault();
		}

		setSearch(inputID);
	 }
}


function gotoURL(pUrl) {
	var aUrl = pUrl.split("_atarget_");
	var tUrl = '';
	if(aUrl.length>1) {
		pUrl = aUrl[0];
		tUrl = aUrl[1];
	}
	if (tUrl == '') { 
		location.href = pUrl;
	} else {
		nWindow = window.open(pUrl,tUrl);
	}
}


/*
--------------------------------------------------------
Search
--------------------------------------------------------
*/




function setSearch(sourceControl) {
	
	if(sourceControl == 'searchboxtel'){
		location = '/Personaleinfo.aspx?tsearch=' + encodeURI(document.getElementById(sourceControl).value);
		return;
	}

	var rbGroup = eval(document.getElementById("searchCategory"));

	if (eval("document.forms[0].searchCategory[1]").checked) {
		location = '/Personaleinfo.aspx?tsearch=' + encodeURI(document.getElementById(sourceControl).value);
	}
	else {
		if (eval("document.forms[0].searchCategory[2]").checked) {
			location = '/Other/search.aspx?search=' + encodeURI(document.getElementById(sourceControl).value) + '&kpath=/sitecore/content/Intranet/Kompetencer';
		}
		else
		{
			location = '/Other/search.aspx?search=' + encodeURI(document.getElementById(sourceControl).value);
		}
	}
}




function checkEnter(e,caller) //e is event object passed from function invocation
{

	var characterCode //literal character code will be stored in this variable

	if(e && e.which ||e.which == 0)
	{ //if which property of event object is supported (NN4)
	
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
	    if(document.all){
		    e.returnValue=false;
            e.cancel = true;
        }
        else{
         e.preventDefault();
        }
        var obj = document.getElementById(caller);
        if(obj){        
            
            if(obj.click){
		        obj.click();
		    }
		}
		return false
	}
	else
	{
		return true
	}
		
}

// clear form fields
function clearDefault(el) {
    var defaultValue = el.value; //"Skriv søgeord";
if (defaultValue==el.value){el.value = "";}
}


function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function toggleRow(o)
{
	var blockAtt = (document.all) ? 'block' : 'table-row' ;
	var targetRow = o.parentNode.parentNode.nextSibling;
	var icon = o.getElementsByTagName('img').item(0);
	icon.src = (icon.src.indexOf('plus')>=0) ? '/images/minus.gif' : '/images/plus.gif';
	targetRow.style.display = (targetRow.style.display != blockAtt) ? blockAtt: 'none';
}

function saethoejde(){
    if(document.getElementById("contentBox")){
        var contentBox = document.getElementById("contentBox");
    }
    if (document.getElementById("leftBox")){
        var leftBox = document.getElementById("leftBox");
    }
    if (document.getElementById("leftBoxSubpage")){
        var leftSubBox = document.getElementById("leftBoxSubpage");
    }

    if (leftSubBox){
        var leftContent = leftSubBox;
    }
    else if(leftBox) {
        var leftContent = leftBox
    }
    else{
        return false
    }
    
    
    
    if (leftSubBox){
        var leftMenuH = leftSubBox.offsetHeight -10;
    }
    else {
        var leftMenuH = leftBox.offsetHeight -10;
    }
    
    var contentH = contentBox.offsetHeight;
    var netto = leftMenuH - 10;
    if(leftMenuH>contentH){
                contentBox.style.height = leftMenuH+"px";
    }
    if(leftMenuH<contentH){
                leftContent.style.height = -20+contentH+"px";
    }
}

	function openPopup(windowName,url,width,height) 
	{
		t = (screen.availHeight - height) / 2;
		l = (screen.availWidth - width) / 2;
		window.open(url,"popup","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,copyhistory=0,top="+t+",left="+l+",width="+width+",height="+height);
	}



/*
--------------------------------------------------------
Search
--------------------------------------------------------
*/
	function OxySearch(searchnode, searchStr) {
	    var searchStr = encodeURIComponent(searchStr);
	    location.href = searchnode + '?q=' + searchStr;
	}
	function OxySearch(searchnode, searchStr, site, client, proxystylesheet, output) {
	    OxySearch(searchnode, searchStr, site, client, proxystylesheet, output, '0');
	}
	function OxySearch(searchnode, searchStr, site, client, proxystylesheet, output, showall) {
	    var searchStr = encodeURIComponent(searchStr);
	    var searchUrl = searchnode + '?q=' + searchStr;
	    if (site != "default_collection")
	        searchUrl += "&site=" + site;
	    if (client != "odense")
	        searchUrl += "&client=" + client;
	    if (proxystylesheet != "odense")
	        searchUrl += "&proxystylesheet=" + proxystylesheet;
	    if (output != "xml_no_dtd")
	        searchUrl += "&output=" + output;
	    if (showall == "1")
	        searchUrl += "&filter=0";
	    location.href = searchUrl;

	}

	function GoogleMiniSearch(searchnode, searchStr) {
	    var searchStr = encodeURIComponent(searchStr);
	    location.href = '/OxygenSoftware/GoogleMini.aspx?q=' + searchStr;
	}
	function GoogleMiniSearchCat(searchnode, searchStr, category) {
	    var searchStr = encodeURIComponent(searchStr);
	    var categoryStr = encodeURIComponent(category);
	    location.href = '/OxygenSoftware/GoogleMini.aspx?q=' + searchStr + "&c=" + categoryStr;

	}

	function GoogleMiniSearchDocs(searchnode, searchStr) {
	    var searchStr = encodeURIComponent(searchStr);
	    var categoryStr = encodeURIComponent(category);
	    location.href = '/OxygenSoftware/GoogleMini.aspx?q=' + searchStr + "&docs=1";

	}


function postSearch(searchStr,group,category){
    var searchStr = encodeURIComponent(searchStr);
    var category = encodeURIComponent(category);
 
//    if(group == '1'){
//        location.href = '/sog.aspx?q=' + searchStr + '&sorttype=meta&sortkey=category&group=1&results=100000&l=1'; 
//    }
//    else{
//        location.href = '/sog.aspx?q=' + searchStr + '&mc=category='+category;
//        
//    }  
}

function postSearch1(searchStr,group,category, resultsPerGroup){
    var searchStr = encodeURIComponent(searchStr);
    var category = encodeURIComponent(category);
 
//    if(group == '1'){
//        location.href = '/sog.aspx?q=' + searchStr + '&sorttype=meta&sortkey=category&group=1&results=' + resultsPerGroup + '&l=1'; 
//    }
//    else{
//        location.href = '/sog.aspx?q=' + searchStr + '&mc=category='+category;
//        
//    }  
}

function groupSearch(searchStr, mc, category, startPage, resultsPerGroup, resultPage){
    var category = encodeURIComponent(category);
    category = category.replace("-", "%00%2D");
    var strResult = resultPage + '?q=' + searchStr + '&mc=category='+category + '&l=' + startPage + '&results=' + resultsPerGroup;
    location.href = strResult;

}

function postWeblightSearch(searchUrl, searchStr, group, category, resultsPerGroup){
    var searchStr = encodeURIComponent(searchStr);
    var category = encodeURIComponent(category);
 
    if(group == '1'){
        location.href = searchUrl + '?q=' + searchStr + '&sorttype=meta&sortkey=category&group=1&results=' + resultsPerGroup + '&l=1'; 
    }
    else{
        location.href = searchUrl + '?q=' + searchStr + '&mc=category='+category;
        
    }  
}
function OxyWeblightSearch(searchnode,searchStr,site, stylesheet){
    var searchStr = encodeURIComponent(searchStr);
    location.href = searchnode +'?q=' + searchStr + '&site=' + site + '&client=' + stylesheet + '&proxystylesheet=' + stylesheet + '&output=xml_no_dtd';
}

 function searchNavigate(url) {
    var url = encodeURIComponent(url);
    location.href = url;
  }
/*
--------------------------------------------------------
/ Search
--------------------------------------------------------
*/






function checkAllInterestGroups() {
    
        var ckCheckAll = document.getElementById("checkAll");
        
        if (ckCheckAll.checked) {
            for (var i=0;  i<document.forms[0].length; i++) {
                
                if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].id != "checkAll")) {
                    document.forms[0].elements[i].checked = true;
                }
            }
        }
        else {
            for (var i=0;  i<document.forms[0].length; i++) {
               if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].id != "checkAll")) {
                    document.forms[0].elements[i].checked = false;
                }
            }
        }

}

/*
--------------------------------------------------------
/ MiljoForum Search
--------------------------------------------------------
*/

function mfSubmitSearch(e,searchStr,group,category, resultsPerGroup){
	var characterCode //literal character code will be stored in this variable

	if(e && e.which ||e.which == 0)
	{ //if which property of event object is supported (NN4)
	
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
	    if(document.all){
		    e.returnValue=false;
            e.cancel = true;
        }
        else{
         e.preventDefault();
        }
        
        postSearch1(searchStr, group, category, resultsPerGroup);

		return false
	}
	else
	{
		return true
	}
}
function o2mfSubmitSearch(e,searchnode,searchStr,site,client,proxystylesheet,output){
	var characterCode //literal character code will be stored in this variable

	if(e && e.which ||e.which == 0)
	{ //if which property of event object is supported (NN4)
	
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	}
	else
	{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
	    if(document.all){
		    e.returnValue=false;
            e.cancel = true;
        }
        else{
         e.preventDefault();
        }
        
        OxySearch(searchnode,searchStr,site,client,proxystylesheet,output);

		return false;
	}
	else
	{
		return true;
	}
}
function increaseFontSizeToMax() {
    removejscssfile("/css/weblight/screen.css", "css");
    removejscssfile("/css/weblight/screen_large.css", "css");
    loadjscssfile("/css/weblight/screen_All_large.css", "css");
}
function increaseFontSize() {
    removejscssfile("/css/weblight/screen.css", "css");
    removejscssfile("/css/weblight/screen_All_large.css", "css");
    loadjscssfile("/css/weblight/screen_large.css", "css");
}
function decreaseFontSize() {
    removejscssfile("/css/weblight/screen_large.css", "css");
    removejscssfile("/css/weblight/screen_All_large.css", "css");
    loadjscssfile("/css/weblight/screen.css", "css");
}
function loadjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

function removejscssfile(filename, filetype) {
    var targetelement = (filetype == "js") ? "script" : (filetype == "css") ? "link" : "none" //determine element type to create nodelist from
    var targetattr = (filetype == "js") ? "src" : (filetype == "css") ? "href" : "none" //determine corresponding attribute to test for
    var allsuspects = document.getElementsByTagName(targetelement)
    for (var i = allsuspects.length; i >= 0; i--) { //search backwards within nodelist for matching elements to remove
        if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1)
            allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
    }
}

function setHeight() {
    setTimeout("calcHeight();", 2000);
}
function calcHeight() {

    //find the height of the internal page
  var the_height=
    document.getElementById('dagsordenIframe').contentWindow.
      document.body.scrollHeight;
  //change the height of the iframe
  document.getElementById('dagsordenIframe').height =
      the_height;

}

