var xmlHttp

function showResult(str)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
var url="livesearch.php"
url=url+"?class="+str
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChanged
xmlHttp.send(null)
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 
 var classNum = document.getElementById("Area").value
 var strURL="findCircle.php?area="+classNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=stateChanged2
 xmlHttp.send(null)
 }
 else{
	lodingSet()
 } 
}

function stateChanged2() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("circlediv").
 innerHTML=xmlHttp.responseText;
 var obj = document.getElementById("Area");
 var string = obj.options[obj.selectedIndex].text;
 
  // var pTar = null;
  // var iframename = 'searchArea';
  // if (document.getElementById){
	// pTar = window.frames['searchArea'];
  // }
  // else{
    // pTar = document.getElementById(iframename);
  // }
  //string = encodeURIComponent(string)
 //pTar.location.href="http://www.atlaspost.com/act/fubon/mapiframe.php?location1="+string
	// loadforSearch(string, '') ;
 
 // 再塞類別
 var areaNum = document.getElementById("Area").value
 var strURL="findType.php?area="+areaNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=stateChanged4
 xmlHttp.send(null)
 }
 else{
	lodingSet()
 } 
}

function getType(str, circle)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }

var url="livesearchCircle.php"
url=url+"?area="+str+"&circle="+circle
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChanged3
xmlHttp.send(null)
} 

function stateChanged3() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 
 var areaNum = document.getElementById("Area").value
 var circleNum = document.getElementById("circle").value
 var strURL="findType.php?area="+areaNum+"&circle="+circleNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=stateChanged4
 xmlHttp.send(null)
 } 
 else{
	lodingSet()
 } 
}

function stateChanged4() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("typediv").
 innerHTML=xmlHttp.responseText;
 var obj1 = document.getElementById("Area");
 var obj2 = document.getElementById("circle");
 var string1 = obj1.options[obj1.selectedIndex].text
 var string2 = obj2.options[obj2.selectedIndex].text
 
 // var pTar = null;
  // var iframename = 'searchArea';
  // string1 = encodeURIComponent(string1)
  // string2 = encodeURIComponent(string2)
  // if (document.getElementById){
	// pTar = window.frames['searchArea'];
  // }
  // else{
    // pTar = document.getElementById(iframename);
  // }
  // if ( string2 == "請選擇行政區" ){
	// pTar.location.href="http://www.atlaspost.com/act/fubon/mapiframe.php?location1="+string1+"&location2="+string2;
  // }
  // else{
	// pTar.location.href="http://www.atlaspost.com/act/fubon/mapiframe.php?location1="+string1;
  // }
  // if (string2 == "請選擇行政區") loadforSearch(string1, '') ;
  // else loadforSearch(string1+string2, '') ;
 }
 else{
	lodingSet()
 } 
}

function getFinal(area, str, circle)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
 // 判斷是否有商圈
 var url="livesearchType.php"
if ( circle != "" ){
	url=url+"?area="+area+"&circle="+circle+"&type="+str
}
else{
	url=url+"?area="+area+"&type="+str
}
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChanged5
xmlHttp.send(null)
}

function getFinal1(area, str)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }

 var url="livesearchType.php"
 url=url+"?area="+area+"&type="+str
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChanged5
xmlHttp.send(null)
}

