/* TOGGELRS */
function toggleWindowedControls(strVisibility) {
	//var controlArray = new Array('select', 'object', 'applet', 'embed');
	var controlArray = new Array('select', 'object', 'applet', 'embed');
	for (var g = 0; g < controlArray.length; g++) {
		var colControls = document.getElementsByTagName(controlArray[g]);
		for (var t = 0; t < colControls.length; t++) {
			colControls[t].style.visibility = strVisibility;
		}
	}
}

function toggleDisplay(strClientId) {
	var coll = document.getElementsByName(strClientId);
	if (coll.length == 0) {
		alert('Object (' + strClientId + ') was not found on the page!');
		return false;
	}
	for (var i = 0; i < coll.length; i++) {
		var theObj = coll[i];
		if (theObj.style.display == 'none') {
			theObj.style.display = '';
			theObj.style.visibility = 'visible';
		} else {
			theObj.style.display = 'none';
			theObj.style.visibility = 'hidden';
		}
	}
}

function togglePlus(strClient_Id) {
	var theImg = document.getElementById(strClient_Id);
	var a = theImg.src.split('_');
	if (a[a.length - 1].indexOf('plus') > 0) {
		theImg.src = '/images/shared/minus.gif';
	} else {
		theImg.src = '/images/shared/plus.gif';
	}
}

function toggleDisplayById(strClientId) {
	var theObj = getObj(strClientId);
	if (theObj.style.display == 'none') {
		theObj.style.display = 'inline';
	} else {
		theObj.style.display = 'none';
	}
}

function _toggleDisabled(chkBoxClientId, arrFieldsToDisable, blnClearValues) {
	if (document.getElementById(chkBoxClientId).checked) {
		for (var i = 0; i < arrFieldsToDisable.length; i++) {
			document.getElementById(arrFieldsToDisable[i]).disabled = false;
		}
	} else {
		for (var i = 0; i < arrFieldsToDisable.length; i++) {
			document.getElementById(arrFieldsToDisable[i]).disabled = true;
			if (blnClearValues) {
				document.getElementById(arrFieldsToDisable[i]).value = '';
			}
		}
	}
}

function toggleDisplay2(clientId, show) {
	if (show) {
		getObj(clientId).style.display = '';
		getObj(clientId).style.visibility = 'visible';
	} else {
		getObj(clientId).style.display = 'none';
		getObj(clientId).style.visibility = 'hidden';
	}
}

function toggleDisplayByName(clientName) {
	var elements = document.getElementsByName(clientName);
	for (i = 0; i < elements.length; i++) {
		if (elements[i].style.display == "none") {
			elements[i].style.display = "";
		} else {
			elements[i].style.display = "none";
		}
	}
}

/* SET CLIENT FOCUS */
var clientFocus = ''
var clientFocusMode = ''
function setFocus(strClientId, focusMode) {
	clientFocus = strClientId;
	clientFocusMode = (arguments[1]) ? arguments[1] : 'first';
	GBAttachEvent('onload', _runSetFocus);
}

function _runSetFocus() {
	if (!getObj(clientFocus))
		return;

	if (clientFocus != '') {
		getObj(clientFocus).focus();
		if (clientFocusMode == 'select')
			getObj(clientFocus).select();
		if (clientFocusMode == 'first')
			getObj(clientFocus).focus();
		if (clientFocusMode == 'end') {
			var range = getObj(clientFocus).createTextRange(); // Lav textrange
			range.move('sentence', 1);
			range.select(); // Flyt cursor
		}
	}
}

/* POSTBACKS */
allowWindowLeave = false;

function onbeforepostback() { return true; } // event
function onbeforeredirect() { return true; } // event

function _validatePostBack(strCommand) {
	var theValidatorObject;
	if (arguments[2]) { // a browser comp. hack
		theValidatorObject = eval(arguments[2]);
	} else {
		theValidatorObject = eval('cv');
	}
	theValidatorObject.validate()

	if (!theValidatorObject.isValid) {
		theValidatorObject.render();
	} else {
		(arguments[1]) ? _postBack(strCommand, arguments[1]) : _postBack(strCommand);
	}
}

