﻿
var isIe=(window.ActiveXObject)?true:false;
var pageLinkUrl="";
var waitHtml="<div style='border:#666 1px solid;background:#eee;padding:3px;'>操作正在进行中，请等待</div>";

function g(nodeId)
{
   return document.getElementById(nodeId);
}
function setInnerHtml(objName,dcontent)
{
   if(g(objName)!=null)
   {g(objName).innerHTML=dcontent;}
}
function getPos(obj){
	this.Left=0;
	this.Top=0;
	this.Height=obj.offsetHeight;
	this.Width=obj.offsetWidth;
	var tempObj=obj;
	while (tempObj.tagName.toLowerCase()!="body" && tempObj.tagName.toLowerCase()!="html"){
		this.Left+=tempObj.offsetLeft;
		this.Top+=tempObj.offsetTop;
		tempObj=tempObj.offsetParent;
	}
}
function getNullPos()
{
   return {Left:0,Top:0}
}
function getMousePos(ev)
{
	if(ev.pageX || ev.pageY)
	{
		return {Left:ev.pageX, Top:ev.pageY};
	}
	return {
		Left:ev.clientX + document.documentElement.scrollLeft,Top:ev.clientY + document.documentElement.scrollTop
		}; 
} 
function setSelectState(state)
{
  var objl=document.getElementsByTagName('select');
  for(var i=0;i<objl.length;i++)
  {
     objl[i].style.visibility=state;
  }
}
function showMessageBox(wTitle,content,pos,wWidth,isModel)
{
   closeWindow();
   var bWidth=parseInt(document.documentElement.scrollWidth);
    var bHeight=parseInt(document.documentElement.scrollHeight);
   if(isModel)
   {
        
        if(isIe){
        
        setSelectState('hidden');}
        var back=document.createElement("div");
		back.id="back";
		var styleStr="top:0px;left:0px;position:absolute;background:#333;width:"+bWidth+"px;height:"+bHeight+"px;";
		styleStr+=(isIe)?"filter:alpha(opacity=50);":"opacity:0.5;";
		back.style.cssText=styleStr;
		document.body.appendChild(back);
	}
	   
		var mesW=document.createElement("div");
		mesW.id="mesWindow";
		mesW.innerHTML="<div style='border-bottom:#666 1px solid;'><table width='100%' height='100%'><tr><td>"+wTitle+"</td><td style='width:25px;'><a href='javascript:closeWindow();' title='关闭窗口'>关闭</a></td></tr></table></div><div style='padding:3px 0 0 0' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
		if(bWidth-pos.Left<wWidth)
		{
		   styleStr="left:"+(pos.Left-wWidth)+"px;";
		}
		else
		{
		   styleStr="left:"+(pos.Left)+"px;";
		}
		styleStr+="top:"+pos.Top+"px;position:absolute;width:"+wWidth+"px;border:#666 1px solid;background:#fff;padding:4px;";
		mesW.style.cssText=styleStr;
		document.body.appendChild(mesW);
		
}
function closeWindow()
{
    
    if(g('back')!=null)
    {
       g('back').parentNode.removeChild(g('back'));
    }
    if(g('mesWindow')!=null)
    {  
       g('mesWindow').parentNode.removeChild(g('mesWindow'));
    }
    document.documentElement.onmousedown=null;
    if(isIe){
        setSelectState('');}
}

