// JavaScript Document

var qsParm = new Array();
  
function retrieveGETqs() {
 var query = window.location.search.substring(1);
 var parms = query.split('&');
 for (var i=0; i<parms.length; i++) {
   var pos = parms[i].indexOf('=');
   if (pos > 0) {
     var key = parms[i].substring(0,pos);
     var val = parms[i].substring(pos+1);
     qsParm[key] = val;
   }
 }
}

function setShopJSON(shp_id){
	strURL = "./getDetail.php";
	strURL+= "?shp_id=" + shp_id;
	strURL+= "&id=" + Math.random();
	//alert(strURL);
	new Ajax.Request(strURL, {method: 'get', onComplete: setShopJSONReceive});
}

function setShopJSONReceive(httpObj){
	text = httpObj.responseText;
	t = text.parseJSON();
	$('shopDetail_Name').innerHTML		=decodeURIComponent(t.shp_vch0);
	$('shopDetail_Floor').innerHTML		=decodeURIComponent(t.shp_vch2+"&nbsp;"+t.shp_vch3);
	$('shopDetail_Category').innerHTML	=decodeURIComponent(t.shp_vch5);
	$('shopDetail_Tel').innerHTML		=decodeURIComponent(t.shp_vch6);
	$('shopDetail_Time').innerHTML		=decodeURIComponent(t.shp_vch8).replace(/\n/g,"<br>");
	$('shopDetail_Products').innerHTML	=decodeURIComponent(t.shp_vch9);
	$('shopDetail_Url').innerHTML		=decodeURIComponent(t.shp_vch10);
	$('shopDetail_Url').href			=decodeURIComponent(t.shp_vch10);
	//$('shopDetail_Url').onclick			=openURL(decodeURIComponent(t.shp_vch10));
	//$('shopDetail_Url').style.cursor="hand"
	//$('shopDetail_Url').onmousemove	=function(){this.style.background = '#FFFFCC';};
	//$('shopDetail_Url').onmouseout	=function(){this.style.background = '#FFFFFF';};
	
	$('shopDetail_Contents').innerHTML	=decodeURIComponent(t.shp_txt0);
	$('shopimg').src	=("../files/"+t.shp_vch11);
	$('logoimg').src	=("../files/"+t.shp_vch12);
	
	var returnURL="";
	if(t.shp_vch2=="ROX") returnURL="floor_rox.html";
	if(t.shp_vch2=="ROX2G") returnURL="floor_rox2.html";
	if(t.shp_vch2=="ROX3") returnURL="floor_rox3.html";
	if(t.shp_vch2=="ROX%20DOME") returnURL="floor_roxd.html";
	//alert(t.shp_vch2);
	$('returnFloor').href	=(returnURL+"?building="+t.shp_vch2+"&floor="+t.shp_vch14);
	if(t.shp_vch11=="")$('shopimg').outerHTML="";
	if(t.shp_vch12=="")$('logoimg').outerHTML="";
	if(t.shp_vch10=="")$('outURL').style.display="none";
}
function openURL(URL){
	var fn = function(e){
		//location.href=URL;
		window.open(URL,'linkWindow','_blank');
	};
	return fn;
}


function searchCategory(category){
	//location.href='./category.html?category='+encodeURIComponent(category) + "&id=" + Math.random();
	location.href='./category.html?category='+encodeURIComponent(category);
}

function setCategoryList(){
	retrieveGETqs();
	category=qsParm['category'];

	strURL = "./getCategoryList.php";
	strURL+= "?category=" + category;
	//strURL+= "&id=" + Math.random();
	//alert(strURL);
	new Ajax.Request(strURL, {method: 'get', onComplete: setCategoryListRecieve});
}

function setCategoryListRecieve(httpObj){
	text = httpObj.responseText;
	//alert(text);
	t = text.parseJSON();
	//alert('parse ok='+t.CategoryList);
	objTableList = $("CategoryList");
	var shp_id=0;
	for(i=0;i<t.listCount;i++){
		var _tr = objTableList.insertRow(-1);
		_tr.style.cursor="hand";
		_tr.className="top";
		shp_id=t.shp_dat[i].shp_id;
		_tr.onclick		=loadDetail(shp_id);
		var _td0=_tr.insertCell(0);
		
		var thObj = document.createElement("table");
		var _tr1 = thObj.insertRow(-1);
		var _tr2 = thObj.insertRow(-1);
		var _td11=_tr1.insertCell(0);
		var _td21=_tr2.insertCell(0);
		var _td22=_tr2.insertCell(1);
		_td0.appendChild(thObj);  
		thObj.style.background = 'transparent';
		thObj.style.width='96%';
		thObj.className='clTable';
		thObj.onmousemove	=function(){this.style.background = '#FFFFCC';};
		thObj.onmouseout	=function(){this.style.background = '#FFFFFF';};
		
		_td11.className="shop";
		_td11.colSpan=2;
		_td21.className="floor";
		_td22.className="category";
			
		_td11.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch0);
		_td21.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch2+" "+t.shp_dat[i].shp_vch3);
		_td22.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch9);

	}
}
function loadDetail(shp_id){
	var fn = function(e){
		location.href='./detail.html?shp_id='+shp_id
	};
//		location.href='./detail.html?shp_id='+shp_id + "&id=" + Math.random();

	return fn;
}