function _confirmPostBack(strConfirm, strCommand) {
	if (confirm(strConfirm)) {
		(arguments[2]) ? _postBack(strCommand, arguments[2]) : _postBack(strCommand);
	}
}

function _postBack(strCommand) {
	allowWindowLeave = true;
	document.forms['frmPageForm'].command.value = strCommand;
	if (arguments[1]) {
		document.forms['frmPageForm'].commandValue.value = arguments[1];
	}
	if (onbeforepostback(strCommand, arguments[1])) {
		document.forms['frmPageForm'].submit();
	}
}

/* REDIRECT */
function _redirect(strUrl) {
	allowWindowLeave = true;
	if (onbeforeredirect(strUrl)) {
		self.location.href = strUrl;
	}
}

function _confirmRedirect(strConfirm, strUrl) {
	allowWindowLeave = true;
	if (confirm(strConfirm)) {
		_redirect(strUrl);
	}
}

/* PAGER FUNCTIONS */
function Pager() {
	this.PageSize;
	this.currPageSize = '';
}

Pager.prototype.ChangePageSize = function(obj) {
	var newPageSize = obj.options[obj.selectedIndex].value;
	if (this.PageSize == '') {
		var strUrl = document.location.href;
		var qs = (strUrl.indexOf('?') < 0) ? '?' : '&';
		self.location.href = document.location + qs + 'pagerPageSize=' + newPageSize;
	} else {
		var strUrl = document.location.href;
		myNewUrl = strUrl.replace('pagerPageSize=' + this.PageSize, 'pagerPageSize=' + newPageSize);
		self.location.href = myNewUrl;
	}
};

/* COOKIES */
function setCookie(sName, sValue) {
	var date = new Date();
	date.setDate(date.getDate() + 30);
	//alert('set:'+sValue)
	document.cookie = sName + '=' + escape(sValue) + '; expires=' + date.toGMTString() + '; path=/;';
}

