

function dvXMLHTTP(){
	this.ObjRequest = null;
	this.settime    = null;
	this.lasttime	= 0;
	this.outtime	= 0;
}

dvXMLHTTP.prototype = {

	initXML : 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;

		}
		return objXMLHttp;
		
	},

	setSend : function(url,data,callback){

		if(this.ObjRequest == null){
			this.ObjRequest = this.initXML();
			if(this.ObjRequest == null){
				window.alert("Can't creat XMLHttpRequest Object.");
				return false;
			}
		}
				

		var nowtime	= new Date().getTime();
		if(nowtime-this.lasttime<1500){
			clearTimeout(this.settime);
			this.settime = setTimeout("dvAJAX.setSend('"+url+"','"+data+"',"+callback+");",1500+this.lasttime-nowtime);
			return;
		}
		this.lasttime = nowtime;
		url	+= (url.indexOf("?") >= 0) ? "&nowtime=" + nowtime : "?nowtime=" + nowtime;

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

			this.ObjRequest.open("GET",url,true);
			this.ObjRequest.send(null);		

		} else{

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

			this.ObjRequest.setRequestHeader("Content-Length",getByteLen(data));
			this.ObjRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			this.ObjRequest.send(data);		

		}		
		
		if(typeof(callback) == "function"){
			this.ObjRequest.onreadystatechange = function(){
				if(dvAJAX.ObjRequest.readyState == 4){
					if(dvAJAX.ObjRequest.status == 200 || dvAJAX.ObjRequest.status == 304){
								
						callback();

					} else{
						alert("Error loading page\n" + dvAJAX.ObjRequest.status + ":" + dvAJAX.ObjRequest.statusText);
					}
				}
			}
		}
	},

	seturl : function(){ //提示信息函数@@@\t来分割获取的内容...
		var rText = dvAJAX.ObjRequest.responseText.split('@@@');

		var o = dvAJAX.create();
		o.innerHTML  = rText[0];
		o.style.top  = (ietruebody().scrollTop + 170) + 'px';
		o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + ietruebody().scrollLeft + 'px';
		dvAJAX.outtime = setTimeout("dvAJAX.clear();",3000);

		if (rText[1] == null )
		if(typeof(rText[1]) != 'undefined' && in_array(rText[1],['mp','nextto','reload'])){
			
			if(rText[1]=='mp'){
				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);
			}
		}
	},

	showinfo : function(strerr,objname){ //提示信息函数
		var o = dvAJAX.create();
		o.innerHTML  = strerr;
		o.style.top  = (ietruebody().scrollTop + 170) + 'px';
		o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + ietruebody().scrollLeft + 'px';
		dvAJAX.outtime = setTimeout("dvAJAX.clear();",3000);
	},


	clear : function(){
		document.body.removeChild(getObj('dvAJAX_seturl'));
	},

	create : function(){ //创建一个DIV
		if(!IsElement('dvAJAX_seturl')){
			var o = document.createElement('div');
			o.style.cssText = 'border:#EFEF9D 1px solid;background:url('+imgpath+'AjaxImportant.gif) no-repeat .5em center #FFFFD8;font:bold 14px Helvetica;text-align:center;padding:1em 1.5em 1em 4.5em;position:absolute;z-index:901;';
			o.id  = 'dvAJAX_seturl';
			document.body.appendChild(o);
		} else{
			clearTimeout(dvAJAX.outtime);
			var o = getObj('dvAJAX_seturl');
		}
		return o;
	},

	convert : function(str){
		f = new Array(/\r\n/g,/\+/g,/\&/g,/\s/g);
		r = new Array('%0A', '%2B', '%26','%20');
		for(var i = 0;i<f.length;i++){
			str = str.replace(f[i], r[i]);
		}
		return str;
	},
	showinfoUp : function(strerr,objname){ //提示信息函数
		
		var o = dvAJAX.createUp();
		  o.innerHTML= strerr;
		o.style.top  = (ietruebody().scrollTop + 170) + 'px';
		o.style.left = (ietruebody().clientWidth - o.offsetWidth)/2 + ietruebody().scrollLeft + 'px';
		alert(o.style.top+''+o.style.left)

		dvAJAX.outtime=setTimeout("dvAJAX.clearUp();",3000);
	},
	createUp : function(){ //创建一个DIV
		if(!IsElement('seturl')){
			var o = parent.document.createElement('div');
			o.style.cssText = 'border:#EFEF9D 1px solid;background:url('+imgpath+'AjaxImportant.gif) no-repeat .5em center #FFFFD8;font:bold 14px Helvetica;text-align:center;padding:1em 1.5em 1em 4.5em;position:absolute;z-index:901;';
			o.id  = 'seturl';
			parent.document.body.appendChild(o);
		} else{
			clearTimeout(dvAJAX.outtime);
			var o = getObj('seturl');
		}
		return o;
	},
	clearUp : function(){
		parent.document.body.removeChild(getObj('seturl'));
	}

}

