

function XMLhttp(){

	this.request = null;

	this.time    = null;

	this.t       = null;

	this.last	 = 0;

}



XMLhttp.prototype = {



	init : function(){

		var objXMLHttp = null;

		if(window.XMLHttpRequest){

			objXMLHttp = new XMLHttpRequest();

			if(objXMLHttp.overrideMimeType){

				objXMLHttp.overrideMimeType("text/xml");

			}

		} else if(window.ActiveXObject){

			var MSXML = [

				'MSXML2.XMLHTTP.6.0',

				'MSXML2.XMLHTTP.5.0',

				'MSXML2.XMLHTTP.4.0',

				'MSXML2.XMLHTTP.3.0',

				'MsXML2.XMLHTTP.2.6',

				'MSXML2.XMLHTTP',

				'Microsoft.XMLHTTP.1.0',

				'Microsoft.XMLHTTP.1',

				'Microsoft.XMLHTTP'

			];

			for(var i=0;i<MSXML.length;i++){

				try {

					objXMLHttp = new ActiveXObject(MSXML[i]); break;

				} catch(e){}

			}

		}

		return objXMLHttp;

	},



	send : function(url,data,callback){

		

		if(this.request == null){

			this.request = this.init();

			if(this.request == null){

				window.alert("Can't creat XMLHttpRequest Object.");

				return false;

			}

		}

		var nowtime	= new Date().getTime();

		if(nowtime-this.last<1500){

			clearTimeout(this.t);

			//this.t = setTimeout("ajax.send('"+url+"','"+data+"',"+callback+");",1500+this.last-nowtime);

			this.t = setTimeout("ajax.send('"+url+"','"+data+"',"+callback+");",1);

			return;

		}

		this.last = nowtime;

		url	+= (url.indexOf("?") >= 0) ? "&nowtime=" + nowtime : "?nowtime=" + nowtime;

		if(typeof(data) == 'undefined'){

			this.request.open("GET",url,true);

			this.request.send(null);

		} else{

			this.request.open('POST' , url, true);

			this.request.setRequestHeader("Content-Length",data.length);

			this.request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

			this.request.send(data);

		}

		

		if(typeof(callback) == "function"){

			this.request.onreadystatechange = function(){

				if(ajax.request.readyState == 4){

					if(ajax.request.status == 200 || ajax.request.status == 304){

						callback();

					} else{

						alert("Error loading page\n" + ajax.request.status + ":" + ajax.request.statusText);

					}

				}

			}

		}

	},



	guide : function(){

		var rText = ajax.request.responseText.split('\t');

		var o = ajax.create();

		o.innerHTML  = rText[0];

		o.style.top  = (ietruebody().scrollTop + 170) + 'px';

		o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + ietruebody().scrollLeft + 'px';

		ajax.time = setTimeout("ajax.clear();",3000);



		if(typeof(rText[1]) != 'undefined' && in_array(rText[1],['jump','nextto','reload'])){

			if(rText[1]=='jump'){

				setTimeout("window.location.href='"+rText[2]+"';",200);

			} else if(rText[1]=='nextto'){

				sendmsg(rText[2],rText[3],rText[4]);

			} else if(rText[1]=='reload'){

				setTimeout("window.location.reload();",200);

			}

		}

		

	},



	clear : function(){

		document.body.removeChild(getObj('ajax_guide'));

	},



	create : function(){

		if(!IsElement('ajax_guide')){

			var o = document.createElement('div');

			o.style.cssText = 'border:#EFEF9D 1px solid;background:url(images/important.gif) no-repeat .5em center #FFFFD8;font:bold 14px Helvetica;text-align:center;padding:1em 1.5em 1em 4.5em;position:absolute;z-index:3005;';

			o.id  = 'ajax_guide';

			document.body.appendChild(o);

			

		} else{

			clearTimeout(ajax.time);

			var o = getObj('ajax_guide');

		}

		

		return o;

	},



	convert : function(str){

		f = new Array(/\r?\n/g, /\+/g, /\&/g);

		r = new Array('%0A', '%2B', '%26');

		for(var i = 0;i<f.length;i++){

			str = str.replace(f[i], r[i]);

		}

		return str;

	}

}



var ajax = new XMLhttp();



function PwMenu(){

	this.pid  = null;

	this.obj  = null;

	this.w	  = null;

	this.w	  = null;

}



PwMenu.prototype = {



	get : function(){

		if(ajax.request.responseText.indexOf('<') != -1){

			getObj("showmenu").innerHTML = ajax.request.responseText;

			getObj("showmenu").className = 'menu';

			menupz(read.obj,1);

		} else{

			read.close();

			ajax.guide();

		}

	},



	guide : function(){

		getObj("showmenu").innerHTML = '<div style="padding:13px 30px"><img src="'+imgpath+'/loading.gif" align="absbottom" /> 正在加载数据...</div>';

		getObj("showmenu").className = 'menu';

		menupz(read.obj,1);

	},



	close : function(){

		closep();

	},



	submit : function(obj,recall){

		if(typeof recall == 'undefined' || typeof recall != 'function'){

			recall = ajax.guide;

		}

		var d = '';

		var o = obj.elements;

		for(var i=0;i<o.length;i++){

			if(o[i].name && (o[i].type != 'radio' && o[i].type != 'checkbox' || o[i].checked === true))

				d += "&" + o[i].name + "=" + ajax.convert(o[i].value);

		}

		ajax.send(obj.action,d,recall);

		read.close();

	},



	move : function(e){

		if(is_ie){

			document.body.onselectstart = function(){return false;}

		}

		var e  = is_ie ? window.event : e;

		var o  = getObj("showmenu");

		var x  = e.clientX;

		var y  = e.clientY;

		read.w = e.clientX - parseInt(o.offsetLeft);

		read.h = e.clientY - parseInt(o.offsetTop);

		document.onmousemove = read.moving;

		document.onmouseup   = read.moved;

	},



	moving : function(e){

		var e  = is_ie ? window.event : e;

		var x  = e.clientX;

		var y  = e.clientY;

		var o  = getObj("showmenu");

		o.style.left = x - read.w + 'px';

		o.style.top  = y - read.h + 'px';

	},



	moved : function(){

		if(is_ie){

			document.body.onselectstart = function(){return true;}

		}

		document.onmousemove = '';

		document.onmouseup   = '';

	}

}



var read = new PwMenu();



function sendmsg(url,data,id){

	read.obj = getObj(id);

	read.guide();

	setTimeout("ajax.send('"+url+"','"+data+"',"+read.get+");",300);

}

function getObj(id){

	return document.getElementById(id);

}

function IsElement(id){

	return document.getElementById(id)!=null ? true : false;

}

function ietruebody(){

	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

}