// tab panel change
function setTab(name, curSel, n)
{
	var i, menu, cont;
	for(i = 1; i <= n; i++)
	{
		menu = document.getElementById(name + i);
		if (!menu) continue;
		menu.className = (i == curSel) ? "selected" : "";
		cont = document.getElementById("cont_" + name + "_" + i);
		if (!cont) continue;
		cont.style.display = (i == curSel) ? "block" : "none";
	}
}
// show all tab panel content
function showAll(name, curSel, n)
{
	var i, menu, cont;
	for(i = 1; i <= n; i++)
	{
		menu = document.getElementById(name + i);
		if (!menu) continue;
		menu.className = (i == curSel) ? "selected" : "";
		cont = document.getElementById("cont_" + name + "_" + i);
		if (!cont) continue;
		cont.style.display = "block";
	}
}

function copyToClipboard(txt)
{
	if(window.clipboardData)
	{
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
		alert("已经复制，请按 Ctrl + v 粘贴到您的记事本中。");
	}
	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("已经复制，请按 Ctrl + v 粘贴到您的记事本中。");
	}
}

/*
	读取Cookie
	
	name	Cookie名称
*/
function getCookie(name)
{
	var cookieName = name + "=";
	var offset = document.cookie.indexOf(cookieName);
	if (offset != -1)
	{
		offset	+= cookieName.length;
		var end	= document.cookie.indexOf(";", offset);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(offset, end));
	}
	else return "";
	
}

/*
	写入Cookie
	
	name	Cookie名称
	value	Cookie值
	hours	Cookie失效时间
*/
function setCookie(name, value, hours)
{
	var expireDate	= new Date(new Date().getTime() + hours * 3600000);
	document.cookie	= name + "=" + escape(value) + "; expires=" + expireDate.toGMTString() ;
}

function count_up(type, id)
{
	if (type < 1 || type > 6) return;
	if (parseInt(id) < 1) return;
	
	//是否已顶踩过
	var cookieStr = getCookie(type + "(" + id + ")");
	if (cookieStr != "")
	{
		alert("您已" + cookieStr + "过了");
		return;
	}
	
	var tmp	= document.createElement('script');
	tmp.src = "/source2/count_up_down.php?action=1&type=" + type + "&id=" + id;
	tmp.type = 'text/javascript';
	
	var obj = document.getElementById("count_up");
	if (!obj) return;
	obj.innerHTML = parseInt(obj.innerHTML) + 1;
	obj.appendChild(tmp);
	
	//写入Cookie
	setCookie(type + "(" + id + ")", "顶", 12);
	alert('好文，我顶！');
}

function count_down(type, id)
{
	if (type < 1 || type > 6) return;
	if (parseInt(id) < 1) return;
	
	//是否已顶踩过
	var cookieStr = getCookie(type + "(" + id + ")");
	if (cookieStr != "")
	{
		alert("您已" + cookieStr + "过了");
		return;
	}
	
	var tmp	= document.createElement('script');
	tmp.src = "/source2/count_up_down.php?action=2&type=" + type + "&id=" + id;
	tmp.type = 'text/javascript';
	
	var obj = document.getElementById("count_down");
	if (!obj) return;
	obj.innerHTML = parseInt(obj.innerHTML) + 1;
	obj.appendChild(tmp);
	
	//写入Cookie
	setCookie(type + "(" + id + ")", "踩", 12);
	alert('烂，我踩！');
}

