/* ---------------------- SEARCH JS V0.01 ------------------ */
var site = "";
var root = "/search/service/";
function searchSubmit(isnew){
	var catid,keyword,splitcount,currpage,sort,cid,type,tkp;
	if(isnew == 0){
		catid = document.getElementById("categoryid").value;
		splitcount = document.getElementById("splitcount").value;
		currpage = document.getElementById("currpage").value;
		sort = document.getElementById("sort").value;
		cid = document.getElementById("cid").value;
		type = document.getElementById("type").value;
		tkp = "-1";
	}else{
		catid = document.getElementById("catid").value;
		splitcount = 20;
		currpage = 1;
		sort = "bestT0";
		cid = 0;
		type = 0;
		tkp = "-0";
	}
	
	keyword = document.getElementById("keyword").value;
	keyword = keyword.replace(/["]/g, "'");
	keyword = Utils.trim(keyword);
	
	var reg=/[\u4E00-\u9FA0]+/;
	if(reg.test(keyword)){
		alert("Can't input Chinese");
		return;
	}
	
	var catname = document.getElementById("catid").options[document.getElementById("catid").selectedIndex].text;
	
	if(cid != 0){
		document.location = site + "/seller-products/"+ catid +"-" + splitcount +"-" + sort + "-" + currpage + "/" + cid + ".html";
		return;
	}else if(catid=="0" && keyword == ""){
		document.location = site + "/wholesale-list.html";
		return;
	}
	
	keyword = formatPotKey(keyword);
	
	if(keyword != ""){
		document.location = site + "/buy/" + keyword + "/" + catid + "-" + splitcount + "-" + sort + "-" + currpage + "-" + type + tkp + ".html";
	}else{
		document.location = site + "/China/" + keyFilter(catname) + "/" + catid + "-" + splitcount + "-" + sort + "-" + currpage + "-" + type + tkp + ".html";
	}
}

function keyFilter(key){
	var keyword = key.replace(/[^\w\s\'\.]/g, " ");
	keyword = keyword.replace(/^\s*|\s*$/g, "");
	keyword = keyword.replace(/(\s+)/g, "-");
	return keyword;
}

function formatPotKey(keyword){
	keyword = encodeURIComponent(encodeURIComponent(keyword));
	keyword = keyword.replace(/\%2520/g, "+");
	return keyword;
}
function formatTpKey(keyword){
	keyword = encodeURIComponent(encodeURIComponent(keyword));
	keyword = keyword.replace(/\%2520/g, "-");
	return keyword;
}