function getCookie(sName) {
	// cookies are separated by semicolons
	var aCookie = document.cookie.split('; ');
	for (var i = 0; i < aCookie.length; i++) {
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split('=');
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	// a cookie with the requested name does not exist
	return null;
}

function deleteCookie(sName) {
	document.cookie = sName + "=''; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

/* HOVERS */
function hover(obj) { // used to swap image buttons
	obj.style.backgroundColor = '#7B2E00';
	var newSrc = obj.src.replace('_off.gif', '_on.gif');
	newSrc = newSrc.replace('_off.jpg', '_on.jpg');
	obj.src = newSrc;
}

function hover_noColor(obj) { // used to swap image buttons
	var newSrc = obj.src.replace('_off.gif', '_on.gif');
	newSrc = newSrc.replace('_off.jpg', '_on.jpg');
	obj.src = newSrc;
}

function dehover(obj) { // used to swap image buttons
	obj.style.backgroundColor = '';
	var newSrc = obj.src.replace('_on.gif', '_off.gif');
	newSrc = newSrc.replace('_on.jpg', '_off.jpg');
	obj.src = newSrc;
}

function hoverRow(obj) {
	for (var i = 0; i < obj.childNodes.length; i++) {
		obj.childNodes[i].style.color = '#7B2E00';
	}
}

function deHoverRow(obj) {
	for (var i = 0; i < obj.childNodes.length; i++) {
		obj.childNodes[i].style.color = '';
	}
}

function newsHover(guid) {
	document.getElementById('a1_' + guid).style.color = '#7B2E00';
	document.getElementById('a2_' + guid).style.color = '#7B2E00';
	hover(document.getElementById('a3_' + guid));
}

function newsDeHover(guid) {
	document.getElementById('a1_' + guid).style.color = '';
	document.getElementById('a2_' + guid).style.color = '';
	dehover(document.getElementById('a3_' + guid));
}

function buttonHover(obj) {
	obj.style.backgroundColor = '#7B3000';
}

function buttonDeHover(obj) {
	obj.style.backgroundColor = '';
}

function disabledButton(strId) {
	if (getObj(strId)) {
		var theObj = document.getElementById(strId);
		theObj.className = 'button disabled';
		theObj.disabled = true;
		buttonDeHover(theObj);
	}
}

function unDisableButton(strId) {
	if (document.getElementById(strId)) {
		var theObj = document.getElementById(strId);
		theObj.className = 'button';
		theObj.disabled = false;
	}
}

function rowHover(obj) {
	row = obj.parentNode
	for (var i = 0; row.childNodes[i]; i++) {
		td = row.childNodes[i]
		if (td.attributes) {
			switch (td.getAttribute("hover")) {
				case 'link':
					td.childNodes[0].style.color = '#7B3000';
					//td.childNodes[0].runtimeStyle.color = '#7B3000';
					//td.childNodes[0].runtimeStyle.textDecoration = 'underline';
					break;
				case 'image':
					hover(td.childNodes[0].childNodes[0]);
					break;
			}
		}
	}
}

function rowDehover(obj) {
	row = obj.parentNode
	for (var i = 0; row.childNodes[i]; i++) {
		td = row.childNodes[i]
		if (td.attributes) {
			switch (td.getAttribute("hover")) {
				case 'link':
					td.childNodes[0].style.color = ''
					//td.childNodes[0].runtimeStyle.color = '';
					//td.childNodes[0].runtimeStyle.textDecoration = '';
					break;
				case 'image':
					dehover(td.childNodes[0].childNodes[0])
					break;
			}
		}
	}
}


/* GOLFBOX PAGE */
function GolfBoxPage() {
	this.LCID = 1030;
	this.countryISOCode = 'DK';
}

GolfBoxPage.prototype.getDateDelimiter = function() {
	switch (this.LCID) {
		case 1031: return '.'; break;
		case 1030: return '-'; break;
		case 1044: return '.'; break;
		case 1053: return '-'; break;
		case 1035: return '.'; break;
		case 1061: return '.'; break;
		case 2052: return '-'; break;
		default: return '/'; break;
	}
}

GolfBoxPage.prototype.getCountryISOCode = function() {
	switch (this.LCID) {
		case 1031: return 'DE'; break;
		case 1030: return 'DK'; break;
		case 1044: return 'NO'; break;
		case 1053: return 'SE'; break;
		case 1035: return 'FI'; break;
		case 1061: return 'EE'; break;
		case 2052: return 'CN'; break;
		case 1033: return 'UK'; break;
		default: return 'DK'; break;
	}
}

GolfBoxPage.prototype.getField = function(strClientId) {
	if (document.getElementById) {
		return (document.getElementById(strClientId)) ? document.getElementById(strClientId).value : ''
	} else {
		return (document.all(strClientId)) ? document.all(strClientId).value : ''
	}
}

GolfBoxPage.prototype.getObject = function(strClientId) {
	if (document.getElementById) {
		return (document.getElementById(strClientId)) ? document.getElementById(strClientId) : null
	} else {
		return (document.all(strClientId)) ? document.all(strClientId) : null
	}
}

function IsNumeric(strString) {
	// check for valid numeric strings
	var strValidChars = '0123456789.-';
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	// test strString consists of valid characters listed above
	for (var i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

/* OBJECT EXTENSIONS */
Array.prototype.exists = function(value, objectProperty_1, objectProperty_2) { // kaldes theArray.exists(value)
	for (var intLoop = 0; intLoop < this.length; intLoop++) {

		var compareVal_1
		var compareVal_2

		if (typeof (this[intLoop]) == 'object') {
			compareVal_1 = (objectProperty_1) ? eval('this[intLoop].' + objectProperty_1) : this[intLoop]
		} else {
			compareVal_1 = this[intLoop]
		}

		if (typeof (value) == 'object') {
			compareVal_2 = (objectProperty_2) ? eval('value.' + objectProperty_2) : value
		} else {
			compareVal_2 = value
		}

		//alert(compareVal_1 +'=='+ compareVal_2)
		if (compareVal_1 == compareVal_2) {
			this.onExist(intLoop);
			return true;
		}
	}
	return false;
}

function IsNumeric(strString)
//  check for valid numeric strings
{
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}


Array.prototype.onExist = function() { }

Array.prototype.add = function(value) {
	this[this.length] = value; return this[this.length - 1]
}

Array.prototype.addKey = function(key, value) {
	this[key] = value; return this[key]
}

Array.prototype.remove = function(value) {
	for (var ii = 0; ii < this.length; ii++) {
		if (this[ii] == value) {
			val = this[ii]
			this.splice(ii, 1);
			return val
		}
	}
}

Date.prototype.clone = function() {
	var tdate = new Date(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds())
	return tdate
}

Date.prototype.dateDiff = function(start, end, interval, rounding) {

	var iOut = 0;

	var bufferA = Date.parse(start);
	var bufferB = Date.parse(end);

	// check that the start parameter is a valid Date.
	if (isNaN(bufferA) || isNaN(bufferB)) {
		return null;
	}

	// check that an interval parameter was not numeric.
	if (interval.charAt == 'undefined') {
		// the user specified an incorrect interval, handle the error.
		return null;
	}

	var number = bufferB - bufferA;

	// what kind of add to do?
	switch (interval.charAt(0)) {
		case 'd': case 'D':
			iOut = parseInt(number / 86400000);
			if (rounding) iOut += parseInt((number % 86400000) / 43200001);
			break;
		case 'h': case 'H':
			iOut = parseInt(number / 3600000);
			if (rounding) iOut += parseInt((number % 3600000) / 1800001);
			break;
		case 'n': case 'N':
			iOut = parseInt(number / 60000);
			if (rounding) iOut += parseInt((number % 60000) / 30001);
			break;
		case 's': case 'S':
			iOut = parseInt(number / 1000);
			if (rounding) iOut += parseInt((number % 1000) / 501);
			break;
		default:

			return null;
	}

	return iOut;
}

String.prototype.isOneOf = function() {

	/*
	example:
	myVal = 'teststring'
	alert(myVal.isOneOf('teststring1','teststring2')) // returns false
	alert(myVal.isOneOf('teststring1','teststring2','teststring')) // returns true
	*/

	// check base type
	base_type = typeof (this).toString()
	if (base_type != 'string') {
		alert('Invalid base type for string.isOneOf() - Only strings are allowed as base types.');
		return false;
	}

	// check to if this eaquels one of the provided argument values.
	for (var iArguments = 0; iArguments < arguments.length; iArguments++) {
		arg = arguments[iArguments]
		arg_type = typeof (arg)
		if (arg_type == 'string') { // test string
			if (this.toLowerCase() == arg.toLowerCase()) {
				return true;
			}
		}
		if (arg_type == 'number') { // test numeric
			if (this == arg) {
				return true;
			}
		}
	}; return false;
}


String.prototype.trim = function() {
	// Use a regular expression to replace leading and trailing
	// spaces with the empty string
	return this.replace(/(^\s*)|(\s*$)/g, '');
}

String.prototype.format = function() {
	var str = this;
	for (var i = 0; i < arguments.length; i++) {
		var re = new RegExp('\\{' + (i) + '\\}', 'gm');
		str = str.replace(re, arguments[i]);
	}
	return str;
}

String.format = function() {
	if (arguments.length == 0)
		return null;
	var str = arguments[0];
	for (var i = 1; i < arguments.length; i++) {
		var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
		str = str.replace(re, arguments[i]);
	}
	return str;
}

/* SELECT LIST */
function fillSelectList(strClient_ID, arrDataSource, arrFilterArray) {
	objSelectList = document.getElementById(strClient_ID)
	objSelectList.options.length = 0

	useFilter = (arrFilterArray && arrFilterArray.length > 0) ? true : false

	for (var g = 0; g < arrDataSource.length; g++) {
		theOP = document.createElement('option')
		theOP.text = arrDataSource[g].Text
		theOP.value = arrDataSource[g].Value
		theOP.className = arrDataSource[g].className
		//	alert(theOP.className)

		if (useFilter) {
			if (!arrFilterArray.exists(arrDataSource[g].Value)) { objSelectList.options.add(theOP) }
		} else {
			objSelectList.options.add(theOP)
		}
	}

}

function optionItem(strText, strValue, strClassName) {
	this.Value = strValue;
	this.Text = strText;
	this.className = strClassName;
}

/* EVENT HANDLER */
var cmdButton = ""
var cmdButtonDisabled = false
function setCMDButton(btn) {
	cmdButton = btn
}

function doButtonCmd(evt) {
	//IE browsers don't pass the event object as an argument, so get them from the window object
	if (!evt)
		var evt = window.event;
	if (evt.keyCode) { //on IE use keycode
		var code = evt.keyCode;
	}
	else if (evt.which) { //on mozilla use wich
		var code = evt.which;
	}

	var event_element = evt.target ? evt.target : evt.srcElement;

	if (code == 116) { allowWindowLeave = true };
	if (cmdButtonDisabled) { return true }
	if (cmdButton == 'NONE') { return true }

	if ((code == 13 || (code == 78 && evt.altKey)) && event_element.tagName != "TEXTAREA" && event_element.tagName != "SELECT") { //ENTER eller ctrl+højrepil

		if (cmdButton == "") {
			if (document.getElementById("cmdSubmit")) {
				cmdButton = "cmdSubmit"
			}
		}

		if (document.getElementById(cmdButton)) {
			document.getElementById(cmdButton).click()
			cmdButton = ""

			if (window.event) {
				evt.returnValue = false
				evt.cancelBubble = true
			}
			else {
				evt.preventDefault();
				evt.stopPropagation();
			}

		} else { }
	} else if (code == 66 && evt.altKey) { //ctrl+venstrepil
		evt.returnValue = false
		evt.cancelBubble = true

		if (cmdButton == "") {
			if (document.getElementById("cmdCancel")) {
				cmdButton = "cmdCancel"
			}
		}

		if (document.getElementById(cmdButton)) {
			document.getElementById(cmdButton).click()
			cmdButton = ""
		} else { }
	}
}
//document.onkeydown = doButtonCmd



/* WINDOW HANDLERS */
var theOpenWin;
window.onfocus = test;

function test() {
	if (theOpenWin) setTimeout("if(!theOpenWin.closed) theOpenWin.focus();", 100);
}

function modalDialog(url, obj, height, width, scroll) {

	blnScroll = (arguments[4]) ? arguments[4] : 0

	if (navigator.appName == 'Netscape') {
		var winl = (screen.width - width) / 2;
		var wint = (screen.height - height) / 2;
		theOpenWin = window.open(url, 'exportWin', 'width=' + width + ',height=' + height + ',top=' + wint + ',left=' + winl + ',location=0,status=0,scrollbars=' + blnScroll, 'exportWin')

		if (theOpenWin) {
			theOpenWin.dialogArguments = obj
			theOpenWin.focus()
		} else {
			alert('Failed to open window')
		}
	} else {
		//window.showModalDialog(url, obj, 'dialogHeight:'+height+'px; dialogWidth:'+width+'px; help:no; resizeable:no; scroll:'+blnScroll+'; status:no;');
		window.showModalDialog(url, obj, 'dialogHeight:' + height + 'px; dialogWidth:' + width + 'px; help:no; resizeable:no; scroll:no; status:no;');
	}
}

var myWin;
function openWindow(url, name, width, height, scroll, status) {
	status = (arguments[5]) ? arguments[5] : 'no';
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	settings = 'height=' + height + ',width=' + width + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',toolbar=no,location=no,status=' + status + ',menubar=no,resizable=no,dependent=no';
	myWin = window.open(url, name, settings);
	if (parseInt(navigator.appVersion) >= 4 && myWin) { myWin.focus(); }
}
function XMLObject() {
	this.progId;
	this.error;
	this.xmlhttp = null;
	this.xmldom = null;
}

XMLObject.prototype.getHTTPObject = function() {
	if (this.xmlhttp === null) {
		try {
			// Mozilla
			this.xmlhttp = new XMLHttpRequest();
			this.progId = 'XMLHttpRequest()';
			return this.xmlhttp;
		}
		catch (e) {
			// IE
			var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
			for (var i = 0; i < progIds.length; i++) {
				try {
					this.xmlhttp = new ActiveXObject(progIds[i]);
					this.progId = progIds[i];
					return this.xmlhttp;
				}
				catch (ex) {
					this.error = ex;
				}
			}
		}
		return null;
	}
	else {
		return this.xmlhttp;
	}
};

XMLObject.prototype.request = function(path, options) {
	var _this = this;
	var url = path;
	var method = (options.method) ? options.method : 'post';
	var postBody = (options.postBody) ? options.postBody : '';
	var asynchronous = (typeof options.asynchronous === 'boolean') ? options.asynchronous : true;
	var contentType = (options.contentType) ? options.contentType : 'application/x-www-form-urlencoded';
	var encoding = (options.encoding) ? options.encoding : '';
	var onComplete = (options.onComplete) ? options.onComplete : null;

	if (method == 'get' && postBody != '')
		url += (this.url.indexOf('?') > -1 ? '&' : '?') + postBody;

	this.getHTTPObject();
	this.xmlhttp.open(method, url, asynchronous);
	this.xmlhttp.setRequestHeader('Content-Type', contentType + ((encoding) ? '; charset=' + encoding : ''));
	this.xmlhttp.setRequestHeader('Content-Length', postBody.length);
	this.xmlhttp.setRequestHeader('Connection', 'close');
	if (onComplete) {
		this.xmlhttp.onreadystatechange = function() {
			if (_this.StateOK())
				(onComplete)(_this.Text());
		}
	}
	this.xmlhttp.send((method == 'post') ? postBody : null);
};

XMLObject.prototype.get = function(file, async, statePointer) {
	this.request(file,
	{
		method: 'get',
		asynchronous: async,
		onComplete: statePointer
	});
}

XMLObject.prototype.send = function(file, postData, statePointer) {
	this.request(file,
	{
		method: 'post',
		postBody: postData,
		asynchronous: true,
		onComplete: statePointer
	});
};

XMLObject.prototype.StateOK = function() {
	return (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200);
};

XMLObject.prototype.Text = function() {
	return this.xmlhttp.responseText;
};

XMLObject.prototype.getDOMDocumentObject = function() {
	try {
		// Mozilla
		this.xmldom = new DOMParser();
		this.progId = 'DOMParser()';
	}
	catch (e) {
		// IE
		var progIds = ['Msxml2.DOMDocument.4.0', 'Msxml2.DOMDocument.3.0', 'Msxml2.DomDocument', 'Msxml2.DOMDocument.6.0', 'Msxml2.DOMDocument.5.0', 'Microsoft.DomDocument'];
		for (var i = 0; i < progIds.length; i++) {
			try {
				this.xmldom = new ActiveXObject(progIds[i]);
				this.progId = progIds[i];
				break;
			}
			catch (ex) {
				this.error = ex;
			}
		}
	}
	return this.xmldom;
}

function getPageXY(elm) {
	var point = { x: 0, y: 0 };
	while (elm) {
		point.x += elm.offsetLeft;
		point.y += elm.offsetTop;
		elm = elm.offsetParent;
	}
	return point;
}

function setPageXY(elm, x, y) {
	var parentXY = { x: 0, y: 0 };

	if (elm.offsetParent) {
		parentXY = getPageXY(elm.offsetParent);
	}

	elm.style.left = (x - parentXY.x) + 'px';
	elm.style.top = (y - parentXY.y) + 'px';
}

function getObject(strClientId) {
	if (document.getElementById) {
		return (document.getElementById(strClientId)) ? document.getElementById(strClientId) : null;
	} else {
		return (document.all(strClientId)) ? document.all(strClientId) : null;
	}
}

function getObj(strClientId) {
	return getObject(strClientId);
}

function GBParseInt(val) {
	return parseInt(val, 10)
}

function GBAttachEvent(sEvent, sPointer) {
	var event = '';
	switch (sEvent) {
		case 'onload':
			event = 'load';
			break;
		default:
			event = sEvent.replace('on', '');
			break;
	}
	GBElementAttachEvent((sEvent == 'onkeydown') ? document : window, event, sPointer);
}

function GBElementAttachEvent(element, eventName, handler) {
	var pointer = (typeof handler == 'function') ? handler : eval('' + handler);
	if (element.addEventListener)
		element.addEventListener(eventName, pointer, false);
	else
		element.attachEvent('on' + eventName, pointer);
}

function GBElementDetachEvent(element, eventName, handler) {
	var pointer = (typeof handler == 'function') ? handler : eval('' + handler);
	if (element.removeEventListener)
		element.removeEventListener(eventName, pointer, false);
	else
		element.detachEvent('on' + eventName, pointer);
}

function RegisterClientChange() {
	this.RegisterChanges = false;
	this._hasChanges = false;
}

RegisterClientChange.prototype.Register = function(obj) {
	if (!this.RegisterChanges) return;

	this._hasChanges = false; // reset the flag

	var _monitorFields = [];

	if (!_monitorFields.exists(obj.Name, 'Name')) _monitorFields.add(obj);
	_newValue = (obj.NewValue != null) ? obj.NewValue : getObj(obj.Name).value
	for (var iField = 0; iField < _monitorFields.length; iField++) {
		if (_monitorFields[iField].OrgValue != _newValue) {
			this._hasChanges = true;
		}
	}

	RegisterClientChange_OnChange(this._hasChanges);
}

RegisterClientChange.prototype.HasChanges = function() {
	return this._hasChanges
}

function fieldOjb(name, orgvalue, newvalue) {
	this.Name = name;
	this.OrgValue = orgvalue;
	this.NewValue = (newvalue != 'undefined') ? newvalue : null;
}

function RegisterClientChange_OnChange(hasChanges) { }

function preloadImages() {
	var d = document;
	if (d.images) {
		if (!d._p) d._p = new Array();
		var i, j = d._p.length, a = preloadImages.arguments;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf('#') != 0) {
				d._p[j] = new Image();
				d._p[j++].src = a[i];
			}
		}
	}
}

function getWindowSize() {
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == 'number') {
		// Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		// IE 6+
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		// IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	return [myWidth, myHeight];
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == 'number') {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	}
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX, scrOfY];
}

