﻿/////////////////////////////////////////////////公用部分函数////////////////////////
function tabpane(titlename,contentname,idnum,length){
    for(var id = 1;id<=length;id++)
    {
            var curtitleid=titlename+id;
            var curcontentid=contentname+id;
            if(id==idnum){
                  document.getElementById(curtitleid).className="branch_selected";
                  document.getElementById(curcontentid).style.display="block";
            }
            else{
                  document.getElementById(curtitleid).className="branch";
                  document.getElementById(curcontentid).style.display="none";
            }
    }    
} 
function tableftmenu(titlename,idnum,length){
    for(var id = 1;id<=length;id++)
    {
		var curtitleid=titlename+id;
		if(id==idnum){
			  document.getElementById(curtitleid).className="tab_left_menu_on";
		}
		else{
			  document.getElementById(curtitleid).className="tab_left_menu_off";
		}
    }    
}
function tableftmenuover(titlename,idnum,length){
	var OnObj = null;
    for(var id = 1;id<=length;id++)
    {
		var curtitleid=titlename+id;
		if(document.getElementById(curtitleid).className == "tab_left_menu_on")
		{
		   OnObj = document.getElementById(curtitleid);
		}
		if(id==idnum)
		{
			  document.getElementById(curtitleid).className="tab_left_menu_over";
		}
		else
		{
			  document.getElementById(curtitleid).className="tab_left_menu_off";
		}
    } 
    OnObj.className="tab_left_menu_on";  
}
function QueryString(qs)
{
    var s = location.href;
    s = s.replace("?","?&").split("&");
    var re = "";
    for(i=1;i<s.length;i++)
        if(s[i].indexOf(qs+"=")==0)
            re = s[i].replace(qs+"=","");
    return re;
}
function SetMenuDisplay()
{
    var menu=QueryString("MenuId");
    if(menu!="")
    {
    document.getElementById(menu).style.display="block";
    }
}
function CreateXMLHttp()
 {
 var xmlHttp;
 
 try
    {
   // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
return xmlHttp;
    }
 catch (e)
    {

  // Internet Explorer
   try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
      }
   catch (e)
      {

      try
         {
         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
         }
      catch (e)
         {
         alert("您的浏览器不支持AJAX！");
         return false;
         }
      }
    }
 }

///////////////////////////////start////////发送Get请求////////////////////
function SendRequestByGet(http,url)
{
    http.open("GET",url+"&Rand="+Math.random(),true);
    http.send(null);
}
function SendRequestByGet1(http,url)
{
    http.open("GET",url+"&Time="+new Date().getTime(),false);
    http.send(null);
}
////////////////////////////end//////////////////////////////////////////////

