﻿var topSearch = Class.create();
Object.extend(topSearch.prototype, {initialize:function () {
	this.defaultText = "作品,作者名";
	$("txtFinder").value = this.defaultText;
	addEvent($("txtFinder"), "keydown", this.CheckFindKey.bind(this), false);
	addEvent($("txtFinder"), "focus", this.focus.bind(this), false);
	addEvent($("txtFinder"), "blur", this.blur.bind(this), false);
}, FindBook:function () {
	var strText = $("txtFinder").value.trim();
	if(strText == "" || strText == this.defaultText)
	{
		window.location.reload(); 
		return;
	}
	
	if(strText.length>80)
	{
		alert("关键字字数不能超过80个！");
		return;
	}		
	strText = strText.split(" ")[0];
	strText = strText.replace("#","＃");
	strText = strText.replace("%", "％");
	strText = strText.replace("&","＆");
	strText = strText.replace("*","＊");
	strText = strText.replace("$","＄");
	strText = strText.replace("~","～");
	strText = strText.replace("|","｜");
	strText = strText.replace("\"","＂");
	strText = strText.replace(",","＇");
	strText = strText.replace(".","．");
	strText = strText.replace("?","？");
	strText = strText.replace("\\","＼");
	strText = encodeURI(strText);
	var strLocation = "";
	if (!strText || strText == this.defaultText) {
		
		strLocation = RewriteUrl("BookTag", "TypeClass,03,Area,%e6%97%a5%e6%9c%ac");
		//strLocation = RewriteUrl("SearchBookList", "searchkey,03,PageIndex,0");
	} else {
		//strLocation = RewriteUrl("Search", "searchkey,"+(strText)+",showNum,20,online,1");
		strLocation = RewriteUrl("SearchBookList", "searchkey,"+(strText)+",PageIndex,0");
	}
	window.location = strLocation;
	return false;
}, CheckFindKey:function (e) {
	var keyCode = MS.Keys.getCode(e);
	if (keyCode == 13) {
		this.FindBook();
		return false;
	}	
}, focus:function () {
	var target = $("txtFinder");
	if (target.value == this.defaultText) {
		target.value = "";
	}
	target.style.color = "#000000";
}, blur:function () {
	var target = $("txtFinder");
	if (target.value == "") {
		target.value = this.defaultText;
		target.style.color = "#eeeeee";
	}else
	{
	target.style.color = "#000000";
	}
	
}}, false);

