
function openWindow(url, title, width, height, crome) {
    var x = 0, y = 0;
    if (window.screenLeft) {
      x = window.screenLeft + 100;
      y = window.screenTop + 100;
    }
    else if (window.screenX) {
      x = window.screenX + 100;
      y = window.screenY + 100;
    }

    if (crome == null) {
        crome = "left="+x+",top="+y+",height=" + height + 
                ",width=" + width + ",toolbar=no,scrollbars=no"
    } else {
        crome = "left="+x+",top="+y+",height=" + height + 
                ",width=" + width + ", " + crome
    }
    var w = window.open(url, title, crome);   
    return false; 
}

function openWindowCentered(url, name, height, width)
{
   marginTop = (screen.height - height)/3;
   marginLeft = (screen.width - width)/2;
   extraFeatures = "menubar=yes";
   extraFeatures += ", location=yes";
   extraFeatures += ", resizable=yes";
   extraFeatures += ", scrollbars=yes";
   extraFeatures += ", titlebar=yes";
   extraFeatures += ", toolbar=yes";
   extraFeatures += ", width="+width;
   extraFeatures += ", height="+height;
   extraFeatures += ", top="+marginTop;
   extraFeatures += ", left="+marginLeft;
   newWindow = window.open(url, name, extraFeatures);
   newWindow.focus();
}

function closeWindow() {
    window.close();
}

function logoff() 
{
    var str = new String(document.location);
    if(str.indexOf("?") == -1)
    {
        document.location += "?logoff=true";
    }
    else
    {
        document.location += "&logoff=true";
    }
}

function chartSSLKrifaerhverv()
{
    document.write('<img src="https://secure.chart.dk/reghit.asp?website_id=119775&secID=' + Math.random()*10000000 + '&ref=' + escape(document.referrer) + '" width="1" height="1">');
}

function chartKrifaerhverv()
{
    document.write('<img src="http://cluster.chart.dk/reghit.asp?website_id=119775&secID=' + Math.random()*10000000 + '&ref=' + escape(top.document.referrer) + '&doc=' + escape(document.location) + '" width="1" height="1">');
}

function chartSSLKrifaselv()
{
    document.write('<img src="https://secure.chart.dk/reghit.asp?website_id=99642&secID=' + Math.random()*10000000 + '&ref=' + escape(document.referrer) + '" width="1" height="1">');
}

function chartKrifaselv()
{
    document.write('<img src="http://cluster.chart.dk/reghit.asp?website_id=99642&secID=' + Math.random()*10000000 + '&ref=' + escape(top.document.referrer) + '&doc=' + escape(document.location) + '" width="1" height="1">');
}

function chartSSL()
{
    document.write('<img src="https://secure.chart.dk/reghit.asp?website_id=73361&secID=' + Math.random()*10000000 + '&ref=' + escape(document.referrer) + '" width="1" height="1">');
}

function chart()
{
    document.write('<img src="http://cluster.chart.dk/reghit.asp?website_id=62197&secID=' + Math.random()*10000000 + '&ref=' + escape(top.document.referrer) + '&doc=' + escape(document.location) + '" width="1" height="1">');
}

