function KeyEncoding(str){
	
	keyword = replaceText(str, "%", "%25");
	keyword = replaceText(keyword, "/", "%252F");
	
	return keyword;
}

function replaceText ( OrgStr, Target, Change )
{
	var index, len=0;
	var fullStr = '';
	
	while ( (index=OrgStr.indexOf(Target)) >= 0)
	{
	        fullStr = fullStr + ''+ OrgStr.substring(0,index) + ''+Change ;
	
	        OrgStr = OrgStr.substring(index+Target.length);
	}
	return fullStr+''+OrgStr;
}

function SearchX()
{

  var form = document.searchForm;
  //var keyword = form.keyword.value;
  var keyword = document.getElementById('SearchTextIdx').value;
  var category = form.category.value;
  var l_path;

  if(keyword.length < 1) {
      alert('Please input a keyword.');
      form.keyword.focus();
      return false;
  }
  else
  {
	keyword = trim_keyword(keyword);
	if ( keyword.length <1 )
	{
		alert('Pleas input a keyword.');
		form.keyword.focus(); return false;
    }
  }

  /*
  if(check(keyword)){
       alert('Sorry, the information you filled in is not in English. Please input the information in English instead.');
       form.keyword.focus();
       return false;
  }
  */

  keyword = KeyEncoding(keyword);
 if(keyword.length > 0 && category.length > 1)
 	l_path = category + '/1/' + keyword + '.html';
 if(keyword.length > 0 && category.length < 2)
  	l_path = keyword + '.html';
  
//alert(keyword);
	if(form.st.value =='0')
	{
    location.href = '/ec-market/'+ l_path;
		return false;
	}
	else if(form.st.value =='1')
	{
    location.href = '/offers/' + l_path;
		return false;
	}
    else if(form.st.value =='2')
	{
    location.href = 'http://importer.ec21.com/buy_leads/' + l_path;
		return false;
	}
	 else if(form.st.value =='3')
	{
    location.href = '/companies/' + l_path;
		return false;
	}
}

function changeSearchType(sType)
{
	//select box
	var form = document.searchForm;                
	var typeSel = document.getElementById('IndexAreaOptionIdx');
	switch(sType){
		case("product"):{
			typeSel.value="0"; break;}
		case("sell"):{
			typeSel.value="1"; break;}
		case("buy"):{
			typeSel.value="2"; break;}
		case("company"):{
			typeSel.value="3"; break;}
	}

	//boxing - reset
	var searchTabProduct = document.getElementById("searchTabProduct");
	var searchTabSell = document.getElementById("searchTabSell");
	var searchTabBuy = document.getElementById("searchTabBuy");
	var searchTabCompany = document.getElementById("searchTabCompany");

	searchTabProduct.className = "";
	searchTabSell.className = "";
	searchTabBuy.className = "";
	searchTabCompany.className = "";

	switch(sType){
		case("product"):{ searchTabProduct.className = "current"; break; }
		case("sell"):{ searchTabSell.className = "current"; break; }
		case("buy"):{ searchTabBuy.className = "current"; break; }
		case("company"):{ searchTabCompany.className = "current"; break; }
	}
}
                                                             
function SearchChkX(obj){ 
	var form = document.searchForm;
	var keyword = form.keyword.value;
	var category = form.category.value;
	var l_path;
    
	keyword = KeyEncoding(keyword);
	if(keyword.length > 0 && category.length > 1)
		l_path = category + '/1/' + keyword + '.html';
	else if(keyword.length > 0 && category.length < 2)
		l_path = keyword + '.html';
  	
	if(keyword.length > 0){ 
		if(form.st.value =='0')
		{
			location.href = '/ec-market/'+ l_path;
		}
		else if(form.st.value =='1')
		{
			location.href = '/offers/' + l_path;
		}
		else if(form.st.value =='2')
		{
			location.href = 'http://importer.ec21.com/buy_leads/' + l_path;
		}
		 else if(form.st.value =='3')
		{
			location.href = '/companies/' + l_path;
		}
	}
	return;
}

function jsView(offer_id)
{
	window.open('http://www.ec21.com/RequestProcessor?event=LeadsDesc.Click&offer_id='+offer_id, '', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=yes, width=770, height=580, top=50, left=50');
    return;
}

function showCategoryCount(categoryCount, offerType)
{
	for (var i=0; i<categoryCount.length; i++)
	{
		var cntElement = document.getElementById("categoryCnt"+categoryCount[i].categorymId);
		//var cntProcElement = document.getElementById("categoryProductCnt"+categoryCount[i].categorymId);

		if (cntElement != null)
		{
			if (offerType=="B")
			{
				cntElement.appendChild(document.createTextNode(categoryCount[i].BofrEcnt));
			}
			else if (offerType=="S")
			{
				cntElement.appendChild(document.createTextNode(categoryCount[i].SofrEcnt));
			}
			//cntProcElement.appendChild(document.createTextNode(categoryCount[i].ProdEcnt));
		}
	}

}