 var pageSizes=1;
try{
	pageSizes=pageSize;
}
catch(e){}
function ReplaceUrl(p_source)
{	
	var res= p_source.replace(/[/]/g,'xiegang').replace(/[-]/g,'henggang').replace(/[^a-zA-Z0-9]/g,'-');
	//var res= p_source.replace(/[/]/g,'xiegang').replace(/[-]/g,'henggang').replace(/^([a-zA-Z0-9]|[_])/g,'-');
	ress = res.split("-");
	var result="";
	for(var i=0;i<ress.length;i++)
	{
		if (ress[i].length>0) {
			result += ress[i]+"-";
		}
	};
	if (result.lastIndexOf("-")==result.length-1) {
		result = result.substring(0,result.length-1)
	}
	
	return result;
}
function getKWD()
{
	return GE("Header_txtKeyWord").value;
}
function getCategories()
{
	if(GE("Header_Categories"))
		return GE("Header_Categories").value;
	else
		return "0";
}

function getCategories1()
{
	if(GE("Categories"))
		return GE("Categories").value;
	else
		return -1;
}

function getSearchType()
{
	if(GE("Header_SearchType"))
		return GE("Header_SearchType").value;
	else
		return "2";
}

function getKWD1()
{
	return GE("txtKeyWord1").value;
}
function getCountry()
{
	if(GE("selectCountry"))
		return GE("selectCountry").value;
	else
		return -1;
}
function getMarkets()
{
	if(GE("selectMarkets"))
		return GE("selectMarkets").value;
	else
		return -1;
}
function getBusinessType()
{
	if(GE("selectBusinessType"))
		return GE("selectBusinessType").value;
	else
		return -1;
}
function getIsOEM()
{
	if(GE("selectBusinessType"))
		return GE("chk_OEM").checked ? 1:0;
	else
		return 0;
}
function getPurchaseType()
{
	if(GE("selectBusinessType"))
		return GE("selectBusinessType").value;
	else
		return -1;
}

function changPageSize(values)
{
	switch(getSearchType())
		{
			case "0":
				window.location= "/tradeleads/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values+"&pID="+pType+"&pID2="+pType2+"&pID3="+pType3;
				break;
			case "1":
				window.location="/buyingleads/Search.html?selectPurchaseType="+getPurchaseType()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values
				break;
			case "2":
				window.location= "/product/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values+"&pID="+pType+"&pID2="+pType2+"&pID3="+pType3;
				break;
			case "3":
				window.location= "/manufacturers/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values+"&pID="+pType+"&pID2="+pType2+"&pID3="+pType3;
				break;			
		}
}
function changPageSize1(values)
{
	switch(getSearchType())
		{
			case "0":
				window.location= "/tradeleads/P1T0V1IY"+pType2+"CZ"+pType3+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values;
				break;
			case "1":
				window.location="/buyingleads/Search.html?selectPurchaseType="+getPurchaseType()+"&kw="+ReplaceUrl(getKWD1())+"&pagesize="+values+"&pID="+pType+"&pID2="+pType2+"&pID3="+pType3;
				break;
			case "2":
				window.location= "/product/P1T1ICY"+pType2+"G0Z"+pType3+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values;
				break;
			case "3":
				window.location= "/manufacturers/P1CM0V"+pType1+"IY"+pType2+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+ReplaceUrl(getKWD())+"&pagesize="+values;
				break;			
		}
}
//new start
function SearchOfHead()
{
	var oKey=GE(objKey);
	var oType=GE(objType);
	if(oKey.value.trim().length<1)
	{
		alert("Please enter a keyword for search");
		oKey.focus();
		return false;		
	}
	else if(oKey.value.trim().length<2)
	{
		alert("Key word for search must at least 2 characters");
		oKey.focus();
		return false;
	}
	else if(oKey.value.trim().length>50)
	{
		alert("Key word for search must be less than 50 characters");
		oKey.focus();
		return false;
	}
	else if(ReplaceUrl(oKey.value).length<1)
	{
		alert("Please input the information in English instead");
		oKey.focus();
		return false;	
	}
	
	switch(oType.value)
		{
			case "0":
				window.location = "/tradeleads/P1T0V1IY0CZ0K/"+ReplaceUrl(oKey.value)+".html";
				break;
			case "1":
				window.location="/tradeleads/P1T0V2IY0CZ0K/"+ReplaceUrl(oKey.value)+".html";
				break;
			case "3":
				window.location = "/company/P1T1ICY0G0Z0K/"+ReplaceUrl(oKey.value)+".html";
				break;		
			default:
				window.location = "/product/P1T1ICY0G0Z0K/"+ReplaceUrl(oKey.value)+".html";
				break;	
		}
	
}

