function OpenBrInMiddle( theURL, winName, width, height , features) {
	var top = screen.height/2 - height/2;
	var left = screen.width/2 - width/2;
	window.open(theURL,winName, 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left +','+ features +'');
}

function statusbar(texti)
{
	window.defaultStatus = "";
	window.status = texti;
	return true;
}

var field_length = 0;
function TabNext(obj,event,len,next_field) 
{
var next_obj;
next_obj = GetElement(next_field);
	if (event == "down") 
	{
		field_length=obj.value.length;
	}
	else if (event == "up") 
	{
		if (obj.value.length != field_length) 
		{
			//obj.style.backgroundColor = "white";
			field_length=obj.value.length;
			if (field_length == len) 
			{	
				if( obj.m_erAutoTabVirkt == true )
				{
					next_obj.focus();
				}
			}

			else
			{
				obj.m_erAutoTabVirkt = true;
			}
		}
	}
}

function NBKSetFocus( controlToFocus, wait )
{
	//alert("inni i fallinu");
	var oControl;
	//alert("control to focus " + controlToFocus);
	oControl = GetElement( controlToFocus );
	//alert("control from getelement " + oControl);
	if(oControl != null)
	{
		//alert("oControl" + oControl);
		if(GetElement( controlToFocus ))
		{
			//alert("Fer ağ reyna ağ focusa!");
			oControl.focus();
		}
		else
		{
		/*	if(wait == null)
			{
				alert("Fer í timeout!");
				settimeout('NBKSetFocus(\'' + controlToFocus + '\', false)', 1000);
				//alert("Eftir set timeout, controlToFocus:" + controlToFocus);
			}*/
		}
	}
}

