function log(kw,sum){
	
	//alert(frombar);
	var pattern = /b$/;
	//alert(location);
	var frombar=pattern.test(location);
	if (frombar && sum>0) {
		var url = '/fulltext/search_log.do';
		var pars = 'keyword=' + kw + '&resultCount=' + sum;
		
		new Ajax.Request(url, {
			method: "post",
			parameters: pars
		});
		
		//search_log_cookie(kw);
	}
}

function search_log_cookie(kw){
	if (kw && kw != "") {
		
		var log_cookie = getCookie("search_log");
		var expire_time = new Date((new Date()).getTime() + 30 * 24 * 3600000).toGMTString();
		
		
		if (!log_cookie) {
			document.cookie = "search_log=" + encodeURI(kw) + ";expires=" + expire_time+";domain=.yihaodian.com;path=/";
		}
		else {
			//alert(decodeURI(log_cookie));
			var log_cookie_array = decodeURI(log_cookie).split(":||:");
			var length = log_cookie_array.length;
			var exists = false;
			for (var i = 0; i < length; i++) {
				if (log_cookie_array[i] == kw) {
					exists = true;
					break;
				}
				
			}
			//alert(decodeURI(exists));
			if (!exists) {
				if (length >= 5) {
					var index = log_cookie.indexOf(":||:");
					log_cookie = log_cookie.substring(index + 4);
					
				}
				document.cookie = "search_log=" + log_cookie + ":||:" + encodeURI(kw) + ";expires=" + expire_time+";domain=.yihaodian.com;path=/";
				//alert(document.cookie);
			}
			
			
		}
	}
}
		


function list_search_log(){
	var log_cookie=getCookie("search_log");
	//alert(decodeURI(log_cookie));
	if(log_cookie){
		document.write('<div class="border_blue mt10" >');
		document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0">');
		document.write('<tr><td class="left_title2"><strong>您的搜索记录</strong></td></tr>');
		document.write('<tr><td class="list1"><div><ul>');
		
		var log_cookie_arr=log_cookie.split(":||:");
		for(var i=0;i<log_cookie_arr.length;i++){
			document.write('<li><a href="/search/0/k'+log_cookie_arr[i]+'/o-a1-s1-p">');
			document.write(getShowStr(decodeURI(log_cookie_arr[i])));
			document.write('</a></li>');
			
		}
		document.write('</ul></div>');
		document.write('<div style="padding-left:30px; padding-bottom:10px; text-align:left"><input type="button" name="Submit" value=" 清 除 " onclick="clear_search_log_cookie();"/></div>');
		document.write('</td></tr></table></div>');
	
	}
}

function getShowStr(str){
	if(!str)
	 return "";
	//alert(str.length);
	if(str.length>12)
	 return str.substr(0,12)+"...";
	return str;
}

function clear_search_log_cookie(){
	var expire_time=new Date((new Date()).getTime(  )).toGMTString();
	document.cookie = "search_log=;expires=" + expire_time+";domain=.yihaodian.com;path=/";
	if($('search_history_div'))
		$('search_history_div').innerHTML="";
}
