program modern_program_part2;
                                                
uses 'modern_program_variables.pas';

function GetMovie5(MovieCode, season: integer; FullDesc, FullComments, FullPersons, FullAwards: boolean): string;
var
  sl, PreviousCodes: 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: 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: 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, MediaType: Integer;
  page_width, PicWidth, PicHeight, TrailerCnt, MovieSeries, MovieSeriesNumber, ConnectionsCnt: Integer;
  NoTrailerAdded: Boolean;
  trunc_name, trunc_character, front_cover_url: String;
  temp_name, new_name, name: string;
  OldLinkStatus: Integer;
  LinkYearStr: string;
  LinkMovieStr: string;
  LinkMovieStatusTitle: string;
  FullAwardsText, ends_with, status: string;
begin
	result:='';
  sl:=TStringList.Create;
  all:='';
  OtherRating := '';
  PreviousCodes := TStringList.Create;

  
  with sl do begin
	Clear;
    Add('select code from images');
    Add(format('where movie=%d and mode=3', [MovieCode]));
  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');
			comment:=GetStringField('comment');
			
	  FullAwardsText := awards;

			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');
      
      if flCollection=0 then
	      collection:=format('<a href="collection:%d"><img src="%snot_collection.gif" border="0" alt="%s"></a>',  [MovieCode, ImgPath, GetLangStr(326)])
      else
	      collection:=format('<a href="collection:%d"><img src="%scollection.gif" border="0" alt="%s"></a>',  [MovieCode, ImgPath, GetLangStr(325)]);


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

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

      if flForSale=0 then
	      sale:=format('<a href="sale:%d"><img src="%snot_sale.gif" border="0" alt="%s"></a>',  [MovieCode, ImgPath, GetLangStr(332)])
      else
	      sale:=format('<a href="sale:%d"><img src="%ssale.gif" border="0" alt="%s"></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 href="rating:%d"><img src="%sstar-left.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
					else
	    	  	rate:=rate+format('<a href="rating:%d"><img src="%snot-star-left.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
				end
				else begin
					if i<=rating then
		      	rate:=rate+format('<a href="rating:%d"><img src="%sstar-right.gif" align="absmiddle" border="0"></a>',  [i, ImgPath])
					else
	    	  	rate:=rate+format('<a href="rating:%d"><img src="%snot-star-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);
					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]));
      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;

	    all:=GetPatternTop;
		all:= all + '<p class="title">' + movie;
		if (OriginalTitle <> '') and (OriginalTitle <> movie) then
			all := all + '<font size="3"> <b>('+OriginalTitle+')</b></font>';
		all:= all + Format('</p></td><td class="icons"><table class="icons-container"><tr><td class="icons-border"><img src="%sicons-left.gif"></td><td class="icons-place">%s%s%s%s&nbsp;</td><td class="edit-link"><p><a href="UpdateMovie:%d">%s</a></p></td><td class="icons-border"><img src="%sicons-right.gif"></td></tr></table>', [ImgPath, collection, seen, wanted, sale, MovieCode, GetLangStr(304), ImgPath]) + ClosePatternTop;
		
	if (ActiveTab <> 2) and (ActiveTab <> 7) then begin
		
      //pictures
	  front_cover_url := '';
	  all := all + '<tr><td class="left"><table class="left-pane">';
      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+'<tr><td>';
      if RecordCount>0 then begin
		front_cover_url := GetStringField('path');
        if (MyFileExists(ImagesPath+GetStringField('path'))) then begin
    			FileName := GetImageFileName(GetStringField('path'), 'ThumbsCovers', '', MainCoverWidth, 0);
				all:=all+format('<div class="cover"><a href="ShowImage:%d"><img class="cover-image" src="%s"></a></div>',
  	          [GetIntegerField('code'), FileName]);
	  		end;
	  end
	  else begin
		FileName:=ImgPath+'no-cover.gif';
		if (MyFileExists(FileName)) then
			all:=all+format('<div class="cover"><img class="cover-image" src="%s"></div>', [FileName]);
	  end;

	  all:=all+'</td></tr><tr><td class="free-space"></td></tr>';
	  
	  //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+'<tr><td class="site-link">'; 
				if postfix<>'' then
					url:=url+postfix;
				if site='buy' then begin
					if Pos('amazon', url)>0 then
						all:=all+'<a class="picture" alt="Buy at Amazon"  href="link:http://www.movienizer.com/redirect/'+url+'">'+format('<img src="%samazon.gif"></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="picture" href="link:http://www.movienizer.com/redirect/'+url+'">'+format('<img src="%s%s"></a> ', [PicturesPath, s]);
				end;
				i := RegReadInteger('ShowSiteRating', 1);
				if i=1 then begin
					SiteRating:=GetFloatField('mc.rating');
					if (SiteRating>0) and (site<>'imdb') then
						all := all + format('<p class="simple-text">%s: %f</p>', [GetLangStr(75),SiteRating]);
				end;
				all := all + '</td></tr>';
			end;
			GetNextRecord;
		end; //for
		
		//my rating
		i := RegReadInteger('ShowRating', 1);
		if i=1 then begin
			all := all + '<tr><td class="free-space"></td></tr>';
			all := all + Format('<tr><td class="my-rating-cell-name">%s</td></tr>', [GetLangStr(298)]);
			all := all + '<tr><td class="my-rating-cell-value">'+rate+'</td></tr>';
		end;
		
		//imdb rating
		if IMDBRating <> 0 then begin
			if i<>1 then
				all := all + '<tr><td class="free-space"></td></tr>'
			else
				all := all + '<tr class="small-free-space"><td></td></tr>';
			all := all + Format('<tr><td class="imdb-rating-cell-name">%s</td></tr>', [GetLangStr(707)]) + Format ('<tr><td class="imdb-rating-cell-value">%0.1f</td></tr>', [IMDBRating]);
		end;
		
	all := all + '<tr><td class="free-space"></td></tr></table>';

    //pictures from movie
	MaxShots := RegReadInteger('ShotsCnt', 3);
	with sl do begin
		Clear;
        Add('select i.path, i.code, i.mode from images i');
		Add('left join images_modes im on im.code = i.mode');
        Add(format('where i.movie=%d', [MovieCode]));
		if (RegReadInteger('OnlyShots', 1) = 1) then
			Add('and mode=3');
		Add('order by im.sort_order, i.sort_order');
      end;
      RecordCount:=ExecuteSQL(sl.text);
      kol:=0;
	  j := 0;
	  if ((front_cover_url = '') and (RecordCount>0)) or (RecordCount > 1) then begin
			all:=all+'<table class="shots">';
			if RecordCount < MaxShots then
				MaxShots := RecordCount;
			for i:=1 to MaxShots do begin
				//skip the cover
				if (front_cover_url <> '') and (GetIntegerField('i.mode') = 1) and (j = 0) then
					j := j + 1
				else begin
					if (MyFileExists(ImagesPath+GetStringField('i.path'))) then begin
						FileName := GetImageFileName(GetStringField('i.path'), 'ThumbsScreenshots', '', ScreenshotWidth, 0);
						all:=all+format('<tr><td class="shots-cell"><a class="picture" href="ShowImage:%d"><img class="shot-image" src="%s"></a></td></tr>', [GetIntegerField('i.code'), FileName]);
					end;
				end;
				GetNextRecord;
			end;
			if RecordCount > MaxShots then 
				all:=all+format('<tr><td class="shots-cell"><a href="userref:110,%d"><img alt="%s" src="%sshots-more.gif" border="0"></a></td></tr>', [MovieCode, GetLangStr(1411), ImgPath]);
			all:=all+'</table>';
	  end; //if
		
	//end left pane
	all := all + '</td>';
		
		
		//right pane
		all := all + '<td width="100%"><table class="contents">';
	end; //if ActiveTab <> 2
	
	//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 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;
		
	
	//tabs
	if RegReadInteger('HideNavigationMenu', 0) = 0 then
		all := all + GetMovieTabs(MovieCode, season, SeasonCnt, awards<>'', shotCnt>0, (EditionsCount > 1) or (VideoFileName <>''), PosterCnt>0, TrailerCnt>0, description <> '', ConnectionsCnt > 0);
	
	//shots from the movie
	if ActiveTab = 2 then begin
		all := all + '<tr><td><table class="contents">';
		all := all + GetShots(MovieCode, 3, 'movie', 5, 7);
	end;
	
	//posters from the movie
	if ActiveTab = 7 then begin
		all := all + '<tr><td><table class="contents">';
		all := all + GetShots(MovieCode, 4, 'movie');
	end;
	
	//actors
	if ActiveTab = 4 then begin
		all := all + GetCast(MovieCode);
	end;
	
	if ActiveTab = 1 then begin	
		all := all + '<tr><td><table class="names-values"><tr style="background:url('+WhiteBarFile+') repeat-x;"><td colspan="2">&nbsp;&nbsp;</td></tr>';
		
	  //tagline
	  if TagLine <> '' then begin
		all := all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">"', [GetLangStr(3406)]);
		all := all + TagLine + '"</p></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
		all := all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(20271)]);
		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+'</p></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
				all := all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(173)]);
				all := all + Format('<a href="media_type:%d">%s</a></p></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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
      	//'Genres: '
        all:=all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(72)]);
        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+'</p></td></tr>';
      end;
	  
	  //year
      if year<>'' then
        all:=all+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="year:%s">%s</a></p></td></tr>', [GetLangStr(169), year, year]);
		
      //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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
      	//'Countries: '
		all := all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(73)]);
		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+format('%s</p></td></tr>', [country]);
      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
        all:=all+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%d %s%s</p></td></tr>', [GetLangStr(705), duration, GetLangStr(706), s]);

    //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
			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="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%s</p></td></tr>', [GetLangStr(708), 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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
        studios := format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(493)]);
        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 + '</p></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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
	      //'Directors: ';
        all:=all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(66)]);
        i:=1;
        while i<=RecordCount do begin
          if GetIntegerField('p.in_collection')=1 then
            img:=format('<img src="%sperson.gif" align="absmiddle">', [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+'</p></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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
      	//'Writers: '
        all:=all + Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">', [GetLangStr(67)]);
        i:=1;
        while i<=RecordCount do begin
          if GetIntegerField('p.in_collection')=1 then
            img:=format('<img src="%sperson.gif" align="absmiddle">', [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+'</p></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]));
      end;
      RecordCount:=ExecuteSQL(sl.text);
      if RecordCount>0 then begin
      	//'Composers: '
        all:=all+Format('<tr><td class="field-names"><p class="without-border">%s</p></td><td class="field-values"><p class="without-border">', [GetLangStr(491)]);
        i:=1;
        while i<=RecordCount do begin
          if GetIntegerField('p.in_collection')=1 then
            img:=format('<img src="%sperson.gif" align="absmiddle">', [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+'</p></td></tr>';
      end;
	  all := all + '</table></td></tr>';
	  
	  
		//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 + '<div style="margin: 0 5; float: left;"><a class="pic" href="userref:135,' + name + '"><img border="0" alt="'+ name + '" src="' + PicturesPath + 'awards\' + sl.Values[sl.Names[i]] + '"></a></div>';
			end;
			if s2 <> '' then
				all := all + '<tr><td><p class="description">' + s2 + '</p></td></tr><tr class="small-free-space"><td></td></tr>';
		end;

	  if RegReadInteger('ShowAllActors', 0) = 1 then
		FullPersons := True;
      //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('<tr><td><p class="header">%s (%d):</p></td></tr><tr><td><p class="description">', [GetLangStr(68), RecordCount]);
        i:=1;
		s:='';
        while i<=RecordCount do begin
          if GetIntegerField('p.in_collection')=1 then
            img:=format('<img src="%sperson.gif" align="absmiddle">', [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 (i=10) and (i<RecordCount) and not FullPersons then
						i:=RecordCount;          	
          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+'</p></td></tr>';
      end;
	  
	//photos of people
	temp := '';
	if (RegReadInteger('HidePhotosCovers', 0) = 0) then begin
		LastCode:=0;
		  with sl do begin
			Clear;
			Add('select distinct i.path as path, i.width, i.height, i.person as code, 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.mode desc, i.sort_order');
		  end;
		  RecordCount:=ExecuteSQL(sl.text);
		  PreviousCodes.Clear;
		  page_width := GetHTMLWidth - LeftColumnWidth;
		  if RecordCount>0 then begin
				all:=all+'<tr><td><table class="boxes">';
				j := 0;
				all := all + '<tr>';
				for i:=1 to RecordCount do begin
					if (PreviousCodes.IndexOf(IntToStr(GetIntegerField('code'))) < 0) then begin
						LastCode:=GetIntegerField('code');
						PreviousCodes.Add(IntToStr(GetIntegerField('code')));
						PicHeight := GetIntegerField('i.height');
						if PicHeight > 0 then
							PicWidth := Round(GetIntegerField('i.width') * (PhotoHeight / PicHeight)) + 5
						else
							PicWidth := StandardPhotoWidth;
						if PicWidth < StandardPhotoWidth then
							PicWidth := StandardPhotoWidth;
						{
						//to do: count page width, next line
						age := GetStringField('p.birth_date');
						while (Pos('/', age)> 1) do
							delete(age, 1, Pos('/', age));
						try
							if (StrToInt(age)>0) then
								age := IntToStr(StrToInt(year) - StrToInt(age));
						except
						end;
						}
						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
							trunc_name := TruncateName(GetStringField('p.name'), MaxNameLength);
							trunc_character := TruncateName(GetStringField('c.name'), MaxCharacterNameLength);

							FileName := GetImageFileName(GetStringField('path'), 'ThumbsMoviePhotos', 'nophoto.gif', 0, PhotoHeight);
							temp:=temp+format('<td class="photo"><a class="picture" href="person:%d"><img src="%s"></a><p><a href="person:%d">%s', [GetIntegerField('code'), FileName, GetIntegerField('code'), trunc_name]);
    					//end 2.05.11
							
							
							if age <> '' then
								temp := temp + format(' (%s)', [age]);
							temp := temp + '</a>';
							if trunc_character <> '' then
								temp := temp + '<br>(' + trunc_character + ')';
							temp := temp + '</p></td>';
							page_width := page_width - PicWidth;
							if (page_width >= 0) then begin
								all := all + temp;
								temp := '';
							end
							else begin						
								all := all + '</tr></table></td></tr><tr><td><table class="boxes"><tr>' + temp;
								page_width := GetHTMLWidth - LeftColumnWidth - PicWidth;
								temp := '';
							end;
						end;//if MyFileExists
					end;
					GetNextRecord;
				end;//for
				//all := all + '<td colspan="' + IntToStr(kol-j) + '">';
				all := all + temp + '</tr></table></td></tr>';
			end;//if recordcount
	  end;
	end; //activeTab = 1
	
	if (ActiveTab = 1) or (ActiveTab = 10) then begin  
		//description
		if description<>'' then
			all:=all+Format('<tr style="background:url(%s) repeat-x;"><td>&nbsp;</td></tr>', [WhiteBarFile])+'<tr><td><p class="description">'+description+'</p></td></tr>';
	end;
		
	if ActiveTab = 1 then begin
	 all := all + '<tr><td><table class="full-content">';

      //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;
		        cust:=cust+'<tr><td class="field-names"><p class="border">'+format(GetLangStr(539+i), [s])+'</p></td><td class="field-values"><p class="border">'+format('<a href="custom%d:%d">', [i, custom[i]])+GetStringField('name')+'</a></p></td></tr>';
	    	  end;
	      end;
	end;
	
	//custom list1
	border := '';
      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 > 2) then
			border := 'without-';
        cust:=cust+Format('<tr><td class="field-names"><p class="%sborder">%s</p></td><td class="field-values"><p class="%sborder">', [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+'</p></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>2 then
			border := 'without-';
        cust:=cust+Format('<tr><td class="field-names"><p class="%sborder">%s</p></td><td class="field-values"><p class="%sborder">', [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+'</p></td></tr>';
      end;
	if cust <> '' then
		all:=all+Format('<tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile])+cust;
	
//	if (cust<>'') or (s<>'') then
//		all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
	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]));
		end;
		RecordCount := ExecuteSQL(sl.text);
		page_width := GetHTMLWidth - 300;
		all := all + Format('<tr style="background:url(%s) repeat-x;"><td>&nbsp;</td></tr>', [WhiteBarFile]) + '<tr><td><table class="trailers"><tr>';
		temp := '';
		for i := 1 to RecordCount do begin
			PicWidth := GetIntegerField('i.width');
			if PicWidth = 0 then
				PicWidth := 200;
			PicWidth := PicWidth + 10;
			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><tr>';
				page_width := GetHTMLWidth - 300 - 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>'+url+format('<img class="trailer" src="%s"></a></td>', [FileName]);	
			GetNextRecord;
		end;
		if temp <> '' then
			all := all + temp + '</tr></table></td></tr>';
	end;
	
	//movie connections
	if (ActiveTab = 11) then begin
		//movie series
		if MovieSeriesNumber > 0 then begin
			temp := '<tr><td class="free-space"></td></tr>';
			//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 + '<tr><td><p class="header">'+GetLangStr(3907)+':';
				temp := temp + '</p><ol>';
				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="%smovie.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></td></tr><tr><td class="free-space"></td></tr>';
			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 + '<tr><td><p class="header">'+GetLangStr(3908)+':';
				temp := temp + '</p><ol>';
				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="%smovie.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></td></tr><tr><td class="free-space"></td></tr>';
			end;
			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></td></tr><tr><td class="free-space"></td></tr>';
					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 + '<tr><td><p class="header">'+LinkMovieStatusTitle+':';
					temp := temp + '</p><ol>';
				end;
				LinkYearStr := GetStringField('m.year');
				if (LinkYearStr <> '') then
					LinkYearStr := ' (' + LinkYearStr + ')';
				if (GetIntegerField('m.in_collection')=1) then
					img:=format('<img src="%smovie.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 + '<tr><td class="free-space"></td></tr>' + temp + '</ol></td></tr><tr><td class="free-space"></td></tr>';
		end;
	end; // end movie connections
		
      //editions
	if (ActiveTab = 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;

      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('<tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]) + '<tr><td colspan="2"><p class="header">';
			if VideoFileFolder<>'' then
				ed:=ed+format('<a 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) 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 href="play:%s">', [VideoFileName])+format('<img src="%splay.png" align="absmiddle" border="0" alt="%s"></a> ', [ImgPath, VideoFileName]);

			  
			if duration>0 then begin
				ed:=ed+Format('<font size="2">(%d:%0.2d)</font> ', [duration div 60, duration mod 60]);
			end;
			//ed:=ed+'<br>';
			if barcode<>'' then
				ed:=ed+GetLangStr(1259)+': '+barcode;
				
			(*******************Loans **********************)
			if (ActiveTab = 8) then begin
				//media format
				ThisBlockCnt := 0;
				if MediaFormat > 0 then begin
					with sl do begin
					  Clear;
					  Add('select name from manuals');
					  Add(format('where code=%d', [MediaFormat]));
					end;
					RecordCount := ExecuteSQL(sl.text);
					ed := ed + '  ';
					ThisBlockCnt := 1;
					if RecordCount > 0 then
						ed := ed + GetStringField('name');
				end;
				
				//disc number
				if disc_nom <> '' then begin
					if ThisBlockCnt = 1 then
						ed := ed + ', ';
					ed := ed + format('%s %s', [GetLangStr(391), disc_nom]);
					ThisBlockCnt := 1;
				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
						if ThisBlockCnt = 1 then
							ed := ed + ', ';
						ed := ed + format('%s: %s', [GetLangStr(1000), GetStringField('name')]);
					  end;
				end;
			(*************************End loans***************)
			end;
			ed := ed + '</p></td></tr>';

			all:=all+ed;
		end;
	
		//loan tab
		if (ActiveTab = 8) then begin
			with sl do begin
				Clear;
				Add('select l.loan_date, l.return_date, l.due_date, l.comment, ');
				Add('l.code, m.name from loans l');
				Add('join manuals m on m.code=l.location');
				Add(format('where edition=%d', [EditionCode]));
				Add('order by loan_date');
			end;
			RecordCount := ExecuteSQL(sl.text);
			loan_date := '';
			return_date := '';
			if RecordCount > 0 then begin
				ed := '<tr><td><table class="loans">';
				ed := ed + format('<tr><td><b>%s</b></td><td><b>%s</b></td><td><b>%s</b></td><td><b>%s</b></td><td><b>%s</b></td><td><b>%s</b></td></tr>', [GetLangStr(239), GetLangStr(240), GetLangStr(241), GetLangStr(245), GetLangStr(163), GetLangStr(1446)]);
				for j:=1 to RecordCount do begin
					ed := ed + '<tr>';
					loan_date := GetSmartDate(GetStringField('l.loan_date'));
					return_date := GetSmartDate(GetStringField('l.return_date'));
					if return_date = '' then
						return_date := Format('<a href="userref:11,%d;%d;%d">%s</a>', [EditionCode, MovieCode, GetIntegerField('l.code'), GetLangStr(1445)]);
					ed := ed + format('<td class="loan-date">%s</td>', [loan_date]);
					ed := ed + format('<td class="loan-date">%s</td>', [GetSmartDate(GetStringField('l.due_date'))]);
					ed := ed + format('<td class="loan-date">%s</td>', [return_date]);
					ed := ed + format('<td>%s</td>', [GetStringField('m.name')]);
					ed := ed + format('<td>%s</td>', [GetStringField('l.comment')]);
					ed := ed + format('<td><a class="picture" href="userref:14,%d;%d;%d"><img src="%sdelete.png"></a></td>', [EditionCode, MovieCode, GetIntegerField('l.code'), ImgPath]);
					ed := ed + '</tr>';
					GetNextRecord;
				end;
				ed := ed + '</table></td></tr>';
				all := all + ed;
			end
			else
				all := all + format('<tr><td><p class="description">%s</p></td></tr>', [GetLangStr(1441)]);
			if (loan_date = '') or (Pos('<a href', return_date) = 0) then
				all := all + format('<tr><td><p class="description"><a href="userref:10,%d;%d">%s</a></p></td></tr>', [EditionCode, MovieCode, GetLangStr(1442)]);
		end;
	
	//editions
	if (ActiveTab = 1) or (ActiveTab = 5) then begin
		
        ed:='';
		ThisBlockCnt := 0;
		
		if (ActiveTab = 1) then begin
			//disc #
			if disc_nom<>'' then begin
				ed:=ed+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%s</p></td></tr>', [GetLangStr(391), disc_nom]);
				ThisBlockCnt := ThisBlockCnt + 1;
			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;
				ed:=ed+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="disc_label:%d">%s</a></p></td></tr>', [GetLangStr(1000), DiscLabel, GetStringField('name')]);
			  end;
			end;
			//Cost
			if EditionCost>0 then begin
				ed:=ed+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%f</p></td></tr>', [GetLangStr(3350), EditionCost]);
				ThisBlockCnt := ThisBlockCnt + 1;
			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>2 then
					border := 'without-';
				ed:=ed+Format('<tr><td class="field-names"><p class="%sborder">', [border])+GetLangStr(333)+format('</p></td><td class="field-values"><p class="%sborder"><a href="location:%d">%s</a></p></td></tr>', [border, GetIntegerField('l.location'), GetStringField('m.name')]);
			end;
			
			if (ed<>'') then begin
				if (PrevBlockCnt=0) or (PrevBlockCnt>2) then
					all:=all+Format('<tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
				PrevBlockCnt := PrevBlockCnt + ThisBlockCnt;
				all := all + ed;
			end;
		end;
		
        //parameters
		ThisBlockCnt := 0;
        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);
        if (RecordCount>0) and (EditionsCount = 1) then begin
			if (PrevBlockCnt=0) or (PrevBlockCnt>2) then
				all:=all+Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
        end;
        for i:=1 to RecordCount do begin
        	if GetIntegerField('reference')=1 then begin
        		//Video standard
        		all:=all+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%s</p></td></tr>', [GetLangStr(201), GetStringField('name')]);
				ThisBlockCnt := ThisBlockCnt + 1;
			end
        	else if GetIntegerField('reference')=2 then begin
        		//media format
            //all:=all+GetLangStr(249)+': '+format('<a href="aspect_ratio:%d">%s</a>, ', [ScreenRatio, GetStringField('name')])
            all:=all+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="media_format:%d">%s</a></p></td></tr>', [GetLangStr(249), MediaFormat, GetStringField('name')]);
			ThisBlockCnt := ThisBlockCnt + 1;
			end
        	else if GetIntegerField('reference')=4 then begin
        		//screen ratio
            all:=all+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="aspect_ratio:%d">%s</a></p></td></tr>', [GetLangStr(202), ScreenRatio, GetStringField('name')]);
			ThisBlockCnt := ThisBlockCnt + 1;
			end
        	
        	else if GetIntegerField('reference')=5 then begin
        		//resolution
        		//all:=all+GetLangStr(203)+': '+GetStringField('name')+', '
            all:=all+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="resolution:%d">%s</a></p></td></tr>', [GetLangStr(203), resolution, GetStringField('name')]);
			ThisBlockCnt := ThisBlockCnt + 1;
			end

        	else if GetIntegerField('reference')=19 then begin
        		//video codec
        		all:=all+Format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border"><a href="video_codec:%d">%s</a></p></td></tr>', [GetLangStr(571), VideoCodec, GetStringField('name')]);
				ThisBlockCnt := ThisBlockCnt + 1;
			end;
          GetNextRecord;
        end;

        s2:='';
        //video bitrate
        if VideoBitrate>0 then begin
        	s2:=format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%d</p></td></tr>', [GetLangStr(630), VideoBitrate]);
			ThisBlockCnt := ThisBlockCnt + 1;
		end;
        //filesize
        if filesize>0 then begin
        	s2:=s2+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%d</p></td></tr>', [GetLangStr(631), filesize]);
			ThisBlockCnt := ThisBlockCnt + 1;
		end;
		
		//duration
		if (duration>0) and (EditionsCount=1) then begin
			s2:=s2+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%d %s', [GetLangStr(147), duration, GetLangStr(706)]);
			s2:=s2+format(' (%d:%.2d)</p></td></tr>', [duration div 60, duration mod 60]);
			ThisBlockCnt := ThisBlockCnt + 1;
		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;
      all:=all+Format('<tr><td class="field-names"><p class="without-border">%s</p></td><td class="field-values"><p class="without-border">', [GetLangStr(254)]);
      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 + '</p></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;
      all:=all+Format('<tr><td class="field-names"><p class="without-border">%s</p></td><td class="field-values"><p class="without-border">', [GetLangStr(253)]);
      for i:=1 to RecordCount do
      begin
        s2 := '';
        if (GetStringField('am.Short_Comment') <> '') then
          s2 := ' ' + Trim(GetStringField('am.Short_Comment'));
        //all:=all+GetStringField('m.name')+', ';
        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 + '</p></td></tr>';

    end;
	
		//show filename
		if (RegReadInteger('ShowFileNames', 1) = 1) and (VideoFileName<>'') then begin
			all := all + Format('<tr><td class="field-names"><p class="without-border">%s</p></td><td class="field-values"><p class="without-border">', [GetLangStr(195)]);
			all := all + Format('<a href="play:%s">%s</a></p></td></tr>', [VideoFileName, VideoFileName]);
		end;
		// DVD Features
		if EditionFeatures<>'' then begin
			all := all + Format('<tr><td class="free-space" colspan="2"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
			all := all + '<tr><td colspan="2"><p class="header">' + GetLangStr(1537) + '</p></td></tr>';
			all := all + '<tr><td colspan="2"><p class="description">' + EditionFeatures + '</p></td></tr>';
			PrevBlockCnt := 0;
		end;
		
		//Edition comments
		if EditionComment<>'' then begin
			all := all + Format('<tr><td class="free-space" colspan="2"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
			all := all + '<tr><td colspan="2"><p class="description">' + EditionComment + '</p></td></tr>';
			PrevBlockCnt := 0;
		end;
		
	  end;
	end; //editions
	end;  
	if (ActiveTab = 1) then begin
		//dates
		s:='';
		PrevBlockCnt := PrevBlockCnt + ThisBlockCnt;
		if DateAdd<>'' then
			s:=s+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%s</p></td></tr>', [GetLangStr(670), SQLDate2Str(DateAdd)]);
		if DateUpdate<>'' then
			s:=s+format('<tr><td class="field-names"><p class="border">%s</p></td><td class="field-values"><p class="border">%s</p></td></tr>', [GetLangStr(671), SQLDate2Str(DateUpdate)]);
		if DateSeen<>'' then
			s:=s+format('<tr><td class="field-names"><p class="without-border">%s</p></td><td class="field-values"><p class="without-border">%s</p></td></tr>', [GetLangStr(672), SQLDate2Str(DateSeen)]);
		if (s<>'') then begin
			if (PrevBlockCnt = 0) or (PrevBlockCnt > 2) then
				all := all + Format('<tr><td class="free-space" colspan="2"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
			all:=all+copy(s, 1, length(s)+1);
		end;

		all := all + '</table></td></tr>';



		//salary
		cust := '';
		if salary<>'' then
			cust:=cust+'<tr><td><p class="description">'+salary+'</p></td></tr>';
			
		if cust<>'' then
			all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td>&nbsp;</td></tr>', [WhiteBarFile]);
		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+'<tr><td><p class="description">'+comment+'</p></td></tr>';
		end;
		
		if cust<>'' then
			all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td>&nbsp;</td></tr>', [WhiteBarFile]);
		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:='<tr><td><p class="description">'+cust+temp+'</p></td></tr>';
		end;

		if cust<>'' then
			all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
		all := all + cust;
	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, ed.filename from episodes e');
			Add('left outer join editions ed on ed.movie=e.movie and e.season=ed.season and e.episode=ed.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);
		  for i:=1 to RecordCount do begin
			if GetIntegerField('e.season')>kol then begin
				kol:=GetIntegerField('e.season');
				seasons:=seasons+'<p class="header">'+format(GetLangStr(514), [kol])+'</p>';
			end;
			  seasons:=seasons+'<p class="header">'+format(GetLangStr(518), [GetIntegerField('e.episode')])+'. '+GetStringField('e.title');
			  s:=GetStringField('e.original_air_date');
			  s:=SQLDate2Str(s);
			  if s<>'' then
				  seasons:=seasons+'. '+s;
				  
			  if GetStringField('ed.filename')<>'' then
				seasons:=seasons+format('&nbsp;<a href="play:%s">', [GetStringField('ed.filename')])+format('<img src="%splay.png" align="absmiddle" border="0"></a>', [ImgPath]);

			  seasons:=seasons+'</p>';
			  seasons:=seasons+'<p class="description">'+GetStringField('e.description')+'</p>';
					GetNextRecord;
				end;
		if seasons<>'' then
			all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
		all := all + '<tr><td>' + seasons + '</td></tr>';
	end;
	if (ActiveTab = 1) and (SeasonCnt > 0) and (RegReadInteger('ShowSeasonsOnGeneralTab', 0) = 0) then begin
		all := all + Format('<tr><td class="free-space"></td></tr><tr style="background:url(%s) repeat-x;"><td colspan="2">&nbsp;</td></tr>', [WhiteBarFile]);
		all := all + Format('<tr><td><p class="header"><a href="userref:114,%d;0">%s %d</a></p></td></tr>',[MovieCode, GetLangStr(517), SeasonCnt]);
	end;
     

	  all := all + '</table>' + GetPatternBottom;

  sl.Free;
  PreviousCodes.Free;
  result:=all;
end;


begin

end.