function SO(){
	this.data=[["title","商品名称"],["serial","商品货号"],["stuff","商品面料"],["color","商品颜色"],["size","商品尺码"]];
	this.iv="想找什么？右侧选框试试";
	this.popmenu=null;
	this.text=null;
	this.field=null;
	this.input=null;
	this.button=null;
	this.init();
}
SO.prototype.init = function(){
	this.popmenu = document.getElementById("search_popmenu");
	this.field = document.getElementById("search_field");
	this.text = document.getElementById("search_select");
	this.input = document.getElementById("search_keyword");
	this.button = document.getElementById("search_submit");
	//input赋初值
	this.input.changed = false;
	this.input.style.color = "#999";
	this.input.value = this.iv;
	//填充内容
	var str = "";
	for(var i=0;i<this.data.length;i++){
		str += '<li><a href="javascript:so.setField('+i+');">'+this.data[i][1]+'</a></li>';
	}
	this.popmenu.innerHTML = str;
	//设置初始值
	this.setField(getCookies("search_index"),true);
	//事件
	this.text.onclick = Delegate.create(this,function(){this.popmenu.style.display="block";});
	document.onmouseup = Delegate.create(this,this.hidePopmenu);
	this.input.onfocus = function(){
		if(!this.changed){
			this.style.color = "#333";
			this.value = "";
		}
	};
	this.input.onblur = function(){
		if(this.value == ""){
			this.style.color = "#999";
			this.value = "想找什么？右侧选框试试";
			this.changed = false;
		}else{
			this.changed = true;
		}
	};
	this.button.onclick = Delegate.create(this,this.submit);
};
SO.prototype.setField = function(n,init){
	n = parseInt(n);
	if(isNaN(n) || n>=this.data.length){
		this.field.value = this.data[0][0];
		this.text.innerHTML = this.data[0][1];
	}else{
		this.field.value = this.data[n][0];
		this.text.innerHTML = this.data[n][1];
	}
	if(!init){
		setCookies("search_index",n,false);
		this.input.focus();
	}
};
SO.prototype.hidePopmenu = function(e){
	var tag=e?e.target:event.srcElement;
	if(tag!=this.text){
		this.popmenu.style.display="none";
	}
};
SO.prototype.submit = function(){
	if(!this.input.changed) this.input.value = "";
	document.searchForm.submit();
};


function roll(e) {
	e.className = "change";
}
function out(e) {
	e.rowIndex % 2 == 0 ?e.className = "on" : e.className = "";
}
function agreeDel() {
	if(confirm("确定要删除?")) {
		return true;
	}else{
		return false;
	}
}
function setCookies(name,value,dui){
	//标准浏览器必须转码
	value = escape(value);
	var expires = 30*24*60*60*1000;
	var e = new Date ();
	e.setTime (e.getTime() + expires);
	e = e.toGMTString();
	if(dui == false) {
		document.cookie = name+"="+value;
	} else {
		document.cookie = name+"="+value+";path=/;expires="+e+";";
	}
}
function getCookies(name){
	var search;
	search = name + "=";
	offset = document.cookie.indexOf(search);
	if (offset != -1) {
		offset += search.length ;
		end = document.cookie.indexOf(";", offset) ;
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(offset, end));
	}
	else {
		return null;
	}
}

/**
* 改自as的代理类
*/
var Delegate = {
	create:function(target,handler) {
		// Get any extra arguments for handler
		var extraArgs = Array.prototype.slice.call(arguments,2);
		// Create delegate function
		var delegate = function () {
			// Augment arguments passed from broadcaster with additional args
			var fullArgs = Array.prototype.concat.call(Array.prototype.slice.call(arguments,0),extraArgs);
			// Call handler with arguments
			return handler.apply(target, fullArgs);
		};
		return delegate;
	}
};