function MyOnfocus(obj,len)
{
	//obj.style.backgroundColor = "yellow";
	if( obj.m_erAutoTabVirkt )
	{
		obj.m_erAutoTabVirkt = ( len != obj.value.length );
	}
	else
	{
		obj.m_erAutoTabVirkt = true;
	}
}
function NBKPrentvaent( PrentvaentSectionName, PrentvaentPage, HasParameters )
{
 NBKPrentvaent( PrentvaentSectionName, PrentvaentPage, HasParameters, false );
}
function NBKPrentvaent( PrentvaentSectionName, PrentvaentPage, HasParameters, PrintNow)
{
	var oPrentVaentControl, sInnerText; 
	
	oPrentVaentControl = GetElement( PrentvaentSectionName ); 
	if(oPrentVaentControl)
	{
		sInnerText = oPrentVaentControl.innerHTML; 
		var height = 480;
		var width = 640;
		var top = screen.height/2 - height/2;
		var left = screen.width/2 - width/2;
		var prentGluggi;
		
		if(HasParameters == true){
			prentGluggi = window.open(PrentvaentPage + '&PrentvaentSectionName=' + PrentvaentSectionName,'HelpWindow', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=1,resizable=1' );
		}else{
			prentGluggi = window.open(PrentvaentPage + '?PrentvaentSectionName=' + PrentvaentSectionName,'HelpWindow', 'width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + ', scrollbars=1,resizable=1' );
		}
		
		if(prentGluggi)
		{
			if(PrintNow == true)
			{
				prentGluggi.print();
			}
        }
		
		if(prentGluggi.document)
		{
	          var obj;
		  try
		  {
		    if( prentGluggi.document.getElementById )
		    {
		      prentGluggi.focus();
		      obj = prentGluggi.document.getElementById( 'm_oPrentvaentBody' );
  		    }
		    else if( prentGluggi.document.all )
		    {
		      prentGluggi.focus();
		      obj = prentGluggi.document.all( 'm_oPrentvaentBody' );
	    	    }
		    else if( prentGluggi.document.layers )
		    {
		      prentGluggi.focus();
		      obj = prentGluggi.document.layers[ 'm_oPrentvaentBody' ];
		     }
	 	  }
		  catch(e)
		  {
		    alert('villa:' + e);
	 	  }
	 	}
	 	else
	 	{
	 	  alert('ekkert document');
	 	}
		if(obj)
		{
		  obj.innerHTML = sInnerText;
		  if(obj.parent)
		  {
			obj.parent.focus();
		  }		
		}
		else
		{
		}
		  
		
	}

}

function NBKFillSpecificBoxes(DataDelimterString, BoxDelimiterString, Delimiter)
{
 var iter, arrBox, arrData, oControl;
 arrBox = BoxDelimiterString.split(Delimiter);
 arrData = DataDelimterString.split(Delimiter);
 for(iter = 0; iter < arrBox.length; iter++)
 {
		oControl = GetElement( arrBox[iter] ); 
		oControl.value = arrData[iter];
 }
}

function NBKFillOneBox(boxname, data)
{
	var boxname;
	boxname = GetElement(boxname);
	boxname.value = data;
}

function NBKValidateNumericInput(args)
{
	if ((args.keyCode < 48) || (args.keyCode > 57)) 
		args.returnValue = false;
}

function NBKValidationSummaryOnSubmit() {
    if (typeof(Nbk_ValidationSummaries) == "undefined") 
        return;
    	var summary, sums, s, relatedcontrol;
    	for (sums = 0; sums < Nbk_ValidationSummaries.length; sums++) {
        summary = Nbk_ValidationSummaries[sums];
        relatedcontrol = GetElement( summary.relatedcontrolid );
        if( typeof(relatedcontrol) != "undefined" )
        {
        	relatedcontrol.style.display = "none";
        }
        else
        {
        	alert( "ELSE!" );
        }
        if (!Page_IsValid) {
            if (summary.showsummary != "False") {
                summary.style.display = "";
	        if( typeof(relatedcontrol) != "undefined" )
	        {
	        	relatedcontrol.style.display = "";
	        }
                if (typeof(summary.displaymode) != "string") {
                    summary.displaymode = "BulletList";
                }
                switch (summary.displaymode) {
                    case "List":
                        headerSep = "<br />";
                        first = "";
                        pre = "";
                        post = "<br />";
                        endir = "";
                        break;
                    case "BulletList":
                    default: 
                        headerSep = "";
                        first = "<ul>";
                        pre = "<li>";
                        post = "</li>";
                        endir = "</ul>";
                        break;
                    case "SingleParagraph":
                        headerSep = " ";
                        first = "";
                        pre = "";
                        post = " ";
                        endir = "<br />";
                        break;
                }
                s = "";
                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + headerSep;
                }
                s += first;
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        s += pre + Page_Validators[i].errormessage + post;
                    }
                }   
                s += endir;
                summary.innerHTML = s; 
                window.scrollTo(0,0);
            }
            if (summary.showmessagebox == "True") {
                s = "";
                if (typeof(summary.headertext) == "string") {
                    s += summary.headertext + "<BR>";
                }
                for (i=0; i<Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid && typeof(Page_Validators[i].errormessage) == "string") {
                        switch (summary.displaymode) {
                            case "List":
                                s += Page_Validators[i].errormessage + "<BR>";
                                break;
                            case "BulletList":
                            default: 
                                s += "  - " + Page_Validators[i].errormessage + "<BR>";
                                break;
                            case "SingleParagraph":
                                s += Page_Validators[i].errormessage + " ";
                                break;
                        }
                    }
                }
                span = document.createElement("SPAN");
                span.innerHTML = s;
                s = span.innerText;
                alert(s);
            }
        }
    }
}
function GetElement( nafn )
{
	var obj;
		if( !nafn )
		{
			return false;
		}
	  if( document.getElementById )
	  {
	    obj = document.getElementById( nafn );
	  }
	  else if( document.all )
	  {
	    obj = document.all( nafn );
	  }
	  else if( document.layers )
	  {
	    obj = document.layers[ nafn ];
	  }
	  if(obj)
			return obj;
		else
			return false;
}

function GetParentElement( nafn, gluggi )
{
	var obj;
	if( gluggi )
	{
		if( gluggi.opener.document.getElementById )
		{
			obj = gluggi.opener.document.getElementById( nafn );
		}
		else if( gluggi.opener.document.all )
		{
			obj = gluggi.opener.document.all( nafn );
		}
		else if( this.opener.document.layers )
		{
			obj = gluggi.opener.document.layers[ nafn ];
		}
	}
	return obj;
}