var IsSearchinputEnter = false;
function ValidateInput(e)
{
	IsSearchinputEnter = false;
	var key=e.keyCode;	
	
	if (key==13) 
	{
		SearchOfHead();
		IsSearchinputEnter = true;
	}
}
// end
function doSearch()
{
	if(getKWD().length<1)
	{		
		alert("Please enter a keyword for search");
		GE("Header_txtKeyWord").focus();
		return false;		
	}
	else if (getKWD().length==1) {
		alert("Key word for search must at least 2 characters");
		GE("Header_txtKeyWord").focus();
		return false;				
	}
	else if (getKWD().length>50) {
		alert("Key word for search must be less than 50 characters");
		GE("Header_txtKeyWord").focus();
		return false;				
	}
	else if (ReplaceUrl(getKWD()).length<1) {
		alert("Please input the information in English instead");
		GE("Header_txtKeyWord").focus();
		return false;	
	}
	
	if(getCategories()=="0")
	{
		switch(getSearchType())
		{
			case "0":
				window.location = "/tradeleads/P1T0V1IY0CZ0K/"+ReplaceUrl(getKWD())+".html";
				break;
			case "1":
				window.location="/tradeleads/P1T0V2IY0CZ0K/"+ReplaceUrl(getKWD())+".html";
				break;
			case "2":
				window.location = "/product/P1T1ICY0G0Z0K/"+ReplaceUrl(getKWD())+".html";
				break;
			case "3":
				window.location = "/company/P1T1ICY0G0Z0K/"+ReplaceUrl(getKWD())+".html";//"/manufacturers/P1CM0V0IY0K/"+ReplaceUrl(getKWD())+".html";
				break;			
		}
	}
	else
	{
		switch(getSearchType())
		{
			case "0":
				window.location ="/tradeleads/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD()))+"&pagesize="+pageSizes+"&pID="+getCategories();
				break;
			case "1":
				window.location="/buyingleads/Search.html?selectPurchaseType="+getPurchaseType()+"&kw="+escape(ReplaceUrl(getKWD()))+"&pagesize="+pageSizes+"&pID="+getCategories();
				break;
			case "2":
				window.location ="/product/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD()))+"&pagesize="+pageSizes+"&pID="+getCategories();
				break;
			case "3":
				window.location ="/manufacturers/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD()))+"&pagesize="+pageSizes+"&pID="+getCategories();
				break;	
		}
	}
	return false;
}
function changGallery(state)
{
	window.location= "/product/P1T1ICY"+pType2+"G0Z"+pType3+"CN/" + CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(getKWD())+"&pagesize="+pageSize+"&viewMode="+state;
}
function doSearch1()
{
	if(getCountry()=="-1" && getMarkets()=="-1" && getBusinessType()=="-1" && getKWD1().length<1)
	{		
		alert("Please enter a keyword for search");
		GE("txtKeyWord1").focus();
		return false;
	}
	else if (getKWD().length==1) {
		alert("Key word for search must at least 2 characters");
		GE("Header_txtKeyWord").focus();
		return false;				
	}
	else if (getKWD().length>50) {
		alert("Key word for search must be less than 50 characters");
		GE("txtKeyWord1").focus();
		return false;				
	}
	switch(getSearchType())
		{
			case "0":
				window.location ="/tradeleads/P1T0V1IY"+pType2+"CZ"+pType3+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pID="+pType;
				break;
			case "1":
				window.location="/buyingleads/Search.html?selectPurchaseType="+getPurchaseType()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pageindex=1&pID="+getCategories();
				break;
			case "2":
				window.location ="/product/P1T1ICY"+pType2+"G0Z"+pType3+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize;
				break;
			case "3":
				window.location ="/manufacturers/P1CM0V"+pType1+"IY"+pType2+"CN/"+CategoryName+".html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize;
				break;			
		}	
	return false;
}
function doSearch3()
{
	//if( getCategories1()=="-1" && getCountry()=="-1" && getMarkets()=="-1" && getBusinessType()=="-1" && getKWD1().length<1)
	if( getKWD1().length<1)
	{		
		alert("Please enter a keyword for search");
		GE("txtKeyWord1").focus();
		return false;
	}
	else if (getKWD1().length==1) {
		alert("Key word for search must at least 2 characters");
		GE("txtKeyWord1").focus();
		return false;				
	}
	else if (getKWD1().length>50) {
		alert("Key word for search must be less than 50 characters");
		GE("txtKeyWord1").focus();
		return false;				
	}
	switch(getSearchType())
		{
			case "0":
				window.location ="/tradeleads/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pageindex=1&pID="+getCategories1()+"&pID2="+pType2+"&pID3="+pType3;
				break;
			case "1":
				window.location="/buyingleads/Search.html?selectPurchaseType="+getPurchaseType()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pageindex=1&pID="+getCategories();
				break;
			case "2":
				window.location ="/Product/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pageindex=1&pID="+getCategories1()+"&pID2="+pType2+"&pID3="+pType3;
				break;
			case "3":
				window.location ="/manufacturers/Search.html?selectCountry="+getCountry()+"&selectMarkets="+getMarkets()+"&selectBusinessType="+getBusinessType()+"&oem="+getIsOEM()+"&kw="+escape(ReplaceUrl(getKWD1()))+"&pagesize="+pageSize+"&pageindex=1&pID="+getCategories1()+"&pID2="+pType2+"&pID3="+pType3;
				break;				
		}	
	return false;
}
function AddRemoveValues(oChk){
	if(oChk.checked)
		GE("HdnSelectedValues").value += "," + oChk.value; 
	else
		GE("HdnSelectedValues").value = GE("HdnSelectedValues").value.replace("," + oChk.value,"");
}
function Contact(id)
{
	window.open("/sendMsg/sendMsg.html?chkIDs="+id);
	return false;
}
function ContactAll()
{
	if(GE("HdnSelectedValues").value.length>0)
		window.open("/sendMsg/sendMsg.html?chkIDs="+GE("HdnSelectedValues").value.substring(1,GE("HdnSelectedValues").value.length));
	else{
		alert("No item(s) selected.");
	}
	return false;
}
var timer;			
var currentSelect =-1;
function validate(e)
{	
	var strKey = getKWD();
	var key=e.keyCode;	
	
	if (key==13) {
		if (currentSelect!=-1) {
			GE("Header_txtKeyWord").value = arry[currentSelect][0].toString();
		}
		doSearch();
	}
	return;
	//up
	if (key==38){
		if (currentSelect<1) {
			currentSelect =0;
		}
		else{
			currentSelect--;
		}
		clearStyle();
		GE("searchLi"+currentSelect).className="active_a";
		GE("Header_txtKeyWord").value = arry[currentSelect][0].toString();
	 }//down 
	else if (key==40){ 
		if (currentSelect<arry.length-1){
			currentSelect++;
		}
		clearStyle();
		GE("searchLi"+currentSelect).className="active_a";
		GE("Header_txtKeyWord").value = arry[currentSelect][0].toString();
	} 	
	if (key>=48 && key<=90 || key==8 || key==32 || key== 45 || key==46 || key==13)
	{
		if (strKey.replace(/\s+/g,"").length>0) {
			//IndexHeader.SearchKey(strKey,doSearch_callback );
		}
		else{
			//DivSetVisibles();
		}
	}
}
var isEnterKeyUC = false;
function validateUC(e)
{
	var key=e.keyCode;	
	isEnterKeyUC = false;
	if (key==13) {
		isEnterKeyUC=true;
		doSearch();
	}
}


