var userAgent = navigator.userAgent.toLowerCase();
var is_webtv = userAgent.indexOf('webtv') != -1;
var is_kon = userAgent.indexOf('konqueror') != -1;
var is_mac = userAgent.indexOf('mac') != -1;
var is_saf = userAgent.indexOf('applewebkit') != -1 || navigator.vendor == 'Apple Computer, Inc.';
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko' && !is_saf) && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ns = userAgent.indexOf('compatible') == -1 && userAgent.indexOf('mozilla') != -1 && !is_opera && !is_webtv && !is_saf;
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera && !is_saf && !is_webtv) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

window.addEvent('domready', function() {

   setTimeout('showtimes()',960);
});

function showtimes(){

   var now=new Date();
   var str="";
   var hour=now.getHours();
   var minutes=now.getMinutes();
   var seconds=now.getSeconds();
   str=str+hour;
   str=str+(minutes<10?":0":":")+minutes;
   str=str+(seconds<10?":0":":")+seconds;
   $('widgets').innerHTML=str;
   setTimeout('showtimes()',960);
}

function toggle_collapse(objname, noimg) {
	var obj = $(objname);
	obj.style.display = obj.style.display == '' ? 'none' : '';
	if(!noimg) {
		var img = $(objname + '_img');
		img.src = img.src.indexOf('_yes.gif') == -1 ? img.src.replace(/_no\.gif/, '_yes\.gif') : img.src.replace(/_yes\.gif/, '_no\.gif');
	}

	Cookie.set(objname, !obj.style.display, {duration: 30}); 
}

function ShowSub(id_num,num){ //舌签功能
	for(var i = 0;i <= 9;i++){
		if($("t_menu_" + id_num + i)){$("t_menu_" + id_num + i).className = '';}
		if($("t_cont_" + id_num + i)){$("t_cont_" + id_num + i).style.display = 'none';}
	}
	if($("t_menu_" + id_num + num)){$("t_menu_" + id_num + num).className = 'selected';}
	if($("t_cont_" + id_num + num)){$("t_cont_" + id_num + num).style.display = 'block';}
}

function convertdate(strdate, fmt) {
	strdate = strdate.replace(/-/ig,'/');
	var d = new Date(strdate);
	var now = new Date();
	var result;

	if (d.getYear() == now.getYear() && d.getMonth() == now.getMonth()) {
		var xday = now.getDate() - d.getDate();

		switch (xday) {
			case 0:
				result = "今天 " + d.format("hh") + ":" + d.format("mm");
				break;
			case 1:
				result = "昨天 " + d.format("hh") + ":" + d.format("mm");
				break;
			case 2:
				result = "前天 " + d.format("hh") + ":" + d.format("mm");
				break;
			default:
				result = xday + " 天前";
				break;		
		}
	} else {
		result = d.format(fmt);
	}
	
	return result;
}

function convertdate2(strdate, fmt)
{
	strdate = strdate.replace(/-/ig,'/');
	var d = new Date(strdate);
	var now = new Date();
	var result = now - d;
	if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() - d.getDate() > 0){
		result = convertdate(strdate);
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() - d.getHours() > 0){
		result = (now.getHours() - d.getHours()) + " 小时前"
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() == d.getHours() && now.getMinutes() - d.getMinutes() > 0){
		result = (now.getMinutes() - d.getMinutes()) + " 分钟前"
	} else if (now.getYear() == d.getYear() && now.getMonth() == d.getMonth() && now.getDate() == d.getDate() && now.getHours() == d.getHours() && now.getMinutes() == d.getMinutes() && now.getSeconds() - d.getSeconds()> 0){
		result = (now.getSeconds() - d.getSeconds()) + " 秒前"
	} else {
		result = convertdate(strdate, fmt);
	}
	return result;

}

Date.prototype.format = function(format) {
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(),    //day
	"h+" : this.getHours(),   //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	"S" : this.getMilliseconds() //millisecond
	};
	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;
}

function attachimg(obj, action, text) {
	if(action == 'load') {
		if(obj.width > screen.width * 0.7) {
			obj.resized = true;
			obj.width = screen.width * 0.7;
			obj.alt = text;
		}
		obj.onload = null;
	} else if(action == 'mouseover') {
		if(obj.resized) {
			obj.style.cursor = 'pointer';
		}
	} else if(action == 'click') {
		if(!obj.resized) {
			return false;
		} else {
			window.open(text);
		}
	}
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

//复制URL地址
function setCopy(_sTxt){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}

//加入收藏
function addBookmark(site, url){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.external.addFavorite(url,site)
	} else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		alert ("请使用Ctrl+T将本页加入收藏夹");
	} else {
		alert ("请使用Ctrl+D将本页加入收藏夹");
	}
}

// Set Article Font Size
function setFontSize(pt){
  try{
    var t=document.getElementById("textboxContent");
    if(t){
      t.style.fontSize=pt+"pt";
    }
  }catch(e){}
}
// 复制引用地址
function copyText(obj) 
{
var rng = document.body.createTextRange();rng.moveToElementText(obj);rng.scrollIntoView();rng.select();rng.execCommand("Copy");rng.collapse(false);
}