	var mainFunction = {
			currentBrowser : "",
			currentBrowserVersion : "",
			fullHttp : null,
			baseMap : null,
			baseImg : null,
			baseAdmImg : null,
			sesDefMap : null,
			sesDefLonlat : null,
			sesDefXY : null,
			sesCustomPos : null,
			firstLevel : null
	};

	function strTrim(AStr) {
		return AStr.replace(/^\s+/,"").replace(/\s+$/,"");
	}
	
	function clearAjaxInstance(queueName, clearAll) {
		$.manageAjax.clear(queueName, clearAll);
	}
	
	function createAjaxInstance(options) {
		var dd = new Date();
		var queueName = (options.genUniqueName != undefined && options.genUniqueName ?
							options.queueName + dd.getDate() + dd.getMonth() + dd.getFullYear() +
							dd.getHours() + dd.getMinutes() + dd.getSeconds() + dd.getMilliseconds() +
							(Math.random() * 5 + 1) : options.queueName
		);
		var queue = (options.queue != undefined ? options.queue : true);
		var abortOld = (options.abortOld != undefined ? options.abortOld : false);
		var preventDoubbleRequests = (options.preventDoubbleRequests != undefined ?
									  options.preventDoubbleRequests : false);
		var cacheResponse = (options.cacheResponse != undefined ? options.cacheResponse : false);
		
		$.manageAjax.create(queueName, {
			queue: queue,
			abortOld: abortOld,
			preventDoubbleRequests: preventDoubbleRequests,
			cacheResponse: cacheResponse
		});
		
		return queueName;
	}
	
	function setAjaxInstance(options) {
		var type = (options.type != undefined ? options.type : "POST");
		var dataType = (options.dataType != undefined ? options.dataType : "xml");
		var cache = (options.cache != undefined ? options.cache : false);
		
		$.manageAjax.add(options.queueName, {
			type : type,
			url : options.url,
			data : options.data,
			dataType : dataType,
			cache : cache,
			error : options.error,
			success : options.success
		});
	}
	
	
	function getHttpObject() {
			var req = null;
			
			if (window.XMLHttpRequest) req = new XMLHttpRequest();
			else {
					try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
					catch(e) {
							try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
							catch(e) { req = null; }
					}
			}
								
			return req;
	}
	
	function ajaxClass() {
		this.xmlHttp = null;
		
		this.runAjax = function(method, uri, postUrl, callback) {
			if (isNotError(this.xmlHttp)) {
				this.xmlHttp.onreadystatechange = callback;
				this.xmlHttp.open(method, uri, true);
				
				if (method == "POST") {
					this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
					this.xmlHttp.setRequestHeader("Content-length", postUrl.length);
					this.xmlHttp.send(postUrl);
				} else this.xmlHttp.send(null);
			}
		};
		
		this.getHttpObject = function() {
			if (window.XMLHttpRequest) this.xmlHttp = new XMLHttpRequest();
			else {
					try { this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
					catch(e) {
							try { this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
							catch(e) { this.xmlHttp = null; }
					}
			}
			
			return isNotError(this.xmlHttp);
		};
		
		this.getObject = function() {
			return this.xmlHttp;
		};
		
		this.abortProcess = function() {
			try {
				this.xmlHttp.onreadystatechange = function(){};
				this.xmlHttp.abort();
			} catch(e) {}
		};
		
		isNotError = function(xmlHttp) {
			if (xmlHttp == null) {
				alert("Your browser doesn't support AJAX / HTTP Request,\nplease re-install with new browser ...");
				return false;
			}
			
			return true;
		};
	}
	
	function buildPagingLinks(isObjArray, rootPaging, myFunction, options) {
		//format the Paging
		var tempFunc;
		if (isObjArray) {
			var firstPaging = rootPaging[0];
			var prevPaging = rootPaging[1];
			var firstSeparator = rootPaging[2];
			var leftPaging = rootPaging[3];
			var midPaging = rootPaging[4];
			var rightPaging = rootPaging[5];
			var lastSeparator = rootPaging[6];
			var nextPaging = rootPaging[7];
			var lastPaging = rootPaging[8];
		} else {
			var firstPaging = rootPaging.attr('first');
			var prevPaging = rootPaging.attr('prev');
			var firstSeparator = rootPaging.attr('firstseparator');
			var leftPaging = rootPaging.attr('leftpage');
			var midPaging = rootPaging.attr('middlepage');
			var rightPaging = rootPaging.attr('rightpage');
			var lastSeparator = rootPaging.attr('lastseparator');
			var nextPaging = rootPaging.attr('next');
			var lastPaging = rootPaging.attr('last');
		}
		
		var linkClass = (options != undefined && options.linkClass != undefined ? "class=\"" + options.linkClass + "\"" : "");
		var cAlign = (options != undefined && options.align != undefined ? options.align : "left");
		var cVAlign = (options != undefined && options.vAlign != undefined ? options.vAlign : "top");
		var paddingTop = (options != undefined && options.paddingTop != undefined ? options.paddingTop : "0") + "px;";
		var paddingLeft = (options != undefined && options.paddingLeft != undefined ? options.paddingLeft : "0") + "px;";
		var paddingBottom = (options != undefined && options.paddingBottom != undefined ? options.paddingBottom : "0") + "px;";
		var paddingRight = (options != undefined && options.paddingRight != undefined ? options.paddingRight : "0") + "px;";
		var firstText = (options != undefined && options.firstText != undefined ? options.firstText : "First");
		var prevText = (options != undefined && options.prevText != undefined ? options.prevText : "Previous");
		var nextText = (options != undefined && options.nextText != undefined ? options.nextText : "Next");
		var lastText = (options != undefined && options.lastText != undefined ? options.lastText : "Last");
		
		firstSeparator = (firstSeparator == "" ? "" : firstSeparator + "&nbsp;");
		
		if (leftPaging != "") {
				var leftPagingTemp = leftPaging.split(";");
				leftPaging = "";
				
				for (var i=0; i < leftPagingTemp.length; i++) {
						if (leftPagingTemp[i] != "" && leftPagingTemp[i] != " ") {
							tempFunc = myFunction;
							tempFunc = tempFunc.replace(/xxxx/, (parseInt(leftPagingTemp[i]) - 1));
							leftPaging += "<a " + linkClass + " href=\"" + tempFunc + "\">" + leftPagingTemp[i] + "</a>&nbsp;&nbsp;";
						}
				} //end for
		}
		
		if (options != undefined && options.midUnderline != undefined && options.midUnderline) midPaging = "<u>" + midPaging + "</u>";
		midPaging += "&nbsp;";
		
		if (rightPaging != "") {
				var rightPagingTemp = rightPaging.split(";");
				rightPaging = "";
				
				for (var i=0; i < rightPagingTemp.length; i++) {
						if (rightPagingTemp[i] != "" && rightPagingTemp[i] != " ") {
							tempFunc = myFunction;
							tempFunc = tempFunc.replace(/xxxx/, (parseInt(rightPagingTemp[i]) - 1));
							rightPaging += "&nbsp;<a " + linkClass + " href=\"" + tempFunc + "\">" + rightPagingTemp[i] + "</a>&nbsp;";
						}
				} //end for
		}
		
		lastSeparator = (lastSeparator == "" ? "" : "&nbsp;...");
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(firstPaging) - 1));
		firstPaging = (firstPaging == "" ? firstText : "<a " + linkClass + " href=\"" + tempFunc + "\">" + firstText + "</a>");
		firstPaging += "&nbsp;&nbsp;";
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(prevPaging) - 1));
		prevPaging = (prevPaging == "" ? prevText : "<a " + linkClass + " href=\"" + tempFunc + "\">" + prevText + "</a>");
		prevPaging += "&nbsp;&nbsp;";
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(nextPaging) - 1));
		nextPaging = (nextPaging == "" ? nextText : "<a " + linkClass + " href=\"" + tempFunc + "\">" + nextText + "</a>");
		nextPaging += "&nbsp;&nbsp;";
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(lastPaging) - 1));
		lastPaging = (lastPaging == "" ? lastText : "<a " + linkClass + " href=\"" + tempFunc + "\">" + lastText + "</a>");
		lastPaging += "&nbsp;&nbsp;"
		
		
		var contentPage = "<table border=\"0\" cellspacing=\"0\" width=\"100%\">\n";
		contentPage += "<tr>\n";
		contentPage += "<td align=\"" + cAlign + "\" valign=\"" + cVAlign + "\" width=\"100%\" ";
		contentPage += "style=\"padding-top:" + paddingTop + "padding-left:" + paddingLeft + "padding-bottom:" + paddingBottom + "padding-right:" + paddingRight + "\">";
		contentPage += "<b>" + firstPaging;
		contentPage += prevPaging;
		contentPage += firstSeparator;
		contentPage += leftPaging;
		contentPage += midPaging;
		contentPage += rightPaging;
		contentPage += lastSeparator + "&nbsp;&nbsp;";
		contentPage += nextPaging;
		contentPage += lastPaging + "</b>";
		contentPage += "</td>\n";
		contentPage += "</tr>\n";
		contentPage += "</table>\n";

		firstPaging = "";
		prevPaging = "";
		firstSeparator = "";
		leftPaging = "";
		midPaging = "";
		rightPaging = "";
		lastSeparator = "";
		nextPaging = "";
		lastPaging = "";
		
		return contentPage;
	}
	
	
	
	function buildPagingLinksCI(isObjArray, rootPaging, myFunction, options) {
		//format the Paging
		var tempFunc;
		if (isObjArray) {
			var firstPaging = rootPaging[0];
			var prevPaging = rootPaging[1];
			var firstSeparator = rootPaging[2];
			var leftPaging = rootPaging[3];
			var midPaging = rootPaging[4];
			var rightPaging = rootPaging[5];
			var lastSeparator = rootPaging[6];
			var nextPaging = rootPaging[7];
			var lastPaging = rootPaging[8];
		} else {
			var firstPaging = rootPaging.attr('first');
			var prevPaging = rootPaging.attr('prev');
			var firstSeparator = rootPaging.attr('firstseparator');
			var leftPaging = rootPaging.attr('leftpage');
			var midPaging = rootPaging.attr('middlepage');
			var rightPaging = rootPaging.attr('rightpage');
			var lastSeparator = rootPaging.attr('lastseparator');
			var nextPaging = rootPaging.attr('next');
			var lastPaging = rootPaging.attr('last');
		}
		
		var linkClass = (options != undefined && options.linkClass != undefined ? "class=\"" + options.linkClass + "\"" : "");
		var cAlign = (options != undefined && options.align != undefined ? options.align : "left");
		var cVAlign = (options != undefined && options.vAlign != undefined ? options.vAlign : "top");
		var paddingTop = (options != undefined && options.paddingTop != undefined ? options.paddingTop : "0") + "px;";
		var paddingLeft = (options != undefined && options.paddingLeft != undefined ? options.paddingLeft : "0") + "px;";
		var paddingBottom = (options != undefined && options.paddingBottom != undefined ? options.paddingBottom : "0") + "px;";
		var paddingRight = (options != undefined && options.paddingRight != undefined ? options.paddingRight : "0") + "px;";
		var firstText = (options != undefined && options.firstText != undefined ? options.firstText : "First");
		var prevText = (options != undefined && options.prevText != undefined ? options.prevText : "Previous");
		var nextText = (options != undefined && options.nextText != undefined ? options.nextText : "Next");
		var lastText = (options != undefined && options.lastText != undefined ? options.lastText : "Last");
		
		firstSeparator = (firstSeparator == "" ? "" : firstSeparator + "&nbsp;");
		
		if (leftPaging != "") {
				var leftPagingTemp = leftPaging.split(";");
				leftPaging = "";
				
				for (var i=0; i < leftPagingTemp.length; i++) {
						if (leftPagingTemp[i] != "" && leftPagingTemp[i] != " ") {
							tempFunc = myFunction;
							tempFunc = tempFunc.replace(/xxxx/, (parseInt(leftPagingTemp[i]) - 1));
							leftPaging += "<a href=\"" + tempFunc + "\">" + leftPagingTemp[i] + "</a>&nbsp;";
						}
				} //end for
		}
		
		midPaging = "<b>" + midPaging + "</b>";
		if (options != undefined && options.midUnderline != undefined && options.midUnderline) midPaging = "<u>" + midPaging + "</u>";
		midPaging += "&nbsp;";
		
		if (rightPaging != "") {
				var rightPagingTemp = rightPaging.split(";");
				rightPaging = "";
				
				for (var i=0; i < rightPagingTemp.length; i++) {
						if (rightPagingTemp[i] != "" && rightPagingTemp[i] != " ") {
							tempFunc = myFunction;
							tempFunc = tempFunc.replace(/xxxx/, (parseInt(rightPagingTemp[i]) - 1));
							rightPaging += "<a href=\"" + tempFunc + "\">" + rightPagingTemp[i] + "</a>&nbsp;";
						}
				} //end for
		}
		
		lastSeparator = (lastSeparator == "" ? "" : "&nbsp;...");
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(firstPaging) - 1));
		firstPaging = (firstPaging == "" ? "" : "<a href=\"" + tempFunc + "\">" + firstText + "</a>&nbsp;");
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(prevPaging) - 1));
		prevPaging = (prevPaging == "" ? "" : "<a href=\"" + tempFunc + "\">" + prevText + "</a>&nbsp;");
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(nextPaging) - 1));
		nextPaging = (nextPaging == "" ? "" : "<a href=\"" + tempFunc + "\">" + nextText + "</a>&nbsp;");
		
		tempFunc = myFunction;
		tempFunc = tempFunc.replace(/xxxx/, (parseInt(lastPaging) - 1));
		lastPaging = (lastPaging == "" ? "" : "<a href=\"" + tempFunc + "\">" + lastText + "</a>");
		
		
