
function isIE () {

	var 	agent;
	var		version;

	agent = navigator.userAgent.toLowerCase ();
	version = parseInt (navigator.appVersion);

	if (agent.indexOf ("msie") != -1)
		return true;

	return false;
}


function isNS () {

	var 	agent;
	var		version;

	agent = navigator.userAgent.toLowerCase ();
	version = parseInt (navigator.appVersion);

	if (isSafari () || ((agent.indexOf ("mozilla") != -1 || agent.indexOf ("spoofer") != -1 || 
		agent.indexOf ("compatible") != -1) && agent.indexOf ("msie") == -1)) {

		return true;
		}

	return false;
}


function isMac () {

	var 	agent;

	agent = navigator.userAgent.toLowerCase ();
	
	if (agent.indexOf ("mac") != -1)
		return 1;

	return false;
}


function isSafari () {

	var 	agent = navigator.userAgent.toLowerCase ();

	if (agent.indexOf('safari') >= 0)
		return true;
	
	return false;
}

function isFireFox () {

	var 	agent = navigator.userAgent.toLowerCase ();

	if (agent.indexOf('firefox') >= 0)
		return true;
	
	return false;
}

function isMozillaClient () {

	// for now returns true is firefox or Safari
	
	var 	agent = navigator.userAgent.toLowerCase ();

	if (agent.indexOf('firefox') >= 0 || agent.indexOf('safari') >= 0)
		return true;
	
	return false;
	
	
}

function isWindows () {

	var 	agent;

	agent = navigator.userAgent.toLowerCase ();

	if (agent.indexOf ("windows") != -1)
		return true;

	return false;
}
	

var		showErrors = true;

function handleKeyDown (e) {

	var 	key;
	var		evt = e;
	
	if (isIE())
		evt = event;
		
	key = evt.keyCode;

	if (key == 13) {	// enter key
		showErrors = false;
		handleReturn (e);
	}

	if (key == 38 /*&& evt.ctrlKey*/) {	// arrow up
		showErrors = false;
		handleArrowUp ();
	}

	if (key == 40 /*&& evt.ctrlKey*/) {	// arrow down
		showErrors = false;
		handleArrowDown ();
	}

}


function handleError (msg, url, line) {

	if (showErrors)
		return false;

	showErrors = true;	// only skip one error!
	
	return true;
}

/**
 * Retrieves the absolute position of element in window.
 * Returns Array object with 2 number entries: Left Position, Top Position (Index 0,1)
 * @param {Object} elem
 */
function getPosition(elem) {
	var curTop = 0;
	var curLeft = 0; 
	if (elem.offsetParent) {
		curLeft = elem.offsetLeft;
		curTop = elem.offsetTop;
		while (elem = elem.offsetParent) {
			curLeft += elem.offsetLeft;
			curTop += elem.offsetTop;
		}
	}
	return [curLeft,curTop];
}

	
document.onkeydown = handleKeyDown;
window.onerror = handleError;

	