var dvAJAX = new dvXMLHTTP();

function dvAJAXModule(){
	this.dname= null;
	this.defname = "showAjax";
	this.replyCon   = "showReplyCon";	
	this.replyErr   = "showReplyErr";	
	this.wid= null;
	this.hei= null;
	this.mid=null;
	this.disp=null;
	this.timeunm=0;
}

dvAJAXModule.prototype = {

	setInnerHTML : function (el, htmlCode) {
		var ua = navigator.userAgent.toLowerCase();
		
		if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
			htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
			htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
			'<script$1 defer>');	
			el.innerHTML = htmlCode;
			el.removeChild(el.firstChild);
		} else {
			var el_next = el.nextSibling;
			var el_parent = el.parentNode;
			el_parent.removeChild(el);
			el.innerHTML = htmlCode;
			if (el_next) {
				el_parent.insertBefore(el, el_next)
			} else {
				el_parent.appendChild(el);
			}
		}
	},
	returnFunc : function(){ //返回内容

		if(dvAJAX.ObjRequest.responseText.indexOf('@@@') != -1){
			
			ObjAJAX.AJAXclose();//关闭DIV
			dvAJAX.seturl();//游客

		} else{
			var strText = dvAJAX.ObjRequest.responseText;

			ObjAJAX.setInnerHTML(getObj(ObjAJAX.dname), strText );//取得内容	
			getObj(ObjAJAX.dname).className = 'AjaxCss';								

			div_location(ObjAJAX.obj,1,ObjAJAX.dname);			
		}
	},
	loading : function(){ //加载提示
		getObj(ObjAJAX.dname).innerHTML = '<div style="padding:13px 30px"><img src="'+imgpath+'loading.gif" align="absbottom" /> 正在加载数据...</div>';
		getObj(ObjAJAX.dname).className = 'AjaxCss';		
		div_location(ObjAJAX.obj,1,ObjAJAX.dname);
	},

	returnDhtmlFunc : function(){ //返回内容

		if(dvAJAX.ObjRequest.responseText.indexOf('<') != -1){
			if (ObjAJAX.objfa.innerText=="全部功能") 
			{
				ObjAJAX.objfa.innerText="简单功能";
				ObjAJAX.obj1.style.display=""
				ObjAJAX.obj2.style.display=""
				ObjAJAX.obj3.style.display=""
				var reText=dvAJAX.ObjRequest.responseText.split('@@@');
				if (reText[0]!='' && ObjAJAX.obj1.innerText =='')
				{
					ObjAJAX.setInnerHTML(ObjAJAX.obj1, reText[0]);//取得编辑器图片内容							
				}
				if (reText[1]!='' && ObjAJAX.obj2.innerText =='')
				{
					ObjAJAX.setInnerHTML(ObjAJAX.obj2, reText[1]);//取得左边内容
				}
				if (reText[2]!='' && ObjAJAX.obj3.innerText =='')
				{
					ObjAJAX.setInnerHTML(ObjAJAX.obj3, reText[2]);//取得左边内容
				}

			}else{
				ObjAJAX.objfa.innerText="全部功能";
				ObjAJAX.obj1.style.display="none"
				ObjAJAX.obj2.style.display="none"
				ObjAJAX.obj3.style.display="none"
			}

		} else{
			ObjAJAX.AJAXclose();//关闭DIV
			dvAJAX.seturl();//游客
		}
	},

	AJAXclose : function(){ //关闭showmenu

		ObjAJAX.mid = arguments[0]?arguments[0]:this.defname;
		getObj(ObjAJAX.mid).style.display = "none";
		getObj(ObjAJAX.mid).oncontextmenu = null; //释放内存
		document.onmouseout = '';
		return false;
	},
	//============================回复===========================================
	ReplyClose : function(){ 
		ObjAJAX.mid = arguments[0]?arguments[0]:this.replyErr;
		getObj(ObjAJAX.mid).style.display = "none";
		getObj(ObjAJAX.mid).oncontextmenu = null; //释放内存
		return false;
	},
	ReplyLoad : function(){ //返回内容
		var rText = arguments[0]?arguments[0]:'非法操作!';
		var rInfo = arguments[1]?arguments[1]:0;//失败0 成功1 加载2
		var rImg; 
		var rColor ;
		switch (parseInt(rInfo))
		{
			case 0:
				rImg='icn_cancel.gif';
				rColor='#FF6600';
			break;		
			case 1:
				rImg='note_ok.gif';
				rColor='#33CC00';
			break;		
			case 2:
				rImg='loading.gif';
				rColor='#0066FF';
			break;	
			default :
				rImg='icn_cancel.gif';
				rColor='#FF6600';

		}
		getObj(ObjAJAX.replyErr).style.cssText = 'width:98%;border:#9CC3D9 1px solid;background: #FFFFCC;font: 14px Helvetica;text-align:center;height:27px;padding-top:10px;margin-bottom:10px;position:relative;';
		getObj(ObjAJAX.replyErr).style.display = "";
		getObj(ObjAJAX.replyErr).innerHTML = "<IMG SRC='"+imgpath+rImg+"' align=absmiddle BORDER=0>&nbsp; 操作信息：<FONT COLOR="+rColor+">"+rText+"</FONT>";	
		getObj(ObjAJAX.replyErr).className = 'AjaxCss';	
	},
	ReplyFunc : function(){ //返回内容
         receiveData=dvAJAX.ObjRequest.responseText;
         
        if(BASE64SUPPORT)receiveData=base64decode(receiveData);

		if(receiveData.indexOf('@@@') != -1){
			var rText = receiveData.split('@@@');
			var errInfo=(rText[1]=='') ? 1 : rText[1];
			ObjAJAX.ReplyLoad(rText[0],errInfo);
			setTimeout("ObjAJAX.ReplyClose(ObjAJAX.replyErr);",3000);
			if ( rText[1] != 'undefined' )
			{
				var ae = parseInt(rText[1]);
				if ( ae === 1 )
				{
					getObj(ObjAJAX.replyCon).style.display = "";
					getObj(ObjAJAX.replyCon).innerHTML += rText[2];
					
					if (getObj('ajax_getcodeinfo') != null )getObj('ajax_getcodeinfo').innerHTML = rText[3];

					document.Dvform.position.value=parseInt(document.Dvform.position.value)+1;
					if (document.Dvform.bodystyle.value == "tablebody2")
					{
						document.Dvform.bodystyle.value="tablebody1";
					}else{
						document.Dvform.bodystyle.value="tablebody2";
					}
					if (document.Dvform.getcode!=null){ //验证码
						document.Dvform.getcode.value='';
					}
					Dvbbs_InitDocument('Body','gb2312');
					IframeID.document.body.innerHTML='';

				}else if (ae===3&&BASE64SUPPORT){
					getObj('ajax_getcodeinfo').innerHTML = rText[2];
				}
			}			
			ObjAJAX.timeunm=$postlimit;
			ObjAJAX.disp=window.setInterval(ObjAJAX.ReplyBut,1000);
		}
	},
	ReplyBut : function(){ 
		
		var strInfo =  "请缓一下稍后再灌...";
		ObjAJAX.timeunm--;
		if(ObjAJAX.timeunm <= 0){
			document.Dvform.Submit.value = "OK! 发表回复";
			document.Dvform.Submit.disabled = false;
			var post=0;
			clearInterval(ObjAJAX.disp);
		}
		else{
			document.Dvform.Submit.value = strInfo + ObjAJAX.timeunm +"秒";
		}   
	} ,
	AJAXsubmit : function(obj,func){
		
		var f = ObjAJAX.ReplyFunc;
		if(typeof func != 'undefined' || typeof func == 'function'){
			f = dvAJAX.seturl;
		}
		var d = '';
		if (ObjAJAX.timeunm > 0)return

		ObjAJAX.ReplyLoad('数据处理中,请稍等...',2);
		d=ObjAJAX.AJAXQuery(obj);	
		dvAJAX.setSend(obj.action,d,f);
	},
	AJAXQuery : function (form){//将表单元数拼成Query条件
		var queryString="";
		var o = form.elements;
		queryString=(BASE64SUPPORT?"&base64encode=1":"");
		for(var i=0;i<o.length;i++){
			if(o[i].name && (o[i].type != 'radio' && o[i].type != 'checkbox' || o[i].checked === true))
			    if(BASE64SUPPORT){
				    data=base64encode(o[i].value);
				    data=data.replace(/\=/g,',');
				    data=data.replace(/\+/g,'_');
				    queryString += "&" + o[i].name + "=" + data;
			    }else{
			    	queryString += "&" + o[i].name + "=" + dvAJAX.convert(o[i].value);
			    }
				
		}
		queryString=queryString.substring(1);
	    return queryString;
	},

	AJAXmove : function(){
		var e = arguments[0]?arguments[0]: window.event;//
		ObjAJAX.mid = arguments[1]?arguments[1]:this.defname;//
		
		if(is_ie){
			document.body.onselectstart = function(){return false;}
		}
		var e  = is_ie ? window.event : e;
		var o  = getObj(ObjAJAX.mid);
		var x  = e.clientX;
		var y  = e.clientY;
		ObjAJAX.wid = e.clientX - parseInt(o.offsetLeft);
		ObjAJAX.hei = e.clientY - parseInt(o.offsetTop);
		document.onmousemove = ObjAJAX.AJAXmoving;
		document.onmouseup   = ObjAJAX.AJAXmoved;
	},

	AJAXmoving : function(){
		var e = arguments[0]?arguments[0]:null;//
		e  = is_ie ? window.event : e;
		var x  = e.clientX;
		var y  = e.clientY;
		var o  = getObj(ObjAJAX.mid);
		o.style.left = x - ObjAJAX.wid + 'px';
		o.style.top  = y - ObjAJAX.hei + 'px';
	},

	AJAXmoved : function(){
		if(is_ie){
			document.body.onselectstart = function(){return true;}
		}
		document.onmousemove = '';
		document.onmouseup   = '';
	}
}

