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 navigatorSelectedSet(){
	var s = document.location.href+"?";
	s = s.substr(0,s.indexOf("?"));
	var lab = ["brand","cart","member","login","help","zhushou"];
	for(var i=0; i<lab.length; i++){
		if(s.indexOf(lab[i])>-1){
			document.getElementById("nav"+(i+1)).className = "selected";
			document.getElementById("nav0").className = "";
			return;
		}
	}
}

function navigatorSelected(){
	var s = document.location.href+"?";
	s = s.substr(0,s.indexOf("?"));
	var lab = ["shencai","kuyao","xiema","neiyi","neiku","bangzhu"];
	for(var i=0; i<lab.length; i++){
		if(s.indexOf(lab[i])>-1){
			document.getElementById("nav"+(i+1)).className = "selected";
			document.getElementById("nav0").className = "";
			return;
		}
	}
}
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;
	}
};

function loadfile(filename,filetype){
	arguments.length == 1 ? filetype = filename.substr(filename.lastIndexOf(".")) : null;
	if (filetype==".js"){
		var fileref=document.createElement('script');
		fileref.setAttribute("type","text/javascript");
		fileref.setAttribute("src",filename);
	}else if(filetype==".css"){
		var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css") ;
		fileref.setAttribute("href", filename);
	}else{
		return;
	}
	var objHead = document.getElementsByTagName('head');
	objHead[0].appendChild(fileref);
}

function CopyContents(tname)
{
  var txt=document.getElementById(tname).value;
     if(window.clipboardData) {   
             window.clipboardData.clearData();   
             window.clipboardData.setData("Text", txt);   
     } else if(navigator.userAgent.indexOf("Opera") != -1) {   
          window.location = txt;   
     } else if (window.netscape) {   
          try {   
               netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
          } catch (e) {   
               alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将 'signed.applets.codebase_principal_support'设置为'true'");   
          }   
          var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
          if (!clip)   
               return;   
          var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
          if (!trans)   
               return;   
          trans.addDataFlavor('text/unicode');   
          var str = new Object();   
          var len = new Object();   
          var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
          var copytext = txt;   
          str.data = copytext;   
          trans.setTransferData("text/unicode",str,copytext.length*2);   
          var clipid = Components.interfaces.nsIClipboard;   
          if (!clip)   
               return false;   
          clip.setData(trans,null,clipid.kGlobalClipboard);   
          alert("复制成功！")   
     }   
}

