String.prototype.has=function(pStr){
	return(this.indexOf(pStr)!=-1);
}

String.prototype.is=function(s){
	return(this==s);
}

function VietEasyObject(pParent,pName)
{
	if(!this.objType)
		this.objType="VietEasyObject";
	this.parent=pParent;
	this.name=pName;
	
	var eb=(typeof(vieteasy)=="object");
	this._Doc=eb?vieteasy._Doc:null;
	this.oGlobals=eb?vieteasy.oGlobals:null;
	this.oUtils=eb?vieteasy.oUtils:null;
	this._get=ebObjectGet;
	this._exec=ebObjectExecute;
	this.throwError=ebObjectThrowErrorWrapper;
	this.EVENT_BEFORE=0;
	this.EVENT_AFTER=1;
}

function ebObjectGet(pName)
{
	var p=eval("this."+pName);
	if(typeof(p)=="undefined")
	{
		p="";
	}
	return p;
}

function ebObjectExecute(pFunction)
{
	var s="this."+pFunction,f=eval(s);
	if(typeof(f)=="function")
	{
		var _a=arguments;
		s+='(';
		for(var i=1,len=_a.length;i<len;i++)
		{
			s+=((i>1)?',':'')+'_a['+i+']';
		}
		s+=');';
		return eval(s);
	}
	return true;
}

function ebObjectThrowErrorWrapper(pMsg,pCmd)
{if(typeof(ebObjectThrowError)=="function")
{this.throwError=ebObjectThrowError;this.throwError(pMsg,pCmd);}}

function VietEasyBase(pParent,pName,pDoNotAdd)
{
	if(!this.objType)
		this.objType="VietEasyBase";
	this.base=VietEasyObject;
	this.base(pParent,pName);
	this.controls=[];
	this._addControl=ebBaseAddControl;
	this._getControl=ebBaseGetControl;
	this.actualGetControl=ebBaseActualGetControl;
	this.clearControl=ebControlClearControl;
	var p=this.parent;
	
	if(!pDoNotAdd&&p&&p._addControl)
		p._addControl(pName,this,true);
}

function ebBaseAddControl(pName,pObj,pReplace){
	var c=this.controls,n=pName;if(!c[n]||pReplace)
	c[n]=pObj;return c[n];
}

function ebBaseActualGetControl(pName){
	var c=this.controls,rc;
	if(c){
		for(var i in c){
			if(i==pName)
				return c[i];
			else if(c[i]&&c[i].controls){
				rc=c[i].actualGetControl(pName);
				if(rc)
					return rc;
			}
		}//END FOR	
	}
	return null;
}

function ebBaseGetControl(){
	var a=arguments,l=a.length,i=0,ct=this,n=a[i];
	while(ct.controls[n]){
		ct=ct.controls[n];
		if(i==(l-1))
			return ct;
		i++;
		n=a[i];
	}
	with(this){
		var c=actualGetControl(n);
		if(c)return c;
	}
	this.throwError("Control not found at '"+n+"'","_getControl");
	return null;
}

function ebControlClearControl(pName){
	var e=this._getControl(pName),p;
	if(!e)
		return;
	if(e.cleanupMemory)
		e.cleanupMemory();
	p=e?e.parent:null;
	if(p&&p.controls[pName])
		p.controls[pName]=null;
}

function VietEasySetup(pName)
{
	if(!this.objType)
		this.objType="VietEasySetup";
	this.name=pName;
	this.oGlobals=vieteasy.oGlobals;
}

function VietEasy(pName)
{
	if(!this.objType)
		this.objType="VietEasy";
	this.base=VietEasyBase;
	this.base(parent,pName,true);
		
	this.init=function(){
		this._Doc=new VietEasyDOM(this,"Document object");
		this.oGlobals=new VietEasyGlobals(this,"Global objects");
		this.oUtils=new VietEasyUtils(this,"Common functions");
		
	}
	this.init();
}
window.vieteasy=new VietEasy("VietEasyJavascript2");

