program jef_program_getmovie;

uses 'jef_program_variables.pas';

function GetMovie(MovieCode, season: integer; FullDesc: boolean): string;
begin
	result:=GetMovie3(MovieCode, season, FullDesc, false, false);
end;

//show movie's info
function GetMovie3(MovieCode, season: integer; FullDesc, FullComments, FullPersons: boolean): string;
begin
	result:=GetMovie4(MovieCode, season, FullDesc, FullComments, FullPersons, false);
end;

//show movie's info
function GetMovie4(MovieCode, season: integer; FullDesc, FullComments, FullPersons, FullAwards: boolean): string;
var
  jEdList, jEdDetails, jEpImdbCodeList, sl, sl2: TStringList;
  duration, i, j, k, m, kol, ie, RecordCount: integer;
  all, s, s2, country, description, comment, genre, year, director, writer, composer, actor, character, down, salary, awards: string;
  rating: integer;
  IMDBRating: double;
  FileName, img, OriginalTitle, site, url, postfix: string;
  flCollection, flSeen, flWanted, flForSale, LastCode: integer;
  collection, seen, wanted, sale, rate, mpaa, mpaa_value, mpaa_desc, mpaa_help, disc_nom, seasons: string;
  VideoStandard, ScreenRatio, resolution, mpaa_code, VideoBitrate, VideoCodec, filesize: integer;
  jDiscLabelCode, jEpisodesNbr: integer;   // 20090828-JeF
  custom: array[1..6] of integer;
  cust: string;
  DateAdd, DateUpdate, DateSeen: string;
  jVideoFileName, jVideoFileFolder, EpisodeDesc: string;
  PosCrLf: integer;
  ThmPage, tag, info, txtpos: string;										// 20090703-JeF
  MediaFormat, MediaType, CoverCode, jListWidth: integer;					// 20090703-JeF
  CoverPath, links, StudiosInfo: string;									// 20090703-JeF
  VideoStdInfo, ScrRatioInfo, ResolutionInfo, VideoCodecInfo: string;		// 20090703-JeF
  MediaFormatInfo, MediaTypeInfo, AudioTracksInfo, SubtitlesInfo: string;	// 20090703-JeF
  MovieThumbsInfo, PeopleThumbsInfo, LoanInfo, DiscLabelInfo: string;		// 20090703-JeF
  Custfld: array[1..4] of string;											// 20090703-JeF
  Custlst1, Custlst2: string;												// 20090703-JeF
  DurationInfo: string;														// 20090728-JeF
  imdb_code, IMDBrate, jRatedLinks: string;									// 20090830-JeF
  episodeIMDB: string;
  jEdVideoFileName, jEdVideoFileFolder, jEdVideoStdInfo, jEdScrRatioInfo: string;
  jEdResolutionInfo, jEdMediaFormatInfo, jEdVideoCodecInfo, jEdAudioTracksInfo: string;
  jEdSubtitlesInfo, jEdDurationInfo, jEdBarCodeInfo, jEdDiscNom, jEdLoanInfo: string;
  jEdDiscLabelInfo, jEdDiscNomInfo, jEdFeatures, jEdComment, jEpTitle: string;
  jEdEditionInfo, jMainEdInfo, jEdTableInfo, jEdLineInfo, jEdAllInfo: string;
  jEdCode, jEdEdition, jEdSortOrder, jVideoRefEdCode, jEdFileSize, jEdDuration: integer;
  jEdVideoBitrate, jEdColSpan, jEdSeason, jEdEpisode, jEpSeason, jEpEpisode: integer;
  jEdCost, jMainCost: Integer;
  jTagline: String;
  ThumbFileName: String;
  TVSeriesMovieCode: Integer;

