if(com==undefined) var com = {};
if(com.dc==undefined) com.dc = {};
/**************************************************************************************************
 * Utils.js
 * Description :  
 **************************************************************************************************/
com.dc.utils = new Utils();
var utils = com.dc.utils;
function Utils(){}
Utils.prototype.addListener = function(element, type, expression, bubbling){
	bubbling = bubbling || false;

	if(element.addEventListener) {
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(element.attachEvent) {
		element.attachEvent("on"+type, expression);
		return true;
	} else return false;
};
Utils.prototype.getParam = function(name){
	var start = location.search.indexOf("?"+name+"=");
	if (start < 0) start = location.search.indexOf("&"+name+"=");
	if (start < 0) return "";
	start += name.length+2;
	var end = location.search.indexOf("&",start)-1;
	if (end < 0) end=location.search.length;
	var result = location.search.substring(start,end);
	var result = "";
	for(var i=start;i<=end;i++){
		var c = location.search.charAt(i);
		result = result+(c=="+"?" ":c);
	}
	//alert(unescape(result));
	return unescape(result);
}
Utils.prototype.popup = function(url, name){
	var win_w = 975;
	var win_h = 580;
	var loc_x = (window.screen.width - win_w)/2;
	var loc_y = (window.screen.height - win_h)/2;
	var s = 1;
	var r = 1;
	var settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	window.open(url, name, settings);
}

/**************************************************************************************************
 * Ajax.js
 * Description :  
 **************************************************************************************************/
com.dc.ajax = new Ajax();
var ajax = com.dc.ajax;
function Ajax(){
	//this.exploer = false;//not necessary
}
Ajax.prototype.request = function(path, method, sync, xml) {
	method = method || "GET";//default GET
	sync = sync || false;//default sync, not async
	xml = xml || "";//avoid sending out a null
	
	var ret;
	
	try{
		var xmlhttp = this.getXMLHttp();
		var exploer = false;
		if (!xmlhttp){
			return;
		}
		xmlhttp.open(method, path, sync);
		var mimeType = (xmlhttp.overrideMimeType) ? true: false;
		if (mimeType){
			exploer = false;
			xmlhttp.overrideMimeType("text/xml;charset=UTF-8");
		}
		else{
			exploer = true;
			xmlhttp.setRequestHeader("content-type","text/xml; charset=UTF-8");
		}	
		xmlhttp.send("");	
		if(exploer){
			ret = new ActiveXObject("Microsoft.XMLDOM");
			ret.async = "false";
			ret.loadXML(xmlhttp.responseText);
		}else{
			ret = xmlhttp.responseXML;
		}	
	}catch (e){
	}finally{	
	}
	return ret;
};
Ajax.prototype.requestHtml = function(path, method, sync, xml) {
	method = method || "GET";//default GET
	sync = sync || false;//default sync, not async
	xml = xml || "";//avoid sending out a null
	
	var ret;
	
	try{
		var xmlhttp = this.getXMLHttp();
		var exploer = false;
		if (!xmlhttp){
			return;
		}
		xmlhttp.open(method, path, sync);
		var mimeType = (xmlhttp.overrideMimeType) ? true: false;
		if (mimeType){
			exploer = false;
			xmlhttp.overrideMimeType("text/xml;charset=UTF-8");
		}
		else{
			exploer = true;
			xmlhttp.setRequestHeader("content-type","text/xml; charset=UTF-8");
		}	
		xmlhttp.send("");	
		ret = xmlhttp.responseText;
	}catch (e){
	}finally{	
	}
	return ret;
};
Ajax.prototype.getXMLHttp = function(){
	var obj;
	try{
		if (window.XMLHttpRequest){
			/* If IE7, Mozilla, Safari, etc: Use native object*/
			obj = new XMLHttpRequest();
		} else if (window.ActiveXObject){
			/* ...otherwise, use the ActiveX control for IE5.x and IE6*/
			try{
				obj = new ActiveXObject("MSXML2.ServerXMLHTTP");
			}catch (err){
				obj = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}catch (e){
	}finally{	
	}
	return obj;
};
Ajax.prototype.parse = function(str){
	var xmlDoc;
	if (window.XMLHttpRequest){ // code for IE7, Firefox, Opera, etc.
		xmlDoc = this.parseFromString(str, "text/xml");
	}else { // code for IE6, IE5
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async = "false";
		xmlDoc.loadXML(str);
	}	
	return xmlDoc;
};
Ajax.prototype.parseFromString = function(str, contentType) {
	if (typeof ActiveXObject != "undefined") {
		var d = new ActiveXObject("MSXML.DomDocument");
		d.loadXML(str);
		return d;
	}else if (typeof XMLHttpRequest != "undefined") {
		var req = new XMLHttpRequest;
		req.open("GET", "data:" + (contentType || "application/xml") +";charset=utf-8," + encodeURIComponent(str), false);
		if (req.overrideMimeType) {
		   req.overrideMimeType(contentType);
		}
		req.send("");
		return req.responseXML;
	}
}
Ajax.prototype.makeLoader = function(id){
	var element = document.getElementById(id);
	if(element==null) return;
	element.innerHTML = "<div align='center'><img src='/common/images/ajax-loader.gif'/></div>";
}
 /**************************************************************************************************
 * PagingDiv.js
 * Description :  
 **************************************************************************************************/
function PagingDiv(){
	this.prefix = "<<";	
	this.suffix = ">>";
	this.willHidePreviousNext = true; //set true to hidden prefix at first page, and hidden suffix at last page
	this.activeClass = "active";
	
	this.totalItems = 0;
	this.itemPerPage = 0;//set by Paging()
	this.totalPage = 0;//set by Paging()
	this.maxPage = 0;//set by Paging()
	this.hasMaxPage = true;//set by Paging()
	
	this.divName = "";//the name of this div
	this.previousContainerName = "";
	this.numContainerName = "";
	this.nextContainerName = "";
	
	this.div;
	this.previousContainer;
	this.numContainer;
	this.nextContainer;
}
PagingDiv.prototype.setPagingDivName = function(str){
	this.divName = str;
	this.previousContainerName = str + "Previous";
	this.numContainerName = str + "Num";
	this.nextContainerName = str + "Next";
	
	this.div = document.getElementById(this.divName);
	this.previousContainer = document.getElementById(this.previousContainerName);
	this.numContainer = document.getElementById(this.numContainerName);
	this.nextContainer = document.getElementById(this.nextContainerName);
	
	if(!this.numContainer||this.numContainer==null||this.numContainer==undefined) return;
}	
PagingDiv.prototype.setTotalItems = function(str){
	this.totalItems = str;
}
PagingDiv.prototype.setItemPerPage = function(str){
	this.itemPerPage = str;
}
PagingDiv.prototype.setTotalPage = function(str){
	this.totalPage = str;
}
PagingDiv.prototype.setMaxPage = function(str){
	this.maxPage = str;
}
PagingDiv.prototype.setHasMaxPage = function(str){
	this.hasMaxPage = str;
}
PagingDiv.prototype.initItems = function(totalItems, itemPerPage){
	if(totalItems) this.totalItems = totalItems;
	if(itemPerPage) this.itemPerPage = itemPerPage;	
	this.totalPage = Math.ceil(totalItems / itemPerPage);
};
PagingDiv.prototype.genPaging = function(){
	if(this.totalPage<=0) return;

	this.numContainer.innerHTML = "";

	for(var i=0;i<this.totalPage;i++){
		var a = document.createElement("a");
		var text = document.createTextNode(i+1);
		a.appendChild(text);
		if(i+1==a) a.className = this.activeClass;
		
		a.href="javascript:;";
		
		if(a.addEventListener) {
			eval("a.addEventListener('click', function(){com.dc.paging.go("+(i+1)+");}, false);");
		} else if(a.attachEvent) {
			eval("a.attachEvent('onclick', function(){com.dc.paging.go("+(i+1)+");});");
		}	
		this.numContainer.appendChild(a);
	}		
};

PagingDiv.prototype.genPrevious = function(){
	var a = document.createElement("a");
	a.appendChild(document.createTextNode(this.prefix));
	a.href="javascript:;";
	
	if(a.addEventListener) {
		eval("a.addEventListener('click', function(){com.dc.paging.goPrevious();}, false);");
	} else if(a.attachEvent) {
		eval("a.attachEvent('onclick', function(){com.dc.paging.goPrevious();});");
	}		
	this.previousContainer.appendChild(a);
}
PagingDiv.prototype.genNext = function(){
	var a = document.createElement("a");
	a.appendChild(document.createTextNode(this.suffix));
	a.href="javascript:;";
	
	if(a.addEventListener) {
		eval("a.addEventListener('click', function(){com.dc.paging.goNext();}, false);");
	} else if(a.attachEvent) {
		eval("a.attachEvent('onclick', function(){com.dc.paging.goNext();});");
	}	
	this.nextContainer.appendChild(a);
}
PagingDiv.prototype.findCurrent = function(){
	var a = this.numContainer.getElementsByTagName("a");
	
	for(var i=0;i<a.length;i++){
		if(a[i].className==this.activeClass){
			return i+1;
		}
	}
	return 1;
};
PagingDiv.prototype.goPrevious = function(){
	var current = this.findCurrent();
	if(current==1) return;
	this.go(current-1);
};
PagingDiv.prototype.goNext = function(){
	var current = this.findCurrent();
	if(current>=this.totalPage) return;
	this.go(current+1);
};
PagingDiv.prototype.go = function(page){	
	this.updatePageNum(page);//manipulate the pagniation
	this.updateShowHidePreviousNext(page);		
};
PagingDiv.prototype.updatePageNum = function(page){
	var pageIndex = page-1;
	if(pageIndex<0) pageIndex = 0;

	var a = this.numContainer.getElementsByTagName("a");	
	if(a.length < pageIndex || a.length==0) return;	
	if(a[pageIndex].className == this.activeClass) return;
	
	for(var i=0;i<a.length;i++){
		a[i].className = "";
	}
	
	if(this.hasMaxPage){
		var firstPage = page;
		var lastPage = page;
		
		while(lastPage>1&&(firstPage%10!=1)){
			firstPage--;
		}
		while(lastPage<this.totalPage&&(lastPage%10!=0)){
			lastPage++;
		}
		
		for(var i=0;i<a.length;i++){
			a[i].style.display = "none";
		}
		firstPageIndex = firstPage - 1;
		lastPageIndex = lastPage - 1;
		if(firstPageIndex<0) firstPageIndex = 0;
		for(var i=firstPageIndex;i<lastPageIndex+1;i++){
			a[i].style.display = "";
		}
	}
	
	a[pageIndex].className = this.activeClass;	
};
PagingDiv.prototype.updateShowHidePreviousNext = function(page){
	if(!this.willHidePreviousNext) return;
	
	if(page==1) this.showPrevious(false);
	else this.showPrevious(true);
	if(page==this.totalPage) this.showNext(false);
	else this.showNext(true);
};

PagingDiv.prototype.showPrevious = function(flag){
	if(flag){
		this.previousContainer.style.display = "";
	}else{
		this.previousContainer.style.display = "none";
	}
};
PagingDiv.prototype.showNext = function(flag){
	if(flag){
		this.nextContainer.style.display = "";
	}else{
		this.nextContainer.style.display = "none";
	}
};
PagingDiv.prototype.cleanContainer = function(){
	this.previousContainer.innerHTML = "";
	this.nextContainer.innerHTML = "";
	this.numContainer.innerHTML = "";
}

 /**************************************************************************************************
 * paging.js
 * 
 * Description :  
 * just a simple js-based paging
 *
 *
 * Author : Felix.Chau
 * Version : v1.0.0
 * Creation Date : 25-Nov-2010
 * 
 * Usage:
 * 
 * (1) create ONE pagination Div as below:
 * <div id="{id}"><span id="{id}Previous"></span><span id="{id}Num"></span><span id="{id}Next"></span></div>
 * 
 * (2) create ONE content Div as below:
 * <div id="{contentDiv}">...</div>
 * 
 * (3) optional to create infinite shadow copy of pagination Div as below:
 * <div id="{id2}"><span id="{id2}Previous"></span><span id="{id2}Num"></span><span id="{id2}Next"></span></div>
 *
 * (4) initialize as below:
 * com.dc.paging.initDivName("{id}", "{contentDiv}", ["{id2}", "{id3}"....]);
 * com.dc.paging.initItems(10, 3);
 * 
 * (5) call javascript as below:
 * com.dc.paging.start();
 * 
 * Amendment History: 
 * *********need revise the shadowcopy
 **************************************************************************************************/
com.dc.paging = new Paging();
var paging = com.dc.paging;
function Paging(){
	this.totalItems = 0;
	this.itemPerPage = 3;//default 3 in this project
	this.totalPage = 0;//number of page
	this.maxPage = 10;//number of page to display in one time, unless click goPrevious or goNext
	this.hasMaxPage = true;//default max page 

	this.itemsContainerDivName = "";//div to store each items 
	this.itemsContainerDiv;
	
	//html instance reference of the div
	this.pagingDiv = new PagingDiv();
	this.pagingDivShadowCopy = new Array();
}
Paging.prototype.setItemsContainerDivName = function(str){
	this.itemsContainerDivName = str;
	this.itemsContainerDiv = document.getElementById(this.itemsContainerDivName);
	if(!this.itemsContainerDiv||this.itemsContainerDiv==null||this.itemsContainerDiv==undefined) return;
};
Paging.prototype.addPagingDivNameShadowCopy = function(newNames){
	if(typeof newNames=="Array"){
		//when it is Array
		for(var newName in newNames){	
			var copy = new PagingDiv();
			copy.setPagingDivName(newName);
			this.pagingDivShadowCopy.concat(copy);
		}
	}else{
		//when it is string
		var copy = new PagingDiv();
		copy.setPagingDivName(newNames);
		this.pagingDivShadowCopy.push(copy);
	}
};
Paging.prototype.initDivName = function(pagingDivName, itemsContainerDivName, pagingDivNameShadowCopy){
	if(pagingDivName) this.pagingDiv.setPagingDivName(pagingDivName);
	if(itemsContainerDivName) this.setItemsContainerDivName(itemsContainerDivName);
	if(pagingDivNameShadowCopy) this.addPagingDivNameShadowCopy(pagingDivNameShadowCopy);
};
Paging.prototype.initItems = function(totalItems, itemPerPage){
	this.pagingDiv.initItems(totalItems, itemPerPage);
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
		this.pagingDivShadowCopy[i].initItems(totalItems, itemPerPage);
	}	
};
Paging.prototype.init = function (){
	this.pagingDiv.setTotalItems(this.totalItems);
	this.pagingDiv.setItemPerPage(this.itemPerPage);
	this.pagingDiv.setMaxPage(this.maxPage);
	this.pagingDiv.setHasMaxPage(this.hasMaxPage);
	
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
		this.pagingDivShadowCopy[i].setTotalItems(this.totalItems);
		this.pagingDivShadowCopy[i].setItemPerPage(this.itemPerPage);
		this.pagingDivShadowCopy[i].setMaxPage(this.maxPage);
		this.pagingDivShadowCopy[i].setHasMaxPage(this.hasMaxPage);
	}	
};
Paging.prototype.start = function (){
	this.init();
	this.genPaging();
	this.genPrevious();
	this.genNext();
	this.go(1, true);
}
Paging.prototype.genPaging = function(){
	this.pagingDiv.genPaging();
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
		this.pagingDivShadowCopy[i].genPaging();
	}
};
Paging.prototype.genPrevious = function(){
	this.pagingDiv.genPrevious();
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
		this.pagingDivShadowCopy[i].genPrevious();
	}
}
Paging.prototype.genNext = function(){
	this.pagingDiv.genNext();
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
		this.pagingDivShadowCopy[i].genNext();
	}
}
Paging.prototype.go = function(page, first){	
	if(first){
		this.pagingDiv.go(page);	
		for(var i=0;i<this.pagingDivShadowCopy.length;i++){		
			this.pagingDivShadowCopy[i].go(page);	
		}
		this.showHideItemsByPage(page);//manipulate the center content
	}else{
		//$("#"+this.itemsContainerDivName).fadeOut("linear", function(){
			com.dc.paging.pagingDiv.go(page);	
			for(var i=0;i<com.dc.paging.pagingDivShadowCopy.length;i++){		
				com.dc.paging.pagingDivShadowCopy[i].go(page);	
			}
			com.dc.paging.showHideItemsByPage(page);//manipulate the center content
		//	$("#"+this.itemsContainerDivName).fadeIn("linear");
		//});
	}
};
Paging.prototype.goPrevious = function(){
	var current = com.dc.paging.pagingDiv.findCurrent();
	current = current - 1;
	if(current<1) current = 1;
	
	this.go(current);
	
/*	com.dc.paging.pagingDiv.goPrevious();	
	for(var i=0;i<com.dc.paging.pagingDivShadowCopy.length;i++){		
		com.dc.paging.pagingDivShadowCopy[i].goPrevious();	
	}*/
};
Paging.prototype.goNext = function(){
	var current = com.dc.paging.pagingDiv.findCurrent();
	current = current + 1;
	if(current>com.dc.paging.pagingDiv.totalPage) current = com.dc.paging.pagingDiv.totalPage;
	
	this.go(current);
/*	com.dc.paging.pagingDiv.goNext();	
	for(var i=0;i<com.dc.paging.pagingDivShadowCopy.length;i++){		
		com.dc.paging.pagingDivShadowCopy[i].goNext();	
	}*/
};
Paging.prototype.showHideItemsByPage = function(page){
	var items = this.itemsContainerDiv.getElementsByTagName("dl");
	for(var i=0;i<items.length;i++){
		items[i].style.display = "none";
	}
	var from = page*this.itemPerPage-this.itemPerPage;
	var to = page*this.itemPerPage;
	for(var i=from;i<items.length && i<to;i++){
		items[i].style.display = "";
	}
};
/**************************************************************************************************
 * SearchBlox.js
 * Description :  
 * Author : Felix.Chau
 * Version : v1.0.0
 * Creation Date : 25-Nov-2010
 * 
 * Usage: * 
 * var query = com.dc.utils.getParam("query");	
 * var page = com.dc.utils.getParam("page");	
 * var col = com.dc.utils.getParam("col");
 * com.dc.searchblox.search(col, query, page);
 * 
 * Amendment History: 
 **************************************************************************************************/
