﻿
var winW = null;
var winH = null;
var SearchBoxTerm;

try{
    $(document).ready(function () {
        $('.bookmarkpage').bind('click', BookmarkPage);
    });
}
catch (ex) { }

function catToggle() {

    // Follow the link if it has been set. '#' indicates not set.
    var url = $(this).attr('href');
    if (url != '#')
        location.href = url;

    // Toggle the display.
    if (!$(this).hasClass('selected')) {

        // Close previously selected item.
        $(this).parent().find('div').removeClass('display').addClass('nodisplay');
        $(this).parent().find('a').removeClass('selected');

        // Dont display a div with no children.
        if ($(this).next().children().length > 0) {
            $(this).next().removeClass('nodisplay').addClass('display');
        }

        // Display the selected item.
        $(this).addClass('selected');
    }
    else {
        $(this).next().removeClass('display').addClass('nodisplay');
        $(this).removeClass('selected');
    }

    return false;
}

function menuItemToggle() {
    $(this).toggleClass('menuItem menuItemHover');
}

function menuItemNavigate() {
    var url = $(this).children(':first-child').attr('href');

    if (url != '#') {
        location.href = url;
    }
    else if($(this).hasClass('bookmark')) {
        BookmarkSite(document.title, location.href);
        pageTracker._trackEvent('Download', 'Added To Favorites');
        return false;
    }
}

function ClearSearchBox(obj)
{
    obj.value = "";
    obj.style.color = "black";
}

//function ResetSearchBox(obj)
//{

//}



function ShowLoader()
{
    var txtSearch = document.getElementById("ctl00_SearchBar_txtSearchTerm");
    if (txtSearch == null)
        txtSearch = document.getElementById("ctl00_searchBox_txtSearchTerm");
    //var myRegxp = /^[0-9]{9}(\s)?/;
    //if(!myRegxp.test(txtSearch.value.trim()))
        //return;


    var table = document.createElement("table");
    table.setAttribute("cellpadding", "4");
    table.setAttribute("cellspacing", "0");
    table.setAttribute("border", "0");
    table.style.width = "277px";
    table.style.height = "57px";
    //table.style.border = "3px solid #52C314";
    //table.style.backgroundColor = "white";
    table.style.position = "absolute";
    table.style.backgroundImage = "url(/Gfx/loaderBg.png)";
    
    var tr = document.createElement("tr");
    var td0 = document.createElement("td");
    td0.style.verticalAlign = "middle";
    td0.style.paddingLeft = "10px";
    
    var img = document.createElement("img");
    img.src = "/Gfx/loader.gif";
    td0.appendChild(img);
    
    var td1 = document.createElement("td");
    td1.style.verticalAlign = "middle";
    td1.style.fontWeight = "bold";
    td1.style.fontFamily = "Lucida Sans Unicode";
    td1.style.fontSize = "14px";
    td1.innerHTML = "Vent venligst. Søger...";
    
    tr.appendChild(td0);
    tr.appendChild(td1);
    table.appendChild(tr);
    
    // Set the position    
    GetWindowDimensions();        
    table.style.left = (winW / 2) - (300 / 2) + "px";
    table.style.top = (winH / 2) - (75 / 2) - 50 + "px";

    document.body.appendChild(table);

    pageTracker._trackEvent('Search', 'SearchBox');
}

function QuickSearch(obj)
{
    document.getElementById("ctl00_SearchBar_txtSearchTerm").value = obj.innerHTML;
    document.getElementById("ctl00_SearchBar_btnSearch").click();
}

function AddSearch(term) {
    document.getElementById("ctl00_SearchBar_txtSearchTerm").value = term;
    document.getElementById("ctl00_SearchBar_btnSearch").click();
}

function ToggleQuestion(obj)
{
    var answer = getNextSibling(obj);
    answer.style.visibility = (answer.style.visibility == "visible" ? "hidden" : "visible");
    answer.style.display = (answer.style.display == "block" ? "none" : "block");
}

function Debug()
{
    document.getElementById("ctl00_ContentPlaceHolder_imgCached").className = 'visible';
}

function BookmarkPage()
{
    // Firefox
    if (window.sidebar)
        window.sidebar.addPanel(document.title, location.href, "");
	// Opera
    else if(window.opera && window.print)
    { 
	    var elem = document.createElement('a');
	    elem.setAttribute('href', location.href);
	    elem.setAttribute('title', document.title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
    }
    // Ie
    else if(document.all)
        window.external.AddFavorite(location.href, document.title);
}

function GetWindowDimensions()
{
    if (parseInt(navigator.appVersion) > 3)
    {
        if (navigator.appName == "Netscape")
        {
            this.winW = window.innerWidth;
            this.winH = window.innerHeight;
        }
        if (navigator.appName.indexOf("Microsoft")!= -1)
        {
            this.winW = document.documentElement.offsetWidth;
            this.winH = document.documentElement.clientHeight;
        }
    }
}

function TermTrim(obj) {
    obj.value = obj.value.trim();
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

// FireFox bug fixes.
function getNextSibling(startBrother)
{
  endBrother = startBrother.nextSibling;
  
  while(endBrother.nodeType!=1)
  {
    endBrother = endBrother.nextSibling;
  }
  
  return endBrother;
}

function getParentNode(obj) {

    parentNode = obj.parentNode;

    while (parentNode.nodeType != 1)
    {
        parentNode = parentNode.parentNode;
    }

    return parentNode;
}
