var contextPath = "";
var debug = false;
/**
 * 定义常量 用于添加收藏等信息
 */
var LOGIN = 0;
var SUCCESS = 1;
var ADDED = 2;
function getOs() {
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		return "MSIE";
	}
	if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
		return "Firefox";
	}
	if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
		return "Safari";
	}
	if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
		return "Camino";
	}
	if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
		return "Gecko";
	}
}

/*---
 validate email on client;
 如果验证不同过 返回提示字符
 */
function validateEmail(email) {
	var errorMsg = null;
	if (email == null || email == ""
			|| email.replace(/^\s+|\s+$/g, "").length == 0) {
		errorMsg = "请您输入email地址!";
	} else {
		email = email.replace(/^\s+|\s+$/g, "");
		if (!email.match("(\\w{4,64})")) {
			errorMsg = "您输入的必须是字母和数字，长度在4位和64位之间";
		} else {
			if (!email
					.match(/\b(^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-])+(\.[A-Za-z0-9-]+)*((\.[A-Za-z0-9]{2,})|(\.[A-Za-z0-9]{2,}\.[A-Za-z0-9]{2,}))$)\b/gi)) {
				errorMsg = "您必须输入有效的电子邮件地址";
			} else {
				if (email.length < 6 || email.length > 64) {
					errorMsg = "email地址的长度必须在6和64个字符之间!";
				}
			}
		}
	}
	return errorMsg;
}
/**
 * 公用的显示错误信息的对话框
 */
function showInfo(msg) {
	if (msg == null || msg == "") {
		return;
	}
	showCap();
	var divObj = getInfoDiv(400, 160, "信息提示");
	divObj.innerHTML = "<p>"
			+ msg
			+ "<br><a class=\"winBtn\" href=\"javascript:void(null);\"  onclick='closePop()'>确&nbsp;定</a></p>";
}

function showTipsInfo(msg) {
	if (msg == null || msg == "") {
		return;
	}
	showCap();
	var divObj = getInfoDiv(300, 120, "信息提示");
	divObj.innerHTML = "<p>"
			+ msg
			+ "<br></p>";
}

function getInfoDiv(infoWidth, infoHeight, title) {
	if (title == null) {
		title = "音悦台";
	}
	var arrySize = getPageSize();
	var infoDiv = document.getElementById("infoDiv");
	if (infoDiv == null) {
		infoDiv = document.createElement("div");
		infoDiv.id = "infoDiv";
		document.body.appendChild(infoDiv);

		var infoHead = document.createElement("div");
		infoHead.id = "infoHead";
		infoHead.className = "infoHead";
		infoHead.innerHTML = title;
		infoDiv.appendChild(infoHead);

		var closeSpan = document.createElement("span");
		closeSpan.id = "closeSpan";
		closeSpan.className = "closeSpan";
		closeSpan.innerHTML = "&nbsp;";
		closeSpan.onclick = closePop;
		infoHead.appendChild(closeSpan);
		var infoContent = document.createElement("div");
		infoContent.id = "infoContent";
		infoDiv.appendChild(infoContent);
	}
	var infoHead = document.getElementById("infoHead");
	var closeSpan = document.getElementById("closeSpan");
	if (infoHead != null) {
		infoHead.innerHTML = title;
		infoHead.appendChild(closeSpan);
	}
	infoDiv.style.left = (document.documentElement.scrollLeft + (arrySize[0] - infoWidth)
			/ 2)
			+ 'px';
	infoDiv.style.top = (document.documentElement.scrollTop + (arrySize[3] - infoHeight)
			/ 2)
			+ 'px';
	infoDiv.style.height = infoHeight + "px";
	infoDiv.style.width = infoWidth + "px";
	infoDiv.className = "infoShow";
	return document.getElementById("infoContent");
}
/**
 *
 * 用于显示登陆框和ajax
 *
 */