var ObjAJAX = new dvAJAXModule();

function DvAjaxSend(){
	var url = arguments[0]?arguments[0]:null;//GET地址
	var data = arguments[1]?arguments[1]:null;//POST
	var id = arguments[2]?arguments[2]:null;//显示位置ID
	ObjAJAX.dname = arguments[3]?arguments[3]:ObjAJAX.defname;//showAjaxPic  父类ID 如果有多个div同时显示,请设置多个父类
	getObj(ObjAJAX.dname).innerHTML = "";
	ObjAJAX.obj = getObj(id);
	setTimeout("dvAJAX.setSend('"+url+"','"+data+"',"+ObjAJAX.returnFunc+");",0);
}

function DvAjaxSendDhtml(url,data,showid1,showid2,showid3,idfa){
	ObjAJAX.obj1 = getObj(showid1);
	ObjAJAX.obj2 = getObj(showid2);
	ObjAJAX.obj3 = getObj(showid3);
	ObjAJAX.objfa = getObj(idfa);
	setTimeout("dvAJAX.setSend('"+url+"','"+data+"',"+ObjAJAX.returnDhtmlFunc+");",300);
}

function  getByteLen(str)  {  
  var l= str.length;  
  var n=l;  
  for(var   i=0; i<l;i++)  
  if(str.charCodeAt(i)<0||str.charCodeAt(i)>255)  
  n++;  
  return n;  
}   


