﻿var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22295693-1']);
  _gaq.push(['_setDomainName', '.bizweb.no']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

function radioGroupValue(group_name) {
    var group = document.getElementsByName(group_name);
    for (var i = 0; i < group.length; i++) {
        if (group[i].checked == true) {
            return group[i].value
        }
    }
    return "InternFeilUgyldigType"
}

function byteashex(byte) {
    var HEX_CHARS = "0123456789ABCDEF";
    return HEX_CHARS.charAt((byte / 16) & 0xF) + HEX_CHARS.charAt(byte & 0xF);
}

function urlencode(s) {
    var OK_CHARS = "-_.!~*'()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    var result = "";
    for (var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (c == " ") {
            result += "+";
        }
        else if (OK_CHARS.indexOf(c) >= 0) {
            result += c;
        }
        else {
            var code = c.charCodeAt(0);
            if (code <= 127) {
                result += "%" + byteashex(code);
            }
            else if (code <= 2047) {
                // UTF-8: First five bits masked with 110X.XXXX, last six bits masked with 10XX.XXXX
                result += "%" + byteashex((code >> 6) | 0xC0) + "%" + byteashex((code & 0x3F) | 0x80);
            }
            else {
                alert("Unicode characters from 2048 and up are not yet implemented. This will not work!")
            }
        }
    }
    return result;
}

/*
// Position 2048 - 65535: three bytes for UTF-8 character encoding.
if (charcode > 2047 && charcode < 65536) {
// First UTF byte: Mask the first four bits of charcode with binary 1110.XXXX:
encoded = encoded + gethex((charcode >> 12) | 0xE0);
// Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
// Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
encoded = encoded + gethex((charcode & 0x3F) | 0x80);
}

// Position 65536 - : four bytes for UTF-8 character encoding.
if (charcode > 65535) {
// First UTF byte: Mask the first three bits of charcode with binary 1111.0XXX:
encoded = encoded + gethex((charcode >> 18) | 0xF0);
// Second UTF byte: Get the next six bits of charcode and mask them binary 10XX.XXXX:
encoded = encoded + gethex(((charcode >> 12) & 0x3F) | 0x80);
// Third UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
encoded = encoded + gethex(((charcode >> 6) & 0x3F) | 0x80);
// Fourth UTF byte: Get the last six bits of charcode and mask them binary 10XX.XXXX:
encoded = encoded + gethex((charcode & 0x3F) | 0x80);
}

*/


function displayNone(elem) {
    elem.style.display = 'none';
}
function toggleDisplayBlockNone(elem) {
    if (elem.style.display == 'none') {
        elem.style.display = 'block';
    } else {
        elem.style.display = 'none';
    }
}

function getElementAbsolutePos(element) {
    var res = new Object(); //{ x: 0; y: 0 } 
    res.x = 0; res.y = 0;
    if (element !== null) {
        res.x = element.offsetLeft;
        res.y = element.offsetTop;

        var offsetParent = element.offsetParent;
        var parentNode = element.parentNode;

        while (offsetParent !== null) {
            res.x += offsetParent.offsetLeft;
            res.y += offsetParent.offsetTop;

            if (offsetParent != document.body && offsetParent != document.documentElement) {
                res.x -= offsetParent.scrollLeft;
                res.y -= offsetParent.scrollTop;
            }
            //next lines are necessary to support FireFox problem with offsetParent  
            if (navigator.userAgent.match(/gecko/i)) {
                while (offsetParent != parentNode && parentNode !== null) {
                    res.x -= parentNode.scrollLeft;
                    res.y -= parentNode.scrollTop;

                    parentNode = parentNode.parentNode;
                }
            }
            parentNode = offsetParent.parentNode;
            offsetParent = offsetParent.offsetParent;
        }
    }
    return res;
}
function visDialog(dialogDivId) {
    var d = document.getElementById(dialogDivId);
    d.style.zIndex += 1;
    d.style.position = "absolute";
    var pos = getElementAbsolutePos(d.parentNode);
    //d.style.left = "100px"; //pos.x + "px";
    //d.style.top = "100px"; //pos.y + "px";
    d.style.display = "block";
}

function showRelativeDialog(dialogDivId) {
    d = document.getElementById(dialogDivId);
    d.style.zIndex += 1;
    d.style.left = event.clientX - 200 + 'px';
    d.style.top = event.clientY + document.body.scrollTop - 100 + 'px';
    d.style.display = "block";
}

function showErrorMsgDiv(divId, message) {
    d = document.getElementById(divId);
    d.innerHTML = "<b>" + message + "</b>" + "<br/> <a href=\"javascript:skjulDialog('accountingStatusErrorDlg')\">[Lukk]</a><br />";
    d.style.zIndex += 1;
    d.style.left = event.clientX + document.body.scrollLeft - 200 + 'px';
    var scroll = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop
    d.style.top = event.clientY + scroll + 'px';
    d.style.display = "block";
}

function skjulDialog(dialogDivId) {
    var d = document.getElementById(dialogDivId);
    d.style.zIndex -= 1;
    d.style.display = "none";
}
function getPrintModeOrIntranetModeParam(questionmark_or_ampersand) {
    if (!window.location.search || window.location.search.length <= 1) return "";
    if (!questionmark_or_ampersand) questionmark_or_ampersand = "";
    var querystring = window.location.search.substring(1);
    if (querystring.indexOf("intranett=1") >= 0) return questionmark_or_ampersand + "intranett=1";
    if (querystring.indexOf("utskrift=1") >= 0) return questionmark_or_ampersand + "utskrift=1";
    return "";
}

function getAllNodeText(node) {
    var result = ""
    for (var i = 0; i < node.childNodes.length; i++) {
        result += getAllNodeText(node.childNodes[i]);
        var text = node.childNodes[i].nodeValue;
        if (text) {
            result += node.childNodes[i].nodeValue;
        }
    }
    return result;
}

function infoBar(settings) {
//Copyright (c) 2008 Lewis Linn White Jr.
//Author: Lewis Linn White Jr.

//Permission is hereby granted, free of charge, to any person
//obtaining a copy of this software and associated documentation
//files (the "Software"), to deal in the Software without
//restriction, including without limitation the rights to use,
//copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the
//Software is furnished to do so, subject to the following
//conditions:

//The above copyright notice and this permission notice shall be
//included in all copies or substantial portions of the Software.
//Except as contained in this notice, the name(s) of the above 
//copyright holders shall not be used in advertising or otherwise 
//to promote the sale, use or other dealings in this Software without 
//prior written authorization.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
//OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
//HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
//OTHER DEALINGS IN THE SOFTWARE.

    if(!document.createElement)
    {
        alert('Please get a newer release of the browser you are using!');
        return;
    }
     if(!settings)
     {
        settings = {};
     }
     var ie6 = (document.all && window.external && (typeof document.documentElement.style.maxHeight == 'undefined')) ? true : false; 
 
     var infoBarDiv = document.createElement('div');
     this.currentOpacity = 10;
     this.infoBar = infoBarDiv;
     infoBarDiv.style.backgroundColor = settings.backColor || '#fff68f';
     infoBarDiv.style.opacity = '1';
     infoBarDiv.style.filter = 'alpha(opacity=100)';
     infoBarDiv.style.fontSize = '8pt';
     infoBarDiv.style.top = '0px';
     infoBarDiv.style.left = '0px';
     infoBarDiv.style.lineHeight = '12px';
     infoBarDiv.style.padding = '0px';
     infoBarDiv.style.width = '100%';
     infoBarDiv.style.fontFamily = 'Verdana';
     infoBarDiv.style.fontColor = settings.fontColor || '#000000';
     infoBarDiv.style.position = (ie6) ? 'absolute' : 'fixed';
     infoBarDiv.style.display = 'none';
     infoBarDiv.style.border = '1px solid #000000';
     infoBarDiv.style.borderTop = '0px';
     infoBarDiv.style.borderLeft = '0px';
     infoBarDiv.style.borderRight = '0px';
     infoBarDiv.style.zIndex = 1500;
     if(ie6)
     {
        window.onscroll = function()
         {
             infoBarDiv.style.top = parseInt(window.pageYOffset || (document.documentElement.scrollTop || 0), 10) + 'px';
             infoBarDiv.style.left = parseInt(window.pageXOffset || (document.documentElement.scrollLeft || 0), 10) + 'px';
         };
     }

     var icon = document.createElement('img');
     this.infoBar.icon = icon;
     icon.src = 'images/' + (settings.icon || 'DlgWarning2') + '.png'; 
     icon.style.cssFloat = 'left';
     icon.style.styleFloat = 'left';
     icon.style.verticalAlign = 'middle';
     icon.style.paddingTop = '3px';
     icon.style.paddingLeft = '3px';
     icon.style.paddingRight = '3px';
     icon.style.paddingBottom = '3px';

     var download = document.createElement('img');
     download.src = 'images/goto.png';
     download.style.cssFloat = 'right';
     download.style.styleFloat = 'right';
     download.style.verticalAlign = 'middle';
     download.style.paddingTop = '3px';
     download.style.paddingBottom = '3px';
     download.style.paddingRight = '10px';
     download.style.cursor = 'pointer';
     download.onmouseover = function () { }
     download.onclick = function () {
         $.cookie("HideWarningBar", "hide");
         infoBarDiv.style.display = 'none';
         window.open('http://windows.microsoft.com/nb-NO/internet-explorer/products/ie/home');
     }

     var close = document.createElement('img');
     close.src = 'images/icon_button_close2.png';
     close.style.cssFloat = 'right';
     close.style.styleFloat = 'right';
     close.style.verticalAlign = 'middle';
    close.style.paddingTop = '3px';
    close.style.paddingBottom = '3px';
    download.style.paddingRight = '10px';
    close.style.cursor = 'pointer';
    close.onmouseover = function () { }
    close.onclick = function()
        {
            $.cookie("HideWarningBar", "hide");
            infoBarDiv.style.display = 'none';
        };

    var infoText = document.createElement('div');
    this.infoBar.infoText = infoText;
    infoText.innerHTML = settings.text || '';
    infoText.style.paddingTop = '3px';
    infoText.style.paddingBottom = '3px';

    infoBarDiv.appendChild(close);
    infoBarDiv.appendChild(download);
    infoBarDiv.appendChild(icon);
    infoBarDiv.appendChild(infoText);
        document.body.insertBefore(infoBarDiv, document.body.firstChild);
    }

    infoBar.prototype.show = function(fade)
    {
        var that = this;
        if(typeof fade == "number")
        {
            this.currentOpacity = 0;
            this.infoBar.style.opacity = '0';
            this.infoBar.style.filter = 'alpha(opacity=0)';
            this.intervalID = window.setInterval(function()
                    {
                        if(that.currentOpacity < 11)
                        {
                            that.infoBar.style.opacity = that.currentOpacity / 10;
                            that.infoBar.style.filter = 'alpha(opacity=' + that.currentOpacity * 10 + ')';
                            that.currentOpacity++;
                        }
                        else
                        {
                            window.clearInterval(that.intervalID);
                        }
                    }, fade);
            }
            else
            {
                this.infoBar.style.opacity = '1';
                this.infoBar.style.filter = 'alpha(opacity=100)';
            }
            this.infoBar.style.display = 'block';
    };

