function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function GetElement(sElementName){
	var oElement;
	
	if(document.getElementById){
		oElement = document.getElementById(sElementName);
	}
	else if(document.all){
		oElement = document.all(sElementName);
	}
	else
		return null;
		
	return oElement;
}
function SetCssClass(sEl, sCss){
	var oEl = GetElement(sEl);
	if(oEl){
		oEl.className = sCss;
	}
}
function ToggleCssClass(sEl, sCss){
	var oEl = GetElement(sEl);
	if(oEl){
		if(oEl.className == sCss){
			oEl.className = "";
		}else{
			oEl.className = sCss;
		}
	}
}
function ShowHide(sElementName){
	var oElement = GetElement(sElementName);
	if(oElement){
		if(oElement.style.display == "none")
			oElement.style.display = "";
		else
			oElement.style.display = "none";		
	}
}

function ToggleValue(oEl, sCompareString){
	if(oEl){
		if(oEl.value == sCompareString)
			oEl.value = "";
		else if(oEl.value == "")
			oEl.value = sCompareString;
	}
}

var myKey;
function docOnKeypress(evt)
{
	var e = evt? evt : window.event;
	if(!e) return;
	var key = 0;
	if (e.keyCode) { myKey = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
	else if (typeof(e.which)!= 'undefined') { myKey = e.which; }
}

function formatitNumeric(svaedi){ 
	val=svaedi.value; 
	val=StripNonNumeric(val); 
	svaedi.value=val; 
}

function FormatNumber(pFld, pEvent, pKeyCode){
	if(myKey == 'undefined' || myKey == null){
		docOnKeypress(event);
	}
	if(myKey == 16 || myKey == 37 || myKey == 38 || myKey == 39 || myKey == 40 || myKey == 46 || myKey == 32){
		return true;
	}
	else{
		formatit(pFld, true);
		return true;
	}

}
function formatit(svaedi, keyPressed) 
{
	if(keyPressed){
		if(myKey == 'undefined' || myKey == null){
			docOnKeypress(event);
		}
		if(myKey == 16 || myKey == 37 || myKey == 38 || myKey == 39 || myKey == 40 || myKey == 46 || myKey == 32)
		{
			return;
		}
		//Verð að gera þetta af IE
		myKey = null;
	}
	val=svaedi.value; 
	val=StripNonNumeric(val); 
	svaedi.value=tdl(val); 	
} 

function tdl(str) { 
	sep=""; res=""; str=res+str; 
	while(str.length>0)	
	{ 
		if (str.length>3) 
		{ 
			res=str.substring(str.length-3,str.length)+sep+res; 
			str=str.substring(0,str.length-3); 
		} 	
		else 
		{  
			res=str+sep+res; str=""; 
		} 
		sep="."; 
	} 
	return res; 	
} 
function StripNonNumeric( str ){ 
	var resultStr = ""; 
	if (str+"" == "undefined" || str == null) 
		return null; str += ""; 
	for (var i=0; i < str.length; i++) 
	{ 
		if ( (str.charAt(i) >= "0") && (str.charAt(i) <= "9") ) 
			resultStr = resultStr + str.charAt(i);  	
	} 
	return resultStr; 
}

function MaxChars(oElement, nMaxChars)
{
	var lengd = 0;

		lengd = oElement.value.length;
		lengdLeft = nMaxChars - lengd;
		if(lengdLeft > nMaxChars)
		{
			lengdLeft = nMaxChars;
		}
		if(lengdLeft < 0)
		{
			lengdLeft = 0;
		}

	if (lengd > nMaxChars ){
		lengdLeft = 0;		
		oElement.value = oElement.value.substring(0,nMaxChars);
		return false;
	}
	return true;
	
}

function popUp(link, winWidth, winHeight) {

	
	if((winWidth == null) || (winWidth =="")) {
		winWidth = 250;
	}
	if((winHeight == null) || (winHeight =="")) {
		winHeight = 300;
	}
	
	var theSettings = "toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=" +winWidth+",height=" +winHeight+",left=0,top=0";	
	
	var theTarget = "_blank"; // Set default value for the link target	
	if ((link.target != null) && (link.target != "")) {
		theTarget = link.target;
	}
	
	newWin = window.open(link.href, theTarget, theSettings);
	newWin.focus(); // make sure the new window has focus.
	
	return false;
}


/* Pop up gluggi í miðju skjásins */
function PopUpCenter(link, winName, width, height){
	PopUpCenter(link, winName, width, height, null)
}
function PopUpCenter(link, winName, width, height, features){
	var top = screen.height/2 - height/2;
	var left = screen.width/2 - width/2;
	
	if(features == null){
		features = 'toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=' + width + ', height=' + height + ', top=' + top + ', left=' + left;
	}
	
	var newWin = window.open(link,winName, features);
	newWin.focus();
	
	return false;
}

/* Opnar pop up glugga í miðju skjásins með aðeins myndinni */
function PopUpPicture(winName, imageName, imageWidth, imageHeight, alt) {
	var top = screen.height/2 - imageHeight/2;
	var left = screen.width/2 - imageWidth/2;

	var newWindow = window.open("",winName,"width="+imageWidth+",height="+imageHeight+",scrollbars=no,left="+left+",top="+top);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+ alt +'</title><body style=\"margin:0;padding:0;\">'); 
	newWindow.document.write('<img src=\"'+imageName+'\" style=\"width:'+ imageWidth +'\;height:'+ imageHeight +'" alt=\"'+alt+'\" />'); 
	newWindow.document.write('</body></html>');
	newWindow.document.close();
	newWindow.focus();
}