function showCap() {
	var arrySize = getPageSize();
	var capDivObj = document.getElementById("capDiv");
	if (capDivObj == null) {
		capDivObj = document.createElement("div");
		capDivObj.id = "capDiv";
		document.body.appendChild(capDivObj);
	}
	capDivObj.className = "capDivShow";
	capDivObj.style.width = arrySize[0] + "px";
	capDivObj.style.height = arrySize[1] + "px";
	capDivObj.style.top = "0px";
	capDivObj.style.left = document.documentElement.scrollLeft + "px";
}
function showLogin() {
	showCap();
	var infoDiv = getInfoDiv(490, 160, "用户登录");
	infoDiv.innerHTML = "<form name='popLoginForm' id='popLoginForm' class='WIN_login'>"
			+ "<span id='popLoginMsg' class='loginAlert'></span>"
			+ "<dl><dt>Email：</dt><dd>"
			+ "<input class=\"loginIuput\" type='input' name='popEmail' onblur='validatePopLoginEmain(this.value)' value=''></dd><dt>密&nbsp;&nbsp;码：</dt><dd>"
			+
			            "<input  class=\"loginIuput\" type='password' name='popEasswd' value='' onKeyDown='popLoginKeyDown(event.keyCode)'></dd><dt></dt><dd><input type='hidden' name='popExistEmail' id='popExistEmail' value='0'></dd><dt>"
			+ "</dt><dd><a class=\"btn_gray1\" href=\"javascript:void(null);\"  onclick='popLogin()' >登&nbsp;录</a>"
			+ "<a class=\"btn_gray1\" href=\"javascript:void(null);\"  onclick='closePop()'>取&nbsp;消</a></dd> </dl>"
			+ "<div class=\"reg\"><span style=\"margin-bottom:10px\" class=\"fc14bgreen\">如果你还没有注册</span>"
			+ "<a class=\"btn_green2\" style=\"margin-bottom:10px\" href=\"javascript:window.location.href=contextPath+'/reg';\" >那就点这里…</a>"
			+ "<a class=\"btn_green2\" style=\"margin-bottom:10px\" href=\"javascript:window.location.href=contextPath+'/forgot-password';\" >忘记密码了？</a>"
			+ "</form>"
}
function popLoginKeyDown(keyCode) {
	if (keyCode == 13) {
		popLogin();
	}
}
function closePop() {
	var capDivObj = document.getElementById("capDiv");
	if (capDivObj != null) {
		capDivObj.className = "capDivHide";
	}
	var infoDiv = document.getElementById("infoDiv");
	if (infoDiv != null) {
		infoDiv.className = "capDivHide";
	}
}

function validatePopLoginEmain(email) {
	var errorMsg = validateEmail(email);
	if (errorMsg != null) {
		$('popLoginMsg').innerHTML = errorMsg;
		return;
	}
	// ajax验证
	$('popLoginMsg').innerHTML = "";
	var requestUrl = contextPath + "/register/validateEmail.do";
	email = email.replace(/^\s+|\s+$/g, "");
	var params = "email=" + email;
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			$('popLoginMsg').innerHTML = "";
			if (!action.exist) {
				$('popLoginMsg').innerHTML = "没有此邮箱!";
				$("popExistEmail").value = 0;
			} else {
				$("popExistEmail").value = 1;
			}
		}
	}).send();
}
var _LOGGINED_ = false;
function popLogin() {
	var email = document.forms["popLoginForm"].elements["popEmail"].value;
	var passwd = document.forms["popLoginForm"].elements["popEasswd"].value;
	var popExistEmail = $("popExistEmail").value;

	var errorMsg = validatePasswd(passwd);
	if (errorMsg != null) {
		$('popLoginMsg').innerHTML = errorMsg;
	} else {
		if (popExistEmail == 0) {
			// 如果没有当前的email 则不登陆
			$('popLoginMsg').innerHTML = "没有邮箱地址!";
		} else {
			// 如果有当前的email
			$('popLoginMsg').innerHTML = "";
			// 进行ajax 验证
			var requestUrl = contextPath + "/register/popLogin.do";
			email = email.replace(/^\s+|\s+$/g, "");
			passwd = passwd.replace(/^\s+|\s+$/g, "");
			var params = "email=" + email + "&password=" + passwd;
			new Request.JSON({
				url: requestUrl,
				method : 'post',
				data : params,
				onSuccess : function(action) {
					if (action.result == SUCCESS) {
						if (document.getElementById("__LOGINED__") != null) {
							document.getElementById("__LOGINED__").value = 1;
							// 成功登陆 刷新信息,等候 写完cookie再刷新
							window.setTimeout("refreshAfterLogin()", 1000);
						}
						closePop();
					} else {
						$('popLoginMsg').innerHTML = "用户名密码不匹配";
					}
				}
			}).send();
		}
	}
}
function refreshAfterLogin() {
	try {
		refreshDiv("loginInfo");
		refreshDiv("myHomeInfo");
	} catch (e) {
		// alert(e);
	}
	// 钩子程序，调用页面的程序
	try {
		afterPopLogin();
	} catch (e) {
	}
}
function validatePasswd(passwd) {
	var errorMsg = null;
	if (passwd == null || passwd == ""
			|| passwd.replace(/^\s+|\s+$/g, "").length == 0) {
		errorMsg = "请您输入密码!";
	} else {
		passwd = passwd.replace(/^\s+|\s+$/g, "");
		if (!passwd.match("(\\w{4,64})")) {
			errorMsg = "您输入的必须是字母和数字，长度在4位和64位之间";
		}
	}
	return errorMsg;
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else {
		if (document.body.scrollHeight > document.body.offsetHeight) { // all
			// but
			// Explorer
			// Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
			// and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else {
		if (document.documentElement
				&& document.documentElement.clientHeight) { // Explorer 6 Strict
			// Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else {
			if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
		}
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
	return arrayPageSize;
}
/**
 *
 * 通用的发送消息的界面，需要传送一个接收人的id
 *
 */
function checkLogin() {
	var obj = document.getElementById("__LOGINED__");
	if (obj == null) {
		alert("没有发现__LOGINED__");
		return false;
	} else {
		if (obj.value != "0") {
			return true;
		} else {
			return false;
		}
	}
}

function sendMessage(pid, name) {
	if (!checkLogin()) {
		login_ajax();
	} else {
		showMessagePage(pid, name);
	}
}
function showMessagePage(pid, name) {
	showCap();
	var title = null;
	if (name != null && name != "") {
		title = "给" + name + "发送短消息"
	}
	var infoDiv = getInfoDiv(492, 280, title);
	infoDiv.innerHTML = "<form name='popMessageForm' id='popMessageForm' >"
			+ "<textarea name='content' cols='50' rows='15'></textarea>"
			+ "<input type='hidden' name='personId' value='"
			+ pid
			+ "'>"
			+ "<a class='btn_gray1' href='javascript:submitPopMessageForm()'>提交</a>"
			+ "<a class='btn_gray1' href='javascript:closePop()'>取消</a></form>";
}
function submitPopMessageForm() {
	var requestUrl = contextPath + "/adder/messageAdd.do";
	// 进行相应的转换
	//	var contentValue = document.forms["popMessageForm"].elements["content"].value;
	//	document.forms["popMessageForm"].elements["content"].value = escape(contentValue);

	var params = Form.serialize('popMessageForm');
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			if (action.result == SUCCESS) {
				showInfo("恭喜您消息发送成功！");
			}
		}
	}).send();
	//	var myAjax = new Ajax.Request(requestUrl, {
	//		// 请求方式：POST
	//		method : 'post',
	//		// 请求参数
	//		parameters : params,
	//		// 指定回调函数
	//		onComplete : processAfterSubmitPopMessageForm,
	//		// 是否异步发送请求
	//		asynchronous : true
	//	});
	closePop();
}
//function processAfterSubmitPopMessageForm(response) {
//	var action = response.responseText.parseJSON();
//	if (action.result == SUCCESS) {
//		showInfo("恭喜您消息发送成功！");
//	}
//}

