function performSearch(c,d,k,p){ 
	// category, district, search key, page
	document.getElementById("contentcell").innerHTML = '<div align="center" valign="middle"><img src="../images/share/loader.gif" valign="middle" />&nbsp;&nbsp;<font class="general_txt">搜尋進行中...請稍候...</font></div>';
	if(window.XMLHttpRequest)
	{
		oRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}

	oRequest.open("POST", "/asp/process_search.asp", true);
	oRequest.onreadystatechange = refresh_search_content;

	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oRequest.send("cat="+c+"&dis="+d+"&key="+escape(k.replace('é','e').replace('É','E'))+"&c_page="+p);
	//oRequest.send("cat="+c+"&dis="+d+"&key="+k.replace(/ /g, '%20')+"&c_page="+p);
}


function refresh_search_content()
{
	if(oRequest.readyState == 4)
	{ 
		if(oRequest.status == 200)
		{
			var result = oRequest.responseText;
			document.getElementById("contentcell").innerHTML = result;
		}
	}
}

function search_gotopage(p){
	document.getElementById("contentcell").innerHTML = '<div align="center" valign="middle"><img src="../images/share/loader.gif" valign="middle" />&nbsp;&nbsp;<font class="general_txt">搜尋進行中...請稍候...</font></div>';
	if(window.XMLHttpRequest)
	{
		oRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}

	oRequest.open("POST", "/asp/process_search.asp", true);
	oRequest.onreadystatechange = refresh_search_content;

	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oRequest.send("c_page="+p+"&turnp=1");
}



/***********************************************************************/
/***** For Search Panel ***************************************************/
/***********************************************************************/
function showTypeMenu(){
	if (document.getElementById('typepulldown').style.display == '')
	{
		document.getElementById('typepulldown').style.display = 'none';
	}else{
		document.getElementById('typepulldown').style.display = '';
	}
}

function hideTypeMenu(){
	document.getElementById('typepulldown').style.display = 'none';
}

function selPullDown(id,html){
	document.getElementById('searchtype').innerHTML = '&nbsp;&nbsp;'+html;
	document.getElementById('searchtypeh').value=id;
	document.getElementById('typepulldown').style.display = 'none';
}

function showDisMenu(){
	if (document.getElementById('dispulldown').style.display == '')
	{
		document.getElementById('dispulldown').style.display = 'none';
	}else{
		document.getElementById('dispulldown').style.display = '';
	}
}

function selDisPullDown(id,html){
	document.getElementById('searchdis').innerHTML = '&nbsp;&nbsp;'+html;
	document.getElementById('searchdish').value=id;
	document.getElementById('dispulldown').style.display = 'none';
}

function showKeyBox(obj){
	obj.innerHTML = '<input type="text" name="searchkey" id="searchkey" size="12" onmouseout="resumeimg(this)" onkeyup="cpytxt(this.value)" onmouseover="cleantxt(this);" onfocus="this.value=\'\';" />';
	obj.onclick = null;
	//document.getElementById('searchkey').focus();
}

function resumeimg(obj){
	if (obj.value == '')
	{
		obj.value = '請輸入關鍵字';
		document.getElementById('searchkeyh').value = '';
	}else{
		document.getElementById('searchkeyh').value =obj.value;
	}
}

function cpytxt(t){
	if (t == '請輸入關鍵字')
	{
		t = '';
	}
	document.getElementById('searchkeyh').value = t;
}


function cpytxt2(t, e){
	var characterCode;
	var sLang;

	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	e = event;
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}

	if (document.getElementById('searchkeyh').value == t && characterCode == 13)
	{
		if (window.location.href.indexOf('/tc/') > 0)
		{
			sLang = 'tc';
		}else{
			sLang = 'sc';
		}
		restsearch(sLang);
	}else{
		if (t == '請輸入關鍵字')
		{
			t = '';
		}
		document.getElementById('searchkeyh').value = t;
	}
}

function cleantxt(obj){
	if (obj.value == '請輸入關鍵字')
	{
		obj.value = '';
	}
}

function search(){
	if (window.location.href.indexOf('search/search.asp') > 0 )
	{
		//already in search page
		document.getElementById('typepulldown').style.display = 'none';
		document.getElementById('dispulldown').style.display = 'none';
		performSearch(document.getElementById('searchtypeh').value,document.getElementById('searchdish').value,document.getElementById('searchkeyh').value,1);
	}else{
		//go to search page
		window.location.href = '/tc/trans.asp?section=search&redirect=/tc/search/search.asp&c='+document.getElementById('searchtypeh').value+'&d='+document.getElementById('searchdish').value+'&k='+document.getElementById('searchkeyh').value;
	}
}

function restsearch(sLang){
	c = document.getElementById('searchtypeh').value;
	d = document.getElementById('searchdish').value;
	k = document.getElementById('searchkeyh').value;
	//window.location.href = '/tc/trans.asp?section=search&redirect=/tc/search/restaurantsearch.asp&c='+c+'&d='+d+'&k='+k;
	if (navigator.userAgent.indexOf('Safari') != -1){
		window.location.href = '/'+sLang+'/search/restaurantsearch.asp?c='+c+'&d='+d+'&k='+k.replace('é','e').replace('É','E');
	}else{
		window.location.href = '/'+sLang+'/search/restaurantsearch.asp?c='+c+'&d='+d+'&k='+escape(k.replace('é','e').replace('É','E'));
	}
}


function getSearchShopDetail(qs){
	document.getElementById('tempsearchcontent').innerHTML = document.getElementById('contentcell').innerHTML;
	if(window.XMLHttpRequest)
	{
		oRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}

	oRequest.open("POST", '/asp/search_shopdetail.asp', true);
	oRequest.onreadystatechange = refresh_search_content;

	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oRequest.send("seriesid="+qs);
}

function getSearchCakeShopDetail(qs){
	document.getElementById('tempsearchcontent').innerHTML = document.getElementById('contentcell').innerHTML;
	if(window.XMLHttpRequest)
	{
		oRequest = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		oRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}

	oRequest.open("POST", '/asp/search_cakeshopdetail.asp', true);
	oRequest.onreadystatechange = refresh_search_content;

	oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	oRequest.send("seriesid="+qs);
}

function backtosearchresult(){
	document.getElementById('contentcell').innerHTML = document.getElementById('tempsearchcontent').innerHTML;
}

var xx = 0;
var yy = 0;


function chkEnter(evt){
	var keyCode = (window.Event) ? evt.which : evt.keyCode;
	var sLang;
	if (keyCode == 13){
		if (window.location.href.indexOf('/tc/') > 0)
		{
			sLang = 'tc';
		}else{
			sLang = 'sc';
		}
		restsearch(sLang);
	}
}