//		var contentPage = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
//		contentPage += "<tr>\n";
//		contentPage += "<td align=\"left\" valign=\"top\" width=\"100%\" style=\"padding-top:4px;\">";
//		contentPage += "<b>" + firstPaging + prevPaging + firstSeparator + leftPaging + midPaging + rightPaging + lastSeparator + "&nbsp;&nbsp;" + nextPaging + lastPaging + "</b>";
//		contentPage += "</td>\n";
//		contentPage += "</tr>\n";
//		contentPage += "</table>\n";
		var contentPage = firstPaging + prevPaging + leftPaging + midPaging + rightPaging + nextPaging + lastPaging;
		
		firstPaging = "";
		prevPaging = "";
		firstSeparator = "";
		leftPaging = "";
		midPaging = "";
		rightPaging = "";
		lastSeparator = "";
		nextPaging = "";
		lastPaging = "";
		
		return contentPage;
	}
	
	
	
	
	var messages = {
			getViewportWidth : function() {
					//var offset = 17;
					//var width = null;
					if (window.innerWidth != window.undefined) return window.innerWidth; 
					if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth; 
					if (document.body) return document.body.clientWidth;
					
					return window.undefined;
			},
			
			getViewportHeight : function() {
					if (window.innerHeight != window.undefined) return window.innerHeight;
					if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
					if (document.body) return document.body.clientHeight; 
				
					return window.undefined;
			},
			
			getPageSize : function() {
					var theBody = document.getElementsByTagName("BODY")[0];
			
					var fullHeight = parseInt(messages.getViewportHeight());
					var fullWidth = parseInt(messages.getViewportWidth());
			
					// Determine what's bigger, scrollHeight or fullHeight / width
					if (fullHeight > parseInt(theBody.scrollHeight)) {
							popHeight = fullHeight;
					} else {
							popHeight = parseInt(theBody.scrollHeight);
					}
			
					if (fullWidth > parseInt(theBody.scrollWidth)) {
							popWidth = fullWidth;
					} else {
							popWidth = parseInt(theBody.scrollWidth);
					}
					
					var pageSize = new Array(popWidth, popHeight);
					return pageSize;
			},
			
			setCenterElement : function(obj, options) {
					var pageSize = new Array();
					
					if (options == undefined || options == null) {
							pageSize = messages.getPageSize();
					} else {
							pageSize[0] = parseInt(options[0]);
							pageSize[1] = parseInt(options[1]);
					}
					
					document.getElementById(obj).style.width = pageSize[0] + "px";
					//document.getElementById(obj).style.height = pageSize[1] + "px";
			}
	};