/**
 * 留言的通用方法
 */

function sendMessageBoard(pid, pageInfo) {
	if (!checkLogin()) {
		login_ajax();
	} else {
		showMessageBoardPage(pid, pageInfo);
	}
}
function showMessageBoardPage(pid, pageInfo) {
	showCap();
	var infoDiv = getInfoDiv(492, 280);
	infoDiv.innerHTML = "<form name='popMessageBoardForm' id='popMessageBoardForm' >"
			+ "<textarea name='content' cols='50' rows='15'></textarea>"
			+ "<input type='hidden' name='personId' value='"
			+ pid
			+ "'>"
			+ "<a class='btn_gray1'  href='javascript:submitPopMessageBoardForm(\""
			+ pageInfo
			+ "\")'>提交</a>"
			+ "<a class='btn_gray1'  href='javascript:closePop()'>取消</a></form>";
}
function submitPopMessageBoardForm(pageInfo) {
	var requestUrl = contextPath + "/adder/messageBoardAdd.do";
	var params = Form.serialize('popMessageBoardForm');
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			if (action.result > 0) {
				showInfo("恭喜您留言发送成功！");
				if (refreshPageInfo != "") {
					eval("controller." + refreshPageInfo + "()");
				}
			}
		}
	}).send();
	//	var myAjax = new Ajax.Request(requestUrl, {
	//		// 请求方式：POST
	//		method : 'post',
	//		// 请求参数
	//		parameters : params,
	//		// 指定回调函数
	//		onComplete : processAfterSubmitPopMessageBoardForm,
	//		// 是否异步发送请求
	//		asynchronous : true
	//	});
	closePop();
	refreshPageInfo = pageInfo;
}
//function processAfterSubmitPopMessageBoardForm(response) {
//	var action = response.responseText.parseJSON();
//	if (action.result > 0) {
//		showInfo("恭喜您留言发送成功！");
//		if (refreshPageInfo != "") {
//			eval("controller." + refreshPageInfo + "()");
//		}
//	}
//}

/**
 *
 * 通用搜索
 *
 */