begin
	SetIntXFvar(2,'MovieCode',MovieCode);
	SetIntXFvar(2,'season',season);
	SetBoolXFvar(2,'FullDesc',FullDesc);
	s:=IntToStr(MovieCode);
	while (length(s)<9) do s:='0'+s;
	jHomePageCode:='000200000'+s;

	result:='';
	sl:=TStringList.Create;
	sl2:=TStringList.Create;

	if GetBoolOption('AlwaysFullDesc') then FullDesc:=True;
	
	all:='';
	      
	m:=GetIntOption('EdDiscAutoNbrMode');
	if (m>0) then begin
		with sl do begin
			Clear;
			Add('select code from editions ');
			Add(format('where movie=%d ', [MovieCode]));
			Add('and disc_nom is null or disc_nom = '''' ');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if (RecordCount>0) then begin
			sl.Clear;
			for i:=1 to RecordCount do begin
				sl.Add(GetStringField('code'));
				GetNextRecord;
			end;
			ExtraFeature(211,'00003000000000');
			j:=GetIntXFvar(211,'HighestDisk');
			sl2.Clear;
			sl2.CommaText:=GetStrXFvar(211,'Gaps');
			for i:=1 to sl.Count do begin
				k:=-1;
				if (m=1) and (sl2.Count>0) then begin
					k:=StrToIntDef(sl2[0],-1);
					sl2.Delete(0);
				end;
				if (k<0) then begin
					j:=j+1;
					k:=j;
				end;
				s:=format('update editions set disc_nom=''%.4d'' where code=%s',[k,sl[i-1]]);
				RecordCount:=ExecuteSQL(s);
			end;
		end;
	end;
	
	jVideoFileName:='';
	with sl do begin
		Clear;
		Add('select filename from editions');
		Add(format('where movie=%d and filename>'' limit 1', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if (RecordCount>0) then jVideoFileName:=ClearExtraSDQuotes(GetStringField('filename'));
	
	with sl do begin
		Clear;
		Add('select * from movies');
		Add(format('where code=%d', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount=0 then exit;
	
	s:='movie:'+IntToStr(MovieCode);
	movie:=GetStringField('title');
	if (jVideoFileName='') 
		then jVideoFileName:=ClearExtraSDQuotes(GetStringField('FileName'));
	jVideoFileFolder:=jVideoFileName;
	while (length(jVideoFileFolder)>0) and (pos(jVideoFileFolder[length(jVideoFileFolder)],'/\')=0) 
		do delete(jVideoFileFolder,length(jVideoFileFolder),1);

	OriginalTitle:=GetStringField('original_title');
	rating:=GetIntegerField('rating');
	IMDBRating:=GetFloatField('imdb_rating');
	imdb_code:=GetStringField('imdb_code');   // 20090902-JeF

	flCollection:=GetIntegerField('in_collection');
	flSeen:=GetIntegerField('seen');
	flWanted:=GetIntegerField('wanted');
	flForSale:=GetIntegerField('for_sale');

	mpaa_code:=GetIntegerField('mpaa');
	mpaa_desc:=GetStringField('mpaa_rating');

	DateAdd:=GetStringField('date_add');
	DateUpdate:=GetStringField('date_update');
	DateSeen:=GetStringField('date_seen');
	jTagline := GetStringField('tagline');

	//GoForward(s, GetStringField('m.title'), ChangeHistory);

	description:=GetStringField('description');
	salary:=GetStringField('salary');
	awards:=GetStringField('awards');
	comment:=GetStringField('comment');

	custom[1]:=GetIntegerField('custom1');
	custom[2]:=GetIntegerField('custom2');
	custom[3]:=GetIntegerField('custom3');
	custom[4]:=GetIntegerField('custom4');

	if GetStringField('duration')='' then
		duration:=0
	else
		duration:=GetIntegerField('duration');
		
	//Movie Duration
	DurationInfo:='';
	if duration>0 then begin
		s:=GetLangStr(297);
		k:=pos('%',s);
		all:=all+copy(s,1,k-1);
		s:=copy(s,k,length(s)-k+1);
		DurationInfo:=format(s, [Duration]);
		// Added H:MM notation
		i:=int(Duration/60);
		j:=Duration-(i*60);
		s:=' ('+IntToStr(i)+':';
		if (j<10) then s:=s+'0';
		s:=s+IntToStr(j)+')';
		DurationInfo:=DurationInfo+s;
	end;

	year:=GetStringField('year');
	i:=StrToIntDef(year,0);
	if (i>0) then SetStrXFvar(2,'EndDate',DateToStr(EncodeDate(i,06,30)))
	else SetStrXFvar(2,'EndDate','');

	MediaType:=GetIntegerField('media_type');		 // 20090703-JeF

	if flCollection=0 then
		collection:=format('<a href="collection:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('not_collection.gif'), GetLangStr(326)])
	else
		collection:=format('<a href="collection:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('collection.gif'), GetLangStr(325)]);

	if flSeen=0 then
		seen:=format('<a href="seen:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('not_seen.gif'), GetLangStr(328)])
	else
		seen:=format('<a href="seen:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('seen.gif'), GetLangStr(327)]);

	if flWanted=0 then
		wanted:=format('<a href="wanted:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('not_wanted.gif'), GetLangStr(330)])
	else
		wanted:=format('<a href="wanted:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('wanted.gif'), GetLangStr(329)]);

	if flForSale=0 then
		sale:=format('<a href="sale:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('not_sale.gif'), GetLangStr(332)])
	else
		sale:=format('<a href="sale:%d"><img src="%s" border="0" alt="%s"></a>',  [MovieCode, GetRscPath('sale.gif'), GetLangStr(331)]);

	rate:='';
	for i:=1 to 10 do begin
		if i mod 2=1 then begin
			if i<=rating then
				rate:=rate+format('<a href="rating:%d"><img src="%s" align="absmiddle" border="0"></a>',  [i, GetRscPath('BarUnitLeft-On.gif')])
			else
				rate:=rate+format('<a href="rating:%d"><img src="%s" align="absmiddle" border="0"></a>',  [i, GetRscPath('BarUnitLeft-Off.gif')])
			end
		else begin
			if i<=rating then
				rate:=rate+format('<a href="rating:%d"><img src="%s" align="absmiddle" border="0"></a>',  [i, GetRscPath('BarUnitRight-On.gif')])
			else
				rate:=rate+format('<a href="rating:%d"><img src="%s" align="absmiddle" border="0"></a>',  [i, GetRscPath('BarUnitRight-Off.gif')])
		end;
	end;

	// 20090830-JeF
	IMDBrate:='';
	for i:=1 to 10 do begin
		if i mod 2=1 then begin
			if (i<=round(IMDBrating+0.1)) then
				IMDBrate:=IMDBrate+format('<img src="%s" align="absmiddle" border="0">',  [GetRscPath('Bar2UnitLeft-On.gif')])
			else
				IMDBrate:=IMDBrate+format('<img src="%s" align="absmiddle" border="0">',  [GetRscPath('Bar2UnitLeft-Off.gif')])
			end
		else begin
			if (i<=round(IMDBrating)) then
				IMDBrate:=IMDBrate+format('<img src="%s" align="absmiddle" border="0">',  [GetRscPath('Bar2UnitRight-On.gif')])
			else
				IMDBrate:=IMDBrate+format('<img src="%s" align="absmiddle" border="0">',  [GetRscPath('Bar2UnitRight-Off.gif')]);
		end;
	end;

	//description
	if description<>'' then begin
		if (length(description)>DescriptionLength) and not FullDesc then begin
			description:=copy(description, 1, DescriptionLength)
						+BlockTag('', 'TB0003+', 'tag-s')
						+'...<a href="custom110100031:1"><img src="'+GetRscPath('toggle-right.png')
						+'" border="0" align="absmiddle"></a>&nbsp;'
						+BlockTag('', 'TB0003+', 'tag-e')
						+BlockTag('', 'TB0003-', 'tag-s')
						+copy(description, DescriptionLength+1, length(description)-DescriptionLength)
						+'<a href="custom110100030:1"><img src="'+GetRscPath('toggle-left.png')
						+'" border="0" align="absmiddle"></a>&nbsp;'
						+BlockTag('', 'TB0003-', 'tag-e');
			description:=BlockTag(description, 'TB0003+', 'show');
		end;
		
	end;

	if description='' then
		down:='<br>'+format('<a href="DownloadMovie:%d">', [MovieCode])+GetLangStr(324)+'</a>'
	else
		down:='';

	//pictures
	CoverPath:=GetRscPath('no-cover.gif'); 	// 20090703-JeF
	CoverCode:=0; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select * from images');
		Add(format('where movie=%d and mode=1', [MovieCode]));
		Add('order by sort_order');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		FileName:=ImagesPath+GetStringField('path');
		CoverCode:=GetIntegerField('code');   // 20090703-JeF
		CoverPath:=FileName; 				// 20090703-JeF
	end;
	
	//Auto Cover Set : If no cover found, set Cover from latest added image of parametered type
	m:=GetIntOption('CoverAutoSetMode');
	if (m>0) and (CoverCode=0) then begin
		with sl do begin
			Clear;
			Add('select * from images');
			Add(format('where movie=%d and mode=%d', [MovieCode,m]));
			Add('order by code descend, sort_order');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if (RecordCount>0) then begin
			FileName:=ImagesPath+GetStringField('path');
			CoverCode:=GetIntegerField('code');
			CoverPath:=FileName;
			with sl do begin
				Clear;
				Add('update images set mode=1');
				Add(format('where code=%d', [CoverCode]));
			end;
		end;
	end;

	//mpaa
	mpaa:='';
	mpaa_value:='';
	mpaa_help:='';
	if mpaa_code>0 then begin
		with sl do begin
			Clear;
			Add('select name from manuals');
			Add(format('where code=%d', [mpaa_code]));
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			mpaa_value:=GetStringField('name');
			s:=format('<a href="custom000400011:%d">%s</a>', [mpaa_code, mpaa_value]);
			mpaa:=format(GetLangStr(374), [s]);
			if mpaa_desc<>'' then
				mpaa:=mpaa+' '+mpaa_desc;
		end;
		s:=GetLangStr(1190);
		i:=pos('www.',s);
		if (i>0) then begin
			j:=MyPos(' ',s,i);
			if (j=0) then j:=length(s)+1;
			s2:=copy(s,i,j-i);
			insert('</a>',s,j);
			insert('<a href="link:http://'+s2+'">',s,i);
		end;
		s:='<center><div>'+s+'</div></center>'
			+'<br><center><img src="'+GetRscPath('mpaa\ratings.png')+'"></center>';
		SetStrXFvar(213,'PgTitle',GetLangStr(708));
		SetStrXFvar(213,'PgContent',s);
		s2:=GetRscPath('help.png');
		mpaa_help:=format('<a href="custom021300000:1"><img src="%s" border="0" height="14px" align="absmiddle"></a>', [s2]);
	end;
		
	// media type  // 20090703-JeF_Begin
	MediaTypeInfo:='';
	with sl do begin
		Clear;
		Add('select * from manuals');
		Add(format('where code in (%d) and reference = 3', [MediaType]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		MediaTypeInfo:=GetStringField('name');
		MediaTypeInfo:=format('<a href="custom000400003:%d">%s</a>', [MediaType, GetStringField('name')]);
	end;
	// 20090703-JeF_End
	  
	//countries
	country:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select * from movies_manuals mm');
		Add('join manuals m on m.code=mm.ref_code');//and m.reference=mm.reference надо ли???
		Add(format('where mm.movie=%d and m.reference=9', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		//'Countries: '
		country:=GetLangStr(73)+': ';
		for i:=1 to RecordCount do begin
		  s:=GetFlagTag(GetStringField('m.name'));    // 20090703-JeF
		  if (s>'') then country:=country+format('<a href="country:%d">',[GetIntegerField('m.code')])+s+'</a> ' ;    // 20090703-JeF
		  country:=country+format('<a href="country:%d">%s</a> / ', [GetIntegerField('m.code'), GetStringField('m.name')]);
		  GetNextRecord;
		end;
		country:=copy(country, 1, length(country)-3);
		// 20090703-JeF //all:=all+format('%s<br>', [country]);
		all:=all+country+'<br>';    // 20090703-JeF
	end;

	// Studios // 20090703-JeF
	StudiosInfo:='';
	with sl do begin
		Clear;
		Add('select * from movies_manuals mm');
		Add('join manuals m on m.code=mm.ref_code');
		Add(format('where mm.movie=%d and m.reference=12', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		for i:=1 to RecordCount do begin
		  //StudiosInfo:=StudiosInfo+GetStringField('m.name')+', ';
		  StudiosInfo:=StudiosInfo+format('<a href="custom000400012:%d">%s</a> / ', [GetIntegerField('m.code'), GetStringField('m.name')]);
		  GetNextRecord;
		end;
		StudiosInfo:=copy(StudiosInfo, 1, length(StudiosInfo)-2);
	end;
	
	//genres
	genre:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select * from movies_manuals mm');
		Add('join manuals m on m.code=mm.ref_code');//and m.reference=mm.reference надо ли???
		Add(format('where mm.movie=%d and m.reference=8', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		//'Genres: '
		genre:=GetLangStr(72)+': ';
		for i:=1 to RecordCount do begin
		  genre:=genre+format('<a href="genre:%d">%s</a> / ', [GetIntegerField('m.code'), GetStringField('m.name')]);
		  GetNextRecord;
		end;
		genre:=copy(genre, 1, length(genre)-3);
		all:=all+genre+'<br>';
	end;

	//directors
	director:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select distinct * from data d');
		Add('inner join persons p on p.code=d.person');
		Add(format('where d.movie=%d and d.mode=1', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		  //'Directors: ';
		director:=GetLangStr(66)+': ';
		for i:=1 to RecordCount do begin
		  if GetIntegerField('p.in_collection')=1 then
			img:=format('<img src="%s" align="absmiddle">', [GetRscPath('person.gif')])
		  else
			img:='';
		  director:=director+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
		  GetNextRecord;
		end;
		director:=copy(director, 1, length(director)-2);
		all:=all+director+'<br>';
	end;

	//writers
	writer:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select distinct * from data d');
		Add('inner join persons p on p.code=d.person');
		Add(format('where d.movie=%d and d.mode=2', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		//'Writers: '
		writer:=GetLangStr(67)+': ';
		for i:=1 to RecordCount do begin
		  if GetIntegerField('p.in_collection')=1 then
			img:=format('<img src="%s" align="absmiddle">', [GetRscPath('person.gif')])
		  else
			img:='';
		  writer:=writer+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
		  GetNextRecord;
		end;
		writer:=copy(writer, 1, length(writer)-2);
		all:=all+writer+'<br>';
	end;

	//composers
	composer:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select distinct * from data d');
		Add('inner join persons p on p.code=d.person');
		Add(format('where d.movie=%d and d.mode=4', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		//'Composers: '
		composer:=GetLangStr(491)+': ';
		for i:=1 to RecordCount do begin
		  if GetIntegerField('p.in_collection')=1 then
			img:=format('<img src="%s" align="absmiddle">', [GetRscPath('person.gif')])
		  else
			img:='';
		  composer:=composer+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
		  GetNextRecord;
		end;
		composer:=copy(composer, 1, length(composer)-2);
		all:=all+composer+'<br>';
	end;

	//actors
	actor:=''; 	// 20090717-JeF
	with sl do begin
		Clear;
		Add('select distinct p.code, p.name, p.in_collection, c.name from data d');
		Add('inner join persons p on p.code=d.person');
		Add('left outer join characters c on c.person=p.code and c.movie=d.movie');
		Add(format('where d.movie=%d and d.mode=3', [MovieCode]));
		Add('order by d.sort_order');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		//'Actors: '
		actor:=GetLangStr(68)+': ';
		kol:=RecordCount;
//		if (kol>10) and NOT FullDesc then   // 20090818-JeF
//		  kol:=10;
		for i:=1 to kol do begin
		  if (i=11) and not FullDesc then begin
			actor:=actor+BlockTag('', 'TB0002+', 'tag-s')
						+'...<a href="custom110100021:1"><img src="'+GetRscPath('toggle-right.png')
						+'" border="0" align="absmiddle"></a>&nbsp;'
						+BlockTag('', 'TB0002+', 'tag-e')
						+BlockTag('', 'TB0002-', 'tag-s');
		  end;
		  if GetIntegerField('p.in_collection')=1 then
			img:=format('<img src="%s" align="absmiddle">', [GetRscPath('person.gif')])
		  else
			img:='';
		  character:=GetStringField('c.name');
		  if character='' then
			//actor:=actor+format('%s<a href="person:%d">%s</a>, ', [img, GetIntegerField('p.code'), GetStringField('p.name')])
			actor:=actor+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, '
		  else
			actor:=actor+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+format('</a> (%s), ', [character]);
		  GetNextRecord;
		end;
		actor:=copy(actor, 1, length(actor)-2);
		if (RecordCount>10) and not FullDesc then begin
			actor:=actor+'&nbsp;<a href="custom110100020:1"><img src="'+GetRscPath('toggle-left.png')
						+'" border="0" align="absmiddle"></a>'
						+BlockTag('', 'TB0002-', 'tag-e');
			actor:=BlockTag(actor, 'TB0002+', 'show');
		end;
//		if kol<RecordCount then
//		  actor:=actor+format(GetLangStr(566), [MovieCode]);   // 20090818-JeF
		all:=all+actor+'<br>';
	end;
	all:=all+'</td></tr></table>';

	//dates
	s:='';
	if DateAdd<>'' then
		s:=s+format(GetLangStr(620), [SQLDate2Str(DateAdd)])+', ';
	if DateUpdate<>'' then
		s:=s+format(GetLangStr(621), [SQLDate2Str(DateUpdate)])+', ';
	if DateSeen<>'' then
		s:=s+format(GetLangStr(622), [SQLDate2Str(DateSeen)])+', ';
	if s<>'' then
		all:=all+copy(s, 1, length(s)-2)+'<br>';

	//custom fields
	cust:='';
	for i:=1 to 4 do begin
		CustFld[i]:='';		// 20090703-JeF
		if custom[i]>0 then begin
			with sl do begin
				Clear;
				Add('select name from manuals');
				Add(format('where code=%d', [custom[i]]));
			end;
			RecordCount:=ExecuteSQL(sl.text);
			if RecordCount>0 then begin
				CustFld[i]:=format('<a href="custom%d:%d">', [i, custom[i]])+GetStringField('name')+'</a>';		// 20090703-JeF
				cust:=cust+format(GetLangStr(539+i), [s])+format(': <a href="custom%d:%d">', [i, custom[i]])+GetStringField('name')+'</a><br>';
			end;
		end;
	end;
	all:=all+cust;

	//custom list1
	CustLst1:='';		// 20090703-JeF
	cust:='';
	with sl do begin
		Clear;
		Add('select * from movies_manuals mm');
		Add('join manuals m on m.code=mm.ref_code');
		Add(format('where mm.movie=%d and m.reference=17', [MovieCode]));
		Add('order by m.name');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		cust:=cust+GetLangStr(544)+': ';
		for i:=1 to RecordCount do begin
			CustLst1:=CustLst1+format('<a href="custom5:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);		// 20090703-JeF
			cust:=cust+format('<a href="custom5:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);
			GetNextRecord;
		end;
		cust:=copy(cust, 1, length(cust)-2);
		CustLst1:=copy(CustLst1, 1, length(CustLst1)-2);	// 20090703-JeF
		all:=all+cust+'<br>';
	end;

	//custom list2
	CustLst2:='';		// 20090703-JeF
	cust:='';
	with sl do begin
		Clear;
		Add('select * from movies_manuals mm');
		Add('join manuals m on m.code=mm.ref_code');
		Add(format('where mm.movie=%d and m.reference=18', [MovieCode]));
		Add('order by m.name');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	if RecordCount>0 then begin
		cust:=cust+GetLangStr(545)+': ';
		for i:=1 to RecordCount do begin
			CustLst2:=CustLst2+format('<a href="custom6:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);		// 20090703-JeF
			cust:=cust+format('<a href="custom6:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);
			GetNextRecord;
		end;
		cust:=copy(cust, 1, length(cust)-2);
		CustLst2:=copy(CustLst2, 1, length(CustLst2)-2);	// 20090703-JeF
		all:=all+cust+'<br>';
	end;

	//description
	if description<>'' then begin   // 20090614-JeF
		
		// 20090614-JeF_Begin
		if GetBoolOption('DescNewLine') then begin
			PosCrLf:=pos(#13#10,description);
			while (PosCrLf > 0) do begin
				description:=copy(description,1,PosCrLf-1) + '<br>' + copy(description,PosCrLf+2,length(description)-poscrlf-1);
				PosCrLf:=pos(#13#10,description);
			end;
		end;
		// 20090614-JeF_End
		
		all:=all+'<hr height="1">'+description+'';
		
	end;  // 20090614-JeF
	  
	//awards
	if (awards>'') and (GetBoolOption('MovieAwards')) then all:=all+'<br><small>'+awards+'</small>';		// 20090818-JeF

	//salary
	if salary<>'' then
		all:=all+'<br><small>'+salary+'</small>';
	if comment<>'' then
		all:=all+'<hr height="1">'+comment+'';

	with sl do begin
		Clear;
		Add('select count(*) from episodes');
		Add(format('where movie=%d', [MovieCode]));
	end;
	ExecuteSQL(sl.text);
	jEpisodesNbr:=GetIntegerField('count(*)');

	//Reset Left column infos (main edition)
	VideoStdInfo:='';
	ScrRatioInfo:='';
	ResolutionInfo:='';
	VideoCodecInfo:='';
	VideoBitrate:=0;
	MediaFormatInfo:='';
	filesize:=0;
	AudioTracksInfo:='';
	SubtitlesInfo:='';
	disc_nom:='';
	DiscLabelInfo:='';
	jVideoFileName:='';
	LoanInfo:='';

	// Editions
	jEdList:=TStringList.Create;
	jEdDetails:=TStringList.Create;
	jEdAllInfo:='';
	jMainEdInfo:='';
	with sl do begin
		Clear;
		Add('select e.code, e.filename from editions e');
		Add(format('where e.movie=%d', [MovieCode]));
		Add('order by e.sort_order');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	jVideoRefEdCode:=0;
	for ie:=1 to RecordCount do begin
		jEdCode:=GetIntegerField('e.code');
		jEdList.Add(IntToStr(jEdCode));
		if (length(GetStringField('e.filename'))>5) and (jVideoRefEdCode=0)
			then jVideoRefEdCode:=jEdCode;
		GetNextRecord;
	end;
	for ie:=1 to jEdList.Count do begin
		//editons
        with sl do begin
        	Clear;
        	Add('select * from editions');
        	Add(format('where code=%s', [jEdList[ie-1]]));
        end;
        RecordCount:=ExecuteSQL(sl.text);
		
		jEdCode:=GetIntegerField('code');
		jEdSeason:=GetIntegerField('season');
		jEdEpisode:=GetIntegerField('episode');
		jEdBarCodeInfo:='';
		jEdLoanInfo:='';

		//VideoFile parameters
		jEdVideoStdInfo:='';
		jEdScrRatioInfo:='';
		jEdResolutionInfo:='';
		jEdVideoCodecInfo:='';
		jEdMediaFormatInfo:='';
		jEdAudioTracksInfo:='';
		jEdSubtitlesInfo:='';
		jEdDiscLabelInfo:='';
		jEdDiscNomInfo:='';
		jEdEditionInfo:='';
		jEdDurationInfo:='';
		
		MediaFormat:=GetIntegerField('media_format');
		VideoStandard:=GetIntegerField('video_standard');
		ScreenRatio:=GetIntegerField('screen_ratio');
		Resolution:=GetIntegerField('resolution');
		VideoCodec:=GetIntegerField('video_codec');
		jEdVideoBitrate:=GetIntegerField('video_bitrate');
		jEdFileSize:=GetIntegerField('filesize');
		jEdDuration:=GetIntegerField('duration');
		jEdDiscNom:=GetStringField('disc_nom');
		jDiscLabelCode:=GetIntegerField('disc_label');
		jEdBarCodeInfo:=GetStringField('barcode');
		jEdVideoFileName:=ClearExtraSDQuotes(GetStringField('filename'));
		jEdVideoFileFolder:=jEdVideoFileName;
		while (length(jEdVideoFileFolder)>0) and (pos(jEdVideoFileFolder[length(jEdVideoFileFolder)],'/\')=0) 
			do delete(jEdVideoFileFolder,length(jEdVideoFileFolder),1);
		jEdEdition:=GetIntegerField('edition');
		jEdSortOrder:=GetIntegerField('sort_order');
		jEdFeatures:=GetStringField('features');
		jEdComment:=GetStringField('comment');
		jEdCost:=GetIntegerField('cost');

		with sl do begin
			Clear;
			Add('select * from manuals');
			Add(format('where code in (%d, %d, %d, %d, %d, %d)', [VideoStandard, ScreenRatio, Resolution, VideoCodec, MediaFormat, jEdEdition]));
			Add('order by reference');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		for i:=1 to RecordCount do begin
			if GetIntegerField('reference')=1 then begin
				//Video standard
				jEdVideoStdInfo:=format('<a href="custom000400001:%d">%s</a>', [VideoStandard, GetStringField('name')]);
			end
			else if GetIntegerField('reference')=2 then begin
				//media format
				jEdMediaFormatInfo:=format('<a href="media_format:%d">%s</a>', [MediaFormat, GetStringField('name')]);   //20090703-JeF
			end
			else if GetIntegerField('reference')=4 then begin
				//screen ratio
				jEdScrRatioInfo:=format('<a href="aspect_ratio:%d">%s</a>', [ScreenRatio, GetStringField('name')]);   //20090703-JeF
			end
			else if GetIntegerField('reference')=5 then begin
				//resolution
				jEdResolutionInfo:=format('<a href="resolution:%d">%s</a>', [resolution, GetStringField('name')]);   //20090703-JeF
			end
			else if GetIntegerField('reference')=19 then begin
				//video codec
				jEdVideoCodecInfo:=format('<a href="custom000400019:%d">%s</a>', [VideoCodec, GetStringField('name')]);
			end
			else if GetIntegerField('reference')=21 then begin
				//edition
				jEdEditionInfo:=format('<a href="custom000400021:%d">%s</a>', [jEdEdition, GetStringField('name')]);
			end;
			GetNextRecord;
		end;

		//Duration
		jEdDurationInfo:='';
		if jEdDuration>0 then begin
			s:=GetLangStr(297);
			k:=pos('%',s);
			all:=all+copy(s,1,k-1);
			s:=copy(s,k,length(s)-k+1);
			jEdDurationInfo:=format(s, [jEdDuration]);
			// Added H:MM notation
			i:=int(jEdDuration/60);
			j:=jEdDuration-(i*60);
			s:=' ('+IntToStr(i)+':';
			if (j<10) then s:=s+'0';
			s:=s+IntToStr(j)+')';
			jEdDurationInfo:=jEdDurationInfo+s;
		end;

		//audio tracks
		with sl do begin
		  Clear;
		  Add('select m.code, m.name, am.Bitrate, am.Codec, am.Channel, am.Short_Comment from audio_manuals am');
		  Add('left join manuals m on m.code=am.reference');
		  Add(format('where am.edition=%d and am.media_type=0', [jEdCode]));
		end;
		RecordCount := ExecuteSQL(sl.text);
		for i:=1 to RecordCount do begin
			s := '';
			if GetStringField('am.codec') <> '' then
				s := ' ' + GetStringField('am.codec');
			if (s <> '') then
			  S := s + ' ';
			if (GetIntegerField('am.channel') > 0) then
			  s := s + GetStringField('am.channel') + ' ch ';
			if (GetIntegerField('am.Bitrate') > 0) then
			  s := s + GetStringField('am.Bitrate') + ' kbps ';
			if (GetStringField('am.Short_Comment') <> '') then
			  s := s + GetStringField('am.Short_Comment') + ' ';
			  
			if (s<>'') then
				s := copy(s, 1, length(s) - 1);
				
			jEdAudioTracksInfo:=jEdAudioTracksInfo+format('<a href="audio_track:%d">%s</a>%s, ', [GetIntegerField('m.code'), GetStringField('m.name'), s]);
			GetNextRecord;
		end;
		
		//subtitles
		with sl do begin
		  Clear;
		  Add('select m.code, m.name, am.Short_Comment from audio_manuals am');
		  Add('join manuals m on m.code=am.reference');
		  Add(format('where am.edition=%d and am.media_type=1', [jEdCode]));
		end;
		RecordCount:=ExecuteSQL(sl.text);
		for i:=1 to RecordCount do begin
			s := '';
			if (GetStringField('am.Short_Comment') <> '') then
			  s := ' ' + Trim(GetStringField('am.Short_Comment'));
			jEdSubtitlesInfo:=jEdSubtitlesInfo+format('<a href="subtitle:%d">%s</a>%s, ', [GetIntegerField('m.code'), GetStringField('m.name'), s]);
			GetNextRecord;
		end;
		
		if (length(jEdAudioTracksInfo)>2)
			then jEdAudioTracksInfo:=copy(jEdAudioTracksInfo, 1, length(jEdAudioTracksInfo)-2);
		if (length(jEdSubtitlesInfo)>2) 
			then jEdSubtitlesInfo:=copy(jEdSubtitlesInfo, 1, length(jEdSubtitlesInfo)-2);

		//disc label   // 20090828-JeF
		if jDiscLabelCode>0 then begin
			with sl do begin
				Clear;
				Add('select * from manuals');
				Add(format('where code=%d', [jDiscLabelCode]));
			end;
			RecordCount:=ExecuteSQL(sl.text);
			if RecordCount>0 then begin
				jEdDiscLabelInfo:=format('<a href="disc_label:%d">%s</a>', [jDiscLabelCode, GetStringField('name')]);    // 20090828-JeF
			end;
		end;
		
		//disc # (disc_nom)
		if (jEdDiscNom>'') then	jEdDiscNomInfo:=format('<a href="custom005600001:%d">%s</a>', [jEdCode, jEdDiscNom]);

		//loans
		with sl do begin
			Clear;
			Add('select * from loans l');
			Add('inner join manuals m on m.code=l.location');
			Add(format('where edition=%d', [jEdCode]));
			Add('and (return_date='''' or return_date is null)');
			Add('order by loan_date desc');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			jEdLoanInfo:=format('<a href="location:%d">%s</a>', [GetIntegerField('l.location'), GetStringField('m.name')]);
		end;

		//main infos from 'main' edition
		if (jEdCode=jVideoRefEdCode)
		or (jVideoRefEdCode=0) and (ie=1) then begin
			if (DurationInfo='') then DurationInfo:=jEdDurationInfo;
			VideoStdInfo:=jEdVideoStdInfo;
			ScrRatioInfo:=jEdScrRatioInfo;
			ResolutionInfo:=jEdResolutionInfo;
			VideoCodecInfo:=jEdVideoCodecInfo;
			VideoBitrate:=jEdVideoBitrate;
			MediaFormatInfo:=jEdMediaFormatInfo;
			filesize:=jEdFileSize;
			AudioTracksInfo:=jEdAudioTracksInfo;
			SubtitlesInfo:=jEdSubtitlesInfo;
			disc_nom:=jEdDiscNomInfo;
			DiscLabelInfo:=jEdDiscLabelInfo;
			jVideoFileName:=jEdVideoFileName;
			LoanInfo:=jEdLoanInfo;
			jMainEdInfo:=jEdEditionInfo;
			jMainCost:=jEdCost;
		end;
		
		//no edition tables if only one edition without extra infos (dvd features, comment)
		if (jEdList.Count<=1) and (jEdFeatures='') and (jEdComment='') then continue;

		//Current edition Table
		jEdTableInfo:='';
		if (jEdEditionInfo='') then jEdEditionInfo:=format(GetLangStr(1260), [ie]);
		jEdTableInfo:=jEdTableInfo+'<table class="MovieInfo"><tr><td class="NameC" colspan=4><h2 class="DeepColor">';
		if (jEdSeason+jEdEpisode>0) then begin
			s2:='<a href="custom110199990:'+format('%.5d%.4d',[jEdSeason,jEdEpisode])+'">'
				+'<img src="'+GetRscPath('toggle-up.png')
				+'" border="0" align="absmiddle"></a>&nbsp;';
		end
		else begin
			s2:='<a href="custom110100040:1"><img src="'+GetRscPath('toggle-left.png')
				+'" border="0" align="absmiddle"></a>&nbsp;';
		end;
		jEdTableInfo:=jEdTableInfo+s2+jEdEditionInfo+'</h2></td></tr>';
		if (jEdList.Count>1) then begin
			//Line 1
			jEdLineInfo:='';
			if (jEdDurationInfo='') or (jEdBarCodeInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdDurationInfo>'') then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'
							+copy(GetLangStr(297),1,pos(':',GetLangStr(297))-1)
							+'</td><td colspan='+IntToStr(jEdColSpan)+'><nobr>'
							+jEdDurationInfo+'</nobr></td>';
			end;
			if (jEdBarCodeInfo>'') then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'
							+copy(GetLangStr(1259),1,pos(':',GetLangStr(297))-1)
							+'</td><td colspan='+IntToStr(jEdColSpan)+'><nobr>'
							+jEdBarCodeInfo+'</nobr></td>';
			end;
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 2 by Vlad
			if (jEdCost>0) then begin
				jEdTableInfo:=jEdTableInfo+'<tr><td class="Name">'+GetLangStr(3350)+'</td><td colspan="3">'
							+IntToStr(jEdCost)+'</td></tr>';
			end;
			//Line 2
			jEdLineInfo:='';
			if (jEdDiscNomInfo='') or (jEdDiscLabelInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdDiscNomInfo>'') then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'
							+GetLangStr(391)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
							+jEdDiscNomInfo+'</td>';
			end;
			if (jEdDiscLabelInfo>'') then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'
							+GetLangStr(673)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
							+jEdDiscLabelInfo+'</td>';
			end;
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 3
			jEdLineInfo:='';
			if (jEdMediaFormatInfo='') or (jEdVideoStdInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdMediaFormatInfo>'')
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(249)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdMediaFormatInfo+'</td>';
			if (jEdVideoStdInfo>'') 
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(201)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdVideoStdInfo+'</td>';
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 4
			jEdLineInfo:='';
			if (jEdResolutionInfo='') or (jEdScrRatioInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdResolutionInfo>'') 
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(203)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdResolutionInfo+'</td>';
			if (jEdScrRatioInfo>'') 
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(202)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdScrRatioInfo+'</td>';
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 5
			jEdLineInfo:='';
			if (jEdAudioTracksInfo='') or (jEdSubtitlesInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdAudioTracksInfo>'')
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(254)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdAudioTracksInfo+'</td>';
			if (jEdSubtitlesInfo>'')
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(253)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdSubtitlesInfo+'</td>';
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 6
			jEdLineInfo:='';
			if (jEdVideoCodecInfo='') and (jEdVideoBitrate=0) or (jEdLoanInfo='') then jEdColSpan:=3 else jEdColSpan:=1;
			if (jEdVideoCodecInfo>'') or (jEdVideoBitrate>0) then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'
								+GetLangStr(571)+'</td><td colspan='+IntToStr(jEdColSpan)+'>';
				if (jEdVideoCodecInfo>'')
					then jEdLineInfo:=jEdLineInfo+jEdVideoCodecInfo+', ';
				if (jEdVideoBitrate>0) then begin
					s:=GetLangStr(572);
					k:=pos('%', s);
					s:=copy(s,k,length(s)-k+1);
					s:=format(s, [jEdVideoBitrate]);
					jEdLineInfo:=jEdLineInfo+s
				end;
				if (copy(jEdLineInfo,length(jEdLineInfo)-1,2)=', ') then delete(jEdLineInfo,length(jEdLineInfo)-1,2);
				jEdLineInfo:=jEdLineInfo+'</td>';
			end;
			if (jEdLoanInfo>'')
				then jEdLineInfo:=jEdLineInfo+'<td class="Name">'
									+GetLangStr(333)+'</td><td colspan='+IntToStr(jEdColSpan)+'>'
									+jEdLoanInfo+'</td>';
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
			//Line 7
			jEdLineInfo:='';
			if (jEdVideoFileName>'') then begin
				jEdLineInfo:=jEdLineInfo+'<td class="Name">'+GetLangStr(195)+'</td><td colspan=3>'
							+'<a href="link:file://'+jEdVideoFileFolder+'">'
							+'<img src="'+GetRscPath('Folder.png')+'" align="absmiddle" height=18 '
							+'alt="'+jEdVideoFileFolder+'" border=0></a>&nbsp;';
				if (jEpisodesNbr>0) then begin
					jEdLineInfo:=jEdLineInfo+'<a href="custom022000001:'+IntToStr(MovieCode)+'">'
						+'<img src="'+GetRscPath('GearWheel.png')+'" align="absmiddle" height=18 border=0></a>&nbsp;';
				end;
				// Button to export filepath to Filepaths List TextFile
				jEdLineInfo:=jEdLineInfo
							+Format('<a href="userref:10000,,%d">',[jEdCode])
							+'<img src="'+GetRscPath('AddToList.png')+'" align="absmiddle" height=18 '
							+'alt="'+jEdVideoFileName+'" border=0></a>&nbsp;';
				jEdLineInfo:=jEdLineInfo+'<a href="link:file://'+jEdVideoFileName+'">'+jEdVideoFileName;
				if (jEdFileSize>0) then begin
					s:=GetLangStr(629);
					k:=pos('%',s);
					s:=copy(s,k,length(s)-k+1);
					s:=format(s, [jEdFileSize]);
					jEdLineInfo:=jEdLineInfo+' ('+s+')';
				end;
				jEdLineInfo:=jEdLineInfo+'</td>';
			end;
			if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
		end;
		//Line 8
		jEdLineInfo:='';
		if (jEdFeatures>'') then begin
			jEdLineInfo:=jEdLineInfo+'<td class="Name">'+GetLangStr(1537)+'</td><td colspan=3>'
						+jEdFeatures
						+'</td>';
		end;
		if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
		//Line 9
		jEdLineInfo:='';
		if (jEdComment>'') then begin
			jEdLineInfo:=jEdLineInfo+'<td class="Name">'+GetLangStr(163)+'</td><td colspan=3>'
						+jEdComment
						+'</td>';
		end;
		if (jEdLineInfo>'') then jEdTableInfo:=jEdTableInfo+'<tr>'+jEdLineInfo+'</tr>';
		jEdTableInfo:=jEdTableInfo+'</table>';
		if (jEdSeason+jEdEpisode>0) then begin
			s:=format('TBS%.5dE%.4d',[jEdSeason,jEdEpisode]);
			jEdDetails.Values[s+'-duration']:=jEdDurationInfo;
			jEdDetails.Values[s+'-filename']:=jEdVideoFileName;
			jEdList[ie-1]:=s+'='+jEdTableInfo;
		end
		else begin
			jEdList[ie-1]:=jEdTableInfo;
			if (jEdAllInfo>'') then jEdAllInfo:=jEdAllInfo+'<br>';
			jEdAllInfo:=jEdAllInfo+jEdTableInfo;
		end;
	end;
	if (jEdAllInfo>'') then begin
		s:='<h2><a href="custom110100041:1">'+GetLangStr(1254)+'</a>'
			+'&nbsp;<a href="custom110100041:1"><img src="'+GetRscPath('toggle-right.png')
			+'" border="0" align="absmiddle"></a></h2>';
		s:=BlockTag(s,'TB0004+','tag');
		jEdAllInfo:='<a id="TB0004"></a>'+s+BlockTag(jEdAllInfo,'TB0004-','tag');
		jEdAllInfo:=BlockTag(jEdAllInfo,'TB0004-','show');
	end;

