﻿
// Finna hvaða vafra er verið að nota
var ns4 = (navigator.appName == 'Netscape' && parseInt(navigator.appVersion) == 4);
var ns6 = (document.getElementById)? true:false;
var ie4 = (document.all)? true:false;
if (ie4) var docRoot = 'document.body';
var ie5 = false;
if (ns4) {
	var oW = window.innerWidth;
	var oH = window.innerHeight;
	window.onresize = function () {if (oW!=window.innerWidth||oH!=window.innerHeight) location.reload();}
}

if (ie4) {
	if ((navigator.userAgent.indexOf('MSIE 5') > 0) || (navigator.userAgent.indexOf('MSIE 6') > 0)) {
		if(document.compatMode && document.compatMode == 'CSS1Compat') docRoot = 'document.documentElement';
		ie5 = true;
	}
	if (ns6) {
		ns6 = false;
	}
}


function formatCurrency(money) {
	var s = new String(Math.round(money).toString());
	var ns = '';
	for(i=0; i<s.length; i++) {
	    ns = s.charAt(s.length-i-1) + ns;
    	if( (i%3 == 2) && (i<s.length-1))
	    	ns = '.' + ns;
    }
	return ns;
}

function unFormatCurrency(money) {
	var ns = '';
	for(var i=0; i<money.length; i++) {
		var c = money.charAt(i);
		switch(c) {
			case "," :
				ns += ".";
				break;
			case "." :
				break;
			default :
				ns += c;
		}
	}
	var num = parseInt(ns,10);
	if(isNaN(num)) {
		num = 0;
	}
	return num;
}

function reformatCurrency(field) {
	var currency;
	currency = unFormatCurrency(field.value);
	field.value = formatCurrency(currency);
}

function isNumber(objEvent, blnAllowSpecial) {
	if (ie4) {
		if (objEvent.keyCode == 13) return objEvent.keyCode;

		if ( (blnAllowSpecial && ((objEvent.keyCode > 43 && objEvent.keyCode < 58) || (objEvent.keyCode > 0 && objEvent.keyCode < 31))) ||
		     (!blnAllowSpecial && (objEvent.keyCode > 47 && objEvent.keyCode < 58))) {
				return objEvent.keyCode;
		} else {
			return false;
		}
	} else {
		return true;
	}
}