function stateChanged5() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 var obj1 = document.getElementById("Area");
 var obj2 = document.getElementById("circle");
 var obj3 = document.getElementById("type");
 var string1 = obj1.options[obj1.selectedIndex].text
 var string2 = obj2.options[obj2.selectedIndex].text
 var string3 = obj3.value
 
 // var pTar = null;
  // var iframename = 'searchArea';
  // string1 = encodeURIComponent(string1)
  // string2 = encodeURIComponent(string2)
  // string3 = encodeURIComponent(string3)
  // if (document.getElementById){
	// pTar = window.frames['searchArea'];
  // }
  // else{
    // pTar = document.getElementById(iframename);
  // }
  // if ( string2 == "請選擇行政區" ){
	// pTar.location.href="http://www.atlaspost.com/act/fubon/mapiframe.php?type="+string3+"&location1="+string1+"&location2="+string2;
  // }
  // else{
	// pTar.location.href="http://www.atlaspost.com/act/fubon/mapiframe.php?location1="+string1;
  // }
  // if (string2 == "請選擇行政區") loadforSearch(string1, string3) ;
  // else loadforSearch(string1+string2, string3) ;
 } 
 else{
	lodingSet()
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 // Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function lodingRemove(){
	$("#TB_load").remove();
	$("#TB_ImageOff").click(tb_remove);
	$("#TB_window").css({display:"block"}); //for safari using css instead of show
}

function lodingSet(){
	var tb_pathToImage = "images/loadingAnimation.gif";
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
}

function lodingSetIndex(){
	var tb_pathToImage = "images/loading.gif";
	imgLoader = new Image();// preload image
	imgLoader.src = tb_pathToImage;
	$("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
	$('#TB_load').show();//show loader
}

function refreshIframe(){
	//生一個IFRAME出來
	var iframe = document.getElementById("searchArea");
	//把檔案網址丟給IFRAM
	iframe.src = "modules/code_backup_download.php?file_name="+file_name;
	//把IFRAME設為不顯示
	iframe.style.display = "none";
	//把IRAME 附加到BODY
	document.body.appendChild(iframe);
}

// 主要分頁
function mainPaging( no ){
var url="livesearchMain.php"
url=url+"?no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=mainChangedArea
xmlHttp.send(null)
}

function mainChangedArea() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 }
 else{
	lodingSet()
 } 
}

// 地區分頁
function areaPaging( str, no ){
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
 
var url="livesearch.php"
url=url+"?class="+str+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChangedArea
xmlHttp.send(null)
}

function stateChangedArea() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 
 var classNum = document.getElementById("Area").value
 var strURL="findCircle.php?area="+classNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=stateChangedCircle
 xmlHttp.send(null)
 }
 else{
	lodingSet()
 } 
}

function stateChangedCircle() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("circlediv").
 innerHTML=xmlHttp.responseText;
 }
 else{
	lodingSet()
 } 
}

// 行政區分頁
function circlePaging(area, circle, no)
{
if (area.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }

var url="livesearchCircle.php"
url=url+"?area="+area+"&circle="+circle+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=circleChanged
xmlHttp.send(null)
} 

function circleChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 
 var areaNum = document.getElementById("Area").value
 var circleNum = document.getElementById("circle").value
 var strURL="findType.php?area="+areaNum+"&circle="+circleNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=circleReplace
 xmlHttp.send(null)
 } 
 else{
	lodingSet()
 } 
}

function circleReplace() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("typediv").
 innerHTML=xmlHttp.responseText;
 }
 else{
	lodingSet()
 } 
}

// 類別分頁
function typePaging(area, circle, str, no)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }

var url="livesearchType.php"
url=url+"?area="+area+"&circle="+circle+"&type="+str+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=typeChanged5
xmlHttp.send(null)
}

function typeChanged5() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 } 
 else{
	lodingSet()
 } 
}

// 類別分頁沒有商圈
function typePagingNoCircle(area, str, no)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }

var url="livesearchType.php"
url=url+"?area="+area+"&type="+str+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=typeChanged6
xmlHttp.send(null)
}

function typeChanged6() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 } 
 else{
	lodingSet()
 } 
}

// 關鍵字雲
function getkeyword( key ){
if (key.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
var url="livesearchKeyword.php"
url=url+"?keyword="+key
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=keyChanged
xmlHttp.send(null)
} 

function keyChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 }
 else{
	lodingSet()
 } 
}

// 關鍵字分頁
function keyPaging( str, no ){
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
 
var url="livesearchKeyword.php"
url=url+"?keyword="+str+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=keyPagined
xmlHttp.send(null)
}

