ref procGetSailTextureData()
{
	int st,i,sq;
	ref shref, char;
	aref arEmbl,arSail;
	string attrName;

	int chrIdx = GetEventData();
	makeref(char,Characters[chrIdx]);
	ref pchar = GetMainCharacter();

	st = GetCharacterShipType(char);
	shref = GetShipByType(st);

	if(!CheckAttribute(pchar,"Viper_SailsType"))
	{
		pchar.Viper_SailsType = "default";
	}
	else
	{
		if (pchar.Viper_SailsType != "default" && pchar.Viper_SailsType != "set")
		{
			pchar.Viper_SailsType = "default";
		}
	}

	if(!CheckAttribute(char,"Viper_SailsType"))
	{
		char.Viper_SailsType = "default";
	}
	else
	{
		if (char.Viper_SailsType != "default" && char.Viper_SailsType != "set")
		{
			char.Viper_SailsType = "default";
		}
	}

	DeleteAttribute(&BI_objRetValue,"");
	BI_objRetValue.normalTex = "ships\sails\sail_parus_whole_white_plain.tga"; // KK

	string nationFileName = "ships\sails\sail_parus_whole_white_plain.tga"; // KK
	string tmpStr;

	if(chrIdx>=0)
	{
// KK -->
		if(IsCompanion(char))
		{
			char.Viper_SailsType = pchar.Viper_SailsType;		// so your companions all have the same sails as you (a much more impressive effect when you all have coordinated sails, i feel ^_^ )
			if (char.Viper_SailsType == "set")
			{
				char.EmblemedSails.nationFileName = PChar.EmblemedSails.nationFileName;
				char.EmblemedSails.normalTex = PChar.EmblemedSails.normalTex;
			}
		}

		switch(char.Viper_SailsType)					// this switch statement decides which logoed sails and which normal sails to use according to Viper_SailsType, to be applied below
		{
			case "set":
				nationFileName = char.EmblemedSails.nationFileName;
				BI_objRetValue.normalTex = char.EmblemedSails.normalTex;
			break;

			// default:
				BI_objRetValue.normalTex = "ships\sails\" + KAM_GetDefaultNormalSail(char);
				nationFileName = "ships\sails\" + KAM_GetDefaultEmblemedSail(char);
		}
// <-- KK

		if(st!=SHIP_NOTUSED)
		{

			//NK 04-09-05 no longer necessary
			/*if(shref.Name == "Frigate_sat")						// fix for the animist frigate
			{
				shref.GeraldSails.rey_b2	= 1;
				shref.GeraldSails.rey_b3	= 1;
			}*/

			makearef(arEmbl,shref.GeraldSails);						// actually sets the texture of each individual sail -->
			sq = GetAttributesNum(arEmbl);
			for(i=0; i<sq; i++)
			{
				arSail = GetAttributeN(arEmbl,i);
				attrName = GetAttributeName(arSail);
				tmpStr = GetAttributeValue(arSail);
				if(tmpStr=="1")	{BI_objRetValue.(attrName) = nationFileName;}
				else	{BI_objRetValue.(attrName) = tmpStr;}				// <--
			}
		}
	}

	return &BI_objRetValue;
}
