﻿
var isIe=(window.ActiveXObject)?true:false;
var pageLinkUrl="";
var ajaxUrl="service/ajaxservice.aspx";
function g(nodeId)
{
   return document.getElementById(nodeId);
}
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 clearWaitInfo()
{
   var newd=g("waitInfo");
   if(newd!=null)
   {
      newd.parentNode.removeChild(newd);
   }
}
function Message(){
	this.left=0;
	this.top=0;
	this.height=0;
	this.width=0;
	this.content='';
	this.title='';
	this.isShowTitle=true;
	this.IsWait=true;
	this.sender=null;
	this.isModal=false;//是否模式显示
	this.isCenter=false;
	this.show=function(){closeMessage();
	    var pos=null;
	    if(this.sender!=null)
	    {
	       pos=new getPos(this.sender);
	       this.left=pos.Left+pos.Width;
	       this.top=pos.Top;
	    }
//	    var bWidth=parseInt(document.documentElement.scrollWidth);
//        var bHeight=parseInt(document.documentElement.scrollHeight);
        var bWidth=parseInt(document.body.offsetWidth);
        
        var bHeight=parseInt(document.body.offsetHeight);
	    var mesW=document.createElement("div");
	    if(this.isModal)
        {
            var back=document.createElement("div");
		    back.id="backW";
		    var styleStr="top:0px;left:0px;background:#eee;position:absolute;width:"+bWidth+"px;height:"+bHeight+"px;";
		    styleStr+=(isIe)?"filter:alpha(opacity=40);":"opacity:0.4;";
		    back.style.cssText=styleStr;
		    document.body.appendChild(back);
	    }
	    mesW.id="MessageW";
	    if(this.isShowTitle){
	       mesW.innerHTML+="<div class='messageTitle'><table><tr><td class='messageTitleText'>"+this.title+"</td><td class='messageTitleClose'><div onclick='closeMessage()' title='关闭'></div></td></tr></table></div>";
	     }
	    var contentStyle="";
	    if(this.height!=0)
	    {
	       contentStyle="overflow:auto;height:"+this.height+"px";
	    }
	    mesW.innerHTML+="<div id='MWContent' style='"+contentStyle+"'>";
	    mesW.innerHTML+="</div>";
	    if(!this.isCenter){
	        if(bWidth-this.left<this.width)
	        {
	           styleStr="left:"+(this.left-this.width-((this.sender==null)?0:pos.Width)-12)+"px;";
	        }
	        else
	        {
	           styleStr="left:"+(this.left+5)+"px;";
	        }
	        styleStr+="top:"+this.top+"px;";
	    }else{
	       styleStr="left:"+(bWidth-this.width)/2+"px;";
	       styleStr+="top:";
	       if(this.top>0)
	       {
	          styleStr+=this.top;
	       }else{
	          styleStr+=(document.documentElement.scrollTop+(window.screen.availHeight-this.height)/2);
	       }
	       styleStr+="px;";
	      
	    }
	    styleStr+="position:absolute;width:"+this.width+"px;";
	    
	    mesW.style.cssText=styleStr;
	    mesW.className='message';
	    document.body.appendChild(mesW);
	    if(this.content=='' && this.IsWait)
	    {
	      g('MWContent').innerHTML="<div class='MWWait'></div>";
	    }else{
	      g('MWContent').innerHTML=this.content;
	    }
	}
}
function closeMessage()
{
    if(g('MessageW')!=null)
    {  
       g('MessageW').parentNode.removeChild(g('MessageW'));
    }
    if(g('backW')!=null)
    {  
       g('backW').parentNode.removeChild(g('backW'));
    }
}
//页面定位
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 Ajax()
{
   this.httpType="GET";
   this.type="ajax";
   this.url='';
   this.param='';
   this.sender=null;
   this.container=null;
   this.runCode='';
   this.isPostXml=true;
   this.xml=null;
   this.process=function(){
     if(this.url=='')this.url=ajaxUrl;
     if(this.type=="ajax"){
          if(this.sender!=null){this.sender.disabled=true;}
          var xmlHttp=createXmlHttp();
          var t=this.container;
          var s=this.sender;
          var run=this.runCode;
          var pType=this.httpType;
          xmlHttp.onreadystatechange=function(){backAjaxValue(xmlHttp,s,t,run,'')};
          if(this.httpType=="GET"){
	            xmlHttp.open(this.httpType,this.url+'?roid='+Math.random()+'&'+this.param);
	            xmlHttp.send(null);
          }else{
          
               xmlHttp.open(this.httpType,this.url+'?roid='+Math.random()+'&'+this.param,true);
               if(!this.isPostXml)xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
               xmlHttp.send(this.xml);
          }
     }
     if(this.type=="json"){
           var js=document.createElement('script');
           js.type='text/javascript';
           js.src=this.url+'?roid='+Math.random()+'&'+this.param;
           //js.charset='UTF-8';
           js.charset='GB2312';
           document.getElementsByTagName('head')[0].appendChild(js);
     }
     
     
     
   }
}
function backAjaxValue(xmlHttp,curBtn,resObjId,runCode,onOverRunCode)
{
   
   if(xmlHttp.readyState==4)
   {
        clearWaitInfo();
		if(curBtn!=null){curBtn.disabled=false;}
		
		if(onOverRunCode!=null)eval(onOverRunCode);
		if(xmlHttp.status==200)
		{
		    var backValue=xmlHttp.responseText;
		    if(!checkErrorFromBackValue(backValue))
		    {
		       return;
		    }
		    if(resObjId!=null)
		    {
		        g(resObjId).innerHTML=xmlHttp.responseText;
		    }
		    if(runCode!=null)
		    {
		    var backValue=xmlHttp.responseText;
		    eval(runCode);}
		}
	}
}
function checkErrorFromBackValue(bakValue)
{
   if(bakValue!=null)
   {
      if(bakValue.indexOf('error_')==0)
      {
         if(bakValue.length>6)
         {bakValue=bakValue.substr(6);}
         else{bakValue='程序发生了未知错误，请再次尝试！';}
         alert(bakValue);
         return false;
      }
       return true;
   }
   return true;
}








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 '<table>'+xmlDoc+'</table>';   
}
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);} 

