function myAjax(){ //WiteOKFunc 为异步状态事件处理函数 

//xmlhttp和xmldom对象
this.xhttp = null;
this.xdom = null;
this.rText='';

//post或get发送数据的键值对
this.keys = Array();
this.values = Array();
this.keyCount = -1;

//http请求头
this.rkeys = Array();
this.rvalues = Array();
this.rkeyCount = -1;
//请求头类型
this.rtype = 'text';

//初始化xmlhttp
if(window.XMLHttpRequest){//IE7, Mozilla ,Firefox 等浏览器内置该对象
     this.xhttp = new XMLHttpRequest();
}else if(window.ActiveXObject){//IE6、IE5
     try { this.xhttp = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) { }
     if (this.xhttp == null) try { this.xhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { }
}
//rs: responseBody、responseStream、responseXml、responseText

//以下为成员函数
//--------------------------------

//初始化xmldom
this.InitXDom = function(){
  var obj = null;
  if (typeof(DOMParser) != "undefined") { // Gecko、Mozilla、Firefox
    var parser = new DOMParser();
    obj = parser.parseFromString(xmlText, "text/xml");
  } else { // IE
    try { obj = new ActiveXObject("MSXML2.DOMDocument");} catch (e) { }
    if (obj == null) try { obj = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { }
  }
  this.xdom = obj;
};

//增加一个POST或GET键值对
this.AddKey = function(skey,svalue){
        this.keyCount++;
        this.keys[this.keyCount] = skey;
        this.values[this.keyCount] = svalue;
};

//增加一个Http请求头键值对
this.AddHead = function(skey,svalue){
        this.rkeyCount++;
        this.rkeys[this.rkeyCount] = skey;
        this.rvalues[this.rkeyCount] = svalue;
};

//清除当前对象的哈希表参数
this.ClearSet = function(){
        this.keyCount = -1;
        this.keys = Array();
        this.values = Array();
        this.rkeyCount = -1;
        this.rkeys = Array();
        this.rvalues = Array();
};

//发送http请求头
this.SendHead = function(){
        if(this.rkeyCount!=-1){ //发送用户自行设定的请求头
          for(;i<=this.rkeyCount;i++){
                  this.xhttp.setRequestHeader(this.rkeys[i],this.rvalues[i]); 
          }
  }
  if (this.rtype=='binary'){
          this.xhttp.setRequestHeader("Content-Type","multipart/form-data");
  }else{
          this.xhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  }
};

//用Post方式发送数据
this.SendPost = function(purl){
        var pdata = "";
        var i=0;
        this.state = 0;
        this.xhttp.open("POST", purl, true); 
        this.SendHead();
  if(this.keyCount!=-1){ //post数据
          for(;i<=this.keyCount;i++){
                  if(pdata=="") pdata = this.keys[i]+'='+this.values[i];
                  else pdata += "&"+this.keys[i]+'='+this.values[i];
          }
  }
 // alert(pdata);
  this.xhttp.send(pdata);
};

//用GET方式发送数据
this.SendGet = function(purl){
        var gkey = "";
        var i=0;
        this.state = 0;
        if(this.keyCount!=-1){ //get参数
          for(;i<=this.keyCount;i++){
                  if(gkey=="") gkey = this.keys[i]+'='+this.values[i];
                  else gkey += "&"+this.keys[i]+'='+this.values[i];
          }
          if(purl.indexOf('?')==-1) purl = purl + '?' + gkey;
          else  purl = purl + '&' + gkey;
  }
        this.xhttp.open("GET", purl, true); 
        this.SendHead();
  this.xhttp.send();
};
//处理数据传送和完成的函数
//Doing 数据传送中的函数，Done 数据传送完成后的函数
//getObj 接受数据的函数
//varDoing doing的参数数组
//varDone done的参数叔祖
this.ToDo=function(Doing,Done,varDoing,varDone){
    var xhttp = this.xhttp;
    this.xhttp.onreadystatechange= function () {
   	 if(xhttp.readyState != 4){
	    Doing(varDoing);
        }
	 else if(xhttp.readyState == 4 && xhttp.status == 200){
        //xhttp.responseText;
        //alert(xhttp.responseText);
	 	Done(xhttp.responseText,varDone);
        }
     else{
     	alert('无法连接服务器，请检查网络！');
     }
    }
};
//删除指定值的select选项
this.delSelectValue=function(dGetObj,setValue){
for(var d=0; d<dGetObj.options.length;d++){
			if(setValue==dGetObj.options[d].value){
				getDown(getObj,d);//将这个项目移到最底下
				dGetObj.options.length --;
				ii--;
				//alert(dGetObj.options.length);
				return;
			}
		}
}
//正在操作的函数
this.ajaxDoing=function(id){
	if (typeof(id) == "undefined") id = varDoing[0];
	document.getElementById(id).innerHTML='正在处理中.....';
}
//正在获取列表的函数
this.ajaxGeting=function(id){
	if (typeof(id) == "undefined") id = varDoing[0];
	document.getElementById(id).innerHTML='正在获取列表.....';
}
this.ajaxDone=function(id){
	if (typeof(id) == "undefined") id = varDoing[0];
	document.getElementById(id).innerHTML='处理成功.';
}
//正在获取列表的函数
this.ajaxGeted=function(id){
	if (typeof(id) == "undefined") id = varDoing[0];
	document.getElementById(id).innerHTML='获取列表成功.';
}
/*示例
<script type="text/javascript">
function a(){//处理数据传送中的函数

	alert('loading');
}
function b(){//处理数据传送完后的函数

	alert('done');
}
var myAjax=new MAjax();//建立新事例
myAjax.AddKey('name','qibinghua');//添加传送的参数和值
myAjax.AddKey('password','19830102');//同上
myAjax.SendPost('test.php');//post发送数据
myAjax.ToDo(a,b);//处理xmlhttp相干的函数
</script>


*/
} 
// End Class myAjax
//var str='1|a,2|b,3|c,4|d,5|e,6|f';
/*
divObj,要显示的div标签
setObj,传送数据的对象
getObj，获取数据的对象
str ajax返回的数据，文本格式，ID|TEXT，ID|TEXT ...
col 列数，默认5
row 行数，默认15
height 高度 默认20
width 宽度 默认100
multiple 是否允许多选
所有单位 像素
*/
var temp=[];//临时存放抄做的数据
var tempInnerText=[];//临时存放innserText文本
var tempInnerHTML=[];//临时存放innserHTML文本
var colsId=[];//存储每个列的id
var colsValue=[];//存储每个列的值
var colsText=[];//存储每个列的文本
var arrayStr=[];//定义数组
function buildTable(divObj,setObj,getObj,str,col,row,height,width,multiple,isClick){
//alert(getObj);
if (typeof(divObj) == "undefined") divObj = 'loadData';//显示数据的层
if (typeof(setObj) == "undefined") setObj = 'tdDataId';//显示数据的单元格id，也是传送数据的id
if (typeof(getObj) == "undefined") getObj = 'selectData';//接受传送的数据的select控件
if (typeof(str) == "undefined") str = 'nothing';//用来创建表格的数据
if (typeof(col) == "undefined") col = 4;//默认创建的表格列数
if (typeof(row) == "undefined") row = 15;//默认创建的表格的行
if (typeof(height) == "undefined") height = 20;//表格高
if (typeof(width) == "undefined") width = 100;//表格框
if (typeof(multiple) == "undefined") multiple = 1;//允许多选，1为多选
if (typeof(isClick) == "undefined") isClick = 1;//是否允许传送值到外面的控件
//loadPage();

            	var re = /<script language=\'javascript\'>((.|\n)*)<\/script>/;
            	var r = str.match(re);
            	if(r!=null && r.length>0){
            		alert("当前账户已在其他地方登陆！");
            		parent.location.href='/out.html';
            		return false;
            	}
            	
display(divObj,'');//显示数据层

	if(str=='nothing'){//如果用来创建表格的数据为空
		deleteOldTable();//将整个表格数据置空
		//document.getElementById('result').innerHTML='暂时没有任何数据';显示没有数据
		return false;//返回值，终止程序
	}else{//不为空
	
		deleteOldTable();//将整个表格数据置空
		var arrayIndex=0;//定义序数为0
		var tempGetObj;//临时存储控件
		var ci=0;
		colsId=[];//存储每个列的id
		colsValue=[];//存储每个列的值
		colsText=[];//存储每个列的文本
		arrayStr=[];//定义数组
		var sGetObj=document.getElementById(getObj);//获得接受数据的select控件的对象
		var table=document.getElementsByTagName("table")[3].parentElement;//通过获取表格数量集合获取表格对象，表格为整个html页面的第4个表格

		arrayStr=str.split(',');//将字符串转为数组
		/*
		设置表格属性
 		//table.setAttribute("border","0");
 		//table.setAttribute("width","100%");
		//table.setAttribute("id","tableData");
		*/
		//table=document.getElementById('tableData');//通过ID取得表格对象
 		//document.getElementById(divObj).appendChild(table);//将此表格附加到数据层上
		if(tempGetObj==''){
				tempGetObj=sGetObj;
		}
		var tablehtml = "<table width='86%' border='0' cellspacing='0' cellpadding='0'>";
		for(var n=0;;n++){//循环生成表格
			var row = "";//添加一个新行
			row += "<tr>";
			for(var m=0;m<col;m++){//循环生成列
			    if (arrayIndex >= arrayStr.length){//如果
					//改变表格的值/
					//if(tempGetObj==sGetObj) sGetObj.options.length=0;//如果为同一个select则将select为空
					if(m<col){
						row += "</tr>";
						tablehtml += row;
					}
					tablehtml += "</table>";
					table.innerHTML = tablehtml;
					if(multiple=='1'){
						document.getElementById('doDiv').style.display='';
						if(sGetObj.options.length==0){//select无数据
							return;	
						}else{
							for(var si=0;si<sGetObj.options.length;si++){//获取select的值
								//alert(sGetObj.options[si].value+":"+sGetObj.options[si].text);
								for(var ci=0;ci<colsId.length;ci++){//循环获取列的值
									if(sGetObj.options[si].value==colsValue[ci]){//如果列的值和select的值相等
										document.getElementById(colsId[ci]).innerHTML=colsText[ci]+"<a href=javascript:setVar('"+ci+"','"+getObj+"','"+colsValue[ci]+"',"+multiple+")>[取消]</a>";
									}
								}
							}
						}
					}
				//tempGetObj=sGetObj;//将当前select存储
//结束/		
				return;
			    }
				cols="<td ";//添加一个新列
				var arrayValue=arrayStr[arrayIndex++].split('|');//获取数据
				var setValue=arrayValue[0];//数据值
				var textValue=arrayValue[1];//数据显示文本
				var setObjOk=setObj+arrayIndex;//生成单元格id
				/*
				给单元格设置属性
				//cols.bgColor  = "#EEEEEE";
				//cols.setAttribute("width",width);
				*/
				//cols.setAttribute("height",height);
				cols += " height='"+height+"' ";
				//alert(textValue);
				//cols.setAttribute("id",setObjOk);//设置单元格id
				cols += " id='"+setObjOk+"'>";
				colsId[ci]=setObjOk;//将列的id存储到数组
				colsValue[ci]=setValue;//将列的值存储到数组
				colsText[ci]=textValue;//将列的文本存储到数组
				
				
				if(isClick==1){//如果允许传值出去
					cols +="<a href=javascript:setVar('"+ci+"','"+getObj+"','"+setValue+"',"+multiple+")>"+textValue+"</a>";//设置列的数据
					//tempGetObj=sGetObj;//将当前select存储
				}else{
					cols +=textValue;
				}
				cols +="</td>";
				ci++;
				row += cols;
				//alert('html:'+cols.innerHTML+"\n"+document.getElementById(setObjOk).innerText);
				//++arrayIndex;
				//alert(arrayIndex);
			}
			row += "</tr>";
			tablehtml += row;
		}
	}
	
}

//buildTable('loadData',"tdDataId",'zg5',str,5,15,20,100);
//删除原来表格的数据
function deleteOldTable() {
 //delRow = document.getElementsByTagName("table").length
 //此句仅在本例中使用，因为本例中已经有一个table了，因此不能删除，需要根据情况变化一下2005.11.17
 //if(delRow == 1) return
 
 var node = document.getElementsByTagName("table")[3]; //表格
//var node=document.getElementById('tableData');
  //var node = document.getElementById(table); //表格
 var c = node.childNodes.length
 for(var a=0;a<c;a++)
 node.removeChild(node.childNodes[a]); //删除全部单元行
}
function setVar(ci,getObj,setValue,multiple){
	var dGetObj=document.getElementById(getObj);
	var dSetObj=document.getElementById(colsId[ci]);
	var re = new RegExp("[取消]","ig");
	var slength=dGetObj.options.length;//得到当前select的长度
	if(multiple==1){
		if(!re.test(dSetObj.innerText)){
			//tempInnerText[ii]=dSetObj.innerText;
			dGetObj.options[slength++]=new Option(colsText[ci],setValue);
			dSetObj.innerHTML=colsText[ci]+"<a href=javascript:setVar('"+ci+"','"+getObj+"','"+setValue+"',"+multiple+")>[取消]</a>";
		}else{
			//alert('dd');
			for(var d=0; d<slength;d++){
				if(setValue==dGetObj.options[d].value){
					dSetObj.innerHTML="<a href=javascript:setVar('"+ci+"','"+getObj+"','"+setValue+"',"+multiple+")>"+colsText[ci]+"</a>";
					getDown(getObj,d);//将这个项目移到最底下
					dGetObj.options.length --;
					//tempInnerText.splice();
					//ii--;
					//alert(dGetObj.options.length);
					return;
				}
			}
		}
	}
//单选
else{
	var setToText=colsText[ci];//获取当前单元格值
	if(dGetObj.options.length==0){
		dGetObj.options[0]=new Option(setToText,setValue);//增加一个option
	}else{
		dGetObj.options.length=0;//将select的option置空
		dGetObj.options[0]=new Option(setToText,setValue);//增加一个option
	}
/*
	if(temp[0]==''){
			//alert(temp.join(','));
			temp[0]=setObj;//存放临时的id
			temp[1]=dSetObj.innerHTML;//临时存放其值
			temp[2]=dSetObj.innerText;//临时存放其值
			temp[3]=getObj;
			temp[4]=setValue;
			temp[5]=multiple;
			temp[6]=dSetObj.innerHTML;//临时存放其值
	}
if(re.test(temp[6])){

			if(temp[0]!=setObj){
				if(re.test(temp[6])){	
			document.getElementById(temp[0]).innerHTML=temp[1];
			dGetObj.options.length=0;
			temp[0]=setObj;//存放临时的id
			temp[1]=dSetObj.innerHTML;//临时存放其值
			temp[2]=dSetObj.innerText;//临时存放其值
			temp[3]=getObj;
			temp[4]=setValue;
			temp[5]=multiple;
			dGetObj.options[0]=new Option(dSetObj.innerText,setValue);
			dGetObj.options[0].selected=true;
			dSetObj.innerHTML=dSetObj.innerText+"<a href=javascript:setVar('"+setObj+"','"+getObj+"','"+setValue+"',"+multiple+")>[取消]</a>";
			temp[6]=dSetObj.innerHTML;//临时存放其值

				}
			}else{
				//alert(temp[6]);
				if(re.test(temp[6])){	
					//alert(dGetObj.options[0].text);
					document.getElementById(temp[0]).innerHTML=dSetObj.innerHTML="<a href=javascript:setVar('"+setObj+"','"+getObj+"','"+setValue+"',"+multiple+")>"+dGetObj.options[0].text+"</a>";;
					//dGetObj.options.length=0;
					alert(dGetObj.options.length);
					dGetObj.options.length=0;
					temp[6]=dSetObj.innerHTML;//临时存放其值

					//dSetObj.innerHTML="<a href=javascript:setVar('"+setObj+"','"+getObj+"','"+setValue+"',"+multiple+")>"+dGetObj.options[0].text+"</a>";
				}else{
					document.getElementById(temp[0]).innerHTML=temp[1];
					dGetObj.options.length=0;
					temp[6]=dSetObj.innerHTML;//临时存放其值

				}
		}
	
}else{

			dGetObj.options[0]=new Option(dSetObj.innerText,setValue);
			dGetObj.options[0].selected=true;
	temp[0]=setObj;//存放临时的id
	temp[1]=dSetObj.innerHTML;//临时存放其值
	temp[2]=dSetObj.innerText;//临时存放其值
	temp[3]=getObj;
	temp[4]=setValue;
	temp[5]=multiple;
	dSetObj.innerHTML=dSetObj.innerText+"<a href=javascript:setVar('"+setObj+"','"+getObj+"','"+setValue+"',"+multiple+")>[取消]</a>";
	temp[6]=dSetObj.innerHTML;//临时存放其值
}
*/
display('loadData','none');
}
//alert(temp[6]);
}
function  getDown(getObj,n){  
           var j;

		   var dGetObj=document.getElementById(getObj); 
           j=dGetObj.options.length-1;
           if(n<j){  
                       temp_Text=dGetObj.options[n].text;  
                       temp_ID=dGetObj.options[n].value;  
                       for(k=n+1;k<=j;k++){  
                                   dGetObj.options[k-1].text=dGetObj.options[k].text;  
                                   dGetObj.options[k-1].value=dGetObj.options[k].value;  
                       }  
                         
                       dGetObj.options[j].text=temp_Text;  
                       dGetObj.options[j].value=temp_ID;  
           }  

}
//将返回的字符串用,连接
function rStr(strD){
	strA=strD.split(',');
	var strC=[];
	for(stri=0;stri<strA.length;stri++){
		strB=strA[stri].split('|');
		strC[stri]=strB[1];
	}
	
return strC.join(',');
}
//验证字符串
function havegg(elem){
   		var str = "~!%^&*();'\"?><[]{}\\|,:/=+—";
  		for(i=0;i<elem.length;i++)
    			if (str.indexOf(elem.charAt(i)) !=-1){
					return false;
  			}else{
}
      		return true;
 	}
function clearVar(){
			temp[0]='';//存放临时的id
			temp[1]='';//临时存放其值
			temp[2]='';//临时存放其值
			temp[3]='';
			temp[4]='';
			temp[5]='';
			temp[6]='';//临时存放其值
}
//-->