function searchedFieldOnFocus(obj) {
	obj.className = "searchedOnFocus";
}
function searchedFieldFocusOut(obj) {
	var v = obj.value;
	v = v.replace(/^\s+|\s+$/g, "");
	if (v == "") {
		obj.className = "searchedOnFocusOut";
		obj.value = v;
	}
}
function submitSearcheForm() {
	var formkey = "";
	var ArrayKey = (document.getElementById("key").value).split("'");
	for (var i = 0; i < ArrayKey.length; i++) {
		formkey = formkey + ArrayKey[i] + " ";
	}
	document.forms["searchedForm"].elements["key"].value = formkey;
	document.forms["searchedForm"].submit();
}
/**
 *
 * 通用的操作资源的函数，主要用于数字性质的添加和删除<br>
 * resourceId:需要传递的参数<br>
 * actionName:需要执行的在adder中的动作名称<br>
 * successInfo:执行成功后提示的信息<br>
 * addedInfo:已经添加后的信息<br>
 * regreshTopic:在执行成功后需要执行的刷新动作 此函数将要替换掉其他的一些操作，比如删除，加为好友等等
 *
 */
var _SUCCESSINFO_ = "";
var _ADDEDINFO_ = "";
var _REFRESHTOPIC_ = "";
function operateResource(resourceId, actionName, successInfo, addedInfo,
                         refreshTopic) {
	if (!checkLogin()) {
		login_ajax();
		return
	}
	_ADDEDINFO_ = addedInfo;
	_SUCCESSINFO_ = successInfo;
	_REFRESHTOPIC_ = refreshTopic;
	var requestUrl = contextPath + "/adder/" + actionName + ".do";
	var params = "resourceId=" + resourceId;
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			if (action.result == LOGIN) {
				login_ajax();
			} else {
				if (action.result == ADDED) {
					showInfo(_ADDEDINFO_);
				} else {
					if (action.result == SUCCESS) {
						var topic = _REFRESHTOPIC_;
						showInfo(_SUCCESSINFO_);
						if (topic != null && topic != "") {
							refreshDiv(topic);
						}
					}
				}
			}
		}
	}).send();
	//	var myAjax = new Ajax.Request(requestUrl, {
	//		method : 'post',
	//		parameters : params,
	//		onComplete : precessAfterOperateResource,
	//		asynchronous : true
	//	});
}
//function precessAfterOperateResource(response) {
//	if (debug) {
//		alert(response.responseText);
//	}
//	var action = response.responseText.parseJSON();
//	if (action.result == LOGIN) {
//		login_ajax();
//	} else if (action.result == ADDED) {
//		showInfo(_ADDEDINFO_);
//	} else if (action.result == SUCCESS) {
//		var topic = _REFRESHTOPIC_;
//		showInfo(_SUCCESSINFO_);
//		if (topic != null && topic != "") {
//			refreshDiv(topic);
//		}
//	}
//}
/**
 * 追加刷新的代码
 */

function showDiv(id) {
	try {
		document.getElementById(id).style.display = "block";
	} catch (e) {
		alert("没有发现id为:" + id + "的元素");
	}
}
function hideDiv(id) {
	document.getElementById(id).style.display = "none";
}
/**
 * 在IE 和 FF下同时响应的
 */
function showImg(fileObj, imgId, width, height) {
	var errorMsg = "上传的图片格式必须为gif,jpg,png";
	var dImg = document.getElementById(imgId);
	if (!fileObj.value.match(/.jpg|.gif|.png/i)) {
		alert(errorMsg);
		return;
	}
	var image = new Image();
	if (fileObj.files) {
		// FF
		image.src = fileObj.files[0].getAsDataURL();
		dImg.src = image.src;
		dImg.height = height;
		dImg.width = width;

	} else {
		if (fileObj.value.indexOf('\\') > -1
				|| fileObj.value.indexOf('\/') > -1) {
			// IE
			image.src = fileObj.value;
			dImg.src = image.src;
			dImg.style.height = height;
			dImg.style.width = width;
		}
	}
}
/**
 *
 * 更新div逐步转向prototype
 *
 */
