(*
 Additional types and functions that can be used in scripts:

  //Types
  TWIDEARRAY : array of String

  //Field functions
  procedure AddSearchResult(Title1, Title2, Year, URL, PreviewURL : String)
  procedure AddFieldValue(AField: Integer; AValue : String)
  procedure AddMoviePerson(Name, TransName, Role, URL : String; AType : Byte)
  procedure AddPersonMovie(Title, OrigTitle, Role, Year, URL : String; AType : Byte)
  procedure AddAward(Event, Award, Category, Recipient, Year: String; const Won : Boolean)
  procedure AddConnection(Title, OrigTitle, Category, URL, Year: String)
  procedure AddEpisode(Title, OrigTitle, Description, URL, Year, Season, Episode : String)
  
  //String functions
  function Pos(Substr : String; Str: String): Integer
  function PosFrom(const SubStr, Str : String; FromIndex : Integer) : Integer
  function LastPos(const SubStr, Str : String) : Integer
  function PrevPos(const SubStr, Str : String; APos : Integer) : Integer
  function RemoveTags(AText : String; doLineBreaks : Boolean) : String
  function ExplodeString(AText : String; var Items : TWideArray; Delimiters : String) : Integer
  function Copy(S: String; Index, Count: Integer): String
  procedure Delete(var S: String; Index, Count: Integer)
  procedure Insert(Source: String; var Dest: String; Index: Integer)
  function Length(S: String): Integer
  function Trim(S: String): String
  function CompareText(S1, S2: String): Integer
  function CompareStr(S1, S2: String): Integer
  function UpperCase(S: String): String
  function LowerCase(S: String): String
  function StringReplace(S, OldPattern, NewPattern: String; ReplaceAll : Boolean; IgnoreCase : Boolean; WholeWord: Boolean): String
  function StrToInt(const S: String): Integer
  function IntToStr(const Value: Integer): String
  function StrToFloat(const S: String): Extended
  function FloatToStr(const Value: Extended): String

  function HTMLValues(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
  function HTMLValues2(const HTML : String; ABegin, AEnd, ItemBegin, ItemEnd : String; ValDelim : String; var Pos : Integer) : String
  function TextBetween(const HTML : String; ABegin, AEnd : String; doLineBreaks : Boolean; var Pos : Integer) : String
  function HTMLToText(const HTML : String) : String

  procedure ShowMessage(const Msg, Head : String)
*)

//Costanti utili
const
 //Script types
 stMovies = 0;
 stPeople = 1; 
 stPoster = 2;
  
 //Script modes
 smSearch   = 0; 
 smNormal   = 1;
 smPhoto    = 2;
 smFinished = 3;
  
 //Parse results
 prError     = 0; 
 prFinished  = 1;
 prList      = 2;
 prListImage = 3;
 prDownload  = 4;
 
 //Download methods
 dmGET  = 0;
 dmPOST = 1;
 
 //Prefix modes
 pmNone   = 0;
 pmEnd    = 1;
 pmBegin  = 2;
 pmRemove = 3; 
  
 //Movie fields
 mfURL         = 0;
 mfTitle       = 1;
 mfOrigTitle   = 2;
 mfAka         = 3;
 mfYear        = 4;
 mfGenre       = 5;
 mfCategory    = 6;
 mfCountry     = 7;
 mfStudio      = 8;
 mfMPAA        = 9;
 mfRating      = 10;
 mfTags        = 11;
 mfTagline     = 12;
 mfDescription = 13;
 mfDuration    = 14;
 mfFeatures    = 15;
  
 //People fields
 pfURL        = 0;
 pfName       = 1;
 pfTransName  = 2;
 pfAltNames   = 3;
 pfBirthday   = 4;
 pfBirthplace = 5;
 pfGenre      = 6;
 pfBio        = 7;
 pfDeathDate  = 8;
  
 //Credits types
 ctActors    = 0;
 ctDirectors = 1;
 ctWriters   = 2;
 ctComposers = 3;
 ctProducers = 4;
  
 //Script data  
 SCRIPT_VERSION = '0.0.1.1';
 SCRIPT_NAME    = 'IAFD.com';
 SCRIPT_DESC    = '[EN] Get people information from IAFD.com';
 SCRIPT_LANG    = $09; //English
 SCRIPT_TYPE    = stPeople;
 
 BASE_URL    = 'http://www.iafd.com/';
 RATING_NAME = 'ADE';

 SEARCH_STR  = 'www.iafd.com/results.asp?SearchType=Mozilla-search&SearchString=%s';
 
 CODE_PAGE   = 0; //Use 0 for Autodetect 


 //OPTIONS
 GET_THEMES  = True; //Set to False if you do not want Themes in Category field 
 GET_REVIEW  = True; 
 GET_CREDITS = True;

//Global variables 
var
 Mode : Byte;
 PhotoURL : String;
//Functions 
function GetScriptVersion : String;    //obbligatoria
begin
 Result := SCRIPT_VERSION;
end; 
 
function GetScriptName : String;    //obbligatoria
begin
 Result :=  SCRIPT_NAME;
end;

function GetScriptDesc : String;    //obbligatoria
begin
 Result := SCRIPT_DESC;
end;

function GetBaseURL : AnsiString;    //obbligatoria
begin
 Result := BASE_URL;
end;

function GetScriptLang: Cardinal;    //obbligatoria
begin
 Result := SCRIPT_LANG;
end;

function GetScriptType : Byte;    //obbligatoria
begin
 Result := SCRIPT_TYPE;
end;

function GetCurrentMode : Byte;    //obbligaotoria
begin
 Result := Mode;
end;

function GetDownloadURL : AnsiString;    //obbligatoria
begin
	if Mode > 0 then
	begin
		if PhotoURL <> '' then
		begin
			LogMessage('Url di download: Foto');
			Result := PhotoURL;
			Exit;
		end;
	end
	else
	begin
		LogMessage('Url di download: Search');
		Result := SEARCH_STR;
	end;
end;

function GetRatingName : String;
begin
 Result := RATING_NAME;
end;

function GetCodePage : Cardinal;
begin
 Result := CODE_PAGE;
end;

function GetDownloadMethod : Byte;
begin
  Result := dmGET;  
end;

function GetPrefixMode : Byte;
begin
 Result := pmBegin;  
end;

function GetIAFDValue ( HTML : String; StartString : String) : String;
var curPos,EndPos: Integer;
begin
	curPos := Pos(StartString, HTML);
	if curPos>0 then begin
		CurPos := PosFrom('<td>',HTML,curPos);
		CurPos := PosFrom('>',HTML,curPos)+1;
		EndPos := PosFrom('</td>',HTML,curPos);
		Result := HTMLToText(Trim(Copy(HTML,curPos,(EndPos-curPos))));
	end
	else
		Result := '';
		LogMessage(StartString + ':' + Result);
end;

//---------------------- Parse Photo -----------------

procedure ParsePhoto(PhotoURL : String);
begin
	
	LogMessage('PARSING PHOTO...' + PhotoURL); 
	PhotoURL:=HTMLToText (PhotoURL);
	AddImageURL(4,PhotoURL);
	
end;

//---------------------- Parse People ----------------

procedure ParsePeople(MovieURL : String; HTML : String);

var
	curPos, EndPos,actPosStart,actPosEnd : Integer;
	Nome, Nomealt,NomeDir, Paesenascita, Biografia, Datamorte, Datanascita, Giorno, Mese, Anno,dbgstrg, value, fullinfo : String;

begin
	AddFieldValue(pfURL,MovieURL);
	LogMessage('PARSING PEOPLE...'); 
	
	fullinfo:= '';
	
	//Nome
	curPos := Pos('<h1>',HTML);
	EndPos := PosFrom('</h1>',HTML,curPos);
	Nome   := Trim(Copy(HTML,curPos+4,EndPos-curPos-4));   //Copia nome
	
	AddFieldValue(pfName, Nome );     //aggiungi il nome
	LogMessage('Name: '+Nome);
	
	//Nome alternativo
	Nomealt := (GetIAFDValue(HTML,'AKA</b>'));
	if Nomealt <> '' then begin
		AddFieldValue(pfAltNames, Nomealt );
		fullinfo:= fullinfo+'Performer AKA : ' + Nomealt +  #13#10; //
	end;

	
(*	curPos := Pos('AKA</b>', HTML);
	if curPos>0 then begin
		CurPos := PosFrom('<td>',HTML,curPos);
		EndPos := PosFrom('</td>',HTML,curPos);
		Nomealt := Trim(Copy(HTML,curPos+4,(EndPos-curPos-4)));

		AddFieldValue(pfAltNames, Nomealt );     //aggiungi il nome alternativo
		LogMessage('Nome alternativo:' + Nomealt);

		fullinfo:= fullinfo+'Performer AKA : ' + Nomealt +  #13#10; // 
		
	end;
*)

	
	curPos := Pos('Director AKA</b>', HTML);
	if curPos>0 then begin
		curPos := PosFrom('<td valign="top">',HTML,curPos)+17;
		EndPos := PosFrom('</td>',HTML,curPos);
		Nomealt := Trim(Copy(HTML,curPos,EndPos-curPos-4));
		AddFieldValue(pfAltNames, Nomealt );     //aggiungi il nome alternativo
		LogMessage('Nome alternativo:' + Nomealt);
		fullinfo:= fullinfo+'Director AKA : ' + Nomealt +  #13#10; // 
	end;
	
	
	//Birthday
	curPos := PosFrom ('<b>Birthday</b>',HTML,curPos);
	if curPos > 0 then
	begin	
				curPos := PosFrom('">',HTML,curPos);
				EndPos := PosFrom(' ',HTML,curPos);
				Mese := Copy(HTML,curPos+2,EndPos-curPos-2);    // Month
				LogMessage(Mese);
				
				curPos := EndPos;
				EndPos := PosFrom(',',HTML,curPos);
				Giorno := Copy(HTML,curPos+1,EndPos-curPos-1);    //Copia mese
				
				LogMessage(Giorno);
				
				curPos := EndPos;
				EndPos := PosFrom('</a>',HTML,curPos);
				
				Anno := Copy(HTML,curPos+2,EndPos-curPos-2);    //Copia mese
				
				LogMessage(Anno);
			
				Mese := StringReplace(Mese,'January','1',true,true,true);
				Mese := StringReplace(Mese,'February','2',true,true,true);
				Mese := StringReplace(Mese,'March','3',true,true,true);
				Mese := StringReplace(Mese,'April','4',true,true,true);
				Mese := StringReplace(Mese,'May','5',true,true,true);
				Mese := StringReplace(Mese,'June','6',true,true,true);
				Mese := StringReplace(Mese,'July','7',true,true,true);
				Mese := StringReplace(Mese,'August','8',true,true,true);
				Mese := StringReplace(Mese,'Septembre','9',true,true,true);
				Mese := StringReplace(Mese,'October','10',true,true,true);
				Mese := StringReplace(Mese,'November','11',true,true,true);
				Mese := StringReplace(Mese,'December','12',true,true,true);

				Datanascita:=(Giorno+'.'+Mese+'.'+Anno);
	
				if Length(Datanascita) < 20 then
				begin
				AddFieldValue(pfBirthday, Datanascita);     //aggiungi la data di nascita
				LogMessage('Birthday found: '+Datanascita);	
				fullinfo:= fullinfo+'Birthday : ' + Datanascita +  #13#10; // 
				end
				else
				fullinfo:= fullinfo+'Birthday : No data' +  #13#10; // 
	
	end
	else
		LogMessage('Data di nascita: NESSUNA');
	
	//Astrology (copy from nome) //href="/astrology.rme/sign=pisces">Pisces</a>&nbsp
	//curPos := Pos('<b>Astrology</b></td><td><a href="/astrology.rme', HTML);
	curPos := Pos('<b>Astrology</b>', HTML);
	if curPos>0 then begin
	
		curPos := PosFrom('">',HTML,curPos+22)+2;
		EndPos := PosFrom('</a>',HTML,curPos);
		
		Nomealt := Trim(Copy(HTML,curPos,EndPos-curPos));

		if Length(Nomealt) < 20 then
			begin
				LogMessage('Astrology: '+Nomealt);	
				fullinfo:= fullinfo+'Astrology : ' + Nomealt +  #13#10; // 
			end
		else
			fullinfo:= fullinfo+'Astrology : No data' + #13#10; //  // 

	end;	
	

	//Paesenascita
	Nomealt := (GetIAFDValue(HTML,'<b>Birthplace</b>'));
	if Nomealt <> '' then begin
		AddFieldValue(pfBirthplace, Nomealt);     //Aggiungi il paese di nascita
		LogMessage('Birtplace found: ' + Nomealt);
		fullinfo:= fullinfo+'Birtplace : ' + Nomealt +  #13#10; // 
	end
	else
		LogMessage('Paese di nascita: NESSUNO');


//Date of death
	curPos := PosFrom ('<b>Date of Death</b>',HTML,curPos);
	if curPos > 0 then
	begin
		LogMessage('Date of death: start...');
		curPos := PosFrom(' ',HTML,curPos+28);
		EndPos := PosFrom(' ',HTML,curPos+1);
		Mese := Trim(Copy(HTML,curPos,EndPos-curPos));// Month
		LogMessage(Mese);
		
		curPos := EndPos;
		EndPos := PosFrom(',',HTML,curPos);
		Giorno := Copy(HTML,curPos+1,EndPos-curPos-1);//Copia mese
		
		LogMessage(Giorno);
		
		curPos := EndPos;
		EndPos := PosFrom('</a>',HTML,curPos);
		Anno := Copy(HTML,curPos+2,4);//Copia anno		
		
		LogMessage(Anno);
	
		Mese := StringReplace(Mese,'January','1',true,true,true);
		Mese := StringReplace(Mese,'February','2',true,true,true);
		Mese := StringReplace(Mese,'March','3',true,true,true);
		Mese := StringReplace(Mese,'April','4',true,true,true);
		Mese := StringReplace(Mese,'May','5',true,true,true);
		Mese := StringReplace(Mese,'June','6',true,true,true);
		Mese := StringReplace(Mese,'July','7',true,true,true);
		Mese := StringReplace(Mese,'August','8',true,true,true);
		Mese := StringReplace(Mese,'Septembre','9',true,true,true);
		Mese := StringReplace(Mese,'October','10',true,true,true);
		Mese := StringReplace(Mese,'November','11',true,true,true);
		Mese := StringReplace(Mese,'December','12',true,true,true);
		
		Datanascita:=(Giorno+'.'+Mese+'.'+Anno);
		LogMessage('Day of death: '+Datanascita);
		AddFieldValue(pfDeathDate, Datanascita);//aggiungi la data di nascita
		fullinfo:= fullinfo+'Date of Death : ' + Datanascita +  #13#10; // 
	end
	else
		LogMessage('Day of death: none');

	//Years active (copy from nome)
	// <b>Years Active as Performer</b></td><td>2005-2010 (Started around 22 years old)</td>	
	Nomealt := (GetIAFDValue(HTML,'Years Active</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Years active as Performer:' + Nomealt);
		fullinfo:= fullinfo+'Years active as Performer: ' + Nomealt +  #13#10; // 
	end
	else
	begin
		//Years active (copy from nome)
		// <b>Years Active as Performer</b></td><td>2005-2010 (Started around 22 years old)</td>
		Nomealt := (GetIAFDValue(HTML,'Years Active as Performer</b>'));
		if Nomealt <> '' then begin	
			LogMessage('Years active as Performer:' + Nomealt);
			fullinfo:= fullinfo+'Years Active as Performer : ' + Nomealt +  #13#10; // 
		end;

	//Years active (copy from nome)
		Nomealt := (GetIAFDValue(HTML,'Years Active as Director</b>'));
		if Nomealt <> '' then begin			
			LogMessage('Years active as Director :' + Nomealt);
			fullinfo:= fullinfo+'Years Active as Director : ' + Nomealt +  #13#10; // 
		end;
	end;
	
	
(*	curPos := Pos('Years Active</b></td><td>', HTML);
	if curPos>0 then begin
		curPos := PosFrom('<td>', HTML,curPos)+4;
		EndPos := PosFrom('</td>',HTML,curPos);
		Nomealt := Trim(Copy(HTML,curPos,(EndPos-curPos)));
		LogMessage('Years active as Performer:' + Nomealt);
		fullinfo:= fullinfo+'Years active as Performer: ' + Nomealt +  #13#10; // 
	end
	else
	begin
		//Years active (copy from nome)
		// <b>Years Active as Performer</b></td><td>2005-2010 (Started around 22 years old)</td>
		curPos := Pos('Years Active as Performer</b>', HTML);
		if curPos>0 then begin
			curPos := PosFrom('<td>', HTML,curPos)+4;
			EndPos := PosFrom('</td>',HTML,curPos);
			Nomealt := Trim(Copy(HTML,curPos ,(EndPos-curPos)));
			LogMessage('Years active as Performer:' + Nomealt);
			fullinfo:= fullinfo+'Years Active as Performer : ' + Nomealt +  #13#10; // 
		end;
	
		//Years active (copy from nome)
		curPos := Pos('Active as Director</b></td><td>', HTML);
		if curPos>0 then begin
			curPos := PosFrom('<td>', HTML,curPos)+4;
			EndPos := PosFrom('</td>',HTML,curPos);
			Nomealt := Trim(Copy(HTML,curPos ,(EndPos-curPos)));
			LogMessage('Years active as Director :' + Nomealt);
			fullinfo:= fullinfo+'Years Active as Director : ' + Nomealt +  #13#10; // 
		end;
	end;*)
		
		
	//Ethnicity (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'<b>Ethnicity</b>'));
	if Nomealt <> '' then begin	
 		LogMessage('Ethnicity:' + Nomealt);
		fullinfo:= fullinfo+'Ethnicity : ' + Nomealt +  #13#10; // 
	end;

	//Nationality/Heritage (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'<b>Nationality/Heritage</b>'));
	if Nomealt <> '' then begin	
			LogMessage('Nationality/Heritage:' + Nomealt);
		fullinfo:= fullinfo+'Nationality/Heritage : ' + Nomealt +  #13#10; // 
 	end;

	//Hair Colors (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'<b>Hair Color</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Hair Colors:' + Nomealt);
		fullinfo:= fullinfo+'Hair Colors : ' + Nomealt +  #13#10; // 
 	end;
			
	//Measurements (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'Measurements</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Measurements:' + Nomealt);
		fullinfo:= fullinfo+'Measurements : ' + Nomealt +  #13#10; // 
 	end;
	
	//Height (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'Height</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Height:' + Nomealt);
		fullinfo:= fullinfo+'Height : ' + Nomealt +  #13#10; // 
 	end;
	
	//Weight (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'Weight</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Weight:' + Nomealt);
		fullinfo:= fullinfo+'Weight : ' + Nomealt +  #13#10; // 
 	end;


	//Tattoos (copy from nome)// </td></tr><tr><td va
	Nomealt := (GetIAFDValue(HTML,'Tattoos</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Tattoos:' + Nomealt);
		fullinfo:= fullinfo+'Tattoos : ' + Nomealt +  #13#10; // 
 	end;

	//Non-Ear Piercings (copy from nome)
	Nomealt := (GetIAFDValue(HTML,'Non-Ear Piercings</b>'));
	if Nomealt <> '' then begin	
		LogMessage('Non-Ear Piercings:' + Nomealt);
		fullinfo:= fullinfo+'Non-Ear Piercings : ' + Nomealt +  #13#10; // 
 	end;
	
	//Comments 
	curPos := Pos('There are no comments for this performer', HTML);
	if curPos>0 then begin
		Nomealt := 'There are no comments for this performer';
		LogMessage('Comments:' + Nomealt);
		fullinfo:= fullinfo+'Comments : ' + Nomealt +  #13#10; // 
	end
	else
	begin	
		//Comments with content(copy from nome)
		curPos := Pos('Comments</b></td><td>', HTML);
		if curPos>0 then begin
			curPos := PosFrom('"cmt">',HTML,curPos)+6;
			EndPos := PosFrom('</span>',HTML,curPos);
			Nomealt := Trim(Copy(HTML,curPos ,(EndPos-curPos)));
			LogMessage('Comments:' + Nomealt);
			fullinfo:= fullinfo+'Comments : ' + Nomealt +  #13#10; // 
		end;
	end;

	//Website (copy from nome)
	curPos := Pos('<b>Website</b></td><td><a', HTML);
	if curPos>0 then begin
		curPos := PosFrom('">', HTML,CurPos) + 2;
		EndPos := PosFrom('</a>',HTML,curPos);
		
		Nomealt := Trim(Copy(HTML,curPos,(EndPos-curPos)));
		LogMessage('Website:' + Nomealt);
		fullinfo:= fullinfo+'Website : <link URL="' + Nomealt + '</link>'  #13#10; // 
	end
	else
	begin
		fullinfo:= fullinfo+'Website : No data';
	end;
	
	fullinfo:= fullinfo +  #13#10 +  #13#10+ 'Biographical data courtesy of the Internet Adult Film Database.'
	curPos := EndPos;
	LogMessage(fullinfo);
	AddFieldValue(pfBio,fullinfo);	
	
	//Foto
	curPos :=Pos('src="/graphics/',HTML);
	if curPos >0 then begin
		EndPos:= PosFrom('>',HTML,curPos);
		LogMessage ('URL Foto: '+PhotoURL);
		PhotoURL := BASE_URL + Copy(HTML,curPos + 6, EndPos - curPos - 7);
		LogMessage ('URL Foto: '+PhotoURL);
		ParsePhoto(PhotoURL);
	end
	else
	begin
		PhotoURL := '';
		LogMessage ('URL Foto: NESSUNO');
	end;
end;


//--------------- Parsing Search Results --------------------
procedure ParseSearchResults(HTML : String);       //Procedura di parsing dei risultati di ricerca
var
	curPos, EndPos, Counter : Integer;
	Name, URL, ImageURL,dbgstrg : String;
	actPosStart,actPosEnd, UrlPosStart,UrlPosEnd,debug_pos1:Integer;
begin
	LogMessage('Search Results...');
	curPos := Pos('<h2>Performers</h2>', HTML);    //ricerca la posizione della stringa
	if curPos < 1 then       //se non esiste tale stringa
		Exit;                //termina
  
	LogMessage('Parsing performers...');
	 //Cast
	 //curPos := Pos('<h3>Females</h3>', HTML); 
	 LogMessage('Cast readout');
	if curPos > 0 then 	begin
		EndPos := curPos;

		while (curPos > 0) AND (Counter < 50) AND (curPos < PosFrom('<h2>Reviews</h2>', HTML, EndPos)) do begin
			LogMessage('Intepreting site');
			Counter := Counter +1;
			EndPos := curPos; // Set last position to actual position
			// get url
			UrlPosStart := PosFrom('href="', HTML, EndPos);  // search for url start
			UrlPosEnd := PosFrom('>', HTML, UrlPosStart);  // search for url start
			
			URL := BASE_URL + Trim(Copy(HTML, UrlPosStart + 6, (UrlPosEnd - UrlPosStart - 7) ));
			
			LogMessage(URL);
		
			// Get Name
			actPosStart:=PosFrom('.htm">', HTML, EndPos);  	// search for url start;
			actPosEnd:=PosFrom('</a>', HTML, actPosStart); 	// search for url end
			Name := Trim(Copy(HTML, (actPosStart + Length('.htm">')), (actPosEnd - actPosStart - 6) ));
			LogMessage(Name);
			
			debug_pos1:=Pos('(',Name);
			if debug_pos1 >0 then 
				Name := Copy(Name,0,debug_pos1-1);
			LogMessage(Name);
			
			AddMoviePerson(Trim(Name), '', '', URL, ctActors);
							
			curPos := PosFrom('href="', HTML, actPosEnd);
		 end; 
	end;

	AddSearchResult(Name, '', '', URL, ImageURL);
	LogMessage('Risultato aggiunto con successo.');

	curPos := PosFrom('<div class="linkblu"', HTML, curPos);
end;



//---------------------- Parse Page -------------------------
// ParsePage
// - Entrypoint for the script. Check if the search-term leads to zero, one or many results.
function ParsePage(HTML : String; URL : AnsiString) : Cardinal;
begin
	if Pos('<b>Titles:</b>', HTML) > 0 then begin
		LogMessage('Search Results...');
		ParseSearchResults(HTML);
		Result := prList; //search results retrieved
	end else
	if Pos('<b>Titles:</b>', HTML) < 0 then		begin
			LogMessage('Error case...');
			Result := prError; //error (person not found)
		end	
	else
	if (Pos('personal biography', HTML) > 0) then begin
		LogMessage('Parsing people...');
		Mode := smNormal;
		ParsePeople(URL, HTML);
		Result := prDownload; //script has finished it's job
	end else
		Result := prError; //error (unknown page retrieved)
end;
//--------------------------Inizia lo script-----------------------------

begin
 Mode := smSearch;   //Modo script inizializzato in ricerca
end.