(function(){
		  var od=vieteasy._Doc;
		  od.base=VietEasyBaseControl;
		  od.base(od.parent,od.name,true);
		  od.aCustomDocFunctions=[];
		
		od.onload=function(){
			  jsObj._exec("load");
			}
		
		od.onunload=function(){
			if(jsObj){
				jsObj._exec("unload");
				jsObj=null;
			}
			window.vieteasy=null;
		}
		
		od.onresize=function(pEvent){
			jsObj._exec("resize");
		}
		od.onDocLoad=function(){
			with(this){
				executeCustomFunction(aCustomDocFunctions["onDocLoad"]);
				if(bind)
					bind();
			}
		}
		
		od.onDocUnload=function(){
			with(this){
				executeCustomFunction(aCustomDocFunctions["onDocUnload"]);
				doc=win=null;
			}
		
			with(window)
				_showVietEasyAlert=dataLoader=null;
		}
		
		od.executeCustomFunction=function(pFunction){
			var f=pFunction;
			if(f){
				if(f[0]){
					for(var i=0,len=f.length;i<len;i++){
						if(typeof(f[i])!="undefined")
							f[i]();
					}
				}
				else if(typeof(f)!="undefined")
					f();
			}
		}
		
		od.registerDocEvent=function(pEvent,pEJ2Event,pDOMElem,pExist,pChildControl){
			var e=pEvent,j2e=pEJ2Event,twoe="this."+pDOMElem+".on"+e;
			if(pExist.is("unknown"))
				eval(twoe+"=null;");
			var cc=pChildControl,tEvt=eval(twoe),tej2e="this."+(cc?(cc+"."):"")+"on"+e,tej2ef=eval(tej2e);
			
			if(tEvt!=tej2ef){
				if(!tEvt||!tej2ef||!tEvt.toString().is(tej2ef.toString())){
					var acdf=this.aCustomDocFunctions,b=acdf[j2e];
					acdf[j2e]=acdf[j2e]?[acdf[j2e],tEvt]:tEvt;
					if(!b)this._registerEvent(e,j2e);eval(twoe+"="+tej2e);
				}
			}
		}
		
		od.registerEvents=function(){
			with(this){
				win.jsObj=this;
				registerDocEvent("load","onDocLoad","win",typeof(win.onload));
				registerDocEvent("unload","onDocUnload","win",typeof(win.onunload));
				registerDocEvent("resize","","win",typeof(win.onresize));
				_registerEvent("bind");
			}
		}
		
		od.registerEvents();
		od.restoreEventHandlers=function(){
			var cts=this.controls;
			this.registerEvents();
			for(var i in cts){
				if(cts[i].registerEvents)
					cts[i].registerEvents();
			}
		}
		
		od._registerEvent("footer","_footer");
		od._footer=function(){
			this.restoreEventHandlers();
		}
})();

function VietEasyBaseControl(pParent,pName,pDoNotAdd){
	if(!this.objType)
		this.objType="VietEasyBaseControl";
	this.base=VietEasyBase;
	this.base(pParent,pName,pDoNotAdd);
	this.controls=[];
	var eh=this.oEventHandler=new VietEasyEventHandler(this,"Event Handler");
	this._registerEvent=eh.registerEvent;
	this._getEvent=eh.getEvent;
	this._getEventEx=eh.getEventEx;
	this._registerListener=ebBaseControlRegisterListener;
	this._unregisterListener=ebBaseControlUnregisterListener;
	this._processEvent=eh.processEvent;
}

function ebBaseControlRegisterListener(pEvent,pSequence,pHandler,pBlocking){
	pEvent.registerListener(pSequence,this,pHandler,pBlocking);
}

function ebBaseControlUnregisterListener(pEvent,pSequence,pHandler){
	pEvent.unregisterListener(pSequence,this,pHandler);
}