//非法字符过滤
function is_forbid(temp_str)
{
    temp_str=trimTxt(temp_str);
	temp_str = temp_str.replace('*',"@");
	temp_str = temp_str.replace('-',"@");
	temp_str = temp_str.replace('/',"@");
	temp_str = temp_str.replace('+',"@");
	temp_str = temp_str.replace('\'',"@");
	temp_str = temp_str.replace('\\',"@");
	temp_str = temp_str.replace('$',"@");
	temp_str = temp_str.replace('^',"@");
	temp_str = temp_str.replace('.',"@");
	temp_str = temp_str.replace('(',"@");
	temp_str = temp_str.replace(')',"@");
	//temp_str = temp_str.replace(',',"@");
	temp_str = temp_str.replace(';',"@");
	temp_str = temp_str.replace('<',"@");
	temp_str = temp_str.replace('>',"@");
	//temp_str = temp_str.replace('?',"@");
	temp_str = temp_str.replace('"',"@");
	temp_str = temp_str.replace('{',"@");
	temp_str = temp_str.replace('}',"@");
	temp_str = temp_str.replace('[',"@");
	temp_str = temp_str.replace(']',"@");
	var forbid_str=new String('@,#,%,~,&');
	var forbid_array=new Array();
	forbid_array=forbid_str.split(',');
	for(i=0;i<forbid_array.length;i++)
	{
		if(temp_str.search(new RegExp(forbid_array[i])) != -1)
		return false;
	}
	return true;
}
function checknumber(String) 
{ 
    var Letters = "1234567890"; 
    var i; 
    var c; 
    for( i = 0; i < String.length; i ++ ) 
    { 
        c = String.charAt( i ); 
        if (Letters.indexOf( c ) ==-1) 
        { 
           return false; 
        } 
    } 
    return true; 
} 
function trimTxt(txt)
{
   return txt.replace(/(^\s*)|(\s*$)/g, "");
}
//检查是否为空
function isEmpty(inputId)
{
   if(trimTxt(g(inputId).value)==''){return true}
   return false;
}
//设置是否可显示
function setDisplay(nodeId,state)
{
   if(g(nodeId)!=null){g(nodeId).style.display=state;}
}
//删除元素
function removeNode(nodeId)
{
   if(g(nodeId)!=null){g(nodeId).parentNode.removeChild(g(nodeId));}
}

//显示提示信息
function showAlert(info,obj,infoSign)
{
   if(g(infoSign)!=null){return;}
   var newd=document.createElement("span");
   newd.id=infoSign;
   newd.className='alertInfo';
   newd.innerHTML=info;
   obj.appendChild(newd);
}
//删除提示信息
function removeAlert(infoSign)
{
   if(g(infoSign)==null){return;}
   g(infoSign).parentNode.removeChild(g(infoSign));
}
//显示等待信息
function showWaitInfo(info,obj)
{
   try{
   if(obj==null)return;
   clearWaitInfo();
   var newd=document.createElement("span");
   newd.className='waitInfo';
   newd.id='waitInfo';
   newd.innerHTML=info;
   obj.parentNode.appendChild(newd);
   }catch(e){}
}
function showWaitInfoOnInner(info,obj)
{
   try{
   if(obj==null)return;
   clearWaitInfo();
   var newd=document.createElement("span");
   newd.className='waitInfo';
   newd.id='waitInfo';
   newd.innerHTML=info;
   obj.innerHTML='';
   obj.appendChild(newd);
   }catch(e){}
}
function clearWaitInfo()
{
   try{
   if(g('waitInfo')!=null){g('waitInfo').parentNode.removeChild(g('waitInfo'));}
   }catch(e){}
}
//设置radio的默认值
function setRadioDefaultItem(radioName,valueId)
{
   var rList=document.getElementsByName(radioName);
   if(rList.length==0){return;}
   for(var i=0;i<rList.length;i++)
   {
      if(rList[i].checked)
      {
          return;
      }
   }
   rList[0].click();
   g(valueId).value=rList[0].value;
}
