function AX_Application(DOMContainer, l, t, w, h, minW, minH) {
	if (DOMContainer) {
		this.DOMContainer = DOMContainer;  
	} else {
		this.DOMContainer = document.body;  
	}
	if (this.DOMContainer == document.body) {
		with (document.body) {
			//style.overflow = 'hidden';
			style.position = 'absolute';
			style.width = '100%';
			style.height = '100%';
			style.margin = '0px';
			style.padding = '0px';
			style.border = '0px solid black';
		}
	}
	this.Left = l || 0;
	this.Top = t || 0;
	this.Width = w || '100%';
	this.Height = h || '100%';
	this.MinW = minW || 740;
	this.MinH = minH || 480;
	this.InnerRect = new Array();
	this.InnerPadding = 4;
	this.AutoSize = false;
	this.AutoWidth = false;
	this.AutoHeight = false;
	this.PercWidth = 100;
	this.PercHeight = 100;
	this.calcSize(this.Width, this.Height);
	
	//  color, fonts and layout
	this.BackgroundColor = '#D0D0D0';
	this.Padding = 0;
	this.BorderSize = 1;
	this.BorderColor = '#000000';
	this.BorderColorHigh = '#F0F0F0';
	this.BorderColorShadow = '#808080';
	this.BorderStyle = 'solid';
	
	this.FontFamily = 'Tahoma, Verdana, Arial, sans-serif';
	this.FontSize = 8;
	this.FontColor = '#000000';
	this.FontBold = false;
	this.FontSmallCaps = false;

	this.agent = this.checkAgent();
	this.ImagesBasePath = '';

	this.RootPanel = new AX_Panel();
	this.RootPanel.Application = this;
	this.RootPanel.setParent(this);
	this.RootPanel.Name = 'AX_Application';
	this.RootPanel.Padding = this.InnerPadding;

	this.resize();
	this.RootPanel.SetVisible(true);
	this.resize();
	this.evObjects = 0;
}

AX_Application.eventList = new Array();

AX_Application.prototype.bindEvent = function(obj, sEvent, dstObj, dstFunc) {
	if (!obj.eventId) obj.eventId = ++this.evObjects;
	var sEvId = obj.eventId + '_' + sEvent;
	AX_Application.eventList[sEvId] = new Array(dstObj, dstFunc);
	if (sEvent.indexOf("mouse") != -1) {
		if (this.agent == 'opera') {
			obj.addEventListener(sEvent, this.evMHubEx, false);
		} else if (this.agent == 'mozilla') {
			obj.addEventListener(sEvent, this.evMHub, false);
		} else {
			obj.attachEvent('on' + sEvent, this.evMHubEx);
		}
	} else {
		if (this.agent.substr(0, 2) == 'ie') {
			obj.attachEvent('on' + sEvent, this.evHubEx);
		} else {
			obj.addEventListener(sEvent, this.evHub, false);
		}
	}
}

AX_Application.prototype.unbindEvent = function(obj, sEvent) {
	if (sEvent.indexOf("mouse") != -1) {
		if (this.agent == 'opera') {
			obj.removeEventListener(sEvent, this.evMHubEx, false);
		} else if (this.agent == 'mozilla') {
			obj.removeEventListener(sEvent, this.evMHub, false);
		} else {
			obj.detachEvent('on' + sEvent, this.evMHubEx);
		}
	} else {
		if (this.agent.substr(0, 2) == 'ie') {
			obj.detachEvent('on' + sEvent, this.evHubEx);
		} else {
			obj.removeEventListener(sEvent, this.evHub, false);
		}
	}
}

AX_Application.prototype.evHubEx = function() {
	var obj = event.srcElement;
	var sEvId = obj.eventId + '_' + event.type;
	AX_Application.eventList[sEvId][1].call(AX_Application.eventList[sEvId][0], obj, event);
}

AX_Application.prototype.evHub = function(ev) {
	var obj = ev.currentTarget;
	var sEvId = obj.eventId + '_' + ev.type;
	AX_Application.eventList[sEvId][1].call(AX_Application.eventList[sEvId][0], obj, ev);
}

AX_Application.prototype.evMHubEx = function() {
	var obj = event.srcElement;
	var sEvId = obj.eventId + '_' + event.type;
	AX_Application.eventList[sEvId][1].call(AX_Application.eventList[sEvId][0], obj, event, event.offsetX, event.offsetY, event.clientX, event.clientY);
}

