//
// class shopInfo
//
function ShopInfo() {
	this.XML = new AX();
	this.catNameList = [];
	this.catIndexList = [[],[],[],[],[]];
	this.atozIndexList = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
	this.onLoadDone = function() {};
}
ShopInfo.prototype.load = function(aURL) {
	this.url = aURL;
	var ts = this;
	this.XML.onLoadDone = function() {
		ts.initCatNameList();
		ts.initSortList();
		ts.onLoadDone();
	}
	this.XML.load(aURL);
}
ShopInfo.prototype.initCatNameList = function() {
	var tType = this.XML.getXML().getElementsByTagName("type");
	for (var i=0; i<tType.length; i++) {
		this.catNameList.push(tType[i].getAttribute("id"));
	}
}
ShopInfo.prototype.initSortList = function() {
	var tShop = this.XML.getXML().getElementsByTagName("shop");
	for (var i=0; i<tShop.length; i++) {
		// for catalogue
		var tCat = tShop[i].getAttribute("type");
		var tIndex = this.catNameList.indexOf(tCat);
		if (tIndex == -1) {
			this.catNameList.push(tCat);
			this.catIndexList.push(new Array());
			tIndex = this.catNameList.length-1;
		}
		this.catIndexList[tIndex].push(i);
		// for alphabatical order
		var tNameCode = tShop[i].getAttribute("name").toUpperCase().charCodeAt(0);
		if (tNameCode < 65) {
			tIndex = 0;
		} else if (tNameCode > 90) {
			tIndex = 27;
		} else {
			tIndex = tNameCode - 64;
		}
		this.atozIndexList[tIndex].push(i);
	}
}
ShopInfo.prototype.getShopInfo = function(aIndex) {
	return this.XML.getXML().getElementsByTagName("shop")[aIndex];
}
ShopInfo.prototype.getShopIndexList = function(aTypeId) {
	var tIndex = this.catNameList.indexOf(aTypeId);
	return this.catIndexList[tIndex];
}
ShopInfo.prototype.getTypeFullName = function(aTypeId, aLang) {
	var tTypeInfo = this.XML.getXML().getElementsByTagName("type");
	for (var i=0; i<tTypeInfo.length; i++) {
		if (tTypeInfo[i].getAttribute("id") == aTypeId) {
			if (aLang == "en") {
				return tTypeInfo[i].getAttribute("name");
			} else {
				return tTypeInfo[i].getAttribute("name_"+aLang);
			}
		}
	}
	return aTypeId;
}
ShopInfo.prototype.getShopName = function(aIndex, aLang) {
	var tShopInfo = this.XML.getXML().getElementsByTagName("shop")[aIndex];
	var tName = tShopInfo.getAttribute("name");
	if (aLang == "en") {
		return tName;
	} else {
		var tLangName = tShopInfo.getAttribute("name_"+aLang);
		if (tLangName != null) {
			return tLangName;
		} else {
			return tName;
		}
	}
}
ShopInfo.prototype.getShopLoc = function(aIndex) {
	var tLoc = this.XML.getXML().getElementsByTagName("shop")[aIndex].getAttribute("loc");
	if (tLoc == null) {
		return "";
	} else {
		return tLoc;
	}
}