function VietEasyEvent(pParent,pName,pHandler)
{if(!this.objType)
this.objType="VietEasyEvent";this.base=VietEasyObject;this.base(pParent,pName);this.aHandlers=[pHandler];this.aListeners=[[],[]];this.registerListener=ebEventRegisterListener;this.unregisterListener=ebEventUnregisterListener;this.notify=ebEventNotify;this.addHandler=ebEventAddHandler;}
function ebEventRegisterListener(pSequence,pParent,pHandler,pBlocking)
{var sa=this.aListeners[pSequence];sa[sa.length]=new VietEasyEventListener(pParent,pHandler,pBlocking);}
function ebEventUnregisterListener(pSequence,pParent,pHandler)
{var t=[],al=this.aListeners[pSequence];for(var i=0,len=al.length;i<len;i++)
{if(!((al[i].sHandler==pHandler)&&(al[i].parent==pParent)))
t[t.length]=al[i];}
al=this.aListeners[pSequence]=[];for(var i=0,len=t.length;i<len;i++)
al[i]=t[i];}
function ebEventNotify(pSequence)
{with(this)
{var a=arguments,aStr="";for(var i=1,len=a.length;i<len;i++)
aStr+=",a["+i+"]";var l=aListeners[pSequence],rv,fn="_listener_",lp="l[i].parent.",sH;for(var i=0,len=l.length;i<len;i++)
{sH=l[i].sHandler;if(eval("typeof("+lp+sH+") == 'function'"))
eval(lp+fn+"="+lp+sH+";rv="+lp+fn+"(this"+aStr+");");if(!rv&&l[i].bBlocking)
return false;}}
return true;}
function ebEventAddHandler(pName)
{this.aHandlers[this.aHandlers.length]=pName;}

function VietEasyEventListener(pParent,pHandler,pBlocking)
{if(!this.objType)
this.objType="VietEasyEventListener";this.base=VietEasyObject;this.base(pParent,"Event Listener");this.sHandler=pHandler;this.bBlocking=pBlocking;}

function VietEasyEventHandler(pParent,pName)
{if(!this.objType)
this.objType="VietEasyEventHandler";this.base=VietEasyObject;this.base(pParent,pName);this.aEvents=[];this.registerEvent=ebEventHandlerRegisterEvent;this.getEvent=ebEventHandlerGetEvent;this.getEventEx=ebEventHandlerGetEventEx;this.processEvent=ebEventHandlerProcessEvent;}
function ebEventHandlerRegisterEvent(pName,pHandler)
{var eh=this.oEventHandler,e=eh.aEvents[pName];if(e)
{e.addHandler(pHandler);}
else
{with(eh)
aEvents[pName]=e=new VietEasyEvent(eh,pName,pHandler);var s="this."+pName+" = function() {"+'var a = arguments, len = a.length, s = "";'+'for (var i=0; i<len; i++)'+' s += ",a[" + i + "]";'+" return eval('this._processEvent(\""+pName+"\"' + s + ')'); }";eval(s);}
return e;}
function ebEventHandlerGetEvent(pName,pEx)
{var e=this.oEventHandler.aEvents[pName];if(!e)
e=pEx?new VietEasyEvent():null;return e;}
function ebEventHandlerGetEventEx(pName)
{return this._getEvent(pName,true)}
function ebEventHandlerProcessEvent(pEventID)
{var rv=false;with(this)
{var e=oEventHandler.aEvents[pEventID];if(e)
{var a=arguments,l=a.length,aStr="";for(var i=1;i<l;i++)
aStr+=",a["+i+"]";rv=eval("e.notify(EVENT_BEFORE"+aStr+");");if(rv)
{var hs=e.aHandlers,ef,fn="this._event_";for(var i=0,l=hs.length;i<l;i++)
{ef=hs[i];if(ef&&eval('typeof('+ef+')=="function"'))
eval(fn+"="+ef+";rv="+fn+"(e"+aStr+")");}
eval("e.notify(EVENT_AFTER"+aStr+");");}}}
return rv;}

