/*
+--------------------------------------------------------
+	Copyright (c) 2004-2007 WeSofts
+	JavaScript Project for wespace
+	http://www.wesofts.com
+--------------------------------------------------------
*/
var Ajax_method = 'text';
var Ajax_container = '';
var Ajax_query_loading = false;
function Ajax_object(){
	this.create = null;
	this.ajaxdisabled = "ERROR: Ajax disabled . \nREASON: Browser can not run ajax project .\n-----------------------------------------\nHELP: http://www.wesofts.com\n-----------------------------------------\t\n";
	this.request = function(){
		if(window.XMLHttpRequest){
			this.create = new XMLHttpRequest();
			if(this.create.overrideMimeType){
				this.create.overrideMimeType('text/xml');
			}
		}else if(window.ActiveXObject){
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0; i<versions.length; i++){
				try{
					this.create = new ActiveXObject(versions[i]);
					if(this.create){
						return this.create;
					}
				}catch(e){}
			}
		}
	}
	this.get = function(action,option,extent,eid){
		if(this.create == null){alert(this.ajaxdisabled);return false;}
		Ajax_method = 'text';
		Ajax_container = eid ? eid : '';
		this.targeturl = Ajax_targeturl(action,option,extent);
		if(window.XMLHttpRequest){
			Ajax.create.open('GET',this.targeturl);
			Ajax.create.send(null);
		}else{
			Ajax.create.open("GET",this.targeturl,true);
			Ajax.create.send();
		}
		Ajax.create.onreadystatechange = this.process;
	}
	this.post = function(action,option,extent,eid,data){
		if(this.create == null){alert(this.ajaxdisabled);return false;}
		Ajax_method = 'text';
		Ajax_container = eid ? eid : '';
		var Ajax_postdat = data && data != '' ? data : '';
		this.targeturl = Ajax_targeturl(action,option,extent);
		Ajax.create.open('POST',this.targeturl);
		Ajax.create.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		Ajax.create.send(Ajax_postdat);
		Ajax.create.onreadystatechange = this.process;
	}
	this.xml = function(url,eid){
		Ajax_query_loading = true;
		if(this.create == null){alert(this.ajaxdisabled);return false;}
		Ajax_method = 'xml';
		Ajax_container = eid ? eid : '';
		this.targeturl = Ajax_targeturl(url);
		if(window.XMLHttpRequest){
			this.create.open('GET',this.targeturl);
			this.create.send(null);
		}else{
			this.create.open("GET",this.targeturl,true);
			this.create.send();
		}
		this.create.onreadystatechange = this.process;
	}
	this.security = function(fname,secode){
		var certform = eval('document.' + fname);
		if (!fname || !certform || !$(fname + '_security')){
			return false;
		}
		if (secode){
			certform.formhash.value = secode;
			$(fname + '_security').src = Ajax_prefix + 'ajax.php?action=security&option=' + secode;
		}else{
			Ajax.xml('security&amp;create=1&amp;fname=' + fname);
		}
	}
	this.process = function(){
		if(Ajax.create.readyState == 4){
			if(Ajax.create.status == 200){
				var responsed = Ajax.create.responseText;
				var querytype = '';
				switch (responsed.substr(2,3)){
					case 'xml'	: querytype = 'xml'; break;
					case 'tml'	: querytype = 'tml'; break;
					default	: break;
				}
				if (querytype == 'xml'){
					Ajax_parse(Ajax.create.responseXML.lastChild.firstChild.nodeValue);
					Ajax_query_loading = false;
				}else{
					if(querytype == 'tml' && Ajax_method == 'xml'){
						eval(responsed.replace(/<[a-z\/]+>/ig,''));
						Ajax_query_loading = false;
					}else{
						Ajax_parse(responsed);
						Ajax_query_loading = false;
					}
					return false;
				}
			}else{
				Ajax_parse('<b>Fail</b>: HTTP 404 NOT FOUND. ');
				Ajax_query_loading = false;
			}
			Ajax_container = '';
		}
	}
}
function Ajax_evaler(str){
	if (str.indexOf('<script') == -1){
		return false;
	}
	var JsTmp;
	var JsReg = /<script>.*?<\/script>/ig;
	while ( (JsTmp = JsReg.exec(str)) != null){
		eval(JsTmp[0].replace(/<[a-z\/]+>/ig,''));
	}
}
function Ajax_targeturl(url){
	var urls = 'ajax.php?jsrandid=';// + Math.ceil(Math.random(0,9) * 100000);
	if (typeof Ajax_prefix != 'undefined'){
		urls = Ajax_prefix + urls;
	}
	urls += url ? '&action=' + url.replace(/&amp;/g,'&') : '';
	return urls;
}
function Ajax_parse(contain){
	if (!$(Ajax_container) && contain != ''){
		return false;
	}
	$(Ajax_container).innerHTML = contain;
	Ajax_evaler(contain);
}
Ajax = new Ajax_object();
Ajax.request();