﻿function GetParam(name){
	var start=location.search.indexOf("?"+name+"=");
	if (start<0) start=location.search.indexOf("&"+name+"=");
	if (start<0) return '';
	start += name.length+2;
	var end=location.search.indexOf("&",start)-1;
	if (end<0) end=location.search.length;
	var result='';
	for(var i=start;i<=end;i++) {
		var c=location.search.charAt(i);
		result=result+(c=='+'?' ':c);
	}
	return unescape(result);
}
function checkform(){
	if(document.ExtUserForm.username.value.length <= 0){
		alert('Skriva brúkaranavn');
		document.ExtUserForm.username.focus();
		return false;
	}
	if(document.ExtUserForm.password.value.length <= 0){
		alert('Skriva loyniorð');
		document.ExtUserForm.password.focus();
		return false;
	}
	return true;
}
function getfocus(el){
  document.getElementById(el).focus();
}
function Left(str, n){
	if (n <= 0){ return "";}
	else if (n > String(str).length){ return str;}
	else { return String(str).substring(0,n);}
}
function Right(str, n){
    if (n <= 0) { return "";}
    else if (n > String(str).length) { return str;}
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/geral/utf-8 [v1.0]
UTF8 = {
    encode: function (s) {
        for (var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
        return s.join("");
    },
    decode: function (s) {
        for (var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
        return s.join("");
    },
    encodenordic: function (s) {
        //used for ajax result box from searching
        return encodeURIComponent(s);
    }
};
var closeTimer = null;
var timerRunning = false;
var mouseover = false;
var delayTimer = 2000;
var hasFocus = false;
function slideToggler(id, lia) {
    $("#" + lia).css("color", "e16f1a");
    $("#footer-menu-hover-overview").html($("#" + id).html());
    $("#footer-menu-hover").fadeIn('fast', function () { });
    clearTimeout(closeTimer);
}
function deactivateToggler(lia) {
    $("#" + lia).css("color", "ffffff");
    delayToggler(delayTimer);
}
function hideToggler() {
    $("#footer-menu-hover").fadeOut('fast', function () { });
    document.getElementById("footer-menu-hover-overview").innerHtml = '';
}
function delayToggler(delay) {
    if (mouseover) {
        if (timerRunning) {
            clearTimeout(closeTimer);
        }
    }
    else
    {
        closeTimer = setTimeout('hideToggler()', delay); // closeTimer holds the id of the timer
        timerRunning = true; // whenever you start a timer set the timerRunning flag to true
    }
}
function setMouseOver() {
    mouseover = true;
    if (timerRunning) {
        clearTimeout(closeTimer);
    }
}
function setMouseOut(newtimer) {
    if (!hasFocus) {
        mouseover = false;
        closeTimer = setTimeout('hideToggler()', newtimer); // closeTimer holds the id of the timer
        timerRunning = true; // whenever you start a timer set the timerRunning flag to true
    }
}
$(".parentnodes").mouseover(function () {
    mouseover = true;
    if (timerRunning) {
        clearTimeout(closeTimer);
    }
}).mouseout(function () {
    mouseover = false;
    closeTimer = setTimeout('hideToggler()', delayTimer); // closeTimer holds the id of the timer
    timerRunning = true; // whenever you start a timer set the timerRunning flag to true
});
$("footer-menu-hover-overview").mouseenter(function () {
    mouseover = true;
    if (timerRunning) {
        clearTimeout(closeTimer);
    }
}).mouseleave(function () {
    mouseover = false;
    closeTimer = setTimeout('hideToggler()', delayTimer); // closeTimer holds the id of the timer
    timerRunning = true; // whenever you start a timer set the timerRunning flag to true
});