AX_Application.prototype.evMHub = function(ev) {
	var obj = ev.currentTarget;
	var sEvId = obj.eventId + '_' + ev.type;
	AX_Application.eventList[sEvId][1].call(AX_Application.eventList[sEvId][0], obj, ev, ev.layerX, ev.layerY, ev.clientX, ev.clientY);
}


AX_Application.prototype.AddControl = function(oParent, sType, sName, sDockPos, sTitlebarPos, hTitlebar) {
	var oItem = null;
	switch (sType) {
	case 'panel':
		oItem = new AX_Panel();
		oItem.Application = this;
		if (sName) oItem.Name = sName;
		oItem.setParent(oParent);
		oParent.addChild(oItem);
		break;
	case 'multi': 
		oItem = new AX_MultiPanel();
		oItem.Application = this;
		if (sName) oItem.Name = sName;
		oItem.setParent(oParent);
		oParent.addChild(oItem);
		break;
	case 'tabs':
		oItem = new AX_TabbedPanel(sDockPos, sTitlebarPos, hTitlebar);
		oItem.Application = this;
		if (sName) oItem.Name = sName;
		oItem.setParent(oParent);
		oParent.addChild(oItem);
		break;
	case 'float':
		oItem = new AX_FloatPanel(sDockPos, sTitlebarPos, hTitlebar);
		oItem.Application = this;
		if (sName) oItem.Name = sName;
		oItem.setParent(oParent);
		oParent.addChild(oItem);
		break;
	case 'login':
		oItem = new AX_LoginPanel();
		oItem.Application = this;
		if (sName) oItem.Name = sName;
		oItem.setParent(oParent);
		oParent.addChild(oItem);
		break;
	}
	return oItem;
}

AX_Application.prototype.SetLayout = function(iPadding, iBorderSize, sBorderStyle, colBorderColor, colBorderColor2) {
	if (iPadding !== false) this.InnerPadding = iPadding;
	if (iBorderSize !== false) this.BorderSize = iBorderSize;
	if (sBorderStyle !== false) this.BorderStyle = sBorderStyle;
	if (colBorderColor !== false) this.BorderColor = colBorderColor;
	if (colBorderColor !== false) this.BorderColorHigh = colBorderColor;
	if (colBorderColor2 !== false) this.BorderColorShadow = colBorderColor2;
	this.RootPanel.Padding = this.InnerPadding;
	this.RootPanel.SetBorder(this.BorderSize, this.BorderStyle, this.BorderColor, this.BorderColorShadow);
	this.RootPanel.SetSize(this.Left, this.Top, this.Width, this.Height);
}

AX_Application.prototype.SetImagesPath = function(sPath) {
	if (sPath.lastIndexOf('/') < sPath.length - 1) {
		sPath += '/';
	}
	this.ImagesBasePath = sPath;
	this.RootPanel.ImagesBasePath = sPath;
}

AX_Application.prototype.SetBackgroundColor = function(bgcol) {
	this.BackgroundColor = bgcol;
	this.RootPanel.SetBackgroundColor(bgcol);
}

AX_Application.prototype.getDIV = function() {
	var ret = document.createElement('DIV');
	with (ret.style) {
		position = 'absolute';
		display = 'none';
		backgroundColor = 'transparent';
		overflow = 'hidden';
		margin = '0px';
		padding = '0px';
		border = '0px solid black';
	}
	return ret;
}

AX_Application.prototype.getSPAN = function() {
	var ret = document.createElement('SPAN');
	with (ret.style) {
		position = 'absolute';
		backgroundColor = 'transparent';
		margin = '0px';
		padding = '0px';
		border = '0px solid black';
	}
	return ret;
}


AX_Application.prototype.getTABLE = function() {
	var ret = document.createElement('TABLE');
	ret.cellPadding = 0;
	ret.cellSpacing = 0;
	with (ret.style) {
		position = 'absolute';
		backgroundColor = 'transparent';
		margin = '0px';
		padding = '0px';
		border = '0px solid black';
	}
	ret.appendChild(document.createElement("TBODY"));
	return ret;
}

AX_Application.prototype.getTD = function() {
	var ret = document.createElement('TD');
	with (ret.style) {
		backgroundColor = 'transparent';
		margin = '0px';
		padding = '0px';
		border = '0px solid black';
		textAlign = 'center';
		verticalAlign = 'middle';
	}
	return ret;
}

