const
	script_name='ozon';
	language='Russian';
	version=30;
	MinProgramBuild=5500;
	author='Alex';
var
	DownloadMovieBigCover, DownloadMovieShortCast, DownloadMovieFullCast, 
	DownloadMovieBigDescription, DownloadMovieComments, 
	DownloadMovieStudios,	DownloadMovieAwards, DownloadMovieEarnings, 
	DownloadMovieAdditionalInfo, DownloadMovieTechnicalInfo, DownloadMovieSeasonsList: boolean;
	MaxShotsCount: integer;

	title, MovieName, year, director, BasicURL, country, description: string;
	movie_code, movie_site_url, title_code, imdb_code, salary: string;
	titles: array of string;
	titles_count: integer;
	director_code, code: string;
	directors, writers, actors, characters, genres, imdb_codes: array of string;
	directors_codes, writers_codes, actors_codes: array of integer;
	directors_count, writers_count, actors_count, genres_count: integer;
	duration: integer;
	imdb_rating, rating: double;
	front_cover_url: string;
	posters_exists: boolean;
	original_title, mpaa, mpaa_rating: string;
	resolution, barcode, aspect_ratio, features, media_format, video_codec: string;
	
	RequestParameters: TStringList;

function GetStr(str: String; s1: String; s2: String): String;
var
  I: Integer;
  J: Integer;
begin
  // Вырезает кусок строки между s1 и s2
	Result := '';
	I := Pos(LowerCase(s1), LowerCase(str));
	if I > 0 then
	begin
		J := MyPos(LowerCase(s2), LowerCase(str), I + Length(s1));
		if J > 0 then
  		Result := Copy(str, I + Length(s1), J - I - Length(s1));
	end;
end;
	
// Function, which delete all symbol key of ASCII < 32, and delete reiteration spaces
function CorrectStr(Str: String): String;
var
	i: Integer;
	IsDoubleSpace: Boolean;
begin
	Result := '';
	for i := 1 to Length(Str) do begin
		IsDoubleSpace := ((Copy(Str, i, 1) = ' ') and (Copy(Str, i-1, 1) = ' '));
		if (Ord(Copy(Str, i, 1)) > 31) and not IsDoubleSpace then Result := Result+Copy(Str, i, 1);
	end;
end;

function ClearExtraBlankCharacters(text: string): string;
begin
	// Clear all extra blank charackters
	while (length(text) > 0) and (ord(text[1]) in [1..20, 32]) do
		delete(text, 1, 1);
	while (length(text) > 0) and (ord(text[length(text)]) in [1..20, 32]) do
		delete(text, length(text), 1);
	Result := text;
end;

function MovieSearch: integer;
var
	i, j, ii, jj, k, l: integer;
	title, code, s, s2, s3, s4, description, year, original_title, small_cover, director: string;
begin
	titles_count:=0;

	i:=pos('color="#993333">Ничего не найдено.</', all);
	j:=pos('color="#993333">Ваш запрос слишком общий.</', all);
	if (all='') or (i>0) or (j>0) then
		// Movie not found!
	else begin
		i := Pos('<div class="SearchResults', all);
		if i>0 then begin
			i := Pos('<div class="bOneTile inline"', all);
			while (i>0) do begin
				delete(all, 1, i);
				i := Pos('<div class="bOneTile inline"', all);
				if i = 0 then
					j := Length(all)
				else
					j := i;
				s2 := copy(all, 1, j-1);
				code := ParseString(s2, 'href="/context/detail/id/(\d+)/"', 1);
				title := GetStr(s2, '<a class="jsUpdateLink bOneTile_link', '</a>');
				title := RemoveTags('<' + title);
				title := ClearExtraBlankCharacters(title);
				
				small_cover := ParseString(s2, '/multimedia/video_dvd_covers/(.*?).jpg"', 1);
				if (small_cover <>'') and (Pos('noimg_', small_cover) = 0) then
					small_cover := 'http://www.ozon.ru/multimedia/video_dvd_covers/' + small_cover + '.jpg';
				if small_cover = '' then begin
					small_cover := GetStr(s2, 'src="', '"');
					if small_cover <> '' then
						small_cover := 'http:' + small_cover;
				end;
					
				
				//original_title := ParseString(s2, '<p class="Short">(.*?)<br/>', 1);
				//original_title := RemoveTags(original_title);
				//original_title := ClearExtraBlankCharacters(original_title);
				
				director := GetStr(s2, '<div class="bOneTilePropety mBlack">', '</div>');
				director := ClearExtraBlankCharacters(RemoveTags(director));
				
				description := GetStr(s2, '<div class="bOneTilePropety">', '</div>');
				description := RemoveTags(description);
				description := ClearExtraBlankCharacters(description);
				year := ParseString(description, '\((\d+)\)', 1);
				j := Pos('(', description);
				if j > 0 then
					delete(description, j, length(description) - j + 1);					
				if (title<>'') and (code<>'') then begin
					titles_count := titles_count + 1;
					SetSearchResult2(title, code, year, director, description, small_cover);
				end;
			end;
		end
		else begin
			code := ParseString(all, 's.products = ";(\d+)";', 1);
			if code<>'' then begin
				titles_count := 1;
				SetSearchResult('title', code);
			end;
		end;
	end;

	result:=titles_count;
