// JavaScript Document by Positron
//window.onerror=handleErr;
document.onmousemove=mload;
function mload(e){if(!document.getElementById('loading'))return;if(document.all)e = event;this.$('loading').style.left = Math.floor(document.body.scrollLeft+e.clientX+16)+'px';this.$('loading').style.top = Math.floor(document.body.scrollTop+e.clientY+16)+'px';}
function ajax(){
	this.go=function(sFunction,aArgs) {
		var xmlhttp,value;this.c=false;
		try{
			xmlhttp=new XMLHttpRequest();
			this.c=true;
		}catch(e){
			this.b=['Msxml2.XMLHTTP','Microsoft.XMLHTTP','MSXML2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0'];
			for(this.d=0;(this.d<this.b.length)&&(!this.c);this.d++){
				try{
					xmlhttp=new ActiveXObject(this.b[this.d]);
					this.c=true;
				}catch(e){
					alert('NO AJAX');
				}
			};
		};
		if(!this.c){
			alert('not support AJAX!');
			return;
		};
		this.data='ajaxplus='+sFunction;
		if(aArgs){
			for(i=0;i<aArgs.length;i++){
				value=aArgs[i];
				if(typeof(value)=="object") value=this.objectToXML(value);
				this.data+="&plusargs[]="+encodeURIComponent(value);
			}
		};
		xmlhttp.open("POST",ajaxURI,true);
		try{
			xmlhttp.setRequestHeader("Method","POST "+ajaxURI+" HTTP/1.1");
			xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		}catch(e){
			alert("บราวเซอร์ของคุณไม่รองรับการPost.");
			return;
		};
		if(document.getElementById('loading')) this.$('loading').style.display='block';
		document.body.style.cursor = 'wait';
		xmlhttp.send(this.data);
		xmlhttp.onreadystatechange=function(){
			if(xmlhttp.readyState==4){
				if(xmlhttp.status==200){
					ajax.xml(xmlhttp);
				}else if(xmlhttp.status==404){
					alert("ไม่มี URL นี้ในระบบ!");
				}
				document.body.style.cursor = 'default';
				if(document.getElementById('loading')) this.$('loading').style.display='none';
				return true;
			}
		}
	}
	this.objectToXML=function(obj){
		var sXml="<plusobj>";
		for(i in obj){
			try{
				if(i=='constructor') continue;
				if(obj[i]&&typeof(obj[i])=='function') continue;
				var key=i;var value=obj[i];
				if(value&&typeof(value)=="object"&&this.depth <=50){
					this.depth++;
					value=this.objectToXML(value);
					this.depth--;
				}
				sXml+="<e><k>"+key+"</k><v>"+value+"</v></e>";
			}catch(e){
				if(xajaxDebug)this.DebugMessage(e.name+": "+e.message);
			}
		}
		sXml+="</plusobj>";
		return sXml;
	}
	this.xml = function(x){
		var t=x.responseXML;
		if(t==null) return;
		window.status='Processing...';
		this.t=t.documentElement;
		if(this.t==null){
			window.status='XML response processing error';
			alert(x.responseTEXT);
			return;
		};
		var i,j;
		for(i=0;i<this.t.childNodes.length;i++){
			if(this.t.childNodes[i].nodeName=="cmd"){
				for(j=0;j<this.t.childNodes[i].attributes.length;j++){
					eval('this.'+this.t.childNodes[i].attributes[j].name+'=this.t.childNodes[i].attributes[j].value');
				};
				this.d=(this.t.childNodes[i].firstChild?this.t.childNodes[i].firstChild.nodeValue:'');
				switch(this.a){
					case "al":alert(this.d);break;
					case "rm":this.remove(this.d);break;
					case "ap":eval("this.$(this.s)."+this.p+"+=this.d;");break;
					case "as":eval("this.$(this.s)."+this.p+"=this.d;");break;
					case "js":eval(this.d);break;
				}
			}
		};
		delete this.t;document.body.style.cursor='default';window.status='Done';
	}
	this.remove=function(sId){objElement = this.$(sId);if(objElement&&objElement.parentNode && objElement.parentNode.removeChild){objElement.parentNode.removeChild(objElement);}}		
	this.$=function(sId){if (!sId){return null;}var returnObj = document.getElementById(sId);if(!returnObj&&document.all){returnObj=document.all[sId];};return returnObj;}	
	this.getForm=function(frm){
		var objForm;var submitDisabledElements=false;
		if(arguments.length > 1&&arguments[1]==true) submitDisabledElements=true;
		var prefix="";
		if(arguments.length > 2) prefix=arguments[2];
		if(typeof(frm)=="string") objForm=this.$(frm);
		else objForm=frm;
		var sXml="<plusquery><q>";
		if(objForm&&objForm.tagName=='FORM'){
			var formElements=objForm.elements;
			for(var i=0;i < formElements.length;i++){
				if(!formElements[i].name) continue;
				if(formElements[i].name.substring(0,prefix.length)!=prefix) continue;
				if(formElements[i].type&&(formElements[i].type=='radio'||formElements[i].type=='checkbox')&&formElements[i].checked==false) continue;
				if(formElements[i].disabled&&formElements[i].disabled==true&&submitDisabledElements==false) continue;
				var name=formElements[i].name;
				if(name){
					if(sXml!='<plusquery><q>') sXml+='&';
					if(formElements[i].type=='select-multiple'){
						for(var j=0;j < formElements[i].length;j++){
							if(formElements[i].options[j].selected==true) sXml+=name+"="+encodeURIComponent(formElements[i].options[j].value)+"&";
						}
					}else{
						sXml+=name+"="+encodeURIComponent(formElements[i].value);
					}
				}
			}
		};
		sXml+="</q></plusquery>";
		return sXml;
	}
	this.LTrim=function(value){var re = /\s*((\S+\s*)*)/;return value.replace(re,"$1");}
	this.RTrim=function(value){var re = /((\s*\S+)*)\s*/;return value.replace(re,"$1");}
	this.trim=function(value){return this.LTrim(this.RTrim(value));}
}
var ajax=new ajax();