var plzWaitDiv;
function showPleaseWait(waitTxt) {
	plzWaitDiv = document.createElement('div');
	plzWaitDiv.style.filter = 'Alpha(Opacity=80)';
	plzWaitDiv.style.opacity = '0.8';
	plzWaitDiv.style.backgroundColor = 'white';

	plzWaitDiv.innerHTML = waitTxt;
	plzWaitDiv.style.textAlign = 'center';
	plzWaitDiv.style.paddingTop = '200px';
	plzWaitDiv.style.fontFamily = 'Verdana';
	plzWaitDiv.style.fontSize = '16pt';
	plzWaitDiv.style.position = 'absolute';
	plzWaitDiv.style.left = 0;
	plzWaitDiv.style.top = 0;
	plzWaitDiv.style.width = getWindowSize()[0];
	plzWaitDiv.style.height = getWindowSize()[1] + getScrollXY()[1];
	if (getObj('frmPageForm')) {
		var elementsArray = getObj('frmPageForm')
		for (suv = 0; suv < elementsArray.length; suv++) {
			if (elementsArray[suv].tagName == 'INPUT') {
				if (elementsArray[suv].type == 'button')
					disabledButton(elementsArray[suv].id);
			}
		}
	}

	toggleWindowedControls('hidden');
	document.body.appendChild(plzWaitDiv);
}

