var sitePath = "/";
function $(id){
	if(typeof(id) == "object") return id;
	if (typeof(id) != "string" || id == "") return null;
	if (document.all) return document.all(id);
	if (document.getElementById) return document.getElementById(id);
	try {return eval(id);} catch(e){ return null;}
}

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		alert("无法创建事件！");
	}
}
function removeEvent(obj, evType, fn, useCapture){
	if (obj.removeEventListener){
		obj.removeEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.detachEvent){
		var r = obj.detachEvent("on"+evType, fn);
		return r;
	} else {
		alert("无法删除事件！");
	}
}﻿
function Event(e)
{
    var ev = !e ? window.event : e;
    return {
        pageX   : ev.pageX ? ev.pageX : ev.clientX + document.body.scrollLeft,
        pageY   : ev.pageY ? ev.pageY : ev.clientY + document.body.scrollTop
    };
}

function createXmlDocument(xmlFile){
	var xmlDom = createXMLDom();
	try{
		xmlDom.load(xmlFile);
	}catch(e){
		var xmlHttp = createXMLHttpRequest();
			xmlHttp.onreadystatechange = function(){
				if(xmlHttp.readyState == 4){
					if(xmlHttp.status == 200){
						xmlDom=xmlHttp.responseXML;
					} else {
						return false;	
					}
				}else{
					//window.state="XML文件加载中...";
				}
			}		
			xmlHttp.open("GET",xmlFile,false);
			xmlHttp.send(null);
	}
	return xmlDom;
}

function createXMLDom(){
	if (window.ActiveXObject) 
		var xmldoc=new ActiveXObject("Msxml2.DOMDocument");
	else 
		if (document.implementation&&document.implementation.createDocument)
			var xmldoc=document.implementation.createDocument("","doc",null);
	xmldoc.async = false;
	//为了和FireFox一至，这里不能改为False;
	xmldoc.preserveWhiteSpace=true;
	return xmldoc;
}
	
function createXMLHttpRequest(){
	var xmlHttp = false;
	if(window.XMLHttpRequest){
        xmlHttp = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        var ieArr = ["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
        for(var i=0; i<ieArr.length; i++)
        {
			try{
            	xmlHttp = new ActiveXObject(ieArr[i]);
				break;
			} catch(e){}
        }
    }
	return xmlHttp
}

function getDOMAtt(pNode,pAttribute){
	try{
		return pNode.attributes.getNamedItem(pAttribute).nodeValue;
	}catch(e){
		//alert("指定节点不存在，或指定属性："+pAttribute+" 不存在!")
		return false;
	}
	
}
function getNodeDepth(node)
{
	return getNodePath(node).length;
}
function getNodePath(node)
{
	var paths = new Array();
	if(node)
	{
		while(node.nodeType  == 1)
		{
			paths[paths.length] = node;
			node = node.parentNode;
		}
	}
	return paths;
}

function getPos(e) { 
    var x = e.offsetLeft;
    var y = e.offsetTop;
    while(e = e.offsetParent){
        x += e.offsetLeft;
        y += e.offsetTop;
    }
    return {"x": x, "y": y};
}

String.prototype.byteLength = function()
{
    return this.replace (/[^\x00-\xff]/g,"rr").length;
}
function inString(str1, str2)
{
    for(i=0;i<str2.length;i++)
        if (str1.indexOf(str2.charAt(i)) != -1)
            return true;
    return false;
}