function VietEasyClient(pParent,pName){
	if(!this.objType)
		this.objType="VietEasyClient";
	if(!pParent.objType.is("VietEasyGlobals"))
		return;
	this.base=VietEasyObject;this.base(pParent,pName);
	this.bFirefox=this.bWebTV=this.bOpera=this.bNav=this.bIE=this.bSafari=this.bWin=this.bMac=this.bMacppc=this.bMactel=this.bActiveXLibLoaded=this.bActiveXSupported=this.bWinXp=this.bXpSp2=this.bAOL=this.bVista=false;
	
	this.iVer=this.fVer=-1;
	this.fMinorVer=0;
	this.aMimeTypes=null;
	
	this.init=function(){
		var nv=navigator,agt=nv.userAgent.toLowerCase(),i=0,ver;
		with(this){
			if(agt.has("webtv")){
				bWebTV=true;
				i=agt.indexOf("webtv/")+6;
			}
			else if(agt.has("firefox"))
			{
				bFirefox=true;
				i=agt.lastIndexOf("firefox")+8;
			}
			else if(agt.has("safari"))
			{
				bSafari=true;
				i=agt.lastIndexOf("safari")+7;
			}
			else if(typeof(window.opera)!="undefined")
			{
				bOpera=true;i=agt.lastIndexOf("opera")+6;
			}
			else if(nv.appName.is("Netscape"))
			{
				bNav=true;i=agt.lastIndexOf("/")+1;
			}
			else if(agt.has("msie"))
			{
				bIE=true;
				i=agt.indexOf("msie")+4;
				if(agt.has('aol')||agt.has('america online'))
				bAOL=true;
			}
			ver=agt.substring(i);
			iVer=parseInt(ver);
			fVer=parseFloat(ver);
			fMinorVer=fVer-iVer;
			bWin=agt.has("win");
			bWinXp=(bWin&&agt.has("windows nt 5.1"));
			bVista=(bWin&&agt.has("windows nt 6.0"));
			bXpSp2=(bWinXp&&agt.has("sv1"));
			bMac=agt.has("mac");
			bMacppc=(bMac&&agt.hasAny("ppc","powerpc"));
			bMactel=(bMac&&agt.has("intel"));
			aMimeTypes=nv.mimeTypes;
			bActiveXSupported=(!bMac&&(typeof(ActiveXObject)=='function'));
			writeActiveXHelper();
		}
	}
	
	this.activeXLibLoaded=function(pName){
		return(this.bIE&&!this.bMac)?vbCheckActiveXControl(pName):false;
	}
	this.writeActiveXHelper=function(){
		if(this.bIE){
			var d=this.parent.parent._Doc.doc;
			dw=function(s){d.writeln(s);
		}
		dw('<scr'+'ipt language="vbscript" type="text/vbscript">');
		dw(' Function vbCheckActiveXControl (pActXName)');
		dw('  aX = false');
		dw('  on error resume next');
		dw('  aX = IsObject(CreateObject(pActXName))');
		dw('  vbCheckActiveXControl = aX');
		dw('End Function');
		dw('</scr'+'ipt>');
	}
	}//end init()
	this.init();
}

function VietEasyGlobals(pParent,pName){
	if(!this.objType)
		this.objType="VietEasyGlobals";
	if(pParent.objType.is("VietEasy")){
		this.base=VietEasyObject;
		this.base(pParent,pName);
		this.oClient=new VietEasyClient(this,"Client Information");
	}
}