function focusStyle()
{
	for(var i=0;i<arry.length;i++)
	{
		if( arry[i][0].toString() == GE("Header_txtKeyWord").value)
		{
			clearStyle();
			currentSelect = i;
			GE("searchLi"+i).className="active_a";
		}
	}
}

function clearStyle(){
	for(var i=0;i<arry.length;i++){
		GE("searchLi"+i).className="";
	}
}
var arry =new Array();
function doSearch_callback(res)
{
	var result = res.value;
	if (result =="" && result == null)
		return;
	eval(result);
	result = "";
	for(var i=0;i<arry.length;i++){
		result	+="<LI ><A id='searchLi"+i+"' href=\"javascript:changeSearch('";
		switch(getSearchType()) {
		case "1" : 
			result += "/tradeleads/P1T0V2IY0CZ0K/";
			result += ReplaceUrl(arry[i][0].toString())+".html";
			break;
		case "2":
			result += "/product/P1T1ICY0G0Z0K/";
			result += ReplaceUrl(arry[i][0].toString())+".html";
			break;
		case "3":
			result += "/manufacturers/P1CM0V0IY0K/";
			result += ReplaceUrl(arry[i][0].toString())+".html";
			break;
		default:
			result += "/tradeleads/P1T0V1IY0CZ0K/";
			result += ReplaceUrl(arry[i][0].toString())+".html";
			break;
		}
		result += "','" + arry[i][0].toString();
		result += "');\">"+arry[i][0].toString()+"<SPAN>"+arry[i][1].toString()+" Results</SPAN></A></LI>";
	}
	if (arry.length<10) {
		for(var j=11;j>arry.length-1;j--){
			result += "<LI >&nbsp;</LI>";
		}
	}
	result +="<LI class=\"close02\"><A href=\"javascript:DivSetVisible(false)\"><IMG class=\"right\" style=\"MARGIN: 3px 6px 0px 0px\" src=\"/Images/close01.gif\"></A></LI>";
	GE("search_list").innerHTML = result;
	
	DivSetVisible(true);
	result =null;
	currentSelect =-1;
	focusStyle();
}
var changeUrl ="";
var isSearchBlur =false;
function changeSearch(url,keys){	
	DivSetVisible(false);
	GE("Header_txtKeyWord").value= keys;
	changeUrl = url;
	setTimeout('changeSearchNow()',1000);
	document.onmousedown = DivSetVisible;
}
function changeSearchNow(){
	window.location = changeUrl;
}
function DivSetVisibles()
{
	DivSetVisible(false);
}
function beOnBlur()
{
	isSearchBlur =true
}
var isEnterKey = false;
function SignInEnterKey(e)
{
	isEnterKey = false;
	var code=window.event ? event.keyCode:e.which
	if (code== 13)
	{ doSearch3();isEnterKey = true }
}
function bookmark(){
	var title=document.title
	var url=document.location.href
	if (window.sidebar) window.sidebar.addPanel(title, url,"");
	else if( window.opera && window.print ){
	var mbm = document.createElement('a');
	mbm.setAttribute('rel','sidebar');
	mbm.setAttribute('href',url);
	mbm.setAttribute('title',title);
	mbm.click();}
	else if( document.all ) window.external.AddFavorite( url, title);
}
function ViewService(flag)
{
	if(flag==1)//china
	{
		window.open('/services/China_Supplier.html')
	}
	else
	{
		window.open('/services/CreditPass.html')
	}
	//window.open('/services/');
}
function ViewHotRank()
{
	window.open('/services/Hot_Rank.html');
}
function AuthenticationStatus()
{
	window.open('/help/helpPage40.html');
}
function EmailPage(page)
{
	window.open('/sendMsg/sendemail.html?url='+page);
}
//document.onmousedown=DivSetVisibles;