AX_Application.prototype.GetDOMContainer = function() {
	return this.DOMContainer;
}

AX_Application.prototype.calcSize = function(w, h) {
	if (w) {
		var s = '' + w;
		if (s.indexOf('%') > 1) {
			this.AutoWidth = true;
			this.PercWidth = parseInt(w);
			this.Width = 100;
		} else {
			this.AutoWidth = false;
			this.Width = Math.max(parseInt(w), this.MinW);
		}

	}
	if (h) {
		var s = '' + h;
		if (s.indexOf('%') > 1) {
			this.AutoHeight = true;
			this.PercHeight = parseInt(h);
			this.Height = 100;
		} else {
			this.AutoHeight = false;
			this.Height = Math.max(parseInt(h), this.MinH);
		}
	}
	this.AutoSize = this.AutoWidth || this.AutoHeight;
}

AX_Application.prototype.resize = function() {
	var needresizing = false;
	if (this.AutoSize) {
		var newW = this.MinW;
		var newH = this.MinH;
		if (this.AutoWidth) {
			newW = Math.floor((this.DOMContainer.offsetWidth - this.Left * 2) * this.PercWidth / 100) - 2;
			if (newW != this.Width) {
				this.Width = Math.max(newW, this.MinW);
				needresizing = true;
			}
		}
		if (this.AutoHeight) {
			newH = Math.floor((this.DOMContainer.offsetHeight - this.Top * 2) * this.PercHeight / 100);
			if (newH != this.Height) {
				this.Height = Math.max(newH, this.MinH);
				needresizing = true;
			}
		}
	}
  this.InnerRect['left'] = 0;
  this.InnerRect['top'] = 0;
  this.InnerRect['width'] = this.Width;
  this.InnerRect['height'] = this.Height;
	if (needresizing) {
		this.RootPanel.SetSize(this.Left, this.Top, this.Width, this.Height);
	}
}

AX_Application.prototype.checkAgent = function() {
	var sAgent = navigator.userAgent.toLowerCase();
	if (sAgent.indexOf("opera") != -1) return 'opera';
	if (sAgent.indexOf("msie 7") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1) return 'ie7';
	if (sAgent.indexOf("msie") != -1 && sAgent.indexOf("mac") == -1 && sAgent.indexOf("opera") == -1) return 'ie6';
	return 'mozilla';
}



//================================================================
function AX_XMLHttpClass() {
	this.responseText = '';
	this.responseXML = null;
}

AX_XMLHttpClass.prototype.sendPOST = function(sUrl, sData, cbfunc, ownerObj) {
	var httpObj = this.getHttpObject(true);
	if (!httpObj) {
		return false;
	}
	var bAsynch = (cbfunc ? true : false);
	if (!ownerObj) ownerObj = this;
	if (bAsynch) {
		httpObj.onreadystatechange = function() { 
		cbfunc(httpObj, ownerObj); 
		}
	}
  httpObj.open('POST', sUrl, bAsynch);
  httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  httpObj.send(sData);
	if (!bAsynch) {
  	return httpObj;
  }
}

AX_XMLHttpClass.prototype.downloadUrl = function(sUrl, cbfunc, ownerObj) {
	var httpObj = this.getHttpObject(false);
	if (!httpObj) {
		return false;
	}
	var bAsynch = (cbfunc ? true : false);
	if (!ownerObj) ownerObj = this;
	if (bAsynch) {
		httpObj.onreadystatechange = function() { 
			cbfunc(httpObj, ownerObj); 
		}
	}
  httpObj.open('GET', sUrl, bAsynch);
  httpObj.send(null);
	if (!bAsynch) {
  	return httpObj;
  }
}

AX_XMLHttpClass.prototype.downloadXML = function(sUrl, cbfunc) {
	var httpObj = this.getHttpObject(true);
	if (!httpObj) {
		return false;
	}
	httpObj.onreadystatechange = function() { 
		cbfunc(httpObj); 
	}
  httpObj.open('GET', sUrl, true);
  httpObj.send(null);
}

AX_XMLHttpClass.prototype.getHttpObject = function(bRequireXml) {
	var ret = null;
	if (window.XMLHttpRequest) { 
		ret = new XMLHttpRequest();
		if (bRequireXml) {
			if (ret.overrideMimeType) {
				ret.overrideMimeType('text/xml');
			}
		}
	} else if (window.ActiveXObject) { 
		try {
			ret = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ret = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	}
	return ret;
}