//base64 encode
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && 
  navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  document.write('<script language="vbscript"> \n');
  document.write('Function GetByteCode(ch)\n');
  document.write('code=ASC(ch)\n');
  document.write('if code<0 then code= code+65536\n');
  document.write('GetByteCode = code\n');
  document.write('End Function\n');
  document.write('Function GetCharFromCode(code)\n');
  document.write(' GetCharFromCode = chr(code)\n');
  document.write('End Function\n');
  document.write('</SCRIPT\> \n');
  BASE64SUPPORT=true;
}else{
  GetByteCode=function(ch){
     return ch.charCodeAt(0);
  }
  GetCharFromCode=function(code){
     return String.fromCharCode(code);
  }
  BASE64SUPPORT=false;
} 
 BASE64SUPPORT=false;
function base64encode(input){
	  var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	  var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;
	  var len=input.length;
	  if(len==0)return "";
	  var nextchr1=false;
      do {
         chr1 = (nextchr1===false?GetByteCode(input.charAt(i++)):nextchr1);
		 nextchr1=false;
		 chr2=false;
		 chr3=false;
		 if(chr1>255){
		     chr2=chr1&0x00FF;
			 chr1=(chr1&0xFF00)>>8;
		 }else if(i<len){
		      chr2 = GetByteCode(input.charAt(i++));
			  if(chr2>255){
			     chr3=chr2&0x00FF;
				 chr2=(chr2&0xFF00)>>8;
			  }
		}
		
        if(chr3 ===false&&i<len){
		    chr3=GetByteCode(input.charAt(i++));
			if(chr3>255){
			     nextchr1=chr3&0x00FF;
				 chr3=(chr3&0xFF00)>>8;
			}
		}	
         enc1 = chr1 >> 2;
         enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
         enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
         enc4 = chr3 & 63;
         if (chr2===false) {
            enc3 = enc4 = 64;
         } else if (chr3===false) {
            enc4 = 64;
         }
         output = output + 
            keyStr.charAt(enc1) + 
            keyStr.charAt(enc2) + 
            keyStr.charAt(enc3) + 
            keyStr.charAt(enc4);
      } while (i <len||nextchr1!==false);
      return output;
}