function fixSizes() {
  if (document.layers == null)
  {
    var pxContent 
    var pxLeft
    pxContent = document.getElementById("CenterContent").offsetHeight;
    pxLeft = document.getElementById("Left").offsetHeight;
    if(pxContent < pxLeft) { document.getElementById("CenterSpace").style.height = pxLeft + 10 + "px"; }
  }
}

		function SizeOMatic() {
			
			var hLeft = 0;
			var hRight = 0;
			var hCenter = 0;
			hLeft = document.getElementById('Left').offsetHeight;
			if(document.getElementById('Right')){
			hRight = document.getElementById('Right').offsetHeight;
			}
			hCenter = document.getElementById('Content').offsetHeight;
			var hFixer = ((hLeft > hRight) ? hLeft : hRight);
			
			hCenter = (hFixer > hCenter) ? hFixer : hCenter;
			document.getElementById('CenterContent').style.height = hCenter + "px";
		}      

      /* FontZoom Functions Begin */
      function setCookie (name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; " : "") + ((secure) ? "; secure" : "");
        document.cookie = curCookie;
      }
      
      function getFontCookie (fontSize) {
        var prefix = 'fontSize=';
        var c = document.cookie;
        var cookieStartIndex = c.indexOf(prefix);
        if (cookieStartIndex == -1)
          return 12;
        var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
        if (cookieEndIndex == -1)
          cookieEndIndex = c.length;
        return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
      }
      
      function setFontCookie(newSize)
      {
        var now = new Date();
        var base = new Date(0);
        var skew = base.getTime();
        if (skew > 0) { now.setTime(now.getTime() - skew); }
        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
        setCookie('fontSize', newSize, now, '/', document.location.host, '');
      }

      function zoom_in()
      {
        if (parseInt(currentFontSize) < 30)
        {
        setFontCookie(parseInt(currentFontSize) + 5);
        document.location.href = document.location.href;
        }
      }
      
      function zoom_out()
      {
        if (parseInt(currentFontSize) > 12)
        {
          setFontCookie(parseInt(currentFontSize) - 5);
          document.location.href = document.location.href;
        }
        return;
      }
      /* FontZoom Functions End */      
      /* Scroll Position Functions Begin */
			function SetScrollPos(iPos){
				if(iPos > 0){
					/*
						Sma browser fix herna, fyrst ad reyna nota document.body
						athuga ta hvort scrollTop hafi breyst, ef ekki ta nota eg document.documentElement
						turfti ad gera tetta utaf Safari 10 build85, hann for i koku ef eg notadi documentElement
					*/
					document.body.scrollTop = iPos;
					if(!document.body.scrollTop > 0){
						document.documentElement.scrollTop = iPos;
					}
				}
			}
			
			function SetScrollPosLeft(iPos){
				if(iPos > 0){
					/*
						Sma browser fix herna, fyrst ad reyna nota document.body
						athuga ta hvort scrollLeft hafi breyst, ef ekki ta nota eg document.documentElement
						turfti ad gera tetta utaf Safari 10 build85, hann for i koku ef eg notadi documentElement
					*/
					document.body.scrollLeft = iPos;
					if(!document.body.scrollLeft > 0){
						document.documentElement.scrollLeft = iPos;
					}
				}
			}
			
			function LoadScroller() {
				window.onscroll = Scroller;
			}
			function Scroller() {
				if(document.documentElement.scrollTop){
					document.forms[0].__SCROLLPOS.value = document.documentElement.scrollTop;
				}
				else if(document.body.scrollTop){
					document.forms[0].__SCROLLPOS.value = document.body.scrollTop;
				}
				
				if(document.documentElement.scrollLeft){
					document.forms[0].__SCROLLPOSLEFT.value = document.documentElement.scrollLeft;
				}
				else if(document.body.scrollLeft){
					document.forms[0].__SCROLLPOSLEFT.value = document.body.scrollLeft;
				}
			}
			/* Scroll Position Functions End */