var bigInterval = 5;
function getBottomNav(divId, curPage, totalPages) {
	// 点击向前或者向后的...翻的页数
	if (totalPages <= 1) {
		return "";
	}

	var startPage = curPage;
	var dotAfter = false;
	var dotBefore = false;
	if (curPage > 3) {
		startPage = curPage - 3;
		dotBefore = true;
	} else {
		startPage = 1;
	}

	var endPage = totalPages;
	if (endPage - curPage > 3) {
		endPage = 3 + curPage;
		dotAfter = true;
	}

	// alert(endPage);
	var strArray = new Array();
	if (dotBefore) {

		if (curPage > bigInterval) {
			strArray[strArray.length] =
			"<a href='javascript:void(null)' onclick=\"gotoPage('" + divId + "'," + 1 + ")\">&lt;&lt;</a><a href='javascript:void(null)' onclick=\"gotoPage('" + divId + "'," +
			(curPage - bigInterval) + ")\">...</a>";
		} else {
			strArray[strArray.length] = "<a href='javascript:void(null)' onclick=\"gotoPage('"
					+ divId + "'," + 1 + ")\">&lt;&lt;</a><a>...</a>";
		}
	}
	for (var i = startPage; i <= endPage; i++) {
		if (i == curPage) {
			strArray[strArray.length] = "<a class='selected' href='javascript:void(null)'>"
					+ i + "</a>";
		} else {
			strArray[strArray.length] = "<a href='javascript:void(null)' onclick=\"gotoPage('"
					+ divId + "'," + i + ")\">" + i + "</a>";
		}
	}
	if (dotAfter) {
		if (curPage + bigInterval <= totalPages) {
			strArray[strArray.length] = "<a  href='javascript:void(null)' onclick=\"gotoPage('"
					+ divId
					+ "',"
					+ (curPage + bigInterval)
					+ ")\">...</a><a href='javascript:void(null)' onclick=\"gotoPage('"
					+ divId + "'," + totalPages + ")\">&gt;&gt;</a>";
		} else {
			strArray[strArray.length] = "<a>...</a><a href='javascript:void(null)' onclick=\"gotoPage('"
					+ divId + "'," + totalPages + ")\">&gt;&gt;</a>";
		}
	}
	strArray[strArray.length] =
	"<span class='gotoText'>跳转到&nbsp;&nbsp;第</span><input class='gotoInput' type='text' name='navPage' id='navPage' maxLength='3' onblur=\"navGoto(13,this.value,'"
			+ divId
			+ "',"
			+ totalPages
			+ ")\" onKeyDown=\"navGoto(event.keyCode,this.value,'"
			+ divId
			+ "'," + totalPages + ")\"/><span>页</span>";
	strArray[strArray.length] = "<em>";
	if (startPage < curPage) {
		strArray[strArray.length] = "<a href='javascript:void(null)' onclick=\"gotoPage('"
				+ divId + "'," + (curPage - 1) + ")\">上一页</a>";
	}
	if (endPage > curPage) {
		strArray[strArray.length] = "<a href='javascript:void(null)' onclick=\"gotoPage('"
				+ divId + "'," + (curPage + 1) + ")\">下一页</a>";
	}
	strArray[strArray.length] = "</em>";
	return strArray.join("");
}
function navGoto(keyCode, value, divId, totalPages) {
	if (keyCode == 13) {
		try {
			if (value == "") {
				return;
			}
			var curPage = parseInt(value);
			if (curPage <= totalPages) {
				gotoPage(divId, curPage);
			} else {
				gotoPage(divId, totalPages);
			}
		} catch (e) {
			alert(e);
		}
	}
}
// refresh pageInfo
function refreshBottomNav(divId, curPage, totalPages) {
	if (debug) {
		alert("formId=[" + divId + "] curPage=[" + curPage + "]totalPages=["
				+ totalPages + "]");
	}
	var navhtml = getBottomNav(divId, curPage, totalPages);
	if (navhtml.trim() == "") {
		generateBottomNav(divId, curPage, totalPages);
	}
	if (debug) {
		alert(navhtml);
	}
	var nav = document.getElementById(divId + "_nav");
	if (nav == null) {
		alert("没有找到id为" + divId + "_nav的div");
	} else {
		if (navhtml == "") {
			nav.className = "bottomPage";
		}
		else {
			nav.className = "bottomPageShow";
		}
		nav.innerHTML = navhtml;
	}
}

function refreshDiv(divId) {
	var divObj = document.getElementById(divId);
	if (divObj == null) {
		alert("没有发现div=" + divId);
		return;
	}
	// 添加indicator
	var indicatorId = divObj.getAttribute("indicator");
	if (indicatorId != null && indicatorId != "") {
		var indicatorObj = document.getElementById(indicatorId);
		if (indicatorObj != null) {
			var cloneObj = indicatorObj.cloneNode(false);
			cloneObj.style.display = "block";
			divObj.innerHTML = "";
			divObj.appendChild(cloneObj);
		}
	}
	var pageInfo = divObj.getAttribute("formId");
	var requestUrl = divObj.getAttribute("href");
	var executeScripts = (divObj.getAttribute("executeScripts") == "true");
	var params = null;
	if (pageInfo != null) {
		try {
			params = Form.serialize(pageInfo);
		} catch (e) {
			alert("没有找到该Form" + pageInfo);
		}
	}
	new Request.HTML({
		url: requestUrl,
		method : 'post',
		data : params,
		evalScripts : executeScripts,
		onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {
			$(divId).innerHTML = responseHTML;
			if (executeScripts) {
				eval(responseJavaScript);
			}
		},
		onFailure : function() {
			showInfo('对不起，网络通讯失败，请稍后再试！');
		}
	}).send();
	//	new Ajax.Updater({success:divId}, requestUrl, {
	//		method : 'post',
	//		evalScripts : executeScripts,
	//		parameters : params,
	//		onFailure : function() {
	//			//refreshDiv(divId);
	//			showInfo('对不起，网络通讯失败，请稍后再试！');
	//		}
	//	});
}

