var shopsObj = new Object();
var catsObj = new Object();

function catObj(id, title, cats)
{
  this.id = (id)?id:null;	// cat id
	this.title = (title)?title:new Object();	// cat title - all langs
	this.cats = (cats)?cats:new Object();	// sub cat
	
	this.getTitle = function()
		{
			return unescape(this.title[getLang()]);
		}
	this.getID = function()
		{
			return this.id;
		}
	
	this.getInfoByName = function(index, nam)
		{
			for (var item in this)
				{
					if (this[item][index] == nam) return this[item][index];
				}
			return null;
		}
	
	this.getInfoByID = function(index, id)
		{
			for (var item in this)
				{
					if (item == id) return (this[item][index])?this[item][index]:null;
				}
			return null;
		}
	
}

function shopObj(id, catid, subcatid, name, tel, u, loc, hours, desc, other, logo, image, zone,hidden,hodPath)
{
//if(getLang()=='gb' && id==198) alert(id+'|'+hodPath);

	this.id = (id)?id:null;	// section group id - the folder struct which relative to the root htm
	this.catid = (catid)?catid:"";	// cat id
	this.subcatid = (subcatid)?subcatid:"";	//sub cat id
	this.name = (name)?name:new Object();	// shop name - all langs
	this.tel = (tel)?tel:new Array();	// shop tels
	this.url = (u)?u:"";	//	shot url
	this.loc = (loc)?loc:"";	//	shot location id
	this.hours = (hours)?hours:"";	//	shot operation hours
	this.desc = (desc)?desc:new Object();	// shop desc - all langs
	this.other = (other)?other:"";	// shop other info
	this.logo = (logo)?logo:"";	// shop other info
	this.image = (image)?image:"";	// shop other info
	this.zone = (zone)?zone:"";	// shop other info
	this.hidden = (hidden)?hidden:"";	
	this.hidden = (hidden)?hidden:"";
	this.hodPath = (hodPath)?hodPath:this.id;
//if(getLang()=='gb' && id==198) alert(this.id+'|'+this.hodPath);
	this.getShopsByName = function()
		{
			var list = new Object;
			var shops = shopsObj["shops"];
			for (var shop in shops)
				{
					var s = shops[shop];
					if (s.name[getLang()] == this.name[getLang()])
						{
							list[shop] = s;
						}
				}
			return list;
		}
	this.getHodPath = function()
		{
			return this.hodPath;
		}
	this.getCat = function()
		{
			var lv0 = shopsObj["cats"];
			
			for (var item0 in lv0)
				{
					var lv1 = lv0[item0];
					var catid = lv1.getID();
					if (catid==this.catid)
						{
							return lv1.getTitle();
						}
				}
		}
		
	this.getSubCat = function()
		{
			var lv0 = shopsObj["cats"];
			var catTitle = new Object();
			
			var scid = this.catid.split(",");
			var sscid = this.subcatid.split(",");
			
			
			for (var item0 in lv0)
				{
					var lv1 = lv0[item0];
					var catid = lv1.getID();
					
					for (var i=0; i<scid.length; i++)
						{
							if (scid[i] == catid)
								{
									for (var item1 in lv1.cats)
										{
											var lv2 = lv1.cats[item1];
											var subcatid = lv2.getID();
											
											for (var k=0; k<sscid.length; k++)
												{
													if ((scid[k] == catid)
													&& (sscid[k] == subcatid))
														{
															catTitle[lv2.getTitle()] = lv2.getTitle();
														}
												}
										}
								}
						}
				}
				
			var tempTitle = "";
			for (var item in catTitle)
				{
					tempTitle += (tempTitle=="")?item:"  /  "+item;
				}
			
			return tempTitle;
		}
	

	this.getZone = function()
		{
			return (this.zone=="")?'':this.zone;
		}
		
	this.getZoneList = function()
		{
			var list = this.getShopsByName();
			var str = "";
			for (var s in list)
				{
					if (str != list[s].getZone())
					{
					str += (str=="")?"":",";
					if (list[s].getLoc() != "")
						{
							str += list[s].getZone();
						}
					}
				}
		
			return str;
		}
		
	this.getLogo = function()
		{
			return (this.logo=="")?(this.loc + ".jpg"):this.logo;
		}
	this.getImage = function()
		{
			return (this.image=="")?(this.loc + ".jpg"):this.image;
		}
	this.getHiddenName = function()
		{
			if (this.hidden == '')
			{
				return '';
			}
			return unescape(this.hidden.toLowerCase());
		}
	this.getName = function()
		{
			return unescape(this.name[getLang()]);
		}
	this.getID = function()
		{
			return this.id;
		}
	this.getHours = function()
		{
			var hours = this.hours;
			
			while (hours.indexOf("^BR^")!=-1) 
				{
					hours = hours.replace("^BR^","<BR>");
				}

			return hours;
		}
	this.getDesc = function()
		{
			var desc = this.desc[getLang()];
			
			while (desc.indexOf("^BR^")!=-1) 
				{
					desc = desc.replace("^BR^","<BR>");
				}
				
			//desc = desc.replace("^newline^","<BR>");
			return unescape(desc);
		}
	this.getOther = function()
		{
			return this.other;
		}
	this.getTel = function()
		{
			var str = "";
			for (var t in this.tel)
				{
					str += (str=="")?"":"<BR>";
					str += this.tel[t];
				}
			return str;
		}
	this.getURL = function()
		{
			var url = this.url;
			if (this.url.indexOf("//")==-1)
				{
					url = "http://" + url;
				}
			return '<a href='+url+' class="black" target="_blank">'+this.url+'</a>';
		}
	this.getLoc = function()
		{
			var loc = this.loc;
			return (loc=="GF")?"G/F":loc;
			return loc;
		}
	this.getLocList = function()
		{
			var list = this.getShopsByName();
			var str = "";
			for (var s in list)
				{
					str += (str=="")?"":" & ";
					if (list[s].getLoc() != "")
						{
							str += list[s].getLoc();
						}
				}
		
			return str;
		}
	this.getCatID = function()
		{
			return this.catid;
		}
	this.getSubCatID = function()
		{
			return this.subcatid;
		}

	this.getInfoByName = function(index, nam)
		{
			for (var item in this)
				{
					if (this[item][index] == nam) return this[item][index];
				}
			return null;
		}
	
	this.getInfoByID = function(index, id)
		{
			for (var item in this)
				{
					if (item == id) return (this[item][index])?this[item][index]:null;
				}
			return null;
		}
	
}

