function $(id){
	if(document.getElementById(id)==null)
		return document.getElementsByName(id);
	else
		return document.getElementById(id);
}

function $$(tagName)
{
	return document.getElementsByTagName(tagName);
}
function $F(id)
{
	return $(id).value;
}

function $I(id)
{
	return $(id).innerHTML;
}

//判断是否为空
function $N(id)
{
	if($F(id)==""||$F(id)==null)
		return true;
	else
		return false;
}

//设置隐藏

function $H(id){
	$(id).style.display="none";
}

//设置显示
function $S(id)
{
	$(id).style.display = "block";
}

//设置焦点
function $FC(id)
{
	$(id).focus();
}


//Ajax调试
window.AjaxProDEBUG = true;
function showAjaxProError(error, customMessage)
{
	if(!window.AjaxProDEBUG) {
		var msg = !customMessage ? error.Message : customMessage;
		alert("系统错误\n\n" + msg); 
	} 
	else {
		var win = window.open("AjaxProError", "");
		var doc = win.document; 
		doc.write("<html><head><title>AjaxProError:")
		doc.write(error.Type);
		doc.write("</title></head><body><div><h3>");
		doc.write("AjaxPro 调用发生未处理的异常");
		doc.write("</h3>");
		doc.write("<pre>");
		doc.write("Type" + ":\n " + error.Type + "\n"); // 异常类型
		doc.write("Message" + ":\n " + error.Message + "\n"); // 异常信息 
		doc.write("Stack" + ":\n" + error.Stack + "\n"); // 堆栈跟踪
		doc.write("TargetSite" + ":\n " + error.TargetSite + "\n"); // 引发异常的方法
		doc.write("Source" + ":\n " + error.Source + "\n"); // 导致异常的对象 
		doc.write("</pre>"); 
		doc.write((new Date()).toLocaleString());
		doc.write("<br/><br/>");
		doc.write("<input type='button' value='close' onclick='window.close()' />");
		doc.write("</div>");
		doc.close();
	}
	return false; 
}

//载入过程
function Loading(id){
	var loadImg = "images/loding_ico02.gif";
	obj = $(id);
	obj.innerHTML = "<div id='loadingStatus' style='text-align:center; line-height:22px; height:22px; marging:0px;padding:0px;'><img style='border:0px;margin:0px;padding:0px;' id='loadingImg' src='"+ loadImg +"' /> 数据载入中，请稍侯...</div>";
}

//载入过程
function LoadingMsg(id,msg){
	var loadImg = "images/loding_ico02.gif";
	obj = $(id);
	obj.innerHTML = "<div id='loadingStatus' style='text-align:center; line-height:22px; height:22px; marging:0px;padding:0px;'><img style='border:0px;margin:0px;padding:0px;' id='loadingImg' src='"+ loadImg +"' /> "+ msg +"</div>";
}

//格式化数字为n为小数
function FormatNumber(srcStr,nAfterDot){
　　var srcStr,nAfterDot;
　　var resultStr,nTen;
　　srcStr = ""+srcStr+"";
　　strLen = srcStr.length;
　　dotPos = srcStr.indexOf(".",0);
　　if (dotPos == -1){
　　　　resultStr = srcStr+".";
　　　　for (i=0;i<nAfterDot;i++){
　　　　　　resultStr = resultStr+"0";
　　　　}
　　　　return resultStr;
　　}
　　else{
　　　　if ((strLen - dotPos - 1) >= nAfterDot){
　　　　　　nAfter = dotPos + nAfterDot + 1;
　　　　　　nTen =1;
　　　　　　for(j=0;j<nAfterDot;j++){
　　　　　　　　nTen = nTen*10;
　　　　　　}
　　　　　　resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　　　　return resultStr;
　　　　}
　　　　else{
　　　　　　resultStr = srcStr;
　　　　　　for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　　　　resultStr = resultStr+"0";
　　　　　　}
　　　　　　return resultStr;
　　　　}
　　}
}

//检测浏览器版本
// code from Browser Detect Lite  v2.1
// http://www.dithered.com/javascript/browser_detect/index.html
// modified by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
// modified by Michael Lovitt to include OmniWeb and Dreamcast
// modified by Jemima Pereira to detect only relevant browsers


