////常用函数////
function $G(id){
	return document.getElementById(id);
}

//检测浏览器类型
function is_IE(){return navigator.userAgent.indexOf("MSIE")>0;}
function is_FF(){return navigator.userAgent.indexOf("Firefox")>0;}

//---------------------------------------------------
//	打开新窗口
//---------------------------------------------------
function PopWindow(pageUrl,WinWidth,WinHeight) {
	var popwin=window.open(pageUrl,"_blank","scrollbars=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,width="+WinWidth+",height="+WinHeight);
	return false;
}

//+---------------------------------------------------
//|	打开模式窗口，返回新窗口的操作值
//+---------------------------------------------------
function PopModalWindow(url,width,height){
	var result=window.showModalDialog(url,"win","dialogWidth:"+width+"px;dialogHeight:"+height+"px;center:yes;status:no;scroll:auto;dialogHide:no;resizable:no;help:no;edge:sunken;");
	return result;
}

//检查数组中是否存在指定的值
function in_array(value, array){
	if (typeof(value) != "string" && typeof(value) != "number"){
		return false;
	}
	if (array.constructor != Array){
		return false;
	}
	for(var i in array){
		if (array[i] == value){
			return true;
		}
	}
	return false;
}

//滑动门
function tabit(btn, n){
	var idname = new String(btn.id);
	var s = idname.indexOf("_");
	var e = idname.lastIndexOf("_") + 1;
	var tabName = idname.substr(0, s);
	var id = parseInt(idname.substr(e, 1));
	for (i=0; i<n; i++){
		$G(tabName + "_div_" + i).style.display = "none";
		$G(tabName + "_btn_" + i).className = '';
	};
	$G(tabName+"_div_"+id).style.display = "block";
	btn.className = "cur";
}

//滚动
function marquee(i, direction){
	var obj = document.getElementById("marquee" + i);
	var obj1 = document.getElementById("marquee" + i + "_1");
	var obj2 = document.getElementById("marquee" + i + "_2");

	if (direction == "up"){
		if (obj2.offsetTop - obj.scrollTop <= 0){
			obj.scrollTop -= (obj1.offsetHeight + 20);
		}else{
			var tmp = obj.scrollTop;
			obj.scrollTop++;
			if (obj.scrollTop == tmp){
				obj.scrollTop = 1;
			}
		}
	}else{
		if (obj2.offsetWidth - obj.scrollLeft <= 0){
			obj.scrollLeft -= obj1.offsetWidth;
		}else{
			obj.scrollLeft++;
		}
	}
}

//屏蔽鼠标右键
function disabledRightButton(){
	document.oncontextmenu = function(e){return false;}
	document.onselectstart = function(e){return false;}
	if (navigator.userAgent.indexOf("Firefox") > -1){
		document.writeln("<style>body {-moz-user-select: none;}</style>");
	}
}
disabledRightButton();


//设为首页
function setHomePage(){
	if(is_IE()){
		var obj = document.links(0);
		if (obj){
			obj.style.behavior = 'url(#default#homepage)';
			obj.setHomePage(window.location.href);
		}
  	}else{
		if(window.netscape){
			try{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}catch (e){
				alert("此操作被浏览器拒绝！");
			}
		}
   	}
}

//加入收藏
function addFavorite(){
	var url		= document.location.href;
	var title	= document.title;
	if (document.all){
		window.external.addFavorite(url,title);
	}else if (window.sidebar){
		window.sidebar.addPanel(title, url, "");
	}
}

//复制到剪贴板
function copyToClipboard(txt) {
	if(window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
	} else if(navigator.userAgent.indexOf("Opera") != -1) {
		window.location = txt;
	} else if (window.netscape) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		} catch (e) {
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		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 = txt;
		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);
	}
	//alert("复制成功！");
}