com.dc.searchblox = new SearchBlox();
var searchblox = com.dc.searchblox;
function SearchBlox(){
	this.defaultQuery = "?xsl=xml&pagesize=";
	this.pageSize = "9";
	this.servletUrl = "/searchblox/servlet/SearchServlet";
	this.searchResultPage = "/html/others/searchResult.html";
	this.isInit = false;	

	this.searchingText;
	this.noResultText;
	
	this.itemsContainerDivName = "";//div to store each items 
	this.itemsContainerDiv;
	
	this.prefix = "<<";	
	this.suffix = ">>";
	this.pagingDiv = new PagingDiv();
	this.pagingDivShadowCopy = new Array();
	
	this.featuredResultUrl = "/searchblox/servlet/Client";
	this.featuredResultIds = new Array();
}
SearchBlox.prototype.setPageSize = function(str){
	this.pageSize = str;
}
SearchBlox.prototype.setServletUrl = function(str){
	this.servletUrl = str + this.defaultQuery + this.pageSize;
}
SearchBlox.prototype.setItemsContainerDivName = function(str){
	this.itemsContainerDivName = str;
	this.itemsContainerDiv = document.getElementById(this.itemsContainerDivName);
	if(!this.itemsContainerDiv||this.itemsContainerDiv==null||this.itemsContainerDiv==undefined) return;
};
SearchBlox.prototype.addPagingDivNameShadowCopy = function(newNames){
	if(typeof newNames=="Array"){
		/*when it is Array*/
		for(var newName in newNames){	
			var copy = new PagingDiv();
			copy.setPagingDivName(newName);
			this.pagingDivShadowCopy.concat(copy);
		}
	}else{
		/*when it is string*/
		var copy = new PagingDiv();
		copy.setPagingDivName(newNames);
		this.pagingDivShadowCopy.push(copy);
	}
};
SearchBlox.prototype.initDivName = function(pagingDivName, itemsContainerDivName, pagingDivNameShadowCopy){
	if(pagingDivName) this.pagingDiv.setPagingDivName(pagingDivName);
	if(itemsContainerDivName) this.setItemsContainerDivName(itemsContainerDivName);
	if(pagingDivNameShadowCopy) this.addPagingDivNameShadowCopy(pagingDivNameShadowCopy);
};
SearchBlox.prototype.init = function(){
	this.searchingText = document.getElementById("searchingText");
	this.noResultText = document.getElementById("noResultText");
	
	this.initDivName("pagingTop", "searchResultsContainer", ["pagingBottom"]);

	this.isInit = true;
}
SearchBlox.prototype.showSearching = function(){
	if(this.searchingText) this.searchingText.style.display = "block";
	if(this.noResultText) this.noResultText.style.display = "none";
}
SearchBlox.prototype.showNoResult = function(){
	if(this.searchingText) this.searchingText.style.display = "none";
	if(this.noResultText) this.noResultText.style.display = "block";
}
SearchBlox.prototype.hideMessage = function(){
	this.searchingText.style.display = "none";
	this.noResultText.style.display = "none";
}
SearchBlox.prototype.goSearch = function(query, lang){
	if(!query || query==null || query=="") return;
	
	query = escape(query);
	lang = lang || "en";
	location.href = "/"+lang+this.searchResultPage+"?query="+value;
};
SearchBlox.prototype.search = function(col, query, page, first, lang){
	var that = this;
	if(!this.isInit) this.init();
	if(!query || query==null || query=="") return;
	if(first) this.showSearching();
	
	lang = lang || "en";
	debug.debug("lang:" + lang);
	col = (lang=="tc" ? 2 : (lang=="en" ? 1 : 1));
	debug.debug("col:" + col);
	query = unescape(query);
	query = escape(query);
	debug.debug("1query:" + query);
	query = query.replace(/%u/gim, "\\u");
	debug.debug("2query:" + query);
	
	page = page || 1;
	if(isNaN(page)) page = 1;
	page = parseInt(page);
	
	var xmlDoc;
	if(lang=="tc")
		xmlDoc = com.dc.ajax.request(this.servletUrl+"&query="+query+"&page="+page+"&col="+col);
	else
		xmlDoc = com.dc.ajax.request(this.servletUrl+"&query="+query+"&page="+page+"&col="+col);
	
	if(!xmlDoc){
		this.showNoResult();
	}else{
		this.parsePagination(col, query, page, xmlDoc, false, lang);

		if(first){
			var flag = this.parseResult(xmlDoc);
			if(flag) this.hideMessage();
			else this.showNoResult();
		}else{
			//$("#"+this.itemsContainerDivName).fadeOut("linear", function(){
				var flag = that.parseResult(xmlDoc);
				if(flag) that.hideMessage();
				else that.showNoResult();
			//	$("#"+this.itemsContainerDivName).fadeIn("linear");
			//});
		}
	}
};
SearchBlox.prototype.parseResult = function(xmlDoc){
	try{
		if(!xmlDoc) return false;
		var results = xmlDoc.getElementsByTagName("results");
		if(!results || results.length==0) return false;	
		
		var result = results[0].getElementsByTagName("result");
		if(!result || result.length==0) return false;
		
		var ret = "";
		for(var i=0;i<result.length;i++){
			var title = this.childNodes2Html(result[i].getElementsByTagName("title")[0].childNodes);
			var url = "";
			var urlElement = result[i].getElementsByTagName("url")[0];
			
			if(urlElement.textContent ) { url = urlElement.textContent;}
			else if(urlElement.text ) {url = urlElement.text;}
			var context = this.childNodes2Html(result[i].getElementsByTagName("description")[0].childNodes);
			
			ret += this.result2Html(title, url, context);
		}
		this.itemsContainerDiv.innerHTML = ret;
		this.itemsContainerDiv.style.display = "block";
		return true;
	}catch(e){
		return false;
	}
};
SearchBlox.prototype.parsePagination = function(col, query, page, xmlDoc, first, lang){
	var that = this;
	if(!xmlDoc) return;
	var results = xmlDoc.getElementsByTagName("results");
	results = results[0];

	var links  = xmlDoc.getElementsByTagName("links");
	if(!links  || links .length==0) return;	
	
	var link = links[0].getElementsByTagName("link");
	if(!link || link.length==0) return;
	
	this.pagingDiv.cleanContainer();
	for(var i=0;i<this.pagingDivShadowCopy.length;i++){
		this.pagingDivShadowCopy[i].cleanContainer();
	}
	
	var hasPrev = false;
	var hasNext = false;
	var maxPage = 0;
	for(var i=0;i<link.length;i++){
		var linkPage = link[i].getAttribute("page");
		
		if(isNaN(linkPage)){
			if(linkPage=="prev") hasPrev = true;
			else if(linkPage=="next") hasNext = true;
		}else{
			linkPage = parseInt(linkPage);
			
			if(maxPage==0){
				maxPage = linkPage;
			}else if (maxPage < linkPage){
				maxPage = linkPage;
			}			
			
			var a = document.createElement("a");
			var text = document.createTextNode(linkPage);
			a.appendChild(text);
			if(linkPage==page) a.className = "active";

			//a.href = location.pathname+"?query="+query+"&col="+col+"&page="+linkPage;
			a.href="javascript:;";
			if(a.addEventListener) {
				eval("a.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+linkPage+", " + first + ", \""+lang+"\");}, false);");
			} else if(a.attachEvent) {
				eval("a.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+linkPage+", " + first + ", \""+lang+"\");});");
			}			
			this.pagingDiv.numContainer.appendChild(a);
					
			for(var j=0;j<this.pagingDivShadowCopy.length;j++){
				var clone = a.cloneNode(true);
				if(clone.addEventListener) {
					eval("clone.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+linkPage+", " + first + ", \""+lang+"\");}, false);");
				} else if(clone.attachEvent) {
					eval("clone.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+linkPage+", " + first + ", \""+lang+"\");});");
				}	
				this.pagingDivShadowCopy[j].numContainer.appendChild(clone);
			}
		}
	}
	
	if(hasPrev){
		var previousA = document.createElement("a");
		previousA.appendChild(document.createTextNode(this.prefix));
		//previousA.href = location.pathname+"?query="+query+"&col="+col+"&page="+(page-1);
		previousA.href="javascript:;";
		if(previousA.addEventListener) {
			eval("previousA.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+(page-1)+", " + first + ", \""+lang+"\");}, false);");
		} else if(previousA.attachEvent) {
			eval("previousA.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+(page-1)+", " + first + ", \""+lang+"\");});");
		}
		this.pagingDiv.previousContainer.appendChild(previousA);
		
		for(var j=0;j<this.pagingDivShadowCopy.length;j++){
			var clone = previousA.cloneNode(true);
			if(clone.addEventListener) {
				eval("clone.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+(page-1)+", " + first + ", \""+lang+"\");}, false);");
			} else if(clone.attachEvent) {
				eval("clone.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+(page-1)+", " + first + ", \""+lang+"\");});");
			}	
			this.pagingDivShadowCopy[j].previousContainer.appendChild(clone);
		}
	}
	if(hasNext){
		var nextA = document.createElement("a");
		nextA.appendChild(document.createTextNode(this.suffix));
		//nextA.href = location.pathname+"?query="+query+"&col="+col+"&page="+(page+1);
		nextA.href="javascript:;";
		if(nextA.addEventListener) {
			eval("nextA.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+(page+1)+", " + first + ", \""+lang+"\");}, false);");
		} else if(nextA.attachEvent) {
			eval("nextA.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+(page+1)+", " + first + ", \""+lang+"\");});");
		}
		this.pagingDiv.nextContainer.appendChild(nextA);
		
		for(var j=0;j<this.pagingDivShadowCopy.length;j++){
			var clone = nextA.cloneNode(true);
			if(clone.addEventListener) {
				eval("clone.addEventListener('click', function(){that.search("+col+", \""+query+"\", "+(page+1)+", " + first + ", \""+lang+"\");}, false);");
			} else if(clone.attachEvent) {
				eval("clone.attachEvent('onclick', function(){that.search("+col+", \""+query+"\", "+(page+1)+", " + first + ", \""+lang+"\");});");
			}	
			this.pagingDivShadowCopy[j].nextContainer.appendChild(clone);
		}
	}
}
SearchBlox.prototype.result2Html = function(header, url, context){
	var div = document.createElement("div");

	var dl = document.createElement("dl");
	dl.className = "searchResults clearfix";
	
	var title = document.createElement("dd");
	title.className = "title";
	var a = document.createElement("a");
	a.innerHTML = unescape(header);
	a.href = unescape(url);
	title.appendChild(a);
	
	var detail = document.createElement("dd");
	detail.className = "promoDetail2";
	detail.innerHTML = context;
	
	dl.appendChild(title);
	dl.appendChild(detail);
	
	div.appendChild(dl);
	
	return div.innerHTML;
};
SearchBlox.prototype.childNodes2Html = function(childNodes){
	var str = "";
	for(var j=0;j<childNodes.length;j++){
		if(childNodes[j].firstChild && childNodes[j].firstChild.nodeValue!=null){
			str += "<span class='highlight'>"+childNodes[j].firstChild.nodeValue+"</span>";
		}
		if(childNodes[j].nodeValue!=null){
			str += childNodes[j].nodeValue;
		}
	}
	return str;
}
SearchBlox.prototype.setFeaturedResultUrl = function(str){
	this.setFeaturedResultUrl = str;
}
SearchBlox.prototype.setFeaturedResultIds = function(array){
	this.featuredResultIds = array;
}
SearchBlox.prototype.searchFeaturedResult = function(query){
	var thisInstance = this;
	var url = this.featuredResultUrl;
	var uids = "";
	for(var i=0;i<this.featuredResultIds.length;i++){
		uids += "&uid=" + this.featuredResultIds[i];
	}
	var reverseUids = this.featuredResultIds.reverse();
	$.ajax({
		type: "POST",
		url: url,
		data: "query=" + encodeURIComponent(query) + uids,
		success: function (jqXHR) {
			var json = $.parseJSON(jqXHR);
			var renderedAds = new Array();
			debug.debug("jqXHR:" + jqXHR);
			$(reverseUids).each(function(i, uid){
				var ad = json[uid];
				
				if(ad==undefined || ad==null)
					return;
				
				debug.debug("ad.title:" + ad.title);
				debug.debug("ad.description:" + ad.description);
				debug.debug("ad.url:" + ad.url);
				
				var dl = $("<dl/>").attr({
					"class": "searchResults lightblue clearfix"
				});
				
				if(ad.imageUrl){
					var promoImg = $("<dt/>").attr({
						"class": "promoImg"
					});
					
					var img = $("<img/>").attr({
						"src": ad.imageUrl
					});
					$(img).appendTo($(promoImg));
					$(promoImg).appendTo($(dl));
				}
				
				var title = $("<dd/>").attr({
					"class": "title"
				});
				
				var a = $("<a/>").attr({
					"href": ad.url,
					"text": ad.title
				})
				$(a).text(ad.title);
				$(a).appendTo($(title));
				$(title).appendTo($(dl));
				
				if(ad.description){
					$("<dd/>").attr({
						"class": (ad.imageUrl ? "promoDetail" : "promoDetail2")
					}).text(ad.description).appendTo($(dl));
				}
				
				$("#searchResultsContainer").prepend($(dl));
			});
		},
		error: function (jqXHR, textStatus, errorThrown) {
			console.log("error...");
		}
	});
}

