var BafangwangUtil;
if(!BafangwangUtil){ BafangwangUtil = new Object;}
//oTarget：目标；sEventType：事件名称；funName：事件触发的函数名；
BafangwangUtil.addEvent=function(oTarget,sEventType,funName){
 //document.getElementById("dd").attachEvent
	if(oTarget.addEventListener){//for DOM;
		oTarget.addEventListener(sEventType,funName, false);
	}else if(oTarget.attachEvent){
		oTarget.attachEvent("on"+sEventType,funName);
	}else{
		oTarget["on"+sEventType]=funName;
	}
};
BafangwangUtil.removeEvent=function(oTarget,sEventType,funName){
 //document.getElementById("dd").attachEvent
	if(oTarget.removeEventListener){//for DOM;
		oTarget.removeEventListener(sEventType,funName, false);
	}else if(oTarget.detachEvent){
		oTarget.detachEvent("on"+sEventType,funName);
	}else{
		oTarget["on"+sEventType]=null;
	}
};
BafangwangUtil.GlobalEval = function(code){
	if(!!(window.attachEvent && !window.opera)){//ie
		execScript(code); 
	}else{//not ie
		window.eval(code);
	}
};
BafangwangUtil.addOnLoadEvent = function(func){//add body load event func is string name of the full function
	if(undefined==func){
		return;
	}
	var oldonload=window.onload;
	if(typeof window.onload!="function"){
		window.onload= new Function(func);
	}else{
		window.onload=function(){oldonload();eval(func);}
	}
};
BafangwangUtil.copy2Clipbrd = function(content){
	if(!content){content=document.location.toString();}
	var msg;
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", content);
		msg = "已经复制到系统剪贴板";
　　}else if(window.netscape) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		　　if (!clip)return;
		　　var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		　　if (!trans)return;
		　　trans.addDataFlavor('text/unicode');
		　　var str = new Object();
		　　var len = new Object();
		　　var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		　　var copytext = content;
		　　str.data = copytext;
		　　trans.setTransferData("text/unicode", str, copytext.length * 2);
		　　var clipid = Components.interfaces.nsIClipboard;
		　　if (!clip)return false;
		　　clip.setData(trans, null, clipid.kGlobalClipboard);
		} catch (e) {
	　　	alert("你使用的是Firefox 浏览器,复制功能被浏览器拒绝！n请在浏览器地址栏输入'about:config' 并回车n然后将'signed.applets.codebase_principal_support'设置为'true'");
	　　}
		msg = "已经复制到系统剪贴板";
	}else{
		msg = "您的浏览器不支持复制地址到剪贴板!";
	}
	alert(msg);
};
BafangwangUtil.setHomePage = function(obj, url){
	if(!url){url = document.location;}
	try{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(url);
	}catch(e){
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}catch (e) {
				alert("抱歉！您的浏览器不支持直接设为首页。请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”，点击“加入收藏”后忽略安全提示，即可设置成功。");  
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',url);
		}
	}
};
BafangwangUtil.addExplorerFavorite = function(title, url){//add explorer favorite link
	title = (title==undefined||title==""?document.title:title);
	url = (url==undefined||url==""?document.location:url);
	if (document.all){
		window.external.addFavorite(url,title);
	}else if(window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}else{
		alert("按 '确定' 后 再按 CTRL + d 收藏!");
	}
};
BafangwangUtil.loadCssFile = function(filename){//add explorer favorite link
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", filename); 
	document.getElementsByTagName('head')[0].appendChild(fileref);
};
function _add_element_onmouse_event(n, elname, funcover, funcout){
	var _obj  = undefined!=n ? document.getElementById(n) : undefined;
	if(_obj  != undefined){
		var els = _obj.getElementsByTagName(elname);
		for(var i=0 ; i<els.length ; i++){
			els[i].onmouseover = new Function(funcover);
			els[i].onmouseout = new Function(funcout);
		}
	}
}
function _add_detail_onmouse_event(n, funcover, funcout){
	var _obj  = undefined!=n ? document.getElementById(n) : undefined;
	if(_obj  != undefined){
		var els = _obj.getElementsByTagName("div");
		for(var i=0 ; i<els.length ; i++){
			if(els[i].id.substr(0, 8)=="EFF_div_"){
				els[i].onmouseover = new Function(funcover);
				els[i].onmouseout = new Function(funcout);
			}
		}
	}
}
