var guiSiteLayout = {
	active:false,
	init:function() {
		guiSiteLayout.active = true;
		guiSiteEvents.add(window, "load", guiSiteLayout.start);
	},
	start:function() {
		guiSiteEvents.remove(window, "load", guiSiteLayout.start);
		if (guiSiteLayout.active) {
			var objId = document.getElementById("mainbox");
			if (typeof(objId) == "object" && objId != null && objId.tagName == "DIV") {
				objId.style.visibility = "visible";
				guiSiteLayout.autoresize();
				guiSiteEvents.add(window, "resize", guiSiteLayout.autoresize);
			} else {
				guiSiteLayout.active = false;
			}
		}
	},
	autoresize:function() {
		if (guiSiteLayout.active) {
			var guiId = guiSiteLayout;
			var sHeight = 0;
			var sWidth = 0;
			var xpos = 0;
			var ypos = 0;
			if (document.documentElement && document.documentElement.clientHeight) {
				sHeight = document.documentElement.clientHeight;
			} else {
				if (document.body && document.body.clientHeight) {
					sHeight = document.body.clientHeight;
				}
			}
			if (document.documentElement && document.documentElement.clientWidth) {
				sWidth = document.documentElement.clientWidth;
			} else {
				if (document.body && document.body.clientWidth) {
					sWidth = document.body.clientWidth;
				}
			}
			if (sHeight > 768) ypos = Math.round((sHeight - 768) / 2);
			if (sWidth > 1024) xpos = Math.round((sWidth - 1024) / 2);
			var conId = document.getElementById("mainbox");
			if (conId != undefined && typeof(conId) == "object") {
				conId.style.left = Number(xpos) + "px";
				conId.style.top = Number(ypos) + "px";
			}
		}
	}
}


var guiSiteEvents = {
	add:function(objId, iEvent, iFunc) {
		if (objId != undefined && iEvent != undefined && iFunc != undefined) {
			if (objId.addEventListener) {
				objId.addEventListener(iEvent, iFunc, false);
			} else {
				if (objId.attachEvent) {
					objId.attachEvent("on" + iEvent, iFunc);
				}
			}
		}
	},
	remove:function(objId, iEvent, iFunc) {
		if (objId != undefined && iEvent != undefined && iFunc != undefined) {
			if (objId.removeEventListener) {
				objId.removeEventListener(iEvent, iFunc, false);
			} else {
				if (objId.detachEvent) {
					objId.detachEvent("on" + iEvent, iFunc);
				}
			}
		}
	}
}


var guiAjaxObject = function() {
	var aModul = null;

	if (window.XMLHttpRequest && !(window.ActiveXObject)) {
		aModul = new XMLHttpRequest();
	}	else if (window.ActiveXObject) {
		var aVer = new Array("MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "MICROSOFT.XMLHTTP");
		for (var inx = 0; inx < aVer.length; inx++) {
			try {
				aModul = new ActiveXObject(aVer[inx]);
				break;
			} catch(e) {
				aModal = null;
			}
		}
	}

	this.ajaxModul = aModul;
	if (aModul == null) this.error = true
	else this.error = false;

	this.get = function(urlPath, fCallbackMethod) {
		var aModul = this.ajaxModul;
		if (aModul != undefined && aModul != null && typeof(aModul) == "object") {
			aModul.abort();
			aModul.open("GET", urlPath, true);
			aModul.onreadystatechange = fCallbackMethod;
			aModul.send(null);
		} else {
			throw new Error("XMLHTTP Ajax not supported!");
		}
	}

	this.post = function(urlPath, urlParm, fCallbackMethod) {
		var aModul = this.ajaxModul;
		if (aModul != undefined && aModul != null && typeof(aModul)) {
			aModul.abort();
			aModul.open("POST", urlPath, true);
			aModul.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			aModul.onreadystatechange = fCallbackMethod;
			aModul.send(urlParm);
		} else {
			throw new Error("XMLHTTP Ajax not supported!");
		}
	}

	this.abort = function() {
		var aModul = this.ajaxModul;
		if (aModul != undefined && aModul != null && typeof(aModul)) {
			aModul.abort();
		} else {
			throw new Error("XMLHTTP Ajax not supported!");
		}
	}

	this.runscripts = function(scripts) {
		try	{
			if (scripts != "") {
				var script = "";
				scripts = scripts.replace(/<script[^>]*>([\s\S]*?)<\/script>/gi, function(){ if (scripts !== null) script += arguments[1] + '\n'; return ""; });
				if (script) (window.execScript) ? window.execScript(script) : window.setTimeout(script, 0);
			}
			return false;
		}
		catch(e) {
			alert(e);
		}
	}
}


var urlTextBuilder = function(iParm, iName, iValue) {
	var iResult = "";
	var iText = "";
	if (iParm != undefined) {
		if (iName != undefined && iName != "" && iValue != undefined) {
			iValue = iValue.toString();
			for (var inx = 0; inx < iValue.length; inx++) {
				var iCode = encodeURI(iValue.charAt(inx));
				switch (iCode.toUpperCase()) {
					case "%C5%A0":
						iText += "%A9";
						break;
					case "%C4%90":
						iText += "%D0";
						break;
					case "%C4%8C":
						iText += "%C8";
						break;
					case "%C4%86":
						iText += "%C6";
						break;
					case "%C5%BD":
						iText += "%AE";
						break;
					case "%C5%A1":
						iText += "%B9";
						break;
					case "%C4%91":
						iText += "%F0";
						break;
					case "%C4%8D":
						iText += "%E8";
						break;
					case "%C4%87":
						iText += "%E6";
						break;
					case "%C5%BE":
						iText += "%BE";
						break;
					default:
						iText += iCode;
						break;
				}
			}
			if (String(iParm).length > 0) {
				iResult = iParm + "&" + iName + "=" + iText;
			} else {
				iResult = iName + "=" + iText;
			}
		} else {
			iResult = iParm;
		}
	}
	return iResult;
}


guiSiteLayout.init();