//等待信息
function setWaitInfo(parentObjId)
{
   clearWaitInfo();
   if(!g(parentObjId)){return;}
   var newd=document.createElement("div");
   newd.id="waitInfo";
   newd.innerHTML=waitHtml;
   if(g(parentObjId).firstChild!=null)
   {
       g(parentObjId).insertBefore(newd,g(parentObjId).firstChild);
   }
   else
   {
       g(parentObjId).appendChild(newd);
   }
}
function clearWaitInfo()
{
   var newd=g("waitInfo");
   if(newd!=null)
   {
      newd.parentNode.removeChild(newd);
   }
   
   
    if(g('back')!=null)
    {
       g('back').parentNode.removeChild(g('back'));
    }
    if(g('mesWindow')!=null)
    {  
       g('mesWindow').parentNode.removeChild(g('mesWindow'));
    }
    document.documentElement.onmousedown=null;
    if(isIe){
        setSelectState('');}
}
//页面定位
function setScroll(objId)
{
   if(g(objId))
   {
      
      var objPos=new getPos(g(objId));
      scroll(0,objPos.Top);
   }
}
//ajax通用方法
function createXmlHttp(){
  var ajaxObj=null;
  if(window.ActiveXObject)
  {
     ajaxObj=new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    if(window.XMLHttpRequest){
    ajaxObj=new XMLHttpRequest();
    }
  }
  return ajaxObj;
}
function setAjax(postType,requst,postXml,isXml,waitObjId,scrollId,curBtn,resObjId,runCode,isHistory)
{   
    if(curBtn!=null){curBtn.disabled=true;}
    if(waitObjId!=null){setWaitInfo(waitObjId);}
    if(scrollId!=null)
    {
       if(scrollId=="#")
       {
          scroll(0,0);
       }else
       {
          setScroll(scrollId);
       }
    }
    var xmlHttp=createXmlHttp();
    xmlHttp.onreadystatechange=function(){backAjaxValue(xmlHttp,curBtn,resObjId,runCode,isHistory)};
    if(postType=="GET"){
		xmlHttp.open(postType,pageLinkUrl+'ajaxServer/ajax.aspx?roid='+Math.random()+'&'+requst);
		xmlHttp.send(null);
    }else
    {
        xmlHttp.open(postType,pageLinkUrl+'ajaxServer/ajax.aspx?roid='+Math.random()+'&'+requst,true);
       if(!isXml){xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");}
       xmlHttp.send(postXml);
    }
}
function backAjaxValue(xmlHttp,curBtn,resObjId,runCode,isHistory)
{
   if(xmlHttp.readyState==4)
   {
        clearWaitInfo();
		if(curBtn!=null){curBtn.disabled=false;}
		if(xmlHttp.status==200)
		{
		    if(resObjId!=null)
		    {
		      if(resObjId=='listDiv' || resObjId=='contentMiddle'){closeWindow();}
		      g(resObjId).innerHTML=xmlHttp.responseText;
		    }
		    if(runCode!=null)
		    {eval(runCode);}
		    if(isHistory){saveHistory();}
		    
		}
	}
}









function getFormXmlBySign(sign)
{
  var xmlDoc="";
    var eList=document.getElementsByTagName("input");
    for(var i=0;i<eList.length;i++)
    {                  
		if(isDataControl(eList[i].id,sign))
		{
		    var columnName=getDataColumnName(eList[i].id,sign);
		    if(eList[i].type=="checkbox" || eList[i].type=="radio")
		    {
		       if(eList[i].checked)
			   {
			      xmlDoc+="<"+columnName+">1</"+columnName+">";
			   }else
			   {  xmlDoc+="<"+columnName+">0</"+columnName+">";}
		    }else
		    {
				
				xmlDoc+="<"+columnName+"><![CDATA["+eList[i].value+"]]></"+columnName+">";		    
				columnName=null;
			}
		}			
    }
    eList=document.getElementsByTagName("select");
    for(var i=0;i<eList.length;i++)
    {                  
		if(isDataControl(eList[i].id,sign))
		{
		    var columnName=getDataColumnName(eList[i].id,sign);
			xmlDoc+="<"+columnName+"><![CDATA["+eList[i].value+"]]></"+columnName+">";		    
			columnName=null;
		}			
    }
    eList=document.getElementsByTagName("textarea");
    for(var i=0;i<eList.length;i++)
    {                  
		if(isDataControl(eList[i].id,sign))
		{
		    var columnName=getDataColumnName(eList[i].id,sign);
			xmlDoc+="<"+columnName+"><![CDATA["+eList[i].value+"]]></"+columnName+">";		    
			columnName=null;
		}			
    }
	return xmlDoc;   
}
function getFormXml()
{   
    return getFormXmlBySign('t_');
}
function isDataControl(controlId,sign){if(controlId.substring(0,sign.length)==sign){return true;}else{return false;}}
function getDataColumnName(controlId,sign){return controlId.substr(sign.length);} 