// toggleElementDisplay() felur eda synir element (oftast <table>) og togglar iconinu imgID a milli imgA og imgB. Parametrar eru şessir:
// eID  		: element id sem á ağ syna eğa fela. Einu sinni vard ad vera style="display:block" a thessu element-i, en thegar kom ad 
//				  thvi ad fela <tr> i Firefox, for allt i stoppu. Tekid af http://www.snook.ca/archives/000343.php:
//				  When using the DOM to dynamically hide and show table elements (like a table row), you can't use display:block to bring 
//				  a table row back to life in Firefox; although, it works okay in IE. It's best to simply use display:"" so that Firefox 
//				  correctly resets it to 'table-row' and IE can still do what it does.
//
//				  Function-in getur hondlad array af hlutum til ad fela / syna, og er array-id sent inn sem eID og delimiterad med kommu (,)
// imgID		: id iconsins sem a ad skipta um thegar buid er ad toggla displayinu a eID
// imgA 		: source-id ad iconinu eins og thad er i sinni "edlilegu" (frumstilltu) stodu
// imgB 		: source-id ad iconinu sem a ad skipta ut eftir toggle
// toggleState	: segir til um ağ state-iğ á toggle EIGI ağ vera opiğ (1) eğa lokağ (0)
function toggleElementDisplay(eID, imgID, imgA, imgB, toggleState) 
{
	var eArray = new Array();
	
	if (eID.indexOf(",") > 0)
	{
		eArray = eID.split(",");
	}
	else
	{
		eArray = [eID];
	}
	
	for (n = 0; n < eArray.length; n++)
	{
		var elemToToggle = GetElement(eArray[n]);
		//debug info
		// alert("umferd:"+n+"\n\neID:"+eArray[n]+"\nimgID:"+imgID+"\nimgA:"+imgA+"\nimgB:"+imgB+"\ntoggleState:"+toggleState+"\n\nelemToToggle:"+elemToToggle);	
		if (elemToToggle != null)
		{
			try 
			{
				if( toggleState != null )
				{
					elemToToggle.style.display = toggleState == 1 ? "" : "none";
				}
				else
				{
					elemToToggle.style.display = elemToToggle.style.display == "" ? "none" : "";
				}
			}
			catch(err)
			{
				// Ekkert í catch
			}
		}
	}
	
	if (imgID != "" && imgA != "" && imgB != "")
	{
		imgToToggle = GetElement(imgID);
		if (imgToToggle != null)
		{
			try	{
				// Sma galdrar her: borid er saman .src-id a iconinu vid baedi .src-in sem send eru sem parametrar. Vandamalid er ad .src-parameterinn er sendur 
				// inn sem "/img/common/...", en thegar bedid er um .src af myndinni sem er i HTML-skjalinu faum vid slod sem byrjar a "http://...". Thvi verdum 
				// vid ad bera saman thessi tvo .src-gildi med substring, byrja aftan fra og bera saman eins langt og styttri strengurinn er. Svoldid flokid ordalag..
				if( toggleState != null )
				{
					imgToToggle.src = toggleState == 1 ? imgA : imgB;
				}
				else
				{
					if (imgToToggle.src.substring(imgToToggle.src.length-imgA.length, imgToToggle.src.length) == imgA)
					{
						imgToToggle.src = imgB;
					} else if (imgToToggle.src.substring(imgToToggle.src.length-imgB.length, imgToToggle.src.length) == imgB) {
						imgToToggle.src = imgA;
					}
				}
			}
			catch(err) {
				// Ekkert í catch
			}	
		}
	}
}

// Hér hefjast stefjur og breytur fyrir birtingu skilaboğaglugga. Allar stefjur sem şessu tengjast hafa forskeytiğ "skilabod".
var msgFjoldi = 0;
var msgShown = 0;
var msgFela = 1;	

function skilabodFela(bOverride) 
{
	if (msgFela || bOverride)
	{
		GetElement("divSkilabodTilkynning").style.display = "none";
	}
}

function skilabodBirta(nEndTop) 
{
	oDiv = GetElement("divSkilabodTilkynning"); // Finnum DIViğ sem á ağ nota
	nNaestaX = parseInt(oDiv.style.top) - 2;
	oDiv.style.top = nNaestaX + "px";
	if (nEndTop < parseInt(oDiv.style.top)) 
	{
		setTimeout("skilabodBirta(" + nEndTop +")", 16);
	} 
	else 
	{
		setTimeout("skilabodFela(0)", 15000);
	}
}

