////常用函数////
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 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 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 GetParentNode(obj, tag){
	while(obj.parentNode && obj.tagName.toLowerCase() != tag){
		obj	= obj.parentNode;
	}
	return obj;
}

//获取下一个节点
function nextsibling(obj){
	var	obj	= obj.nextSibling;
	while(obj.nodeType != 1){
		obj	= obj.nextSibling;
	}
	return obj;
}

//全选
function CheckAll(strSection, obj){
	var	colInputs = document.getElementById(strSection).getElementsByTagName("input");
	for	(var i=0; i < colInputs.length; i++){
		colInputs[i].checked = obj.checked;
	}
}
//获取选中的选择框对象值组成字符串
function getSelectCheckboxValues(){
	var obj = document.getElementsByName('ids');
	var result ='';
	for (var i=0; i<obj.length; i++){
		if (obj[i].checked==true){
			result += "," + obj[i].value;
		}
	}
	return result.substring(1);
}

//获取扩展名
function getFileExt(filename){
	var dot	= filename.lastIndexOf(".");
	if (dot >= 0){
		return filename.substr(dot + 1).toLowerCase();
	}else{
		return "";
	}
}

//检查数组中是否存在指定的值
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";
}

Date.prototype.format = function(format) {
	var o = {
		"M+": this.getMonth() + 1,
		"d+": this.getDate(),
		"h+": this.getHours(),
		"m+": this.getMinutes(),
		"s+": this.getSeconds(),
		"q+": Math.floor((this.getMonth() + 3) / 3),
		"S": this.getMilliseconds()
	};
	if (/(y+)/.test(format)){
		format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) if (new RegExp("(" + k + ")").test(format)){
		format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
	}
	return format;
}

// select的 hidden/visible
function hideSelects(visibility){
	selects = document.getElementsByTagName('select');
	for(i = 0; i < selects.length; i++) {
		selects[i].style.visibility = visibility;
	}
}

//设置Cookies
function getcookie(name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}

//设置Cookies
function setcookie(cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds * 1000);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? ';expires=' + expires.toGMTString() : '')
		+ (path ? ';path=' + path : '/')
		+ (domain ? ';domain=' + domain : '')
		+ (secure ? ';secure' : '');
}

//+---------------------------------------------------
//| 页面内容滚动JS文件。
//| lh:     每次滚动的高度
//| speed:  滚动速度
//| delpay: 停留时间
//| id:     滚动的标签
//+---------------------------------------------------
function startmarquee(lh,speed,delay,id){
    var t;
    var p = false;
    var o = document.getElementById(id);
    o.innerHTML += o.innerHTML;
    o.onmouseover = function(){p=true}
    o.onmouseout = function(){p=false}
    o.scrollTop = 0;
    function start(){
        t=setInterval(scrolling,speed);
        if(!p) o.scrollTop += 2;
    }

    function scrolling(){
        if(o.scrollTop%lh!=0){
            o.scrollTop += 2;
            if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0;
        }else{
            clearInterval(t);
            setTimeout(start,delay);
        }
    }
    setTimeout(start,delay);
}

//滚动
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 reImgSize(img, w, h){
	if(w > 0 && img.width > w){
		img.height = img.height * w / img.width;
		img.width = w;
	}
	if(h > 0 && img.height > h){
		img.width = img.width * h / img.height;
		img.height = h;
	}
}

//文件下载
function down(id){
	return PopModalWindow('confirm.php?table_name=news_info&field_name=file1&id='+id, 350, 180);
}
