program breeze_program_part2;
                                                
uses 'breeze_program_variables.pas';

function GetMovie5(MovieCode, season: integer; FullDesc, FullComments, FullPersons, FullAwards: boolean): string;
var
  sl, TempList, SeenList, UnseenList, SeasonCovers: TStringList;
  duration, i, j, k, l, kol, rmax, RecordCount: integer;
  all, s, s2, s3, country, description, comment, genre, year, director, writer, composer, actor, character, down, salary, awards, studios: string;
  rating: integer;
  IMDBRating, SiteRating, EditionCost: double;
  FileName, img, OriginalTitle, site, url, postfix, ShortFilename: string;
  flCollection, flSeen, flWanted, flForSale, LastCode: integer;
  collection, seen, wanted, sale, rate, mpaa, mpaa_desc, disc_nom, seasons: string;
  VideoStandard, ScreenRatio, resolution, mpaa_code, VideoBitrate, VideoCodec, filesize: integer;
  DiscLabel: integer;
  custom: array[1..6] of integer;
  cust: string;
  DateAdd, DateUpdate, DateSeen, loan_date, return_date: string;
  age, border, bckgrnd: string;                                              
  editions: array [1..1000] of integer;
  EditionsCount, EditionCode, MediaFormat, ie: integer;
  ed, temp, barcode, OtherRating, EditionFeatures, EditionComment, VideoFileFolder, VideoFileName, TagLine: string;
  PrevBlockCnt, ThisBlockCnt, ShotCnt, MaxShots, hours, minutes, SeasonCnt, PosterCnt, ConnectionsCnt: Integer;
  page_width, PicWidth, PicHeight, TrailerCnt, AdditionalSpace, ScreenshotTotalHeight, page_width_rest, page_width_copy, MediaType, PrevPicWidth, this_width, this_height, this_season, LineSpace: Integer;
  NoTrailerAdded, ShowScreenshots, fl, FixedContentsWidth: Boolean;
  trunc_name, trunc_character, media_format, prev_media_format: String;
  OldLinkStatus, MovieSeries, MovieSeriesNumber: Integer;
  LinkYearStr, LinkMovieStr, LinkMovieStatusTitle, FullAwardsText, name, status, ends_with, temp_name, new_name: string;
