// 让Mozilla支持innerText
try{
	HTMLElement.prototype.__defineGetter__
	(
	'innerText',
	function ()
	{
		var anyString = '';

		var childS = this.childNodes;
			for(var i=0; i<childS.length; i++)
			{
				if(childS[i].nodeType==1)
				anyString += childS[i].tagName=='BR' ? '\n' : childS[i].innerText;
				else if(childS[i].nodeType==3)
				anyString += childS[i].nodeValue;
			}
			return anyString;
	}
	); 
}
catch(e){}

// IE6背景缓存
try {
	document.execCommand('BackgroundImageCache', false, true);
} catch(e) {}

//去掉链接虚线
//function bluring(){
//if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus();
//}
//document.onfocusin=bluring;



var
// 定义Cookie域
NameSpace = 'Mudoo',



// 用ID获取元素
$ = function(element) {
	return typeof(element) == 'object' ? element : document.getElementById(element);
},

// 用Tag获取元素
$t = function(tag, efrom) {
	return efrom == undefined ? document.getElementsByTagName(tag) : efrom.getElementsByTagName(tag);
},

// 用Class获取元素
$c = getElementsByClassName = function(className, parentElement) {
	var elems = ($(parentElement)||document.body).getElementsByTagName("*");
	var result=[];
	for (i=0; j=elems[i]; i++){
	   if ((" "+j.className+" ").indexOf(" "+className+" ")!=-1){
			result.push(j);
	   }
	}
	return result;
},

// 判断浏览器
brower = function() {
	var ua = LCase(navigator.userAgent);
	var os = new Object();
	os.isFirefox = ua.indexOf ('gecko') != -1;
	os.isOpera = ua.indexOf ('opera') != -1;
	os.isIE = !os.isOpera && ua.indexOf ('msie') != -1;
	os.isIE7 = os.isIE && ua.indexOf ('7.0') != -1;
	return os;
},

// 获取传递参数
request = function(strName) {
	var strHref = self.location.toString();
	var intPos = strHref.indexOf('?');
	var strRight = strHref.substr(intPos + 1);
	
	var arrTmp = strRight.split('&');
	for(var i = 0; i < arrTmp.length; i++) {
		var arrTemp = arrTmp[i].split('=');
		if(LCase(arrTemp[0]) == LCase(strName)) return arrTemp[1];
	}
	return '';
},




// 获取鼠标位置
/*
getXY = function (e) {
	var XY;
	if(brower().isIE) XY = new Array(event.clientX, event.clientY);
	if(!brower().isIE) XY = new Array(e.pageX, e.pageY);
	return XY;
},
*/
getXY = function (e){
	var XY;
	if(brower().isIE){
		var scrollPos;
		if (typeof window.pageYOffset != 'undefined'){
			scrollPos ={
				x : window.pageXOffset, y : window.pageYOffset
			};
		}else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat'){
			scrollPos ={
				x : document.documentElement.scrollLeft, y : document.documentElement.scrollTop
			};
		}else if(typeof document.body != 'undefined'){
			scrollPos ={
				x : document.body.scrollLeft, y : document.body.scrollTop
			};
		}
		XY ={
			x : window.event.clientX + scrollPos.x - document.body.clientLeft,
			y : window.event.clientY + scrollPos.y - document.body.clientTop
		};
	}else{
		XY ={
			x: e.pageX, y: e.pageY
		};
	}
	return XY;
},

// 获取元素坐标
/*
getPlace = function(e){
	var _left = e.offsetLeft; 
	var _top = e.offsetTop; 
	if(e.offsetParent!=null) {
		_left += getPlace(e.offsetParent)[0]; 
		_top += getPlace(e.offsetParent)[1];
	}
	return new Array(_left, _top); 
},
*/
getCoords = function(node){
	var x = node.offsetLeft;
	var y = node.offsetTop;
	var parent = node.offsetParent;
	while (parent != null){
		x += parent.offsetLeft;
		y += parent.offsetTop;
		parent = parent.offsetParent;
	}
	return {x: x, y: y};
},


