/* ---------------------- SEARCH JS V0.01 ------------------ */
var site = "";
var root = "/search/service/";
function searchSubmit(isnew){
	var catid,keyword,splitcount,currpage,sort,cid,type,tkp,freeshipping,trustworthy,quality,packageselling,attr,maxp,minp,isg;
	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;
		freeshipping = document.getElementById("freeshipping").value;
		trustworthy = document.getElementById("trustworthy").value;
		quality = document.getElementById("quality").value;
		packageselling = document.getElementById("packageselling").value;
		isg = document.getElementById("isg").value;
		attr = document.getElementById("attr").value;
		maxp = document.getElementById("maxp").value;
		minp = document.getElementById("minp").value;
		tkp = "-1";
	}else{
		catid = document.getElementById("catid").value;
		splitcount = 24;
		currpage = 1;
		sort = "bestT0";
		cid = 0;
		type = 0;
		tkp = "-0";
		freeshipping=0;
		trustworthy=0;
		quality=0;
		packageselling=0;
		isg=0;
		attr="";
		maxp = 0;
		minp = 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(maxp=="") maxp=0;
    if(minp=="") minp=0;
    maxp = parseFloat(maxp);
    minp = parseFloat(minp);
	if(maxp<minp){
		var tempprice = maxp;
		maxp = minp;
		minp = tempprice;
	}
	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;
	}
	
	
	if(keyword != ""){
		if(type==0&&sort=="bestT0"&&splitcount==24&&freeshipping==0&&trustworthy==0&&quality==0&&packageselling==0&&attr==""&&maxp==0&&minp==0&&isg==0){
			document.location = site + "/wholesale+" + formatPotKey(keyword) + (catid==0?"":"_c"+catid) + ".html";
		}else{
			document.location = site + "/search/index.jsp?keyword="+ formatTomcatPotKey(keyword) +"&catid="+ catid +"&splitcount="+ splitcount +"&sort="+ sort +"&currpage="+ currpage+"&type="+type+"&freeshipping="+freeshipping+"&trustworthy="+trustworthy+"&quality="+quality+"&packageselling="+packageselling+"&attr="+attr+"&maxp="+maxp+"&minp="+minp+"&isg="+isg;
		}
		
	}else{
		if(type==0&&sort=="bestT0"&&splitcount==24&&freeshipping==0&&trustworthy==0&&quality==0&&packageselling==0&&attr==""&&maxp==0&&minp==0&&isg==0){
			document.location = site + "/wholesale-" + keyFilter(catname) + "_c" + catid  + ".html";
		}else{
			document.location = site + "/search/index.jsp?keyword="+ formatTomcatPotKey(keyword) +"&catid="+ catid +"&splitcount="+ splitcount +"&sort="+ sort +"&currpage="+ currpage+"&type="+type+"&freeshipping="+freeshipping+"&trustworthy="+trustworthy+"&quality="+quality+"&packageselling="+packageselling+"&attr="+attr+"&maxp="+maxp+"&minp="+minp+"&isg="+isg;
		}
		
	}
}

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 formatTomcatPotKey(keyword){
	keyword = encodeURIComponent(keyword);
	keyword = keyword.replace(/\%2520/g, "+");
	return keyword;
}
function formatTpKey(keyword){
	keyword = encodeURIComponent(encodeURIComponent(keyword));
	keyword = keyword.replace(/\%2520/g, "-");
	return keyword;
}