/**************************************************************************************************
 * CardList.js
 * Description :  
 * Author : Felix.Chau
 * Version : v1.0.0
 * Creation Date : 25-Nov-2010
 * 
 * Usage:
 * Amendment History: 
 **************************************************************************************************/
com.dc.cardlist = new CardList();
var cardlist = com.dc.cardlist;
function CardList(){
	this.cards = ["leisure", "travel", "beauty", "restaurant", "financial", "charity", "other"];/*a default full list, will be replaced in list page*/
	this.selectDefaultOption = {en: "Choose One", tc: "Choose One(tc)"};
}
CardList.prototype.init = function(lang){
	this.initEvent();
	//this.initCardOption(lang);	
	//this.registerApplyNow();
	/*this.registerOpenSelectedCardDetail();*/
	
	this.initOnChange();
	this.showApplyNow();
}
CardList.prototype.setCards = function(cardType){
	this.cards = cardType;
}
CardList.prototype.initEvent = function(){
	var that = this;
	for(var i=0;i<this.cards.length;i++){
		var a = document.getElementById(this.cards[i]);
		if(!a) continue;
		if(a.addEventListener) {
			eval("a.addEventListener('click', function(){ location.href='card-type.html?type="+a.id+"'; that.showCardByTypeWrapper('"+this.cards[i]+"');that.changeHover('"+a.id+"');}, false);");
		} else if(a.attachEvent) {
			eval("a.attachEvent('onclick', function(){ location.href='card-type.html?type="+a.id+"'; that.showCardByTypeWrapper('"+this.cards[i]+"');that.changeHover('"+a.id+"');});");
		}
		
		var a2 = document.getElementById(this.cards[i]+"_text");
		if(a2.addEventListener) {
			eval("a2.addEventListener('click', function(){ that.showCardByTypeWrapper('"+this.cards[i]+"');that.changeHover('"+a2.id+"');}, false);");
		} else if(a2.attachEvent) {
			eval("a2.attachEvent('onclick', function(){ that.showCardByTypeWrapper('"+this.cards[i]+"');that.changeHover('"+a2.id+"');});");
		}
	}
	var type = com.dc.utils.getParam("type");
	if(type==""){
		this.changeHover(this.cards[0]);
		this.showCardByType(this.cards[0]);
	}else{
		var isFound = false;
		for(var i=0;i<this.cards.length;i++){
			if(type!=this.cards[i]) continue;
			this.changeHover(this.cards[i]);
			this.showCardByType(this.cards[i]);
			isFound = true;
		}	
		if(!isFound){
			this.changeHover(this.cards[0]);
			this.showCardByType(this.cards[0]);
		}
	}	
}
CardList.prototype.initCardOption = function(lang){
	lang = lang || "en";
/*	applyNowDropDownList.options.length = 0;	
	var selectDefaultOption = this.selectDefaultOption.en;
	if(lang=="ec") selectDefaultOption = this.selectDefaultOption.tc;	
	applyNowDropDownList.appendChild(new Option(selectDefaultOption, ""));*/
	
	for(var i=0;i<this.cards.length;i++){
		var optgroup = document.getElementById("applyNowDropDownList_"+this.cards[i].type);
		for(var j=0;j<this.cards[i].items.length;j++){
			//cardLineUp.appendChild(this.newCardLine(this.cards[i].items[j]));
			var option = new Option(this.cards[i].items[j].title, this.cards[i].items[j].link);
			optgroup.appendChild(option);
		}
		//applyNowDropDownList.appendChild(optgroup);
	}
}
CardList.prototype.initDetail = function(lang, type){
	var ret = com.dc.ajax.requestHtml("card-type.html");
	var root = document.createElement("div");
	root.innerHTML = ret;
	var div = root.getElementsByTagName("div");	
	for(var i=0;i<div.length;i++){
		if(div[i].id!="cardTypeDiv") continue;
		
		var cardTypeDiv = document.getElementById("cardTypeDiv");
		if(cardTypeDiv) cardTypeDiv.innerHTML = div[i].innerHTML;
		hoverFunction.ini();
		break;
	}
	
	this.initDetailEvent(type);
}
CardList.prototype.initDetailEvent = function(type){
	for(var i=0;i<this.cards.length;i++){
		/*$("#"+this.cards[i]).bind("click", function(){
			location.href="card-type.html?type="+$(this).id;
		});*/
		
		var a = document.getElementById(this.cards[i]);
		if(!a) continue;
		if(a.addEventListener) {
			eval("a.addEventListener('click', function(){ location.href='card-type.html?type="+a.id+"';return false;}, false);");
			/*a.addEventListener("click", function(){
				location.href="card-type.html?type="+a.id;
			}, false);*/
		} else if(a.attachEvent) {
			eval("a.attachEvent('onclick', function(){ location.href='card-type.html?type="+a.id+"';return false;});");
			/*a.attachEvent("onclick", function(){
				window.location ="card-type.html?type="+a.id;	
				return false;
			});*/
		}
	}
	this.changeHover(type);
}
CardList.prototype.getApplyNowDropDown = function(path){
	if(!path) return;
	var ret = com.dc.ajax.requestHtml(path);
	var root = document.createElement("div");
	root.innerHTML = ret;
	var p = root.getElementsByTagName("p");	
	for(var i=0;i<p.length;i++){
		if(p[i].id!="applyNowDrop") continue;
		
		var applyNowDrop = document.getElementById("applyNowDrop");
		if(applyNowDrop) applyNowDrop.innerHTML = p[i].innerHTML;
		break;
	}
	this.initOnChange();
}
CardList.prototype.initOnChange = function(){
	var applyNowDropDownList = document.getElementById("applyNowDropDownList");	
	if(!applyNowDropDownList) return;
	
	if(applyNowDropDownList.addEventListener){
		applyNowDropDownList.addEventListener("change", function(){
			var value = document.getElementById("applyNowDropDownList").value;
			if(!value || value == "") return;
			location.href = value;			
		}, false);
	}else if(applyNowDropDownList.attachEvent){
		applyNowDropDownList.attachEvent("onchange",function(){
			var value = document.getElementById("applyNowDropDownList").value;
			if(!value || value == "") return;
			location.href = value;			
		});
	}
}
CardList.prototype.changeHover = function(id){	
	var cardType = document.getElementById("cardType");
	if(!cardType) return;
	
	var a = cardType.getElementsByTagName("a");
	for(var i=0;i<a.length;i++){
		if(a[i].id.match(/_text$/gi)) continue;	
		var img = a[i].getElementsByTagName("img");
		img[0].src = img[2].src;
	}
	
	var currentCardType = document.getElementById(id);
	var img = currentCardType.getElementsByTagName("img");
	img[0].src = img[1].src;
}
CardList.prototype.showCardByType = function(type){	
	var cardLineUp = document.getElementById("cardLineUp");
	if(!cardLineUp) return;
	var cardLineUps = cardLineUp.getElementsByTagName("div");
	for(var i=0;i<cardLineUps.length;i++){
		cardLineUps[i].style.display = "none";
	}
	var cardLineUp_ = document.getElementById("cardLineUp_"+type);
	if(!cardLineUp_) return;
	cardLineUp_.style.display = "";
	
	var subTitle = document.getElementById("subTitle");
	var _text = document.getElementById(type+"_text");
	debug.debug("subTitle:" + subTitle + ", _text:" + _text)
	if(subTitle && subTitle) {
		subTitle.innerHTML = _text.innerHTML;
	}
	
	this.backWrapper();
}
CardList.prototype.showCardByTypeWrapper = function(type){
	//$("#cardLineUp").fadeOut("linear", function(){
		com.dc.cardlist.showCardByType(type);
	//	$("#cardLineUp").fadeIn("linear");
	//});
}
CardList.prototype.newCardLine = function(obj){
	var cardLine = document.createElement("dl");
	cardLine.className = "cardLineUp clearfix";

	var cardImg = document.createElement("dt"); 
	cardImg.className = "cardImg";
	if(obj.image){
		var img = document.createElement("img"); 
		img.src = obj.image;
		if(img.addEventListener) {
			eval("img.addEventListener('error', function(){this.style.display='none';}, false);");
		} else if(img.attachEvent) {
			eval("img.attachEvent('onerror', function(){this.style.display='none';});");
		}
		cardImg.appendChild(img);
	}		
	
	var cardTitle = document.createElement("dd"); 
	cardTitle.className = "cardTitle";
	if(obj.title){
		cardTitle.appendChild(document.createTextNode(obj.title));
	}
		

	var cardTypes = document.createElement("dd"); 
	if(obj.type){
		var img = document.createElement("img"); 
		img.src = "/en/images/credit-card/icon_"+obj.type+".gif";
		cardTypes.appendChild(img);
	}
		
	var btn_detail = document.createElement("dd"); 
	btn_detail.className = "btn_detail clearfix";			
	var a = document.createElement("a"); 
	a.href = "#";
	if(obj.link){
		a.href = obj.link;
	}
	//a.appendChild(document.createTextNode("Detail"));
	btn_detail.appendChild(a);
	
	cardLine.appendChild(cardImg);
	cardLine.appendChild(cardTitle);
	cardLine.appendChild(cardTypes);
	cardLine.appendChild(btn_detail);
	return cardLine;
}
CardList.prototype.registerApplyNow = function(){
	var applyNowButton = document.getElementById("applyNowButton");
	if(!applyNowButton) return;
	
	if(applyNowButton.addEventListener) {
		applyNowButton.addEventListener('click', function(){com.dc.cardlist.goSelectedCard();}, false);
	} else if(applyNowButton.attachEvent) {
		applyNowButton.attachEvent('onclick', function(){com.dc.cardlist.goSelectedCard();});
	}
}
CardList.prototype.goSelectedCard = function(){
 	var applyNowDropDownList = document.getElementById("applyNowDropDownList");
	if(applyNowDropDownList&&applyNowDropDownList.value&&applyNowDropDownList.value!=""){
		location.href = applyNowDropDownList.value;
		/*this.openSelectedCardDetail(applyNowDropDownList.value);*/
	}
}
CardList.prototype.registerOpenSelectedCardDetail = function(){
	var cardLineUp = document.getElementById("cardLineUp");
	if(!cardLineUp) return;
	
	var cardLineUps = cardLineUp.getElementsByTagName("div");
	for(var i=0;i<cardLineUps.length;i++){
		var dl = cardLineUps[i].getElementsByTagName("dl");
		for(var j=0;j<dl.length;j++){
			var dd = dl[j].getElementsByTagName("dd");
			for(var k=0;k<dd.length;k++){
				if(dd[k].className!="btn_detail clearfix") continue;

				var a = dd[k].getElementsByTagName("a");
				if(!a || a.length==0) continue;				
				a = a[0];				
				if(a.addEventListener) {
					eval("a.addEventListener('click', function(){ com.dc.cardlist.openSelectedCardDetailWrapper('"+a.href+"');}, false);");
				} else if(a.attachEvent) {
					eval("a.addEventListener('click', function(){ com.dc.cardlist.openSelectedCardDetailWrapper('"+a.href+"');}, false);");
				}
				a.href = "javascript:;";
			}
		}
	}
}
CardList.prototype.openSelectedCardDetailWrapper = function(link){
	//$("#cardLineUp").fadeOut("linear", function(){
		cardlist.openSelectedCardDetail(link);
	//	$("#cardDetail").fadeIn("linear");
	//});
}
CardList.prototype.openSelectedCardDetail = function(link){
	if(!link || link=="undefined") return;
	var ret = com.dc.ajax.requestHtml(link);
	var root = document.createElement("div");
	root.innerHTML = ret;
	var div = root.getElementsByTagName("div");	
	for(var i=0;i<div.length;i++){
		if(div[i].id!="cardDetail") continue;
		
		var cardLineUp = document.getElementById("cardLineUp");
		var cardDetail = document.getElementById("cardDetail");
		
		if(cardLineUp) cardLineUp.style.display = "none";		
		if(cardDetail) cardDetail.innerHTML = div[i].innerHTML;
		break;
	}
}
CardList.prototype.backWrapper = function(){
	//$("#cardDetail").fadeOut("linear", function(){
		cardlist.back();
	//	$("#cardLineUp").fadeIn("linear");
	//});
}
CardList.prototype.back = function(){
	var cardLineUp = document.getElementById("cardLineUp");
	var cardDetail = document.getElementById("cardDetail");
	
	if(cardLineUp) cardLineUp.style.display = "";
	if(cardDetail) cardDetail.innerHTML = "";
}
CardList.prototype.showApplyNow = function(){
	var btn_applyNow = document.getElementById("btn_applyNow");
	if(btn_applyNow) btn_applyNow.style.display = "";
	
	var applyNowButton = document.getElementById("applyNowButton");
	if(applyNowButton) applyNowButton.style.display = "";
	
	var applyNowDrop = document.getElementById("applyNowDrop");
	if(applyNowDrop) applyNowDrop.style.display = "";
	
	var applyNowText = document.getElementById("applyNowText");
	if(applyNowText) applyNowText.style.display = "";
}

