//---------------------------------------------------------------------------

#ifndef Unit3H
#define Unit3H
#include <vcl.h>
#include <objbase.h>
#include <mshtml.h>
#include <urlmon.h>
#include <utilcls.h>
#include <map>
#include <vector>
#include <ExtCtrls.hpp>
#include "SHDocVw_OCX.h"
#include <OleCtrls.hpp>
using namespace std;

//---------------------------------------------------------------------------
class THotelListParser
{
  private :
    AnsiString SeedURL;
    TStringList * UrlList;
    map<AnsiString , int > urlMap;
    map<AnsiString , int > nextUrlMap;
    vector<AnsiString> GoneQue;
    IHTMLDocument2 *pDoc;
    IHTMLElementCollection *pAnchorCollection;
    LPDISPATCH Document;
    HRESULT hr;
    IMoniker *pMoniker;
    IBindCtx *pBCtx;
    IPersistMoniker *pPMoniker;


    void __fastcall ComInit (void)
      {
        hr = S_OK;
        pDoc = NULL;
        pAnchorCollection=NULL;
        Document=NULL;
        pMoniker = NULL;
        pBCtx= NULL;
        pPMoniker = NULL;
      }
   public :
    THotelListParser()
      {
        UrlList = new TStringList();
        ComInit();
      }
    THotelListParser(AnsiString SeedUrl)
      {
        UrlList = new TStringList();
        SeedURL = SeedUrl;
        ComInit();
      }
    void PutSeedUrl ( AnsiString SeedUrl )
      {
        SeedURL = SeedUrl;
      }

    ~THotelListParser()
      {
        if ( UrlList != NULL )
          delete UrlList;
        urlMap.clear();
        nextUrlMap.clear();
        GoneQue.clear();
/*        ::CoUninitialize();*/
//        FreeMemory(this);
      }

    int __fastcall GetUrlCount ( void )
      {
        return UrlList->Count;
      }

    AnsiString __fastcall GetUrl ( int idx )
      {
//        if (( 0 < idx ) && ( idx < UrlList->Count ))
          return UrlList->Strings[idx];
//        else
//          return "";
      }

    void __fastcall HotelListParaser (AnsiString SeedUrl);
    bool __fastcall IsNextPage (void)
      {
        return !GoneQue.empty();
      }
    void __fastcall GetNextPage ( void );
    void __fastcall CppWebBrowser1DocumentComplete(TObject *Sender, const _di_IDispatch pDisp, OleVariant &URL);
/*{
  if (pDisp == CurDispatch)
  {
    Beep(); // the document is loaded, not just a frame
    CurDispatch = NULL; //clear the global variable

  }
}*/
};
//---------------------------------------------------------------------------
#endif