function base64decode(input) {
      var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	  var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i= 0;
      var base64test = /[^A-Za-z0-9\+\/\=]/g;
	  var chr0=false;
      if (base64test.exec(input)) {
         return input;
      }
      if(input.length==0)return "";
      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));
         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = (enc3==64?false:(((enc2 & 15) << 4) | (enc3 >> 2)));
         chr3= (enc4==64?false:(((enc3 & 3) << 6) | enc4));
		 
		 if(chr0!==false){
		     output+=GetCharFromCode((chr0<<8)|chr1);
			 chr0=false;
			 if(chr2!==false){
			    if(chr2>127){
				   output+=GetCharFromCode((chr2<<8)|chr3);
				}else{
				    output+=String.fromCharCode(chr2);
					if(chr3!==false){
					   if(chr3>127){
					     chr0=chr3;
					   }else{
					     output+=String.fromCharCode(chr3);
					   }
					}
				}
			 }
		 }else{
		     if(chr1>127) {
			    output+=GetCharFromCode((chr1<<8)|chr2);  
				if(chr3!==false){
					   if(chr3>127){
					     chr0=chr3;
					   }else{
					     output+=String.fromCharCode(chr3);
					   }
				}
			 }else{
			     output+=String.fromCharCode(chr1);
				 if(chr2!==false){
			         if(chr2>127){
				        output+=GetCharFromCode((chr2<<8)|chr3);
				     }else{
				        output+=String.fromCharCode(chr2);
					    if(chr3!==false){
					        if(chr3>127){
					        chr0=chr3;
					    }else{
					        output+=String.fromCharCode(chr3);
					    }
					}
				  }
			    }  
			 }
		 }
		 
      } while(i<input.length);
	  
      return output;
   }
//END base64 encode
//================================================================================================




