#define NONEISLAND_TEXTURE_NAME	"interfaces\empty_sea.tga"

int nCurScroll;
int idxIsland;
ref refIsland;
int townsQty, nCurScrolli; // added by MAXIMUS
int curTown = 1; // added by MAXIMUS
bool bBeParty; // added by MAXIMUS

void InitInterface(string iniName)
{
	ref PChar = GetMainCharacter();
	GameInterface.title = "titleTradeBook";

	FillScroll();
// KK -[improved by MAXIMUS]->
	string town = GetCurrentTownID();
	string island = "";
	if(town=="")
	{
		if(CheckAttribute(PChar,"location.from_sea") && PChar.location.from_sea!="")
		{
			island = Islands[FindIslandBySeaLocation(PChar.location.from_sea)].id
		}
	}
	else
	{
		island = GetIslandIDFromTown(town);
	}
	if(island!="")
	{/*
		for(int i=0; i<ISLANDS_QUANTITY; i++)
		{
			int curIsl = XI_GetIsland(i);

			if(FindIsland(island)==curIsl)
			{*/
				GameInterface.islandslist.current=FindIsland(island);
				townsQty = GetIslandTownsQuantity(island);
				while(townsQty>1)
				{
					if(GetTownIDFromIsland(island, townsQty)==town)
					{
						curTown = townsQty;
						break;
					}
					townsQty--;
				}/*
				break;
			}
		}*/
	}
// <-[improved by MAXIMUS]- KK
	if(bAnimation && bNewInterface) iniName = "RESOURCE\INI\NEW_INTERFACES\ANIMATION\TradeBook.ini";
	SendMessage(&GameInterface,"ls",MSG_INTERFACE_INIT,iniName);
// MAXIMUS interface MOD -->
	CreateExitString();//MAXIMUS: standard exit-string for exit-button

	CreateString(true,"IslandName","",FONT_NORMAL,COLOR_NORMAL,430,42,SCRIPT_ALIGN_CENTER,1.0);
	CreateString(true,"VisitDate","",FONT_NORMAL,COLOR_GREEN,275,76,SCRIPT_ALIGN_LEFT,1.0); // added by MAXIMUS
	CreateString(true,"TownName","",FONT_NORMAL,COLOR_NORMAL,430,111,SCRIPT_ALIGN_CENTER,0.8);

	CreateString(true,"Import0","",FONT_NORMAL,COLOR_NORMAL,72,163,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import1","",FONT_NORMAL,COLOR_NORMAL,72,207,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import2","",FONT_NORMAL,COLOR_NORMAL,72,251,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import3","",FONT_NORMAL,COLOR_NORMAL,72,295,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import4","",FONT_NORMAL,COLOR_NORMAL,72,339,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import5","",FONT_NORMAL,COLOR_NORMAL,72,383,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Import6","",FONT_NORMAL,COLOR_NORMAL,72,427,SCRIPT_ALIGN_LEFT,0.8);

	CreateString(true,"Export0","",FONT_NORMAL,COLOR_NORMAL,258,163,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export1","",FONT_NORMAL,COLOR_NORMAL,258,207,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export2","",FONT_NORMAL,COLOR_NORMAL,258,251,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export3","",FONT_NORMAL,COLOR_NORMAL,258,295,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export4","",FONT_NORMAL,COLOR_NORMAL,258,339,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export5","",FONT_NORMAL,COLOR_NORMAL,258,383,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Export6","",FONT_NORMAL,COLOR_NORMAL,258,427,SCRIPT_ALIGN_LEFT,0.8);

	CreateString(true,"Contraband0","",FONT_NORMAL,COLOR_NORMAL,468,163,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband1","",FONT_NORMAL,COLOR_NORMAL,468,207,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband2","",FONT_NORMAL,COLOR_NORMAL,468,251,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband3","",FONT_NORMAL,COLOR_NORMAL,468,295,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband4","",FONT_NORMAL,COLOR_NORMAL,468,339,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband5","",FONT_NORMAL,COLOR_NORMAL,468,383,SCRIPT_ALIGN_LEFT,0.8);
	CreateString(true,"Contraband6","",FONT_NORMAL,COLOR_NORMAL,468,427,SCRIPT_ALIGN_LEFT,0.8);


	CreateString(true,"Import00","",FONT_NORMAL,COLOR_MONEY,82,183,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import01","",FONT_NORMAL,COLOR_MONEY,82,227,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import02","",FONT_NORMAL,COLOR_MONEY,82,271,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import03","",FONT_NORMAL,COLOR_MONEY,82,315,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import04","",FONT_NORMAL,COLOR_MONEY,82,359,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import05","",FONT_NORMAL,COLOR_MONEY,82,403,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Import06","",FONT_NORMAL,COLOR_MONEY,82,447,SCRIPT_ALIGN_LEFT,0.7);

	CreateString(true,"Export00","",FONT_NORMAL,COLOR_MONEY,268,183,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export01","",FONT_NORMAL,COLOR_MONEY,268,227,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export02","",FONT_NORMAL,COLOR_MONEY,268,271,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export03","",FONT_NORMAL,COLOR_MONEY,268,315,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export04","",FONT_NORMAL,COLOR_MONEY,268,359,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export05","",FONT_NORMAL,COLOR_MONEY,268,403,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Export06","",FONT_NORMAL,COLOR_MONEY,268,447,SCRIPT_ALIGN_LEFT,0.7);

	CreateString(true,"Contraband00","",FONT_NORMAL,COLOR_MONEY,478,183,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband01","",FONT_NORMAL,COLOR_MONEY,478,227,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband02","",FONT_NORMAL,COLOR_MONEY,478,271,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband03","",FONT_NORMAL,COLOR_MONEY,478,315,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband04","",FONT_NORMAL,COLOR_MONEY,478,359,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband05","",FONT_NORMAL,COLOR_MONEY,478,403,SCRIPT_ALIGN_LEFT,0.7);
	CreateString(true,"Contraband06","",FONT_NORMAL,COLOR_MONEY,478,447,SCRIPT_ALIGN_LEFT,0.7);

	string groupIcons = "GOODS";
	if(bNewIcons==true) groupIcons = "GOODS_NEW";

	CreateImage("igood0",groupIcons,"",34,164,66,196);
	CreateImage("igood1",groupIcons,"",34,208,66,240);
	CreateImage("igood2",groupIcons,"",34,252,66,284);
	CreateImage("igood3",groupIcons,"",34,296,66,328);
	CreateImage("igood4",groupIcons,"",34,340,66,372);
	CreateImage("igood5",groupIcons,"",34,384,66,416);
	CreateImage("igood6",groupIcons,"",34,428,66,460);

	CreateImage("egood0",groupIcons,"",220,164,252,196);
	CreateImage("egood1",groupIcons,"",220,208,252,240);
	CreateImage("egood2",groupIcons,"",220,252,252,284);
	CreateImage("egood3",groupIcons,"",220,296,252,328);
	CreateImage("egood4",groupIcons,"",220,340,252,372);
	CreateImage("egood5",groupIcons,"",220,384,252,416);
	CreateImage("egood6",groupIcons,"",220,428,252,460);

	CreateImage("cgood0",groupIcons,"",430,164,462,196);
	CreateImage("cgood1",groupIcons,"",430,208,462,240);
	CreateImage("cgood2",groupIcons,"",430,252,462,284);
	CreateImage("cgood3",groupIcons,"",430,296,462,328);
	CreateImage("cgood4",groupIcons,"",430,340,462,372);
	CreateImage("cgood5",groupIcons,"",430,384,462,416);
	CreateImage("cgood6",groupIcons,"",430,428,462,460);

	SetTownFlagImage(town); // KK

	SetSelectable("I_SHIPHOLD",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_NATIONS",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_QUESTBOOK",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	//SetSelectable("I_SHIPLOG",!LAi_IsBoardingProcess() && !LAi_group_IsActivePlayerAlarm());
	SetSelectable("I_SHIPLOG",false);
	SetSelectable("EXIT_BUTTON",true);
	SetNodeUsing("VIDEOPIE",bAnimation && bNewInterface);

	SetEventHandler("ievnt_command","ProcessCommandExecute",0);
// MAXIMUS interface MOD <--

	SetEventHandler("InterfaceBreak","ProcessCancelExit",0);
	SetEventHandler("frame","FrameProcess",1);
	SetEventHandler("exitCancel","ProcessCancelExit",0);
}

void FrameProcess()
{
	if(nCurScroll!=sti(GameInterface.islandslist.current))
	{
		nCurScroll = sti(GameInterface.islandslist.current);
		SetVariable();
	}
}

void SetVariable()
{
	idxIsland = XI_GetIsland(nCurScroll);
	if(idxIsland==-1) return;
	refIsland = GetIslandByIndex(idxIsland);
	GameInterface.strings.IslandName = XI_ConvertString(FindIslandName(refIsland.id)); // KK

	townsQty = GetIslandTownsQuantity(refIsland.id);

	SetNodeUsing("LEFTCHANGE_TOWN",townsQty>1);
	SetSelectable("LEFTCHANGE_TOWN",townsQty>1);
	SetNodeUsing("RIGHTCHANGE_TOWN",townsQty>1);
	SetSelectable("RIGHTCHANGE_TOWN",townsQty>1);

	string town = GetTownIDFromIsland(refIsland.id, curTown);
	GameInterface.strings.TownName = GetTownName(town); // KK
	SetTownFlagImage(town); // KK
	int curStore = GetTownStoreIndex(GetTownIDFromIsland(refIsland.id, curTown));//MAXIMUS: the simplest way :) -->
	XI_SetIslandData(curStore);
	if(curStore<0)
	{
		GameInterface.strings.VisitDate = XI_ConvertString("There is no shop")+"!";
		ChangeStringColor("VisitDate", COLOR_RED);
		ChangeStringColor("TownName", COLOR_NORMAL);
		return;
	}//MAXIMUS <--
	if(CheckAttribute(Stores[curStore],"STORE_CURDATE"))
	{
		GameInterface.strings.VisitDate = XI_ConvertString("Last visit") + ": " + Stores[curStore].STORE_CURDATE;
		ChangeStringColor("VisitDate", COLOR_GREEN);
		ChangeStringColor("TownName", COLOR_GREEN);
	}
	else
	{
		GameInterface.strings.VisitDate = XI_ConvertString("Store was not visited");
		ChangeStringColor("VisitDate", COLOR_RED);
		ChangeStringColor("TownName", COLOR_NORMAL);
	}
}

void SetNextParty(bool bRight)
{
	if(bRight)
	{
		curTown++;
		if(curTown > townsQty) { curTown = 1; }
	}
	else
	{
		curTown--;
		if(curTown < 1) { curTown = townsQty; }
	}
}

void XI_SetIslandData(int curStore)
{	// trade info
	string tradeAttr,strAttr,picAttr,strPrice;
	int idxGoods;
	bool fIvisible = false;
	if(CheckAttribute(refIsland,"visible") && sti(refIsland.visible)==true)	fIvisible = true;
	for(int i=0;i<7;i++)
	{
		string impAttr1, impAttr2, impSell, impBuy;
		string expAttr1, expAttr2, expSell, expBuy;
		string conAttr1, conAttr2, conSell, conBuy;
		int j;
		tradeAttr = "id"+(i+1);
		// for import goods
		strAttr = "Import"+i;
		strPrice = "Import0"+i; // added by MAXIMUS
		picAttr = "igood"+i;
		if(fIvisible)
		{
			if(CheckAttribute(refIsland,"Trade.Import."+tradeAttr) && curStore!=-1)
			{
				idxGoods = sti(refIsland.Trade.Import.(tradeAttr));
// added by MAXIMUS -->
				impAttr1 = "importsell"+i;
				impAttr2 = "importbuy"+i;
				if(CheckAttribute(Stores[curStore],impAttr1) && CheckAttribute(Stores[curStore],impAttr2))
				{
				//	GameInterface.strings.(strPrice) = Stores[curStore].(impAttr1) + " " + XI_ConvertString("gp")+"." + " / "+Stores[curStore].(impAttr2) + " " + XI_ConvertString("gp")+".";
					GameInterface.strings.(strPrice) = Stores[curStore].(impAttr1) + " / " + Stores[curStore].(impAttr2);
				}
				else GameInterface.strings.(strPrice) = "...";
// added by MAXIMUS <--
				GameInterface.strings.(strAttr) = XI_ConvertString(Goods[idxGoods].name);
				GameInterface.pictures.(picAttr).pic = Goods[idxGoods].name;
			}
			else
			{
				GameInterface.strings.(strAttr) = "";
				GameInterface.strings.(strPrice) = "";
				GameInterface.pictures.(picAttr).pic = "";
			}
		}
		else
		{
			GameInterface.strings.(strAttr) = "";
			GameInterface.strings.(strPrice) = "";
			GameInterface.pictures.(picAttr).pic = "";
		}
		// for export goods
		strAttr = "Export"+i;
		strPrice = "Export0"+i; // added by MAXIMUS
		picAttr = "egood"+i;
		if(fIvisible)
		{
			if(CheckAttribute(refIsland,"Trade.Export."+tradeAttr) && curStore!=-1)
			{
				idxGoods = sti(refIsland.Trade.Export.(tradeAttr));
// added by MAXIMUS -->
				expAttr1 = "exportsell"+i;
				expAttr2 = "exportbuy"+i;
			//	if(CheckAttribute(Stores[curStore],expAttr1)) expSell = Stores[curStore].(expAttr1) + " " + XI_ConvertString("gp")+".";
				if(CheckAttribute(Stores[curStore],expAttr1)) expSell = Stores[curStore].(expAttr1);
			//	if(CheckAttribute(Stores[curStore],expAttr2)) expBuy = " / "+Stores[curStore].(expAttr2) + " " + XI_ConvertString("gp")+".";
				if(CheckAttribute(Stores[curStore],expAttr2)) expBuy = " / " + Stores[curStore].(expAttr2);
				if(CheckAttribute(Stores[curStore],"STORE_CURDATE")) GameInterface.strings.(strPrice) = expSell + expBuy;
				else GameInterface.strings.(strPrice) = "...";
// added by MAXIMUS <--
				GameInterface.strings.(strAttr) = XI_ConvertString(Goods[idxGoods].name);
				GameInterface.pictures.(picAttr).pic = Goods[idxGoods].name;
			}
			else
			{
				GameInterface.strings.(strAttr) = "";
				GameInterface.strings.(strPrice) = "";
				GameInterface.pictures.(picAttr).pic = "";
			}
		}
		else
		{
			GameInterface.strings.(strAttr) = "";
			GameInterface.strings.(strPrice) = "";
			GameInterface.pictures.(picAttr).pic = "";
		}
		// for contraband goods
		strAttr = "Contraband"+i;
		strPrice = "Contraband0"+i;
		picAttr = "cgood"+i;
		if(fIvisible)
		{
			if(CheckAttribute(refIsland,"Trade.Contraband."+tradeAttr) && curStore!=-1)//MAXIMUS: if we'll have contraband trader - curStore!=-1 can be deleted
			{
				idxGoods = sti(refIsland.Trade.Contraband.(tradeAttr));
				GameInterface.strings.(strAttr) = XI_ConvertString(Goods[idxGoods].name);
				conAttr1 = "contrasell"+i;
				conAttr2 = "contrabuy"+i;
			//	if(CheckAttribute(Stores[curStore],conAttr1)) conSell = Stores[curStore].(conAttr1) + " " + XI_ConvertString("gp")+".";
				if(CheckAttribute(Stores[curStore],conAttr1)) conSell = Stores[curStore].(conAttr1);
			//	if(CheckAttribute(Stores[curStore],conAttr2)) conBuy = " / "+Stores[curStore].(conAttr2) + " " + XI_ConvertString("gp")+".";
				if(CheckAttribute(Stores[curStore],conAttr2)) conBuy = " / " + Stores[curStore].(conAttr2);
				if(CheckAttribute(Stores[curStore],"STORE_CURDATE")) GameInterface.strings.(strPrice) = conSell + conBuy;
				else GameInterface.strings.(strPrice) = XI_ConvertString("by deal");
				GameInterface.pictures.(picAttr).pic = Goods[idxGoods].name;
			}
			else
			{
				GameInterface.strings.(strAttr) = "";
				GameInterface.strings.(strPrice) = "";
				GameInterface.pictures.(picAttr).pic = "";
			}
		}
		else
		{
			GameInterface.strings.(strAttr) = "";
			GameInterface.strings.(strPrice) = "";
			GameInterface.pictures.(picAttr).pic = "";
		}
	}
}

void FillScroll()
{
    int i;
    string attributeName;

	nCurScroll = -1;
	GameInterface.islandslist.current = 0;
	GameInterface.islandslist.BadPicture1 = NONEISLAND_TEXTURE_NAME;
	GameInterface.islandslist.ImagesGroup.t1 = "ISLANDSICON";

	int islandIdx;
	ref islandRef;
    for(i=0; i<ISLANDS_QUANTITY; i++) // NK 05-03-30 use int for max, and oversized array
    {
		attributeName = "pic" + (i+1);
		islandIdx = XI_GetIsland(i);
		if(islandIdx==-1) break;

		islandRef = GetIslandByIndex(islandIdx);
		GameInterface.islandslist.(attributeName).img1 = islandRef.id;
		GameInterface.islandslist.(attributeName).tex1 = 0;
    }
	GameInterface.islandslist.ListSize = i;
}

void ProcessCancelExit()
{
	IDoExit(RC_INTERFACE_TRADEBOOK_EXIT);
}

int XI_GetIsland(int inum)
{
	if(inum<0) return -1;
	if(inum>=ISLANDS_QUANTITY) return -1; // NK 05-03-30 use int for max, and oversized array

	int idx = 0;
	for(int i=0; i<ISLANDS_QUANTITY; i++) // NK 05-03-30 use int for max, and oversized array
	{
		if( !CheckAttribute(&Islands[i],"visible") ) continue;
		if( !sti(Islands[i].visible) ) continue;
		if( idx==inum ) return i;
		idx++;
	}
	return -1;
}

void IDoExit(int exitCode)
{
	DelEventHandler("InterfaceBreak","ProcessCancelExit");
	DelEventHandler("frame","FrameProcess");
	DelEventHandler("exitCancel","ProcessCancelExit");
	DelEventHandler("ievnt_command","ProcessCommandExecute"); // MAXIMUS interface MOD

    interfaceResultCommand = exitCode;
// MAXIMUS interface MOD -->
	EndCancelInterface(true);
}

void ProcessCommandExecute()
{
	string comName = GetEventData();
	string nodName = GetEventData();

	switch(nodName)
	{
	case "LEFTCHANGE_TOWN":
		if(comName=="click")
		{
			if(bBeParty)
			{
				SetNextParty(false);
				SetVariable();
			}
		}
	break;

	case "RIGHTCHANGE_TOWN":
		if(comName=="click")
		{
			if(bBeParty)
			{
				SetNextParty(true);
				SetVariable();
			}
		}
	break;
	}

	int x;ref tmpch;string tmpstr;
        if(nodName=="I_CHARACTER")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIP")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIPHOLD")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_PASSENGER")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_QUESTBOOK")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_SHIPLOG")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_NATIONS")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
        if(nodName=="I_ITEMS")
{ 
if(comName=="activate" || comName=="click")
	{

		PostEvent("LaunchIAfterFrame",1,"sl", nodName, 2);
		InterfaceStack.SelectMenu_node = nodName;
		interfaceResultCommand = RC_INTERFACE_TRADEBOOK_EXIT;
		EndCancelInterface(false);

	}
}
}
// MAXIMUS interface MOD <--