begin
	result:='';
	sl:=TStringList.Create;
	all:='';
	OtherRating := '';
	
	LineSpace := Round((BasicFontSize + BiggerModifier) * LineSpacings[RegReadInteger('BreezeLineSpacing', DefaultLineSpacing)]);
	
	if (RegReadInteger('FixedContentsWidthOnMoviePage', 0) = 1) then
		FixedContentsWidth := True
	else
		FixedContentsWidth := False;

	bckgrnd := ' style="background-image: url(' + GetProperPath(ImgPath + 'list-background.gif') + ');"';
	with sl do begin
		Clear;
		Add('select code from images');
		Add(format('where movie=%d and mode in (3, 5, 7)', [MovieCode]));
		Add('order by sort_order');    
	end;
	ShotCnt:=ExecuteSQL(sl.text);
  
	with sl do begin
		Clear;
		Add('select count(code) as amount from movies_codes');
		Add(format('where movie=%d and script=''trailer''', [MovieCode]));
	end;
	RecordCount:=ExecuteSQL(sl.text);
	TrailerCnt := GetIntegerField('amount');
	// count movie connections
	with sl do begin
		Clear;
		Add('select count(code) as amount from movies_links');
		Add(Format('where movie_primary=%d', [MovieCode]));
	end;
	RecordCount := ExecuteSQL(sl.text);
	ConnectionsCnt := GetIntegerField('amount');
  
      
    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');

    OriginalTitle:=GetStringField('original_title');
    rating:=GetIntegerField('rating');
    IMDBRating:=GetFloatField('imdb_rating');

	flCollection:=GetIntegerField('in_collection');
	flSeen:=GetIntegerField('seen');
	flWanted:=GetIntegerField('wanted');
	flForSale:=GetIntegerField('for_sale');
	mpaa_code:=GetIntegerField('mpaa');
	mpaa_desc:=GetStringField('mpaa_rating');
	MediaType := GetIntegerField('media_type');

	DateAdd:=GetStringField('date_add');
	DateUpdate:=GetStringField('date_update');
	DateSeen:=GetStringField('date_seen');
	TagLine := GetStringField('tagline');
	MovieSeriesNumber := GetIntegerField('series_nom');
	MovieSeries := GetIntegerField('series');
	
	if (ConnectionsCnt <= 0) and (MovieSeries > 0) then
		ConnectionsCnt := 1;

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

    description:=GetStringField('description');
    salary:=GetStringField('salary');
    awards:=GetStringField('awards');
	FullAwardsText := 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');
    year:=GetStringField('year');

    disc_nom:=GetStringField('disc_nom');
      
	collection := '';
    if (flCollection=0) then begin
		if (RegReadInteger('ShowInCollectionStatusIcon', 1) = 1) then
			collection:=format('<a class="pic" href="collection:%d"><img class="icons" src="%snot-in-collection.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(326)]);
	end
    else
	    collection:=format('<a class="pic" href="collection:%d"><img class="icons" src="%sin-collection.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(325)]);

	seen := '';
    if (flSeen=0) then begin
		if (RegReadInteger('ShowSeenStatusIcon', 1) = 1) then
			seen:=format('<a class="pic" href="seen:%d"><img class="icons" src="%snot-seen.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(328)]);
	end
    else
	    seen:=format('<a class="pic" href="seen:%d"><img class="icons" src="%sseen.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(327)]);

	wanted := '';
    if (flWanted=0) then begin
		if (RegReadInteger('ShowWantedStatusIcon', 0) = 1) then
			wanted:=format('<a class="pic" href="wanted:%d"><img class="icons" src="%snot-wanted.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(330)]);
	end
    else
	    wanted:=format('<a class="pic" href="wanted:%d"><img class="icons" src="%swanted.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(329)]);
	sale := '';
    if (flForSale=0) then begin
		if (RegReadInteger('ShowForSaleStatusIcon', 0) = 1) then
			sale:=format('<a class="pic" href="sale:%d"><img class="icons" src="%snot-for-sale.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, GetLangStr(332)]);
	end
    else
	    sale:=format('<a class="pic" href="sale:%d"><img class="icons" src="%sfor-sale.gif" alt="%s" border="0"></a>',  [MovieCode, ImgPath, 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 class="pic" href="rating:%d"><img src="%shalfstar-left.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
			else
	    	  	rate:=rate+format('<a class="pic" href="rating:%d"><img src="%snot-halfstar-left.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
		end
		else begin
			if i<=rating then
		      	rate:=rate+format('<a class="pic" href="rating:%d"><img src="%shalfstar-right.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
			else
	    	  	rate:=rate+format('<a class="pic" href="rating:%d"><img src="%snot-halfstar-right.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
		end;
	end;

	//description
    if description<>'' then begin
		if (ActiveTab <> 10) and (not FullDesc) and (length(description)>DescriptionLength) then begin
			description:=copy(description, 1, DescriptionLength);
			description:=RemoveUnclosedTags(description);
			i := Pos('<br>', description);
			if i>0 then
				delete(description, i, length(description));
			description:=description+format(GetLangStr(566), [MovieCode]);
		end;
	end;

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

	// Count seasons
	with sl do begin
		Clear;
		Add('select distinct e.season from episodes e');
		Add(format('where e.movie=%d', [MovieCode]));
		Add(' order by e.season');
	 end;
	SeasonCnt:=ExecuteSQL(sl.text);

	VideoFileName := '';
    with sl do begin
      	Clear;
      	Add('select e.filename from editions e');
      	Add('left outer join manuals m on m.code=e.edition and m.reference=21');
      	Add(format('where e.movie=%d', [MovieCode]));
      	Add('order by e.sort_order');
    end;
    EditionsCount:=ExecuteSQL(sl.text);
	VideoFileName := GetStringField('e.filename');
	
	with sl do begin
		Clear;
        Add('select code from images');
        Add(format('where movie=%d and mode=4', [MovieCode]));
    		Add('order by sort_order');        
    end;
    PosterCnt:=ExecuteSQL(sl.text);
	
	if (ActiveTab <> 3) and (not FullAwards) and (length(awards)>DescriptionLength) then begin
		awards:=copy(awards, 1, DescriptionLength);
		awards:=RemoveUnclosedTags(awards);
		awards:=awards+format(GetLangStr(1331), [MovieCode]);
	end;
	
	//Check if the active tab exists
	//no seasons
	if ((ActiveTab = 6) and (SeasonCnt = 0)) or
	//no parameters
	((ActiveTab = 5) and (EditionsCount = 1) and (VideoFileName = '')) or 
	//no awards
	((ActiveTab = 3) and (awards = '')) or
	//no shots
	((ActiveTab = 2) and (shotCnt = 0)) or
	//no posters
	((ActiveTab = 7) and (PosterCnt = 0)) or
	//no trailers
	((ActiveTab = 9) and (TrailerCnt = 0)) or
	//No connections
	((ActiveTab = 11) and (ConnectionsCnt = 0)) then begin
		ActiveTab := 1;
		Result := GetMovie5(MovieCode, season, FullDesc, FullComments, FullPersons, FullAwards);
		exit;
	end;

	all:=GetPatternTop;
	all:= all + Format('<p class="page-header" style="font-size: %dpt;">', [BasicFontSize + PageHeaderModifier]) + movie;
	if (OriginalTitle <> '') and (OriginalTitle <> movie) then
		all := all + Format(' / <span style="font-size: %dpt;">', [BasicFontSize + SubHeaderModifier])+OriginalTitle+'</span>';
	all:= all + '</p>';

	//tab background
	all := all + '<table class="envelope"><tr><td><div style="margin-left: 10px; margin-right: 10px; height: 46px; background-image: url(' +GetProperPath(ImgPath + 'inactive-tab-button.gif') + ');">';
	//icons
	all := all + '<div class="icon-container">' + collection + seen + wanted + sale + '</div>';
	//tabs
	all := all + GetMovieTabs(MovieCode, season, SeasonCnt, awards<>'', shotCnt>0, (EditionsCount > 1) or (VideoFileName <>''), PosterCnt>0, TrailerCnt>0, description <> '', ConnectionsCnt>0);
	//close tab background
	all := all + '</div></td></tr></table>';
	
	//shots from the movie
	AdditionalSpace := 0;
	ShowScreenshots := False;
	MaxShots := RegReadInteger('ShotsCnt', 5);
	if (ActiveTab = 1) and (MaxShots > 0) then begin
		showScreenshots := True;
		i := GetHTMLWidth - LeftColumnWidth - ScreenshotWidth;
		if (i < DataArea) then
			showScreenshots := False;
	end;
	
	ScreenshotTotalHeight := 0;
	if ShowScreenshots then begin
		AdditionalSpace := ScreenshotWidth + NormalImageBorders;
		s := '';
		if (RegReadInteger('ShowCoversOnTheRight', 1) = 1) then
			s := '2';
		if (RegReadInteger('ShowPostersOnTheRight', 0) = 1) then begin
			if s<>'' then
				s := s + ',';
			s := s + '4';			
		end;
		if (RegReadInteger('ShowBackdropsOnTheRight', 1) = 1) then begin
			if s<>'' then
				s := s + ',';
			s := s + '7';
		end;
		if (RegReadInteger('ShowShotsOnTheRight', 1) = 1) then begin
			if s<>'' then
				s := s + ',';
			s := s + '3';
		end;
		with sl do begin
			Clear;
			Add('select path, i.code as code, mode, width, height from images i');
			Add('inner join images_modes im on i.mode=im.code');
			Add(format('where movie=%d', [MovieCode]));
			Add(format('and mode in (%s)', [s]));
  		Add('order by im.sort_order, i.sort_order');        
		end;
		RecordCount:=ExecuteSQL(sl.text);
		j := 0;
		//if there are other pictures than the main cover, show them according to the settings
		if ((fl or (GetIntegerField('mode') <> 1)) and (RecordCount>0)) or (RecordCount>1) then begin
			all := all + '<div class="shot-space">';
			if RecordCount < MaxShots then
				MaxShots := RecordCount;
			ScreenshotTotalHeight := ScreenshotTotalHeight + ScreenshotPadding div 2;
			for i:=1 to MaxShots do begin
				//skip the main cover
				if (RegReadInteger('OnlyShots', 1) <> 1) and (GetIntegerField('mode') = 1) and (j = 0) then
					j := 1
				else
					if (MyFileExists(ImagesPath+GetStringField('path'))) then begin
						FileName := GetImageFileName(GetStringField('path'), ThumbsScreenshots, '', ScreenshotWidth, 0);
						all:=all+'<div class="shots"><div><a class="pic" '+format('href="ShowImage:%d"><img style="width: %dpx" border="0" src="%s"></a></div></div>', [GetIntegerField('code'), ScreenshotWidth, FileName]);
						ScreenshotTotalHeight := ScreenshotTotalHeight + Round(GetIntegerField('height') * (ScreenshotWidth / GetIntegerField('width'))) + ScreenshotPadding div 2;
					end;
				GetNextRecord;
			end;
			if RecordCount > MaxShots then begin
				all:=all+format('<div class="arrow-down"><a class="pic" href="userref:110,%d"><img border="0" alt="%s" src="%sarrow-down.gif"></a></div>', [MovieCode, GetLangStr(1411), ImgPath]);
				ScreenshotTotalHeight := ScreenshotTotalHeight + 30; //arrow down height
			end;
			all := all + '</div>';
		end; //if
	end;
	
	if not (ActiveTab in [2, 6, 7]) then begin
		//pictures
		with sl do begin
			Clear;
			Add('select path, code from images');
			Add(format('where movie=%d and mode=1', [MovieCode]));
  		Add('order by sort_order');      
		end;
		RecordCount:=ExecuteSQL(sl.text);
		all:=all+Format('<div class="cover-space" style="font-size: %dpt;">', [BasicFontSize + BiggerModifier]);
		fl := False;
		if RecordCount>0 then begin
			if (MyFileExists(ImagesPath+GetStringField('path'))) then begin
    			FileName := GetImageFileName(GetStringField('path'), ThumbsCovers, '', MainCoverWidth, 0);
				all:=all+'<div style="padding: 3px;"><a class="pic"'+format(' href="ShowImage:%d"><img style="width: %dpx;" border="0" src="%s"></a></div>',
  	          [GetIntegerField('code'), MainCoverWidth, FileName]);
			  fl := True;
	  		end;
		end;
		if not fl then begin
			FileName:=ImgPath+'no-cover.jpg';
			if (MyFileExists(FileName)) then
				all:=all+format('<div style="padding: 3px;"><img class="cover-image" border="0" src="%s"></div>', [FileName]);
		end;
		
		//imdb rating
		if IMDBRating <> 0 then begin
			all := all + '<div style="vertical-align: middle; font-weight: bold;"><img src="' + GetProperPath(ImgPath + 'tag-icon.gif') + '"/>&nbsp;' + Format ('IMDB:&nbsp;%0.1f</div>', [IMDBRating]);
		end;
		
		//my rating
		i := RegReadInteger('ShowRating', 1);
		if i=1 then begin
			all := all + '<hr class="line-separator">';
			all := all + '<div style="vertical-align: middle; color: #666666; margin-bottom: 5px;">' + Format('%s:</div>', [GetLangStr(298)]);
			all := all + '<div>' + rate + '</div>';
		end;
		
		//awards
		if FullAwardsText <> '' then begin
			s2 := '';
			temp := LowerCase(FullAwardsText);
			i := Pos('<br>', temp);
			//remove the general description for awards received from kinopoisk
			s := copy(temp, 1, i-1);
			if (Pos('.', s) > 5) then
				delete(temp, 1, i+3);
			sl.LoadFromFile(PicturesPath + 'awards\awards.txt');
			for i := 0 to sl.Count - 1 do begin
				name := sl.Names[i];
				j := Pos(':', name);
				status := '';
				ends_with := '';
				if j > 0 then begin
					status := LowerCase(copy(name, j+1, length(name)-j));
					delete(name, j, length(name)-j+1);
					j := Pos(':', status);
					if j > 0 then begin
						ends_with := copy(status, j+1, length(status)-j);
						delete(status, j, length(status)-j+1);
					end;
				end;
				j := Pos(LowerCase(name), temp);
				s := '';
				if j > 0 then begin
					k := MyPos(ends_with, temp, j+1);
					if k = 0 then
						k := Length(temp);
					s := copy(temp, j, k-j);
				end;
				if Pos('<br>'+ status, s) > 0 then
					s2 := s2 + '<a class="pic" href="userref:135,' + name + '"><img border="0" alt="'+ name + '" src="' + PicturesPath + 'awards\' + sl.Values[sl.Names[i]] + '"></a>';
			end;
			if s2 <> '' then
				all := all + '<hr class="line-separator"><div>' + s2 + '</div>';
		end;
	  
		//site links
		with sl do begin
			Clear;
			Add('select distinct mc.code, mc.site, mc.script, mc.rating, p.* 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, mc.script');
		end;
		RecordCount:=ExecuteSQL(sl.text);
			
		for i:=1 to RecordCount do begin
			site:=GetStringField('mc.script');
			url:=GetStringField('mc.site');
			if (site <> 'trailer') and (url <> '') then begin
				postfix:=GetStringField('p.postfix');
				all := all+'<hr class="line-separator"><div>';
				if postfix<>'' then
					url:=url+postfix;
				if site='buy' then begin
					if Pos('amazon', url)>0 then
						all:=all+'<a class="pic" alt="Buy at Amazon"  href="link:http://www.movienizer.com/redirect/'+url+'">'+format('<img src="%samazon.gif" border="0"></a> ', [PicturesPath])
					else if Pos('ozon', url)> 0 then
						all := all + '<a class="pic" alt="Купить на озоне"  href="link:http://www.movienizer.com/redirect/'+url+'">'+format('<img src="%sozon.gif" border="0"></a> ', [PicturesPath])
					else
						all:=all+format(GetLangStr(375), ['http://www.movienizer.com/redirect/'+url, movie])+' ';
				end
				else begin
					s:=GetStringField('p.picture');
					if s='' then
					all:=all+'<a href="link:http://www.movienizer.com/redirect/'+url+format('">%s</a> ', [site])
					else
						all:=all+'<a class="pic" href="link:http://www.movienizer.com/redirect/'+url+'">'+format('<img src="%s%s" border="0"></a> ', [PicturesPath, s]);
				end;
				all := all + '</div>';
				i := RegReadInteger('ShowSiteRating', 1);
				if i=1 then begin
					SiteRating:=GetFloatField('mc.rating');
					if (SiteRating>0) and (site<>'imdb') then
						all := all + format('<div style="font-weight: bold;">%s: %f</div>', [GetLangStr(75),SiteRating]);
				end;
			end;
			GetNextRecord;
		end; //for
		
		if RegReadInteger('ShowCodecLogos', 1) = 1 then begin
			//media format logo
			with sl do begin
				Clear;
				Add('select m.name, e.filename from editions e');
				Add('left outer join manuals m on m.code=e.media_format');
				Add(format('where e.movie=%d', [MovieCode]));
				Add('order by e.media_format');
			end;
			RecordCount:=ExecuteSQL(sl.text);
			prev_media_format := 'dummy';
			s := '';
			for i:=1 to RecordCount do begin
				media_format := LowerCase(GetStringField('m.name'));
				if (prev_media_format <> media_format) then begin
					if (media_format = 'blu-ray') then begin
						s := s + format('<hr class="line-separator"><div><img alt="Blu-Ray" src="%sbd-logo-medium.gif"></div>', [ImgPath]);
					end;
					if (media_format = 'dvd') then begin
						s := s + format('<hr class="line-separator"><div><img alt="DVD" src="%sdvd-logo-medium.gif"></div>', [ImgPath]);
					end;
					if (media_format = 'hd dvd') then begin
						s := s + format('<hr class="line-separator"><div><img alt="HD DVD" src="%shddvd-logo-medium.gif"></div>', [ImgPath]);
					end;
					if (Pos('mkv', media_format)>0) or 
					(Pos('.mkv', LowerCase(GetStringField('e.filename')))>0) then begin
						s := s + format('<hr class="line-separator"><div><img alt="MKV Matroska" src="%smkv-logo-medium.gif"></div>', [ImgPath]);
					end;
					prev_media_format := media_format;
				end;
				GetNextRecord;
			end;
			//video codec logo (divx, xvid)
			with sl do begin
				Clear;
				Add('select m.name from editions e');
				Add('left outer join manuals m on m.code=e.video_codec');
				Add(format('where e.movie=%d', [MovieCode]));
				Add('order by e.video_codec');
			end;
			RecordCount:=ExecuteSQL(sl.text);
			prev_media_format := '';
			for i:=1 to RecordCount do begin
				media_format := LowerCase(GetStringField('m.name'));
				if (media_format <> prev_media_format) then begin
					if (Pos('divx', media_format)>0) then begin
						s := s + format('<hr class="line-separator"><div><img alt="DivX" src="%sdivx-logo-medium.gif"></div>', [ImgPath]);
					end;
					if (Pos('xvid', media_format)>0) then begin
						s := s + format('<hr class="line-separator"><div><img alt="XviD" src="%sxvid-logo-medium.gif"></div>', [ImgPath]);
					end;
					prev_media_format := media_format;
				end;
				GetNextRecord;
			end;
			all := all + s;
		end;
		
		all := all + '<div class="free-space-bottom" style="background-image: url(' + GetProperPath(ImgPath + 'bottom-shadow.gif') +')"></div></div>';
		
	end; //if ActiveTab <> 2
		
		
	all := all + Format('<div style="font-size: %dpt; line-height: %dpx; text-align: center;">', [BasicFontSize, LineSpace]) + RemainingTabs + '</div>';
	//actors
	if ActiveTab = 4 then begin
		all := all + GetCast(MovieCode);
	end;
	
	//Shots
	if ActiveTab = 2 then
		all := all + GetShots(MovieCode, 3, 'movie', 7, 5);
	//Posters
	if ActiveTab = 7 then
		all := all + GetShots(MovieCode, 4, 'movie');
	
	if ActiveTab = 1 then begin	
		if FixedContentsWidth then
			all := all + '<table class="envelope"><tr><td>';
		all := all + Format('<table class="names-values" style="font-size: %dpt; line-height: %dpx;">', [BasicFontSize + BiggerModifier, LineSpace]);
		ThisBlockCnt := 0;
		//Tagline
		if TagLine <> '' then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all := all + '<tr><td class="small-table-name"' + border + Format('>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"', [GetLangStr(3406)])+ border + '>"' + TagLine + '"</td></tr>';
		end;
		
		//sequence
		with sl do begin
			Clear;
			Add('select m.code, m.name, mov.series_nom from movies mov');
			Add('join manuals m on m.code=mov.series'); 
			Add(format('where mov.code=%d', [MovieCode]));
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all := all + '<tr><td class="small-table-name"' + border + Format('>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"', [GetLangStr(20271)])+ border + '>';
			all := all + Format('<a href="sequence:%d">%s</a> %s%d', [GetIntegerField('m.code'), GetStringField('m.name'), GetLangStr(529), GetIntegerField('mov.series_nom')]);
			all:=all+'</td></tr>';
		end;
		
		//media type
		if MediaType > 0 then begin
			with sl do begin
				Clear;
				Add('select * from manuals');
				Add(Format('where code=%d', [MediaType]));
			end;
			RecordCount := ExecuteSQL(sl.text);
			if RecordCount > 0 then begin
				ThisBlockCnt := ThisBlockCnt + 1;
				if (ThisBlockCnt mod 2 = 1) then
					border := bckgrnd
				else
					border := '';
				all := all + Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(173), border]);
				all := all + Format('<a href="media_type:%d">%s</a></td></tr>', [GetIntegerField('code'), GetStringField('name')]);
			end;
		end;
		
		//genres
		with sl do begin
			Clear;
			Add('select m.code, m.name 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]));
			Add('order by m.name');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			//'Genres: '
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all + '<tr><td class="small-table-name"' + border + Format('>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"', [GetLangStr(72)])+ border + '>';
			for i:=1 to RecordCount do begin
				if i>1 then
					all := all + ' / ';
				all:=all+format('<a href="genre:%d">%s</a>', [GetIntegerField('m.code'), GetStringField('m.name')]);
			GetNextRecord;
			end;
			all:=all+'</td></tr>';
		end;
	  
		//year
		if year<>'' then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all+format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s><a href="year:%s">%s</a></td></tr>', [border, GetLangStr(169), border, year, year]);
		end;
		
		//countries
		with sl do begin
			Clear;
			Add('select m.code, m.name 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]));
			Add('order by m.name');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			//'Countries: '
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all := all + Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(73), border]);
			country := '';
			for i:=1 to RecordCount do begin
				country:=country+format('<a href="country:%d">%s</a> / ', [GetIntegerField('m.code'), GetStringField('m.name')]);
				GetNextRecord;
			end;
			country:=copy(country, 1, length(country)-3);
			all:=all + country + '</td></tr>';
		end;
	
	
		//duration
		hours := duration div 60;
		minutes := duration mod 60;
		s := '';
		if hours>0 then
			s:=format(' (%d:%.2d)', [hours, minutes]);
		if duration>0 then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all+format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>%d %s%s</td></tr>', [border, GetLangStr(705), border, duration, GetLangStr(706), s]);
		end;

		//mpaa
		mpaa:='';
		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
				ThisBlockCnt := ThisBlockCnt + 1;
				if (ThisBlockCnt mod 2 = 1) then
					border := bckgrnd
				else
					border := '';
				s:=Format('<a href="mpaa:%d">%s</a>', [mpaa_code, GetStringField('name')]);
				mpaa:=s;
				if mpaa_desc<>'' then
					mpaa:=mpaa+' '+mpaa_desc;
				all := all + Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>%s</td></tr>', [border, GetLangStr(708), border, mpaa]);
			end;
		end;
	
		//studios
		studios:='';
		with sl do begin
			Clear;
			Add('select m.code, m.name 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]));
			Add('order by m.name');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			studios := format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(493), border]);
			for i:=1 to RecordCount do begin
				studios := studios + format('<a href="studio:%d">%s</a> / ', [GetIntegerField('m.code'), GetStringField('m.name')]);
				GetNextRecord;
			end;
			studios := copy(studios, 1, length(studios)-3);
			all := all + studios + '</td></tr>';
		end;

		//directors
		s := '';
		with sl do begin
			Clear;
			Add('select distinct p.code, p.name, p.in_collection from data d');
			Add('inner join persons p on p.code=d.person');
			Add(format('where d.movie=%d and d.mode=1', [MovieCode]));
			Add('order by d.sort_order');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			//'Directors: ';
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all + Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(66), border]);
			i:=1;
			while i<=RecordCount do begin
				if GetIntegerField('p.in_collection')=1 then
					img:=format('<img src="%sperson.gif" align="absmiddle" style="margin-right: 5px;">', [ImgPath])
				else
					img:='';
				s:=s+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
				if (i=5) and (i<RecordCount) and not FullPersons then
					i:=RecordCount;          	
				i:=i+1;
				GetNextRecord;
			end; //while
			s:=copy(s, 1, length(s)-2);
			if (RecordCount>=6) and not FullPersons then
				s:=s+format(GetLangStr(1251), [MovieCode]);
			all:=all+s+'</td></tr>';
		end; //if

		//writers
		s := '';
		with sl do begin
			Clear;
			Add('select distinct p.code, p.name, p.in_collection from data d');
			Add('inner join persons p on p.code=d.person');
			Add(format('where d.movie=%d and d.mode=2', [MovieCode]));
			Add('order by d.sort_order');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			//'Writers: '
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all + Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(3408), border]);
			i:=1;
			while i<=RecordCount do begin
				if GetIntegerField('p.in_collection')=1 then
					img:=format('<img src="%sperson.gif" align="absmiddle" style="margin-right: 5px;">', [ImgPath])
				else
					img:='';
				s:=s+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
				if (i=5) and (i<RecordCount) and not FullPersons then
					i:=RecordCount;          	
				i:=i+1;
				GetNextRecord;
			end;
			s:=copy(s, 1, length(s)-2);
			if (RecordCount>=6) and not FullPersons then
				s:=s+format(GetLangStr(1251), [MovieCode]);
			all:=all+s+'</td></tr>';
		end;

		//composers
		s := '';
		with sl do begin
			Clear;
			Add('select distinct p.code, p.name, p.in_collection from data d');
			Add('inner join persons p on p.code=d.person');
			Add(format('where d.movie=%d and d.mode=4', [MovieCode]));
			Add('order by d.sort_order');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount>0 then begin
			//'Composers: '
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			all:=all+Format('<tr><td class="small-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="small-table-value"%s>', [border, GetLangStr(491), border]);
			i:=1;
			while i<=RecordCount do begin
				if GetIntegerField('p.in_collection')=1 then
					img:=format('<img src="%sperson.gif" align="absmiddle" style="margin-right: 5px;">', [ImgPath])
				else
					img:='';
				s:=s+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, ';
				if (i=5) and (i<RecordCount) and not FullPersons then
					i:=RecordCount;          	
				i:=i+1;
				GetNextRecord;
			end;
			s:=copy(s, 1, length(s)-2);
			if (RecordCount>=6) and not FullPersons then
				s:=s+format(GetLangStr(1251), [MovieCode]);
			all:=all+s+'</td></tr>';
		end;
		all := all + '</table>';
	end;

	if (ActiveTab = 1) then begin
		//actors
		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: '
			all := all + Format('<table class="description" style="font-size: %dpt; line-height: %dpx;"><tr><td>', [BasicFontSize + BiggerModifier, LineSpace]);
			i := 1;
			j := 1;
			s:='';
			while i<=RecordCount do begin
				if GetIntegerField('p.in_collection')=1 then
					img:=format('<img src="%sperson.gif" align="absmiddle" style="margin-right: 5px;">', [ImgPath])
				else
					img:='';
				character:=GetStringField('c.name');
				if character='' then
					s:=s+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+'</a>, '
				else
					s:=s+img+format('<a href="person:%d">', [GetIntegerField('p.code')])+GetStringField('p.name')+format('</a> (%s), ', [character]);
				if (j>=10) and (i<RecordCount) and not FullPersons then
					i:=RecordCount;
				j := j + 1;
				i:=i+1;
				GetNextRecord;
			end;
			s:=copy(s, 1, length(s)-2);
			if (RecordCount>=11) and not FullPersons then
				s:=s+format(GetLangStr(1251), [MovieCode]);
			all:=all+s+'</td></tr></table>';
		end;
		//all := all + '<div style="clear: left"></div>';
	end;
	if (ActiveTab = 1) or (ActiveTab = 10) then begin  
		//description
		if description<>'' then begin
			all:=all+Format('<table class="description" style="font-size: %dpt; line-height: %dpx;"><tr><td>', [BasicFontSize + BiggerModifier, LineSpace]);
			all := all + '<hr style="margin: 0;">';
			all := all + '<p>'+description+'</p>';
			all := all + '<hr style="margin: 0;">';
			all := all + '</td></tr></table>';
		end;
	end;

	if (ActiveTab = 1) then begin
		if not FixedContentsWidth then
			all := all + '<div style="clear:left;"></div><table class="envelope"><tr><td>';
		//photos of people
		temp := '';
		if (RegReadInteger('HidePhotosCovers', 0) = 0) then begin
			LastCode:=0;
			with sl do begin
				Clear;
				Add('select i.path as path, i.width, i.height, i.person as code, i.mode, p.name, p.birth_date, c.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');
				Add('left outer join characters c on c.person=d.person and c.movie=d.movie');
				Add(format('where d.movie=%d', [MovieCode]));
				Add('order by d.mode, d.sort_order, i.person, i.sort_order');
			end;
			RecordCount:=ExecuteSQL(sl.text);

			page_width := GetHTMLWidth - WholePageBorder;
			if FixedContentsWidth then
				page_width := page_width - LeftColumnWidth;
			i := ScreenshotAreaHeight;
			if page_width > WidePage then
				i := i - 100;
			if ScreenshotTotalHeight > i then
				page_width := page_width - ScreenshotWidth - ScreenshotPadding;
			if RecordCount>0 then begin
				TempList := TStringList.Create;
				all:=all+'<table class="photos"><tr>';
				j := 0;
				kol := 0;
				i := 0;
				fl := True;
				while (i < RecordCount) and fl do begin
					//only photos! no custom images are allowed
					if (GetIntegerField('i.mode') = 6) then begin
						if (TempList.IndexOf(IntToStr(GetIntegerField('code'))) < 0) then begin
							kol := kol + 1;
							TempList.Add(IntToStr(GetIntegerField('code')));
							PicHeight := GetIntegerField('i.height');
							if PicHeight > 0 then
								PicWidth := Round(GetIntegerField('i.width') * (SmallCoverHeight / PicHeight)) + BigImageBorders
							else
								PicWidth := StandardCoverWidth + BigImageBorders;
							if PicWidth < StandardCoverWidth then
								PicWidth := StandardCoverWidth + BigImageBorders;

							age := '';
							if (YearsBetween(GetStringField('p.birth_date'), year) > 0) then
								age := IntToStr(YearsBetween(GetStringField('p.birth_date'), year));

							if (MyFileExists(ImagesPath+GetStringField('path'))) then begin
								temp := temp + '<td class="one-photo">';
								trunc_name := TruncateName(GetStringField('p.name'), MaxNameLength);
								trunc_character := TruncateName(GetStringField('c.name'), MaxCharacterNameLength);

								FileName := GetImageFileName(GetStringField('path'), ThumbsMoviePhotos, 'nophoto.jpg', 0, SmallCoverHeight);
								temp:=temp+format('<a class="pic" href="person:%d"><img style="height: %dpx" src="%s" border="0"></a><p><a href="person:%d">%s</a></p>', [GetIntegerField('code'), SmallCoverHeight, FileName, GetIntegerField('code'), trunc_name]);
							//end 2.05.11
								
								
								if age <> '' then
									temp := temp + '<p style="color: #666666;">' + Format(GetLangStr(1410), [age]) + '</p>';
								if trunc_character <> '' then
									temp := temp + '<p>' + trunc_character + '</p>';
								temp := temp + '</td>';
								page_width := page_width - PicWidth;
								if (page_width >= 0) then begin
									all := all + temp;
									j := j + 1;
									temp := '';
									page_width_rest := page_width;
								end
								else
									fl := False;
							end;//if MyFileExists
						end;
					end;
					GetNextRecord;
					i := i + 1;
				end;//while
				//all := all + '<td colspan="' + IntToStr(kol-j) + '">';
				all := all + '<td></td>';
				all := all + '</tr></table>';
				TempList.Free;
			end;//if recordcount
		end;


		//custom fields
		cust:='';
		PrevBlockCnt:=0;
		for i:=1 to 4 do begin
			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
					PrevBlockCnt:=PrevBlockCnt+1;
					if (PrevBlockCnt mod 2 = 1) then
						border := bckgrnd
					else border := '';
					cust:=cust+Format('<tr><td class="big-table-name"%s>', [border])+format(GetLangStr(539+i), [s])+format('</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border])+format('<a href="custom%d:%d">', [i, custom[i]])+GetStringField('name')+'</a></td></tr>';
				end;
			end;
		end;
	
		//custom list1
		with sl do begin
			Clear;
			Add('select m.code, m.name 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
			PrevBlockCnt:=PrevBlockCnt+1;
			if (PrevBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			cust:=cust+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(544), border]);
			for i:=1 to RecordCount do begin
				cust:=cust+format('<a href="custom5:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);
				GetNextRecord;
			end;
			cust:=copy(cust, 1, length(cust)-2);
			cust:=cust+'</td></tr>';
		end;

		//custom list2
		with sl do begin
			Clear;
			Add('select m.code, m.name 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
			PrevBlockCnt:=PrevBlockCnt+1;
			if (PrevBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			cust:=cust+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(545), border]);
			for i:=1 to RecordCount do begin
				cust:=cust+format('<a href="custom6:%d">%s</a>, ', [GetIntegerField('m.code'), GetStringField('m.name')]);
				GetNextRecord;
			end;
			cust:=copy(cust, 1, length(cust)-2);
			cust:=cust+'</td></tr>';
		end;
		if cust <> '' then
			all:=all+Format('<table class="names-values" style="font-size: %dpt; line-height: %dpx;">', [BasicFontSize + BiggerModifier, LineSpace])+cust+'</table>';
	end; //if ActiveTab = 1

	
	//Trailers
	if (ActiveTab = 9) then begin
		with sl do begin
			Clear;
			Add('select i.path, i.width, i.height, mc.site from movies_codes mc');
			Add('left join images i');
			Add('on i.code=mc.code');
			Add(format('where mc.movie=%d and mc.script=''trailer''', [MovieCode]));
			Add('order by i.sort_order')
		end;
		RecordCount := ExecuteSQL(sl.text);
		page_width := GetHTMLWidth - LeftColumnWidth;
		all := all + '<table style="width: 100%;"><tr><td><table><tr>';
		temp := '';
		for i := 1 to RecordCount do begin
			PicWidth := GetIntegerField('i.width');
			if PicWidth = 0 then
				PicWidth := DefaultTrailerWidth;
			PicWidth := PicWidth + NormalImageBorders;
			FileName := ImagesPath + GetStringField('i.path');
			if not (MyFileExists(FileName)) then
				FileName := ImgPath + 'trailer.gif';
			url := GetStringField('mc.site');
			page_width := page_width - PicWidth;
			if page_width < 0 then begin
				temp := temp + '</tr></table><table><tr>';
				page_width := GetHTMLWidth - LeftColumnWidth - PicWidth;
			end;
			if Pos('http://', url) > 0 then
				url := '<a class="pic" href="link:http://www.movienizer.com/redirect/'+url+'">'
			else
				url := '<a class="pic" href="play:' + url + '">';
			temp := temp + '<td><div style="width: 5px; vertical-align: middle;">'+url+format('<img class="trailer" src="%s"></a></div></td>', [FileName]);	
			GetNextRecord;
		end;
		if temp <> '' then
			all := all + temp + '</tr></table></td></tr></table>';
	end;
	
	//movie connections
	if (ActiveTab = 11) then begin
		//movie series
		if MovieSeriesNumber > 0 then begin
			temp := '<table style="width: 100%;"><tr><td>';
			//previous movies
			with sl do begin
				Clear;
				Add('SELECT m.title, m.code, m.year, m.in_collection FROM Movies m');
				Add(Format('WHERE m.series=%d AND m.series_nom<%d', [MovieSeries, MovieSeriesNumber]));
				Add('ORDER BY m.series_nom');
			end;
			RecordCount := ExecuteSQL(sl.text);
			if RecordCount > 0 then begin
				temp := temp + Format('<p class="header" style="font-size: %dpt;">', [BasicFontSize + SubHeaderModifier])+GetLangStr(3907)+':';
				temp := temp + Format('</p><div class="filmography" style="font-size: %dpt; line-height: %dpx;"><ol>', [BasicFontSize + BiggerModifier, LineSpace]);
				i := 1;
				while i <= RecordCount do begin
					LinkYearStr := GetStringField('m.year');
					if (LinkYearStr <> '') then
						LinkYearStr := ' (' + LinkYearStr + ')';
					if (GetIntegerField('m.in_collection')=1) then
						img:=format('<img src="%sin-collection-small.gif" align="absmiddle">&nbsp;', [ImgPath])
					else
						img := '';
					temp := temp + '<li>' + img + Format('<a href="movie:%d">', [GetIntegerField('m.code')]) + GetStringField('m.title')+ Format('</a>%s</li>', [LinkYearStr]);
					i := i + 1;
					GetNextRecord;
				end;
				temp := temp + '</ol></div>';
			end;
			//following movies
			with sl do begin
				Clear;
				Add('SELECT m.title, m.code, m.year, m.in_collection FROM Movies m');
				Add(Format('WHERE m.series=%d AND m.series_nom>%d', [MovieSeries, MovieSeriesNumber]));
				Add('ORDER BY m.series_nom');
			end;
			RecordCount := ExecuteSQL(sl.text);
			if RecordCount > 0 then begin
				temp := temp + Format('<p class="header" style="font-size: %dpt;">', [BasicFontSize + SubHeaderModifier])+GetLangStr(3908)+':';
				temp := temp + Format('</p><div class="filmography" style="font-size: %dpt; line-height: %dpx;"><ol>', [BasicFontSize + BiggerModifier, LineSpace]);
				i := 1;
				while i <= RecordCount do begin
					LinkYearStr := GetStringField('m.year');
					if (LinkYearStr <> '') then
						LinkYearStr := ' (' + LinkYearStr + ')';
					if (GetIntegerField('m.in_collection')=1) then
						img:=format('<img src="%sin-collection-small.gif" align="absmiddle">&nbsp;', [ImgPath])
					else
						img := '';
					temp := temp + '<li>' + img + Format('<a href="movie:%d">', [GetIntegerField('m.code')]) + GetStringField('m.title')+ Format('</a>%s</li>', [LinkYearStr]);
					i := i + 1;
					GetNextRecord;
				end;
				temp := temp + '</ol></div>';
			end;
			temp := temp + '</td></tr></table>';
			all := all + temp;
		end;
		//other connections
		with sl do begin
			Clear;
			Add('SELECT ml.*, m.Code, m.title, m.year, m.in_collection FROM Movies_links ml');
			Add('LEFT JOIN Movies m ON m.code = ml.movie_secondary');
			Add(format('where ml.movie_primary=%d', [MovieCode]));
			Add('order by ml.link_status, m.Year');
		end;
		RecordCount:=ExecuteSQL(sl.text);
		temp := '';
		if RecordCount > 0 then begin
			OldLinkStatus := -1;
			i := 1;
			while i<=RecordCount do begin
				if (OldLinkStatus <> GetIntegerField('ml.link_status')) then begin
					if OldLinkStatus > -1 then
						temp := temp + '</ol></div>';
					OldLinkStatus := GetIntegerField('ml.link_status');
					case OldLinkStatus of
						2: LinkMovieStatusTitle := GetLangStr(3915);
						3: LinkMovieStatusTitle := GetLangStr(3916);
						4: LinkMovieStatusTitle := GetLangStr(3917);
						5: LinkMovieStatusTitle := GetLangStr(3918);
					end;
					temp := temp + Format('<p class="header" style="font-size: %dpt;">', [BasicFontSize + SubHeaderModifier])+LinkMovieStatusTitle+':';
					temp := temp + Format('</p><div class="filmography" style="font-size: %dpt; line-height: %dpx;"><ol>', [BasicFontSize + BiggerModifier, LineSpace]);
				end;
				LinkYearStr := GetStringField('m.year');
				if (LinkYearStr <> '') then
					LinkYearStr := ' (' + LinkYearStr + ')';
				if (GetIntegerField('m.in_collection')=1) then
					img:=format('<img src="%sin-collection-small.gif" align="absmiddle">&nbsp;', [ImgPath])
				else
					img := '';
				temp := temp + '<li>' + img + format('<a href="movie:%d">', [GetIntegerField('m.code')]) + GetStringField('m.Title') + Format('</a>%s</li>', [LinkYearStr]);
				i:=i+1;
				GetNextRecord;
			end;
			if temp <> '' then
				all := all + '<table style="width: 100%;"><tr><td>' + temp + '</ol></div></td></tr></table>';
		end;
	end; // end movie connections
		
    //editions
	if ((ActiveTab = 1) and 
	(((SeasonCnt = 0) and (RegReadInteger('ShowEditionsOnMainTab', 1) = 1)) or ((SeasonCnt > 0) and (RegReadInteger('ShowEditionsOfTVSeries', 0) = 1)))) 
	or (ActiveTab = 5) or (ActiveTab = 8) then begin
		with sl do begin
			Clear;
			Add('select e.code from editions e');
			Add('left outer join manuals m on m.code=e.edition and m.reference=21');
			Add(format('where e.movie=%d', [MovieCode]));
			Add('order by e.sort_order');
		end;
		EditionsCount:=ExecuteSQL(sl.text);

		for ie:=1 to EditionsCount do begin
			editions[ie]:=GetIntegerField('e.code');
			GetNextRecord;
		end;
		
		if EditionsCount > 0 then
			//all := all + '<table class="envelope-table"><tr><td>';

		for ie:=1 to EditionsCount do begin
			EditionCode:=editions[ie];
			//editions
			with sl do begin
				Clear;
				Add('select * from editions e');
				Add('left outer join manuals m on m.code=e.edition and m.reference=21');
				Add(format('where e.code=%d', [EditionCode]));
			end;
			ExecuteSQL(sl.text);

			ed:='';
	
			//video parameters
			VideoBitrate:=GetIntegerField('e.video_bitrate');
			filesize:=GetIntegerField('e.filesize');
			DiscLabel:=GetIntegerField('e.disc_label');
			disc_nom:=GetStringField('e.disc_nom');
			duration:=GetIntegerField('e.duration');
			barcode:=GetStringField('e.barcode');

			VideoStandard:=GetIntegerField('e.video_standard');
			ScreenRatio:=GetIntegerField('e.screen_ratio');
			resolution:=GetIntegerField('e.resolution');
			VideoCodec:=GetIntegerField('e.video_codec');
			MediaFormat:=GetIntegerField('e.media_format');
		
			EditionFeatures:=GetStringField('e.features');
			EditionComment:=GetStringField('e.comment');
			EditionCost:=GetFloatField('e.cost');
		
			if ((EditionsCount > 1) or (RegReadInteger('ShowEditions', 0) = 1) or (ActiveTab = 5) or (ActiveTab=8)) then begin
				PrevBlockCnt:=-1;
				VideoFileName := GetStringField('e.filename');
				VideoFileFolder := VideoFileName;
				while (length(VideoFileFolder)>0) and (pos(VideoFileFolder[length(VideoFileFolder)],'/\')=0) do delete(VideoFileFolder,length(VideoFileFolder),1);
				ed:=ed + Format('<p class="header" style="font-size: %dpt;">', [BasicFontSize + SubHeaderModifier]);
				if VideoFileFolder<>'' then
					ed:=ed+format('&nbsp;<a class="pic" href="explore:%s">', [VideoFileName])+format('<img src="%sfolder.png" align="absmiddle" border="0" alt="%s"></a> ', [ImgPath, VideoFileName])+'&nbsp;';
				i := GetIntegerField('e.season');
				j := GetIntegerField('e.episode');
				if (i=0) and ((RegReadInteger('OnlyEditionName', 0) = 0) or (GetStringField('m.name') = '')) then
					ed:=ed+format(GetLangStr(1260), [ie])+'. ';
				if GetStringField('m.name')<>'' then
					ed:=ed+GetStringField('m.name')+'. ';
				barcode := GetStringField('e.barcode');
				if not ((i=0) and (j=0)) then begin
					ed:=ed+format(GetLangStr(1252), [i, j])+'. ';
					with sl do begin
						Clear;
						Add('SELECT title FROM episodes');
						Add(format('where movie=%d and season=%d and episode=%d', [MovieCode, i, j]));
					end;
					ExecuteSQL(sl.text);
					ed := ed+GetStringField('title')+'. ';
				end;
				if VideoFileName<>'' then
					ed:=ed+format('<a class="pic" href="play:%s">', [VideoFileName])+format('<img src="%splay.png" align="absmiddle" border="0" alt="%s"></a> ', [ImgPath, VideoFileName]);

			  
				if duration>0 then
					ed:=ed+Format('(%d:%0.2d) ', [duration div 60, duration mod 60]);
				if barcode<>'' then
					ed:=ed+GetLangStr(1259)+': '+barcode;
				ed := ed + '</p>';
			end;

			all:=all+ed;
	
	
			//editions
			if (ActiveTab = 1) or (ActiveTab = 5) then begin
				ed:=Format('<table class="names-values" style="font-size: %dpt; line-height: %dpx;">', [BasicFontSize + BiggerModifier, LineSpace]);
				ThisBlockCnt := 0;
		
				if (ActiveTab = 1) then begin
					//disc #
					if disc_nom<>'' then begin
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						ed:=ed+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%s</td></tr>', [border, GetLangStr(391), border, disc_nom]);
					end;
					//disc label
					if DiscLabel>0 then begin
						with sl do begin
							Clear;
							Add('select name from manuals');
							Add(format('where code=%d', [DiscLabel]));
						end;
						RecordCount:=ExecuteSQL(sl.text);
						if RecordCount>0 then begin
							ThisBlockCnt := ThisBlockCnt + 1;
							if (ThisBlockCnt mod 2 = 1) then
								border := bckgrnd
							else
								border := '';
							ed:=ed+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="disc_label:%d">%s</a></td></tr>', [border, GetLangStr(1000), border, DiscLabel, GetStringField('name')]);
						end;
					end;
					//edition cost
					if EditionCost > 0 then begin
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						ed:=ed+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%f</td></tr>', [border, GetLangStr(3350), border, EditionCost]);
					end;
		
					//loans
					border:='';
					with sl do begin
						Clear;
						Add('select l.location, m.name from loans l');
						Add('inner join manuals m on m.code=l.location');
						Add(format('where edition=%d', [EditionCode]));
						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
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						ed:=ed+Format('<tr><td class="big-table-name"%s>', [border])+GetLangStr(333)+format('</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="location:%d">%s</a></td></tr>', [border, GetIntegerField('l.location'), GetStringField('m.name')]);
					end;
				end;
			
				if (ed<>'') then
					all := all + ed;
		
				//parameters
				with sl do begin
					Clear;
					Add('select name, reference from manuals');
					Add(format('where code in (%d, %d, %d, %d, %d)', [VideoStandard, ScreenRatio, resolution, VideoCodec, MediaFormat]));
					Add('order by reference');
				end;
				RecordCount:=ExecuteSQL(sl.text);
				for i:=1 to RecordCount do begin
					if GetIntegerField('reference')=1 then begin
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						//Video standard
						all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%s</td></tr>', [border, GetLangStr(201), border, GetStringField('name')]);
					end
					else if GetIntegerField('reference')=2 then begin
						//media format
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="media_format:%d">%s</a></td></tr>', [border, GetLangStr(249), border, MediaFormat, GetStringField('name')]);
					end
					else if GetIntegerField('reference')=4 then begin
						//screen ratio
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="aspect_ratio:%d">%s</a></td></tr>', [border, GetLangStr(202), border, ScreenRatio, GetStringField('name')]);
					end
        	
					else if GetIntegerField('reference')=5 then begin
						//resolution
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="resolution:%d">%s</a></td></tr>', [border, GetLangStr(203), border, resolution, GetStringField('name')]);
					end

					else if GetIntegerField('reference')=19 then begin
						//video codec
						ThisBlockCnt := ThisBlockCnt + 1;
						if (ThisBlockCnt mod 2 = 1) then
							border := bckgrnd
						else
							border := '';
						all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s><a href="video_codec:%d">%s</a></td></tr>', [border, GetLangStr(571), border, VideoCodec, GetStringField('name')]);
					end;
					GetNextRecord;
				end;
				s2:='';
				//video bitrate
				if VideoBitrate>0 then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					s2:=format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%d</td></tr>', [border, GetLangStr(630), border, VideoBitrate]);
				end;
				//filesize
				if filesize>0 then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					s2:=s2+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%d</td></tr>', [border, GetLangStr(631), border, filesize]);
				end;
		
				//duration
				if (duration>0) and (EditionsCount=1) then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					s2:=s2+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%d %s', [border, GetLangStr(147), border, duration, GetLangStr(706)]);
					s2:=s2+format(' (%d:%.2d)</td></tr>', [duration div 60, duration mod 60]);
				end;
		
				all:=all+s2;

				//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', [EditionCode]));
				end;
				RecordCount:=ExecuteSQL(sl.text);
				if RecordCount>0 then begin
					//Audio tracks
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(254), border]);
					for i:=1 to RecordCount do begin
					    s2 := ' ' + GetStringField('am.codec');
						if (s2 <> '') then
						  S2 := s2 + ' ';
						if (GetIntegerField('am.channel') > 0) then
						  s2 := s2 + GetStringField('am.channel') + ' ch ';
						if (GetIntegerField('am.Bitrate') > 0) then
						  s2 := s2 + GetStringField('am.Bitrate') + ' kbps ';
						if (GetStringField('am.Short_Comment') <> '') then
						  s2 := s2 + GetStringField('am.Short_Comment') + ' ';
						if (s2<>'') then
							s2 := copy(s2, 1, length(s2) - 1);
						all:=all+format('<a href="audio_track:%d">%s</a>%s, ', [GetIntegerField('m.code'), GetStringField('m.name'), s2]);

						GetNextRecord;
					end;
					all:=copy(all, 1, length(all)-2);
					all := all + '</td></tr>';
				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', [EditionCode]));
				end;
				RecordCount:=ExecuteSQL(sl.text);
				if RecordCount>0 then begin
					//Subtitles
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					all:=all+Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(253), border]);
					for i:=1 to RecordCount do begin
						s2 := '';
						if (GetStringField('am.Short_Comment') <> '') then
							s2 := ' ' + Trim(GetStringField('am.Short_Comment'));
						all:=all+format('<a href="subtitle:%d">%s</a>%s, ', [GetIntegerField('m.code'), GetStringField('m.name'), s2]);
						GetNextRecord;
					end;
					all:=copy(all, 1, length(all)-2);
					all := all + '</td></tr>';
				end;
				//show filename
				if (RegReadInteger('ShowFileNames', 1) = 1) and (VideoFileName<>'') then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					all := all + Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(195), border]);
					all := all + Format('<a href="play:%s">%s</a></td></tr>', [VideoFileName, VideoFileName]);
				end;
				// DVD Features
				if EditionFeatures<>'' then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					all := all + Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(1537), border]);
					all := all + EditionFeatures + '</td></tr>';
				end;
		
				//Edition comments
				if EditionComment<>'' then begin
					ThisBlockCnt := ThisBlockCnt + 1;
					if (ThisBlockCnt mod 2 = 1) then
						border := bckgrnd
					else
						border := '';
					all := all + Format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>', [border, GetLangStr(163), border]);
					all := all + EditionComment + '</td></tr>';
				end;
				all := all + '</table>';
		
			end;
		end; //editions 
		//if EditionsCount > 0 then
			//all := all + '</td></tr></table>';
	end;

	//get season covers, save them into a string list
	SeasonCovers := TStringList.Create;
	if (ActiveTab = 6) or ((ActiveTab = 1) and (SeasonCnt > 0) and (RegReadInteger('ShowSeasonsOnGeneralTab', 0) = 0)) then begin
		with sl do begin
			Clear;
			Add('SELECT e.code, e.season, i.path, i.code, i.width, i.height FROM episodes e');
			Add('JOIN images i ON i.movie=e.movie AND i.season=e.season');
			Add(format('WHERE e.movie=%d AND i.mode=9', [MovieCode]));
			Add('ORDER BY e.season');
		end;
		RecordCount := ExecuteSQL(sl.text);
		LastCode := 0;
		for i := 1 to RecordCount do begin
			if (LastCode <> GetIntegerField('i.code')) then begin
				SeasonCovers.Add(IntToStr(GetIntegerField('e.season')) + '=' + GetStringField('i.path') + ':' + IntToStr(GetIntegerField('i.width')) + '<' + IntToStr(GetIntegerField('i.height')) + '>' + IntToStr(GetIntegerField('i.code')) + '?');
				LastCode := GetIntegerField('i.code');
			end;
			GetNextRecord;
		end;
	end;
	
	//seasons
	if (ActiveTab = 6) or ((RegReadInteger('ShowSeasonsOnGeneralTab', 0) = 1) and (ActiveTab = 1)) then begin
		
		seasons:='';
		kol:=0;
		with sl do begin
			Clear;
			Add('select e.season, e.episode, e.title, e.description, e.original_air_date, e.seen, e.code, e.rating, ed.filename, i.path, i.code from episodes e');
			Add('left outer join editions ed on ed.movie=e.movie and e.season=ed.season and e.episode=ed.episode');
			Add('left outer join images i on i.movie=e.movie and i.season=e.season and i.episode=e.episode');
		    if season = 0 then begin
				Add(format('where e.movie=%d', [MovieCode]));
				Add(' order by e.season, e.episode');
			end
			else begin
				Add(format('where e.movie=%d and e.season=%d', [MovieCode, season]));
				Add(' order by e.episode');
			end;
		end;
		RecordCount:=ExecuteSQL(sl.text);
		if RecordCount > 0 then begin
			//season navigation
			if SeasonCnt > 1 then begin
				seasons := seasons + '<table class="envelope"><tr><td>' + Format('<div class="header" style="font-size: %dpt;">', [BasicFontSize + SubheaderModifier]);
				seasons := seasons + '<div style="float: left;">' + GetLangStr(517) + '</div>';
				for i:=1 to SeasonCnt do begin
					s := '';
					seasons := seasons + '<div style="margin-left: 10px; margin-right: 10px; float: left;">';
					if i <> season then begin
						seasons := seasons + Format('<a href="userref:114,%d;%d">', [MovieCode, i]);
						s := '</a>';
					end;
					seasons := seasons + IntToStr(i) + s + '</div>';
				end;
				s := '';
				seasons := seasons + '<div style="margin-left: 10px; margin-right: 10px; float: left;">';
				if season <> 0 then begin
					seasons := seasons + Format('<a href="userref:114,%d;%d">', [MovieCode, 0]);
					s := '</a>';
				end;
				seasons := seasons + GetLangStr(40) + s + '</div>';
				seasons := seasons + '</div></td></tr></table>';
			end; //end season navigation
		
			seasons := seasons + '<table class="envelope" style="vertical-align: top;"><tr><td style="width: 10;">';
			//SeenList := TStringList.Create;
			UnseenList := TStringList.Create;
			UnseenEpisodes := '';
			for i:=1 to RecordCount do begin
				//check if it's already the next season
				if GetIntegerField('e.season')>kol then begin
					if kol > 0 then
						seasons := seasons + '</td></tr></table></td></tr><tr><td style="width: 10;">';
					kol:=GetIntegerField('e.season');
					ShortFilename := SeasonCovers.Values[IntToStr(kol)];
					if ShortFileName <> '' then begin
						s := GetStr(ShortFilename, '>', '?');
						j := Pos(':', ShortFilename);
						ShortFilename := copy(ShortFilename, 1, j-1);
						FileName := GetImageFileName(ShortFilename, ThumbsCovers, 'no-cover.jpg', MainCoverWidth, 0);
						seasons := seasons + '<div style="margin: 10; background-color: #fcfcfc; border: 1px solid #d8d8d8;"><div style="padding: 3px;"><a class="pic"' + format(' href="ShowImage:%s"><img style="width: %dpx" border="0" src="%s">', [s, MainCoverWidth, FileName]) + '</a></div></div>';
					end;
					seasons:=seasons+'</td><td>';
					seasons:=seasons+Format('<p class="season-header" style="font-size: %dpt;">', [BasicFontSize + SeasonHeaderModifier])+format(GetLangStr(514), [kol])+Format('</p><table class="description" style="font-size: %dpt;"><tr><td>', [BasicFontSize + BiggerModifier]);
				end;
				temp := '';
				if (GetIntegerField('e.seen')=1) then begin
					temp := format('<a class="pic" href="userref:150,%d;%d"><img src="%sepisode-seen.gif" border="0"></a> ', [GetIntegerField('e.code'), MovieCode, ImgPath]);
				end
				else begin
					UnseenList.Add('#' + IntToStr(GetIntegerField('e.code')) + '#');
					UnseenEpisodes := UnseenList.CommaText;
					temp := format('<a class="pic" href="userref:151,%d;%d"><img src="%sepisode-not-seen.gif" border="0"></a> ', [GetIntegerField('e.code'), MovieCode, ImgPath]);
				end;
				  fl := False;
				  if MyFileExists(ImagesPath+GetStringField('i.path')) then begin
					FileName := GetImageFileName(GetStringField('i.path'), ThumbsEpisodeCovers, '', EpisodeCoverWidth, 0);
					seasons := seasons + '<div class="episode-cover-space"><div class="episode-cover"><a class="pic" ' + Format('href="ShowImage:%d"><img border="0" style="margin: 0; width: %d;" src="%s">', [GetIntegerField('i.code'), EpisodeCoverWidth, Filename]) + '</a></div></div>';
					fl := True;
				  end;
				  seasons:=seasons+Format('<p class="episode-header" style="font-size: %dpt;">', [BasicFontSize + BiggerModifier])+temp+format(GetLangStr(518), [GetIntegerField('e.episode')])+'. '+GetStringField('e.title');
				  s:=GetStringField('e.original_air_date');
				  s:=SQLDate2Str(s);
				  if s<>'' then
					  seasons:=seasons+'. '+s;
					rating := GetIntegerField('e.rating');
					rate:='';
					for j:=1 to 10 do begin
						if j mod 2=1 then begin
							if j<=rating then
								rate:=rate+format('<a class="pic" href="userref:152,%d;%d;%d"><img src="%shalfstar-left.gif" border="0"></a>',  [GetIntegerField('e.code'), MovieCode, j, ImgPath])
							else
								rate:=rate+format('<a class="pic" href="userref:152,%d;%d;%d"><img src="%snot-halfstar-left.gif" border="0"></a>',  [GetIntegerField('e.code'), MovieCode, j, ImgPath])
						end
						else begin
							if j<=rating then
								rate:=rate+format('<a class="pic" href="userref:152,%d;%d;%d"><img src="%shalfstar-right.gif" border="0"></a>',  [GetIntegerField('e.code'), MovieCode, j, ImgPath])
							else
								rate:=rate+format('<a class="pic" href="userref:152,%d;%d;%d"><img src="%snot-halfstar-right.gif" border="0"></a>',  [GetIntegerField('e.code'), MovieCode, j, ImgPath])
						end;
					end;
				  if rate <> '' then
					seasons := seasons + '&nbsp;' + rate;
					  
				  if GetStringField('ed.filename')<>'' then
					seasons:=seasons+format('&nbsp;<a class="pic" href="play:%s">', [GetStringField('ed.filename')])+format('<img src="%splay.png" align="absmiddle" border="0"></a>', [ImgPath]);

				  seasons:=seasons+'</p>';
				  s := GetStringField('e.description');
				  s := ReplaceStr(s, #13#10, '<br>');
				  if s <> '' then
					seasons:=seasons+Format('<p style="font-size: %dpt; line-height: %dpx;">', [BasicFontSize + BiggerModifier, LineSpace]) + s + '</p>';
				  if fl then
					seasons := seasons + '<div style="clear: both;"></div><hr>';
				GetNextRecord;
			  end;
			if seasons <> '' then
				seasons := seasons + '</td></tr></table></td></tr></table>';
			all := all + seasons;
			//SeenList.Free;
			UnseenList.Free;
		end;
	end;
	
	//show season covers on the general tab
	if (ActiveTab = 1) and (SeasonCnt > 0) and (RegReadInteger('ShowSeasonsOnGeneralTab', 0) = 0) then begin
		seasons := '';
		kol := 0;
		page_width := GetHTMLWidth - WholePageBorder + SeasonCoverSpace div 2;
		if FixedContentsWidth then
			page_width := page_width - LeftColumnWidth;
		i := ScreenshotAreaHeight + 200;
		if (page_width > SuperWidePage) then
			i := i - 200;
		if ScreenshotTotalHeight > i then
			page_width := page_width - ScreenshotWidth - ScreenshotPadding;
		if SeasonCovers.Count > 0 then begin
			seasons := seasons + '<table><tr>';
			temp := '';
			page_width_copy := page_width;
			PrevPicWidth := 0;
			for i := 0 to SeasonCovers.Count - 1 do begin
				//link to season cover
				ShortFilename := GetStr(SeasonCovers[i], '=', ':');
				//picture width
				s := GetStr(SeasonCovers[i], ':', '<');
				//picture height
				s2 := GetStr(SeasonCovers[i], '<', '>');
				//season number
				s3 := SeasonCovers.Names[i];
				
				this_width := 0;
				this_height := 0;
				this_season := 0;
				try
					this_width := StrToInt(s);
					this_height := StrToInt(s2);
					this_season := StrToInt(s3);
				except
				end;
				PicHeight := this_height;
				if PicHeight > 0 then
					PicWidth := Round(this_width * (NoCoverHeight / PicHeight)) + BigImageBorders + SeasonCoverSpace
				else
					PicWidth := MainCoverWidth + BigImageBorders + SeasonCoverSpace;
				if PicWidth < MainCoverWidth then
					PicWidth := MainCoverWidth + BigImageBorders + SeasonCoverSpace;
				if (MyFileExists(ImagesPath+ShortFilename)) then begin
					//удаляем место слева для самой левой обложки
					if ((page_width_copy - PicWidth) < 0) or (page_width_copy = page_width) then
						i := 0
					else
						i := SeasonCoverSpace;
					temp := temp + Format('<td style="padding-left: %dpx; padding-right: 0px;">', [i]);
					temp := temp + '<div><a class="pic" ' + Format('href="userref:114,%d;%d">', [MovieCode, this_season]);
					FileName := GetImageFileName(ShortFilename, ThumbsCovers, 'no-cover.jpg', MainCoverWidth, 0);
					temp := temp + Format('<img style="width: %d; border: 0;" src="%s">', [MainCoverWidth, FileName]) + '</a></div>';
					temp := temp + Format('<div><p style="text-align: center; font-size: %dpt; padding: 0; margin: 0; padding-bottom: 10px;">', [BasicFontSize]) + format('<a href="userref:114,%d;%d">', [MovieCode, this_season]) + Format(GetLangStr(514), [this_season]) + '</a></p></div>';
					temp := temp + '</td>';
				end;
				page_width_copy := page_width_copy - PicWidth;
				PrevPicWidth := PicWidth;
				if page_width_copy < 0 then begin
					seasons := seasons + '</tr><tr>' + temp;
					page_width_copy := page_width - PicWidth;
				end
				else
					seasons := seasons + temp;
				temp := '';
			end;
			seasons := seasons + '</tr></table>';
			all := all + seasons;
		end
		else
			all := all + Format('<p class="header" style="font-size: %dpt;"><a href="userref:114,%d;0">%s %d</a></p>',[BasicFontSize + SubHeaderModifier, MovieCode, GetLangStr(517), SeasonCnt]);
	end;
	SeasonCovers.Free;
	
	if (ActiveTab = 1) then begin
		//dates
		s:='';
		ThisBlockCnt := 0;
		s := Format('<table class="names-values" style="font-size: %dpt; line-height: %dpx;">', [BasicFontSize + BiggerModifier, LineSpace]);
		if DateAdd<>'' then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			s:=s+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%s</td></tr>', [border, GetLangStr(670), border, SQLDate2Str(DateAdd)]);
		end;
		if DateUpdate<>'' then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			s:=s+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%s</td></tr>', [border, GetLangStr(671), border, SQLDate2Str(DateUpdate)]);
		end;
		if DateSeen<>'' then begin
			ThisBlockCnt := ThisBlockCnt + 1;
			if (ThisBlockCnt mod 2 = 1) then
				border := bckgrnd
			else
				border := '';
			s:=s+format('<tr><td class="big-table-name"%s>%s</td><!-- <td class="middle-cell"></td> --><td class="big-table-value"%s>%s</td></tr>', [border, GetLangStr(672), border, SQLDate2Str(DateSeen)]);
		end;
		all:=all+s+'</table>';



		//salary
		cust := '';
		if salary<>'' then
			cust:=cust+Format('<table class="description" style="font-size: %dpt; line-height: %dpx;"><tr><td>', [BasicFontSize + BiggerModifier, LineSpace])+salary+'</td></tr></table>';
		all := all + cust;

		//comments
		cust := '';
		if comment<>'' then begin
			if not FullComments and (length(comment)>DescriptionLength) then begin
				comment:=copy(comment, 1, DescriptionLength);
				comment:=comment+format(GetLangStr(1250), [MovieCode]);
			end;
			cust:=cust+Format('<table class="description" style="font-size: %dpt; line-height: %dpx;"><tr><td>', [BasicFontSize + BiggerModifier, LineSpace])+comment+'</td></tr></table>';
		end;
		
		all := all + cust;
	end;
	
	cust := '';
	
	//awards
	if ((ActiveTab = 1) and (RegReadInteger('ShowAwardsOnGeneralTab', 0) = 1)) 
	or (ActiveTab = 3) then begin
		if awards<>'' then begin
			sl.Clear;
			sl.LoadFromFile(PicturesPath + 'awards\awards.txt');
			//the general description from kinopoisk
			i := Pos('<br>', awards);
			temp := copy(awards, 1, i-1);
			if Pos('.', temp) > 5 then begin
				cust := temp + '<br>';
				delete(awards, 1, i+3);
			end;
			temp := '';
			while awards <> '' do begin
				i := Pos('<br><br>', awards) + 8;
				if i = 8 then
					i := Pos('<br> <br>', awards) + 9;
				if i = 9 then
					i := length(awards) + 1;
				//process each award separately
				s := copy(awards, 1, i-1);
				j := Pos(',', s);
				k := Pos('<br>', s);
				if (k < j) or (j = 0) then
					j := k;
				temp_name := copy(s, 1, j-1);
				j := Pos('"', temp_name);
				if j > 0 then
					temp_name := GetStr(temp_name, '"', '"');
				new_name := '<a href="userref:135,' + temp_name + '">' + temp_name + '</a>';
				s := ReplaceStr(s, temp_name, new_name);
				for k := 0 to sl.Count - 1 do begin
					name := sl.Names[k];
					s3 := sl.Values[sl.Names[k]];
					s3 := ReplaceStr(s3, '-mid.', '.');
					j := Pos(':', name);
					if j > 0 then
						delete(name, j, length(name)-j+1);
					j := Pos('">' + LowerCase(name), LowerCase(new_name));
					if (j > 0) then
						l := Pos(LowerCase(new_name), LowerCase(s))
					else
						l := Pos(LowerCase(name), LowerCase(s));
					if (l = 1) or ((l > 0) and (s[l-1] = '>')) then begin
						s2 := '<div style="clear:both"><div style="float: left; margin: 5px;"><a class="pic" href="userref:135,'+ name + '"><img border="0" alt="' + name + '" src="' + PicturesPath + 'awards\' + s3 + '"></a></div>';
						insert(s2, s, l);
					end;
				end;
				temp := temp + s;
				delete(awards, 1, i - 1);
			end;
			cust:=Format('<table class="description" style="font-size: %dpt; line-height: %dpx;"><tr><td>', [BasicFontSize + BiggerModifier, LineSpace])+cust+temp+'</td></tr></table>';
		end;
		all := all + cust;
	end;
	
	if (ActiveTab = 1) then
		all := all + '</td></tr></table>';
	
	all := all + '</div>';

	sl.Free;
	result:=all;
end;


begin

end.