function skilabodFlettir(bDirection, strAf) 
{ 
	// Sá kóği sem fer í şessa línu mun ekki virka - don't ask me why.	
	msgFela = 0;
	if (bDirection && msgFjoldi > 1 && msgFjoldi > msgShown)
	{
		toggleElementDisplay('divSkilabod_' + msgShown, '', '', '');
		msgShown++;
		toggleElementDisplay('divSkilabod_' + msgShown, '', '', '');
		if (msgShown == msgFjoldi) {
			toggleElementDisplay("imgSkilabod_Naestu", "", "", "", 0); // Felum IMG frekar en DIV, şví ef viğ felum DIV şá færist allt hitt til hægri (breiddin helst ekki)
		}
		toggleElementDisplay("divSkilabod_Fyrri", "", "", "", 1);
	} 
	else if (!bDirection && msgFjoldi > 1 && msgShown > 1) 
	{ 
		toggleElementDisplay('divSkilabod_' + msgShown, '', '', '');
		msgShown--;
		toggleElementDisplay('divSkilabod_' + msgShown, '', '', '');
		if (msgShown == 1) {
			toggleElementDisplay("divSkilabod_Fyrri", "", "", "", 0);
		}
		toggleElementDisplay("imgSkilabod_Naestu", "", "", "", 1);
	}
	GetElement('divSkilabod_Index').innerHTML = msgShown + " " + strAf + " " + msgFjoldi;
}

function skilabodTilkynning(nMsgFjoldi, strNotandi) 
{
	if (getSkilabodCookie(strNotandi) != "1") 
	{
		/* Kökuhlutinn: */
		var newTime = new Date();
		var timeToKeep = 7200000; // 7200000 = 2 klst, 60000 = 1 mínúta
		newTime.setTime(newTime.getTime() + timeToKeep);
		// alert("Setjum koku sem rennur ut: " + newTime);
		setCookie('skilabodTilkynning_' + strNotandi, "1", newTime, '/', document.location.host, '');
		//alert("Kaka er nuna: " + getSkilabodCookie("skilabodTilkynning"));
		/* Kökuhluti endar */
		
		var oDiv = GetElement("divSkilabodTilkynning"); // Finnum DIViğ sem á ağ nota
		msgFjoldi = nMsgFjoldi;
		
		if (msgFjoldi == 1) {
			toggleElementDisplay("divSkilabod_Navigation", "", "", "", 0);
		}
		if( typeof( window.innerWidth ) == 'number' ) 
		{
			// Non-IE: Firefox [0.6, 1.0], Opera 7, Netscape 7.2, K-Meleon, 
			browseWidth = window.innerWidth;
			browseHeight = window.innerHeight;
		} 
		else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{
			//IE 6+ 'standards compliant': Fast Browser 5.1 
			browseWidth = document.documentElement.clientWidth;
			browseHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{
			//IE 4 compatible: IE [5.5, 5.01]
			browseWidth = document.body.clientWidth;
			browseHeight = document.body.clientHeight;
		}
			
		var nX = browseWidth - parseInt(oDiv.style.width) - 20;
		oDiv.style.left = nX + "px";
		oDiv.style.top = browseHeight + "px";
		
		endTop = browseHeight-135; // Finnum út endapunktinn (hvar şağ hættir ağ færast ofar)
		oDiv.style.display = "block";
		msgShown = 1; // Viğ erum ağ sına skilaboğ #1 (gerist alltaf fyrst)
		toggleElementDisplay('divSkilabod_' + msgShown, '', '', ''); // Sınum DIV-iğ
		toggleElementDisplay('divSkilabod_Fyrri', "", "", "", 0); // Felum "Fyrri"-takkann
		skilabodBirta(endTop);
	}
}



function getSkilabodCookie (strSuffix) {
	var prefix = 'skilabodTilkynning_' + strSuffix + "=";
	var c = document.cookie;
	var cookieStartIndex = c.indexOf(prefix);
	if (cookieStartIndex == -1) {return 0; }
	var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1) { cookieEndIndex = c.length; }
	return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}