function BrowserDetectXLite() {
	var ua = navigator.userAgent.toLowerCase(); 
	this.ua = ua;

	// browser name
	this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) ); 
	this.isOpera	=  ( (ua.indexOf("msie") == -1) && (ua.indexOf("opera") != -1) && (ua.indexOf("webtv") != -1) ); 
    this.isSafari   = (ua.indexOf('safari') != - 1);
    this.isFirefox   = (ua.indexOf('firefox') != - 1);

	// browser version
	this.versionMinor = parseFloat(navigator.appVersion); 
	
	// correct version number for IE4+ 
	if (this.isIE && this.versionMinor >= 4) {
		this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	}
	
	this.versionMajor = parseInt(this.versionMinor); 
	
	// platform
	this.isWin   = (ua.indexOf('win') != -1);
	this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1) );
	this.isMac   = (ua.indexOf('mac') != -1);

	this.isIE4x = (this.isIE && this.versionMajor == 4);
	this.isIE4up = (this.isIE && this.versionMajor >= 4);
	this.isIE5x = (this.isIE && this.versionMajor == 5);
	this.isIE55 = (this.isIE && this.versionMinor == 5.5);
	this.isIE5up = (this.isIE && this.versionMajor >= 5);
	this.isIE6x = (this.isIE && this.versionMajor == 6);
	this.isIE6up = (this.isIE && this.versionMajor >= 6);
	
	this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browser = new BrowserDetectXLite();
//end of browser detector

function MoveLayer(x, y, id){
	
	//firfox
    if (document.layers){
        document.layers[''+id+''].left = x;
        document.layers[''+id+''].top = y;
    }
    //IE
    else if (document.all){
        document.all[''+id+''].style.left=x;
        document.all[''+id+''].style.top=y;
    }
    //IE
    else if (document.getElementById){
        document.getElementById(''+id+'').style.left=x+"px";
        document.getElementById(''+id+'').style.top=y+"px";
    }
}

//记录日志
function Log(msg,loger,level){
	LanYu.Org.BLL.Loger.Log(msg,loger,level);
}

//回车的时候转到控件ID
function KeyDown(id,e)
{
	evt = e ? e : window.event;
	if(e.keyCode==13)
		$FC(id)
}


//
function AppendListener(_id,_event,_fun)
{
	if($(_id).addEventListener){
		$(_id).addEventListener(_event,_fun,false)
	}
	else{
		$(_id).attachEvent(_event,_fun)	
	}
}



if(!document.all)
{
	XMLDocument.prototype.loadXML = function(xmlString)
    {
        var childNodes = this.childNodes;
        for (var i = childNodes.length - 1; i >= 0; i--)
            this.removeChild(childNodes[i]);

        var dp = new DOMParser();
        var newDOM = dp.parseFromString(xmlString, "text/xml");
        var newElt = this.importNode(newDOM.documentElement, true);
        this.appendChild(newElt);
    };

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var oNSResolver = this.createNSResolver(this.documentElement)
          var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                       XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)
          var aResult = [];
          for( var i = 0; i < aItems.snapshotLength; i++)
          {
             aResult[i] =  aItems.snapshotItem(i);
          }
          return aResult;
       }

       // prototying the Element
       Element.prototype.selectNodes = function(cXPathString)
       {
          if(this.ownerDocument.selectNodes)
          {
             return this.ownerDocument.selectNodes(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

    // check for XPath implementation
    if( document.implementation.hasFeature("XPath", "3.0") )
    {
       // prototying the XMLDocument
       XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
       {
          if( !xNode ) { xNode = this; } 
          var xItems = this.selectNodes(cXPathString, xNode);
          if( xItems.length > 0 )
          {
             return xItems[0];
          }
          else
          {
             return null;
          }
       }
       
       // prototying the Element
       Element.prototype.selectSingleNode = function(cXPathString)
       {    
          if(this.ownerDocument.selectSingleNode)
          {
             return this.ownerDocument.selectSingleNode(cXPathString, this);
          }
          else{throw "For XML Elements Only";}
       }
    }

}