function $(obj){
	return typeof(obj) == "string" ? document.getElementById(obj) : obj;
}

function SearchBar(){
	this.defaultTip = "搜索";
	this.inputColor = "#000000";
	this.outputColor = "#CCCCCC";
	this.oForm = $("search");
	this.oKeywords = this.oForm.keywords;
	this.oSubmitBtn = this.oForm.submitBtn;
	//add event
	this.addEvent = function(){
		var defaultTip = this.defaultTip;
		var inputColor = this.inputColor;
		var outputColor = this.outputColor;
		var oKeywords = this.oKeywords;
		var oSubmitBtn = this.oSubmitBtn;
		var oForm = this.oForm;
		oKeywords.onfocus = function(){
			if(this.value == defaultTip){
				this.value = "";
				this.style.color = inputColor;
			}
		}
		oKeywords.onblur = function(){
			if(this.value == ""){
				this.value = defaultTip;
				this.style.color = outputColor;
			}else if(this.value == defaultTip){
				this.style.color = outputColor;
			}
		}
		oSubmitBtn.onclick = function(){
			if(oKeywords.value == defaultTip){
				alert("请输入关键字！");
				return;
			}
			oForm.submit();
		}
	}
	//initialize
	this.init = function(){
		this.addEvent();
		this.oKeywords.value = this.defaultTip;
		this.oKeywords.style.color = this.outputColor;
	}
}