/**************************************************************************************************
 * MapAdapter.js
 * Description :  
 **************************************************************************************************/
com.dc.mapAdapter = new MapAdapter();
var mapAdapter = com.dc.mapAdapter;
function MapAdapter(){
	this.isIE6 = false;
	this.map;
/*	this.panorama; Commented on 07-Nov-2011 */
	this.markersArray = new Array();
	this.showFlag = false;
	this.showArray = new Array();
	
	this.atmIcon_image;
	this.branchIcon_image;
	this.atmInternetIcon_image;
	this.juscocityIcon_image;
	this.instantIcon_image;
	this.subicons = new Array();

	this.branch_locations = new Array();
	this.atm_locations = new Array();
	this.all_locations = new Array();
	
	this.currentType;

	this.area_center = new Array();
	this.district_center = new Array();
}
MapAdapter.prototype.initialize = function() {
	if ($.browser.msie && $.browser.version=="6.0"){
		this.isIE6 = true;
	}

	if (!this.isIE6){
		var myOptions = {
			zoom: 10,
			center: new google.maps.LatLng(22.399602,114.090271),
			panControl: false,
			zoomControl: true,
			mapTypeControl: false,
			scaleControl: true,
			streetViewControl: true,
			
			navigationControl: false,
			overviewMapControl: false,
			scrollwheel: false,
			
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		this.map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	/* Commented on 07-Nov-2011
		var panoramaOptions = {
			addressControl: true,
			addressControlOptions: {
				style: {backgroundColor: 'grey', color: 'yellow'}
			},
			position: new google.maps.LatLng(22.399602,114.090271),
			pov: {
				heading: 140,
				pitch: +10,
				zoom: 1
			}
		};
		var panorama = new google.maps.StreetViewPanorama(document.getElementById("map_canvas"), panoramaOptions);
		this.map.setStreetView(panorama);
	*/	
		google.maps.event.trigger(this.map, 'resize');
		this.map.setCenter(new google.maps.LatLng(22.353886,114.120483));
		this.atmIcon_image = new google.maps.MarkerImage('/en/images/useful-info/icon_atm.png', new google.maps.Size(58, 56));
		this.branchIcon_image = new google.maps.MarkerImage('/en/images/useful-info/atmAeonBranchLogo.png', new google.maps.Size(90, 45));
		this.atmInternetIcon_image = new google.maps.MarkerImage('/en/images/useful-info/icon_internet.png', new google.maps.Size(90, 45), new google.maps.Point(0,0));
		this.juscocityIcon_image = new google.maps.MarkerImage('/en/images/useful-info/icon_jusco.png', new google.maps.Size(90, 45), new google.maps.Point(0,0));
		this.instantIcon_image = new google.maps.MarkerImage('/en/images/useful-info/icon_instant.png', new google.maps.Size(90, 45),new google.maps.Point(0,0));
		this.moenyIcon_image = new google.maps.MarkerImage('/en/images/useful-info/icon_money.png', new google.maps.Size(90, 45), new google.maps.Point(0,0));
		this.subicons[0] = this.atmIcon_image;
		this.subicons[1] = this.atmInternetIcon_image;
		this.subicons[2] = this.juscocityIcon_image;
		this.subicons[3] = this.instantIcon_image;
		this.subicons[4] = this.moenyIcon_image;
		this.subicons[99] = this.branchIcon_image;
	}

	this.area_center = new Array();
	this.area_center.push({name:"hk", lat:22.248746, lng:114.189835, zoom:12});
	this.area_center.push({name:"kln", lat:22.322495, lng:114.179335, zoom:12});
	this.area_center.push({name:"nt", lat:22.422645, lng:114.123802, zoom:11});
	this.area_center.push({name:"ot", lat:22.263680, lng:113.972168, zoom:11});

	this.district_center = new Array();
	this.district_center.push({name:"hk:Central And Western District", lat:22.287190, lng:114.144087, zoom:14});
	this.district_center.push({name:"hk:Eastern District", lat:22.275753627993893, lng:114.22021865844727, zoom:13});
	this.district_center.push({name:"hk:Southern District", lat:22.24918338871465, lng:114.14460182189941, zoom:15}); 
	this.district_center.push({name:"hk:Wan Chai District", lat:22.28298113102382, lng:114.17751789093018, zoom:15});
	this.district_center.push({name:"kln:Kowloon City District", lat:22.322606619609772, lng:114.18176651000977, zoom:13});
	this.district_center.push({name:"kln:Kwun Tong District", lat:22.314321, lng:114.225833, zoom:13});
	this.district_center.push({name:"kln:Sham Shui Po District", lat:22.335547979846684, lng:114.14820671081543, zoom:14});
	this.district_center.push({name:"kln:Wong Tai Sin District", lat:22.341025862638695, lng:114.19824600219727, zoom:15}); 
	this.district_center.push({name:"kln:Yau Tsim Mong District", lat:22.312919662722308, lng:114.17223930358887, zoom:14});
	this.district_center.push({name:"nt:Kwai Tsing District", lat:22.35944267251086, lng:114.1185092926025, zoom:14});
	this.district_center.push({name:"nt:North District", lat:22.496222245990904, lng:114.13198471069336, zoom:14});
	this.district_center.push({name:"nt:Sai Kung District", lat:22.35626753412293, lng:114.26090240478516, zoom:12});
	this.district_center.push({name:"nt:Sha Tin District", lat:22.398808372943662, lng:114.20734405517578, zoom:13});
	this.district_center.push({name:"nt:Tai Po District", lat:22.451529831715536, lng:114.16867733001709, zoom:15});
	this.district_center.push({name:"nt:Tsuen Wan District", lat:22.373888638213955, lng:114.11507606506348, zoom:15});
	this.district_center.push({name:"nt:Tuen Mun District", lat:22.394840561182853, lng:113.97714614868164, zoom:13});
	this.district_center.push({name:"nt:Yuen Long District" , lat:22.45315598415649, lng:114.0157699584961, zoom:14});
	this.district_center.push({name:"ot:Islands District", lat:22.299261499741196, lng:113.94126892089844, zoom:13});
	
	this.all_locations = this.all_locations.concat(this.branch_locations, this.atm_locations);
	this.goDetail();
}
MapAdapter.prototype.showMarkers = function(locations, area, district) {
	debug.debug("showMarkers()...area:" + area + ", district:" + district);
	var that = this;
	if(!locations) return;
	if(this.isIE6) return;
		
	for (var i in locations) {
		var sites = locations[i];
		var branchLatLng = new google.maps.LatLng(sites[1], sites[2]);
		for (y in sites[6]) {
			if(area&&(area!=sites[3])) continue;
			if(district&&(district!=sites[4])) continue;
			
			var icons = sites[6][y];
			var marker = new google.maps.Marker({
				position: new google.maps.LatLng(sites[1], sites[2]),
				map: this.map,
				icon: this.subicons[icons],
				title: sites[0],
				area: sites[3],
				district: sites[4],
				detailId: sites[5]
			});			
			
			this.markersArray.push(marker);
			
			
			debug.debug("sites[5]:" + sites[5]);
			
			if(sites[5].match(/^branches_/i) || sites[5].match(/^icon_/i)){
				eval("google.maps.event.addListener(marker, 'click', function() {that.showDetail('"+sites[5]+"', null, null, 'branch');});");
			}else if((sites[5].match(/^branches_/i)==null) && (sites[5].match(/^icon_/i)==null)){
				eval("google.maps.event.addListener(marker, 'click', function() {that.showDetail('"+sites[5]+"', null, null, 'atm');});");
			}
		}
	}
}
MapAdapter.prototype.showBranchOverlay = function() {
	debug.debug("showBranchOverlay()...");
	var area = document.getElementById("area");
	var district = document.getElementById("district");
	if(!area) return;
	if(!district) return;
	
	this.clearOverlays();
	this.showMarkers(this.branch_locations, area.value, district.value);
}
MapAdapter.prototype.showATMOverlay = function() {
	debug.debug("showATMOverlay()...");
	var area = document.getElementById("area");
	var district = document.getElementById("district");
	if(!area) return;
	if(!district) return;
	
	this.clearOverlays();
	this.showMarkers(this.atm_locations, area.value, district.value);
}
MapAdapter.prototype.showDetail = function(id, lat, lng, typeValue){
	debug.debug("showDetail...start")
	try{
		debug.debug("id: "+id+", lat: "+lat+", lng: "+lng+", typeValue:"+typeValue);
		var type = document.getElementById("type");
		if(!type) return;
		
	
		/*if((type.value=="atm") && (id.match(/^branches_/i) || id.match(/^icon_/i))){
			this.showBranchOverlay();
		}else if((type.value=="branch") && (id.match(/^branches_/i)==null) && (id.match(/^icon_/i)==null)){
			this.showATMOverlay();
		}
		*/
		$('.branchesATM').hide();
		$('#atmBranchesDetails').show();
		$('.atmBranchesDetails').show();
		if(this.showFlag == false) {
			$('#' + id).fadeIn();
			this.showFlag = true;
			this.showArray.push(id);

			if(lat && lng ){
				if(!this.isIE6){
					this.map.panTo(new google.maps.LatLng(lat, lng));
					this.map.setZoom(19);
				}
			}
		} else {
			$('#' + this.showArray[0]).hide();
			this.showArray.length = 0;
			$('#' + id).fadeIn();
			this.showArray.push(id);
		}

		debug.debug("type.value:" + type.value);
		this.setAreaDistrictByMarker(id, this.all_locations, false, true);		
		if(typeValue!="" && type.value!=typeValue){
			type.value = typeValue;
			this.onTypeChange(true);
		}

		var href = location.href;
		href = href.replace(/#(.)+$/gim, '');
		debug.debug("href:" + href)
		location.href = href+"#detailTitle";
		
		if(this.isIE6){
			document.getElementById("detailBack").style.display = "block";
		}
	}catch(e){
		debug.error(e);
	}
	debug.debug("showDetail...end")
}
MapAdapter.prototype.setAreaDistrictByMarker = function(id, locations, setCenterAndZoom, isDetail) {
	debug.debug("setAreaDistrictByMarker()...id:" + id + ", locations:locations, setCenterAndZoom:"+setCenterAndZoom + "...start");
	var area = document.getElementById("area")
	var district = document.getElementById("district");	
	for (var i in locations) {
		var sites = locations[i];		
		if(id != sites[5]) continue;
		
		if(area.value!=sites[3]){
			area.value = sites[3];
			this.onAreaChange(setCenterAndZoom);
		}

		if(district.value!=sites[4]){
			district.value = sites[4];
			this.onDistrictChange(setCenterAndZoom);
		}
		break;
	}
	
	debug.debug("setAreaDistrictByMarker...end");
}
MapAdapter.prototype.clearOverlays = function() {
	if (this.markersArray) {
		for (i in this.markersArray) {
			this.markersArray[i].setMap(null);
	  	}
	  	this.markersArray.length = 0;
	}
}
MapAdapter.prototype.registerDetailBack = function() {
	var that = this;
	$('div#detailBack').click(function(){
		that.back();
		that.goBackToCenter()
	});
}
MapAdapter.prototype.back = function() {
	debug.debug("back...start")
	var that = this;

	$('#' + that.showArray[0]).hide();
	that.showArray.length = 0;
	that.showFlag = false;
	$('.branchesATM').fadeIn();
	$('#atmBranchesDetails').hide();
	$('.atmBranchesDetails').hide();

	var href = location.href;
	href = href.replace(/#(.)+$/gim, '');
	debug.debug("href:" + href)
	location.href = href+"#pageTitle";
	debug.debug("back...end")
}
MapAdapter.prototype.goBackToCenter = function() {
	var area = document.getElementById("area").value;
	var district = document.getElementById("district").value;
	
	if(area!="" && district!=""){
		this.setCenterAndZoom(this.district_center, document.getElementById("district").value);
	}else if(area!=""){
		this.setCenterAndZoom(this.area_center, document.getElementById("area").value);
	}
}
MapAdapter.prototype.onAreaChange = function(setCenterAndZoom){
	debug.debug("onAreaChange("+setCenterAndZoom+")...")
	if(typeof setCenterAndZoom=="undefined") setCenterAndZoom = true;
	var area = document.getElementById("area");
	if(!area) return;

	if(setCenterAndZoom) this.setCenterAndZoom(this.area_center, area.value);
	this.resetDistrict();	
	this.resetType();
	this.onTypeChange(true);
	if(setCenterAndZoom!=false)
		this.back();
}
MapAdapter.prototype.onDistrictChange = function(setCenterAndZoom){	
	debug.debug("onDistrictChange("+setCenterAndZoom+")...")
	if(typeof setCenterAndZoom=="undefined") setCenterAndZoom = true;
	var area = document.getElementById("area");
	var district = document.getElementById("district");	
	if(!area) return;
	if(!district) return;
	
	if(setCenterAndZoom) this.setCenterAndZoom(this.district_center, district.value);
	this.resetType();
	this.onTypeChange(true);
	if(setCenterAndZoom!=false)
		this.back();
}
MapAdapter.prototype.onTypeChange = function(goBackToList){
	debug.debug("onTypeChange("+goBackToList+")...start");
	var type = document.getElementById("type");
	if(!type) return;
	
	//debug.debug("type.value:"+type.value);
	if(type.value=="branch"){
		this.showBranchOverlay();
	}else if(type.value=="atm") {
		this.showATMOverlay();
	}else if(type.value=="") {
		this.clearOverlays();
	}
	this.updateTabView();
	if(goBackToList==undefined){
		this.goBackToCenter()
		this.back();
	}
	debug.debug("onTypeChange()...end");
}
/*
MapAdapter.prototype.resetArea = function(){	
	var area = document.getElementById("area");
	var areaAll = document.getElementById("areaAll");	
	if(!area||!areaAll) return;

	if(area&&area){	
		area.options.length = 0;
		area.options[area.options.length] = new Option(areaAll.options[0].text, areaAll.options[0].value);

		var locations;
		if(this.currentType=="branch") locations = this.branch_locations;
		else if(this.currentType=="atm") locations = this.atm_locations;	
		
		var existArea = new Array();
		for (var i=0;i<locations.length;i++) {
			var newArea = locations[i][3];
			var isFound = false;
			for (var j=0;j<existArea.length;j++) {
				if(newArea==existArea[j]){
					isFound = true;
					break;
				}
			}  
			if(!isFound){
				existArea.push(newArea);
			}
		} 
		
		for (var i=0;i<existArea.length;i++) {
			for(var j=1;j<areaAll.options.length;j++){
				if(existArea[i]==areaAll.options[j].value){				
					area.options[area.options.length] = new Option(areaAll.options[j].text, areaAll.options[j].value);
					break;
				}
			}
		}

		area.value = "";
	}
	
	this.resetDistrict();
}
*/
MapAdapter.prototype.resetDistrict = function(){
	var area = document.getElementById("area");	
	var regx = new RegExp("^"+area.value);
	
	var district = document.getElementById("district");	
	var districtAll = document.getElementById("districtAll");	

	if(!district || !districtAll) return;
	
	district.options.length = 0;
	district.options[district.options.length] = new Option(districtAll.options[0].text, districtAll.options[0].value);

	if(!area.value==""){
		var locations = new Array();
		locations = locations.concat(this.all_locations);
		for(var i=1;i<districtAll.options.length;i++){
			if(districtAll.options[i].value.match(regx)==null) continue;
			var isFound = false;
			if(!isFound) isFound = this.isFoundInType(districtAll.options[i].value, this.atm_locations);
			if(!isFound) isFound = this.isFoundInType(districtAll.options[i].value, this.branch_locations);
			if(isFound){
				district.options[district.options.length] = new Option(districtAll.options[i].text, districtAll.options[i].value);
			}
		}
	}
	district.value = "";
	if(district.options.length<=1){
		district.disabled = "disabled";
	}else{
		district.disabled = "";
	}
}
MapAdapter.prototype.resetType = function(){
	debug.debug("resetType()...");
	var area = document.getElementById("area");
	var district = document.getElementById("district");
	var type = document.getElementById("type");
	var typeAll = document.getElementById("typeAll");	
	if(!area) return;
	if(!district) return;
	if(!type || !typeAll) return;
	
	if(area.value=="" || district.value==""){
		type.disabled = "disabled";
		type.value = "";
		return;
	}
	
	type.options.length = 0;
	type.options[type.options.length] = new Option(typeAll.options[0].text, typeAll.options[0].value);	
	var isFound = false;
	for(var i=1;i<typeAll.options.length;i++){
		//debug.debug("district.value:" + district.value + ", typeAll.options[i].value:" + typeAll.options[i].value);
		if(this.isFoundInType(district.value, eval("this."+typeAll.options[i].value+"_locations"))){
			isFound = true;
			type.options[type.options.length] = new Option(typeAll.options[i].text, typeAll.options[i].value);
		}
	}
	if(isFound) type.disabled = "";
}
MapAdapter.prototype.isFoundInType = function(value, locations){
	var isFound = false;	
	for (var j=0;j<locations.length;j++) {
		//debug.debug("value:" + value + ", locations["+j+"][4]:" +locations[j][4] );
		if(value!=locations[j][4]) continue;
		isFound = true;
		break;
	}
	return isFound;
}
MapAdapter.prototype.setCenterAndZoom = function(array, value){
	if(!array || !value) return;
	if(this.isIE6) return;
	for(var i=0;i<array.length;i++){
		if(array[i].name!=value) continue;
		debug.debug("setCenterAndZoom()...array["+i+"].name:" + array[i].name + ", value:" + value + ", lat:" + array[i].lat + ", lng:" + array[i].lng);
		this.map.setCenter(new google.maps.LatLng(array[i].lat, array[i].lng));
		this.map.setZoom(array[i].zoom);
	}
}
MapAdapter.prototype.updateTabView = function(){
	debug.debug("updateTabView()...start");
	var area = document.getElementById("area");
	var district = document.getElementById("district");
	var type = document.getElementById("type");
	
	if(!area) return;
	if(!district) return;
	if(!type) return;

	if(area.value=="hk"){
		$("#hk-a").trigger("click");
		$("#circlek-hk-a").trigger("click");
		$("#shoppingCentre-hk-a").trigger("click");
		$("#atmbranch-hk-a").trigger("click");
	}else if(area.value=="kln"){
		$("#kowloon-a").trigger("click");
		$("#circlek-kowloon-a").trigger("click");
		$("#shoppingCentre-kowloon-a").trigger("click");
		$("#atmbranch-kowloon-a").trigger("click");
	}else if(area.value=="nt"){
		$("#nt-a").trigger("click");
		$("#circlek-nt-a").trigger("click");
		$("#shoppingCentre-nt-a").trigger("click");
		$("#atmbranch-nt-a").trigger("click");
	}else if(area.value=="ot"){
		$("#outlying-a").trigger("click");
		$("#circlek-outlying-a").trigger("click");
		$("#shoppingCentre-outlying-a").trigger("click");
		$("#atmbranch-outlying-a").trigger("click");
	}
	
	debug.debug("type.value:"+type.value);
	if(type.value=="branch"){
		debug.debug("branch...");
		$("#branchA").trigger("click");
	}else if(type.value=="atm") {
		debug.debug("atm...");
		$("#event").trigger("click");
	}
	debug.debug("area.value:"+area.value);
	debug.debug("updateTabView()...end");
}
MapAdapter.prototype.goDetail = function(){
	debug.debug("trickyShowDetail()...");
	var hash = window.location.hash;
	debug.debug("hash:" + hash);
	
	hash = hash.replace("#", "");	
	
	var id = com.dc.utils.getParam("id")
	debug.debug("id :" + id );
	if(id!="") hash = id;
	
	if(hash=="") return;
	var type = "";
	var location = null;
	
	if(location==null){
		location = this.getLocationByCode(this.branch_locations, hash);
		if(location!=null) type = "branch";
	}
	if(location==null){
		location = this.getLocationByCode(this.atm_locations, hash);
		if(location!=null) type = "atm";
	}
	if(location!=null) this.showDetail(location[5], location[1], location[2], type);
	else this.onAreaChange();
}
MapAdapter.prototype.getLocationByDivId = function(locations, id){
	for (var i in locations) {
		if(locations[i][5]==id) return locations[i];
	}
	return null;
}
MapAdapter.prototype.getLocationByCode = function(locations, code){
	for (var i in locations) {
		if(locations[i][7]==code) return locations[i];
	}
	return null;
}


/*
function MapAdapter(){
	this.gmarkers;
	this.htmls;
	this.i;

	this.atmIcon;
	this.atmInternetIcon;
	this.juscocityIcon;
	this.instantIcon;
	this.aeonLogo;;
	this.icons;

	this.map;
	this.xmlDoc;
	this.currentType;
	this.currentDetail;
}
MapAdapter.prototype.init = function(xmlStr) {
	this.initXml(xmlStr);
	if (!GBrowserIsCompatible()){
		alert("Sorry, the Google Maps API is not compatible with this browser");
	}else{
		this.initMapObj();
	}
	this.initEvent();
	this.onAreaChange();
}
MapAdapter.prototype.initXml = function(xmlStr) {
	this.xmlDoc = GXml.parse(xmlStr);	
}
MapAdapter.prototype.initMapObj = function() {
	this.gmarkers = [];
	this.htmls = [];
	this.i = 0;

	this.atmIcon = new GIcon();
	this.atmIcon.image = "/en/images/useful-info/icon_atm.png";
	this.atmIcon.iconSize = new GSize(58, 56);
	this.atmIcon.iconAnchor = new GPoint(9, 55);
	this.atmIcon.infoWindowAnchor = new GPoint(30, 30); 	
	
	this.aeonLogo = new GIcon();
	this.aeonLogo.image = "/en/images/useful-info/atmAeonBranchLogo.gif";
    this.aeonLogo.iconSize = new GSize(38, 38);
    this.aeonLogo.iconAnchor = new GPoint(0, 0);
    this.aeonLogo.infoWindowAnchor = new GPoint(0, 0);  	  

	this.atmInternetIcon = new GIcon();
	this.atmInternetIcon.image = "/en/images/useful-info/icon_atm1.png";
    this.atmInternetIcon.iconSize = new GSize(64, 59);
    this.atmInternetIcon.iconAnchor = new GPoint(15, 0);
    this.atmInternetIcon.infoWindowAnchor = new GPoint(30, 30);
	
	this.juscocityIcon = new GIcon();
	this.juscocityIcon.image = "/en/images/useful-info/icon_atm2.png";
    this.juscocityIcon.iconSize = new GSize(64, 59);
    this.juscocityIcon.iconAnchor = new GPoint(13, 0);
    this.juscocityIcon.infoWindowAnchor = new GPoint(30, 30);	  
	  
	this.instantIcon = new GIcon();
	this.instantIcon.image = "/en/images/useful-info/icon_atm3.png";
    this.instantIcon.iconSize = new GSize(64, 59);
    this.instantIcon.iconAnchor = new GPoint(12, 0);
    this.instantIcon.infoWindowAnchor = new GPoint(30, 30);  	

	this.icons = [];
	this.icons[0] = this.atmIcon;
	this.icons[1] = this.atmInternetIcon;
	this.icons[2] = this.juscocityIcon;
	this.icons[3] = this.instantIcon;
	this.icons[99] = this.aeonLogo;

	this.map = new GMap2(document.getElementById("map"));
	this.map.addControl(new GLargeMapControl());
	//this.map.addControl(new GMapTypeControl());
	this.map.setCenter(new GLatLng(22.298309,114.165459), 11);
}
MapAdapter.prototype.initEvent = function() {
	var area = document.getElementById("area");
	var district = document.getElementById("district");	
	var branches = document.getElementById("branches");
	var atm = document.getElementById("atm");
	var detailBack = document.getElementById("detailBack");
	
	if(area){
		if(area.addEventListener){
			area.addEventListener("change", function(){mapAdapter.onAreaChange()}, false);
		}else if(area.attachEvent){
			area.attachEvent("onchange",function(){mapAdapter.onAreaChange()});
		}
	}
	if(district){
		if(district.addEventListener){
			district.addEventListener("change", function(){mapAdapter.onDistrictChange()}, false);
		}else if(district.attachEvent){
			district.attachEvent("onchange",function(){mapAdapter.onDistrictChange()});
		}
	}
	if(branches){
		if(branches.addEventListener){
			branches.addEventListener("click", function(){mapAdapter.loadBranches()}, false);
		}else if(branches.attachEvent){
			branches.attachEvent("onclick",function(){mapAdapter.loadBranches()});
		}
	}
	if(atm){
		if(atm.addEventListener){
			atm.addEventListener("click", function(){mapAdapter.loadAtm()}, false);
		}else if(atm.attachEvent){
			atm.attachEvent("onclick",function(){mapAdapter.loadAtm()});
		}
	}
	if(detailBack){
		if(detailBack.addEventListener){
			detailBack.addEventListener("click", function(){mapAdapter.detailBackWrapper()}, false);
		}else if(detailBack.attachEvent){
			detailBack.attachEvent("onclick",function(){mapAdapter.detailBackWrapper()});
		}
	}
}
MapAdapter.prototype.createMarker = function(point, html, icontype, detailId) {
	var marker = new GMarker(point,this.icons[icontype]);
	if(detailId&&detailId!=""){
		GEvent.addListener(marker, "click", function() {
			mapAdapter.showDetailWrapper(detailId);
		});
	}
	this.gmarkers[this.i] = marker;
	this.htmls[this.i] = html;
	this.i++;
	return marker;
}
MapAdapter.prototype.loadBranches = function(){	
	this.currentType = "branches";
	this.reloadMarker();
	this.resetArea();
	this.resetDistrict();
	this.highlightType();
}
MapAdapter.prototype.loadAtm = function(){
	this.currentType = "atm";
	this.reloadMarker();
	this.resetArea();
	this.resetDistrict();
	this.highlightType();
}
MapAdapter.prototype.reloadMarker = function(chosenArea, chosenDistrict){
	if(!this.map||this.map==null||this.map=="undefined") return;
	
	this.map.clearOverlays();	
	
	var typeNode = this.xmlDoc.documentElement.getElementsByTagName(this.currentType);
	if(!typeNode || typeNode.length==0) return;
	
	var markers = typeNode[0].getElementsByTagName("marker");	
	if(!markers || markers.length==0) return;
	
	for (var i = 0; i < markers.length; i++) {
		//obtain the attribues of each marker
		var area = markers[i].getAttribute("area");
		var district = markers[i].getAttribute("district");
		
		if(chosenArea&&(chosenArea!=area)) continue;
		if(chosenDistrict&&(chosenDistrict!=district)) continue;
		
		var lat = parseFloat(markers[i].getAttribute("lat"));
		var lng = parseFloat(markers[i].getAttribute("lng"));
		var point = new GLatLng(lat,lng);
		var html = decodeURIComponent(markers[i].getAttribute("html"));
		var icontype = markers[i].getAttribute("icontype").toString().split(',');
		var detailId = markers[i].getAttribute("detailId");
		//create the marker
		for( var j=0; j<icontype.length; j++){
			var marker = this.createMarker(point, html, icontype[j], detailId);
			this.map.addOverlay(marker);
		}
	}  
}

MapAdapter.prototype.onAreaChange = function(){
	var area = document.getElementById("area");
	if(!area) return;
	
	this.reloadMarker(area.value);
	this.resetDistrict();
}
MapAdapter.prototype.onDistrictChange = function(){	
	var area = document.getElementById("area");
	if(!area) return;

	var district = document.getElementById("district");	
	if(!district) return;
	
	this.reloadMarker(area.value, district.value);
}
MapAdapter.prototype.resetArea = function(){	
	var area = document.getElementById("area");
	var areaAll = document.getElementById("areaAll");	
	if(!area||!areaAll) return;

	if(area&&area){	
		area.options.length = 0;
		area.options[area.options.length] = new Option(areaAll.options[0].text, areaAll.options[0].value);

		var typeNode = this.xmlDoc.documentElement.getElementsByTagName(this.currentType);
		if(!typeNode || typeNode.length==0) return;
		
		var markers = typeNode[0].getElementsByTagName("marker");	
		if(!markers || markers.length==0) return;
		
		var existArea = new Array();
		for (var i=0;i<markers.length;i++) {
			if(this.currentType==markers[i].getAttribute("type")){
				var newArea = markers[i].getAttribute("area");
				if(!newArea) continue;
				
				var isFound = false;
				for (var j=0;j<existArea.length;j++) {
					if(newArea==existArea[j]){
						isFound = true;
						break;
					}
				}  
				if(!isFound){
					existArea.push(newArea);
				}
			}
		} 
		
		for (var i=0;i<existArea.length;i++) {
			for(var j=1;j<areaAll.options.length;j++){
				if(existArea[i]==areaAll.options[j].value){				
					area.options[area.options.length] = new Option(areaAll.options[j].text, areaAll.options[j].value);
					break;
				}
			}
		}

		area.value = "";
	}
	
	this.resetDistrict();
}
MapAdapter.prototype.resetDistrict = function(){
	var area = document.getElementById("area");	
	var regx = new RegExp("^"+area.value);
	
	var district = document.getElementById("district");	
	var districtAll = document.getElementById("districtAll");	
	if(!district || !districtAll) return;
	
	district.options.length = 0;
	district.options[district.options.length] = new Option(districtAll.options[0].text, districtAll.options[0].value);

	if(!area.value==""){
		for(var i=1;i<districtAll.options.length;i++){
			if(districtAll.options[i].value.match(regx)==null) continue;
				
			var typeNode = this.xmlDoc.documentElement.getElementsByTagName(this.currentType);
			if(!typeNode || typeNode.length==0) continue;
			
			var markers = typeNode[0].getElementsByTagName("marker");	
			if(!markers || markers.length==0) continue;
			
			var isFound = false;
			for (var j=0;j<markers.length;j++) {
				if(districtAll.options[i].value==markers[j].getAttribute("district")){
					isFound = true;
					break;
				}
			}  
			if(isFound){
				district.options[district.options.length] = new Option(districtAll.options[i].text, districtAll.options[i].value);
			}
		}
	}
	district.value = "";
	if(district.options.length<=1){
		district.disabled = "disabled";
	}else{
		district.disabled = "";
	}
}

MapAdapter.prototype.highlightType = function(){
	var branches = document.getElementById("branches");
	var atm = document.getElementById("atm");
	
	if(this.currentType=="branches"){
		branches.className = "active";
		atm.className = "";
	}else if(this.currentType=="atm"){
		branches.className = "";
		atm.className = "active";
	}
}
MapAdapter.prototype.showDetailWrapper = function(id){
	$(".branchesATM").fadeOut("linear", function(){
		mapAdapter.showDetail(id);
		$(".atmBranchesDetails").fadeIn("linear");
	});
}
MapAdapter.prototype.showDetail = function(id){
	if(this.currentDetail){
		this.currentDetail.style.display = "none";
		this.currentDetail = undefined;
	}
	var detail = document.getElementById(id);
	if(!detail) return;
	
	detail.style.display = "";
	this.currentDetail = detail;
	
	var branchesATM = document.getElementById("branchesATM");
	var atmBranchesDetails = document.getElementById("atmBranchesDetails");
	
	if(branchesATM) branchesATM.style.display = "none";
	if(atmBranchesDetails) atmBranchesDetails.style.display = "";
	
}
MapAdapter.prototype.detailBackWrapper = function(id){
	$(".atmBranchesDetails").fadeOut("linear", function(){
		mapAdapter.detailBack(id);
		$(".branchesATM").fadeIn("linear");
	});
}
MapAdapter.prototype.detailBack = function(id){
	if(this.currentDetail){
		this.currentDetail.style.display = "none";
		this.currentDetail = undefined;
	}

	var branchesATM = document.getElementById("branchesATM");
	var atmBranchesDetails = document.getElementById("atmBranchesDetails");
	
	if(branchesATM) branchesATM.style.display = "";
	if(atmBranchesDetails) atmBranchesDetails.style.display = "none";
	
}
MapAdapter.prototype.start = function(){	
	this.loadBranches();
}
*/

/**************************************************************************************************
 * Landing.js
 * Description :  
 **************************************************************************************************/
com.dc.landing = new Landing();
var landing = com.dc.landing;
function Landing(){
	this.promoProductsXml = null;
	this.promoProductsXmlCache = null;
	this.promoProductsTimerId = null;
	this.lang = "en";
	this.onlineShoppingServiceContainer = null;
}
Landing.prototype.init = function(){}
Landing.prototype.getOnlineShoppingService = function(lang, id, path){
	var that = this;
	this.lang = lang;
	try{
		this.onlineShoppingServiceContainer = document.getElementById(id);	
		if(!this.onlineShoppingServiceContainer) return;
		
		var xmlDoc = com.dc.ajax.request(path);
		if(!xmlDoc||xmlDoc==null) return;
		this.promoProductsXml = xmlDoc;
		
		clearInterval(this.promoProductsTimerId);		
		this.promoProductsTimerId = setInterval("landing.showPromoProductsByInterval()", 500);
	}catch(e){
		//alert("getOnlineShoppingService()..."+e)
	}
}

Landing.prototype.showPromoProductsByInterval = function(){
	try{
		if(this.promoProductsXmlCache==null){		
			this.promoProductsXmlCache = new Array();			
			var Product = this.promoProductsXml.getElementsByTagName("Product");
			if(!Product||Product.length<=0) return;
			for(var i=0;i<Product.length;i++){
				this.promoProductsXmlCache.push(Product[i]);
			}
		}
		if(typeof this.promoProductsXmlCache == "object"){
			if(this.promoProductsXmlCache.length>0){
				if(this.promoProductsXmlCache.length>0) this.showPromoProducts(this.promoProductsXmlCache.shift(), this.lang);
				if(this.promoProductsXmlCache.length>0) this.showPromoProducts(this.promoProductsXmlCache.shift(), this.lang);
				if(this.promoProductsXmlCache.length>0) this.showPromoProducts(this.promoProductsXmlCache.shift(), this.lang);
				if(this.promoProductsXmlCache.length>0) this.showPromoProducts(this.promoProductsXmlCache.shift(), this.lang);
				if(this.promoProductsXmlCache.length>0) this.showPromoProducts(this.promoProductsXmlCache.shift(), this.lang);
				//if(this.promoProductsXmlCache.length>0) this.showPromoProductsByInterval(this);
				if(typeof initSlider=="function") initSlider();
			}else{
				if(typeof initSlider=="function") initSlider();
				this.promoProductsXmlCache == null;			
				clearInterval(this.promoProductsTimerId);	
			}
		}
	}catch(e){
		//alert("showPromoProductsByInterval()..."+e)
	}
}
		
Landing.prototype.showPromoProducts = function(Product, lang){
	try{
		var ProductName = "";
		var ImageURL = "";
		var ProductURL = "";
		
		var ProductNameElement = Product.getElementsByTagName("ProductName");
		var NameElement = ProductNameElement[0].getElementsByTagName("Name");	
		for(var j=0;j<NameElement.length;j++){
			if(NameElement[j].length<=0) continue;			
			if(NameElement[j].getAttribute("lang")==lang){
				ProductName = NameElement[j].firstChild.nodeValue;
				break;
			}
		}
		
		var ImageURLElement = Product.getElementsByTagName("ImageURL")
		ImageURL = ImageURLElement[0].getElementsByTagName("URL")[0].firstChild.nodeValue;

		var ProductURLElement = Product.getElementsByTagName("ProductURL");
		var URLElement = ProductURLElement[0].getElementsByTagName("URL");
		for(var j=0;j<URLElement.length;j++){
			if(URLElement[j].length<=0) continue;				
			if(URLElement[j].getAttribute("lang")==lang){
				ProductURL = URLElement[j].firstChild.nodeValue;
				break;
			}
		}
		
		var img = document.createElement("img");
		img.src = ImageURL;
		img.setAttribute("alt", ProductName);
		
		var a = document.createElement("a");
		a.href = ProductURL;
		a.target = "_blank";		
		a.appendChild(img);
		
		var div = document.createElement("div");
		div.className = "content-item";
		div.appendChild(a);
		
		this.onlineShoppingServiceContainer.appendChild(div);
	}catch(e){
		//alert("showPromoProducts()..."+e)
	}
}
Landing.prototype.initScrollBarX = function(){
	try{
		if(typeof scrollBarX != "undefined") scrollBarX.init();
	}catch(e){
		//alert("initScrollBarX()..."+e)
	}
}
Landing.prototype.calculateScrollBarX = function(){
	try{
		if(typeof scrollBarX != "undefined") scrollBarX.calculateBar();
	}catch(e){
		//alert("initScrollBarX()..."+e)
	}
}

/**************************************************************************************************
 * Year-round Discount Merchants
 * Description :  
 * Author : Sunil Gurung
 * Version : v1.0.0
 * Creation Date : 14-Jan-2010
 * Usage: Year-round Discount Merchants page loads all the pagination pages, uses AJAX to load page
 * Amendment History: 
 **************************************************************************************************/
 
com.dc.merchants = new MerchantStores();
var merchants = com.dc.merchants;
			
function MerchantStores(){

	this.merchantTypes = new Array();
	this.merchantTypePages = new Array();			
	this.finalStaticHKRestaurant = 0; 
	this.finalStaticHKFashion = 1; 
	this.finalStaticHKHealth = 2; 
	this.finalStaticHKAv = 3; 
	this.finalStaticHKLeisure = 4; 
	this.finalStaticHKTravel = 5; 
	this.finalStaticCNRestaurant = 6; 
	this.finalStaticCNFashion = 7; 
	this.finalStaticCNHealth = 8; 
	this.finalStaticCNAv = 9; 
	this.finalStaticCNLeisure = 10;
	this.finalStaticCNTravel = 11; 
	
	
	this.itemCount = 20;
	this.pageCache = new Array();
}

MerchantStores.prototype.initLoadMerchantCategory = function(data){
	//debug.debug(data);
	this.merchantTypes = data;
	for(var i =0; i < data.length; i++){
		this.merchantTypePages[i] = new Array();
	}
}
MerchantStores.prototype.initLoadPages = function(type,data){
	//debug.debug('inside loadPages');
			
	this.merchantTypePages[type] = data;
	//debug.debug('data loaded for: '+ this.merchantTypes[type]);
	this.initPage(type);
				
	//if pages are more than 1, add event
	if (data.length > 2 ){
		this.addEventsOnClick(type);
	}
	//debug.debug('event added');
}
MerchantStores.prototype.initPage = function(type){		
	//debug.debug('trying to load first page for: '+ this.merchantTypes[type]);
	if (this.merchantTypePages[type].length > 0){
		this.loadInnerHtml(type, '1');
	}else{
		debug.debug('No merchants available');
		//default no merchant page
	}
}
MerchantStores.prototype.addEventsOnClick = function(type){
	var that = this;
	//debug.debug('inside event');
	var pages = that.merchantTypePages[type];

	for(var i=0; i<pages.length; i+=2){
		var tempId = "page_" + pages[i] + "_" + this.merchantTypes[type];
		//debug.debug('Page:' + pages[i] + ' id: ' + tempId);
		var a = document.getElementById(tempId);		
		var page = pages[i];
		if(a.addEventListener) {
			//debug.debug('addingevent page'+pages[i]);
			eval("a.addEventListener('click', function(){that.loadInnerHtml('"+type+"','"+page+"');},false);");
		}else if(a.attachEvent) {
			//debug.debug('addingevent page'+pages[i]);
			eval("a.attachEvent('onclick', function(){that.loadInnerHtml('"+type+"','"+page+"');},false);");
		}
		var a2 = document.getElementById(tempId+"_2");		
		if(a2.addEventListener) {
			//debug.debug('addingevent page'+pages[i]);
			eval("a2.addEventListener('click', function(){that.loadInnerHtml('"+type+"','"+page+"');},false);");
		}else if(a2.attachEvent) {
			//debug.debug('addingevent page'+pages[i]);
			eval("a2.attachEvent('onclick', function(){that.loadInnerHtml('"+type+"','"+page+"');},false);");
		}
	}
				
}	
MerchantStores.prototype.loadInnerHtml = function(type,pageNum){		
	//debug.debug('1.category: ' + this.merchantTypes[type] + 'pagenum: '+ pageNum);
	var pages = this.merchantTypePages[type];
	var index = (2 * pageNum) - 2;
	var pageNum = pages[index];
	var pageUrl = pages[index+1];
	var pageDiv = "page " + this.merchantTypes[type];
				
	//debug.debug("Page Url: "+ pageUrl +"\n"+"page div: "+ pageDiv);

	var ret = com.dc.ajax.requestHtml(pageUrl);		
	var divPage = document.getElementById(pageDiv);
	divPage.innerHTML = ret;

	//debug.debug('exit loadinnerHTML');
}
MerchantStores.prototype.loadPage = function(id, path){
	var div = document.getElementById(id);	
	com.dc.ajax.makeLoader(id);
	div.innerHTML = com.dc.ajax.requestHtml(path);
}

MerchantStores.prototype.setItemCount = function(itemCount){
	this.itemCount = itemCount;
}
MerchantStores.prototype.setPageCache = function(pageCache){
	//debug.debug("setPageCache()...start");
	this.pageCache = pageCache;
}
MerchantStores.prototype.setPageCountDiv = function(id, pageCount, divCache){
	//debug.debug("setPageCountCache("+id+", "+pageCount+", "+divCache+")...start");
	for(var i in this.pageCache){
		//debug.debug("id:"+id+", this.pageCache[i].id:"+this.pageCache[i].id);
		if(id!=this.pageCache[i].id) continue;
		this.pageCache[i].pageCount = pageCount;
		this.pageCache[i].divCache = divCache;
		break;
	}
}
MerchantStores.prototype.getPageCount = function(id){
	for(var i in this.pageCache){
		if(id!=this.pageCache[i].id) continue;
		return this.pageCache[i].pageCount;
	}
	return 0;
}
MerchantStores.prototype.loadSubCategory = function(id, pagingId, path){
	debug.debug("loadSubCategory("+id+", "+pagingId+", "+path+")...start");
	var that = this;
	var div = document.getElementById(id);	
	if(div.innerHTML!=""){
		return;
	}
	com.dc.ajax.makeLoader(id);
	//div.innerHTML = com.dc.ajax.requestHtml(path);
	$('#'+id).html("<div align='center'><img src='/common/images/ajax-loader.gif'/></div>");
	
	$.ajax({
		url: path,
		success: function(data) {
			$('#'+id).html(data);
			eval("merchants.loadSubCategoryPaging('"+id+"', '"+pagingId+"');");
		}
	});
}
MerchantStores.prototype.loadSubCategoryPaging = function(id, pagingId){
	debug.debug("loadSubCategoryPaging("+id+", "+pagingId+")...start");
	var div = document.getElementById(id);	
	if(!div.hasChildNodes()) return;
	
	var divCount = 0;
	var divCache = new Array();
	for(var i=0;i<div.childNodes.length;i++){
		if(div.childNodes[i].nodeName.toLowerCase()!="div") continue;
		divCount++;
		divCache.push(div.childNodes[i]);
		//debug.debug("divCache.push(div.childNodes["+i+"]);");
	}
	var pageCount = Math.ceil(divCount / this.itemCount);	
	this.setPageCountDiv(id, pageCount, divCache);
	
	//debug.debug("id:" + id + ", pagingId:" + pagingId + ", divCount:" + divCount + ", pageCount:" + pageCount);
	var paging = document.getElementById(pagingId);
	paging.innerHTML = "";
	var paging2 = document.getElementById(pagingId+"_2");
	paging2.innerHTML = "";
	for(var i=0;i<pageCount;i++){
		if(i!=0){
			paging.innerHTML += " <span>|</span> ";
			paging2.innerHTML += " <span>|</span> ";
		}
		paging.innerHTML += "<a href='javascript:;' onclick=\"javascript:merchants.subCategoryGoPage('"+id+"', "+(i+1)+");\">"+(i+1)+"</a>";
		paging2.innerHTML += "<a href='javascript:;' onclick=\"javascript:merchants.subCategoryGoPage('"+id+"', "+(i+1)+");\">"+(i+1)+"</a>";
	}
	this.subCategoryGoPage2(id, 1);
}
MerchantStores.prototype.showPageNum  = function(pagingId, page){
	debug.debug("showPageNum("+pagingId+", "+page+")...start");
	var paging = document.getElementById(pagingId);
	if(paging==null) return;
	
	var pageCount = 0;
	for(var i=0;i<paging.childNodes.length;i++){
		if(paging.childNodes[i].nodeName.toLowerCase()!="a") continue;
		pageCount++;
		if(page==pageCount){
			paging.childNodes[i].style.textDecoration = "underline";
		}else{
			paging.childNodes[i].style.textDecoration = "";
		}
	}
}
MerchantStores.prototype.subCategoryGoPage  = function(id, page){
	debug.debug("subCategoryGoPage("+id+", "+page+")...start1");
	//$("#"+id).fadeOut("fast", function(){
		var a = merchants.subCategoryGoPage2(id, page);
	//	$("#"+id).fadeIn("fast");
	//});
}
MerchantStores.prototype.subCategoryGoPage2  = function(id, page){
	debug.debug("subCategoryGoPage2("+id+", "+page+")...start2");
	var div = document.getElementById(id);	
	if(!div || !div.hasChildNodes()) return;
	
	var from = page * this.itemCount - this.itemCount + 1;
	var to = from + this.itemCount - 1;
	
	var pageCount = 0;
	var currentPage = 0;
	var divCache;
	var isFirst;
	var pageCacheIndex = 0;
	
	for(var i in this.pageCache){
		//debug.debug("id:"+id+", this.pageCache[i].id:"+this.pageCache[i].id);
		if(id!=this.pageCache[i].id) continue;
		
		pageCount = this.pageCache[i].pageCount;
		divCache = this.pageCache[i].divCache;
		isFirst = this.pageCache[i].isFirst;
		this.pageCache[i].currentPage = currentPage;
		pageCacheIndex = i;
		break;
	}


	debug.debug("divCache.length:" + divCache.length);
	if(isFirst){
		for(var i=0;i<divCache.length;i++){
			//debug.debug("1.divCache["+i+"]:" + divCache[i]);
			divCache[i].style.display = "none";
		}
	}else{
		for(var i=(currentPage-1);i<divCache.length && ((i-currentPage-1)<20);i++){
			//debug.debug("2.divCache["+i+"]:" + divCache[i]);
			divCache[i].style.display = "none";
		}
	}
	
	for(var i=(page-1);i<divCache.length && ((i-page-1)<20);i++){
		//debug.debug("3.divCache["+i+"]:" + divCache[i]);
		divCache[i].style.display = "";
	}
	this.showPageNum(this.pageCache[pageCacheIndex].pagingId, page);
	this.showPageNum(this.pageCache[pageCacheIndex].pagingId+"_2", page);
	return true;
/*	
	
	var divCount = 0;
	var pageCount = 0;
	var isHiddenLastPage = false;
	for(var i=0;i<div.childNodes.length;i++){
		if(isHiddenLastPage) break;
		if(div.childNodes[i].nodeName!="DIV") continue;
		divCount++;
		
		if(div.childNodes[i].style.display!="") continue;
		for(var j=i;j<div.childNodes.length;j++){
			if(div.childNodes[j].nodeName!="DIV") continue;
			if(div.childNodes[j].style.display==""){
				div.childNodes[j].style.display = "none";
			}else{
				isHiddenLastPage = true;
				break;
			}
		}
	}
	
	divCount = 0;
	pageCount = 0;
	var fromCount = 0;
	var toCount = 0;
	for(var i=0;i<div.childNodes.length;i++){
		if(div.childNodes[i].nodeName!="DIV") continue;
		divCount++;
		pageCount = Math.ceil(divCount / this.itemCount);
		if(pageCount == page){
			div.childNodes[i].style.display = "";
		}
		//else{
		//	//debug.debug("div.childNodes["+i+"].style.display = 'none';");
		//	div.childNodes[i].style.display = "none";
		//}
	}
	*/
	
	/*
	
	debug.debug("id:" + id + ", from:" + from  + ", to:" + to);
	for(var i=0;i<from;i++){
		debug.debug("div.childNodes["+i+"].nodeName:" + div.childNodes[i].nodeName);
		//div.childNodes[i].style.display = "none";
	}
	for(var i=from;i<to;i++){
		debug.debug("div.childNodes["+i+"].nodeName:" + div.childNodes[i].nodeName);
		//div.childNodes[i].style.display = "";
	}
	for(var i=to;i<paging.childNodes.length;i++){
		debug.debug("div.childNodes["+i+"].nodeName:" + div.childNodes[i].nodeName);
		//div.childNodes[i].style.display = "none";
	}*/
}