end;

//get  movie name by barcode(UPC-12)
function GetMovieNameByUPC(barcode: string): string;
var
	url, all, s2, s3, res: string;
	i, j: integer;
begin
	res:='';
	url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [barcode]);	
	url:=ReplaceStr(url, ' ', '+', -1);
	all:=DownloadURL(url);
	//search image by title
	i:=pos('<Item>', all);
	while (i>0) and (res='') do begin
		j:=MyPos('</Item>', all, i+1);
		if j>0 then begin
			s2:=copy(all, i, j-i);
			s3:=ParseString(s2, '<Title>(.*?) \(.*\)</Title>', 1);
			if s3='' then
				s3:=ParseString(s2, '<Title>(.*?)</Title>', 1);
			if s3<>'' then
				res:=s3;
		end;
		i:=MyPos('<Item>', all, i+1);
	end;
	result:=res;
end;

//Get search URL by movie name
function GetSearchURLbyName(MovieName, AYear, ABarcode: string): string;
var
	url: string;
begin
	MovieName:=EncodeURL(MovieName, 'windows-1251');	
	url:=format('http://www.ozon.ru/?context=search&group=div_dvd&text=%s', [MovieName]);
	url:=ReplaceStr(url, ' ', '+', -1);
	result:=url;
end;

//Download search results from URL
function DownloadSearchURL(url: string): integer;
begin
	all:=DownloadURL(url);
	if all='-1' then
		result:=-1
	else
		result:=MovieSearch;
end;

function GetMovieURL(code: string; images_only: boolean): string;
begin
	result := format('http://www.ozon.ru/context/detail/id/%s/?type=1', [code]);
end;

function ClearBrackets(name: string): string;
var
	i: integer;
begin
	// clear word in brackets at the end of name
	i := pos(' (', name);
	if i>0 then
		name := copy(name, 1, i-1);
	i := pos(' [', name);
	if i>0 then
		name := copy(name, 1, i-1);
	Result := name;
end;

function GetTextBetween(fromStr, str1, str2: string): string;
var
	i, j: integer;
begin
	Result := '';
	if str1 = '' then
		i := 1
	else
		i := pos(str1, fromStr);
	if str2 = '' then
		j := Length(fromStr) + 1
	else
		j := MyPos(str2, fromStr, i+length(str1));
	if (i>0)and(j>0) then begin
		i := i + length(str1);
		Result := copy(fromStr, i, j-i);
	end;
end;

//returned link to front cover
function GetFrontCoverURL: string;
var
	res, all, url, s, s2, s3, amazon_url: string;
	i, j, frames_count, k: integer;
	item_url: string;
	image_data, image_height, image_width, image_url: string;
	frame_urls: array [1..100] of string;
	int_year: Word;
	year_prew, year_next, title: string;
	valid_year: boolean;