function postSearch(searchStr){   
    document.forms[0].__VIEWSTATE.name = "noviewstate";

    if(searchStr == '' && document.forms[0] != null && document.forms[0].search != null){
        searchStr = document.forms[0].searchBox.value;
        document.forms[0].search.value=searchStr;
      }

    searchStr = escape(searchStr);
        
    searchStr = replaceChars(searchStr,"*",""); //*
    searchStr = replaceChars(searchStr,"%28",""); //(
    searchStr = replaceChars(searchStr,"%29",""); //)
    searchStr = replaceChars(searchStr,"%3A",""); //:
    searchStr = replaceChars(searchStr,"%3D",""); //=
    searchStr = replaceChars(searchStr,"%21",""); //!
    searchStr = replaceChars(searchStr,"%25",""); //%
    searchStr = replaceChars(searchStr,"+",""); //+
    searchStr = replaceChars(searchStr,"-",""); //-
    searchStr = replaceChars(searchStr,"%3F",""); //?
    searchStr = replaceChars(searchStr,"%A7",""); //§
    searchStr = replaceChars(searchStr,"%23",""); //#
    searchStr = replaceChars(searchStr,"%A4",""); //¤
    searchStr = replaceChars(searchStr,"%60",""); //`
    searchStr = replaceChars(searchStr,"%B4",""); //´
    searchStr = replaceChars(searchStr,"%7C",""); //|
    searchStr = replaceChars(searchStr,"%7D",""); //}
    searchStr = replaceChars(searchStr,"%5D",""); //]
    searchStr = replaceChars(searchStr,"%5B",""); //[
    searchStr = replaceChars(searchStr,"%7B",""); //{
    searchStr = replaceChars(searchStr,"%24",""); //$
    searchStr = replaceChars(searchStr,"%A3",""); //£
    searchStr = replaceChars(searchStr,"%7E",""); //~
    searchStr = replaceChars(searchStr,"%5E",""); //^
    searchStr = replaceChars(searchStr,"%A8",""); //¨
    searchStr = replaceChars(searchStr,"%27",""); //'
    searchStr = replaceChars(searchStr,"%2C",""); //,
    searchStr = replaceChars(searchStr,"%3B",""); //;
    searchStr = replaceChars(searchStr,"%3C",""); //<
    searchStr = replaceChars(searchStr,"%3E",""); //>
    searchStr = replaceChars(searchStr,"%5C",""); //\
                
    if (unescape(searchStr).length < 3) {
        alert ("Indtast mindst 3 tegn.");
        return false;
       }
    
    searchStr = replaceChars(searchStr,"%F8","%C3%B8"); //ø
    searchStr = replaceChars(searchStr,"%D8","%C3%98"); //Ø
    searchStr = replaceChars(searchStr,"%E5","%C3%A5"); //å 
    searchStr = replaceChars(searchStr,"%C5","%C3%85"); //Å
    searchStr = replaceChars(searchStr,"%E6","%C3%A6"); //æ
    searchStr = replaceChars(searchStr,"%C6","%C3%86"); //Æ
                
    //document.form1.method="post";        
    document.forms[0].method="get";        
    document.location="/search.aspx?page=1&search="+searchStr+"*";
    //document.form1.submit();
    return false;
}

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)
	{ //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)
	{
	    // setFocus(caller);
		// This is for shitty firefox event model
		// document.getElementById(caller).click();			
        
		if(e.target){
			if(e.stopPropagation){
				e.stopPropagation();
				e.preventDefault();
			}
		}
		else{
			if(window.event){						
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
		}
        postSearch(document.forms[0].searchBox.value);		
		return false;
	}
	else
	{
		return true;
	}
}


function replaceChars(entry,from,to)
 {
    temp = "" + entry;

    while (temp.indexOf(from)>-1) {
        pos= temp.indexOf(from);
        temp = "" + (temp.substring(0, pos) + to + 
        temp.substring((pos + from.length), temp.length));
    }
        return temp;
}

function hideValidationSummary(summaryID) {
    // alert("Kalder hideValidationSummary med id = " + summaryID);
    hideElement(summaryID);
    return false;
}

function hideElement(id) {
    getElement(id).style.display = "none";
}

function getElement(id) {
    if (document.getElementById) {    
        return document.getElementById(id);
    } else if (document.all) {
        eval ("return document.all." + id);
    } else if (document.layers) {
        eval ("return document.layers." + id);
    }
}

function printItem(){
    window.print();
}

//Stop event from bubbling
function StopEvent(e){
    if(!e) var e = window.event;
	
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = false;

    //e.stopPropagation works only in Firefox.
    if (e.stopPropagation){
        e.stopPropagation();
        e.preventDefault();
    }
    return false;
}

//Stop event from bubbling, this function seems to be less stopping that StopEvent 
//and seems to allow postbacks to get to the server side
function StopEvent2(e){
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}