﻿var timeout_ajax = null; 
var isfirstgetguanjiedata=0;
function createxmlhttp(){
	xmlhttpobj = false;
                if (window.XMLHttpRequest){
                    xmlhttpobj = new XMLHttpRequest();    
                    if (xmlhttpobj.overrideMimeType){ 
                        xmlhttpobj.overrideMimeType("text/xml");    
                    }   
                }else if (window.ActiveXObject){   
                            try{    
                                xmlhttpobj = new ActiveXObject("Msxml2.XMLHTTP");    
                            }catch (e){    
                                try{    
                                    xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");    
                                }catch (e){    
                                }    
                            }
                }    
                if (!xmlhttpobj) {
                    //alert("不能创建XMLHttpRequest对象实例..");    
                    return false;    
                }    

return xmlhttpobj; 
}

function getAjaxData(url,domid){
	if(isfirstgetguanjiedata==0){
		var htmlxxx = document.getElementById(domid).innerHTML;
		var strs= new Array();
		strs=htmlxxx.split(",,");
		var str1=document.getElementById(domid).innerHTML;
		for (i=0;i<strs.length-1 ;i++ ){
			if(str1.length==0 && i<5){
				window.setTimeout("adddata('"+strs[i]+"','"+domid+"')", 100*(strs.length-i));
			}else{
				window.setTimeout("adddata('"+strs[i]+"','"+domid+"')", 2000*(strs.length-i));
			}
		}
	isfirstgetguanjiedata=1;
	}else{


	var xmlhttpobj = createxmlhttp();
	if(xmlhttpobj){//如果创建对象xmlhttpobj成功
	xmlhttpobj.open('get',url,true);//get方法
        xmlhttpobj.setRequestHeader("Cache-Control","no-cache"); 
        xmlhttpobj.setRequestHeader("If-Modified-Since","0"); 
		xmlhttpobj.send(null);
		xmlhttpobj.onreadystatechange=function(){//客户端监控函数
			if(xmlhttpobj.readyState==4){//服务器处理请求完成
				if(xmlhttpobj.status==200){
					var htmlxxx = xmlhttpobj.responseText;//获得返回值
						var strs= new Array();
						strs=htmlxxx.split(",,");
						var str1=document.getElementById(domid).innerHTML;
						

						for (i=0;i<strs.length-1 ;i++ ){
							if(str1.length==0 && i<5){
							window.setTimeout("adddata('"+strs[i]+"','"+domid+"')", 100*(strs.length-i));
							}else{
							window.setTimeout("adddata('"+strs[i]+"','"+domid+"')", 2000*(strs.length-i));
							}
						}

				}else{
					//document.getElementById(domid).innerHTML="<font color='red'>加载错误</font>";
				}
			}else{
				//document.getElementById(domid).innerHTML="服务器处理中";//服务器处理中
			}
		} 
	}

	}
}

function adddata(str,domid){
	var str1=document.getElementById(domid).innerHTML;
	if(str1.length>2000){
		str1=str1.substring(0,1000);
	}
        var mystr=new Array(str,str1);
	document.getElementById(domid).innerHTML=mystr.join(" ");
}

//开始自动刷新
function updatedata(url,domid,rtime){
	getAjaxData(url,domid);
	timeout_ajax = window.setInterval("getAjaxData('"+url+"','"+domid+"')", rtime);
}
//停止自动刷新
function Stopupdate(){
	if (timeout_ajax != null){
		window.clearInterval(timeout_ajax);
	}
}