// JavaScript Document
var base="/";

function replyArticle(groupId, menuId,articleId) {
	document.location = "/ArticleWrite.tr?groupId=" + groupId + "&menuId=" + menuId+"&replyId="+articleId+"&mode=n";
}

function writeArticle(groupId, menuId) {
	document.location = "/ArticleWrite.tr?groupId=" + groupId + "&menuId=" + menuId+"&mode=n";
}

function modifyArticle(groupId,menuId,articleId){
	document.location="/ArticleWrite.tr?groupId="+groupId+"&menuId="+menuId+"&id="+articleId+"&mode=m";
}

function previousArticle(groupId,menuId,cId){
	if(Browser.Engine.trident){
		var alink=document.createElement("A");
		alink.href="/ArticlePrevNextRead.tr?groupId="+groupId+"&menuId="+menuId+"&id="+cId+"&direction=prev";
		document.body.appendChild(alink);
		alink.click();
	}else{
		document.location="/ArticlePrevNextRead.tr?groupId="+groupId+"&menuId="+menuId+"&id="+cId+"&direction=prev";
	}
}
function nextArticle(groupId,menuId,cId){
	if(Browser.Engine.trident){
		var alink=document.createElement("A");
		alink.href="/ArticlePrevNextRead.tr?groupId="+groupId+"&menuId="+menuId+"&id="+cId+"&direction=next";
		document.body.appendChild(alink);
		alink.click();
	}else{
		document.location="/ArticlePrevNextRead.tr?groupId="+groupId+"&menuId="+menuId+"&id="+cId+"&direction=next";
	}
}

function goToDirectory(groupId,menuId){
	document.location="/ArticleList.tr?groupId="+groupId+"&menuId="+menuId;
}

function deleteThisArticle(groupId,menuId,articleId){
	if(window.confirm("您确定要删除这篇文章吗?")){
		document.location="/ArticleDelete.tr?groupId="+groupId+"&menuId="+menuId+"&articleIds="+articleId;
	}
}

function checkAll(obj, containerId) {
	var chks = $(containerId).getElementsByTagName("input");
	if (chks != null) {
		for (i = 0; i < chks.length; i++) {
			chks[i].checked = obj.checked;
		}
	}
}
function deleteArticle(formId) {
	var chks = $(formId).getElementsByTagName("input");
	var count = 0;
	for (i = 0; i < chks.length; i++) {
		if (chks[i].checked) {
			count++;
		}
	}
	if (count == 0) {
		alert("\u8bf7\u9009\u62e9\u8981\u5220\u9664\u7684\u6587\u7ae0");
		return false;
	} else {
		really = window.confirm("\u60a8\u771f\u7684\u8981\u5220\u9664\u8fd9\u4e9b\u6587\u7ae0\u5417");
		if (really) {
			$(formId).submit();
		} else {
			return false;
		}
	}
}
function deleteNotice(groupId, menuId, articleId) {
	document.location="/NoticeDelete.tr?groupId="+groupId+"&menuId="+menuId+"&id="+articleId;
}

function isNum(str) {
	var patrn = /^[0-9]+$/;
	if (patrn.test(str)) {
		return true;
	} else {
		return false;
	}
}

function slideShow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var features = "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",toolbar=no,menubar=no,location=no,scrollbars=no";
	window.open(url, "_blank", features);
}

function resizeImage(img, nWidth, nHeight) {
	oWidth = img.width;
	oHeight = img.height;
	if (oWidth > nWidth) {
		var r = oWidth / nWidth;//scale
		oWidth = nWidth;
		oHeight = oHeight / r;
		if (oHeight > nHeight) {
			var r2 = oHeight / nHeight;
			oHeight = nHeight;
			oWidth = oWidth / r2;
		}
	} else {
		if (oHeight > nHeight) {
			var r = oHeight / nHeight;//scale
			oHeight = nHeight;
			oWidth = oWidth / r;
			if (oWidth > nWidth) {
				var r2 = oWidth / nWidth;
				oWidth = nWidth;
				oHeight = oHeight / r2;
			}
		}
	}
	img.width = parseInt(oWidth);
	img.height = parseInt(oHeight);
}
function mousePosition(ev) {
	if (ev.pageX || ev.pageY) {
		return {x:ev.pageX, y:ev.pageY};
	}
	return {x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, y:ev.clientY + document.body.scrollTop - document.body.clientTop};
}
function getAbsPoint(e) {
	var x = e.offsetLeft, y = e.offsetTop;
	while (e = e.offsetParent) {
		x += e.offsetLeft;
		y += e.offsetTop;
	}
	return {"x":x, "y":y};
}
function copyUrl(url) {
	copyToClipboard(url);
	return false;
}
function copyToClipboard(txt) {
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
		alert("\u590d\u5236\u5b8c\u6bd5");
	} else {
		if (navigator.userAgent.indexOf("Opera") != -1) {
			window.location = txt;
			alert("\u590d\u5236\u5b8c\u6bd5");
		} else {
			if (window.netscape) {
				try {
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				}
				catch (e) {
					alert("\u6b64\u64cd\u4f5c\u88ab\u6d4f\u89c8\u5668\u62d2\u7edd\uff01\n\u8bf7\u5728\u6d4f\u89c8\u5668\u5730\u5740\u680f\u8f93\u5165\u201cabout\uff1aconfig\u201d\u8bf7\u56de\u8f66\n\u7136\u540e\u5c06[signed.applets.codebase_principal_support]\u8bbe\u7f6e\u4e3a'true'");
				}
				try {
					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("\u590d\u5236\u5b8c\u6bd5");
				}
				catch (e) {
				}
			}
		}
	}
	return true;
}
function openAttachmentWindow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var features = "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",toolbar=no,menubar=no,location=no,scrollbars=no";
	window.open(url, "_blank", features);
}

function openAttachmentWindow2(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var features = "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",toolbar=no,menubar=no,location=no,scrollbars=yes";
	window.open(url, "_blank", features);
}

function _G(arg1, arg2) {
	return arg1.getElementsByTagName(arg2);
}
function openWindow(url, width, height) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	var features = "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",toolbar=no,menubar=no,location=no,scrollbars=yes";
	window.open(url, "_blank", features);
}
String.prototype.len = function () {
	return this.replace(/[^\x00-\xff]/g, "rr").length;
};
String.prototype.sub = function (n) {
	var r = /[^\x00-\xff]/g;
	if (this.replace(r, "mm").length <= n) {
		return this;
	}
	var m = Math.floor(n / 2);
	for (var i = m; i < this.length; i++) {
		if (this.substr(0, i).replace(r, "mm").length >= n) {
			return this.substr(0, i);
		}
	}
	return this;
};

function showHideMenuListType(obj){
	menuListTypeDiv=$('menu-list-type');
	pos=getAbsPoint(obj);
	menuListTypeDiv.setStyles({
		'position':'absolute',
		'top':pos.y+30+"px",
		'left':(pos.x-100)+"px"
	});
	menuListTypeDiv.style.display=menuListTypeDiv.style.display=="block"?"none":"block";
}