begin
	title:=original_title;
	res:=front_cover_url;
	amazon_url:='';


	if DownloadMovieBigCover then begin
  	s:=title;
  	url:=format('http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&SubscriptionId=0J0N83PT9M72BYH98YR2&Operation=ItemSearch&Keywords=%s&SearchIndex=Video&ResponseGroup=Request,Images,Tracks,ItemAttributes', [title]);
  	url:=ReplaceStr(url, ' ', '+', -1);
  	all:=DownloadURL(url);
  	//search image by title
  	frames_count := 0;
  	i:=pos('<Item>', all);
  	if year<>'' then begin
  		while (i>0) and (amazon_url='') do 
  		begin
  			j := MyPos('</Item>', all, i+1);
  			if j>0 then 
  			begin
  				s2 := copy(all, i, j-i);
  				s3 := GetTextBetween(s2, '<Title>', '</Title>');
  				s3 := ClearBrackets(s3);
  				s3 := DecodeHTML(s3);
  				if s3<>'' then 
  				begin
  					if (UpperCase(title) = UpperCase(s3)) then
  					begin
  						valid_year := true;
  						if pos('<TheatricalReleaseDate>', s2) > 0 then
  						begin
  							int_year := StrToInt(year);
  							year_prew := IntToStr(int_year - 1);
  							year_next := IntToStr(int_year + 1);
  							valid_year := false;
  							valid_year := pos('<TheatricalReleaseDate>'+year, s2) > 0;
  							valid_year := valid_year or (pos('<TheatricalReleaseDate>'+year_prew, s2) > 0);
  							valid_year := valid_year or (pos('<TheatricalReleaseDate>'+year_next, s2) > 0);						
  							year_prew := IntToStr(int_year - 2);
  							year_next := IntToStr(int_year + 2);
  							valid_year := valid_year or (pos('<TheatricalReleaseDate>'+year_prew, s2) > 0);
  							valid_year := valid_year or (pos('<TheatricalReleaseDate>'+year_next, s2) > 0);						
  						end;
  						if valid_year then
  						begin
  							s := '';
  							frames_count := 0;
  							repeat
  								image_data := GetTextBetween(s2, '<LargeImage>', '</LargeImage>');
  								image_url := GetTextBetween(image_data, '<URL>', '</URL>');
  								image_height := GetTextBetween(image_data, '<Height','</Height>');
  								image_height := GetTextBetween(image_height, '>','');
  								image_width := GetTextBetween(image_data, '<Width','</Width>');
  								image_width := GetTextBetween(image_width, '>','');
  								try
  									if (image_height <> '0') and ((StrToInt(image_width) / StrToInt(image_height)) > 1.2) then 
  									begin
  										for k := 1 to frames_count do
  											if frame_urls[k] = image_url then break;
  										if (frames_count = 0) or (frame_urls[k] <> image_url) then begin
  											frames_count := frames_count + 1;
  											frame_urls[frames_count] := image_url;
  										end;
  									end
  									else if amazon_url = '' then
  										amazon_url := image_url;
  								except
  									//Wrong XML format!
  								end;
  								delete(s2, 1, 25 + length(image_data));
  							until (image_data = '') or (frames_count = MaxShotsCount);
  						end;
  					end; //if
  				end; //if
  			end; //if
  			delete(all, 1, j);
  			i := Pos('<Item>', all);
  		end; //while
  	end; //if year<>''
	end;

	if (amazon_url<>'') and (RegReadInteger('OzonAmazonFirst', 1) = 1) then   // front-cover from amazon
		SetImageName('', amazon_url, '', 1);
	if front_cover_url<>'' then // front-cover from movie site
		SetImageName('', front_cover_url, '', 1);
	if (amazon_url<>'') and (RegReadInteger('OzonAmazonFirst', 1) = 0) then   // front-cover from amazon
		SetImageName('', amazon_url, '', 1);
	Result:=amazon_url;
end;

//save front cover to file
function SaveFrontCover(url, FileName: string): boolean;
var
	fs: TFileStream;
	s: string;
begin
	s:=DownloadURL(url);
	if (length(s)>0) and (s<>'-1') then begin
		try
			fs:=TFileStream.Create(FileName, fmCreate);
			fs.Write(s, Length(s));
			fs.Free;
			result:=true;
		except
			result:=false;
		end;
	end
	else
		result:=false;