function setKeywordsList(){
	retrieveGETqs();
	keywords=qsParm['keywords'];

	strURL = "./getKeywordsList.php";
	strURL+= "?keywords=" + keywords;
	//strURL+= "&id=" + Math.random();
	//alert(strURL);
	new Ajax.Request(strURL, {method: 'get', onComplete: setKeywordsListRecieve});
}

function setKeywordsListRecieve(httpObj){
	text = httpObj.responseText;
	t = text.parseJSON();
	objTableList = $("KeywordsList");
	var shp_id=0;
	for(i=0;i<t.listCount;i++){
		var _tr = objTableList.insertRow(-1);
		_tr.style.cursor="hand";
		_tr.className="top";
		shp_id=t.shp_dat[i].shp_id;
		_tr.onclick		=loadDetail(shp_id);
		var _td0=_tr.insertCell(0);
		
		var thObj = document.createElement("table");
		var _tr1 = thObj.insertRow(-1);
		var _tr2 = thObj.insertRow(-1);
		var _td11=_tr1.insertCell(0);
		var _td21=_tr2.insertCell(0);
		var _td22=_tr2.insertCell(1);
		_td0.appendChild(thObj);  
		thObj.style.background = 'transparent';
		thObj.style.width='96%';
		thObj.className='clTable';

		thObj.onmousemove	=function(){this.style.background = '#FFFFCC';};
		thObj.onmouseout	=function(){this.style.background = '#FFFFFF';};
		
		_td11.className="shop";
		_td11.colSpan=2;
		_td21.className="floor";
		_td22.className="category";
			
		_td11.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch0);
		_td21.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch2+" "+t.shp_dat[i].shp_vch3);
		_td22.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch9);

	}
}


function setFloorList(){
	retrieveGETqs();
	building=qsParm['building'];
	sfloor=qsParm['floor'];
	smap=qsParm['map'];

	strURL = "./getFloorList.php";
	strURL+= "?building=" + building;
	strURL+= "&floor=" + sfloor;
	//strURL+= "&id=" + Math.random();
	//alert(strURL);
	new Ajax.Request(strURL, {method: 'get', onComplete: setFloorListRecieve});
}

function setFloorListRecieve(httpObj){
	text = httpObj.responseText;
	//alert(text);
	t = text.parseJSON();
	//alert('parse ok='+t.CategoryList);
	objTableList = $("FloorList");
	var shp_id=0;
	//alert(t.shp_vch2);
	//alert(t.shp_vch3);
	var sbuf="images/map_"+t.shp_vch2+"_"+t.shp_vch3+".gif";
	sbuf=sbuf.replace(" ","_");
	//alert(sbuf);
	$('mapimg').src=sbuf;
	$('cfloor').src="images/cfloor_"+t.shp_vch3.replace(" ","_")+".gif";
	//alert("images/map_"+t.shp_vch2.replace(" ","_")+"_"+t.shp_vch3.replace(" ","_")+".gif"+";"+"images/cfloor_"+t.shp_vch3.replace(" ","_")+".gif");
	for(i=0;i<t.listCount;i++){
		var _tr = objTableList.insertRow(-1);
		_tr.style.cursor="hand";
		_tr.className="top";
		var _td0=_tr.insertCell(0);	
		
		
		var thObj = document.createElement("table");
		var _tr1 = thObj.insertRow(-1);
		var _tr2 = thObj.insertRow(-1);
		var _td11=_tr1.insertCell(0);
		var _td12=_tr1.insertCell(1);
		var _td21=_tr2.insertCell(0);
		_td0.appendChild(thObj);  
		thObj.style.background = 'transparent';
		thObj.style.width='96%';
		thObj.className='clTable';

		_td11.className="fno";
		_td11.rowSpan=2;
		_td12.className="shop";
		_td21.className="category";
			
		_td11.innerHTML = "["+decodeURIComponent(t.shp_dat[i].shp_vch4)+"]";
		_td12.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch0);
		_td21.innerHTML = decodeURIComponent(t.shp_dat[i].shp_vch9);
		
		thObj.onmousemove	=function(){this.style.background = '#FFFFCC';};
		thObj.onmouseout	=function(){this.style.background = '#FFFFFF';};
		shp_id=t.shp_dat[i].shp_id;
		_tr.onclick		=loadDetail(shp_id);
					
	}
}
