var site = "http://www.tradetang.com";
var root = "/listing/service/";
function searchSubmit(isnew){		
	var catid,keyword,splitcount,currpage,sort,cid;
	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;
	}else{
		catid = document.getElementById("catid").value;
		splitcount = 20;
		currpage = 1;
		sort = "best.0";
		cid = 0;
	}
	
	keyword = document.getElementById("keyword").value;
	keyword = keyword.replace(/["]/g, "'");
	
	var catname = document.getElementById("catid").options[document.getElementById("catid").selectedIndex].text;
	
	if(cid != 0){
		document.location = site + "/seller_products/"+ catid +"/" + splitcount +"_" + currpage + "_" + sort + "/" + cid + ".html";
		return;
	}else if(catid=="0" && keyword == ""){
		document.location = site + "/all_categories/0/all_categories.html";
		return;
	}
	
	keyword = formatPotKey(keyword);
	
	if(catid ==0){
		var regex = /^[s|g]{1}[0-9]{8}$/;
		if(regex.test(keyword)){
			document.location = site + "/listing/" + catid + "/" + splitcount + "_" + currpage + "_" + sort + "/" + keyword + ".html";		
		}else{
			document.location = site + "/listing/all_categories/" + keyword + ".html";
		}
	}else if(keyword != "" && catid != 0){
		document.location = site + "/listing/" + catid + "/" + splitcount + "_" + currpage + "_" + sort + "/" + keyword + ".html";		
	}else{
		document.location = site + "/listing/subcategories/" + catid + "_" + splitcount +"_" + currpage + "_" + sort + "/" + keyFilter(catname) + ".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 = keyword.replace(/[\/]/g, " ");
	keyword = keyword.replace(/\s+/g, "_");
	keyword = escape(escape(keyword));
	return keyword;
}