function VietEasyUtils(pParent,pName){
	if(!this.objType)
		this.objType="VietEasyUtils";
	if(!pParent.objType.is("VietEasy"))
		return;
	this.base=VietEasyObject;
	this.base(pParent,pName);
	
	this.scriptTag=function(pPath){
		return'<sc'+'ript src="'+pPath+'" language="javascript" type="text/javascript"> </sc'+'ript>';
	}
	
	this.isInArray=function(pArr,pVal,pInd){
		var rv=false,l=pArr.length,av,ind=(typeof(pInd)!="undefined");
		for(var i=0;i<l&&!rv;i++)
			rv=((ind?pArr[i][pInd]:pArr[i])==pVal);
		return rv;
	}
	
	this.controlPath=function(pObj){
		with(pObj){
			var s="",o=pObj;
			while(o!=vieteasy){
				s=",'"+o.name+"'"+s;
				o=o.parent;
			}
			s=s.substr(1);
			return"vieteasy._getControl("+s+")";
		}
	}
	this.getTopmostObject=function(){
		var t=vieteasy;while(t.parent&&t.parent._Doc)
		t=t.parent._Doc.win.vieteasy;
		return t;
	}
}

function VietEasyDOM(pParent,pName){
	if(!this.objType)
		this.objType="VietEasyDOM";
	
	this.base=VietEasyBase;
	this.base(pParent,pName,true);
	if(!pParent.objType.is("VietEasy")){
		this.throwError("Illegal object creation","constructor");
		return;
	}
	
	this.doc=document;
	this.win=window;
	this.aConfigs=[];
	
	this.addParams=function(pConfig){
		var n=pConfig.name,c=this.aConfigs[n]=pConfig;
		return c;
	}

	this.createConfig=function(pName){
		return this.addParams(new VietEasySetup(pName));
	}
	this.getConfig=function(pName){
		return this.aConfigs[pName];
	}
}

function VietEasyPage(pParent,pName){
	if(!this.objType)
		this.objType="VietEasyPage";
	this.base=VietEasyBaseControl;
	this.base(pParent,pName);
	this.oConfig=new VietEasySetup(pName);
	this.onBeforeLoad=this.onAfterLoad=this.onBeforeUnload=this.onAfterUnload=null;
	
	with(this){
		var p=parent,e=p._getEvent("load"),eb=EVENT_BEFORE,ea=EVENT_AFTER;
		_registerListener(e,eb,"onBeforeLoad");
		_registerListener(e,ea,"onAfterLoad");
		e=p._getEvent("unload");
		_registerListener(e,eb,"onBeforeUnload");
		_registerListener(e,ea,"onAfterUnload");
	}
}
vieteasy._Doc._Page=new VietEasyPage(vieteasy._Doc,"page");

function VietEasyHTML(pParent,pName,pElemName,pDisabled,pCfg)
{if(!this.objType)
this.objType="VietEasyHTML";this.base=VietEasyBaseControl;this.base(pParent,pName);this.sElemName=pElemName;this.bDisabled=pDisabled||false;this.eElem=null;this.aBindEvents=[];this.oConfig=pCfg||null;this.getDocElem=ebHTMLGetDocumentElement;this.getElem=ebHTMLGetElem;this.bind=ebHTMLBind;this.bindHTML=ebHTMLBindHTML;this.bindEvents=ebHTMLBindEvents;this.bindEventString=ebHTMLBindEventsString;this.assignJSObject=ebHTMLAssignJSObject;this.enable=ebHTMLEnable;this.show=ebHTMLShow;this.focus=ebHTMLFocus;this.setLTWH=ebHTMLSetLTWH;this.left=ebHTMLLeft;this.top=ebHTMLTop;this.width=ebHTMLWidth;this.height=ebHTMLHeight;this.setStyle=ebHTMLSetStyle;this.getStyle=ebHTMLGetStyle;this.setClass=ebHTMLSetClass;this.getClass=ebHTMLGetClass;this.cleanupMemory=ebHTMLCleanupMemory;this.onBeforeUnload=ebHTMLOnBeforeUnload;this.subscribeEvents=ebHTMLSubscribeEvents;with(this)
{if(_Doc.bBindHTMLElems)
_registerListener(_Doc._getEvent("bind"),EVENT_AFTER,"bind");_registerListener(_Doc._getEvent("unload"),EVENT_BEFORE,"onBeforeUnload");}}