// goto another page
function gotoPage(divId, curPage) {
	var divObj = document.getElementById(divId);
	var formId = divObj.getAttribute("formId");
	document.forms[formId].elements['curPage'].value = curPage;
	refreshDiv(divId);
}

function changeThis(obj, divId) {
	var id = obj.id;
	var els = document.getElementsByName(id);
	var curIndex = 0;
	var oldIndex = 0
	for (var i = 0; i < els.length; i++) {
		if (els[i].className == "selected") {
			els[i].className = "";
			oldIndex = i;
		}
		if (els[i] == obj) {
			curIndex = i;
		}
	}
	var divObj = document.getElementById(divId);
	var formId = divObj.getAttribute("formId");
	obj.className = "selected";
	document.forms[formId].elements["curType"].value = 1 * document.forms[formId].elements["baseTypeNum"].value + curIndex;
	document.forms[formId].elements['curPage'].value = "1";
	refreshDiv(divId);
}
/**
 *
 * 改变显示的页面
 *
 */

function showThis(obj, divId, topicDiv) {
	var curIndex = 0;
	var els = document.getElementsByName(obj.id);
	for (var i = 0; i < els.length; i++) {
		if (els[i] == obj) {
			curIndex = i;
			if (els[i].className.indexOf("selected") < 0) {
				els[i].className = els[i].className + " selected";
			}
		} else {
			els[i].className = els[i].className.replace("selected", "");
		}
	}
	els = document.getElementsByName(divId);
	for (var i = 0; i < els.length; i++) {
		if (i != curIndex) {
			els[i].style.display = "none";
		} else {
			els[i].style.display = "block";
		}
	}
	if (topicDiv != "") {
		try {
			refreshDiv(topicDiv);
		} catch (e) {
			alert("没有该方法:找到该Div=" + topicDiv + "");
		}
	}
}

/**
 *
 * 发送网站建议
 *
 */
function showAdvice() {
	showCap();
	var title = "欢迎留下你的意见，经采用后有积分奖励哦";
	var infoDiv = getInfoDiv(492, 280, title);

	infoDiv.innerHTML = "<form name='popAdviceForm' id='popAdviceForm' >"
			+ "<textarea id=\"content\" name='content' cols='50' rows='15' onfocus='this.select()'>请在这里描述该页面的问题</textarea>"
			+ "<input type='hidden' name='url' value='"
			+ window.location.href
			+ "'>"
			+ "<a class='btn_gray1' href='javascript:submitAdviceForm()'>提交</a>"
			+ "<a class='btn_gray1' href='javascript:closePop()'>取消</a>"
			+ "</form>";
}
function submitAdviceForm() {
	var content = document.forms["popAdviceForm"].elements["content"].value;

	content = content.replace(/^\s+|\s+$/g, "");
	if (content == "") {
		alert("请您输入内容！");
		return;
	}
	var requestUrl = contextPath + "/adder/addSiteAdvice.do";
	var contentValue = document.forms["popAdviceForm"].elements["content"].value;

	//	document.forms["popAdviceForm"].elements["content"].value = escape(contentValue);

	var params = Form.serialize('popAdviceForm');
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			if (action.result == SUCCESS) {
				showInfo("发送成功，感谢支持！");
			}
		}
	}).send();
	//	var myAjax = new Ajax.Request(requestUrl, {
	//		// 请求方式：POST
	//		method : 'post',
	//		// 请求参数
	//		parameters : params,
	//		// 指定回调函数
	//		onComplete : processAfterSubmitAdviceForm,
	//		// 是否异步发送请求
	//		asynchronous : true
	//	});
	closePop();
}
//function processAfterSubmitAdviceForm(response) {
//	var action = response.responseText.parseJSON();
//	if (action.result == SUCCESS) {
//		showInfo("发送成功，感谢支持！");
//	}
//}
function showUploadCap() {
	if (1 == 1) {
		return;
	}
	showCap();
	var infoWidth = 400;
	var infoHeight = 200;
	var arrySize = getPageSize();
	var infoDiv = document.getElementById("uploadInfoDiv");
	if (infoDiv == null) {
		infoDiv = document.createElement("div");
		infoDiv.id = "uploadInfoDiv";
		infoDiv.innerHTML = "正在上传图片...";
		document.body.appendChild(infoDiv);
	}
	infoDiv.style.left = (document.documentElement.scrollLeft + (arrySize[0] - infoWidth)
			/ 2)
			+ 'px';
	infoDiv.style.top = (document.documentElement.scrollTop + (arrySize[3] - infoHeight)
			/ 2)
			+ 'px';
	infoDiv.style.height = infoHeight + "px";
	infoDiv.style.width = infoWidth + "px";
	infoDiv.className = "infoUploadShow";
}
function hideUploadCap() {
	var capDivObj = document.getElementById("capDiv");
	if (capDivObj != null) {
		capDivObj.className = "capDivHide";
	}
	var infoDiv = document.getElementById("uploadInfoDiv");
	if (infoDiv != null) {
		infoDiv.className = "infoUploadHide";
	}
}
/**
 * 对评论回复的通用函数
 */