Object.toJSON = function(obj) {
	var results = [];
	switch (typeof obj) {
		case 'object':
			if (obj) {
				if (obj instanceof Array) {
					results.push('[');
					for (var i = 0; i < obj.length; i++) {
						if (i > 0)
							results.push(',');
						results.push(Object.toJSON(obj[i]));
					}
					results.push(']');
				}
				else {
					if (obj instanceof Date) {
						results.push('"\\/Date(', obj.getTime(), ')\\/"');
						break;
					}
					var properties = [];
					var propertyCount = 0;
					var needComma = false;
					for (var name in obj) {
						if (name.substr(0, 1) === '$')
							continue;
						properties[propertyCount++] = name;
					}
					results.push('{');
					for (var i = 0; i < propertyCount; i++) {
						var value = obj[properties[i]];
						if (typeof value !== 'undefined' && typeof value !== 'function') {
							if (needComma)
								results.push(',');
							else
								needComma = true;
							results.push(properties[i], ':', Object.toJSON(value));
						}
					}
					results.push('}');
				}
			}
			else
				results.push('null');
			break;
		case 'number':
			if (isFinite(obj))
				results.push(String(obj));
			else
				alert('Error: Cannot serialize non finite numbers.');
			break;
		case 'string':
			var regEx = new RegExp('["\b\f\n\r\t\\\\\x00-\x1F]', 'i');
			results.push('"');
			if (regEx.test(obj)) {
				for (var i = 0; i < obj.length; i++) {
					var curChar = obj.charAt(i);
					if (curChar >= ' ') {
						if (curChar === '\\' || curChar === '"')
							results.push('\\');
						results.push(curChar);
					}
					else {
						switch (curChar) {
							case '\b':
								results.push('\\b');
								break;
							case '\f':
								results.push('\\f');
								break;
							case '\n':
								results.push('\\n');
								break;
							case '\r':
								results.push('\\r');
								break;
							case '\t':
								results.push('\\t');
								break;
							default:
								results.push('\\u00');
								if (curChar.charCodeAt() < 16)
									results.push('0');
								results.push(curChar.charCodeAt().toString(16));
						}
					}
				}
			}
			else
				results.push(obj);
			results.push('"');
			break;
		case 'boolean':
			results.push(obj.toString());
			break;
		default:
			results.push('null');
			break;
	}
	return results.join('');
}