// Open Dialog
showDialogs = function(url,width,height) {
	var dialogWin = null;
	if(brower().isIE) {
		dialogWin = window.showModelessDialog(url,window, 'dialogWidth:'+width+'px;dialogHeight:'+height+'px;edge:Raised;center:1;help:0;status:0;resizable:1;');
	}else{
		var left = screen.availWidth/2 - width/2;
		var top = screen.availHeight/2 - height/2;
		dialogWin = window.open(url, "", "dependent=yes,width="+width+"px,height="+height+"px,left="+left+",top="+top);
	}
	return dialogWin;
},
showDialog = function(url,width,height) {
	var dialogWin = null;
	if(brower().isIE) {
		dialogWin = window.showModalDialog(url,window, 'dialogWidth:'+width+'px;dialogHeight:'+height+'px;edge:Raised;center:1;help:0;resizable:1;');
	}else{
		var left = screen.availWidth/2 - width/2;
		var top = screen.availHeight/2 - height/2;
		dialogWin = window.open(url, "", "width="+width+"px,height="+height+",left="+left+",top="+top);
		
		function addFocus() {
			if(dialogWin.closed == false){
				dialogWin.focus();
			}
		}
		myAddEventListener(window, 'focus', addFocus);
	}
	return dialogWin;
},
windowOpen = function(url,win,width,height) {
	return window.open(url,win,'width='+width+'px,height='+height+'px;toolbar=no,menubar=no,location=no,directories=no,status=yes');
},





ClassAjax = {
	Created : false,
	ajax : null,
	error : new Array('Ajax对象没有被创建!','参数错误'),
	$ : function(id){
		return document.getElementById(id);
	},
	InitAjax : function(){
		var ajax = false;
		try{
			ajax = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
				ajax = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e){
				try{
					ajax = new XMLHttpRequest();
				}
				catch(e){
					ajax = false;
				}
			}
		}
		return ajax;
	},
	CreateAjax : function(){
		ClassAjax.ajax = ClassAjax.InitAjax();
		ClassAjax.Created = true;
	},
	Send : function(method,sendstr,action,callbackfunc,errfunc){
		if(!ClassAjax.Created){
			alert(ClassAjax.error[0]);
			return;
		}
		if(!method || !action || typeof callbackfunc != "function" || typeof errfunc != "function"){
			alert("Function:SendData()" + ClassAjax.error[1]);
			return;
		}
		var ajax = this.ajax;
		var method = method.toUpperCase();
		if(method == "POST"){
			ajax.open(method,action,true);
			ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			ajax.send(sendstr);
			ajax.onreadystatechange = function(){
				if(ajax.readyState == 4){
					if(ajax.status == 200){
						callbackfunc();
					}
					else{
						errfunc();
					}
				}
			}
		}
		if(method == "GET"){
			var action = ClassAjax.InitUrl(action,sendstr);
			ajax.open(method,action,true);
			ajax.onreadystatechange = function(){
				if(ajax.readyState == 4){
					if(ajax.status == 200){
						callbackfunc();
					}
					else{
						errfunc();
					}
				}
			}
			ajax.send(null);
		}
	},
	InitUrl : function(url,sendstr){
		if(!ClassAjax.Created){
			alert(ClassAjax.error[0]);
			return;
		}
		if(!url || !sendstr){
			alert("Function InitUrl()" + ClassAjax.error[1]);
			return;
		}
		var url = url.split("?");
		if(url[1] == "" || typeof url[1] == "undefined"){
			url = url[0] + "?" + sendstr;
		}
		else{
			url = url[0] + url[1] + "&" + sendstr;
		}
		return url;
	},
	GetText : function(){
		if(!ClassAjax.Created){
			alert(ClassAjax.error[0]);
			return;
		}
		var ajax = this.ajax;
		var strText = ajax.responseText;
		return strText;
	}
}
//	子菜单显示隐藏
var doHide = null;
var prvMenu = prvSubMenu = null;
function showMenu(menu, e) {
	clearTimeout(doHide);
	menu = $(menu);
	if(menu==null) return;
	if(prvSubMenu!=null && prvSubMenu!=menu) hideMenu(prvSubMenu.id, true);
	
	if(e!=undefined) {
		var XY = getCoords(e);
		e.style.cssText = 'color: #333333; font-weight: bold';
		prvMenu = e;
		menu.style.left = XY.x +'px';
		menu.style.top = XY.y +'px';
		menu.style.display = '';
		prvSubMenu = menu;
	}
	menu.onmouseover = function() {
		showMenu(this);
	}
	menu.onmouseout = function() {
		hideMenu(this);
	}
}

function hideMenu(menu, t) {
	menu = $(menu);
	if(menu==null) return;
	if(!t) {
		doHide = setTimeout('hideMenu("'+ menu.id +'", true)', 500);
		return;
	}
	if(prvMenu!=null) prvMenu.style.cssText = '';
	menu.style.display = 'none';
	prvMenu = prvSubMenu = null;
}