end;

function ClearExtraQuotes(name: string): string;
begin
	// Clears extra quotes «"»
	if length(name)>0 then
		if (name[1]='"') and (name[length(name)]='"') then
			name := copy(name,2,length(name)-2);
	Result := name;
end;

function GetInfo(url: string; images_only: boolean): string;
var
	s, s2, s3, name, character, code, temp, small_photo: string;
	i,j,k: integer;
begin
	result:='';
	all:=DownloadURL(url, True, RequestParameters);
	if all='-1' then begin
		result:='-1';
		exit;
	end
	else
		result:=all;
	imdb_code := '';
	movie_code := ParseString(url, 'http://www.ozon.ru/context/detail/id/(\d+)/', 1);
	movie_site_url:=GetMovieSiteURL(movie_code);

	//movie title
	title:=ParseString(all, '<h1.*?>(.*?)</h1>', 1);
	i:=Pos('(', title);
	if i>0 then
		delete(title, i, length(title)-i+1);
	
	if title='' then
		exit;
		
	//обложка
	s := GetStr(all, '<div class="img">', '</div>');
	front_cover_url := GetStr(s, 'src="', '"');
	if front_cover_url<>'' then begin
		front_cover_url := 'http:' + front_cover_url;
		front_cover_url := ReplaceStr(front_cover_url, '/c200', '', -1);
	end;

	//Вырезаем кусок с основной информацией
	temp := GetStr(all, '<div class="product-detail">', '</table>');
	//оригинальное название
	original_title := GetStr(temp, '<p class="tov_prop">', '</p>');
	if ((Pos('...', original_title) > 0) and (Length(original_title)<6)) or (Pos('фильм', original_title)>0) then
		original_title := '';
		
	//год, продолжительность, страна
	s := GetStr(temp, '<p>', '</p>');
	year := ParseString(s, '^(\d+) г.', 1);
	delete(s, 1, Pos(',', s));
	//movie duration (minutes)
	s2 := ParseString(s, #9'(\d+) мин.', 1);
	duration:=0;
	if s2<>'' then
		try
			duration:=StrToInt(s2);
		except
		end;
	delete(s, 1, Pos(',', s));
	//movie countries
	s2 := ParseString(s, #9'(.*?)\.', 1);
	if s2<>'' then begin
		i := pos(' - ',s2);
		while i>0 do
			begin
				name := copy(s2,1,i-1);
				DecodeHTML(name);
				name:=ClearExtraSpaces(name);
				SetCountry(name);
				delete(s2,1,i+2);
				i := pos(' - ',s2);
			end;
		name:=DecodeHTML(s2);
		name:=ClearExtraSpaces(name);
		SetCountry(name);
	end;
	
	if DownloadMovieStudios then begin
		s := GetStr(temp, 'Кинокомпании:', '</p>');
		if s = '' then
			s := GetStr(temp, 'Кинокомпания', '</p>');
		i := Pos('<a href', s);
		while i>0 do begin
			j := MyPos('</a>', s, i + 1);
			s2 := copy(s, i, j-i);
			//name := ParseString(s2, '">(.*?)$', 1);
			name := ClearExtraBlankCharacters(RemoveTags(s2));
			if name<>'' then
				SetStudio(name);
			delete(s, 1, j);
			i := Pos('<a href', s);
		end;
	end;

	if not images_only then
	begin
	//movie plot
		s2 := GetStr(all, 'От производителя', '</table>');
		description := GetStr(s2, '>', '</td>');
		if description = '' then
			description := GetStr(s2, '<td >', '</td>');
		description:=DecodeHTML(description); 
		description:=ReplaceStr(description, #10, '', -1);
		description:=ReplaceStr(description, #13, '', -1);
		description:=ReplaceStr(description, '</p>', #10, -1);
		description:=ReplaceStr(description, '<br>', #10, -1);
		description:=RemoveTags(description);
		description:=ClearExtraBlankCharacters(description);
		description:=ReplaceStr(description, #10, '<br>', -1);
	end;
	
	if DownloadMovieTechnicalInfo then begin
		s2 := GetStr(all, 'Дополнительные материалы</h3>', '</div>');
		features := '';
		if s2 <> '' then begin
			s2 := ReplaceStr(s2, '<br>', #13#10, -1);
			features := ClearExtraBlankCharacters(RemoveTags(s2));
		end;
	end;
	
	//movie persons
	s := GetStr(all, '<h2>Персоны</h2>', '<div class="right"');
	if s = '' then
		s := GetStr(all, 'Персоны</h3>', '<div class="right"');
	while (Pos('<div class="item">', s)>0) do begin
		s2 := GetStr(s, '<div class="item">', '<div');
		code := GetStr(s2, '/context/detail/id/', '/"');
		name := GetStr(s2, ' title="', '"');
		name := RemoveTags(name);
		name := DecodeHTML(name);
		name := ClearExtraSpaces(name);
		small_photo := GetStr(s2, ' src="', '"');
		if (Pos('pushkin', small_photo) > 0) then
			small_photo := ''
		else begin
			small_photo := ReplaceStr(small_photo, '/c120', '', -1);
			small_photo := 'http:' + small_photo;
		end;
		if pos('режиссер',s2)>0 then
			SetPersonName(name, '', 1, code, small_photo);
		if pos('сценарист',s2)>0 then
			SetPersonName(name, '', 2, code, small_photo);
		if pos('автор музыки',s2)>0 then
			SetPersonName(name, '', 4, code, small_photo);
		if (pos('актер',s2)>0)or(pos('актриса',s2)>0) then begin
			character := '';
			SetPersonName(name, character, 3, code, small_photo);
		end;
		delete(s, 1, Pos('<div class="item">', s));
	end;
	
	//технические характеристики
	s := GetStr(all, 'Дополнительные характеристики</span>', '<ul>');
	//Дистрибьютор
	if (RegReadInteger('OzonDlDistributor', 0) = 1) then begin
		s2 := GetStr(s, '<div class="techName"><span>Дистрибьютор</span></div>', '</div>');
		s2 := GetStr(s2, '<a ', '</a>');
		s2 := ClearExtraBlankCharacters(DecodeHTML(RemoveTags('<' + s2)));
		if s2 <> '' then
			SetStudio(s2);		
	end;
	//количество слоев
	media_format := '';
	if (RegReadInteger('OzonDlLayers', 0) = 1) then begin
		s2 := GetStr(s, '<div class="techName"><span>Количество слоев</span></div>', '</div>');
		s2 := GetStr(s2, '<span>', '</span>');
		s2 := ClearExtraBlankCharacters(DecodeHTML(RemoveTags(s2)));
		media_format := s2;
	end;
	if DownloadMovieTechnicalInfo then begin
		//звуковые дорожки
		i := Pos('<div class="techName"><span>Звуковые дорожки</span></div>', s);
		if i>0 then begin
			delete(s, 1, i);
			s2 := ClearExtraBlankCharacters(RemoveTags(GetStr(s, '<div class="techDescr"><span>', '</')));
			SetAudioTrack(ParseAudioTrack(s2));
			temp := GetStr(s, '<div class="techName"><span>', '</span');
			i := Pos('<div class="techName"><span>', s);
			while (temp = '') and (i > 0) do begin
				delete(s, 1, i);
				s2 := ClearExtraBlankCharacters(RemoveTags(GetStr(s, '<div class="techDescr"><span>', '</')));
				SetAudioTrack(ParseAudioTrack(s2));
				i := Pos('<div class="techName"><span>', s);
				temp := GetStr(s, '<div class="techName"><span>', '</span');
			end;
		end;
		//субтитры
		i := Pos('<div class="techName"><span>Субтитры</span></div>', s);
		if i>0 then begin
			delete(s, 1, i);
			s2 := ClearExtraBlankCharacters(RemoveTags(GetStr(s, '<div class="techDescr"><span>', '</')));
			SetSubtitle(s2);
			temp := GetStr(s, '<div class="techName"><span>', '</span');
			i := Pos('<div class="techName"><span>', s);
			while (temp = '') and (i > 0) do begin
				delete(s, 1, i);
				s2 := ClearExtraBlankCharacters(RemoveTags(GetStr(s, '<div class="techDescr"><span>', '</')));
				SetSubtitle(s2);
				i := Pos('<div class="techName"><span>', s);
				temp := GetStr(s, '<div class="techName"><span>', '</span');
			end;
		end;
	end;
	
				
(**)	
end;

//Parse Audio Tracks to Movienizer's format
function ParseAudioTrack(s: string): string; //Need redaction
begin
	result:=s;
	if Pos(':', s)>0 then
		result := ReplaceStr(s, ':', '', -1);
	if Pos('Dolby Digital Stereo', s)>0	then
		result := ReplaceStr(result, 'Dolby Digital Stereo', 'AC3 2 ch', -1)
	else if Pos('Dolby Digital 5.1', s)>0 then
		result := ReplaceStr(result, 'Dolby Digital 5.1' , 'AC3 5 ch', -1)
	else if Pos('(Theatrical only)', s)>0 then
		result := ReplaceStr(result, '(Theatrical only)' , '', -1)
	else if Pos('Dolby Digital 5.1 EX', s)>0 then
		result := ReplaceStr(result, 'Dolby Digital 5.1 EX' , 'DD-EX 5.1', -1)
	else if Pos('Dolby Digital 2.0', s)>0 then
		result := ReplaceStr(result, 'Dolby Digital 2.0' , 'AC3 2 ch', -1)
	else if Pos('Dolby Digital 1.0', s)>0 then
		result := ReplaceStr(result, 'Dolby Digital 1.0' , 'AC3 1 ch', -1)
	else if Pos('Dolby TrueHD 5.1', s)>0 then
		result := ReplaceStr(result, 'Dolby TrueHD 5.1' , 'TrueHD 5 ch', -1)
	//else if Pos('Dolby Digital Surround', s)>0 then
		//result := ReplaceStr(result, 'Dolby Digital Surround' , 'AC3 2 ch', -1)
	else if Pos('DTS 5.1', s)>0 then
		result := ReplaceStr(result, 'DTS 5.1' , 'DTS 5 ch', -1);
	if Pos('Дубляж ', s)>0 then
		result := ReplaceStr(result, 'Дубляж ' , '', -1);
end;

//returned images links
procedure GetImages;
begin
	if (original_title <> '') and (RegReadInteger('OzonDlAmazonCover', 1) = 1) then
		GetFrontCoverURL
	else if front_cover_url<>'' then
		SetImageName('', front_cover_url, '', 1);
		
	GetShots;
end;

procedure GetShots;
var
	s, s2, my_img, pic_url, new_url: string;
	i, j, img_cnt: integer;
begin
	img_cnt := 1;
	if MaxShotsCount>4 then begin
		new_url := GetMovieSiteURL(movie_code) + '?type=2#images';
		all := DownloadURL(new_url);
	end;	
	i := Pos('<b>Кадры</b>', all);
	if i>0 then begin
		j := MyPos('</tr><tr>', all, i+1);
		s := copy(all, i, j-i);
		i := Pos('<a href="#images"', s);
		while (i>0) and (img_cnt <= MaxShotsCount) do begin
			img_cnt := img_cnt + 1;
			j := MyPos('</a>', s, i+1);
			s2 := copy(s, i, j-i);
			my_img := ParseString(s2, '/multimedia/video_stills/small/(\d+).gif', 1);
			if my_img<>'' then begin
				pic_url := 'http://www.ozon.ru/multimedia/video_stills/' + my_img + '.jpg';
				SetImageName('', pic_url, '', 3);
			end;
			delete(s, 1, j);
		end;
	end;			
end;

//get movie site url
function GetMovieSiteURL(code: string): string;
begin
	if code='' then
		result:=''
	else
		result:='http://www.ozon.ru/context/detail/id/'+code+'/';
end;

//get person site url
function GetPersonSiteURL(code: string): string;
begin
	if code='' then
		result:=''
	else
		result:=format('http://www.ozon.ru/context/detail/id/%s/', [code]);
end;

//show available settings for the script
function ShowScriptOptions: integer;
var
	s: string;
	f: TForm;
	b: TButton;
	cbDlAmazonCover, cbAmazonFirst, cbDlDistributor, cbDlLayers: TCheckBox;
	my_value: integer;
	
procedure cbDlAmazonClick(Sender: TCheckBox);
begin
	if TCheckBox(Sender).Checked then
		cbAmazonFirst.Enabled := True
	else begin
		cbAmazonFirst.Enabled := False;
		cbAmazonFirst.Checked := False;
	end;
end;

procedure ButtonClick(Sender: TButton);
var
	zn: integer;
begin
	try
		if cbDlAmazonCover.Checked then
			zn := 1
		else
			zn := 0;
		RegWriteInteger('OzonDlAmazonCover', zn);	
		if cbAmazonFirst.Checked then
			zn := 1
		else
			zn := 0;
		RegWriteInteger('OzonAmazonFirst', zn);
		if cbDlDistributor.Checked then
			zn := 1
		else
			zn := 0;
		RegWriteInteger('OzonDlDistributor', zn);
		if cbDlLayers.Checked then
			zn := 1
		else
			zn := 0;
		RegWriteInteger('OzonDlLayers', zn);
	except
	end;

	f.ModalResult := mrOk;
end;

begin
	result:=0;
	f := TForm.Create(nil);
	f.Caption := GetLangStr(1924);
	f.BorderStyle := bsDialog;
	f.Position := poScreenCenter;
	f.Width:=400;
	f.Height:=210;
	f.AutoSize:=false;

	
	cbDlAmazonCover := TCheckBox.Create(f);
	cbDlAmazonCover.Name := 'cbDlAmazonCover';
	cbDlAmazonCover.Parent := f;
	cbDlAmazonCover.SetBounds(10, 10, 350, 20);
	cbDlAmazonCover.Caption := 'Загружать обложку с Amazon';
	my_value := RegReadInteger('OzonDlAmazonCover', 1);
	if my_value=1 then
		cbDlAmazonCover.Checked := True;
		
	cbAmazonFirst := TCheckBox.Create(f);
	cbAmazonFirst.Name := 'cbAmazonFirst';
	cbAmazonFirst.Parent := f;
	cbAmazonFirst.SetBounds(20, 30, 350, 20);
	cbAmazonFirst.Caption := 'Ставить обложку с Amazon главной';
	my_value := RegReadInteger('OzonAmazonFirst', 1);
	if my_value=1 then
		cbAmazonFirst.Checked := True;
		
	cbDlDistributor := TCheckBox.Create(f);
	cbDlDistributor.Name := 'cbDlDistributor';
	cbDlDistributor.Parent := f;
	cbDlDistributor.SetBounds(10, 50, 350, 20);
	cbDlDistributor.Caption := 'Загружать студии-дистрибьюторы';
	my_value := RegReadInteger('OzonDlDistributor', 0);
	if my_value=1 then
		cbDlDistributor.Checked := True;
		
	cbDlLayers := TCheckBox.Create(f);
	cbDlLayers.Name := 'cbDlLayers';
	cbDlLayers.Parent := f;
	cbDlLayers.SetBounds(10, 70, 350, 20);
	cbDlLayers.Caption := 'Загружать информацию о формате';
	my_value := RegReadInteger('OzonDlLayers', 0);
	if my_value=1 then
		cbDlLayers.Checked := True;
		
	if not cbDlAmazonCover.Checked then
		cbDlAmazonClick(cbDlAmazonCover);
		
	cbDlAmazonCover.Onclick := @cbDlAmazonClick;
		

	b := TButton.Create(f);
	b.Name := 'btnOK';
	b.Parent := f;
	b.SetBounds(160, 150, 80, 25);
	b.Caption := '&OK';
	b.OnClick := @ButtonClick;

	f.ShowModal;
	f.Free;
end;

begin
  RequestParameters := TStringList.Create();
  RequestParameters.Add('Host=www.ozon.ru');
  RequestParameters.Add('AcceptLanguage=ru-RU');
  RequestParameters.Add('Connection=Close'); 
  RequestParameters.Add('useragent=Mozilla/5.0');
end.