Object.fromJSON = function(data) {
	try {
		return eval('(' + data.replace(new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)\\)\\\\/\\"', 'g'), '$1new Date($2)') + ')');
	}
	catch (e) {
		alert('Error: The data does not correspond to valid JSON.');
	}
}

function getDimensions(element) {
	var display = element.style.display;
	if (display != 'none' && display != null) // Safari bug
		return { width: element.offsetWidth, height: element.offsetHeight };

	var els = element.style;
	var originalVisibility = els.visibility;
	var originalPosition = els.position;
	var originalDisplay = els.display;

	els.visibility = 'hidden';
	if (originalPosition != 'fixed') // Switching fixed to absolute causes issues in Safari
		els.position = 'absolute';
	els.display = 'block';

	var originalWidth = element.clientWidth;
	var originalHeight = element.clientHeight;

	els.display = originalDisplay;
	els.position = originalPosition;
	els.visibility = originalVisibility;

	return { width: originalWidth, height: originalHeight };
}

function zeroPad(num, count) {
	var numZeropad = num + '';
	while (numZeropad.length < count) {
		numZeropad = '0' + numZeropad;
	}
	return numZeropad;
}

GBAttachEvent('onkeydown', 'doButtonCmd')


function WebSite() {
}


WebSite.Exec = function(command) {
	switch (typeof (command)) {
		case 'string':
			if (command == '') { alert('Invalid command: Command value is empty.'); return; };
			try {
				eval(command)
			} catch (e) {
				alert('Invalid command: ' + e.message)
			}
			break;
		case 'function':
			command();
			break;
		default:
			alert('Invalid command: Command not recognized.');
	};
}


WebSite.UI = function() {
}

WebSite.UI.OnEnterClick = function() { }
WebSite.UI.OnEscClick = function() { }
WebSite.UI.AllowFormSubmit = function() { }

WebSite.UI.RegisterDefaultEvents = function() {
	ShortcutMan.registerShortcut('13', WebSite.UI.OnEnterClick); // ENTER
	ShortcutMan.registerShortcut('27', WebSite.UI.OnEscClick); // ESC
	ShortcutMan.registerShortcut('c81', WebSite.UI.OnEscClick); // CTRL+Q < FF does not allow redirects when catching ESC clicks
}