//////////////////////////////start//////////发送post请求/////////////////////
function SendRequestByPost(http,url,queryString)
{
    queryString=queryString+"&Time="+new Date().getTime()+"&Rand="+Math.random();
    http.open("POST",url,true);
    http.setRequestHeader("content-type","application/x-www-form-urlencoded"); 
    http.send(queryString);
}
/////////////////////////////end///////////////////////////////////
function createXMLDOM()
{
    var xmlDoc;
    try
    {//Create IE Dom
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
        return xmlDoc;
    }
    catch(e)
    {
        try
        {
            xmlDoc=document.implementation.createDocument("","",null);
            return xmlDoc;
        }
        catch(e)
        {
            alert("你的浏览器不支持解析XML文档");
        }
    }
}
function showDialog(page,name,hight,width)
{
    window.showModalDialog(page,name,dialogHeight=hight,dialogWidth=width);
}
function  NextFocus()
{	
	if(event.keyCode==13 && event.srcElement.type!="button" && event.srcElement.type!="submit" && event.srcElement.type!="reset" && event.srcElement.type!="")
	{
		event.keyCode=9;
	}
}
function ArrestBack()
{
    return false;
}
function selectText()
{
    this.select();
}
///xmlDoc:xml文档
//nodeName:根据某个节点来循环读取
//styleName:生成表的样式表类名
//evenNumberRowColor:偶数行的背景颜色
//oddNumberRowColor:奇数行的背景颜色
//titleArray：生成表的标题数组
//titleColor:标题行颜色
//linkColumns:需要生成链接的列
//primaryIndex:需要查询时后的主键列
//columnWidth:每一列的宽度
//linkColumnHandler:链接列的事件处理函数
function xmlToTable(xmlDoc,nodeName,styleName,evenNumberRowColor,oddNumberRowColor,titleArray,titleColor,linkColumns,primaryIndex,columnWidth,linkColumnHandler,dataAlign,linkColor,linkColorColumns,hiddenColumns)
{
    var x=xmlDoc.getElementsByTagName(nodeName);
    if(x.length<1)
    {
        var oTable=document.createElement("div");
       
        oTable.bgColor=evenNumberRowColor;
        oTable.innerText="没有相关信息";
        return oTable;
    }
    else
    {
        var oTable=document.createElement("table");
        oTable.id="XmlTable"
        oTable.width="100%";
        oTable.border="0";
        oTable.cellPadding="2";
        oTable.cellSpacing="1";
        oTable.className=styleName;
        var oTBody=document.createElement("tbody");
        oTable.appendChild(oTBody);
        var titleRow=oTBody.insertRow(0);
        titleRow.style.fontWeight="bold";
        titleRow.height="35px;"
        ////////////////////生成表头区域//////////////////
        if(titleArray==null)
        {
            titleRow.style.display="none";
        }
        else
        {
            var nHiddenIndex=0;
            for(var k=0;k<titleArray.length;k++)
            {
                var newCell=titleRow.insertCell(k);
                newCell.bgColor=titleColor;
                newCell.align="center";
                var tempValue=titleArray[k];
                var oText=document.createTextNode(tempValue);
                newCell.appendChild(oText);
                newCell.width=columnWidth[k];
                if(k==primaryIndex)
                {
                    newCell.style.display="none";
                }
                if(hiddenColumns!=null){
                    if(k==hiddenColumns[nHiddenIndex]){
                        newCell.style.display="none";
                    }
                }
            }
        }
        ////////////////////表头生成结束///////////////////
        
        ///////////////////////表主题区域///////////////////////
        for(var i=1;i<=x.length;i++)
        {
            var handlerIndex=0;//记录事件处理函数的位置
            var linkColumnIndex=0;//记录每个链接列的位置
            var linkColorColumnIndex=0;
            var nHiddenColoumnIndex=0;
            var newRow=oTBody.insertRow(i);
            newRow.id=i;
            for(var j=0;j<x[i-1].childNodes.length;j++)
            {
                var newCell=newRow.insertCell(j);
                newCell.width=columnWidth[j];
                newCell.align=dataAlign;
                if(i%2==0)
                {
                    newCell.bgColor=oddNumberRowColor;
                }
                else
                {
                    newCell.bgColor=evenNumberRowColor;
                }
                try
                {
                var tempValue=x[i-1].childNodes[j].childNodes[0].nodeValue;
                }
                catch(err)
                {
                    tempValue="";
                }
                if(linkColumns!=null)//如果参数有链接列
                {
                    if(j==linkColumns[linkColumnIndex])
                    {
                            var oLink=document.createElement("a");
                            oText=document.createTextNode(tempValue);
                            oLink.appendChild(oText);
                            if(linkColor!=null){
                                if(j==linkColorColumns[linkColorColumnIndex]){
                                    oLink.style.color=linkColor;
                                    linkColorColumnIndex++;
                                }
                            }
                            oLink.href="javascript:function a(){return false}";
                            var tempHandlerName=linkColumnHandler[handlerIndex];
                            EventUtil.addEventHandler(oLink,"click",tempHandlerName);
                            handlerIndex++;
                            newCell.appendChild(oLink);
                            linkColumnIndex++;
                    }
                    else
                    {
                        var oText=document.createTextNode(tempValue);
                        newCell.appendChild(oText);
                    }
                }
                else
                {
    //                    var oText=document.createTextNode(tempValue);
                        newCell.innerHTML=tempValue;
                }
                if(primaryIndex!=null&&j==primaryIndex)
                {
                    newCell.style.display="none";
                }
                if(hiddenColumns!=null&&j==hiddenColumns[nHiddenColoumnIndex]){
                    newCell.style.display="none";
                }
            }
        }
        return oTable;
    }
}