function keyPagined() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 }
 else{
	lodingSet()
 } 
}

// 精選優惠分頁
function sPaging( no ){
if (no.length==0)
 { 
 document.getElementById("sp_content").
 innerHTML="";
 document.getElementById("sp_content").
 style.border="0px";
 return
 }
 
var url="livesearchSpecial.php"
url=url+"?no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=Pagined
xmlHttp.send(null)
}

function Pagined() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 lodingRemove()
 document.getElementById("sp_content").
 innerHTML=xmlHttp.responseText;
 document.getElementById("sp_content").
 style.border="0px";
 }
  else{
	lodingSet()
 } 
}

// 關鍵字輸入搜尋
function keySearch(str)
{
if (str.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
var srarchString = encodeURIComponent(str);
var url="keySearch.php"
url=url+"?keyword="+srarchString
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=keySearchChanged
xmlHttp.send(null)
}

function keySearchChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 }
 else{
	lodingSet()
 } 
}

// 關鍵字輸入搜尋分頁
function keySearchPaging( key, no ){
if (no.length==0)
 { 
 document.getElementById("result_wrap").
 innerHTML="";
 document.getElementById("result_wrap").
 style.border="0px";
 return
 }
var srarchString = encodeURIComponent(key);
var url="keySearch.php"
url=url+"?keyword="+srarchString+"&no="+no
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=Pagined
xmlHttp.send(null)
}

function Pagined() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 lodingRemove()
 document.getElementById("result_wrap").
 innerHTML=xmlHttp.responseText;
 document.getElementById("result_wrap").
 style.border="0px";
 }
  else{
	lodingSet()
 } 
}

// 美食工具
function showResultTools(str)
{
if (str.length==0)
 { 
 document.getElementById("food_map").
 innerHTML="";
 document.getElementById("food_map").
 style.border="0px";
 return
 }
var url="livesearchMap.php"
url=url+"?area="+str
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChangedMap
xmlHttp.send(null)
} 

function stateChangedMap() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("food_map").
 innerHTML=xmlHttp.responseText;
 document.getElementById("food_map").
 style.border="0px";
 
 var classNum = document.getElementById("Area").value
 var strURL="findCircleMap.php?area="+classNum
 strURL=strURL+"&sid="+Math.random()
 xmlHttp=GetXmlHttpObject()
 xmlHttp.open("GET",strURL,true)
 xmlHttp.onreadystatechange=stateChangedMapCircle
 xmlHttp.send(null)
 }
 else{
	lodingSet()
 } 
}

function stateChangedMapCircle() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("circlediv").
 innerHTML=xmlHttp.responseText;
 var obj = document.getElementById("Area");
 var string = obj.options[obj.selectedIndex].text;
 }
 else{
	lodingSet()
 } 
}

function getMapFinal(area, circle)
{
if (circle.length==0)
 { 
 document.getElementById("food_map").
 innerHTML="";
 document.getElementById("food_map").
 style.border="0px";
 return
 }
 var url="livesearchCircleMap.php"
url=url+"?area="+area+"&circle="+circle
url=url+"&sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=stateChangedMapFinal
xmlHttp.send(null)
}

function stateChangedMapFinal() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("food_map").
 innerHTML=xmlHttp.responseText;
 document.getElementById("food_map").
 style.border="0px";
 } 
 else{
	lodingSet()
 } 
}

// 找其餘照片
function getOtherVote(str)
{
var url="livesearchOther.php"
url=url+"?sid="+Math.random()
xmlHttp=GetXmlHttpObject()
xmlHttp.open("GET",url,true)
xmlHttp.onreadystatechange=otherComplete
xmlHttp.send(null)
} 

function otherComplete() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
	lodingRemove()
 document.getElementById("others").
 innerHTML=xmlHttp.responseText;
 document.getElementById("others").
 style.border="0px";
 }
 else{
	lodingSet()
 } 
}