// >> SHOULD SOON BE Deprecated as episode imdb_code is populated by download scripts
	//20120414: Update Episodes Imdb ID if missing and present in title
	with sl do begin
		Clear;
		Add('select code, title from episodes ');
		Add(format('where movie=%d ', [MovieCode]));
		Add('and title like ''%(tt%'' ');
		Add('and (imdb_code = '''' or imdb_code is null)');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	sl2.clear;
	if (RecordCount>0) then begin
		for i:=1 to RecordCount do begin
			jEpTitle := GetStringField('title');
			s := copy(jEpTitle,pos('(tt',jEpTitle)+3,10);
			if (pos(')',s)>0) then s := copy(s,1,pos(')',s)-1);
			sl2.Add('update episodes set imdb_code = '+s+' where code = '+GetStringField('code'));
			GetNextRecord;
		end;
		for i:=0 to sl2.count - 1 do begin
			s := sl2[i];
			ExecuteSQL(s);
		end;
	end;

	//20121219: Retrieve Master TV Series if movie is referenced as an episode 
	TVSeriesMovieCode:=0;
  if (jEpisodesNbr=0) and (imdb_code > '') then begin
    with sl do begin
      Clear;
      Add('select e.movie from episodes e');
      Add(format('where e.imdb_code > 0 and e.imdb_code=%s ', [imdb_code]));
    end;
    RecordCount:=ExecuteSQL(sl.text);
    if (RecordCount>0) 
      then TVSeriesMovieCode:=GetIntegerField('e.movie');
  end;
	
	//20101010-JeF
	if (jEpisodesNbr>0) and (GetStrOption('TitleTVTag')>'') then begin
		movie:=movie+' ('+GetStrOption('TitleTVTag');
		if GetBoolOption('TitleTVTagYear') then movie:=movie+year
		else movie:=ClearExtraBlankCharacters(movie);
		movie:=movie+')';
	end;
	
	//seasons
	jEpImdbCodeList := TStringList.Create;
  
	//20121220: Scan for Episodes added as Movies 
	with sl do begin
		Clear;
		Add('select e.imdb_code from episodes e ');
		Add(format('where e.movie=%d ', [MovieCode]));
		Add('and e.imdb_code > '''' ');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	jEpImdbCodeList.clear;
	if (RecordCount>0) then begin
		for i:=1 to RecordCount do begin
			s2:=GetStringField('e.imdb_code');
      while (length(s2) < 7) do s2 := '0'+s2;
      jEpImdbCodeList.Add(s2);
			GetNextRecord;
		end;
	end;
	if (jEpImdbCodeList.Count>0) then begin
		for i:=0 to jEpImdbCodeList.Count - 1 do begin
    	with sl do begin
    		Clear;
    		Add('select mc.movie from movies_codes mc ');
    		Add(format('where mc.code=''%s'' ', [jEpImdbCodeList[i]]));
    		Add('and mc.script = ''imdb'' ');
      end;
    	RecordCount:=ExecuteSQL(sl.text);
      if (RecordCount>0) 
        then s2:=GetStringField('mc.movie')
      else s2:='*NONE';
      jEpImdbCodeList[i]:=jEpImdbCodeList[i]+'='+s2;
		end;
	end;

  seasons:='';
	kol:=0;
	with sl do begin
		Clear;
		Add('select * from episodes');
		Add(format('where movie=%d order by season, episode', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	jEpisodesNbr:=RecordCount;

	for i:=1 to RecordCount do begin
		if GetIntegerField('season')>kol then begin
			kol:=GetIntegerField('season');
			// 20090703-JeF // seasons:=seasons+'<h3>'+format(GetLangStr(514), [kol])+'</h3>';
			seasons:=seasons+'<h3 class="DeepColor"><div class="season">'+format(GetLangStr(514), [kol])+'</div></h3>';   // 20090703-JeF
		end;
		jEpSeason:=GetIntegerField('season');
		jEpEpisode:=GetIntegerField('episode');
		seasons:=seasons+format('<a id="TBS%.5dE%.4d"></a>',[jEpSeason,jEpEpisode]);
		seasons:=seasons+'<div class="episode">';   // 20090703-JeF
		seasons:=seasons+'<h3 class="DeepColor">';

		s:=format('TBS%.5dE%.4d',[jEpSeason,jEpEpisode]);
		if (jEdDetails.IndexOfName(s+'-filename')<>-1) 
			then seasons:=seasons+GetPlayTag(jEdDetails.Values[s+'-filename']);
		seasons:=seasons+format(GetLangStr(518), [GetIntegerField('episode')])+'. ';
		
		// 20101007-JeF : Episode link on episode title
		episodeIMDB:=GetStringField('imdb_code');
		jEpTitle := GetStringField('title');
    if (episodeIMDB='') and (pos('(tt',jEpTitle)>0) then begin   //20120414-JeF
			s := copy(jEpTitle,pos('(tt',jEpTitle)+3,10);
			if (pos(')',s)>0) then s := copy(s,1,pos(')',s)-1);
			episodeIMDB := s;
		end;
		if (episodeIMDB>'') then begin
      while (length(episodeIMDB) < 7) do episodeIMDB := '0'+episodeIMDB;
			url:='http://www.imdb.com/title/tt'+episodeIMDB;
			s2:='<a href="link:'+jRedir+url+'">'+GetStringField('title')+'.</a> ';
			seasons:=seasons+s2;
		end
		else seasons:=seasons+GetStringField('title')+'.';
		// 20101007-JeF : imdb logo as Episode link
		if (episodeIMDB>'') then begin
			url:='http://www.imdb.com/title/tt'+episodeIMDB;
			s:=GetRscPath('imdb.gif');
			s2:='<a href="link:'+jRedir+url+'">'
				+format('<img src="%s" border="0" align="absmiddle"></a> ', [s]);
			seasons:=seasons+s2;
		end;
		
		// 20120414-JeF : link to the movie card of the episode
		if (episodeIMDB>'') then begin
			if (jEpImdbCodeList.IndexOfName(episodeIMDB) >= 0) then begin
				s := GetRscPath('magnifier.png');
				s2 := jEpImdbCodeList.Values[episodeIMDB];  // movie code or *NONE
        if (s2 <> '*NONE') then begin
				  s2 := '&nbsp;<a href="movie:' + s2 + '"><img src="' + s + '" border="0"></a>';
				  seasons:=seasons+s2;
        end;
			end;
		end;
		
		s2:=GetStringField('original_air_date');
		s2:=SQLDate2Str(s2);
		if s2<>'' then
			seasons:=seasons+'&nbsp('+s2+')';

		if (jEdList.IndexOfName(s)<>-1) then begin
			if (jEdDetails.IndexOfName(s+'-duration')<>-1) 
				then seasons:=seasons+'&nbsp;'+jEdDetails.Values[s+'-duration'];
			s2:='&nbsp;<a href="custom110199991:'+format('%.5d%.4d',[jEpSeason,jEpEpisode])+'">'
				+'<img src="'+GetRscPath('toggle-down.png')
				+'" border="0" align="absmiddle"></a>';
			s2:=BlockTag(s2, s+'+', 'tag');
			s2:=BlockTag(s2, s+'+', 'show');
			s2:=s2+BlockTag(jEdList.Values[s], s+'-', 'tag');
			seasons:=seasons+s2;
		end;
		
		seasons:=seasons+'</h3>';
		seasons:=seasons+'</div>';   // 20090703-JeF
		
		// 20090614-JeF // seasons:=seasons+GetStringField('description');
		// 20090614-JeF_Begin
		EpisodeDesc:=GetStringField('description');
		if GetBoolOption('DescNewLine') then begin
			PosCrLf:=pos(#13#10,EpisodeDesc);
			while (PosCrLf > 0) do begin
				EpisodeDesc:=copy(EpisodeDesc,1,PosCrLf-1) + '<br>' + copy(EpisodeDesc,PosCrLf+2,length(EpisodeDesc)-poscrlf-1);
				PosCrLf:=pos(#13#10,EpisodeDesc);
			end;
		end;
		seasons:=seasons+EpisodeDesc;
		// 20090614-JeF_End

		GetNextRecord;
	end;

  jEpImdbCodeList.Free;
	jEdList.Free;
	jEdDetails.Free;
		
	//pictures from movie
	MovieThumbsInfo:='';    // 20090703-JeF
	with sl do begin
		Clear;
		Add('select * from images');
		Add(format('where movie=%d', [MovieCode]));
		Add('order by mode, sort_order');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	kol:=0;
	for i:=1 to RecordCount do begin
		if GetIntegerField('mode')=1 then
			kol:=kol+1;
				GetNextRecord;
			end;
			if (RecordCount-kol>0) or (kol>1) then begin
				RecordCount:=ExecuteSQL(sl.text);
		  if RecordCount>0 then
			all:=all+'<hr>';
		  for i:=1 to RecordCount do begin
			FileName:=ImagesPath+GetStringField('path');
			if (FileName<>CoverPath) or GetBoolOption('CoverInScreenshots') then begin // 20100910-JeF  Remove Cover from screenshots
				if (MyFileExists(FileName)) then begin
					ThumbFileName := GetThumb(GetStringField('path'),ThumbsScreenshots,'',0,0,false);
          MovieThumbsInfo:=MovieThumbsInfo+format('<a href="ShowImage:%d"><img src="%s" height="100" border="0"></a>&nbsp;',[GetIntegerField('code'), ThumbFileName]);   // 20090703-JeF
					all:=all+format('<a href="ShowImage:%d"><img src="%s" height="100" border="0"></a>&nbsp;',
					[GetIntegerField('code'), ThumbFileName]);
				end;
			end;
			GetNextRecord;
		end;
	end;

	//photos of people
	PeopleThumbsInfo:='';    // 20090703-JeF
	LastCode:=0;
	with sl do begin
		Clear;
		Add('select distinct i.path as path, i.person as code, p.name as name');
		Add('from data d');
		Add('inner join images i on i.person=d.person');
		Add('inner join persons p on p.code=d.person');   // 20090930-JeF
		Add(format('where d.movie=%d', [MovieCode]));
		Add('and i.mode=6');    // 20090721-JeF
		//Add('order by i.person, i.path');
		Add('order by d.mode, d.sort_order, i.person, i.sort_order, i.path');
	end;
	jListWidth:=GetHTMLWidth-GetIntThmOption('MovieOffWidth');
	PeopleThumbsInfo:=BuildList(sl.Text,'Person',5,80,jListWidth,1,9999,0,2);
	if (pos('href',PeopleThumbsInfo)=0) then PeopleThumbsInfo:='';

	//links
	links:='';  // 20090703-JeF	
	with sl do begin
		Clear;
		Add('select * from movies_codes mc');
		Add('left outer join partners p on mc.script=p.site');
		Add(format('where movie=%d', [MovieCode]));
		Add('order by p.sort_order');
	end;
	RecordCount:=ExecuteSQL(sl.text);
	sl.Clear;
	for i:=1 to RecordCount do begin
		site:=GetStringField('mc.script');
		url:=GetStringField('mc.site');
		postfix:=GetStringField('p.postfix');
		if postfix<>'' then
			url:=url+postfix;
		if site='buy' then begin   // 20090703-JeF
			if GetBoolOption('ShowFeaturedDVD') then   // 20090703-JeF
				all:=all+format(GetLangStr(375), [jRedir+url, movie])+' ';
		end  // 20090703-JeF
		else begin
			s:=GetRscPath(GetStringField('p.picture'));
			if GetStringField('p.picture')='' then
				s2:='<a href="link:'+jRedir+url+format('">%s</a> ', [site])
			else
				s2:='<a href="link:'+jRedir+url+'">'
					+format('<img src="%s" border="0" align="absmiddle"></a> ', [s]);
		end;
		links:=links+s2;
		if (site='imdb') then j:=0 else j:=GetIntegerField('mc.rating');
		sl.Add(format('%.4d-%.3d=',[j,i])+s2);
		if (GetIntegerField('mc.rating')>0) 
			then links:=links+format('(%d)&nbsp;',[GetIntegerField('mc.rating')]);
		GetNextRecord;
	end;
    if (pos('imdb',links)=0) and (imdb_code<>'') then begin
		url:='http://www.imdb.com/title/tt'+imdb_code;
        s:=GetRscPath('imdb.gif');
        s2:='<a href="link:'+jRedir+url+'">'
			+format('<img src="%s" border="0" align="absmiddle"></a> ', [s]);
		links:=links+s2;
		sl.Add(format('0000-%.3d=',[RecordCount+1])+s2);
    end;
	jRatedLinks:='';
	if (RecordCount>0) then begin
		sl.sort;
		if (StrToIntDef(copy(sl[sl.Count-1],1,4),0)>0) then begin
			s:='<table class="ratedlinks">';
			for i:=sl.Count downto 1 do begin
				j:=StrToIntDef(copy(sl[i-1],1,4),0);
				s2:=copy(sl[i-1],10,length(sl[i-1]));
				if (j>0) then s2:='<tr><td class="ratedlinklogo">'
								+s2+'</td><td class="ratedlinkrate">'+IntToStr(j)+'</td></tr>'
				else if (pos('</table>',s)=0) then s:=s+'</table>';
				s:=s+s2;
			end;
			if (pos('</table>',s)=0) then s:=s+'</table>';
			jRatedLinks:=s;
		end
		else jRatedLinks:=links;
	end;
	  
	ThmPage:=GetTemplate('movie');
	if (ThmPage<>'') then begin
		
		// Main Cover
		txtpos:='<img SRC="_cover_"';
		i:=pos(txtpos,ThmPage);
		if (i>0) then begin
			s:=format('<a href="ShowImage:%d"><img src="%s"', [CoverCode, CoverPath]); 
			ThmPage:=copy(ThmPage,1,i-1) + s + copy(ThmPage,i+length(txtpos),length(ThmPage)-i-length(txtpos));
			i:=MyPos('</td>',ThmPage,i);
			if (i>0) then ThmPage:=copy(ThmPage,1,i-1) + '</a>' + copy(ThmPage,i,length(ThmPage)-i+1);
		end;

		// Other Tags
		i:=pos('<!--#',ThmPage);
		while (i>0) do begin
			j:=MyPos('-->',ThmPage,i);
			tag:='';
			info:='';
			if (j>i) then begin
				tag:=copy(ThmPage,i+5,j-i-5);
				while (copy(tag,1,1)=' ') do tag:=copy(tag,2,length(tag)-1);
				while (copy(tag,length(tag),1)=' ') do tag:=copy(tag,1,length(tag)-1);
				k:=pos(' ',tag);
				if (k>0) then tag:=copy(tag,1,k-1);
				j:=j+3;
			end;
			
			if (tag='seenlogo') 				then info:=seen
			else if (tag='rating_lbl') 			then info:=GetLangStr(298)
			else if (tag='rating')  			then info:=rate
			else if (tag='ratevalue')   		then info:=IntToStr(rating)   // 20090903-JeF
			else if (tag='IMDBrating_lbl') 		then info:=GetLangStr(299)
			else if (tag='IMDBratingfulltxt') 	then begin
				if (IMDBrating>0) then info:=format(GetLangStr(299), [IMDBRating]);
			end
			else if (tag='IMDBrating')    		then info:=IMDBrate   // 20090830-JeF
			else if (tag='IMDBratevalue')   	then info:=FloatToStr(IMDBrating)   // 20090903-JeF
			else if (tag='ratedlinks') 			then info:=jRatedLinks
			else if (tag='mediatype_lbl')  		then info:='<img src="'+GetRscPath('media.png')+'" width=16 height=16 border=0> '
			else if (tag='mediatype')    		then info:=MediaFormatInfo
			else if (tag='mediacount')    		then info:=''
			else if (tag='edition_lbl')    		then info:=GetLangStr(1255)+' '
			else if (tag='edition')    			then info:=jEdAllInfo
			else if (tag='discnumber_lbl')    	then info:=GetLangStr(391)+' '
			else if (tag='discnumber')    		then info:=disc_nom
			else if (tag='medialabel_lbl')    	then info:=GetLangStr(673)+' '
			else if (tag='medialabel')    		then info:=DiscLabelInfo
			else if (tag='cost_lbl')          then info:=GetLangStr(3350)+' '
			else if (tag='cost') and (jMainCost>0)				then info:=IntToStr(jMainCost)
			else if (tag='barcode_lbl')    		then info:=GetLangStr(250)+' '
			else if (tag='barcode')    			then info:=MediaTypeInfo
			else if (tag='resolution_lbl')		then info:=GetLangStr(203)+' '
			else if (tag='resolution')			then info:=ResolutionInfo
			else if (tag='aspectratio_lbl')    	then info:=GetLangStr(202)+' '
			else if (tag='aspectratio')			then info:=ScrRatioInfo
			else if (tag='filesize_lbl')    	then begin
        if (pos(':',GetLangStr(629)) > 0)  
          then info:=copy(GetLangStr(629),1,pos(':',GetLangStr(629))-1)+' '
        else if (pos('%',GetLangStr(629)) > 0)  
          then info:=copy(GetLangStr(629),1,pos('%',GetLangStr(629))-1)+' ';
      end
			else if (tag='filesize') and (filesize>0) then begin
				info:=GetLangStr(629);
				k:=pos('%',info);
				info:=copy(info,k,length(info)-k+1);
				info:=format(info, [filesize]);
			end;
			
			if (tag='duration_lbl')   		then info:=copy(GetLangStr(297),1,pos(':',GetLangStr(297))-1)+' '
			else if (tag='duration')    		then begin
				info:=DurationInfo;
			end
			else if (tag='subtitles_lbl')    	then info:=GetLangStr(253)+' '
			else if (tag='subtitles')    		then info:=SubtitlesInfo
			else if (tag='subtitlesfulltxt,') then begin
				if (SubtitlesInfo>'')
					then info:=GetLangStr(253)+': '+SubtitlesInfo+', ';
			end

			else if (tag='videostd_lbl')   		then info:=GetLangStr(201)+' '
			else if (tag='videostd')    		then info:=VideoStdInfo
			else if (tag='videostdfulltxt,') and (VideoStdInfo>'')
				then info:=GetLangStr(201)+': '+VideoStdInfo+', '
			else if (tag='vidinfo_lbl')   		then info:=GetLangStr(571)+' '
			else if (tag='vidinfo')    			then begin
				if (VideoCodecInfo<>'') then info:=info+VideoCodecInfo;
				s:='';
				if (VideoBitrate>0) then begin
					s:=GetLangStr(572);
					k:=pos('%', s);
					s:=copy(s,k,length(s)-k+1);
					s:=format(s, [VideoBitrate]);
				end;
				if (info<>'') and (s<>'') then info:=info+', ';
				if (s<>'') then info:=info+s;
			end
			else if (tag='vidinfofulltxt,') and ((VideoCodecInfo>'') or (VideoBitrate>0)) then begin
				if (VideoCodecInfo>'') then info:=GetLangStr(571)+': '+VideoCodecInfo+', ';
				if (VideoBitrate>0) then info:=info+format(GetLangStr(572), [VideoBitrate])+', ';
			end;
			
			if (tag='audinfo_lbl')    		then info:=GetLangStr(254)+' '
			else if (tag='audinfo')    			then info:=AudioTracksInfo
			else if (tag='audinfofulltxt,') then begin
				if (AudioTracksInfo>'')
					then info:=GetLangStr(254)+': '+AudioTracksInfo+', ';
			end
			else if (tag='resolutionfulltxt,') then begin
				if (ResolutionInfo>'')
					then info:=GetLangStr(203)+': '+ResolutionInfo+', ';
			end
			else if (tag='aspectratiofulltxt,') then begin
				if (ScrRatioInfo>'')
					then info:=GetLangStr(202)+': '+ScrRatioInfo+', ';
			end
			else if (tag='videofilefulltxtbr') then begin
				if GetBoolOption('ShowFileName') and (jVideoFileName>'') then begin
					info:=GetLangStr(195)+' ';
					if filesize>0 then info:=info+'('+format('%d Mo', [filesize])+') ';
					info:=info+':  <a href="link:file://'+jVideoFileFolder+'">'
							+'<img src="'+GetRscPath('Folder.png')+'" align="absmiddle" height=18 '
							+'alt="'+jVideoFileFolder+'" border=0></a>&nbsp;'
							+Format('<a href="userref:10000,,%d">',[jVideoRefEdCode])
							+'<img src="'+GetRscPath('AddToList.png')+'" align="absmiddle" height=18 '
							+'alt="'+jVideoFileName+'" border=0></a>&nbsp;'
							+'<a href="link:file://'+jVideoFileName+'">'+jVideoFileName+'</a><br>';
				end;
			end
			else if (tag='mainedition_lbl')  	then info:=GetLangStr(1255)+' '
			else if (tag='mainedition')    		then info:=jMainEdInfo
			else if (tag='movienum_lbl')   		then info:='!movienum '
			else if (tag='movienum')    		then info:='!movienum '
			else if (tag='dateadd_lbl')    		then begin
				info:=GetLangStr(620);
				k:=pos('(',info);
				if (k>0) then info:=copy(info,1,k-1);
				k:=pos(':',info);
				if (k>0) then info:=copy(info,1,k-1);
				if (copy(info,length(info),1)<>' ') then info:=info+' ';
			end;
			
			if (tag='dateadd')    			then info:=SQLDate2Str(DateAdd)
			else if (tag='dateupd_lbl')    		then begin
				info:=GetLangStr(621);
				k:=pos('(',info);
				if (k>0) then info:=copy(info,1,k-1);
				k:=pos(':',info);
				if (k>0) then info:=copy(info,1,k-1);
				if (copy(info,length(info),1)<>' ') then info:=info+' ';
			end
			else if (tag='dateupd')    			then info:=SQLDate2Str(DateUpdate)
			else if (tag='dateseen_lbl')    	then begin
				info:=GetLangStr(622);
				k:=pos('(',info);
				if (k>0) then info:=copy(info,1,k-1);
				k:=pos(':',info);
				if (k>0) then info:=copy(info,1,k-1);
				if (copy(info,length(info),1)<>' ') then info:=info+' ';
			end;
			
			if (tag='dateseen')    		then info:=SQLDate2Str(DateSeen)
			else if (tag='date_lbl')    		then info:='!date '
			else if (tag='date')    			then info:='!date '
			else if (tag='medialocation_lbl')  	then info:='!medialocation '
			else if (tag='medialocation')   	then info:='!medialocation '
			else if (tag='personalmarks_lbl')  	then info:='!persmarks '
			else if (tag='personalmarks')   	then info:=collection
			else if (tag='wishlist_lbl')   		then info:='!wishlist '
			else if (tag='wishlist')    		then info:=wanted
			else if (tag='seen_lbl')   			then info:='!seen '
			else if (tag='seen')    			then info:=seen
			else if (tag='price_lbl')    		then info:='!price '
			else if (tag='price')    			then info:='!price '
			else if (tag='loan_lbl')   			then info:=GetLangStr(333)+' '
			else if (tag='loan')    			then info:=LoanInfo
			else if (tag='title')    			then begin
				info:='<a href="custom110100011:1"><img src="'+GetRscPath('IconsBarShow.png')
						+'" border="0" align="absmiddle" width="16"></a>&nbsp;';
				info:=BlockTag(info, 'TB0001+', 'tag');
				if (GetStrOption('NavBarState')='0') 
					then info:=BlockTag(info, 'TB0001+', 'show');
				info:=info+Movie;
        if (TVSeriesMovieCode > 0)
          then info:=info+'&nbsp'+
                     format('<a href="movie:%d"><img src="%s" border="0"></a>', 
                            [TVSeriesMovieCode,GetRscPath('toggle-up.png')]);
			end
			else if (tag='smallmainnavbar')  	then begin
				BuildMainNavBar(2,'111000111100');
				info:=jMainNavBar;
			end
			else if (tag='mainnavbar')  		then begin
				BuildMainNavBar(2,'111111111111');
				info:=jMainNavBar;
			end
			else if (tag='site_links')  		then info:=links
			else if (tag='btn_shortcuts')  			then begin
				info:='<span>'
					+collection+'&nbsp;'+seen+'&nbsp;'
					+wanted+'&nbsp;'+sale+'&nbsp;'
					+format('<a href="movie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('Refresh.png'),GetLangStr(598)])
					+'&nbsp;'
					+format('<a href="UpdateMovie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('editmovie.png'),GetLangStr(304)]);
				if (down>'')
					then info:=info+'&nbsp;'+format('<a href="DownloadMovie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('dlmovie.png'),GetLangStr(324)]);
				info:=info+'</span>';
			end
			else if (tag='btn_collection')  	then info:=collection
			else if (tag='btn_seen')  			then info:=seen
			else if (tag='btn_wanted')  		then info:=wanted
			else if (tag='btn_sale')  			then info:=sale
			else if (tag='btn_edit')
				then info:=format('<a href="UpdateMovie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('editmovie.png'),GetLangStr(304)])
			else if (tag='btn_download') and (down>'')
				then info:=format('<a href="DownloadMovie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('dlmovie.png'),GetLangStr(324)])
			else if (tag='btn_refresh')
				then info:=format('<a href="movie:%d"><img src="%s" border="0" alt="%s"></a>', [MovieCode,GetRscPath('Refresh.png'),GetLangStr(598)])
			else if (tag='txt_shortcuts')  			then begin
				info:='<span style="vertical-align:middle;font-size:12px;">';
				info:=info+format('<a href="UpdateMovie:%d">%s%s</a>', [MovieCode, GetLangStr(304), down]);
				info:=info+'</span>';
			end;
			
			if (tag='originaltitlefulltxtbr')   	then begin
				if (OriginalTitle<>'') and (movie<>OriginalTitle)
					then info:=format('%s: <b>%s</b><br> ', [GetLangStr(296), OriginalTitle]);
			end
			else if (tag='originaltitle')   	then begin
				if (OriginalTitle<>'') and (movie<>OriginalTitle) then begin
					info:='<tr><td class="Name">'+GetLangStr(296)+'</td><td><h2 class="DeepColor">'+OriginalTitle+'</h2></td></tr>';
				end;
			end
			else if (tag='tagline_lbl')			then info:=GetLangStr(3406)
			else if (tag='tagline_txt')			then info:=jTagline
			else if (tag='tagline') and (jTagline<>'') then
				info := '<tr><td class="Name">'+GetLangStr(3406)+'</td><td>'+jTagline+'</td></tr>'
			else if (tag='country_lbl')   		then info:=GetLangStr(73)
			else if (tag='countrytxt')   		then info:=copy(country,pos(':',country)+2,length(country))
			else if (tag='countryfulltxtbr')   
				then info:=country+'<br>'
			else if (tag='country') and (country>'')
				then info:='<tr><td class="Name">'+GetLangStr(73)+'</td><td>'
							+copy(country,pos(':',country)+2,length(country))+'</td></tr>'
			else if (tag='year_lbl')   			then info:=GetLangStr(169)
			else if (tag='yeartxt')
				then info:=format('<a href="year:%s">%s</a>',[year,year])
			else if (tag='year') and (year>'')
				then info:='<tr><td class="Name">'+GetLangStr(169)+'</td><td>'
							+format('<a href="year:%s">%s</a>',[year,year])+'</td></tr>'
			else if (tag='genre_lbl')  			then info:=GetLangStr(72)
			else if (tag='genretxt') and (genre>'')
				then info:=copy(genre,pos(':',genre)+2,length(genre))
			else if (tag='genrefulltxtbr') and (genre>'')
				then info:=genre+'<br>'
			else if (tag='genre') and (genre>'')
				then info:='<tr><td class="Name">'+GetLangStr(72)+'</td><td>'
							+copy(genre,pos(':',genre)+2,length(genre))+'</td></tr>'
			else if (tag='actors_lbl') 			then info:=GetLangStr(68)
			else if (tag='actorsfulltxtbr') and (actor>'')
				then info:=actor+'<br>'
			else if (tag='actors') and (actor>'')
				then info:='<tr><td class="Name">'+GetLangStr(68)+'</td><td>'
							+copy(actor,pos(':',actor)+2,length(actor))+'</td></tr>'
			else if (tag='director_lbl')   		then info:=GetLangStr(66)
			else if (tag='directorfulltxtbr') and (director>'')
				then info:=director+'<br>'
			else if (tag='director') and (director>'')
				then info:='<tr><td class="Name">'+GetLangStr(66)+'</td><td>'
							+copy(director,pos(':',director)+2,length(director))+'</td></tr>'
			else if (tag='scenario_lbl')   		then info:=GetLangStr(67)
			else if (tag='scenariofulltxtbr') and (writer>'')
				then info:=writer+'<br>'
			else if (tag='scenario') and (writer>'')
				then info:='<tr><td class="Name">'+GetLangStr(67)+'</td><td>'
							+copy(writer,pos(':',writer)+2,length(writer))+'</td></tr>'
			else if (tag='scenariofulltxtbr')  and (writer>'')
				then info:=writer+'<br>'
			else if (tag='composerfulltxtbr')  and (composer>'')
				then info:=composer+'<br>'
			else if (tag='composer_lbl') and (composer>'')
				then info:=GetLangStr(491)
			else if (tag='composer')  and (composer>'')
				then info:='<tr><td class="Name">'+GetLangStr(491)+'</td><td>'
							+copy(composer,pos(':',composer)+2,length(composer))+'</td></tr>'
			else if (tag='studio_lbl')
				then info:=GetLangStr(493)
			else if (tag='studio') and (StudiosInfo>'')
				then info:='<tr><td class="Name">'+GetLangStr(493)+'</td><td>'
							+StudiosInfo+'</td></tr>'
			else if (tag='mpaa') and (mpaa>'')
				then info:='<tr><td class="Name">'+GetLangStr(383)+' '+mpaa_help+'</td><td>'
							+copy(mpaa,pos(':',mpaa)+2,length(mpaa))+'</td></tr>'
			else if (tag='mpaal') and (mpaa>'')	then begin
				info:='<tr><td class="Name">'+GetLangStr(383)+' '+mpaa_help+'</td><td class="mpaal">'
						+copy(mpaa,pos(':',mpaa)+2,length(mpaa))+'</td></tr>';
				if (mpaa_value>'') then begin
					s:=GetRscPath('mpaa\'+UpperCase(mpaa_value)+'.png');
					s:='<img src="'+s+'" align="absmiddle" border=0>';
					info:=ReplaceStr(info,mpaa_value,s);
				end;
			end
			else if (tag='mpaals') and (mpaa>'')	then begin
				info:='<tr><td class="Name">'+GetLangStr(383)+' '+mpaa_help+'</td><td class="mpaals">'
						+copy(mpaa,pos(':',mpaa)+2,length(mpaa))+'</td></tr>';
				if (mpaa_value>'') then begin
					s:=GetRscPath('mpaa\'+UpperCase(mpaa_value)+'_short.png');
					s:='<img src="'+s+'" align="absmiddle" border=0>';
					info:=ReplaceStr(info,mpaa_value,s);
				end;
			end
			else if (tag='mpaa_lbl') and (mpaa_value>'') 
				then info:='MPAA&nbsp;'
			else if (tag='mpaavalue') and (mpaa_value>'') 
				then info:=format('<a href="custom000400011:%d">%s</a>', [mpaa_code, mpaa_value])
			else if (tag='mpaalogo') and (mpaa_value>'') then begin
				info:=GetRscPath('mpaa\'+UpperCase(mpaa_value)+'.png');
				info:=format('<a href="custom000400011:%d"><img src="%s" ', [mpaa_code, info])
					+' align="absmiddle" border=0></a>';
			end
			else if (tag='mpaalogoshort') and (mpaa_value>'') then begin
				info:=GetRscPath('mpaa\'+UpperCase(mpaa_value)+'_short.png');
				info:=format('<a href="custom000400011:%d"><img src="%s" ', [mpaa_code, info])
					+' align="absmiddle" border=0></a>';
			end
			else if (tag='mpaahelp') and (mpaa_value>'') then info:=mpaa_help
			else if (tag='playbutton') and (jVideoFileName>'') 
				then info:=GetPlayTag(jVideoFileName)
			else if (tag='filename') then begin
				if (jVideoFileName>'') or (jEpisodesNbr>0) then begin
					if GetBoolOption('ShowFileName') then begin
						info:='<tr><td class="Name">'+GetLangStr(195)+'</td><td>';
						if (jVideoFileName>'') then begin
							info:=info+'<a href="link:file://'+jVideoFileFolder+'">'
											+'<img src="'+GetRscPath('Folder.png')+'" align="absmiddle" height=18 '
											+'alt="'+jVideoFileFolder+'" border=0></a>&nbsp;';
						end;
						if (jEpisodesNbr>0) then begin
							info:=info+'<a href="custom022000001:'+IntToStr(MovieCode)+'">'
								+'<img src="'+GetRscPath('GearWheel.png')+'" align="absmiddle" height=18 border=0></a>&nbsp;';
							if (length(jVideoFileName)=0) 
								then info:=info+'< '+GetLangStr(1133);
						end;
						info:=info+Format('<a href="userref:10000,,%d">',[jVideoRefEdCode])
							+'<img src="'+GetRscPath('AddToList.png')+'" align="absmiddle" height=18 '
							+'alt="'+jVideoFileName+'" border=0></a>&nbsp;';
						s2:=jVideoFileName;
						k:=0;
						while (k<length(s2)) do begin
							k:=k+1;
							if (k<length(s2)-8) then begin
								insert('<wbr />',s2,k);
								k:=k+8;
							end;
						end;
						info:=info+'<a href="link:file://'+jVideoFileName+'">'+s2+'</td></tr>';
					end;
				end;
			end;
			
			if (tag='url')    				then info:=''
			else if (tag='description')    		then info:='<a id="TB0003"></a>'+description
			else if (tag='episodes_lbl') and (seasons<>'') then begin
				info:='<br><br><h2 class="DeepColor"><center>'+GetLangStr(525)+'</center><br></h2>';
			end
			else if (tag='editions')    		then info:=jEdAllInfo
			else if (tag='episodes')    		then info:=seasons
			else if (tag='trailer_lbl')   		then info:=''
			else if (tag='trailer')   			then info:=''
			else if (tag='screenshots') 		then begin
				if (MovieThumbsInfo<>'')
					then info:='<table width="100%"><tr><td width="1%">'
							+'<nobr>'+GetLangStr(1146)+'</nobr>'
							+'</td><td class="SplitLine">&nbsp;</td></tr></table>'
							+MovieThumbsInfo;
				if (PeopleThumbsInfo<>'') 
					then info:=info+'<table width="100%"><tr><td width="1%">'
							+'<nobr>'+GetLangStr(1147)+'</nobr>'
							+'</td><td class="SplitLine">&nbsp;</td></tr></table>'
							+PeopleThumbsInfo;
				if (MovieThumbsInfo<>'') or (PeopleThumbsInfo<>'') 
					then info:=info+'<div class="SplitLine">&nbsp;</div>';
			end
			else if (tag='comments_lbl') and (comment<>'') then info:='<h2 class="DeepColor"><center>'+GetLangStr(163)+'</center></h2><br>'
			else if (tag='comments')  			then info:=comment
			else if (tag='awards_lbl') and (awards>'') and GetBoolOption('MovieAwards') then info:='<h2 class="DeepColor"><center>'+GetLangStr(574)+'</center></h2><br>'
			else if (tag='awards') and GetBoolOption('MovieAwards') then info:=awards
			else if (tag='userfield')    		then begin
				for k:=1 to 4 do begin
					if (CustFld[k]<>'') then info:=info+GetLangStr(539+k)+' : '+CustFld[k]+'<br>';   // 20090905-JeF-Bug
				end;
				if (CustLst1<>'') then info:=info+GetLangStr(544)+' : '+CustLst1+'<br>';   // 20090905-JeF-Bug
				if (CustLst2<>'') then info:=info+GetLangStr(545)+' : '+CustLst2+'<br>';   // 20090905-JeF-Bug
			end;

			if (info<>'') then ThmPage:=copy(ThmPage,1,j-1) + info + copy(ThmPage,j,length(ThmPage)-j+1);

			i:=MyPos('<!--#',ThmPage,i+1);
		end;
		
		all:=ThmPage;

	end;
	sl.Free;
	sl2.Free;
	result:=all;
	jLastPage:=result;
//exportpage(jLastPage,'C:\Temp\ExportedPage.html');
end;

begin

end.