/* Föll vegna reiknivélar óverðtryggt húsnæðislán */
function SetjaVexti(sElementName, prosenta)
{
	
	var oElement = GetElement(sElementName);
	
	if(oElement)
	{
		oElement.value = prosenta;
	}
}

function SetjaTexta(sElementName, texti)
{
	var oElement = GetElement(sElementName);
	
	if(oElement)
	{
		oElement.innerHTML = texti;
	}
}

function ReiknaAr(sElementName, afborganir, afborganirAri)
{
	var oElement = GetElement(sElementName);
	if(oElement)
	{
		oElement.innerHTML = "";
		if(!isNaN(afborganir) && !isNaN(afborganirAri))
		{
			var ar = afborganir / afborganirAri;
			if(!isNaN(ar))
			{
				var strAr = String(Math.floor(ar));
				strAr = strAr.replace(".",",");
				strAr = strAr + " ár";
				
				var strManudur = String(Math.round((ar - Math.floor(ar)) * 12));
				if(strManudur == "0")
				{
					oElement.innerHTML = strAr;
				}
				else
				{
					strManudur = strManudur + " mánuðir";
					oElement.innerHTML = strAr + " og " + strManudur;
				}	
			}
					
		}
	}	
}


function SetTableAltRows(){
	if(document.getElementById && document.createTextNode){
		var tables = document.getElementsByTagName("table");
		for(var i=0; i<tables.length; i++){
			var e = tables[i];
			var even = false;
			if(e.className == "List" || e.className == "List Vertical"){
				//zebra
				var tbodies = e.getElementsByTagName("tbody");
				
				for (var h = 0; h < tbodies.length; h++) {
					var trs = tbodies[h].getElementsByTagName("tr");
					for (var j = 0; j < trs.length; j++){
						trs[j].className = even ? "Alt" : "";
						even =  ! even;
					}
				}
				
				
				//hover & click
	/*						var tmpClassName;
				
				for(var k = 0; k<trs.length; k++)
				{
					if(trs[k].firstChild.tagName.toLowerCase()!="th")
					{
						trs[k].clicat = false;
						
						//mouseover
						trs[k].onmouseover = function()
						{	
							tmpClassName = this.className;
							this.className = "Over";
							return false;
						}
						
						//mouseout
						trs[k].onmouseout = function()
						{
							if(this.clicat == false)
							{									
								this.className = tmpClassName;
								return false;
							}
							else
							{
								//this.className = "Down";
								//return false;
							}
						}
						
						//mousedown
						trs[k].onmousedown = function()
						{
							if(this.className == "Down" || this.className == "DownAlt")
							{
								this.clicat = false;
								this.className = "Right";
							}
							else
							{
								//this.clicat = true;
								//this.className = "Down";
							}										
							
							return false;
						}
					}
				}
	*/						
			}
		}
	}
}

function hasClass(obj) 
{
var result = false;
if (obj.getAttributeNode("class") != null) 
{
	result = obj.getAttributeNode("class").value;
}
return result;
} 



/*	
DefaultButton
Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
// Extended by Darrell Norton - http://dotnetjunkies.com/weblog/darrell.norton/
//   -- added Mozilla support, fixed a few issues, improved performance
*/
function fnTrapKD(btnID, event){
btn = GetElement(btnID);
 if (document.all){
  if (event.keyCode == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.click();
  }
 }
 else if (document.getElementById){
  if (event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.focus();
   btn.click();
  }
 }
 else if(document.layers){
  if(event.which == 13){
   event.returnValue=false;
   event.cancel = true;
   btn.focus();
   btn.click();
  }
 }
}