/*
+--------------------------------------------------------
+	Copyright (c) 2004-2007 WeSofts
+	JavaScript Project for wespace
+	http://www.wesofts.com
+--------------------------------------------------------
*/
function Ajax_object(){
	/*
	+-------------------------------------------
	+	Create request object
	+-------------------------------------------
	*/
	this.request = function(){
		this.create = null;
		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){
					// Throw
				}
			}
		}
	}
	/*
	+-------------------------------------------
	+	Define
	+-------------------------------------------
	*/
	this.target = '';
	this.tarvar = ['action','option','extent','info','null'];
	this.url = function(urls){
		if (!urls || urls == ''){
			return false;
		}
		this.tmp = urls.split('|');
		this.comma = '';
		this.target = Ajax_prefix + 'ajax.php?';
		for (var i = 0; i < this.tmp.length; i++){
			if (this.tmp[i] != ''){
				if (i > 3){
					this.target += this.comma + this.tmp[i].replace(/&amp;/g,'&');
				} else {
					this.target += this.comma + this.tarvar[i] + '=' + this.tmp[i];
					this.comma = '&';
				}
			}
			if (i >= 4){
				break;
			}
		}
		if (Ajax_mtrand == 1){
			this.target += '&' + Math.ceil(Math.random(0,9) * 100000);
		}
		//alert(this.target);
	}
	this.server = 'xml';
	this.xml = function(urls,id){
		this.url(urls);
		this.server = 'xml';
		this.get(id);
	}
	this.htm = function(urls,id){
		this.url(urls);
		this.server = 'htm';
		this.get(id);
	}
	this.framer = function(urls){
		this.url(urls);
		if ($('ajaxform')){
			$('ajaxform').src = this.target;
		}
	}
	/*
	+-------------------------------------------
	+	Method query
	+-------------------------------------------
	*/
	this.container = '';
	this.ismsger = false;
	this.get = function(id){
		if(Ajax.create == null){
			alert('Request Fail.');
			return false;
		}
		if (id && id != '' && $(id)){
			this.container = id;
		} else {
			this.container = '';
		}
		if (this.ismsger && $('ajaxloading')){
			$('ajaxloading').style.display = '';
		}
		if(window.XMLHttpRequest){
			Ajax.create.open('GET',this.target);
			Ajax.create.send(null);
		}else{
			Ajax.create.open("GET",this.target,true);
			Ajax.create.send();
		}
		Ajax.create.onreadystatechange = function(){
			if(Ajax.create.readyState == 4){
				if(Ajax.create.status == 200){
					var Ajax_getsource = Ajax.create.responseText;
					if (Ajax_getsource.substr(2,3) == 'xml' && Ajax.server == 'xml'){
						Ajax.parser(Ajax.create.responseXML.lastChild.firstChild.nodeValue);
					} else {
						Ajax.parser(Ajax_getsource);
					}
					if ($('ajaxloading')){
						$('ajaxloading').style.display = 'none';
					}
				}
			}
		};
		if (Ajax.create.readyState != 1) {
			this.get(id);
		}
	}
	this.parser = function(sources){
		sources = sources ? sources : '';
		if (Ajax.container){
			$(Ajax.container).innerHTML = sources;
		}
		if (sources.indexOf('<script') == -1){
			return false;
		}
		var JsTmp;
		var JsReg = /<script>.*?<\/script>/ig;
		while ( (JsTmp = JsReg.exec(sources)) != null){
			eval(JsTmp[0].replace(/<[a-z\/]+>/ig,''));
		}
	}
	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|||&create=1&fname=' + fname);
		}
	}
}
Ajax = new Ajax_object();
Ajax.request();
document.write("<div style=\"display:none\"><iframe name=\"ajaxform\" id=\"ajaxform\" src=\"\" width=\"0\" height=\"0\"></iframe></div>");