// KK -->
void SetTownFlagImage(string town)
{
	int town_nation = GetTownNation(town);
	string imageName = GetNationNameByType(town_nation);
	if (hasSubStr(imageName, "unknown") == true || imageName == "no nation" || imageName == "Catalonia") imageName = "PERSONAL_NATION";
	if (imageName == "Britain") imageName = "England";
	CreateImage("nationFlag", GetTextureImage(town_nation), imageName, 557, 71, 621, 135);
	//GameInterface.pictures.nationPicture = CharNation;
}

string GetTextureImage(int curNation)
{
	string nationTexture = curNation;
	switch(curNation)
	{
		case ENGLAND: nationTexture = "NATIONS_2"; break;
		case FRANCE: nationTexture = "NATIONS_2"; break;
		case SPAIN: nationTexture = "NATIONS_1"; break;
		case PIRATE: nationTexture = "NATIONS_2"; break;
		case HOLLAND: nationTexture = "NATIONS_2"; break;
		case PORTUGAL: nationTexture = "NATIONS_1"; break;
		case PERSONAL_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case CATALONIA: nationTexture = "SMALL_NATION_ICONS"; break;
		case NEUTRAL_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case UNKNOWN_NATION: nationTexture = "SMALL_NATION_ICONS"; break;
		case BROKEN: nationTexture = "SMALL_NATION_ICONS"; break;
	}

	return nationTexture;
}
// <-- KK