function sendReply(resourceId, tableName, pageInfo) {
	if (!checkLogin()) {
		login_ajax();
	} else {
		showReplyPage(resourceId, tableName, pageInfo);
	}
}
function showReplyPage(resourceId, tableName, pageInfo) {
	showCap();
	var infoDiv = getInfoDiv(492, 280);
	infoDiv.innerHTML = "<form name='popReplyForm' id='popReplyForm' >"
			+ "<textarea name='content' cols='50' rows='15'></textarea>"
			+ "<input type='hidden' name='resourceId' value='"
			+ resourceId
			+ "'>"
			+ "<input type='hidden' name='tableName' value='"
			+ tableName
			+ "'>"
			+ "<a class='btn_gray1'  href='javascript:submitPopReplyForm(\""
			+ pageInfo
			+ "\")'>提交</a>"
			+ "<a class='btn_gray1'  href='javascript:closePop()'>取消</a></form>";
}
function submitPopReplyForm(pageInfo) {
	var requestUrl = contextPath + "/adder/replyAdd.do";
	// 进行相应的转换
	var contentValue = document.forms["popReplyForm"].elements["content"].value;
	//	document.forms["popReplyForm"].elements["content"].value = escape(contentValue);

	var params = Form.serialize('popReplyForm');
	new Request.JSON({
		url: requestUrl,
		method : 'post',
		data : params,
		onSuccess : function(action) {
			if (action.result > 0) {
				showInfo("回复发送成功！");
				if (_REFRESHTOPIC_ != "") {
					window.setTimeout('refreshDiv(_REFRESHTOPIC_)', 1000);
				}
			}
		}
	}).send();
	//	var myAjax = new Ajax.Request(requestUrl, {
	//		// 请求方式：POST
	//		method : 'post',
	//		// 请求参数
	//		parameters : params,
	//		// 指定回调函数
	//		onComplete : processAfterSubmitPopReplyForm,
	//		// 是否异步发送请求
	//		asynchronous : true
	//	});
	closePop();
	_REFRESHTOPIC_ = pageInfo;
}
//function processAfterSubmitPopReplyForm(response) {
//	var action = response.responseText.parseJSON();
//	if (action.result > 0) {
//		showInfo("回复发送成功！");
//		if (_REFRESHTOPIC_ != "") {
//			window.setTimeout('refreshDiv(_REFRESHTOPIC_)', 1000);
//		}
//	}
//}

function searchKey(str) {
	document.forms["searchedForm"].elements["key"].className = "searchedOnFocus";
	document.forms["searchedForm"].elements["key"].value = str;
	document.forms["searchedForm"].submit();
}

