
// <![CDATA[
window.onerror = function() {
	return true;
}
function validstr(str) // 验证用户名
{
	var s, i, j;
	s = " +=|'#&<>%*`^/\\\";,.";
	str1 = str.value.toString();
	if (str.value.length < 1) {
		alert("昵称不能为空！");
		str.focus();
		return false;
	}
	for (i = 0; i < str1.length; i++) {
		for (j = 0; j < s.length; j++) {
			if (str1.charAt(i) == s.charAt(j)) {
				alert("名字中不能包含特殊字符: +=|'#&<>%*`^/\\\";,.空格.");
				str.focus();
				return false;
			}
		}
	}
	return true;
}

(function() {
	var categoryCtrlObj, categoryListObj, categoryListTitleObj, categoryCache = new Array(), fatherObj, totAlist, tempAobj;
	LetterCategory = {
		/**
		 * 初始化类目筛选功能。 categoryCtrlId String 类目筛选功能控制层ID categoryListId String
		 * 类目筛选功能显示层ID
		 */
		init : function(categoryCtrlId, categoryListId, fatherId) {
			categoryCtrlObj = document.getElementById(categoryCtrlId);
			categoryListObj = document.getElementById(categoryListId);
			fatherObj = document.getElementById(fatherId);
			if (categoryListObj) {
				try {
					categoryListTitleObj = categoryCtrlObj
							.getElementsByTagName("span")[0];
				} catch (e) {
				}
			}
			this.eventBinding(categoryCtrlObj, "a");
		},
		/**
		 * 给bindObj对象下的标签名为tagsName绑定onmouseover和onmouseout事件。 bindObj Object
		 * tagsName String 标签名
		 */
		eventBinding : function(bindObj, tagsName) {
			var bingList = bindObj.getElementsByTagName(tagsName);
			for (var i = 0; i < bingList.length; i++) {
				if (bingList[i].href) {
					bingList[i].onmouseover = this.showResult;
					bingList[i].onmouseout = this.hiddenResult;
				}
			}
		},
		/**
		 * 显示类目结果层。
		 */
		showResult : function() {
			tempAobj = this;
			LetterCategory.changeStyle(this, "show");
			var categoryListStr_1 = LetterCategory
					.getCategoryListStr(this.innerHTML);
			LetterCategory
					.setCategoryContent(categoryListStr_1, this.innerHTML);
			categoryListObj.onmouseover = function() {
				LetterCategory.changeStyle(tempAobj, "show");
			};
			categoryListObj.onmouseout = function() {
				LetterCategory.changeStyle(tempAobj, "hidden");
			};
		},
		/**
		 * 隐藏类目结果层。
		 */
		hiddenResult : function() {
			LetterCategory.changeStyle(this, "hidden");
			if (document.getElementById("categoryScript")) {
				categoryListObj.parentNode.removeChild(document.getElementById("categoryScript"));
			}
		},
		/**
		 * 更改类目层样式。 a_link Object 当前触发的链接的DOM对象 style_type String （show 显示
		 * hidden 隐藏）
		 */
		changeStyle : function(a_link, style_type) {
			if (style_type == "show") {
				a_link.className = "check";
				categoryListTitleObj.className = "title_show";
				categoryCtrlObj.className = "categoryCtrl";
				categoryListObj.style.display = "block";
			} else {
				a_link.className = "";
				categoryListTitleObj.className = "title_hidden";
				categoryCtrlObj.className = "categoryCtrl_hidden";
				categoryListObj.style.display = "none";
			}
		},
		/**
		 * 根据字母获取相应的类目字符串,如果缓存中已经有这个类目字符串,
		 * 则从缓存中读取，如果没有则到页面中去提取新的数据，并把得到的新的数据放到缓存中. letter String 字母
		 */
		getCategoryListStr : function(letter) {
			var tempCategoryListStr = this.getCategoryListStrFromCache(letter);
			if (tempCategoryListStr) {
				return tempCategoryListStr;
			} else {
				tempCategoryListStr = this.getCategoryListStrFromPage(letter);
				this.addCategoryListStrToCache(tempCategoryListStr, letter);
				if (tempCategoryListStr) {
					return tempCategoryListStr;
				}
			}
		},
		/**
		 * 根据字母从页面中提取相关数据. letter String 字母
		 */
		getCategoryListStrFromPage : function(letter) {
			if (!totAlist)
				totAlist = fatherObj.getElementsByTagName("a");
			var tempCategoryListStr = "";
			for (var i = 0; i < totAlist.length; i++) {
				if (totAlist[i].className == "l_" + letter.substring(0, 1)) {
					var tempUrl = "";
					//if (totAlist[i].href.indexOf("?") != -1
					//		&& totAlist[i].href.indexOf("=") != -1) {
					//	continue;
					//} else {
						 //tempUrl = escape(totAlist[i].getAttribute("href")).substring(9,escape(totAlist[i].href).length);
						tempUrl = totAlist[i].getAttribute("href");
					//}
					tempCategoryListStr = tempCategoryListStr + "<a href=\"" + tempUrl + "\" target=\"_blank\">" + totAlist[i].innerHTML + "</a>";
				}
			}
			return tempCategoryListStr;
		},
		/**
		 * 根据字母从缓存中获取相应的类目字符串. letter String 字母.
		 */
		getCategoryListStrFromCache : function(letter) {
			for (var i = 0; i < categoryCache.length; i++) {
				if (categoryCache[i].id == letter) {
					return categoryCache[i].value;
				}
			}
			return null;
		},
		/**
		 * 把新的类目字符串加载到缓存中去. categoryListStr String 类目字符串. letter String 字母.
		 */
		addCategoryListStrToCache : function(categoryListStr, letter) {
			try {
				categoryCache[categoryCache.length] = {
					id : letter,
					value : categoryListStr
				};
			} catch (e) {
				this.printError(e + ":Set cache error!")
			}
		},
		/**
		 * 给类目结果层设置内容。 categoryListStr String 类目列表字符串
		 */
		setCategoryContent : function(categoryListStr, letter) {
			if (categoryListObj) {
				if (!categoryListStr) {
					categoryListStr = "<div style=\"text-align:center;\">没有拼音字母\“<span style='color:#ff7300;font-size:16px;font-weight:bold'>"
							+ letter + "</span>\”开头的类目！</div>";
				}
				categoryListObj.innerHTML = categoryListStr;
				this.addListen(categoryListObj);
			}
		},
		addListen : function(categoryListObj) {
			var categoryAList = categoryListObj.getElementsByTagName("a");
			for (var i = 0; i < categoryAList.length; i++) {
				categoryAList[i].onclick = function() {
					try {
						aliclick(this, '?tracelog=chinaindex_leimu_sx');
					} catch (e) {
					}
				};
			}
		},
		/**
		 * 错误提示。 errorMsg String 错误提示内容
		 */
		printError : function(errorMsg) {
			alert(errorMsg);
		}
	}
})();

