	var selloffer_hb, sample_hb, company_hb, keyword_hb, category_hb, con_hb;
	
	function init_log(){
		var domain=".madeinchina.com";
		var path="/SE2";
		selloffer_hb=new ViewedBuilder("selloffer",4,8,domain,path+"/ViewLogServlet",selloffer_callback);
		sample_hb=new ViewedBuilder("sample",4,8,domain,path+"/ViewLogServlet",sample_callback);
		company_hb=new ViewedBuilder("company",6,6,domain,path+"/ViewLogServlet", company_callback);
		keyword_hb=new ViewedBuilder("keyword",6,6,domain,"", keyword_callback);
		category_hb=new ViewedBuilder("category",6,10,domain,path+"/ViewLogServlet",category_callback);
		con_hb=new ViewedBuilder("closeornot",1,1,domain,"",null);
		var kword=$("sq").value;
		var hotcat=$("hotcat").value;
		var str=con_hb.getList();
		if (typeof str=="undefined"||str==null||str.length<=0||str[0].length!=5)
			str="00000";
		else{
			str=str[0]
			if ("1"==str.charAt(0)){
				$("show_selloffer").style.display = ""; 
				$("a_selloffer").className="sortopen";
			}
			if ("1"==str.charAt(1)){
				$("show_sample").style.display = ""; 
				$("a_sample").className="sortopen";
			}
			if ("1"==str.charAt(2)){
				$("show_company").style.display = ""; 
				$("a_company").className="sortopen";
			}
			if ("1"==str.charAt(3)){
				$("show_category").style.display = ""; 
				$("a_category").className="sortopen";
			}
			if ("1"==str.charAt(4)){
				$("show_keywords").style.display = ""; 
				$("a_keywords").className="sortopen";
			}
		}
		//var re=/`|~|!|@|#|\\$|\$|%|\^|&|\*|\(|\)|-|_|\+|=|\[|]|\{|}|\||\\|:=|:|;|\"|\'|<|>|,|\.|\/|\?/g
		//kword=kword.replace(re, " ").replace(/(^\s*)|(\s*$)/g, "");
		
		kword=kword.replace(/;/g,"%3B").replace(/=/g,"%3D").replace(/\$/g,"%24");
		keyword_add(hotcat, $("setype").value, kword);
		category_add(hotcat);
		
		
		var catSel=$("rootCat");
		var cate_list=[
			["","In all categories"],
			['1','Agriculture'],
			['50','Food & Beverage'],
			['91','Automobile Supplies & Accessories'],
			['146','Computer & PC Peripherals'],
			['181','Electronics & Electrical'],
			['282','Fashion'],
			['446','Furniture & Furnishing'],
			['550','Gifts & Crafts'],
			['593','Health & Beauty'],
			['645','Home Products'],
			['825','Industrial Supplies'],
			['950','Printing & Publishing'],
			['1008','Telecommunication Products'],
			['1035','Office & Stationery'],
			['1173','Minerals, Metals & Materials'],
			['1216','Security Supplies'],
			['1236','Service'],
			['1363','Toy, Game & Hobby'],
			['1382','Sports & Recreation'],
			['1443','Textiles & Leather Products'],
			['1512','Chemicals & Related Products'],
			['1583','Packaging Materials & Equipment'],
			['1650','Transportation'],
			['1666','Excess Inventory'],
			['1682','Environment'],
			['1697','Energy'],
			['1728','Construction & Real Estate'],
			['1820','Luggage, Bags & Cases'],
			['00','-----------------------------------------------'],
			['0','In all industries'],
			['000005001','Construction Machinery'],
			['000005002','Industrial Machinery'],
			['000005003','Printing & Publishing'],
			['000005004','Security'],
			['000005005','Environment & Energy'],
			['000005006','Chemicals Material'],
			['000005007','Broadcast & Telecom'],
			['000005008','Electronic Component'],
			['000005009','Electrical Equipment'],
			['000005010','Auto Part & Accessory'],
			['000005011','Hotel Supplies'],
			['000005012','Fashion Accessories'],
			['000005013','Home Products'],
			['000005014','Gifts and Crafts'],
			['000005015','Textile and Apparel']
		];
		for (var i=0; i<cate_list.length; i++){
			catSel.options.add(new Option(cate_list[i][1], cate_list[i][0]));
			if (catSel.options[i].value==hotcat)
				catSel.selectedIndex=i;
		}
		
	}
	
	
	function selloffer_callback(l){
		if (typeof l=="undefined"){
			return;
		}
		try{
			for (var i=0; i<l.length; i++){
				var item=l[i];
				var li=$("li_selloffer_"+i);
				if (li==null) continue;
				$("img_selloffer_"+i).src=item.image;
				$("img_selloffer_"+i).alt=item.subject;
				$("img_href_selloffer_"+i).href=item.url;
				$("text_href_selloffer_"+i).href=item.url;
				$("text_href_selloffer_"+i).innerHTML=item.subject;
				li.style.display="";
			}
		}catch(e){
			selloffer_hb.deleteCookie();
		}
		
	}
	
	function sample_callback(l){
		if (typeof l=="undefined"){
			return;
		}
		try{
			for (var i=0; i<l.length; i++){
				var item=l[i];
				var li=$("li_sample_"+i);
				if (li==null) continue;
				$("img_sample_"+i).src=item.image;
				$("img_sample_"+i).alt=item.subject;
				$("img_href_sample_"+i).href=item.url;
				$("text_href_sample_"+i).href=item.url;
				$("text_href_sample_"+i).innerHTML=item.subject;
				li.style.display="";
			}
		}catch(e){
			sample_hb.deleteCookie();
		}
	}
	function company_callback(l){
		if (typeof l=="undefined"){
			return;
		}
		try{
			for (var i=0; i<l.length; i++){
				var item=l[i];
				var li=$("li_company_"+i);
				if (li==null) continue;
				$("text_href_company_"+i).href=item.url;
				$("text_href_company_"+i).innerHTML=item.subject;
				li.style.display="";
			}
		}catch(e){
			company_hb.deleteCookie();
		}
		
	}
	function keyword_callback(l){
		if (typeof l=="undefined"){
			return;
		}
		//var re=/`|~|!|@|#|\\$|\$|%|\^|&|\*|\(|\)|-|_|\+|=|\[|]|\{|}|\||\\|:=|:|;|\"|\'|<|>|,|\.|\/|\?/g
		var _url="http://www.madeinchina.com/";
		try{
			for (var i=0; i<l.length; i++){
				//var item=unescape(l[i]);
				var item=l[i];
				item=item.split("$$$");
				var text_href=document.getElementById("text_href_keywords_"+i);
				//var q=item[2].replace(re, " ").replace(/(^\s*)|(\s*$)/g, "").replace(/\s+/g, "-");
				var q=unescape(item[2]).replace(/\s+/g,"+").replace(/\++/g, "+");
				var para="";
				if (item[0]!="")
					para=para+"&cat="+item[0];
				if (text_href!=null){
					if ("sell"==item[1])
						text_href.href=_url+"trade_selling_1/"+q+".shtml"+para;
					else if ("prod"==item[1])
						text_href.href=_url+"trade_product_1/"+q+".shtml"+para;
					else if ("comp"==item[1])
						text_href.href=_url+"trade_supplier_1/"+q+".shtml"+para;
					else
						continue;
					
					text_href.innerHTML=unescape(item[2]);
				}
				text_href.style.display="";
			}
		}catch(e){
			keyword_hb.deleteCookie();
		}
	}
	function category_callback(l){
		if (typeof l=="undefined"){
			return;
		}
		try{
			for (var i=0; i<l.length; i++){
				var item=l[i];
				var li=$("li_category_"+i);
				if (li==null) continue;
				$("text_href_category_"+i).href=item.url;
				$("text_href_category_"+i).innerHTML=item.subject;
				li.style.display="";
			}
		}catch(e){
			category_hb.deleteCookie();
		}
	}
	
	function selloffer_add(item){
		selloffer_hb.addItem(item);
	}
	function sample_add(item){
		sample_hb.addItem(item);
	}
	function company_add(item,obj){
		company_hb.addItem(item.toString());
	}
	function keyword_add(cat, type, keyword){
		if (""==keyword) return; 
		keyword_hb.addItem(cat.toString()+"$$$"+type+"$$$"+keyword);
	}
	function category_add(item){
		if (""==item) return;
		category_hb.addItem(item);
	}
	
	
	function menuChange(tag,obj,k){
		var abra = $("show_"+tag).style;
		if  (typeof abra=="undefined") return ;
		
		var str=con_hb.getList();
		if (typeof str=="undefined"||str==null||str.length<=0||str[0].length!=5)
			str="00000";
		else
			str=str[0];
		var flag="";
		if (abra.display == "") {
			abra.display = "none"; 
			if (obj)obj.className="sortclose";
			flag="0";
		} else {
			abra.display = "";	
			if (obj)obj.className="sortopen";
			flag="1";
		}
		str=str.substring(0,k)+flag+str.substring(k+1);
		con_hb.addItem(str);
		return;
	}
	
	
	function change(v){
		$("_"+v).value=$(v).value;
		search2();
	}
	function search2(flag){
		var ifc = $("isFromCategory").value;
		var posttime=$("_posttime").value;
		var busitype=$("_busitype").value;
		var area=$("_area").value.replace(/\s+/g, "+");
		var cat=$("cat").value;
		var hotcat=$("hotcat").value;
		var cat_level=$("cat_level").value;
		var setype=$("setype").value;
		var ep=escape($("extPhrase").value);
		var lp=escape($("lestPhrase").value);
		
		var key_adv=escape($("_key_adv").value);
		var without=escape($("_without").value);
		var keyword=escape($("_kword").value);
		var p=$("_p").value;

		
		var otype="", e="manufacturer", b="s",c="selling";;
		if (setype=="sell"){
			otype="trade";
			e="manufacturer";
			b="s";
			c="selling";
		}
		else if (setype=="prod"){
			otype="category";
			e="catalog";
			b="P";
			c="product";
		}
		else{
			otype="supplier";
			e="supplier";
			b="c";
			c="supplier";
		}
		
		var para="";
		var _url=document.location.href;
		if (posttime!="") para=para+'&posttime='+posttime;
		if (busitype!="") para=para+"&busitype="+busitype;
		if (area!="") para=para+"&area="+area;
		
		var re=/http:\/\/(\S*).madeinchina.com\/(\S*)/g
		var a=re.exec(_url);
		if (a&&!(a[1]=="trade"||a[1]=="category"||a[1]=="supplier"||a[1]=="www")){
			_url=_url.replace(re,"http://"+otype+".madeinchina.com/$1/$2");
		}
		re=/trade_(selling|product|supplier)_(\d*)\/(\S*.shtml)\S*/g
		if (re.exec(_url))
			_url=_url.replace(re,"trade_"+c+"_1/$3");
		re=/(category|trade|supplier)(.madeinchina.com)/g		
		if (re.exec(_url)&&flag=="head"){
			document.location.href=_url.replace(re,otype+"$2");
			return;
		}
		
		if (a&&(a[1]!="www")&&_url.indexOf(".shtml")<0){
			var arr=_url.split("/");
			var kword="";
			if (arr.length>0&&arr[arr.length-1]!="")
				kword=arr[arr.length-1];
			else if (arr.length>1&&arr[arr.length-2]!="")
				kword=arr[arr.length-2];
			if (_url.indexOf("http://supplier")==0)
				_url="http://www.madeinchina.com/supplier/"+cat+"_c1_"+cat_level+"_"+hotcat+"/"+kword+".shtml";
			if (_url.indexOf("http://trade")==0)
				_url="http://www.madeinchina.com/manufacturer/"+cat+"_s1_"+cat_level+"_"+hotcat+"/"+kword+".shtml";
			if (_url.indexOf("http://category")==0)
				_url="http://www.madeinchina.com/catalog/"+cat+"_P1_"+cat_level+"_"+hotcat+"/"+kword+".shtml";
			document.location=_url+para;
			return;
		}
		
		if (_url.indexOf("/SE2/search")>0){
			_url=_url.substring(0,_url.indexOf("search")+6)+"?setype="+setype;
			if (keyword!="") para=para+"&q="+keyword;
		}else{
			_url=_url.substring(0,_url.indexOf(".shtml")+6);
			var re=/trade_(selling|product|supplier)_(\d*)/g
			_url=_url.replace(re, "trade_$1_1");
			re=/(\d*)_(P|c|s)(\d*)_(\d*)_(\d*)/g
			_url=_url.replace(re, "$1_$21_$4_$5");
		}

		if ($("_fkword").value!=""){
			para=para+"&fkword="+$("_fkword").value.replace(/\s+/g, "+");
		}
		if (p!=""&&p!="20") para=para+"&p="+p;
		if (ifc==1){
			if (flag=="head"){
				re=/(catalog|manufacturer|supplier)\/(\d*)_(\D)(\d*)_(\d*)_(\d*)\/(\S*).shtml\S*/g
				_url=_url.replace(re, e+"/$2_"+b+"1_$5_$6/$7.shtml");
				document.location = _url;
				return;
			}
			document.location.href=_url+para;
			return;
		}
		
		//if (keyword!="") para=para+"&q="+keyword;
		if (cat!="") para="&cat="+cat+para;
		if (ep!="") para=para+"&extPhrase="+ep;
		if (lp!="") para=para+"&lestPhrase="+lp;
		if (key_adv!="") para=para+"&key_adv="+key_adv;
		if (without!="") para=para+"&without="+without;
		document.location.href=_url+para;
	}