function generateBottomNav(divId, curPage, totalPages) {
	// 点击向前或者向后的...翻的页数

	var startPage = curPage;
	var dotAfter = false;
	var dotBefore = false;
	if (curPage > 3) {
		startPage = curPage - 3;
		dotBefore = true;
	} else {
		startPage = 1;
	}

	var endPage = totalPages;
	if (endPage - curPage > 3) {
		endPage = 3 + curPage;
		dotAfter = true;
	}

	// alert(endPage);
	var strArray = new Array();
	if (dotBefore) {

		if (curPage > bigInterval) {
			strArray[strArray.length] = "<a href=\"javascript:changeToPage('"
					+ divId + "'," + 1
					+ ")\">&lt;&lt;</a><a href=\"javascript:changeToPage('"
					+ divId + "'," + (curPage - bigInterval) + ")\">...</a>";
		} else {
			strArray[strArray.length] = "<a href=\"javascript:changeToPage('"
					+ divId + "'," + 1 + ")\">&lt;&lt;</a><a>...</a>";
		}
	}
	for (var i = startPage; i <= endPage; i++) {
		if (i == curPage) {
			strArray[strArray.length] = "<a class='selected' href='javascript:void(null)'>"
					+ i + "</a>";
		} else {
			strArray[strArray.length] = "<a href=\"javascript:changeToPage('"
					+ divId + "'," + i + ")\">" + i + "</a>";
		}
	}
	if (dotAfter) {
		if (curPage + bigInterval <= totalPages) {
			strArray[strArray.length] = "<a  href=\"javascript:changeToPage('"
					+ divId + "'," + (curPage + bigInterval)
					+ ")\">...</a><a href=\"javascript:changeToPage('" + divId
					+ "'," + totalPages + ")\">&gt;&gt;</a>";
		} else {
			strArray[strArray.length] = "<a>...</a><a href=\"javascript:changeToPage('"
					+ divId + "'," + totalPages + ")\">&gt;&gt;</a>";
		}
	}
	strArray[strArray.length] =
	"<span class='gotoText'>跳转到&nbsp;&nbsp;第</span><input class='gotoInput' type='text' name='navPage' id='navPage' maxLength='3' onblur=\"navChangeto(13,this.value,'"
			+ divId
			+ "',"
			+ totalPages
			+ ")\" onKeyDown=\"navChangeto(event.keyCode,this.value,'"
			+ divId
			+ "'," + totalPages + ")\"/><span>页</span>";
	strArray[strArray.length] = "<em>";
	if (startPage < curPage) {
		strArray[strArray.length] = "<a href=\"javascript:changeToPage('"
				+ divId + "'," + (curPage - 1) + ")\">上一页</a>";
	}
	if (endPage > curPage) {
		strArray[strArray.length] = "<a href=\"javascript:changeToPage('"
				+ divId + "'," + (curPage + 1) + ")\">下一页</a>";
	}
	strArray[strArray.length] = "</em>";
	var navhtml = "<em></em>";
	if (totalPages > 1) {
		navhtml = strArray.join("");
	}
	var nav = document.getElementById(divId + "_nav");
	if (navhtml == "<em></em>") {
		nav.className = "bottomPageHide";
	} else {
		nav.className = "bottomPageShow";
		nav.innerHTML = navhtml;
	}
}
function changeToPage(divId, curPage) {
	var divObj = document.getElementById(divId);
	var formId = divObj.getAttribute("formId");
	if (debug) {
		alert("formId='" + formId + "'");
	}
	document.forms[formId].elements['curPage'].value = curPage;
	document.forms[formId].submit();
}
function navChangeto(keyCode, value, divId, totalPages) {
	if (keyCode == 13) {
		if (value == "") {
			return;
		}
		try {
			var curPage = parseInt(value);
			if (curPage <= totalPages) {
				changeToPage(divId, curPage);
			} else {
				changeToPage(divId, totalPages);
			}
		} catch (e) {
			alert(e);
		}
	}
}
function changeType(curType, divId) {

	var divObj = document.getElementById(divId);
	var formId = divObj.getAttribute("formId");
	document.forms[formId].elements["curType"].value = curType;
	document.forms[formId].elements['curPage'].value = "1";
	document.forms[formId].submit();
}

function lodge() {
	showCap();
	var title = "请说明投诉团长的理由";
	var infoDiv = getInfoDiv(492, 280, title);

	infoDiv.innerHTML = "<form name='popAdviceForm' id='popAdviceForm' >"
			+ "<textarea id=\"content\" name='content' cols='50' rows='15' onfocus='this.select()'>我要投诉**团长**!</textarea>"
			+ "<input type='hidden' name='url' value='"
			+ window.location.href
			+ "'>"
			+ "<a class='btn_gray1' href='javascript:submitAdviceForm()'>提交</a>"
			+ "<a class='btn_gray1' href='javascript:closePop()'>取消</a>"
			+ "</form>";
}

function ajax_title_content_form(fanForm, titleMinLength, titleMaxLength, contentMinLength, contentMaxLength
		) {
	if (!fanForm) {
		return;
	}
	var form = $(fanForm);
	if (!form) {
		return;
	}
	form.ajaxJSON({
		onRequest: function() {
			tinyMCE.triggerSave();
			var title = form['title'];
			var content = form['content'];
			var titleLength = title.value.trim().length;
			var contentLength = content.value.trim().length;
			if (titleMinLength > 0 && titleLength < titleMinLength) {
				errorMessage("标题应至少有" + titleMinLength + "个字");
				title.focus();
				return false;
			}
			if (titleMaxLength > 0 && titleLength > titleMaxLength) {
				errorMessage("您的标题有点长哦，请控制在" + titleMaxLength + "字以内吧");
				title.focus();
				return false;
			}
			if (contentMinLength > 0 && contentLength < contentMinLength) {
				errorMessage("内容应至少有" + contentMinLength + "个字");
				content.focus();
				return false;
			}
			if (contentMaxLength > 0 && contentLength > contentMaxLength) {
				errorMessage("您的内容有点长哦，请控制在" + contentMaxLength + "字以内吧");
				content.focus();
				return false;
			}
			successMessage("正在发布主题，请稍候...");
			return true;
		},
		onComplete: function(action) {
			if (!action.error) {
				successMessage("发表成功,正在更新页面内容，请稍候...");
				TB_remove();
				setTimeout(function () {
					window.location.href = window.location.href;
				}, 2000);
			} else {
				errorMessage(action.message);
			}
		}
	});
}
