﻿var d = document;var shopObj = new Object();var natureID = level2;var terminalID = level3;var catID = level4;var linkList = new Array();if (natureID == "insideshopping"){	var tmp = natureID.replace("inside", "");	natureID = tmp; }//window.status = "natureID: "+natureID+"  :  terminalID: "+terminalID+"  :  catID: "+catID;var urlSplit = location.href.split('/');var brandID = urlSplit[urlSplit.length-1].split('.')[0];var xmlStatus = new Array();var xmlList = new Array();var titleObj = new Object;var titleGroupObj = new Object;var titleCatObj = new Object; //modified on 2009 02var shopSectArray = new Array('shopping', 'dining', 'entertainment');var nature = shopSectArray[0];var term = 'all'; //modified on 2008 12 - allow to search for all shopsvar cat = 'all';var brand = '';//loadXML('brand.xml', brandXMLHandler)//loadXML('shop.xml', shopXMLHandler)function genAllObj(){	//alert('genAllObj after all xml loaded');	//genTitle(xmlList[1]);	//genObj(xmlList[0]);	//genShopSearch();	if(xmlList[0])	{		genTitle(xmlList[0]);		genObj(xmlList[0]);	}	if(d.getElementById('terminalGroup'))	{		genShopSearch();	}}function genObj(){}//init multi xml handlingfunction multiXMLHandler(x, i){	xmlReady(x, i)}//for brand detail xml handlingfunction brandXMLHandler(x){	/* Modified on 2009 01 - disable generate details function*/	//genBrandDetail(x);}//for shop detail xml handlingfunction shopXMLHandler(x, tid, sid){	//genShopDetail(x, tid, sid); /* modified on 2009 01 - disable generate details function*/}// urls == array of xml s//e.g. loadXMLList('abc.xml', 'def.xml');function loadXMLList(){	var urls = loadXMLList.arguments;	/*for (var i=0; i<urls.length; i++)	{		xmlStatus[i] = false;	}	for (var i=0; i<urls.length; i++)	{		loadXML(urls[i], multiXMLHandler, i);	}*/	xmlStatus[0] = false;	if(urls[0].search('shops.xml') > 0)	{		urls[0] = urls[0].replace("shops.xml","shops_map.xml");	}	loadXML(urls[0], multiXMLHandler, 0);}function xmlReady(xml, index){	xmlStatus[index] = true;	xmlList[index] = xml;	var xmlDone = true;	for (var i=0; i<xmlStatus.length; i++)	{		if (!(xmlStatus[i]))		{			xmlDone = false;		}	}			if (xmlDone)		{			genAllObj();		}}function loadXML(url, handler, i){//alert(handler);	var x;	if (!i) i=0;	if (window.XMLHttpRequest) // Mozilla, Safari,...	{		x = new XMLHttpRequest();		if (x.overrideMimeType)	x.overrideMimeType('text/xml');	}	else if (window.ActiveXObject) // IE	{		try		{			x = new ActiveXObject("Msxml2.XMLHTTP");		}		catch (e)		{			try			{				x = new ActiveXObject("Microsoft.XMLHTTP");			}			catch (e)	{}		}	}		if (x)	{		x.onreadystatechange = function()			{				if (x.readyState == 4 && x.status == 200)					{						handler(x, i);					}			}		x.open('GET', url, true);		x.send(null);	}}function loadShopXML(url, handler, i, sid){//alert(handler);	var x;	if (!i) i=0;	if (window.XMLHttpRequest) // Mozilla, Safari,...	{		x = new XMLHttpRequest();		if (x.overrideMimeType)	x.overrideMimeType('text/xml');	}	else if (window.ActiveXObject) // IE	{		try		{			x = new ActiveXObject("Msxml2.XMLHTTP");		}		catch (e)		{			try			{				x = new ActiveXObject("Microsoft.XMLHTTP");			}			catch (e)	{}		}	}		if (x)	{		x.onreadystatechange = function()			{				if (x.readyState == 4 && x.status == 200)					{						handler(x, i, sid);					}			}		x.open('GET', url, true);		x.send(null);	}}function genTitle(x){	var root = x.responseXML.getElementsByTagName('titleGroup').item(0).childNodes;		for (var i=0; i<root.length; i++)	{		var name = root.item(i).nodeName;		var titles = root.item(i).childNodes;		titleGroupObj[name] = new Object();				for (var j=0; j<titles.length; j++)		{			if (titles.item(j).firstChild)			{				var id = titles.item(j).attributes.getNamedItem("id").value.toString();				//modified on 2009 02				if(name=='categoryGroup'){					var cata = titles.item(j).attributes.getNamedItem("cat").value.toString();					titleCatObj[id] = cata;				}								titleObj[id] = titles.item(j).firstChild.data;				titleGroupObj[name][id] = titles.item(j).firstChild.data;			}		}	}}function checkTitle(name){	return titleObj[name];}function changeShopBtn(sect){	nature = sect;	for (var i in shopSectArray)	{		var btn = d.getElementById((shopSectArray[i]+'Btn'));				if (shopSectArray[i] == sect)		{			btn.src = path + '/img/shopping/btn_'+shopSectArray[i]+'_over.gif';			btn.clicked = true;		}		else		{			btn.src = path + '/img/shopping/btn_'+shopSectArray[i]+'.gif';			btn.clicked = false;		}	}		var o = d.getElementById('terminalGroup');	o.options.length = 1;	o = d.getElementById('categoryGroup');	o.options.length = 1;	//o = d.getElementById('insideCategoryGroup'); //modified on 2009 02	//o.options.length = 1;	o = d.getElementById('brandGroup');	o.options.length = 1;	cat = 'all'; //modified 2008 12 - allow to search for all shops	term = 'all'; //modified 2008 12 - allow to search for all shops	setComboBox('terminalGroup');	//setComboBox('brandGroup'); //modified 2008 12 - allow to search for all shops}var searchTid = 0;var searchCid = 0;var searchBid = 0;function setComboBox(id){	var list = genFinderData(xmlList[0], id);	var o = d.getElementById(id);	o.options.length = 1;		if (id == 'brandGroup')	{		list.sort(			function(a, b)			{			  if (a.name < b.name) {return -1}			  if (a.name > b.name) {return 1}			  return 0; 			}		);		//alert(list[0].brand + "  :  " + list[0].name);				for (var j in list)		{			var i = list[j].brand;						var isSame = false;			for (var k=0; k<o.options.length; k++)			{				if(o.options[k].value == i)				{					isSame = true;					break;				}			}			if (!isSame)	o.options.add(new Option(titleGroupObj[id][i], i));		}	}		else if(id=='terminalGroup') //modified on 2008 12 - added the option "ALL" for seaching shops in ALL terminals.	{		o.options.add(new Option("所有", "all"));		for (var i in list)		{			if(i!='')			o.options.add(new Option(titleGroupObj[id][i], i));		}				setCatComboBox('categoryGroup'); //modified on 2009 03 17		setComboBox('brandGroup'); //modified on 2009 03 17	}	else	{		for (var i in list)		{			o.options.add(new Option(titleGroupObj[id][i], i));		}	}			}function setCatComboBox(id){	var list = genFinderData(xmlList[0], id);	var o = d.getElementById(id);	o.options.length = 1;	o.options.add(new Option("所有", "all")); //modified on 2009 03 17	for (var i in titleGroupObj[id])		{			if (!(list[i])) continue;						var titles = titleGroupObj[id][i].split('@@');						for (var ti in titles)				{					o.options.add(new Option(titles[ti], i));				}						//o.options.add(new Option(titleGroupObj[id][i], i));		}}function genShopSearch(){	var obj = titleGroupObj;	setComboBox('terminalGroup');	//setComboBox('brandGroup'); //modified on 2009 02 - allow to search for all shops }function selectTerminalGroup(item){	term = item.value;	cat = 'all';	brand = '';	if (term == '' || term == 'all' || term == 'alls')		{			term = 'all'; //modified on 2008 12 - allow to search for all shops						var o = d.getElementById('categoryGroup');			o.options.length = 1;						//dropdown_mousedown(d.getElementById('categoryGroup'), d.getElementById('insideCategoryGroup'),d.getElementById('dummy')); //modified on 2008 02 - clear the enlarged drop down			o = d.getElementById('insideCategoryGroup');						o.options.length = 1;						o = d.getElementById('brandGroup');			o.options.length = 1;			setCatComboBox('categoryGroup'); //modified on 2008 12 - to allow search ALL shops			setComboBox('brandGroup'); //modified on 2008 12 - to allow search ALL shops									return;		}	setCatComboBox('categoryGroup');	setComboBox('brandGroup');}function selectCategoryGroup(item){	cat = item.value;		/*if (cat == '')		{			o = d.getElementById('brandGroup');			o.options.length = 1;			return;		}	*/	setComboBox('brandGroup');}function selectBrandGroup(item){	brand = item.value;	//alert(natureID + ' : ' + term + ' : ' + cat + ' : ' + item.value);}function submitFinder(){	if (term == '') return;	//modified on 2008 12 - allow to search for all shops	if (cat == 'all' || cat == '')	{		if (brand != '')		{			cat = searchCat(xmlList[0], brand);		}else		{			return;		}	}	if (brand == '') return;	if (nature == "shopping")	var natLink = "insideshopping";	else	natLink = nature;	//modified on 2009 02 - to deal with Entertainment	if(nature == "entertainment")		term = 't2';		/* modified on 2008 12 - allow to search for all shops*/	//if (cat == "skyma")	//{	//	location.href = path + 'shopping/'+natLink+'/'+term+'/'+cat+'/list.html';	//}	//else	//{		location.href = path + 'shopping/'+natLink+'/'+term+'/'+cat+'/'+brand+'.html';		//}	//alert(natureID + ' : ' + term + ' : ' + cat + ' : ' + brand);}//modified on 2008 12 - allow to search for all shopsfunction searchCat(x, brandID){	var root = x.responseXML.getElementsByTagName('shopGroup').item(0);		var shops = root.getElementsByTagName('shop');	var list = new Array();		for (var i=0; i<shops.length; i++)	{		var cid = shops.item(i).getElementsByTagName('category').item(0).attributes.getNamedItem("id").value;		var bid = shops.item(i).getElementsByTagName('brand').item(0).attributes.getNamedItem("id").value;			if(brandID==bid)		{			if(cid.indexOf(',')>0)			{					var cate = cid.split(',');				for(var j=0;j<cate.length;j++)				{						if(nature == titleCatObj[cate[j]])					{						cid = cate[j];						break;					}				}			}									return cid;		}	}	return '';}//function genFinderData(x, groupid)function genFinderData(x, groupid){//genHTMLfile(x);//return;	var root = x.responseXML.getElementsByTagName('shopGroup').item(0);	var shops = root.getElementsByTagName('shop');	var list = new Array();		var str = '';	for (var i=0; i<shops.length; i++)		{			var id = shops.item(i).attributes.getNamedItem("id").value;			var nid = shops.item(i).getElementsByTagName('nature').item(0).attributes.getNamedItem("id").value;			var tid = shops.item(i).getElementsByTagName('terminal').item(0).attributes.getNamedItem("id").value;			var cid = shops.item(i).getElementsByTagName('category').item(0).attributes.getNamedItem("id").value;			var bid = shops.item(i).getElementsByTagName('brand').item(0).attributes.getNamedItem("id").value;			var bName = shops.item(i).getElementsByTagName('brand').item(0).attributes.getNamedItem("name").value.toLowerCase();			//modified on 2009 02			//if ((nature != nid) && (nid != ''))			if (!(nid.match(nature)) && (nid != ''))				{					continue;				}						switch(groupid)				{					case 'terminalGroup':						list[tid] = true;						break;					case 'categoryGroup':												if ((term != tid) && (term != '') && (term != 'all') && (term != 'alls')) //modified on 2008 12 - allow to search ALL terminal							{								continue;							}							//modified on 2009 02							if(cid.indexOf(',')>0)							{								var cate = cid.split(',');								for(var j=0;j<cate.length;j++)								{									if(nature == titleCatObj[cate[j]])									{										list[cate[j]] = true;									}								}							}else							{																list[cid] = true;							}						break;					case 'brandGroup':						if((term =='all' || term == 'alls') && (cat =='alls' || cat =='all')) //modified on 2008 12 - allow to search ALL terminal						{							list.push({brand:bid, name:bName});						}else						{							if (term != tid && term !='all')								{									continue;								}							if (!(cid.match(cat)) && (cat != 'all'))								{									continue;								}								list.push({brand:bid, name:bName});						}						break;				}		}	return list;}function genHTMLfile(x){	var root = x.responseXML.getElementsByTagName('shopGroup').item(0);	var shops = root.getElementsByTagName('shop');		var str = '';	for (var i=0; i<shops.length; i++)		{			var id = shops.item(i).attributes.getNamedItem("id").value;			var tid = shops.item(i).getElementsByTagName('terminal').item(0).attributes.getNamedItem("id").value			var cid = shops.item(i).getElementsByTagName('category').item(0).attributes.getNamedItem("id").value			var nid = shops.item(i).getElementsByTagName('nature').item(0).attributes.getNamedItem("id").value			var bid = shops.item(i).getElementsByTagName('brand').item(0).attributes.getNamedItem("id").value						str += 'xcopy list.html .&#92;'+nid+'&#92;'+tid+'&#92;'+cid+'&#92;list.html /Y';			str += '<BR>';			str += 'xcopy src.html .&#92;'+nid+'&#92;'+tid+'&#92;'+cid+'&#92;'+bid+'.html /Y';			str += '<BR>';									str += 'xcopy list.html .&#92;'+nid+'&#92;'+'all'+'&#92;'+cid+'&#92;list.html /Y';			str += '<BR>';			str += 'xcopy src.html .&#92;'+nid+'&#92;'+'all'+'&#92;'+cid+'&#92;'+bid+'.html /Y';			str += '<BR>';		}		d.write(str);}function initSortTable(){}