function ebHTMLSubscribeEvents()
{var aA=arguments,e,len=aA.length;for(var i=0;i<len;i++)
{e=aA[i].toLowerCase();this.aBindEvents[e]=e;}}
function ebHTMLCleanupMemory()
{var e=this.eElem;if(e&&e.jsObjs)
{for(var i in e.jsObjs)
e.jsObjs[i]=null;e.jsObjs=null;this.eElem=null;}
var cts=this.controls;for(var i in cts)
{if(cts[i]&&cts[i].objType.is("VietEasy"))
cts[i]=null;}}

function ebHTMLOnBeforeUnload()
{this.cleanupMemory();}
function ebHTMLGetDocumentElement(pName,pColl)
{var c=eval("this._Doc.doc."+pColl);return c?c[pName]:null;}
function ebHTMLGetElem(pName)
{var d=this._Doc.doc,e=null;if(d.all)
e=d.all[pName];if(!e&&d.getElementById)
e=d.getElementById(pName);return e;}
function ebHTMLBind()
{with(this)
{bindHTML();bindEvents();}}
function ebHTMLBindHTML()
{with(this)
{var eN=sElemName;if(typeof(eN)!="undefined"&&eN.length>0)
{eElem=getElem(eN);if(eElem)
{assignJSObject(eElem);if(bDisabled)
enable(false);}}}}
function ebHTMLAssignJSObject(pElem)
{var set=false,jso=pElem.jsObjs;for(var i in jso)
{if(jso[i]==this)
{jso[i]=this;set=true;break;}}
if(!set)
{if(!jso)
jso=pElem.jsObjs=[];jso[jso.length]=this;}}

function ebHTMLBindEvents()
{var e=this.eElem;if(e&&e.type!='hidden')
{for(var i in this.aBindEvents)
{eval("e."+i+" = function (){"+this.bindEventString(i,0)+"}");}}}
function ebHTMLBindEventsString(pEventId,pIndex)
{var s="var rv = true, jso = this.jsObjs, o;"+"if (jso)"+"{"+"for (var i in jso)"+"{"+"o=jso[i];"+"if (!o.bDisabled && (typeof(o."+pEventId+") == 'function'))"+"rv = o."+pEventId+"(this,arguments[0],"+pIndex+");"+"}"+"}"+"return rv;";return s;}
function ebHTMLEnable(pEnable)
{var e=this.eElem;if(e)
{e.disabled=!pEnable;}
this.bDisabled=!pEnable;}
function ebHTMLShow(pShow,pNoDisplayChange)
{var e=this.eElem;if(e)
{var s=e.style;if(s)
{s.visibility=pShow?"visible":"hidden";if(!pNoDisplayChange)
s.display=pShow?"":"none";}}}
function ebHTMLFocus(pFocus)
{var e=this.eElem;if(e)
{with(e)
pFocus?focus():blur();}}
function ebHTMLSetLTWH(pVal,pName)
{var e=this.eElem;if(e)
{if((pVal!=null)&&!isNaN(parseInt(pVal)))
eval("e.style."+pName.toLowerCase()+"=pVal;");return eval("e.offset"+pName);}}
function ebHTMLLeft(pLeft)
{return this.setLTWH(pLeft,"Left");}
function ebHTMLTop(pTop)
{return this.setLTWH(pTop,"Top");}
function ebHTMLWidth(pWidth)
{return this.setLTWH(pWidth,"Width");}
function ebHTMLHeight(pHeight)
{return this.setLTWH(pHeight,"Height");}
function ebHTMLSetStyle(pName,pVal)
{var e=this.eElem;if(e&&!e.length)
{if(pVal!=null)
eval("e.style."+pName+"=pVal;");return eval("e.style."+pName+";");}}

function ebHTMLGetStyle(pName)
{return this.setStyle(pName);}
function ebHTMLSetClass(pClass)
{var e=this.eElem;if(e)
e.className=pClass;}

function ebHTMLGetClass()
{var e=this.eElem;return e?e.className:"";}

