#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QWebView>
#include <QUrl>
#include <QStringList>
#include <QStringListModel>
#include <QTextCodec>
#include <QDateTime>
#include <Phonon>
#include <QSystemNetworkInfo>
#include <QDesktopServices>
#include <QNetworkConfigurationManager>
#include <QFile>
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <e32base.h>
#include <Etel3rdParty.h>


QTM_USE_NAMESPACE

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    CActive( EPriorityStandard ),
    ui(new Ui::MainWindow),
    iCallParamsPckg(iCallParams)
{
    ui->setupUi(this);
    isDetail = false;

    CActiveScheduler::Add( this );

    iTelephony = CTelephony::NewL();

    SetActive();

    ui->webView_3->setDisabled(true);
    QTextCodec::setCodecForCStrings ( QTextCodec::codecForName("utf8") );

    QTimer *timer = new QTimer(this);
    timer->start(6000);
    connect(timer,SIGNAL(timeout()),this,SLOT(splashTimeout()));

    postBuy = true;
    isRecord = false;
    QNetworkConfigurationManager manager;

    networkManager = new QNetworkAccessManager(this);

    const bool selectIap = (manager.capabilities()& QNetworkConfigurationManager::CanStartAndStopInterfaces);
    QNetworkConfiguration defaultIap = manager.defaultConfiguration();

    if(!defaultIap.isValid() && (!selectIap && defaultIap.state() != QNetworkConfiguration::Active))
        {
        // let the user know that there is no access point available
        }

    session = new QNetworkSession(defaultIap,this);
    session->open();

    nam = new QNetworkAccessManager(this);
    connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(finished(QNetworkReply*)));


    msgBox2.setText("本軟件需要網絡連線，請稍後再嘗試");
    connectButton = msgBox2.addButton("確認", QMessageBox::ActionRole);

    msgBox3.setText("很抱歉，於我們的網上資料庫中，暫時未能找到您搜尋的樓盤。閣下如需要進一步協助，請按此聯絡我們。");
    connectButton3 = msgBox3.addButton("聯絡", QMessageBox::ActionRole);
    QPushButton * cancelButton = msgBox3.addButton("取消",QMessageBox::RejectRole);

    msgBox4.setText("很抱歉，於我們的網上資料庫中，暫時未能找到您搜尋的代理。閣下如需要進一步協助，請按此聯絡我們。");
    connectButton2 = msgBox4.addButton("聯絡", QMessageBox::ActionRole);
    cancelButton = msgBox4.addButton("取消",QMessageBox::RejectRole);

    recordMsgBox.setText("請選擇");
    checkButton = recordMsgBox.addButton("查看",QMessageBox::ActionRole);
    deleteButton = recordMsgBox.addButton("刪除",QMessageBox::RejectRole);

    record360MsgBox.setText("請選擇");
    check360Button = record360MsgBox.addButton("查看",QMessageBox::ActionRole);
    delete360Button = record360MsgBox.addButton("刪除",QMessageBox::RejectRole);

    callMsgBox.setText("");
    callButton = callMsgBox.addButton("確認",QMessageBox::ActionRole);
    QPushButton * cancelButton2 = callMsgBox.addButton("取消",QMessageBox::RejectRole);

    connect(callButton,SIGNAL(clicked()),this,SLOT(calltoAgent3()));

    connect(delete360Button,SIGNAL(clicked()),this,SLOT(record360Delete()));
    connect(check360Button,SIGNAL(clicked()),this,SLOT(record360Check()));


    connect(connectButton2,SIGNAL(clicked()),this,SLOT(pageWeb()));
    connect(connectButton3,SIGNAL(clicked()),this,SLOT(pageWeb()));

    connect(connectButton,SIGNAL(clicked()),this,SLOT(close()));
    connect(deleteButton,SIGNAL(clicked()),this,SLOT(recordDelete()));
    connect(checkButton,SIGNAL(clicked()),this,SLOT(recordCheck()));


//    Phonon::MediaObject *mediaObject = new Phonon::MediaObject(this);
//         Phonon::VideoWidget *videoWidget = new Phonon::VideoWidget(this);
//         Phonon::createPath(mediaObject, videoWidget);
//         Phonon::AudioOutput *audioOutput =
//             new Phonon::AudioOutput(Phonon::VideoCategory, this);
//         Phonon::createPath(mediaObject, audioOutput);
//         mediaObject->setCurrentSource(QUrl("http://www.youtube.com/watch?v=KMqi9Nyf_9I&feature=rec-LGOUT-exp_fresh+div-1r-4-HM"));
//         mediaObject->play();
//         videoWidget->show();


    geoSell=true;
    QCoreApplication::setOrganizationName("Nuthon");
    QCoreApplication::setApplicationName("Centaline");
    ui->label_24->lower();
    recentReadCode1 = settings.value("r1").toString();
    recentReadCode2 = settings.value("r2").toString();
    recentReadCode3 = settings.value("r3").toString();
    record360 = settings.value("record360").toString();
    recordPost = settings.value("recordPost").toString();
    recordRent = settings.value("recordRent").toString();
    estateNumber = 0;
    facilityNumber = 0;
    recordPostCount=0;
    videoCount=0;
    imageCount=0;
    sellSii = 0;
    rentSii = 0;
    postCount=0;
    blogCount=0;
    floorCount=0;
    districtCount=0;
    postSii = 1;
    blogSii = 1;
    districtSii = 1;
    imageNumber = 0;
    isSell = true;

    QTime time = QTime::currentTime();
    QDate date = QDate::currentDate();
    QString dateString = "更新日期  ";
    QString tmpdate = "";
    if(date.day() > 9)
        tmpdate.setNum(date.day());
    else
    {
       tmpdate.setNum(date.day());
       tmpdate.prepend("0");
    }
    dateString.append(tmpdate);
    dateString.append("/");
    if(date.month() > 9)
        tmpdate.setNum(date.month());
    else
    {
        tmpdate.setNum(date.month());
        tmpdate.prepend("0");
    }
    dateString.append(tmpdate);
    dateString.append("/");
    tmpdate.setNum(date.year());
    dateString.append(tmpdate);
    dateString.append("    ");
    tmpdate.setNum(time.hour());
    dateString.append(tmpdate);
    dateString.append(":00");
    ui->timeLabel->setText(dateString);
    ui->timeLabel_2->setText(dateString);
    postOrBlog = 0;//0 = post 1 = blog

    QPalette p;
    p.setColor(QPalette::WindowText,Qt::black);

    //ui->scrollArea->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    //ui->scrollArea->setWidgetResizable(1);
    ui->tncLabel->setPalette(p);
    ui->searchBtn->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->blogBtn->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->infoBtn->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->infoBtn_2->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->infoBtn_3->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->detail360Chart->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->groupBox->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->groupBox_2->setStyleSheet(QString::fromUtf8("Background: transparent; border: none"));
    ui->radio_unlimit->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_1->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_2->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_3->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_4->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_buy->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->radio_sell->setStyleSheet("QRadioButton::indicator:unchecked{image: url(://new/prefix1/Image/but_radio.png)} QRadioButton::indicator:checked{image: url(://new/prefix1/Image/but_radio_l.png)}");
    ui->resetBtn->setStyleSheet("color: rgb(255, 255, 255)");
    ui->postsearchBtn->setStyleSheet("color: rgb(255, 255, 255)");
    ui->blogareaBtn->setStyleSheet("color: rgb(255, 255, 255)");
    ui->resetBtn_2->setStyleSheet("color: rgb(255, 255, 255)");

    //ui->licenseTxt_3->setPalette(p);
    ui->label_2->setPalette(p);
    ui->label_3->setPalette(p);
    ui->label_5->setPalette(p);
    ui->label_6->setPalette(p);
    ui->label_8->setPalette(p);
    ui->label_10->setPalette(p);
    ui->license->setPalette(p);
    ui->hkText->setPalette(p);

    ui->klText->setPalette(p);

    ui->nteText->setPalette(p);

    ui->ntwText->setPalette(p);

    ui->hotText->setPalette(p);
    ui->timeLabel->setPalette(p);
    ui->radio_1->setPalette(p);
    ui->radio_2->setPalette(p);
    ui->radio_3->setPalette(p);
    ui->radio_4->setPalette(p);
    ui->radio_buy->setPalette(p);
    ui->radio_sell->setPalette(p);
    ui->groupBox->setPalette(p);
    //ui->areaTxt->setPalette(p);
    ui->priceTxt->setPalette(p);
    ui->priceTxt_2->setPalette(p);
    ui->price_index->setPalette(p);
    ui->area_index->setPalette(p);
    ui->resetBtn->setPalette(p);
    ui->postsearchBtn->setPalette(p);
    //ui->licenseTxt_2->setPalette(p);
    //ui->areaTxt->setPalette(p);
    ui->roomTxt->setPalette(p);
    ui->buyTxt->setPalette(p);
    ui->sellTxt->setPalette(p);
    ui->label->setPalette(p);


    ui->price_slider->setRange(0,99);
    ui->price_slider->setValue(0);
    ui->area_slider->setRange(0,99);
    ui->area_slider->setValue(0);
    connect(ui->price_slider,SIGNAL(valueChanged(int)),this,SLOT(displayPrice(int)));
    connect(ui->area_slider,SIGNAL(valueChanged(int)),this,SLOT(displayArea(int)));
    connect(ui->resetBtn,SIGNAL(clicked()),this,SLOT(resetPostSearch()));
    connect(ui->postsearchBtn,SIGNAL(clicked()),this,SLOT(postSearch()));

    connect(ui->tab1_1,SIGNAL(clicked()),this,SLOT(changeTab1_1()));
    connect(ui->tab1_2,SIGNAL(clicked()),this,SLOT(changeTab1_2()));
    connect(ui->tab1_3,SIGNAL(clicked()),this,SLOT(changeTab1_3()));
    connect(ui->tab1_4,SIGNAL(clicked()),this,SLOT(changeTab1_4()));

    connect(ui->tab2_1,SIGNAL(clicked()),this,SLOT(changeTab2_1()));
    connect(ui->tab2_2,SIGNAL(clicked()),this,SLOT(changeTab2_2()));
    connect(ui->tab2_3,SIGNAL(clicked()),this,SLOT(changeTab2_3()));
    connect(ui->tab2_4,SIGNAL(clicked()),this,SLOT(changeTab2_4()));

    connect(ui->searchBtn,SIGNAL(clicked()),this,SLOT(pageConditionSearch()));
    connect(ui->areaBtn,SIGNAL(clicked()),this,SLOT(pageArea()));
    connect(ui->blogareaBtn,SIGNAL(clicked()),this,SLOT(pageArea()));
    connect(ui->resetBtn_2,SIGNAL(clicked()),this,SLOT(resetBlogSearch()));
    connect(ui->blogsearchBtn,SIGNAL(clicked()),this,SLOT(blogSearch()));
    connect(ui->blogBtn,SIGNAL(clicked()),this,SLOT(pageBlog()));
    connect(ui->infoBtn,SIGNAL(clicked()),this,SLOT(pageTNC()));
    connect(ui->infoBtn_2,SIGNAL(clicked()),this,SLOT(pageTNC()));
    connect(ui->infoBtn_3,SIGNAL(clicked()),this,SLOT(pageTNC()));
    connect(ui->postDetailNextPageBtn,SIGNAL(clicked()),this,SLOT(pageDetail2()));
    connect(ui->postDetailPreviousPageBtn,SIGNAL(clicked()),this,SLOT(pageDetail1()));
    postDetailMan = new QNetworkAccessManager(this);
    QObject::connect(postDetailMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(postDetailFinished(QNetworkReply*)));
    postSearchMan = new QNetworkAccessManager(this);
    QObject::connect(postSearchMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(postSearchResult(QNetworkReply*)));
    areaType = 0;
    pt = "pt=s";

    facilityImageMan = new QNetworkAccessManager(this);
    QObject::connect(facilityImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(facilityImageDownloaded(QNetworkReply*)));

    searchBoxManager = new QNetworkAccessManager(this);
    QObject::connect(searchBoxManager,SIGNAL(finished(QNetworkReply*)),this,SLOT(searchBoxResult(QNetworkReply*)));

    newPropPreviewFloorPlanImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropPreviewFloorPlanImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropPreviewFloorPlanImageDownloaded(QNetworkReply*)));

    newPropPreviewImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropPreviewImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropPreviewImageDownloaded(QNetworkReply*)));

    newPropVideoImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropVideoImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropVideoImageDownloaded(QNetworkReply*)));

    newPropFloorPlanImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropFloorPlanImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropFloorPlanImageDownloaded(QNetworkReply*)));

    newPropListImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropListImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropListImageDownloaded(QNetworkReply*)));

    newPropDetailMan = new QNetworkAccessManager(this);
    QObject::connect(newPropDetailMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropDetailResult(QNetworkReply*)));

    newPropDetailImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropDetailImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropDetailImageDownloaded(QNetworkReply*)));

    newPropMan = new QNetworkAccessManager(this);
    QObject::connect(newPropMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropResult(QNetworkReply*)));

    newPropImageMan = new QNetworkAccessManager(this);
    QObject::connect(newPropImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(newPropImageDownloaded(QNetworkReply*)));

    recordPostMan = new QNetworkAccessManager(this);
    QObject::connect(recordPostMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(recordPostListResult(QNetworkReply*)));

    recordPostImageMan = new QNetworkAccessManager(this);
    QObject::connect(recordPostImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(recordPostListImageDownladed(QNetworkReply*)));

    record360Man = new QNetworkAccessManager(this);
    QObject::connect(record360Man,SIGNAL(finished(QNetworkReply*)),this,SLOT(record360ListResult(QNetworkReply*)));

    record360ImageMan = new QNetworkAccessManager(this);
    QObject::connect(record360ImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(record360ListImageDownladed(QNetworkReply*)));

    geoPostMan = new QNetworkAccessManager(this);
    QObject::connect(geoPostMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(geoLocationPostResult(QNetworkReply*)));

    geoPostImageMan = new QNetworkAccessManager(this);
    QObject::connect(geoPostImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(geoLocationPostImageDownloaded(QNetworkReply*)));

    geo360Man = new QNetworkAccessManager(this);
    QObject::connect(geo360Man,SIGNAL(finished(QNetworkReply*)),this,SLOT(geoLocation360Result(QNetworkReply*)));

    geo360ImageMan = new QNetworkAccessManager(this);
    QObject::connect(geo360ImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(geoLocation360ImageDownloaded(QNetworkReply*)));

    recentReadImage1Man = new QNetworkAccessManager(this);
    QObject::connect(recentReadImage1Man,SIGNAL(finished(QNetworkReply*)),this,SLOT(recentReadImageDownloaded1(QNetworkReply*)));

    recentReadImage2Man = new QNetworkAccessManager(this);
    QObject::connect(recentReadImage2Man,SIGNAL(finished(QNetworkReply*)),this,SLOT(recentReadImageDownloaded2(QNetworkReply*)));

    recentReadImage3Man = new QNetworkAccessManager(this);
    QObject::connect(recentReadImage3Man,SIGNAL(finished(QNetworkReply*)),this,SLOT(recentReadImageDownloaded3(QNetworkReply*)));

    recentReadMan = new QNetworkAccessManager(this);
    QObject::connect(recentReadMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(recentReadResult(QNetworkReply*)));

    floorPlanMan = new QNetworkAccessManager(this);
    QObject::connect(floorPlanMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(floorPlanResult(QNetworkReply*)));

    floorPlanImageMan = new QNetworkAccessManager(this);
    QObject::connect(floorPlanImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(floorPlanImageDownloaded(QNetworkReply*)));

    district360MoreImageMan = new QNetworkAccessManager(this);
    QObject::connect(district360MoreImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(district360MoreImageDownloaded(QNetworkReply*)));

    district360MoreMan = new QNetworkAccessManager(this);
    QObject::connect(district360MoreMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(district360MoreResult(QNetworkReply*)));

    previewEstateMan = new QNetworkAccessManager(this);
    QObject::connect(previewEstateMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(previewEstateDownloaded(QNetworkReply*)));

    previewFacilityMan = new QNetworkAccessManager(this);
    QObject::connect(previewFacilityMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(previewFacilityDownloaded(QNetworkReply*)));

    detail360Man6 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man6,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360previewEstate(QNetworkReply*)));

    detail360Man7 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man7,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360previewFacility(QNetworkReply*)));

    detail360ChartMan = new QNetworkAccessManager(this);
    QObject::connect(detail360ChartMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360ChartDownloaded(QNetworkReply*)));

    detail360Man1 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man1,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360Result1(QNetworkReply*)));

    detail360Man2 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man2,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360Result2(QNetworkReply*)));

    detail360Man3 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man3,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360Result3(QNetworkReply*)));

    detail360Man4 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man4,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360Result4(QNetworkReply*)));

    detail360Man5 = new QNetworkAccessManager(this);
    QObject::connect(detail360Man5,SIGNAL(finished(QNetworkReply*)),this,SLOT(detail360Result5(QNetworkReply*)));

    topThreeMan = new QNetworkAccessManager(this);
    QObject::connect(topThreeMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(topThreeEstateFinished(QNetworkReply*)));

    districtAreaMan = new QNetworkAccessManager(this);
    QObject::connect(districtAreaMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(districtAreaResult(QNetworkReply*)));

    districtAreaImageMan = new QNetworkAccessManager(this);
    QObject::connect(districtAreaImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(districtAreaImageDownloaded(QNetworkReply*)));

    recentTradeMan = new QNetworkAccessManager(this);
    QObject::connect(recentTradeMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(recentTradeResult(QNetworkReply*)));

    previewImageMan = new QNetworkAccessManager(this);
    QObject::connect(previewImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(previreImageDownloadFinished(QNetworkReply*)));

    districtSearchMan = new QNetworkAccessManager(this);
    QObject::connect(districtSearchMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(districtSearchResult(QNetworkReply*)));

    districtSearchImageMan = new QNetworkAccessManager(this);
    QObject::connect(districtSearchImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(districtImageDownloaded(QNetworkReply*)));

    blogDetailImageMan = new QNetworkAccessManager(this);
    QObject::connect(blogDetailImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(blogDetailImageDownloaded(QNetworkReply*)));

    blogDetailMan = new QNetworkAccessManager(this);
    QObject::connect(blogDetailMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(blogDetailResult(QNetworkReply*)));

    blogSearchMan = new QNetworkAccessManager(this);
    QObject::connect(blogSearchMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(blogSearchResult(QNetworkReply*)));

    blogImageMan = new QNetworkAccessManager(this);
    QObject::connect(blogImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(blogImageDownloaded(QNetworkReply*)));

    postDetailAgentImageMan = new QNetworkAccessManager(this);
    QObject::connect(postDetailAgentImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(postDetailAgentImageFinished(QNetworkReply*)));

    postDetailImageMan = new QNetworkAccessManager(this);
    QObject::connect(postDetailImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(postDetailImageFinished(QNetworkReply*)));

    postImageMan = new QNetworkAccessManager(this);
    QObject::connect(postImageMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(postImageDownloaded(QNetworkReply*)));

    topEstatesMan = new QNetworkAccessManager(this);
    QObject::connect(topEstatesMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(topEstatesFinished(QNetworkReply*)));
    getTopEstates();
    ui->webView->load(QUrl("http://hk.centanet.com/icms/template.aspx?series=571"));
    //ui->webView->load(QUrl("http://www.yahoo.com.hk"));


    connect(ui->hkareaBtn,SIGNAL(clicked()),this,SLOT(changeToHKList()));
    connect(ui->klareaBtn,SIGNAL(clicked()),this,SLOT(changeToKLList()));
    connect(ui->ntwareaBtn,SIGNAL(clicked()),this,SLOT(changeToNTWList()));
    connect(ui->nteareaBtn,SIGNAL(clicked()),this,SLOT(changeToNTEList()));

    connect(ui->list_area,SIGNAL(clicked(QModelIndex)),this,SLOT(currentClicked(QModelIndex)));
    connect(ui->list_postSearch,SIGNAL(clicked(QModelIndex)),this,SLOT(postListClicked(QModelIndex)));
    connect(ui->list_blog,SIGNAL(clicked(QModelIndex)),this,SLOT(blogListClicked(QModelIndex)));
    connect(ui->list_blogDetail,SIGNAL(clicked(QModelIndex)),this,SLOT(blogDetailClicked(QModelIndex)));
    connect(ui->postListDownloadBtn,SIGNAL(clicked()),this,SLOT(postListUpdated()));
    connect(ui->postListDownloadBtn_3,SIGNAL(clicked()),this,SLOT(blogDetailListUpdated()));
    connect(ui->postListDownloadBtn_2,SIGNAL(clicked()),this,SLOT(blogListUpdated()));
    connect(ui->postListDownloadBtn_4,SIGNAL(clicked()),this,SLOT(districtListUpdated()));
    connect(ui->blogDetailSellBtn,SIGNAL(clicked()),this,SLOT(blogDetailChangeToSell()));
    connect(ui->blogDetailRentBtn,SIGNAL(clicked()),this,SLOT(blogDetailChangeToRent()));

    connect(ui->hkBtn1,SIGNAL(clicked()),this,SLOT(hk1BtnClicked()));
    connect(ui->hkBtn2,SIGNAL(clicked()),this,SLOT(hk2BtnClicked()));
    connect(ui->hkBtn3,SIGNAL(clicked()),this,SLOT(hk3BtnClicked()));
    connect(ui->hkBtn4,SIGNAL(clicked()),this,SLOT(hk4BtnClicked()));
    connect(ui->hkareaBtn_2,SIGNAL(clicked()),this,SLOT(hk4BtnClicked()));


    connect(ui->klBtn1,SIGNAL(clicked()),this,SLOT(kl1BtnClicked()));
    connect(ui->klBtn2,SIGNAL(clicked()),this,SLOT(kl2BtnClicked()));
    connect(ui->klBtn3,SIGNAL(clicked()),this,SLOT(kl3BtnClicked()));
    connect(ui->klBtn4,SIGNAL(clicked()),this,SLOT(kl4BtnClicked()));
    connect(ui->klareaBtn_2,SIGNAL(clicked()),this,SLOT(kl4BtnClicked()));


    connect(ui->nteBtn1,SIGNAL(clicked()),this,SLOT(nte1BtnClicked()));
    connect(ui->nteBtn2,SIGNAL(clicked()),this,SLOT(nte2BtnClicked()));
    connect(ui->nteBtn3,SIGNAL(clicked()),this,SLOT(nte3BtnClicked()));
    connect(ui->nteBtn4,SIGNAL(clicked()),this,SLOT(nte4BtnClicked()));
    connect(ui->nteareaBtn_2,SIGNAL(clicked()),this,SLOT(nte4BtnClicked()));


    connect(ui->ntwBtn1,SIGNAL(clicked()),this,SLOT(ntw1BtnClicked()));
    connect(ui->ntwBtn2,SIGNAL(clicked()),this,SLOT(ntw2BtnClicked()));
    connect(ui->ntwBtn3,SIGNAL(clicked()),this,SLOT(ntw3BtnClicked()));
    connect(ui->ntwBtn4,SIGNAL(clicked()),this,SLOT(ntw4BtnClicked()));
    connect(ui->ntwareaBtn_2,SIGNAL(clicked()),this,SLOT(ntw4BtnClicked()));




    connect(ui->districtSearchRentBtn,SIGNAL(clicked()),this,SLOT(districtListChangeToRent()));
    connect(ui->districtSearchSellBtn,SIGNAL(clicked()),this,SLOT(districtListChangeToSell()));

    connect(ui->previewBtn,SIGNAL(clicked()),this,SLOT(previewImageDownload()));
    connect(ui->previewBackBtn,SIGNAL(clicked()),this,SLOT(pageDetail1()));
    connect(ui->previewNextImage,SIGNAL(clicked()),this,SLOT(nextImage()));
    connect(ui->previewPreviousImage,SIGNAL(clicked()),this,SLOT(previousImage()));

    connect(ui->postDetailPromoBtn,SIGNAL(clicked()),this,SLOT(postDetailPromotion()));

    connect(ui->list_districtSearch,SIGNAL(clicked(QModelIndex)),this,SLOT(districtListClicked(QModelIndex)));
    connect(ui->list_districtArea,SIGNAL(clicked(QModelIndex)),this,SLOT(districtAreaListClicked(QModelIndex)));



    connect(ui->detail360Chart,SIGNAL(clicked()),this,SLOT(pageChartDetail()));
    connect(ui->backBtn,SIGNAL(clicked()),this,SLOT(page360Detail()));

    connect(ui->commandLinkButton_4,SIGNAL(clicked()),this,SLOT(pageFacility()));
    connect(ui->backBtn_2,SIGNAL(clicked()),this,SLOT(pageFlatDetail()));

    connect(ui->commandLinkButton,SIGNAL(clicked()),this,SLOT(downloadEstate()));
    connect(ui->commandLinkButton_3,SIGNAL(clicked()),this,SLOT(downloadFacility()));

    connect(ui->commandLinkButton_5,SIGNAL(clicked()),this,SLOT(downloadEstate()));
    connect(ui->commandLinkButton_7,SIGNAL(clicked()),this,SLOT(downloadFacility()));

    connect(ui->previewNextImage_2,SIGNAL(clicked()),this,SLOT(nextEstateImage()));
    connect(ui->previewPreviousImage_2,SIGNAL(clicked()),this,SLOT(previousEstateImage()));
    connect(ui->previewNextImage_3,SIGNAL(clicked()),this,SLOT(nextFacilityImage()));
    connect(ui->previewPreviousImage_3,SIGNAL(clicked()),this,SLOT(previousFacilityImage()));
    connect(ui->previewBackBtn_2,SIGNAL(clicked()),this,SLOT(changeTab2_1()));
    connect(ui->previewBackBtn_3,SIGNAL(clicked()),this,SLOT(pageFaciltyList()));
    connect(ui->backBtn_3,SIGNAL(clicked()),this,SLOT(changeTab2_1()));
    connect(ui->backBtn_9,SIGNAL(clicked()),this,SLOT(changeTab2_1()));

    connect(ui->postListDownloadBtn_5,SIGNAL(clicked()),this,SLOT(tradeSellListUpdated()));
    connect(ui->postListDownloadBtn_6,SIGNAL(clicked()),this,SLOT(tradeRentListUpdated()));

    connect(ui->postDetailTrade1,SIGNAL(clicked()),this,SLOT(trade1Click()));
    connect(ui->postDetailTrade2,SIGNAL(clicked()),this,SLOT(trade2Click()));
    connect(ui->postDetailTrade3,SIGNAL(clicked()),this,SLOT(trade3Click()));

    connect(ui->hkBtn1_2,SIGNAL(clicked()),this,SLOT(hk1Btn360Clicked()));
    connect(ui->hkBtn2_2,SIGNAL(clicked()),this,SLOT(hk2Btn360Clicked()));
    connect(ui->hkBtn3_2,SIGNAL(clicked()),this,SLOT(hk3Btn360Clicked()));
    connect(ui->hkBtn4_2,SIGNAL(clicked()),this,SLOT(hk4Btn360Clicked()));
    connect(ui->hkareaBtn_3,SIGNAL(clicked()),this,SLOT(hk4Btn360Clicked()));

    connect(ui->klBtn1_2,SIGNAL(clicked()),this,SLOT(kl1Btn360Clicked()));
    connect(ui->klBtn2_2,SIGNAL(clicked()),this,SLOT(kl2Btn360Clicked()));
    connect(ui->klBtn3_2,SIGNAL(clicked()),this,SLOT(kl3Btn360Clicked()));
    connect(ui->klBtn4_2,SIGNAL(clicked()),this,SLOT(kl4Btn360Clicked()));
    connect(ui->klareaBtn_3,SIGNAL(clicked()),this,SLOT(kl4Btn360Clicked()));

    connect(ui->nteBtn1_2,SIGNAL(clicked()),this,SLOT(nte1Btn360Clicked()));
    connect(ui->nteBtn2_2,SIGNAL(clicked()),this,SLOT(nte2Btn360Clicked()));
    connect(ui->nteBtn3_2,SIGNAL(clicked()),this,SLOT(nte3Btn360Clicked()));
    connect(ui->nteBtn4_2,SIGNAL(clicked()),this,SLOT(nte4Btn360Clicked()));
    connect(ui->nteareaBtn_3,SIGNAL(clicked()),this,SLOT(nte4Btn360Clicked()));

    connect(ui->ntwBtn1_2,SIGNAL(clicked()),this,SLOT(ntw1Btn360Clicked()));
    connect(ui->ntwBtn2_2,SIGNAL(clicked()),this,SLOT(ntw2Btn360Clicked()));
    connect(ui->ntwBtn3_2,SIGNAL(clicked()),this,SLOT(ntw3Btn360Clicked()));
    connect(ui->ntwBtn4_2,SIGNAL(clicked()),this,SLOT(ntw4Btn360Clicked()));
    connect(ui->ntwareaBtn_3,SIGNAL(clicked()),this,SLOT(ntw4Btn360Clicked()));


    connect(ui->list_districtArea_2,SIGNAL(clicked(QModelIndex)),this,SLOT(distict360MoreClicked(QModelIndex)));

    connect(ui->commandLinkButton_2,SIGNAL(clicked()),this,SLOT(floorPlanSearch()));
    connect(ui->commandLinkButton_6,SIGNAL(clicked()),this,SLOT(floorPlanSearch()));

    connect(ui->backBtn_4,SIGNAL(clicked()),this,SLOT(pageFloorPlanList()));
    connect(ui->list_floorPlan,SIGNAL(clicked(QModelIndex)),this,SLOT(floorPlanClicked(QModelIndex)));

    connect(ui->mainBtn,SIGNAL(clicked()),this,SLOT(mainBack()));

    connect(ui->recentBtn1,SIGNAL(clicked()),this,SLOT(recentReadRecord1()));
    connect(ui->recentBtn2,SIGNAL(clicked()),this,SLOT(recentReadRecord2()));
    connect(ui->recentBtn3,SIGNAL(clicked()),this,SLOT(recentReadRecord3()));

    connect(ui->recordBtn_2,SIGNAL(clicked()),this,SLOT(record360View()));
    connect(ui->bookmark360Btn,SIGNAL(clicked()),this,SLOT(record360Save()));
    connect(ui->bookmark360Btn_2,SIGNAL(clicked()),this,SLOT(record360Save()));

    connect(ui->list_record360,SIGNAL(clicked(QModelIndex)),this,SLOT(record360ListClicked(QModelIndex)));
    connect(ui->GPSBtn,SIGNAL(clicked()),this,SLOT(pageGeoLocationPost()));
    connect(ui->GPSBtn_2,SIGNAL(clicked()),this,SLOT(pageGeoLocation360()));

    connect(ui->list_geoLcationPost,SIGNAL(clicked(QModelIndex)),this,SLOT(geoLocationPostClicked(QModelIndex)));
    connect(ui->list_geoLcation360,SIGNAL(clicked(QModelIndex)),this,SLOT(geoLocation360Clicked(QModelIndex)));

    connect(ui->geolocationPostRentBtn,SIGNAL(clicked()),this,SLOT(geolocationchangetoRent()));
    connect(ui->geolocationPostSellBtn,SIGNAL(clicked()),this,SLOT(geolocationchangetoSell()));

    connect(ui->geolocation500mBtn,SIGNAL(clicked()),this,SLOT(geolocationchangeto500m()));
    connect(ui->geolocation1000mBtn,SIGNAL(clicked()),this,SLOT(geolocationchangeto1000m()));
    connect(ui->geolocation1500mBtn,SIGNAL(clicked()),this,SLOT(geolocationchangeto1500m()));

    connect(ui->bookmarkPostBtn,SIGNAL(clicked()),this,SLOT(recordPostSave()));
    connect(ui->recordBtn,SIGNAL(clicked()),this,SLOT(recordPostView()));
    connect(ui->list_recordPost,SIGNAL(clicked(QModelIndex)),this,SLOT(recordPostListClicked(QModelIndex)));

    connect(ui->clean360Btn,SIGNAL(clicked()),this,SLOT(record360Clean()));
    connect(ui->cleanPostBtn,SIGNAL(clicked()),this,SLOT(recordPostClean()));

    connect(ui->list_newProp,SIGNAL(clicked(QModelIndex)),this,SLOT(newPropClicked(QModelIndex)));

    connect(ui->newPropHKBtn,SIGNAL(clicked()),this,SLOT(newPropChangeToHK()));
    connect(ui->newPropKLBtn,SIGNAL(clicked()),this,SLOT(newPropChangeToKL()));
    connect(ui->newPropNTBtn,SIGNAL(clicked()),this,SLOT(newPropChangeToNT()));
    connect(ui->newPropHotBtn,SIGNAL(clicked()),this,SLOT(newPropChangeToHOT()));

    connect(ui->commandLinkButton_11,SIGNAL(clicked()),this,SLOT(pageNewPropContact()));
    connect(ui->newPropContactBtn_2,SIGNAL(clicked()),this,SLOT(pageNewPropContact()));
    connect(ui->newPropContactBtn_3,SIGNAL(clicked()),this,SLOT(pageNewPropContact()));
    connect(ui->newPropContactBtn_4,SIGNAL(clicked()),this,SLOT(pageNewPropContact()));
    connect(ui->newPropContactBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropContact()));

    connect(ui->newPropDetailBtn,SIGNAL(clicked()),this,SLOT(pageNewPropDetail()));
    connect(ui->newPropDetailBtn_2,SIGNAL(clicked()),this,SLOT(pageNewPropDetail()));
    connect(ui->newPropDetailBtn_3,SIGNAL(clicked()),this,SLOT(pageNewPropDetail()));
    connect(ui->newPropDetailBtn_4,SIGNAL(clicked()),this,SLOT(pageNewPropDetail()));
    connect(ui->newPropDetailBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropDetail()));

    connect(ui->commandLinkButton_10,SIGNAL(clicked()),this,SLOT(newPropFloorPlanDownload()));
    connect(ui->newPropFloorPlanBtn_2,SIGNAL(clicked()),this,SLOT(pageNewPropFloorPlan()));
    connect(ui->newPropFloorPlanBtn_3,SIGNAL(clicked()),this,SLOT(pageNewPropFloorPlan()));
    connect(ui->newPropFloorPlanBtn_4,SIGNAL(clicked()),this,SLOT(pageNewPropFloorPlan()));
    connect(ui->newPropFloorPlanBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropFloorPlan()));

    connect(ui->commandLinkButton_9,SIGNAL(clicked()),this,SLOT(newPropImageDownload()));
    connect(ui->newPropImageBtn_2,SIGNAL(clicked()),this,SLOT(pageNewPropImage()));
    connect(ui->newPropImageBtn_3,SIGNAL(clicked()),this,SLOT(pageNewPropImage()));
    connect(ui->newPropImageBtn_4,SIGNAL(clicked()),this,SLOT(pageNewPropImage()));
    connect(ui->newPropImageBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropImage()));

    connect(ui->newPropVideoBtn,SIGNAL(clicked()),this,SLOT(pageNewPropVideo()));
    connect(ui->newPropVideoBtn_2,SIGNAL(clicked()),this,SLOT(pageNewPropVideo()));
    connect(ui->newPropVideoBtn_3,SIGNAL(clicked()),this,SLOT(pageNewPropVideo()));
    connect(ui->newPropVideoBtn_4,SIGNAL(clicked()),this,SLOT(pageNewPropVideo()));
    connect(ui->newPropVideoBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropVideo()));

    connect(ui->backBtn_5,SIGNAL(clicked()),this,SLOT(pageNewPropImage()));
    connect(ui->list_newPropFloorPlan,SIGNAL(clicked(QModelIndex)),this,SLOT(newPropImageClicked(QModelIndex)));

    connect(ui->backBtn_6,SIGNAL(clicked()),this,SLOT(pageNewPropFloorPlan()));
    connect(ui->list_newPropImage,SIGNAL(clicked(QModelIndex)),this,SLOT(newPropFloorPlanClicked(QModelIndex)));

    connect(ui->list_newPropVideo,SIGNAL(clicked(QModelIndex)),this,SLOT(newPropVideoClicked(QModelIndex)));

    connect(ui->radio_buy,SIGNAL(clicked()),this,SLOT(postSell()));
    connect(ui->radio_sell,SIGNAL(clicked()),this,SLOT(postRent()));

    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(pageRequestForm()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(pageRequestForm()));
    connect(ui->submitBtn,SIGNAL(clicked()),this,SLOT(submitForm()));
    connect(ui->backBtn_7,SIGNAL(clicked()),this,SLOT(postDetailpreviousPage()));
    connect(ui->resetBtn_3,SIGNAL(clicked()),this,SLOT(resetForm()));

    connect(ui->backBtn_8,SIGNAL(clicked()),this,SLOT(postDetailpreviousPage()));
    connect(ui->searchBoxBtn,SIGNAL(clicked()),this,SLOT(searchBox()));
    connect(ui->list_searchBox,SIGNAL(clicked(QModelIndex)),this,SLOT(searchBoxClicked(QModelIndex)));

    connect(ui->commandLinkButton_8,SIGNAL(clicked()),this,SLOT(pageCharacter()));
    connect(ui->backBtn_10,SIGNAL(clicked()),this,SLOT(pageDetail1()));
    connect(ui->list_facility,SIGNAL(clicked(QModelIndex)),this,SLOT(facilityClicked(QModelIndex)));

    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(calltoAgent()));
    connect(ui->postOtherAgentName,SIGNAL(clicked()),this,SLOT(calltoAgent2()));
    connect(ui->postAgentBranch,SIGNAL(clicked()),this,SLOT(calltoBranch()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(calltoAgent3()));

    connect(ui->recordSellBtn,SIGNAL(clicked()),this,SLOT(recordChangetoSell()));
    connect(ui->recordRentBtn,SIGNAL(clicked()),this,SLOT(recordChangetoRent()));

    connect(ui->list_newPropContact,SIGNAL(clicked(QModelIndex)),this,SLOT(newPropContactClicked(QModelIndex)));


    ui->tabBar->setCurrentIndex(0);

    //ui->list_area->setPalette(p);
    ui->list_area->setBackgroundRole(QPalette::Dark);
    AreaMan = new QNetworkAccessManager(this);
    QObject::connect(AreaMan,SIGNAL(finished(QNetworkReply*)),this,SLOT(areaFinished(QNetworkReply*)));
    ui->Content->setCurrentIndex(0);
    ui->loading->lower();
    ui->Content->lower();



}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::calltoAgent()
{
    makeCall(postDetailXml.elementsByTagName("contact").at(0).toElement().text());
}

void MainWindow::calltoAgent2()
{
    QString tmp = "確定致電";
    tmp.append(postDetailXml.elementsByTagName("nameTc").at(1).toElement().text());
    tmp.append("?");
    callMsgBox.setText(tmp);
    contact = postDetailXml.elementsByTagName("contact").at(1).toElement().text();
    callMsgBox.exec();
}

void MainWindow::calltoAgent3()
{
    makeCall(contact);
}

void MainWindow::calltoBranch()
{

    callMsgBox.setText("確定致電分行?");
    if(postDetailXml.elementsByTagName("branchContact").count() == 2)
        contact = postDetailXml.elementsByTagName("branchContact").at(1).toElement().text();
    else
        contact = postDetailXml.elementsByTagName("branchContact").at(0).toElement().text();
    callMsgBox.exec();
    //makeCall(postDetailXml.elementsByTagName("branchContact").at(1).toElement().text());
}

void MainWindow::makeCall(QString text)
{ 
    TBuf<15> buffer(text.utf16());
    CTelephony::TTelNumber telNumber(buffer);
    iCallParams.iIdRestrict = CTelephony::ESendMyId;
    TRequestStatus iStatus;
    iTelephony->DialNewCall(iStatus, iCallParamsPckg, telNumber, iCallId);
}

void MainWindow::RunL()
        {

        }

TInt MainWindow::RunError(TInt aError)
        {
        QMessageBox msgBoxErr;
        QString strerr1;
        strerr1=QString("stack count:%1")
                        .arg(aError);
        msgBoxErr.setText(strerr1);
        msgBoxErr.exec();
        }
void MainWindow::DoCancel()
        {

        }

void MainWindow::splashTimeout()
{
    ui->splash->setVisible(false);
}

void MainWindow::finished(QNetworkReply *reply)
{
    if(reply->error() == QNetworkReply::NoError)
    {

        QString defaultFileName =
            QFileInfo(reply->request().url().toString()).fileName();
          QString fileName =
            QFileDialog::getSaveFileName(this,
                                         tr("Save File"),
                                         defaultFileName);
          if (fileName.isEmpty())
            return;

          // Construct a new request that stores the
          // file name that should be used when the
          // download is complete
          QNetworkRequest newRequest = reply->request();
          newRequest.setAttribute(QNetworkRequest::User,
                                  fileName);

          // Ask the network manager to download
          // the file and connect to the progress
          // and finished signals.
          //webView->page()->networkAccessManager();
          r = networkManager->get(newRequest);

          connect(r, SIGNAL(finished()),
                  this, SLOT(downloadingIssueFinished()));

    }
    else
    {
        QMessageBox msgBox;
         msgBox.setText(reply->errorString());
         msgBox.exec();
    }
}

void MainWindow::downloadingIssueFinished()
{
    qDebug()<<"123";
    QNetworkReply *reply = ((QNetworkReply*)sender());
      QNetworkRequest request = reply->request();
      QVariant v =
        request.attribute(QNetworkRequest::User);
      QString fileName = v.toString();
      QFile file(fileName);
      if (file.open(QFile::ReadWrite))
      {
          qDebug()<<"opened";
        file.write(reply->readAll());
}



}

void MainWindow::searchBox()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=searchbox&searchtext=";
    temp.append(ui->inputField_searchBox->text());
    QUrl url(temp);
    QNetworkReply* reply2 = searchBoxManager->get(QNetworkRequest(url));
}

void MainWindow::searchBoxResult(QNetworkReply *reply)
{
    searchBoxName.clear();
    searchBoxNameEn.clear();
    searchBoxAddress.clear();
    searchBoxType.clear();
    searchBoxCode.clear();
    qDebug()<<"SearchBox Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    searchBoxXml.setContent(string.toAscii());

    if(searchBoxXml.elementsByTagName("Table").count() > 0)
    {
        QStringList empty;
        for(int i=0;i<searchBoxXml.elementsByTagName("Table").count();i++)
        {
            empty.append("");
            QString tmp = searchBoxXml.elementsByTagName("estatename_c").at(i).toElement().text();
            tmp.append("\n");
            tmp.append(searchBoxXml.elementsByTagName("estatename_e").at(i).toElement().text());
            searchBoxName.append(tmp);
            searchBoxNameEn.append(searchBoxXml.elementsByTagName("estatename_e").at(i).toElement().text());
            searchBoxAddress.append(searchBoxXml.elementsByTagName("pc_addr").at(i).toElement().text());
            searchBoxType.append(searchBoxXml.elementsByTagName("estatetype").at(i).toElement().text());
            searchBoxCode.append(searchBoxXml.elementsByTagName("estatecode").at(i).toElement().text());
            qDebug()<<searchBoxType.at(i);
            qDebug()<<searchBoxCode.at(i);
        }

        tradeListModel *postModel = new tradeListModel(searchBoxName,searchBoxAddress,empty,empty,empty,empty,this);
        ui->list_searchBox->setModel(postModel);

        tradeListDelegate* delegate = new tradeListDelegate(this);

        ui->list_searchBox->setItemDelegate(delegate);

        ui->Content->setCurrentIndex(40);

    }
    else
    {
        ui->loading->setVisible(false);

         msgBox3.exec();

    }


}

void MainWindow::searchBoxClicked(QModelIndex index)
{
    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = searchBoxType.at(ui->list_searchBox->currentIndex().row());
    code = searchBoxCode.at(ui->list_searchBox->currentIndex().row());
    detail360Handler2(type,code);

    QString tmpCode = code;

    if(recentReadCode1 == "")
    {
        recentReadCode1 = tmpCode;
    }
        else if(recentReadCode2 == "")
        {
           if(recentReadCode1 != tmpCode)
            {
                recentReadCode2 = tmpCode;
            }
        }
            else if(recentReadCode3 == "")
            {
               if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                {
                    recentReadCode3 = tmpCode;
                }
               else if(recentReadCode2 == tmpCode)
               {
                   recentReadCode2 = recentReadCode1;
                   recentReadCode1 = tmpCode;
               }
            }
            else if(recentReadCode1 == tmpCode)
            {

            }
            else if(recentReadCode2 == tmpCode)
            {
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;
            }
            else if(recentReadCode3 == tmpCode)
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;

            }
            else
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;


            }
            settings.setValue("r1",recentReadCode1);
            settings.setValue("r2",recentReadCode2);
            settings.setValue("r3",recentReadCode3);


}

void MainWindow::DoHttpGet()
{

}

void MainWindow::quitApp()
{
    this->close();
}

void MainWindow::submitForm()
{
    if(ui->inputField_requestMail->text().indexOf("@") == -1)
    {
        QMessageBox msgBox;
        msgBox.setText("電子郵件格式不符");
        msgBox.exec();
    }

    else if(ui->inputField_requestName->text().length() > 0 && ui->inputField_requestMail->text().length() > 0
       && ui->inputField_requestInfo->text().length() > 0)
    {
        QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Enquiry.ashx?";
        temp.append("name=");
        temp.append(ui->inputField_requestName->text().trimmed());
        temp.append("&contact=");
        temp.append(ui->inputField_requestContact->text().trimmed());
        temp.append("&email=");
        temp.append(ui->inputField_requestMail->text().trimmed());
        temp.append("&detail=");
        temp.append(ui->inputField_requestInfo->text().trimmed());
        if(isDetail)
        {
            temp.append("&alic=");
            temp.append(postDetailXml.elementsByTagName("license").at(0).toElement().text().trimmed());
            temp.append("&ID=");
            temp.append(postDetailXml.elementsByTagName("ID").at(0).toElement().text().trimmed());
            pageDetail2();
        }
        else
        {
            temp.append("&alic=");
            temp.append(refNo);
            ui->Content->setCurrentIndex(10);
        }
        QMessageBox msgBox;
        msgBox.setText("已發送");
        msgBox.exec();
        qDebug()<<temp;
        QUrl url(temp);
        QNetworkAccessManager * man = new QNetworkAccessManager(this);
        QNetworkReply* reply2 = man->get(QNetworkRequest(url));
        resetForm();

    }
    else
    {
        QMessageBox msgBox;
         msgBox.setText("請填寫必須填寫的資訊");
         msgBox.exec();
    }

}

void MainWindow::resetForm()
{
    ui->inputField_requestContact->setText("");
    ui->inputField_requestInfo->setText("");
    ui->inputField_requestMail->setText("");
    ui->inputField_requestName->setText("");
}

void MainWindow::newPropFloorPlanDownload()
{
    if(newPropFloorPlanThumb.size() > 0)
    {
    QString temp3 = newPropFloorPlanThumb.at(0);
    QUrl url3(temp3);
    QNetworkReply* reply4 = newPropFloorPlanImageMan->get(QNetworkRequest(url3));
    ui->loading->setVisible(true);
    ui->label_61->setVisible(false);
    }
    else
    {
        ui->label_61->setVisible(true);
        ui->loading->setVisible(false);
        pageNewPropImage();
    }
}

void MainWindow::newPropImageDownload()
{
    if(newPropImageThumb.size() > 0)
    {
    QString temp3 = newPropImageThumb.at(0);
    QUrl url3(temp3);
    QNetworkReply* reply4 = newPropListImageMan->get(QNetworkRequest(url3));
    ui->loading->setVisible(true);
    ui->label_62->setVisible(false);
    }
    else
    {
        ui->label_62->setVisible(true);
        ui->loading->setVisible(false);
        pageNewPropFloorPlan();
    }
}

void MainWindow::newPropContactClicked(QModelIndex index)
{
    QString tmp = "確定致電";
    QString tmp2 = newPropXml.elementsByTagName("Branch").at(ui->list_newPropContact->currentIndex().row()).toElement().elementsByTagName("Name").at(0).toElement().text();
    tmp2.replace("‧",".");
    tmp.append(tmp2);
    tmp.append("?");
    callMsgBox.setText(tmp);
    contact = newPropXml.elementsByTagName("Branch").at(ui->list_newPropContact->currentIndex().row()).toElement().elementsByTagName("Contact").at(0).toElement().text();
    contact.replace(" ","");
    callMsgBox.exec();
}

void MainWindow::newPropVideoClicked(QModelIndex index)
{
    QString temp = newPropVideoUrl.at(ui->list_newPropVideo->currentIndex().row());
    QUrl url(temp);
    nam->get(QNetworkRequest(QUrl(url)));
}

void MainWindow::newPropPreviewFloorPlanImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->newPropPreviewImage_2->setPixmap(QPixmap::fromImage(image).scaled(QSize(360,500),Qt::KeepAspectRatio));
        ui->Content->setCurrentIndex(38);
    }

}
}

void MainWindow::newPropFloorPlanClicked(QModelIndex index)
{
    QString temp = newPropXml.elementsByTagName("Prefix").at(0).toElement().text();
    temp.append(newPropXml.elementsByTagName("FloorPlans").at(0).toElement().elementsByTagName("Full").at(ui->list_newPropImage->currentIndex().row()).toElement().text());
    temp.prepend("http://www.nuthon.com/temp/ImageResize.ashx?ImageUrl=");
    temp.append("&TargetWidth=800&TargetHeight=800");
    ui->webView_3->load(temp);
    ui->Content->setCurrentIndex(38);
    QUrl url(temp);

    //QNetworkReply* reply2 = newPropPreviewFloorPlanImageMan->get(QNetworkRequest(url));
}

void MainWindow::newPropPreviewImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->newPropPreviewImage->setPixmap(QPixmap::fromImage(image).scaled(QSize(360,500),Qt::KeepAspectRatio));
        ui->Content->setCurrentIndex(37);
    }

}
}

void MainWindow::newPropImageClicked(QModelIndex index)
{
    QString temp = newPropXml.elementsByTagName("Prefix").at(0).toElement().text();
    temp.append(newPropXml.elementsByTagName("Images").at(0).toElement().elementsByTagName("Full").at(ui->list_newPropFloorPlan->currentIndex().row()).toElement().text());

    QUrl url(temp);

    QNetworkReply* reply2 = newPropPreviewImageMan->get(QNetworkRequest(url));
}

void MainWindow::newPropDetailResult(QNetworkReply *reply)
{
    newPropImageName.clear();
    newPropImageThumb.clear();
    newPropFloorPlanName.clear();
    newPropFloorPlanThumb.clear();
    newPropBranchName.clear();
    newPropBranchAddress.clear();
    emptyList.clear();
    newPropVideoName.clear();
    newPropVideoThumb.clear();
    newPropVideoUrl.clear();
    newPropEmail.clear();

    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);


    newPropXml.setContent(string.toAscii());
    QString tmpName = newPropXml.elementsByTagName("Name").at(0).toElement().text();
    tmpName.replace("‧",".");
    ui->newPropName->setText(tmpName);
    ui->newPropAddress->setText(newPropXml.elementsByTagName("Address").at(0).toElement().text());
    if(newPropXml.elementsByTagName("BlockCnt").at(0).toElement().text().length() > 0)
        ui->newPropBlockNumber->setText(newPropXml.elementsByTagName("BlockCnt").at(0).toElement().text());
    else
        ui->newPropBlockNumber->setText("-");
    if(newPropXml.elementsByTagName("Size").at(0).toElement().text().length() > 0)
        ui->newPropArea->setText(newPropXml.elementsByTagName("Size").at(0).toElement().text());
    else
        ui->newPropArea->setText("-");
    if(newPropXml.elementsByTagName("Layout").at(0).toElement().text().length() > 0)
    {
        QString tmp;
        for(int i=0;i<newPropXml.elementsByTagName("Layout").at(0).toElement().elementsByTagName("string").count();i++)
        {
           tmp.append(newPropXml.elementsByTagName("Layout").at(0).toElement().elementsByTagName("string").at(i).toElement().text());
           tmp.append("\n");
        }
        ui->newPropRoom->setText(tmp);
    }
    else
        ui->newPropRoom->setText("-");
    if(newPropXml.elementsByTagName("DeveloperName").at(0).toElement().text().length() > 0)
    {
        QString tmp;
        for(int i=0;i<newPropXml.elementsByTagName("DeveloperName").at(0).toElement().elementsByTagName("string").count();i++)
        {
           tmp.append(newPropXml.elementsByTagName("DeveloperName").at(0).toElement().elementsByTagName("string").at(i).toElement().text());
           tmp.append("\n");
        }
        ui->newPropDeveloper->setText(tmp);
    }
    else
        ui->newPropDeveloper->setText("-");
    if(newPropXml.elementsByTagName("UnitCnt").at(0).toElement().text().length() > 0)
        ui->newPropUnitNumber->setText(newPropXml.elementsByTagName("UnitCnt").at(0).toElement().text());
    else
        ui->newPropUnitNumber->setText("-");
    if(newPropXml.elementsByTagName("FloorCnt").at(0).toElement().text().length() > 0)
        ui->newPropFloorNumber->setText(newPropXml.elementsByTagName("FloorCnt").at(0).toElement().text());
    else
        ui->newPropFloorNumber->setText("-");
    if(newPropXml.elementsByTagName("StartDate").at(0).toElement().text().length() > 0)
        ui->newPropDate->setText(newPropXml.elementsByTagName("StartDate").at(0).toElement().text());
    else
        ui->newPropDate->setText("-");


    for(int i=0;i<newPropXml.elementsByTagName("FloorPlans").at(0).toElement().elementsByTagName("Photo").count();i++)
    {

        newPropImageName.append(newPropXml.elementsByTagName("FloorPlans").at(0).toElement().elementsByTagName("Photo").at(i).toElement().attribute("Caption"));
        QString tmp = newPropXml.elementsByTagName("Prefix").at(0).toElement().text();
        tmp.append(newPropXml.elementsByTagName("FloorPlans").at(0).toElement().elementsByTagName("Thumb").at(i).toElement().text());

        newPropImageThumb.append(tmp);
        qDebug()<<"name : "<<newPropImageName.at(i);
        qDebug()<<"thumb : "<<newPropImageThumb.at(i);
    }


    for(int i=0;i<newPropXml.elementsByTagName("Images").at(0).toElement().elementsByTagName("Photo").count();i++)
    {
        newPropFloorPlanName.append(newPropXml.elementsByTagName("Images").at(0).toElement().elementsByTagName("Photo").at(i).toElement().attribute("Caption"));
        QString tmp = newPropXml.elementsByTagName("Prefix").at(0).toElement().text();
        tmp.append(newPropXml.elementsByTagName("Images").at(0).toElement().elementsByTagName("Thumb").at(i).toElement().text());
        newPropFloorPlanThumb.append(tmp);

    }

    for(int i=0;i<newPropXml.elementsByTagName("Branch").count();i++)
    {
        if(newPropXml.elementsByTagName("Branches").at(0).toElement().elementsByTagName("Name").at(i).toElement().text() != "")
        {
            QString tmp = newPropXml.elementsByTagName("Branches").at(0).toElement().elementsByTagName("Name").at(i).toElement().text();
            tmp.replace("‧",".");
            newPropBranchName.append(tmp);
        }
        else
            newPropBranchName.append("");
        if(newPropXml.elementsByTagName("Branches").at(0).toElement().elementsByTagName("Contact").at(i).toElement().text() != "")
            newPropBranchAddress.append(newPropXml.elementsByTagName("Branches").at(0).toElement().elementsByTagName("Contact").at(i).toElement().text());
        else
            newPropBranchAddress.append("");

        emptyList.append("");
    }
    for(int i=0;i<newPropXml.elementsByTagName("Enquiry").at(0).toElement().elementsByTagName("string").count();i++)
    {
        newPropEmail.append(newPropXml.elementsByTagName("Enquiry").at(0).toElement().elementsByTagName("string").at(i).toElement().text());

    }


    for(int i=0;i<newPropXml.elementsByTagName("Video").count();i++)
    {
        newPropVideoUrl.append(newPropXml.elementsByTagName("VideoUrl").at(i).toElement().text());
        newPropVideoName.append(newPropXml.elementsByTagName("VideoTitle").at(i).toElement().text());
        newPropVideoThumb.append(newPropXml.elementsByTagName("VideoThumb").at(i).toElement().text());

    }

    tradeListModel *postModel = new tradeListModel(newPropBranchName,newPropBranchAddress,newPropEmail,emptyList,emptyList,emptyList,this);
    ui->list_newPropContact->setModel(postModel);

    tradeListDelegate* delegate = new tradeListDelegate(this);

    ui->list_newPropContact->setItemDelegate(delegate);

    QString temp = newPropXml.elementsByTagName("Prefix").at(0).toElement().text();
    temp.append(newPropXml.elementsByTagName("Thumb").at(0).toElement().text());
    QUrl url(temp);
    QNetworkReply* reply2 = newPropDetailImageMan->get(QNetworkRequest(url));

    qDebug()<<"FloorPlan : "<<newPropImageThumb.size();
    qDebug()<<"Image : "<<newPropFloorPlanThumb.size();









}

void MainWindow::newPropVideoImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Video Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    newPropVideoImage[videoCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
    videoCount++;
}
}

    if(videoCount == newPropVideoThumb.size())
    {

        qDebug()<<"Video Download  floorCount : "<<videoCount;
        floorplanlistmodel *postModel = new floorplanlistmodel(newPropVideoName,newPropVideoImage,this);
        ui->list_newPropVideo->setModel(postModel);
        floorplanlistdelegate* delegate = new floorplanlistdelegate(this);
        ui->list_newPropVideo->setItemDelegate(delegate);

        videoCount=0;
        ui->loading->setVisible(false);

    }
    else
    {

        qDebug()<<"Video Download : "<<videoCount;
        QUrl url(newPropVideoThumb.at(videoCount));
        QNetworkReply* reply2 = newPropVideoImageMan->get(QNetworkRequest(url));
}
}


void MainWindow::newPropListImageDownloaded(QNetworkReply *reply)
{

    qDebug()<<"New Prop Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    newPropListImage[imageCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
    imageCount++;
}
}
    int limit = newPropImageThumb.size();
    if(limit > 100)
        limit = 100;

    //if(imageCount == newPropImageThumb.size()-1)
    if(imageCount == limit)
    {

        qDebug()<<"New Prop Image Download  floorCount : "<<imageCount;
        floorplanlistmodel *postModel = new floorplanlistmodel(newPropImageName,newPropListImage,this);
        ui->list_newPropImage->setModel(postModel);
        floorplanlistdelegate* delegate = new floorplanlistdelegate(this);
        ui->list_newPropImage->setItemDelegate(delegate);
        pageNewPropFloorPlan();

        imageCount=0;
        ui->loading->setVisible(false);

    }
    else
    {

        qDebug()<<"New Prop Image Download : "<<imageCount;
        QUrl url(newPropImageThumb.at(imageCount));
        QNetworkReply* reply2 = newPropListImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::newPropFloorPlanImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    newPropFloorPlanImage[floorCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
    floorCount++;
}
}

    if(floorCount == newPropFloorPlanThumb.size())
    {

        qDebug()<<"Image Download  floorCount : "<<floorCount;
        floorplanlistmodel *postModel = new floorplanlistmodel(newPropFloorPlanName,newPropFloorPlanImage,this);
        ui->list_newPropFloorPlan->setModel(postModel);
        floorplanlistdelegate* delegate = new floorplanlistdelegate(this);
        ui->list_newPropFloorPlan->setItemDelegate(delegate);
        pageNewPropImage();
        floorCount=0;
        ui->loading->setVisible(false);


    }
    else
    {

        qDebug()<<"Image Download : "<<floorCount;
        QUrl url(newPropFloorPlanThumb.at(floorCount));
        QNetworkReply* reply2 = newPropFloorPlanImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::newPropDetailImageDownloaded(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->newPropImage->setPixmap(QPixmap::fromImage(image.scaled(QSize(80,80),Qt::KeepAspectRatio)));       
        ui->Content->setCurrentIndex(32);
        ui->loading->setVisible(false);
    }
}
}

void MainWindow::newPropChangeToHK()
{
    ui->loading->setVisible(true);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewPropSearch.ashx?rankGroup=hk";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropMan->get(QNetworkRequest(url));
}

void MainWindow::newPropChangeToKL()
{
    ui->loading->setVisible(true);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewPropSearch.ashx?rankGroup=kl";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropMan->get(QNetworkRequest(url));
}

void MainWindow::newPropChangeToNT()
{
    ui->loading->setVisible(true);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewPropSearch.ashx?rankGroup=nt";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropMan->get(QNetworkRequest(url));
}

void MainWindow::newPropChangeToHOT()
{
    ui->loading->setVisible(true);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewPropSearch.ashx?rankGroup=home";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropMan->get(QNetworkRequest(url));
}

void MainWindow::newPropResult(QNetworkReply *reply)
{
    qDebug()<<"New Prop Download";
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtAreaXml.setContent(string.toAscii());

    for(int i=0;i<districtAreaXml.elementsByTagName("NewProp").count();i++)
    {
        districtAreaName.append(districtAreaXml.elementsByTagName("Name").at(i).toElement().text());
        districtAreaNameEn.append(districtAreaXml.elementsByTagName("Address").at(i).toElement().text());
        QString tmp = districtAreaXml.elementsByTagName("Prefix").at(i).toElement().text();
        tmp.append(districtAreaXml.elementsByTagName("Thumb").at(i).toElement().text());
        districtAreaThumb.append(tmp);
        districtAreaCode.append(districtAreaXml.elementsByTagName("id").at(i).toElement().text());
    }
    qDebug()<<"checkPoint 1";
    QUrl url(districtAreaThumb.at(0));
    QNetworkReply* reply2 = newPropImageMan->get(QNetworkRequest(url));

}

void MainWindow::newPropImageDownloaded(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    districtThumb[districtCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
}
}

    if(districtCount == districtAreaThumb.size()-1)
    {

        qDebug()<<"Count : "<<districtCount;
        QStringList a;
        districtAreaListModel *postModel = new districtAreaListModel(districtAreaName,districtAreaNameEn,a,a,a,districtThumb,this);
        ui->list_newProp->setModel(postModel);

        districtAreaListDelegate* delegate = new districtAreaListDelegate(this);

        ui->list_newProp->setItemDelegate(delegate);

        ui->loading->setVisible(false);
        districtCount=0;


    }
    else
    {
        districtCount++;
        qDebug()<<"checkPoint count : "<<districtCount;
        QUrl url(districtAreaThumb.at(districtCount));
        QNetworkReply* reply = newPropImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::newPropClicked(QModelIndex index)
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewProp.ashx?id=";
    temp.append(districtAreaCode.at(ui->list_newProp->currentIndex().row()));
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropDetailMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::geoLocationPostResult(QNetworkReply *reply)
{
    name.clear();
    suite.clear();
    refNoList.clear();
    area.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    price.clear();

    qDebug()<<"GPS Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtListXml.setContent(string.toAscii());

    for(int i=0;i<districtListXml.elementsByTagName("Post").count();i++)
    {

        QString tmp = districtListXml.elementsByTagName("bigestCName").at(i).toElement().text();
        tmp.append(districtListXml.elementsByTagName("estCName").at(i).toElement().text());
        tmp.append(districtListXml.elementsByTagName("blgCName").at(i).toElement().text());
        QString tmpUnit = districtListXml.elementsByTagName("unit").at(i).toElement().text();
        if(tmpUnit.length() > 0)
        {
        tmp.append("(");
        tmp.append(tmpUnit);
        tmp.append("室)");
        }
        if(tmp != "")
        {

        name.append(tmp);
        }
        else
        {
            tmp = districtListXml.elementsByTagName("address").at(i).toElement().text();
            if(tmpUnit.length() > 0)
            {
            tmp.append("(");
            tmp.append(tmpUnit);
            tmp.append("室)");
            }
        name.append(tmp);
        }
        suite.append(districtListXml.elementsByTagName("suiteCount").at(i).toElement().text());
        refNoList.append(districtListXml.elementsByTagName("refNo").at(i).toElement().text());
        area.append(districtListXml.elementsByTagName("scpCName").at(i).toElement().text());
        QString tmpPrice_s = districtListXml.elementsByTagName("price").at(i).toElement().text();
        tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());

        int tmpPrice = tmpPrice_s.toInt();
        qDebug()<<tmpPrice;
        if(tmpPrice > 0)
        {
            tmpPrice_s.prepend("$");
            if(tmpPrice > 100000)
            {
                tmpPrice = tmpPrice/10000;
                tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
            }
            if(tmpPrice > 999)
            {
                tmpPrice_s.insert(1,",");
            }
            tmpPrice_s.append("萬");
            price.append(tmpPrice_s);
        }
        else
        {

            tmpPrice_s = districtListXml.elementsByTagName("rental").at(i).toElement().text();
            tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());
            tmpPrice = tmpPrice_s.toInt();
            tmpPrice_s.prepend("$");
            if(tmpPrice > 9999)
                tmpPrice_s.insert(2,",");
            else if(tmpPrice > 999)
                tmpPrice_s.insert(1,",");
            price.append(tmpPrice_s);
        }
        QString tmpRoom = districtListXml.elementsByTagName("roomCount").at(i).toElement().text();
        QString tmpSuite = districtListXml.elementsByTagName("suiteCount").at(i).toElement().text();
        int tmpSuite_i = tmpSuite.toInt();
        int tmpRoom_i = tmpRoom.toInt();
        if(tmpRoom_i > 0)
        {
        tmpRoom.append("房");
        if(tmpSuite_i > 0)
        {
            tmpRoom.append("(");
            tmpRoom.append(tmpSuite);
            tmpRoom.append("套房)");
        }
        room.append(tmpRoom);
        }
        else
        room.append("");
        thumb.append(districtListXml.elementsByTagName("thumb").at(i).toElement().text());
        QString tmppps_s = districtListXml.elementsByTagName("unitPrice").at(i).toElement().text();
        tmppps_s.remove(tmppps_s.length()-5,tmppps_s.length());

        int tmppps = tmppps_s.toInt();
        qDebug()<<tmppps;
        if(tmppps > 0)
            pps.append(districtListXml.elementsByTagName("unitPrice").at(i).toElement().text());
        else
            pps.append(districtListXml.elementsByTagName("unitRental").at(i).toElement().text());
        QString tmpSize = districtListXml.elementsByTagName("area").at(i).toElement().text();
        tmpSize.remove(tmpSize.length()-3,tmpSize.length());
        tmpSize.append("呎");
        if(districtListXml.elementsByTagName("approx").at(i).toElement().text() == "true")
            tmpSize.prepend("約");
        size.append(tmpSize);

    }
    qDebug()<<"GPS Download : "<<thumb.size();
        QUrl url(thumb.at(0));
        QNetworkReply* reply2 = geoPostImageMan->get(QNetworkRequest(url));
    qDebug()<<"GPS Download";
}

void MainWindow::geoLocationPostImageDownloaded(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    postThumb[postCount] = QPixmap::fromImage(image);
}
}

    if(postCount == thumb.size()-1)
    {

        qDebug()<<"District Image Download  postCount : "<<postCount;
        postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
        ui->list_geoLcationPost->setModel(postModel);

        postSearchListDelegate* delegate = new postSearchListDelegate(this);

        ui->list_geoLcationPost->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(28);
        postCount = 0;

    }
    else
    {
        postCount++;
        QUrl url(thumb.at(postCount));
        QNetworkReply* reply = geoPostImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::geolocationchangetoRent()
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?lat=22.284500&long=114.21600&aradius=1000&pt=r";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geoPostMan->get(QNetworkRequest(url));
    geoSell=false;
}

void MainWindow::geolocationchangetoSell()
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?lat=22.284500&long=114.21600&aradius=1000&pt=s";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geoPostMan->get(QNetworkRequest(url));
    geoSell=true;
}

void MainWindow::geoLocationPostClicked(QModelIndex index)
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
    refNo = refNoList.at(ui->list_geoLcationPost->currentIndex().row());
    temp.append(refNo);
    if(geoSell)
        temp.append("&pt=s");
    else
        temp.append("&pt=r");

    QUrl url(temp);
    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::geoLocation360Result(QNetworkReply *reply)
{
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    qDebug()<<"GPS 360 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtAreaXml.setContent(string.toAscii());
    qDebug()<<"count : "<<districtAreaXml.elementsByTagName("Table").count();

    for(int i=0;i<districtAreaXml.elementsByTagName("Table").count();i++)
    {
        districtAreaName.append(districtAreaXml.elementsByTagName("namec").at(i).toElement().text());
        districtAreaNameEn.append(districtAreaXml.elementsByTagName("namee").at(i).toElement().text());
        districtAreaThumb.append(districtAreaXml.elementsByTagName("path").at(i).toElement().text());
        districtAreaCode.append(districtAreaXml.elementsByTagName("code").at(i).toElement().text());
        districtAreaType.append(districtAreaXml.elementsByTagName("type").at(i).toElement().text());

        QString tmpPPS = districtAreaXml.elementsByTagName("cprice30").at(i).toElement().text();
        int tmpPPS_i = tmpPPS.toInt();
        if(tmpPPS_i > 9999)
            tmpPPS.insert(2,",");
        else if(tmpPPS_i > 999)
            tmpPPS.insert(1,",");
        tmpPPS.append("/呎");
        tmpPPS.prepend("$");
        districtAreaPPS.append(tmpPPS);

        QString tmp = districtAreaXml.elementsByTagName("cprice30up").at(i).toElement().text();
        tmp.remove(tmp.length()-5,tmp.length());
        int tmp2 = tmp.toInt();
        if(tmp2 > 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp);
            districtAreaPrice.append("1");
        }
        else if(tmp2 < 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp.remove(0,1));
            districtAreaPrice.append("-1");
        }
        else
        {
            districtAreaPercent.append("");
            districtAreaPrice.append("0");
        }
    }

    QUrl url(districtAreaThumb.at(0));
    QNetworkReply* reply2 = geo360ImageMan->get(QNetworkRequest(url));
}

void MainWindow::geoLocation360ImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    districtThumb[districtCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
}
}

    if(districtCount == districtAreaThumb.size()-1)
    {

        qDebug()<<"District Image Download  postCount : "<<districtCount;
        districtAreaListModel *postModel = new districtAreaListModel(districtAreaName,districtAreaNameEn,districtAreaPPS,districtAreaPercent,districtAreaPrice,districtThumb,this);

        ui->list_geoLcation360->setModel(postModel);

        districtAreaListDelegate* delegate = new districtAreaListDelegate(this);

        ui->list_geoLcation360->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(29);
        districtCount=0;

    }
    else
    {
        districtCount++;
        QUrl url(districtAreaThumb.at(districtCount));
        QNetworkReply* reply = geo360ImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::geoLocation360Clicked(QModelIndex index)
{
    detail360Handler2(districtAreaType.at(ui->list_geoLcation360->currentIndex().row()),districtAreaCode.at(ui->list_geoLcation360->currentIndex().row()));
}

void MainWindow::geolocationchangeto500m()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=gps&lat=22.284500&long=114.21600&r=500";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geo360Man->get(QNetworkRequest(url));
}

void MainWindow::geolocationchangeto1000m()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=gps&lat=22.284500&long=114.21600&r=1000";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geo360Man->get(QNetworkRequest(url));
}

void MainWindow::geolocationchangeto1500m()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=gps&lat=22.284500&long=114.21600&r=1500";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geo360Man->get(QNetworkRequest(url));
}

void MainWindow::record360Clean()
{
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    record360 = "";
    settings.setValue("record360",record360);
    ui->Content->setCurrentIndex(26);
}

void MainWindow::recordPostClean()
{
    name.clear();
    suite.clear();
    refNoList.clear();
    area.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    price.clear();
    recordPost="";
    recordRent="";
    settings.setValue("recordPost",recordPost);
    settings.setValue("recordRent",recordRent);
    ui->Content->setCurrentIndex(26);
}

void MainWindow::record360Check()
{
    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = districtAreaType.at(ui->list_record360->currentIndex().row());
    code = districtAreaCode.at(ui->list_record360->currentIndex().row());

    QString tmpCode = code;

    if(recentReadCode1 == "")
    {
        recentReadCode1 = tmpCode;
    }
        else if(recentReadCode2 == "")
        {
           if(recentReadCode1 != tmpCode)
            {
                recentReadCode2 = tmpCode;
            }
        }
            else if(recentReadCode3 == "")
            {
               if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                {
                    recentReadCode3 = tmpCode;
                }
               else if(recentReadCode2 == tmpCode)
               {
                   recentReadCode2 = recentReadCode1;
                   recentReadCode1 = tmpCode;
               }
            }
            else if(recentReadCode1 == tmpCode)
            {

            }
            else if(recentReadCode2 == tmpCode)
            {
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;
            }
            else if(recentReadCode3 == tmpCode)
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;

            }
            else
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;


            }
            settings.setValue("r1",recentReadCode1);
            settings.setValue("r2",recentReadCode2);
            settings.setValue("r3",recentReadCode3);

    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp.append("&type=");
    temp.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp2.append("&type=");
    temp2.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp3.append("&type=");
    temp3.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp4.append("&type=");
    temp4.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp5.append("&type=");
    temp5.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp6.append("&type=");
    temp6.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(districtAreaCode.at(ui->list_record360->currentIndex().row()));
    temp7.append("&type=");
    temp7.append(districtAreaType.at(ui->list_record360->currentIndex().row()));

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
}

void MainWindow::record360Delete()
{

    QString tmp = districtAreaCode.at(ui->list_record360->currentIndex().row());;
    tmp.append(",");
    record360.replace(tmp,"");
    settings.setValue("record360",record360);
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=bookmark&p1=";
    temp.append(record360);
    QUrl url(temp);
    qDebug()<<temp;
    if(record360.length() > 1)
        QNetworkReply* reply = record360Man->get(QNetworkRequest(url));
    else
    {
        QMessageBox msgBox;
         msgBox.setText("未有任何樓盤360記錄");
         msgBox.exec();
    }
}

void MainWindow::record360ListClicked(QModelIndex index)
{
    record360MsgBox.exec();
}

void MainWindow::record360ListResult(QNetworkReply *reply)
{
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    qDebug()<<"Record 360 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtAreaXml.setContent(string.toAscii());
    qDebug()<<"Record 360 Download";
    for(int i=0;i<districtAreaXml.elementsByTagName("Table").count();i++)
    {
        districtAreaName.append(districtAreaXml.elementsByTagName("namec").at(i).toElement().text());
        districtAreaNameEn.append(districtAreaXml.elementsByTagName("namee").at(i).toElement().text());
        districtAreaThumb.append(districtAreaXml.elementsByTagName("path").at(i).toElement().text());
        districtAreaCode.append(districtAreaXml.elementsByTagName("code").at(i).toElement().text());
        districtAreaType.append(districtAreaXml.elementsByTagName("type").at(i).toElement().text());

        if(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("cprice30").count() >0)
        {
        QString tmpPPS = districtAreaXml.elementsByTagName("cprice30").at(i).toElement().text();
        int tmpPPS_i = tmpPPS.toInt();
        if(tmpPPS_i > 9999)
            tmpPPS.insert(2,",");
        else if(tmpPPS_i > 999)
            tmpPPS.insert(1,",");
        tmpPPS.append("/呎");
        tmpPPS.prepend("$");
        districtAreaPPS.append(tmpPPS);
        }
        else
            districtAreaPPS.append("");

        QString tmp = districtAreaXml.elementsByTagName("cprice30up").at(i).toElement().text();
        tmp.remove(tmp.length()-5,tmp.length());
        int tmp2 = tmp.toInt();
        if(tmp2 > 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp);
            districtAreaPrice.append("1");
        }
        else if(tmp2 < 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp.remove(0,1));
            districtAreaPrice.append("-1");
        }
        else
        {
            districtAreaPercent.append("");
            districtAreaPrice.append("0");
        }



    }

    qDebug()<<"Record 360 Download";
    QUrl url(districtAreaThumb.at(0));
    QNetworkReply* reply2 = record360ImageMan->get(QNetworkRequest(url));
}

void MainWindow::record360ListImageDownladed(QNetworkReply *reply)
{
    qDebug()<<"District Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    districtThumb[districtCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
}
}

    if(districtCount == districtAreaThumb.size()-1)
    {
        isRecord = true;

        qDebug()<<"District Image Download  postCount : "<<districtCount;
        districtAreaListModel *postModel = new districtAreaListModel(districtAreaName,districtAreaNameEn,districtAreaPPS,districtAreaPercent,districtAreaPrice,districtThumb,this);
        ui->list_record360->setModel(postModel);

        districtAreaListDelegate* delegate = new districtAreaListDelegate(this);

        ui->list_record360->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(27);
        if(record360.count(",") > districtAreaCode.size())
        {
            QMessageBox msgBox;
            int tmp2 = record360.count(",") - districtAreaCode.size();
            record360 = "";
            for(int i=0;i<districtAreaCode.size();i++)
            {
                record360.append(districtAreaCode.at(i));
                record360.append(",");
            }
            QString tmp = "另有";
            QString tmp3 = tmp3.setNum(tmp2);
            tmp.append(tmp3);
            tmp.append("個過往搵樓記錄已被移除或刪除。");
             msgBox.setText(tmp);
             msgBox.exec();
        }
        districtCount=0;

    }
    else
    {
        districtCount++;
        QUrl url(districtAreaThumb.at(districtCount));
        QNetworkReply* reply2 = record360ImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::record360View()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=bookmark&p1=";
    temp.append(record360);
    QUrl url(temp);
    qDebug()<<temp;
    if(record360.length() > 1)
    QNetworkReply* reply = record360Man->get(QNetworkRequest(url));
    else
    {
        QMessageBox msgBox;
         msgBox.setText("未有任何樓盤360記錄");
         msgBox.exec();
    }
}

void MainWindow::recordChangetoRent()
{
    if(recordRent.length() > 1)
    {
        name.clear();
        suite.clear();
        refNoList.clear();
        area.clear();
        room.clear();
        thumb.clear();
        pps.clear();
        size.clear();
        price.clear();
    pt = "pt=r";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
    temp.append(recordRent);
    QUrl url(temp);
    qDebug()<<temp;

    QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
}
    else
    {
        QMessageBox msgBox;
         msgBox.setText("未有任何搵樓記錄");
         msgBox.exec();
    }
}

void MainWindow::recordChangetoSell()
{
    if(recordPost.length() > 1)
    {
        name.clear();
        suite.clear();
        refNoList.clear();
        area.clear();
        room.clear();
        thumb.clear();
        pps.clear();
        size.clear();
        price.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
    temp.append(recordPost);
    QUrl url(temp);
    qDebug()<<temp;

    QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
}
    else
    {
        QMessageBox msgBox;
         msgBox.setText("未有任何搵樓記錄");
         msgBox.exec();
    }
}

void MainWindow::recordPostListResult(QNetworkReply *reply)
{
    qDebug()<<"Record Post Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtListXml.setContent(string.toAscii());
    qDebug()<<districtListXml.elementsByTagName("Post").count();

    for(int i=0;i<districtListXml.elementsByTagName("Post").count();i++)
    {

        QString tmp = districtListXml.elementsByTagName("bigestCName").at(i).toElement().text();
        tmp.append(districtListXml.elementsByTagName("estCName").at(i).toElement().text());
        tmp.append(districtListXml.elementsByTagName("blgCName").at(i).toElement().text());
        QString tmpUnit = districtListXml.elementsByTagName("unit").at(i).toElement().text();
        if(tmpUnit.length() > 0)
        {
        tmp.append("(");
        tmp.append(tmpUnit);
        tmp.append("室)");
        }
        if(tmp != "")
        {

        name.append(tmp);
        }
        else
        {
            tmp = districtListXml.elementsByTagName("address").at(i).toElement().text();
            if(tmpUnit.length() > 0)
            {
            tmp.append("(");
            tmp.append(tmpUnit);
            tmp.append("室)");
            }
        name.append(tmp);
        }
        suite.append(districtListXml.elementsByTagName("suiteCount").at(i).toElement().text());
        refNoList.append(districtListXml.elementsByTagName("refNo").at(i).toElement().text());
        area.append(districtListXml.elementsByTagName("scpCName").at(i).toElement().text());
        QString tmpPrice_s = districtListXml.elementsByTagName("price").at(i).toElement().text();
        tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());

        int tmpPrice = tmpPrice_s.toInt();
        qDebug()<<tmpPrice;
        if(pt == "pt=s")
        {
            tmpPrice_s.prepend("$");
            if(tmpPrice > 100000)
            {
                tmpPrice = tmpPrice/10000;
                tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
            }
            if(tmpPrice > 9999)
            {
                if(tmpPrice == 10000)
                {
                   tmpPrice_s = "1億";
                }
                else
                {
                    tmpPrice_s.insert(1,"億");
                    tmpPrice_s.append("萬");
                }

            }
            else if(tmpPrice > 999)
            {
                tmpPrice_s.insert(1,",");
                tmpPrice_s.append("萬");
            }
            else
                tmpPrice_s.append("萬");

            //tmpPrice_s.prepend("售");
            price.append(tmpPrice_s);
        }
        else
        {

            tmpPrice_s = districtListXml.elementsByTagName("rental").at(i).toElement().text();
            tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());
            tmpPrice = tmpPrice_s.toInt();
            tmpPrice_s.prepend("$");
            if(tmpPrice > 99999)
                tmpPrice_s.insert(4,",");
            else if(tmpPrice > 9999)
                tmpPrice_s.insert(3,",");
            else if(tmpPrice > 999)
                tmpPrice_s.insert(2,",");
            //tmpPrice_s.prepend("租");
            price.append(tmpPrice_s);
        }
        QString tmpRoom = districtListXml.elementsByTagName("roomCount").at(i).toElement().text();
        QString tmpSuite = districtListXml.elementsByTagName("suiteCount").at(i).toElement().text();
        int tmpSuite_i = tmpSuite.toInt();
        int tmpRoom_i = tmpRoom.toInt();
        if(tmpRoom_i > 0)
        {
        tmpRoom.append("房");
        if(tmpSuite_i > 0)
        {
            tmpRoom.append("(");
            tmpRoom.append(tmpSuite);
            tmpRoom.append("套房)");
        }
        room.append(tmpRoom);
        }
        else
        room.append("");
        thumb.append(districtListXml.elementsByTagName("thumb").at(i).toElement().text());
        QString tmppps_s = districtListXml.elementsByTagName("unitPrice").at(i).toElement().text();
        tmppps_s.remove(tmppps_s.length()-5,tmppps_s.length());

        int tmppps = tmppps_s.toInt();
        qDebug()<<tmppps;
        if(tmppps > 0)
            pps.append(districtListXml.elementsByTagName("unitPrice").at(i).toElement().text());
        else
            pps.append(districtListXml.elementsByTagName("unitRental").at(i).toElement().text());
        QString tmpSize = districtListXml.elementsByTagName("area").at(i).toElement().text();
        tmpSize.remove(tmpSize.indexOf("."),tmpSize.length());
        tmpSize.append("呎");
        if(districtListXml.elementsByTagName("approx").at(i).toElement().text() == "true")
            tmpSize.prepend("約");
        size.append(tmpSize);

    }
    qDebug()<<"Record Download : "<<thumb.size();
        QUrl url(thumb.at(0));
        QNetworkReply* reply2 = recordPostImageMan->get(QNetworkRequest(url));
    qDebug()<<"Record Download";
}

void MainWindow::recordPostListImageDownladed(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    postThumb[recordPostCount] = QPixmap::fromImage(image);
    recordPostCount++;
}
}

    if(recordPostCount == thumb.size())
    {

        qDebug()<<"District Image Download  recordPostCount : "<<recordPostCount;
        postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
        ui->list_recordPost->setModel(postModel);

        postSearchListDelegate* delegate = new postSearchListDelegate(this);

        ui->list_recordPost->setItemDelegate(delegate);


        qDebug("0");
        if(pt == "pt=s")
        {
            if(recordPost.count(",") > refNoList.size())
            {
                qDebug("1");
                QMessageBox msgBox;
                qDebug("2");
                int tmp2 = recordPost.count(",") - refNoList.size();
                qDebug("3");
                recordPost = "";
                qDebug("4");
                for(int i=0;i<refNoList.size();i++)
                {
                    recordPost.append(refNoList.at(i));
                    recordPost.append(",");
                }
                settings.setValue("recordPost",recordPost);
                qDebug("5");
                QString tmp = "另有";
                QString tmp3;
                qDebug("6");
                tmp3.setNum(tmp2);
                tmp.append(tmp3);
                qDebug("7");
                tmp.append("個過往搵樓記錄已被移除或刪除。");
                 msgBox.setText(tmp);
                 msgBox.exec();
                 qDebug("8");
            }



                pageNumber = ui->Content->currentIndex();
                ui->Content->setCurrentIndex(30);
                recordPostCount = 0;


        }
        else
        {
            pageNumber = ui->Content->currentIndex();
            ui->Content->setCurrentIndex(30);
            recordPostCount = 0;
            if(recordRent.count(",") > refNoList.size() - recordPostCount)
            {
                QMessageBox msgBox;
                int tmp2 = recordRent.count(",") - (refNoList.size() - recordPostCount);
                recordRent = "";
                for(int i=recordPostCount;i<refNoList.size();i++)
                {
                    recordRent.append(refNoList.at(i));
                    recordRent.append(",");
                }
                settings.setValue("recordRent",recordRent);
                QString tmp = "另有";
                QString tmp3 = tmp3.setNum(tmp2);
                tmp.append(tmp3);
                tmp.append("個過往搵樓記錄已被移除或刪除。");
                msgBox.setText(tmp);
                msgBox.exec();
                recordPostCount = 0;
            }
        }



    }
    else
    {
        //recordPostCount++;
        qDebug()<<thumb.size();
        qDebug()<<recordPostCount;
        QUrl url(thumb.at(recordPostCount));
        QNetworkReply* reply = recordPostImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::recordPostListClicked(QModelIndex index)
{
//    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
//    refNo = refNoList.at(ui->list_recordPost->currentIndex().row());
//    temp.append(refNo);
//    QString tmp = price.at(ui->list_recordPost->currentIndex().row());
//    temp.append(pt);
//    QUrl url(temp);
//    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
//    qDebug()<<temp;
    recordMsgBox.exec();
}

void MainWindow::recordCheck()
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
    refNo = refNoList.at(ui->list_recordPost->currentIndex().row());
    temp.append(refNo);
    QString tmp = price.at(ui->list_recordPost->currentIndex().row());
    temp.append("&");
    temp.append(pt);
    QUrl url(temp);
    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::recordDelete()
{
    refNo = refNoList.at(ui->list_recordPost->currentIndex().row());
    if(pt == "pt=s")
    {
        name.clear();
        suite.clear();
        refNoList.clear();
        area.clear();
        room.clear();
        thumb.clear();
        pps.clear();
        size.clear();
        price.clear();
        QString tmp = refNo;
        tmp.append(",");
        recordPost.replace(tmp,"");
        settings.setValue("recordPost",recordPost);
        pt = "pt=s";
        QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
        temp.append(recordPost);
        QUrl url(temp);
        qDebug()<<temp;
        if(recordPost.length() > 0)
        QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
        else
        {
            QMessageBox msgBox;
             msgBox.setText("未有任何搵樓記錄");
             msgBox.exec();
             ui->Content->setCurrentIndex(26);
        }

    }
    else
    {
        name.clear();
        suite.clear();
        refNoList.clear();
        area.clear();
        room.clear();
        thumb.clear();
        pps.clear();
        size.clear();
        price.clear();
        QString tmp = refNo;
        tmp.append(",");
        recordRent.replace(tmp,"");
        settings.setValue("recordPost",recordPost);
        pt = "pt=r";
        QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
        temp.append(recordRent);
        QUrl url(temp);
        qDebug()<<temp;
        if(recordRent.length() > 0)
        QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
        else
        {
            QMessageBox msgBox;
             msgBox.setText("未有任何搵樓記錄");
             msgBox.exec();
             ui->Content->setCurrentIndex(26);
        }

    }
}

void MainWindow::recordPostView()
{
    name.clear();
    suite.clear();
    refNoList.clear();
    area.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    price.clear();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
    temp.append(recordPost);
    QUrl url(temp);
    qDebug()<<temp;
    pt = "pt=s";
    if(recordPost.length() > 1)
    QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
    else if(recordRent.length() > 1)
    {
        pt ="pt=r";
        QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?ref=";
        temp.append(recordRent);
        QUrl url(temp);
        QNetworkReply* reply = recordPostMan->get(QNetworkRequest(url));
    }
    else
    {
        QMessageBox msgBox;
         msgBox.setText("未有任何搵樓記錄");
         msgBox.exec();
    }
}

void MainWindow::recordPostSave()
{
    if(pt == "pt=s")
    {
        if(recordPost.indexOf(refNo) == -1)
        {

            recordPost.append(refNo);
            recordPost.append(",");
            settings.setValue("recordPost",recordPost);
        }
    }
        else if(recordRent.indexOf(refNo) == -1)
        {
            recordRent.append(refNo);
            recordRent.append(",");
            settings.setValue("recordRent",recordRent);
        }

    QMessageBox msgBox;
     msgBox.setText("已加入至追蹤屋苑");
     msgBox.exec();
    qDebug()<<recordPost;
}

void MainWindow::record360Save()
{
    if(record360.indexOf(code) == -1)
    {
    record360.append(code);
    record360.append(",");

    settings.setValue("record360",record360);
    }
    QMessageBox msgBox;
     msgBox.setText("已加入至追蹤屋苑");
     msgBox.exec();
    qDebug()<<record360;
}

void MainWindow::detail360Handler2(QString t, QString c)
{
    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = t;
    code = c;

    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(code);
    temp.append("&type=");
    temp.append(type);

    QUrl url(temp);
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(code);
    temp2.append("&type=");
    temp2.append(type);

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(code);
    temp3.append("&type=");
    temp3.append(type);

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(code);
    temp4.append("&type=");
    temp4.append(type);

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(code);
    temp5.append("&type=");
    temp5.append(type);

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(code);
    temp6.append("&type=");
    temp6.append(type);

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(code);
    temp7.append("&type=");
    temp7.append(type);

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
}

void MainWindow::recentReadRecord1()
{
    if(recentReadXml.elementsByTagName("Table").count() > 0)
    {
        detail360Handler2(recentReadXml.elementsByTagName("type").at(0).toElement().text(),recentReadXml.elementsByTagName("code").at(0).toElement().text());
        QString tmpCode = recentReadCode1;

        if(recentReadCode1 == "")
        {
            recentReadCode1 = tmpCode;
        }
            else if(recentReadCode2 == "")
            {
               if(recentReadCode1 != tmpCode)
                {
                    recentReadCode2 = tmpCode;
                }
            }
                else if(recentReadCode3 == "")
                {
                   if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                    {
                        recentReadCode3 = tmpCode;
                    }
                   else if(recentReadCode2 == tmpCode)
                   {
                       recentReadCode2 = recentReadCode1;
                       recentReadCode1 = tmpCode;
                   }
                }
                else if(recentReadCode1 == tmpCode)
                {

                }
                else if(recentReadCode2 == tmpCode)
                {
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;
                }
                else if(recentReadCode3 == tmpCode)
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;

                }
                else
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;


                }
    }
}

void MainWindow::recentReadRecord2()
{
    if(recentReadXml.elementsByTagName("Table").count() > 1)
    {
        detail360Handler2(recentReadXml.elementsByTagName("type").at(1).toElement().text(),recentReadXml.elementsByTagName("code").at(1).toElement().text());
        QString tmpCode = recentReadCode2;

        if(recentReadCode1 == "")
        {
            recentReadCode1 = tmpCode;
        }
            else if(recentReadCode2 == "")
            {
               if(recentReadCode1 != tmpCode)
                {
                    recentReadCode2 = tmpCode;
                }
            }
                else if(recentReadCode3 == "")
                {
                   if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                    {
                        recentReadCode3 = tmpCode;
                    }
                   else if(recentReadCode2 == tmpCode)
                   {
                       recentReadCode2 = recentReadCode1;
                       recentReadCode1 = tmpCode;
                   }
                }
                else if(recentReadCode1 == tmpCode)
                {

                }
                else if(recentReadCode2 == tmpCode)
                {
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;
                }
                else if(recentReadCode3 == tmpCode)
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;

                }
                else
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;


                }
    }
}

void MainWindow::recentReadRecord3()
{
    if(recentReadXml.elementsByTagName("Table").count() > 2)
    {
        detail360Handler2(recentReadXml.elementsByTagName("type").at(2).toElement().text(),recentReadXml.elementsByTagName("code").at(2).toElement().text());
        QString tmpCode = recentReadCode3;

        if(recentReadCode1 == "")
        {
            recentReadCode1 = tmpCode;
        }
            else if(recentReadCode2 == "")
            {
               if(recentReadCode1 != tmpCode)
                {
                    recentReadCode2 = tmpCode;
                }
            }
                else if(recentReadCode3 == "")
                {
                   if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                    {
                        recentReadCode3 = tmpCode;
                    }
                   else if(recentReadCode2 == tmpCode)
                   {
                       recentReadCode2 = recentReadCode1;
                       recentReadCode1 = tmpCode;
                   }
                }
                else if(recentReadCode1 == tmpCode)
                {

                }
                else if(recentReadCode2 == tmpCode)
                {
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;
                }
                else if(recentReadCode3 == tmpCode)
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;

                }
                else
                {
                    recentReadCode3 = recentReadCode2;
                    recentReadCode2 = recentReadCode1;
                    recentReadCode1 = tmpCode;


                }
    }
}

void MainWindow::getRecentRead()
{
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=bookmark&p1=";
    temp.append(recentReadCode1);
    temp.append(",");
    temp.append(recentReadCode2);
    temp.append(",");
    temp.append(recentReadCode3);
    temp.append(",");
    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = recentReadMan->get(QNetworkRequest(url));
}

void MainWindow::recentReadImageDownloaded1(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->recentImage_1->setPixmap(QPixmap::fromImage(image).scaled(QSize(50,50)));
}
}
    else
        ui->recentImage_1->setPixmap(p);
}

void MainWindow::recentReadImageDownloaded2(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->recentImage_2->setPixmap(QPixmap::fromImage(image).scaled(QSize(50,50)));
}
}
    else
        ui->recentImage_2->setPixmap(p);
}

void MainWindow::recentReadImageDownloaded3(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->recentImage_3->setPixmap(QPixmap::fromImage(image).scaled(QSize(50,50)));
}
}
    else
        ui->recentImage_3->setPixmap(p);
}

void MainWindow::recentReadResult(QNetworkReply *reply)
{
    qDebug()<<"Recent Read Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

            QString tempP;
            int tempP_i;
            QString tempPPS;
            int tempPPS_i;
    recentReadXml.setContent(string.toAscii());

    if(recentReadXml.elementsByTagName("namec").count() > 0)
    {
    ui->recentName_1->setText(recentReadXml.elementsByTagName("namec").at(0).toElement().text());
    ui->recentNameEn_1->setText(recentReadXml.elementsByTagName("namee").at(0).toElement().text());

    tempPPS = recentReadXml.elementsByTagName("Table").at(0).toElement().toElement().elementsByTagName("cprice30").at(0).toElement().text();
    tempPPS_i = tempPPS.toInt();


    if(tempPPS_i > 9999)
        tempPPS.insert(2,",");
    else if(tempPPS_i > 999)
        tempPPS.insert(1,",");
    if(tempPPS.length() > 0)
    {
        tempPPS.prepend("$");
    tempPPS.append("/呎");
    }

    ui->recentPPS_1->setText(tempPPS);

    tempP = recentReadXml.elementsByTagName("Table").at(0).toElement().elementsByTagName("cprice30up").at(0).toElement().text();
    tempP.remove(tempP.length()-5,tempP.length());

    tempP_i = tempP.toInt();
    if(tempP_i > 0)
    {
        ui->recenrArrow_1->setVisible(true);
        ui->recentPercent_1->setVisible(true);
        tempP.append("%");
        ui->recenrArrow_1->setPixmap(QPixmap(":/new/prefix1/Image/arrow_up.png"));
    }
    else if(tempP_i < 0)
    {
        ui->recenrArrow_1->setVisible(true);
        ui->recentPercent_1->setVisible(true);
        tempP.append("%");
        tempP.remove(0,1);
        ui->recenrArrow_1->setPixmap(QPixmap(":/new/prefix1/Image/arrow_down.png"));
    }
    else
    {
        ui->recenrArrow_1->setVisible(false);
        ui->recentPercent_1->setVisible(false);
    }
    ui->recentPercent_1->setText(tempP);

    QUrl url(recentReadXml.elementsByTagName("Table").at(0).toElement().elementsByTagName("path").at(0).toElement().text());
    QNetworkReply* reply4 = recentReadImage1Man->get(QNetworkRequest(url));
    ui->recentBtn1->setDisabled(false);
}
    else
    {
        ui->recentName_1->setText("未有紀錄");
        ui->recentBtn1->setDisabled(true);
    }





    if(recentReadXml.elementsByTagName("namec").count() > 1)
    {
    ui->recentName_2->setText(recentReadXml.elementsByTagName("namec").at(1).toElement().text());
    ui->recentNameEn_2->setText(recentReadXml.elementsByTagName("namee").at(1).toElement().text());

    tempPPS = recentReadXml.elementsByTagName("Table").at(1).toElement().elementsByTagName("cprice30").at(0).toElement().text();
    tempPPS_i = tempPPS.toInt();
    if(tempPPS_i > 9999)
        tempPPS.insert(2,",");
    else if(tempPPS_i > 999)
        tempPPS.insert(1,",");
    if(tempPPS.length() > 0)
    {
        tempPPS.prepend("$");
    tempPPS.append("/呎");
    }

    ui->recentPPS_2->setText(tempPPS);
    tempP = recentReadXml.elementsByTagName("Table").at(1).toElement().elementsByTagName("cprice30up").at(0).toElement().text();
    tempP.remove(tempP.length()-5,tempP.length());

    tempP_i = tempP.toInt();
    if(tempP_i > 0)
    {
        ui->recenrArrow_2->setVisible(true);
        ui->recentPercent_2->setVisible(true);
        tempP.append("%");
        ui->recenrArrow_2->setPixmap(QPixmap(":/new/prefix1/Image/arrow_up.png"));
    }
    else if(tempP_i < 0)
    {
        ui->recenrArrow_2->setVisible(true);
        ui->recentPercent_2->setVisible(true);
        tempP.append("%");
        tempP.remove(0,1);
        ui->recenrArrow_2->setPixmap(QPixmap(":/new/prefix1/Image/arrow_down.png"));
    }
    else
    {
        ui->recenrArrow_2->setVisible(false);
        ui->recentPercent_2->setVisible(false);
    }

    ui->recentPercent_2->setText(tempP);

    QUrl url2(recentReadXml.elementsByTagName("Table").at(1).toElement().elementsByTagName("path").at(0).toElement().text());
    QNetworkReply* reply2 = recentReadImage2Man->get(QNetworkRequest(url2));
    ui->recentBtn2->setDisabled(false);
}
    else
    {
        ui->recentName_2->setText("未有紀錄");
        ui->recentBtn2->setDisabled(true);
    }





    if(recentReadXml.elementsByTagName("namec").count() > 2)
    {
    ui->recentName_3->setText(recentReadXml.elementsByTagName("namec").at(2).toElement().text());
    ui->recentNameEn_3->setText(recentReadXml.elementsByTagName("namee").at(2).toElement().text());

    tempPPS = recentReadXml.elementsByTagName("Table").at(2).toElement().elementsByTagName("cprice30").at(0).toElement().text();
    tempPPS_i = tempPPS.toInt();
    if(tempPPS_i > 9999)
        tempPPS.insert(2,",");
    else if(tempPPS_i > 999)
        tempPPS.insert(1,",");
    if(tempPPS.length() > 0)
    {
        tempPPS.prepend("$");
    tempPPS.append("/呎");
    }

    ui->recentPPS_3->setText(tempPPS);
    tempP = recentReadXml.elementsByTagName("Table").at(2).toElement().elementsByTagName("cprice30up").at(0).toElement().text();
    tempP.remove(tempP.length()-5,tempP.length());

    tempP_i = tempP.toInt();
    if(tempP_i > 0)
    {
        ui->recenrArrow_3->setVisible(true);
        ui->recentPercent_3->setVisible(true);
        tempP.append("%");
        ui->recenrArrow_3->setPixmap(QPixmap(":/new/prefix1/Image/arrow_up.png"));
    }
    else if(tempP_i < 0)
    {
        ui->recenrArrow_3->setVisible(true);
        ui->recentPercent_3->setVisible(true);
        tempP.append("%");
        tempP.remove(0,1);
        ui->recenrArrow_3->setPixmap(QPixmap(":/new/prefix1/Image/arrow_down.png"));
    }
    else
    {
        ui->recenrArrow_3->setVisible(false);
        ui->recentPercent_3->setVisible(false);
    }
    ui->recentPercent_3->setText(tempP);

    QUrl url3(recentReadXml.elementsByTagName("Table").at(2).toElement().elementsByTagName("path").at(0).toElement().text());
    QNetworkReply* reply3 = recentReadImage3Man->get(QNetworkRequest(url3));
    ui->recentBtn3->setDisabled(false);
}
    else
    {
        ui->recentName_3->setText("未有紀錄");
        ui->recentBtn3->setDisabled(true);
    }
}

void MainWindow::floorPlanClicked(QModelIndex index)
{
    QString temp = floorPlanLink.at(ui->list_floorPlan->currentIndex().row());
//    temp.replace("&","%26");

//    temp.prepend("http://www.nuthon.com/temp/ImageResize.ashx?ImageUrl=");
//    temp.append("&TargetWidth=600&TargetHeight=600");

    ui->webView_2->load(temp);
    qDebug()<<temp;
    ui->Content->setCurrentIndex(25);
}

void MainWindow::floorPlanSearch()
{
    QString temp4 = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=floorplan&type=";
    temp4.append(type);
    temp4.append("&code=");
    temp4.append(code);
//    temp4.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
//    temp4.append("&type=");
//    temp4.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url4(temp4);
    QNetworkReply* reply4 = floorPlanMan->get(QNetworkRequest(url4));
}

void MainWindow::floorPlanResult(QNetworkReply *reply)
{
   floorPlanName.clear();
   floorPlanThumb.clear();
   floorPlanLink.clear();
   ui->loading->setVisible(true);

   qDebug()<<"floor Plan Download";
   QVariant statusCodeV =
       reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
   QVariant tempQ = QVariant(statusCodeV.toString().length());
   QByteArray bytes = reply->readAll();  // bytes
           const QString string(bytes);

   QDomDocument xml;
   xml.setContent(string.toAscii());

   qDebug()<<xml.elementsByTagName("Table").count();
   for(int i=0;i<xml.elementsByTagName("Table").count();i++)
   {
      floorPlanName.append(xml.elementsByTagName("namec").at(i).toElement().text());

      QString tmp = xml.elementsByTagName("path").at(i).toElement().text();
      tmp.replace(";","&");
      floorPlanThumb.append(tmp);
      QString tmp2 = xml.elementsByTagName("path2").at(i).toElement().text();
      tmp2.replace(";","&");
      qDebug()<<tmp<<"   "<<i;
      floorPlanLink.append(tmp2);
   }

   QUrl url(floorPlanThumb.at(0));
   QNetworkReply* reply2 = floorPlanImageMan->get(QNetworkRequest(url));


}

void MainWindow::floorPlanImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    floorPlanImage[floorCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
    }
}

    if(floorCount == floorPlanThumb.size()-1)
    {

        qDebug()<<"Image Download  floorCount : "<<floorCount;
        floorplanlistmodel *postModel = new floorplanlistmodel(floorPlanName,floorPlanImage,this);
        qDebug()<<"1";
        ui->list_floorPlan->setModel(postModel);
        qDebug()<<"2";
        floorplanlistdelegate* delegate = new floorplanlistdelegate(this);
        qDebug()<<"3";
        ui->list_floorPlan->setItemDelegate(delegate);
        qDebug()<<"4";


        ui->Content->setCurrentIndex(24);
        qDebug()<<"5";
        floorCount=0;
        qDebug()<<"6";
        ui->loading->setVisible(false);

    }
    else
    {
        floorCount++;
        qDebug()<<"Image Download : "<<floorCount;
        QUrl url(floorPlanThumb.at(floorCount));
        QNetworkReply* reply2 = floorPlanImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::distict360MoreClicked(QModelIndex index)
{
    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = districtAreaType.at(ui->list_districtArea_2->currentIndex().row());
    code = districtAreaCode.at(ui->list_districtArea_2->currentIndex().row());

    QString tmpCode = code;

    if(recentReadCode1 == "")
    {
        recentReadCode1 = tmpCode;
    }
        else if(recentReadCode2 == "")
        {
           if(recentReadCode1 != tmpCode)
            {
                recentReadCode2 = tmpCode;
            }
        }
            else if(recentReadCode3 == "")
            {
               if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                {
                    recentReadCode3 = tmpCode;
                }
               else if(recentReadCode2 == tmpCode)
               {
                   recentReadCode2 = recentReadCode1;
                   recentReadCode1 = tmpCode;
               }
            }
            else if(recentReadCode1 == tmpCode)
            {

            }
            else if(recentReadCode2 == tmpCode)
            {
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;
            }
            else if(recentReadCode3 == tmpCode)
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;

            }
            else
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;


            }
            settings.setValue("r1",recentReadCode1);
            settings.setValue("r2",recentReadCode2);
            settings.setValue("r3",recentReadCode3);

    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp.append("&type=");
    temp.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp2.append("&type=");
    temp2.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp3.append("&type=");
    temp3.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp4.append("&type=");
    temp4.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp5.append("&type=");
    temp5.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp6.append("&type=");
    temp6.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(districtAreaCode.at(ui->list_districtArea_2->currentIndex().row()));
    temp7.append("&type=");
    temp7.append(districtAreaType.at(ui->list_districtArea_2->currentIndex().row()));

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
}

void MainWindow::district360MoreImageDownloaded(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    districtThumb[districtCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
}
}

    if(districtCount == districtAreaThumb.size()-1)
    {

        qDebug()<<"District Image Download  postCount : "<<districtCount;
        districtAreaListModel *postModel = new districtAreaListModel(districtAreaName,districtAreaNameEn,districtAreaPPS,districtAreaPercent,districtAreaPrice,districtThumb,this);
        ui->list_districtArea_2->setModel(postModel);

        districtAreaListDelegate* delegate = new districtAreaListDelegate(this);

        ui->list_districtArea_2->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(23);
        districtCount=0;
        ui->loading->setVisible(false);

    }
    else
    {
        districtCount++;
        QUrl url(districtAreaThumb.at(districtCount));
        QNetworkReply* reply2 = district360MoreImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::district360MoreResult(QNetworkReply *reply)
{
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    qDebug()<<"District Area Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtAreaXml.setContent(string.toAscii());

    for(int i=0;i<districtAreaXml.elementsByTagName("Table").count();i++)
    {
        districtAreaName.append(districtAreaXml.elementsByTagName("namec").at(i).toElement().text());
        districtAreaNameEn.append(districtAreaXml.elementsByTagName("namee").at(i).toElement().text());
        if(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("path").count() > 0)
            districtAreaThumb.append(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("path").at(0).toElement().text());
        else
            districtAreaThumb.append("");
        districtAreaCode.append(districtAreaXml.elementsByTagName("code").at(i).toElement().text());
        districtAreaType.append(districtAreaXml.elementsByTagName("type").at(i).toElement().text());

        if(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("cprice30").count() >0)
        {
        QString tmpPPS = districtAreaXml.elementsByTagName("cprice30").at(i).toElement().text();
        int tmpPPS_i = tmpPPS.toInt();
        if(tmpPPS_i > 9999)
            tmpPPS.insert(2,",");
        else if(tmpPPS_i > 999)
            tmpPPS.insert(1,",");
        tmpPPS.append("/呎");
        tmpPPS.prepend("$");
        districtAreaPPS.append(tmpPPS);
        }
        else
            districtAreaPPS.append("");

        if(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("cprice30up").count() > 0)
        {
        QString tmp = districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("cprice30up").at(0).toElement().text();
        tmp.remove(tmp.length()-5,tmp.length());
        int tmp2 = tmp.toInt();
        if(tmp2 > 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp);
            districtAreaPrice.append("1");
        }
        else if(tmp2 < 0)
        {
            tmp.append("%");
            districtAreaPercent.append(tmp.remove(0,1));
            districtAreaPrice.append("-1");
        }
        else
        {
            districtAreaPercent.append("");
            districtAreaPrice.append("0");
        }
    }
        else
        {
            districtAreaPercent.append("");
            districtAreaPrice.append("");
        }



    }

    QUrl url(districtAreaThumb.at(0));
    QNetworkReply* reply2 = district360MoreImageMan->get(QNetworkRequest(url));
}

void MainWindow::detail360ChartDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        QTransform myTransform;
        myTransform.rotate(90);
        ui->detail360Chart->setIcon(QIcon(QPixmap::fromImage(image)));
        ui->Chart->setPixmap(QPixmap::fromImage(image.transformed(myTransform)));
    }
    }
    else
    {
        QTransform myTransform;
        myTransform.rotate(90);
        ui->detail360Chart->setIcon(QIcon(QPixmap(":/new/prefix1/no.png")));
        ui->Chart->setPixmap(QPixmap(":/new/prefix1/no.png"));
    }

}

void MainWindow::detail360Result1(QNetworkReply *reply)
{
    qDebug()<<"360 Detail 1 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    QDomDocument xml;
    xml.setContent(string.toAscii());
    ui->tcount->setText(xml.elementsByTagName("bCount").at(0).toElement().text());
    ui->bcount->setText(xml.elementsByTagName("tCount").at(0).toElement().text());
    QString tmp1;
    QString tmpCount = xml.elementsByTagName("estatePhotoCount").at(0).toElement().text();
    int tmpCount_i = tmpCount.toInt();
    if(tmpCount_i > 0)
    {
    tmp1 = xml.elementsByTagName("estatePhotoCount").at(0).toElement().text();
    tmp1.prepend("共");
    tmp1.append("張屋苑外觀相");
    ui->commandLinkButton->setDisabled(false);
    ui->commandLinkButton_5->setDisabled(false);
    }
    else
    {
        tmp1 = "未能提供圖片";
        ui->commandLinkButton->setDisabled(true);
        ui->commandLinkButton_5->setDisabled(true);
    }
    QString tmp2;
    QString tmp3;
    if(xml.elementsByTagName("floorPlanCount").count() > 0)
    {
        tmp2 = xml.elementsByTagName("floorPlanCount").at(0).toElement().text();
        tmp2.prepend("共");
        tmp2.append("張平面圖");
        ui->commandLinkButton_2->setDisabled(false);
        ui->commandLinkButton_6->setDisabled(false);
    }
    else
    {
        tmp2 = "未能提供平面圖";
        ui->commandLinkButton_2->setDisabled(true);
        ui->commandLinkButton_6->setDisabled(true);
    }
    if(xml.elementsByTagName("facilityPhotoCount").count() > 0)
    {
        tmp3 = xml.elementsByTagName("facilityPhotoCount").at(0).toElement().text();
        tmp3.prepend("共");
        tmp3.append("張屋苑規劃及設施圖");
        ui->commandLinkButton_3->setDisabled(false);
        ui->commandLinkButton_7->setDisabled(false);
    }
    else
    {
        tmp3 = "未能提供屋苑規劃及設施圖";
        ui->commandLinkButton_3->setDisabled(true);
        ui->commandLinkButton_7->setDisabled(true);
    }

    ui->commandLinkButton->setText(tmp1);
    ui->commandLinkButton_2->setText(tmp2);
    ui->commandLinkButton_3->setText(tmp3);

    ui->commandLinkButton_5->setText(tmp1);
    ui->commandLinkButton_6->setText(tmp2);
    ui->commandLinkButton_7->setText(tmp3);
}

void MainWindow::detail360Result2(QNetworkReply *reply)
{
    qDebug()<<"360 Detail 2 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    QDomDocument xml;
    xml.setContent(string.toAscii());



    QString tmp = xml.elementsByTagName("cprice30").at(0).toElement().text();
    int tmp2 = tmp.toInt();
    if(tmp2 > 99999)
    {
        tmp.insert(3,",");
    }
    else if(tmp2 > 9999)
    {
        tmp.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmp.insert(1,",");
    }
    tmp.prepend("$");
    tmp.append("/呎");
    ui->detail360cPrice->setText(tmp);

    QString tmpcPriceMax = xml.elementsByTagName("cpricemax30").at(0).toElement().text();
    tmp2 = tmpcPriceMax.toInt();
    if(tmp2 > 9999)
    {
        tmpcPriceMax.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmpcPriceMax.insert(1,",");
    }
    QString tmpcPriceMin = xml.elementsByTagName("cpricemin30").at(0).toElement().text();
    tmp2 = tmpcPriceMin.toInt();
    if(tmp2 > 9999)
    {
        tmpcPriceMin.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmpcPriceMin.insert(1,",");
    }
    tmpcPriceMin.prepend("($");
    tmpcPriceMin.append("~$");
    tmpcPriceMin.append(tmpcPriceMax);
    tmpcPriceMin.append(")");
    ui->detail360CPriceRange->setText(tmpcPriceMin);

    QString tmpAvgPrice = xml.elementsByTagName("AvgPrice").at(0).toElement().text();
    tmpAvgPrice.remove(tmpAvgPrice.indexOf("."),tmpAvgPrice.length());
    tmp2 = tmpAvgPrice.toInt();
    if(tmp2 > 9999)
    {
        tmpAvgPrice.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmpAvgPrice.insert(1,",");
    }
    tmpAvgPrice.prepend("$");
    tmpAvgPrice.append("/呎");
    ui->detail360AvgPrice->setText(tmpAvgPrice);

    QString tmpAvgRange = xml.elementsByTagName("MinPrice").at(0).toElement().text();
    if(tmpAvgRange.indexOf(".") != -1)
        tmpAvgRange.remove(tmpAvgRange.indexOf("."),tmpAvgRange.length());
    tmp2 = tmpAvgRange.toInt();
    if(tmp2 > 9999)
    {
        tmpAvgRange.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmpAvgRange.insert(1,",");
    }
    tmpAvgRange.prepend("($");
    tmpAvgRange.append("~$");
    QString tmpMaxPrice = xml.elementsByTagName("MaxPrice").at(0).toElement().text();
    tmpMaxPrice.remove(tmpMaxPrice.indexOf("."),tmpMaxPrice.length());
    tmp2 = tmpMaxPrice.toInt();
    if(tmp2 > 9999)
    {
        tmpMaxPrice.insert(2,",");
    }
    else if(tmp2 > 999)
    {
        tmpMaxPrice.insert(1,",");
    }
    tmpAvgRange.append(tmpMaxPrice);
    tmpAvgRange.append(")");
    ui->detail360AvgPriceRange->setText(tmpAvgRange);

    QString temp = xml.elementsByTagName("chartPath").at(0).toElement().text();
    QUrl url(temp);
    QNetworkReply* reply2 = detail360ChartMan->get(QNetworkRequest(url));

    QString tempPercent = xml.elementsByTagName("cprice30up").at(0).toElement().text();
    tempPercent.remove(tempPercent.length()-5,tempPercent.length());
    int tmpP_i = tempPercent.toInt();
    if(tmpP_i > 0)
    {
        ui->detail360upAndDown->setVisible(true);
        ui->detail360percent->setVisible(true);
        ui->detail360upAndDown->setPixmap(QPixmap(":/new/prefix1/Image/arrow_up.png"));
        tempPercent.append("%");
        ui->detail360percent->setText(tempPercent);
    }
    else if(tmpP_i < 0)
    {
        ui->detail360upAndDown->setVisible(true);
        ui->detail360percent->setVisible(true);
        ui->detail360upAndDown->setPixmap(QPixmap(":/new/prefix1/Image/arrow_down.png"));
        tempPercent.append("%");
        tempPercent.remove(0,1);
        ui->detail360percent->setText(tempPercent);
    }
    else
    {
        ui->detail360upAndDown->setVisible(false);
        ui->detail360percent->setVisible(false);
    }


}

void MainWindow::detail360Result3(QNetworkReply *reply)
{
    qDebug()<<"360 Detail 3 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    QDomDocument xml;
    xml.setContent(string.toAscii());

    if(xml.elementsByTagName("opdate").at(0).toElement().text().length() > 0)
        ui->flatDate->setText(xml.elementsByTagName("opdate").at(0).toElement().text());
    else
        ui->flatDate->setText("-");
    if(xml.elementsByTagName("pc_faci").at(0).toElement().text().length() > 0)
        ui->flatFacility->setText(xml.elementsByTagName("pc_faci").at(0).toElement().text());
    else
        ui->flatFacility->setText("-");
    if(xml.elementsByTagName("pc_addr").at(0).toElement().text().length() > 0)
        ui->flatAddress->setText(xml.elementsByTagName("pc_addr").at(0).toElement().text());
    else
        ui->flatAddress->setText("-");
    if(xml.elementsByTagName("pc_dev").at(0).toElement().text().length() > 0)
        ui->flatDeveloper->setText(xml.elementsByTagName("pc_dev").at(0).toElement().text());
    else
        ui->flatDeveloper->setText("-");
    if(xml.elementsByTagName("pc_manage").at(0).toElement().text().length() > 0)
        ui->flatCompany->setText(xml.elementsByTagName("pc_manage").at(0).toElement().text());
    else
        ui->flatCompany->setText("-");
    if(xml.elementsByTagName("schoolNet").at(0).toElement().text().length() > 0)
        ui->flatSchool->setText(xml.elementsByTagName("schoolNet").at(0).toElement().text());
    else
        ui->flatSchool->setText("-");
    if(xml.elementsByTagName("x_cnt").at(0).toElement().text().length() > 0)
        ui->flatBlock->setText(xml.elementsByTagName("x_cnt").at(0).toElement().text());
    else
        ui->flatBlock->setText("-");
    QString tmp;
    if(xml.elementsByTagName("name2c").count()>0)
    {
    for(int i=0;i<xml.elementsByTagName("name2c").count();i++)
    {
        tmp.append(xml.elementsByTagName("name2c").at(i).toElement().text());
        tmp.append("，");
    }

    ui->flatNumber->setText(tmp.remove(tmp.length()-1,tmp.length()));
    }
    else
        ui->flatNumber->setText("-");


    QString tmp2 = xml.elementsByTagName("unit_cnt").at(0).toElement().text();
    tmp2.remove(tmp2.length()-6,tmp2.length());
    ui->flatTotal->setText(tmp2);



}

void MainWindow::detail360Result4(QNetworkReply *reply)
{
    qDebug()<<"360 Detail 4 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    QDomDocument xml;
    xml.setContent(string.toAscii());

    for(int i=0;i<xml.elementsByTagName("Table").count();i++)
    {
        address_s.append(xml.elementsByTagName("address").at(i).toElement().text());
        date_s.append(xml.elementsByTagName("displayDate").at(i).toElement().text());
        QString tmpPrice = xml.elementsByTagName("consider").at(i).toElement().text();
        int tmpPrice_i = tmpPrice.toInt();
        tmpPrice_i = tmpPrice_i/10000;
        tmpPrice.setNum(tmpPrice_i);
        if(tmpPrice_i > 100000)
        {
            tmpPrice_i = tmpPrice_i/10000;
            tmpPrice = tmpPrice.setNum(tmpPrice_i);
        }
        if(tmpPrice_i > 9999)
        {
            if(tmpPrice_i == 10000)
            {
               tmpPrice = "1億";
            }
            else
            {
                tmpPrice_i = tmpPrice_i - 10000;
                tmpPrice = tmpPrice.setNum(tmpPrice_i);
                tmpPrice.prepend("1億");
                tmpPrice.append("萬");

            }

        }
        else if(tmpPrice_i > 999)
        {
            tmpPrice.insert(1,",");
            tmpPrice.append("萬");
        }
        else
            tmpPrice.append("萬");


        tmpPrice.prepend("$");
        price_s.append(tmpPrice);

        QString tmpSize = xml.elementsByTagName("int_garea").at(i).toElement().text();
        int tmp = tmpSize.toInt();
//        if(tmp > 999)
//            tmpSize.insert(1,",");
//        else if(tmp > 9999)
//            tmpSize.insert(2,",");

        tmpSize.append("呎");
        if(tmp == 0)
            size_s.append("");
        else
            size_s.append(tmpSize);

        QString tmpPPS = xml.elementsByTagName("int_uprice").at(i).toElement().text();
        tmp = tmpPPS.toInt();
        if(tmp > 9999)
            tmpPPS.insert(2,",");
        else if(tmp > 999)
            tmpPPS.insert(1,",");
        tmpPPS.prepend("$");
        tmpPPS.append("/呎");
        if(tmp == 0)
            pps_s.append("");
        else
            pps_s.append(tmpPPS);

        QString tmpType = xml.elementsByTagName("nature").at(i).toElement().text();
        tmpType.replace(" ","");
        tmpType.trimmed();
        if(tmpType == "C")
            tmpType = "中原成交";
            else if(tmpType == "R")
                tmpType = "集團成交";
                else if(tmpType == "L")
                    tmpType = "註冊處成交";
        type_s.append(tmpType);

    }

    tradeListModel *postModel = new tradeListModel(address_s,date_s,size_s,price_s,pps_s,type_s,this);
    ui->list_trade->setModel(postModel);

    tradeListDelegate* delegate = new tradeListDelegate(this);

    ui->list_trade->setItemDelegate(delegate);


}

void MainWindow::detail360previewEstate(QNetworkReply *reply)
{
    qDebug()<<"Estate XML Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    previewEstateXml.setContent(string.toAscii());
}

void MainWindow::detail360previewFacility(QNetworkReply *reply)
{
    qDebug()<<"Facility XML Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
    qDebug()<<string;
    previewFacilityXml.setContent(string.toAscii());
}

void MainWindow::tradeRentListUpdated()
{
    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp4.append(topThreeXml.elementsByTagName("code").at(_index).toElement().text());
    temp4.append("&type=");
    temp4.append(topThreeXml.elementsByTagName("type").at(_index).toElement().text());
    sellSii+=10;
    temp4.append("&start=");
    QString sii;
    temp4.append(sii.setNum(sellSii));
    temp4.append("&end=");
    temp4.append(sii.setNum(sellSii+9));

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man5->get(QNetworkRequest(url4));

}

void MainWindow::tradeSellListUpdated()
{
    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp5.append(topThreeXml.elementsByTagName("code").at(_index).toElement().text());
    temp5.append("&type=");
    temp5.append(topThreeXml.elementsByTagName("type").at(_index).toElement().text());
    rentSii+=10;
    temp5.append("&start=");
    QString sii;
    temp5.append(sii.setNum(rentSii));
    temp5.append("&end=");
    temp5.append(sii.setNum(rentSii+9));
    qDebug()<<temp5;
    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man4->get(QNetworkRequest(url5));
}

void MainWindow::nextEstateImage()
{
    if(estateNumber < previewEstateXml.elementsByTagName("Table").count())
    {
        estateNumber++;
        downloadEstate();
    }
}

void MainWindow::previousEstateImage()
{
    if(estateNumber > 0)
    {
        estateNumber--;
        downloadEstate();
    }
}

void MainWindow::downloadEstate()
{
    QString temp = previewEstateXml.elementsByTagName("Path2").at(estateNumber).toElement().text();
    QUrl url(temp);
    QNetworkReply* reply = previewEstateMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::nextFacilityImage()
{
    if(facilityNumber < previewFacilityXml.elementsByTagName("Table").count())
    {
        facilityNumber++;
        downloadFacility();
    }
}

void MainWindow::previousFacilityImage()
{
    if(facilityNumber > 0)
    {
        facilityNumber--;
        downloadFacility();
    }
}

void MainWindow::downloadFacility()
{
//    QString temp = previewFacilityXml.elementsByTagName("path2").at(facilityNumber).toElement().text();
//    QUrl url(temp);
//    QNetworkReply* reply = previewFacilityMan->get(QNetworkRequest(url));
//    qDebug()<<temp;
    faciltyName.clear();
    faciltyThumb.clear();
    faciltyLink.clear();

    for(int i=0;i<previewFacilityXml.elementsByTagName("Table").count();i++)
    {
        faciltyName.append(previewFacilityXml.elementsByTagName("namec").at(i).toElement().text());
        faciltyThumb.append(previewFacilityXml.elementsByTagName("path").at(i).toElement().text());
        faciltyLink.append(previewFacilityXml.elementsByTagName("path2").at(i).toElement().text());
    }
    if(faciltyThumb.size()>0)
    {
        QUrl url(faciltyThumb.at(0));
        QNetworkReply* reply = previewFacilityMan->get(QNetworkRequest(url));
    }

}

void MainWindow::facilityClicked(QModelIndex index)
{
    QUrl url(faciltyLink.at(ui->list_facility->currentIndex().row()));
    QNetworkReply* reply = facilityImageMan->get(QNetworkRequest(url));
}

void MainWindow::facilityImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->facilityImage->setPixmap(QPixmap::fromImage(image));
        //ui->previewCaption->setText(postDetailXml.elementsByTagName("photos2").at(estateNumber).);
        pageFacilityPreview();
    }
    }
}

void MainWindow::previewEstateDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->estateImage->setPixmap(QPixmap::fromImage(image));
        //ui->previewCaption->setText(postDetailXml.elementsByTagName("photos2").at(estateNumber).);
        pageEstatePreview();
    }
    }
}

void MainWindow::previewFacilityDownloaded(QNetworkReply *reply)
{
        //ui->facilityImage->setPixmap(QPixmap::fromImage(image));
        //ui->previewCaption->setText(postDetailXml.elementsByTagName("photos2").at(estateNumber).);
        //pageFacilityPreview();
        qDebug()<<"Image Download";
        if (!reply->error())
        {
        QImage image;
        if (image.loadFromData(reply->readAll()))
        {
        faciltyImage[floorCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
        }
    }

        if(floorCount == faciltyThumb.size()-1)
        {

            qDebug()<<"Image Download  floorCount : "<<floorCount;
            floorplanlistmodel *postModel = new floorplanlistmodel(faciltyName,faciltyImage,this);
            qDebug()<<"1";
            ui->list_facility->setModel(postModel);
            qDebug()<<"2";
            floorplanlistdelegate* delegate = new floorplanlistdelegate(this);
            qDebug()<<"3";
            ui->list_facility->setItemDelegate(delegate);
            qDebug()<<"4";


            ui->Content->setCurrentIndex(41);
            qDebug()<<"5";
            floorCount=0;
            qDebug()<<"6";
            ui->loading->setVisible(false);

        }
        else
        {
            floorCount++;
            qDebug()<<"Image Download : "<<floorCount;
            QUrl url(faciltyThumb.at(floorCount));
            QNetworkReply* reply2 = previewFacilityMan->get(QNetworkRequest(url));

        }

}

void MainWindow::detail360Result5(QNetworkReply *reply)
{
    qDebug()<<"360 Detail 5 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    QDomDocument xml;
    xml.setContent(string.toAscii());

    for(int i=0;i<xml.elementsByTagName("Table").count();i++)
    {
        address_r.append(xml.elementsByTagName("address").at(i).toElement().text());
        date_r.append(xml.elementsByTagName("displayDate").at(i).toElement().text());
        QString tmpPrice = xml.elementsByTagName("consider").at(i).toElement().text();
        int tmpPrice_i = tmpPrice.toInt();
        if(tmpPrice_i > 9999)
        {
            tmpPrice.insert(2,",");
        }
        else if(tmpPrice_i > 999)
        {
            tmpPrice.insert(1,",");
        }
        //tmpPrice.setNum(tmpPrice_i);
        tmpPrice.prepend("$");
        price_r.append(tmpPrice);

        QString tmpSize = xml.elementsByTagName("int_garea").at(i).toElement().text();
        tmpSize.append("呎");
        size_r.append(tmpSize);

        QString tmpPPS = xml.elementsByTagName("int_uprice").at(i).toElement().text();
        tmpPPS.prepend("$");
        tmpPPS.append("/呎");
        pps_r.append(tmpPPS);

        QString tmpType = xml.elementsByTagName("nature").at(i).toElement().text();
        tmpType.replace(" ","");
        tmpType.trimmed();
        if(tmpType == "C")
            tmpType = "中原成交";
            else if(tmpType == "R")
                tmpType = "集團成交";
                else if(tmpType == "L")
                    tmpType = "註冊處成交";
        type_r.append(tmpType);

    }

    tradeListModel *postModel = new tradeListModel(address_r,date_r,size_r,price_r,pps_r,type_r,this);
    ui->list_trade_2->setModel(postModel);

    tradeListDelegate* delegate = new tradeListDelegate(this);

    ui->list_trade_2->setItemDelegate(delegate);

}



void MainWindow::topThreeEstate()
{
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=topthree";
    QUrl url(temp);
    QNetworkReply* reply = topThreeMan->get(QNetworkRequest(url));
}

void MainWindow::topThreeEstateFinished(QNetworkReply *reply)
{
    ui->loading->setVisible(false);
    qDebug()<<"Top 3 Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    topThreeXml.setContent(string.toAscii());

      ChecktopEstatesWordLength(ui->hkBtn1_2,topThreeXml.elementsByTagName("namec").at(0).toElement().text());
      ChecktopEstatesWordLength(ui->hkBtn2_2,topThreeXml.elementsByTagName("namec").at(1).toElement().text());
      ChecktopEstatesWordLength(ui->hkBtn3_2,topThreeXml.elementsByTagName("namec").at(2).toElement().text());

      ChecktopEstatesWordLength(ui->klBtn1_2,topThreeXml.elementsByTagName("namec").at(3).toElement().text());
      ChecktopEstatesWordLength(ui->klBtn2_2,topThreeXml.elementsByTagName("namec").at(4).toElement().text());
      ChecktopEstatesWordLength(ui->klBtn3_2,topThreeXml.elementsByTagName("namec").at(5).toElement().text());

      ChecktopEstatesWordLength(ui->nteBtn1_2,topThreeXml.elementsByTagName("namec").at(6).toElement().text());
      ChecktopEstatesWordLength(ui->nteBtn2_2,topThreeXml.elementsByTagName("namec").at(7).toElement().text());
      ChecktopEstatesWordLength(ui->nteBtn3_2,topThreeXml.elementsByTagName("namec").at(8).toElement().text());

      ChecktopEstatesWordLength(ui->ntwBtn1_2,topThreeXml.elementsByTagName("namec").at(9).toElement().text());
      ChecktopEstatesWordLength(ui->ntwBtn2_2,topThreeXml.elementsByTagName("namec").at(10).toElement().text());
      ChecktopEstatesWordLength(ui->ntwBtn3_2,topThreeXml.elementsByTagName("namec").at(11).toElement().text());



}

void MainWindow::detail360Handler(int index)
{
    _index = index;
    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    QString tmpCode = topThreeXml.elementsByTagName("code").at(index).toElement().text();

    if(recentReadCode1 == "")
    {
        recentReadCode1 = tmpCode;
    }
        else if(recentReadCode2 == "")
        {
           if(recentReadCode1 != tmpCode)
            {
                recentReadCode2 = tmpCode;
            }
        }
            else if(recentReadCode3 == "")
            {
               if(recentReadCode1 != tmpCode && recentReadCode2 != tmpCode)
                {
                    recentReadCode3 = tmpCode;
                }
               else if(recentReadCode2 == tmpCode)
               {
                   recentReadCode2 = recentReadCode1;
                   recentReadCode1 = tmpCode;
               }
            }
            else if(recentReadCode1 == tmpCode)
            {

            }
            else if(recentReadCode2 == tmpCode)
            {
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;
            }
            else if(recentReadCode3 == tmpCode)
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;

            }
            else
            {
                recentReadCode3 = recentReadCode2;
                recentReadCode2 = recentReadCode1;
                recentReadCode1 = tmpCode;


            }

    settings.setValue("r1",recentReadCode1);
    settings.setValue("r2",recentReadCode2);
    settings.setValue("r3",recentReadCode3);

    type = topThreeXml.elementsByTagName("type").at(index).toElement().text();
    code = topThreeXml.elementsByTagName("code").at(index).toElement().text();

    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp.append("&type=");
    temp.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url(temp);
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp2.append("&type=");
    temp2.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp3.append("&type=");
    temp3.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp4.append("&type=");
    temp4.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp5.append("&type=");
    temp5.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp6.append("&type=");
    temp6.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(topThreeXml.elementsByTagName("code").at(index).toElement().text());
    temp7.append("&type=");
    temp7.append(topThreeXml.elementsByTagName("type").at(index).toElement().text());

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
}

void MainWindow::hk1Btn360Clicked()
{
    detail360Handler(0);
}

void MainWindow::hk2Btn360Clicked()
{
    detail360Handler(1);
}

void MainWindow::hk3Btn360Clicked()
{
    detail360Handler(2);
}

void MainWindow::hk4Btn360Clicked()
{
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=hk";
    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = district360MoreMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::kl1Btn360Clicked()
{
    detail360Handler(3);
}

void MainWindow::kl2Btn360Clicked()
{
    detail360Handler(4);
}

void MainWindow::kl3Btn360Clicked()
{
    detail360Handler(5);
}

void MainWindow::kl4Btn360Clicked()
{
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=kl";
    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = district360MoreMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::nte1Btn360Clicked()
{
    detail360Handler(6);
}

void MainWindow::nte2Btn360Clicked()
{
    detail360Handler(7);
}

void MainWindow::nte3Btn360Clicked()
{
    detail360Handler(8);
}

void MainWindow::nte4Btn360Clicked()
{
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=ne";
    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = district360MoreMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::ntw1Btn360Clicked()
{
    detail360Handler(9);
}

void MainWindow::ntw2Btn360Clicked()
{
    detail360Handler(10);
}

void MainWindow::ntw3Btn360Clicked()
{
    detail360Handler(11);
}

void MainWindow::ntw4Btn360Clicked()
{
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=nw";
    QUrl url(temp);
    qDebug()<<temp;
    QNetworkReply* reply = district360MoreMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}
void MainWindow::nextImage()
{
    if(imageNumber < postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").count()-1)
    {
        imageNumber++;
        QString tmp;
        tmp.setNum(imageNumber+1);
        ui->detailImageCount->setText(tmp);
        previewImageDownload();
    }
}

void MainWindow::previousImage()
{
    if(imageNumber > 0)
    {
        imageNumber--;
        QString tmp;
        tmp.setNum(imageNumber+1);
        ui->detailImageCount->setText(tmp);
        previewImageDownload();
    }
}

void MainWindow::previewImageDownload()
{
    QString temp = postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").at(imageNumber).toElement().text();
    QUrl url(temp);
    QNetworkReply* reply = previewImageMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::previreImageDownloadFinished(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
        qDebug()<<"Image Download";
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        qDebug()<<"Image Download";
        ui->previewImage->setPixmap(QPixmap::fromImage(image));
        ui->previewCaption->setText(postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").at(imageNumber).toElement().attribute("Caption"));
        pagePreview();
    }
    }
}

void MainWindow::districtAreaListClicked(QModelIndex index)
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtAreaCode.at(ui->list_districtArea->currentIndex().row()));
    temp.append("&type=");
    temp.append(districtAreaType.at(ui->list_districtArea->currentIndex().row()));
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::districtAreaResult(QNetworkReply *reply)
{
    districtAreaName.clear();
    districtAreaNameEn.clear();
    districtAreaThumb.clear();
    districtAreaCode.clear();
    districtAreaType.clear();
    districtAreaPrice.clear();
    districtAreaPPS.clear();
    districtAreaPercent.clear();
    qDebug()<<"District Area Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtAreaXml.setContent(string.toAscii());

    for(int i=0;i<districtAreaXml.elementsByTagName("Table").count();i++)
    {
        districtAreaName.append(districtAreaXml.elementsByTagName("namec").at(i).toElement().text());
        districtAreaNameEn.append(districtAreaXml.elementsByTagName("namee").at(i).toElement().text());
        if(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("path").count() > 0)
            districtAreaThumb.append(districtAreaXml.elementsByTagName("Table").at(i).toElement().elementsByTagName("path").at(0).toElement().text());
        else
            districtAreaThumb.append("");
        districtAreaCode.append(districtAreaXml.elementsByTagName("code").at(i).toElement().text());
        districtAreaType.append(districtAreaXml.elementsByTagName("type").at(i).toElement().text());
        qDebug()<<" : "<<districtAreaThumb.at(i);
    }

    QUrl url(districtAreaThumb.at(0));
    QNetworkReply* reply2 = districtAreaImageMan->get(QNetworkRequest(url));


}

void MainWindow::districtAreaImageDownloaded(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        QString tmp = districtAreaThumb.at(districtCount);
        if(tmp.length() < 1)
        {
            districtThumb[districtCount] = p;
            qDebug()<<"clear";
        }
        else
            districtThumb[districtCount] = QPixmap::fromImage(image).scaled(QSize(60,60));
        qDebug()<<":"<<tmp.length();
        qDebug()<<":"<<tmp;

    }

}
    else
    {
        districtThumb[districtCount] = p;
    }

    if(districtCount == districtAreaThumb.size()-1)
    {

        qDebug()<<"District Image Download  postCount : "<<districtCount;
        QStringList a;
        districtAreaListModel *postModel = new districtAreaListModel(districtAreaName,districtAreaNameEn,a,a,a,districtThumb,this);
        ui->list_districtArea->setModel(postModel);

        districtAreaListDelegate* delegate = new districtAreaListDelegate(this);

        ui->list_districtArea->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(13);
        ui->loading->setVisible(false);
        districtCount=0;

    }
    else
    {
        districtCount++;
        QUrl url(districtAreaThumb.at(districtCount));
        QNetworkReply* reply = districtAreaImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::districtListClicked(QModelIndex index)
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
    refNo = refNoList.at(ui->list_districtSearch->currentIndex().row());
    temp.append(refNo);
    if(districtLink.indexOf("pt=s") != -1)
        temp.append("&pt=s");
    else
        temp.append("&pt=r");

    QUrl url(temp);
    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::districtListUpdated()
{
    QString temp = districtLink;
    districtSii+=10;
    QString sii = "";
    sii.setNum(districtSii);
    temp.append("&sii=");
    temp.append(sii);
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::districtListChangeToRent()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    postCount = 0;
    pt = "pt=r";
    if(districtLink.indexOf("pt=s") != -1)
    {
        districtLink.replace("pt=s","pt=r");
    }
    QUrl url(districtLink);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::districtListChangeToSell()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    postCount = 0;
    pt = "pt=s";
    if(districtLink.indexOf("pt=r") != -1)
    {
        districtLink.replace("pt=r","pt=s");
    }
    QUrl url(districtLink);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::districtSearchResult(QNetworkReply *reply)
{
ui->loading->setVisible(true);

    qDebug()<<"District Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    districtListXml.setContent(string.toAscii());

    for(int i=0;i<districtListXml.elementsByTagName("Post").count();i++)
    {

        QString tmp = districtListXml.elementsByTagName("bigestCName").at(i).toElement().text();
        tmp.append(districtListXml.elementsByTagName("estCName").at(i).toElement().text());
        if(districtListXml.elementsByTagName("estCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        tmp.append(districtListXml.elementsByTagName("blgCName").at(i).toElement().text());
        if(districtListXml.elementsByTagName("blgCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        if(tmp.length() < 1)
            tmp = districtListXml.elementsByTagName("address").at(i).toElement().text();
        QString tmpUnit = districtListXml.elementsByTagName("unit").at(i).toElement().text();
        if(tmpUnit.length() > 0)
        {
        tmp.append("(");
        tmp.append(tmpUnit);
        tmp.append("室)");
        }
        if(tmp != "")
        {

        name.append(tmp);
        }
        else
        {
            tmp = districtListXml.elementsByTagName("address").at(i).toElement().text();
            if(tmpUnit.length() > 0)
            {
            tmp.append("(");
            tmp.append(tmpUnit);
            tmp.append("室)");
            }
        name.append(tmp);
        }
        suite.append(districtListXml.elementsByTagName("suiteCount").at(i).toElement().text());
        refNoList.append(districtListXml.elementsByTagName("refNo").at(i).toElement().text());
        area.append(districtListXml.elementsByTagName("scpCName").at(i).toElement().text());
        QString tmpPrice_s = districtListXml.elementsByTagName("price").at(i).toElement().text();
        tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());

        int tmpPrice = tmpPrice_s.toInt();
        qDebug()<<tmpPrice;
        if(tmpPrice > 0)
        {

            if(tmpPrice > 100000)
            {
                tmpPrice = tmpPrice/10000;
                tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
            }
            if(tmpPrice > 9999)
            {
                if(tmpPrice == 10000)
                {
                   tmpPrice_s = "1億";
                }
                else
                {
                    tmpPrice = tmpPrice - 10000;
                    tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
                    tmpPrice_s.prepend("1億");
                    tmpPrice_s.append("萬");

                }

            }
            else if(tmpPrice > 999)
            {
                tmpPrice_s.insert(1,",");
                tmpPrice_s.append("萬");
            }
            else
                tmpPrice_s.append("萬");
            tmpPrice_s.prepend("$");
            price.append(tmpPrice_s);
        }
        else
        {

            tmpPrice_s = districtListXml.elementsByTagName("rental").at(i).toElement().text();
            tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());
            tmpPrice = tmpPrice_s.toInt();
            tmpPrice_s.prepend("$");
            if(tmpPrice > 99999)
                tmpPrice_s.insert(4,",");
            else if(tmpPrice > 9999)
                tmpPrice_s.insert(3,",");
            else if(tmpPrice > 999)
                tmpPrice_s.insert(2,",");
            price.append(tmpPrice_s);
        }
        QString tmpRoom = districtListXml.elementsByTagName("roomCount").at(i).toElement().text();
        QString tmpSuite = districtListXml.elementsByTagName("suiteCount").at(i).toElement().text();
        int tmpSuite_i = tmpSuite.toInt();
        int tmpRoom_i = tmpRoom.toInt();
        if(tmpRoom_i > 0)
            {
            tmpRoom.append("房");
            if(tmpSuite_i > 0)
            {
                tmpRoom.append("(");
                tmpRoom.append(tmpSuite);
                tmpRoom.append("套房)");
            }
            room.append(tmpRoom);
            }
        else
            room.append("");
        thumb.append(districtListXml.elementsByTagName("thumb").at(i).toElement().text());
        QString tmppps_s = districtListXml.elementsByTagName("unitPrice").at(i).toElement().text();
        tmppps_s.remove(tmppps_s.length()-5,tmppps_s.length());

        int tmppps = tmppps_s.toInt();
        qDebug()<<tmppps;
        if(tmppps > 0)
            pps.append(districtListXml.elementsByTagName("unitPrice").at(i).toElement().text());
        else
            pps.append(districtListXml.elementsByTagName("unitRental").at(i).toElement().text());
        QString tmpSize = districtListXml.elementsByTagName("area").at(i).toElement().text();
        tmpSize.remove(tmpSize.indexOf("."),tmpSize.length());
        int tmpSize_i = tmpSize.toInt();
        if(tmpSize_i > 999)
            tmpSize.insert(1,",");
        tmpSize.append("呎");
        if(districtListXml.elementsByTagName("approx").at(i).toElement().text() == "true")
            tmpSize.prepend("約");
        size.append(tmpSize);

    }
    qDebug()<<"District Download : "<<thumb.size();
        QUrl url(thumb.at(0));
        QNetworkReply* reply2 = districtSearchImageMan->get(QNetworkRequest(url));
    qDebug()<<"District Download";

}

void MainWindow::districtImageDownloaded(QNetworkReply *reply)
{


        if (!reply->error())
        {
        QImage image;
        if (image.loadFromData(reply->readAll()))
        {
        postThumb[postCount] = QPixmap::fromImage(image);
    }
    }

        if(postCount == thumb.size()-1)
        {

            qDebug()<<"District Image Download  postCount : "<<postCount;
            postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
            ui->list_districtSearch->setModel(postModel);

            postSearchListDelegate* delegate = new postSearchListDelegate(this);

            ui->list_districtSearch->setItemDelegate(delegate);


            ui->Content->setCurrentIndex(11);
            ui->loading->setVisible(false);

        }
        else
        {
            postCount++;
            QUrl url(thumb.at(postCount));
            QNetworkReply* reply = districtSearchImageMan->get(QNetworkRequest(url));

        }
}


void MainWindow::hk1BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(0).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(0).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));


}

void MainWindow::hk2BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(1).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(1).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::hk3BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(2).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(2).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::hk4BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=hk";
    QUrl url(temp);
    QNetworkReply* reply = districtAreaMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::kl1BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(3).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(3).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::kl2BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(4).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(4).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::kl3BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(5).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(5).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::kl4BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=kl";
    QUrl url(temp);
    QNetworkReply* reply = districtAreaMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::nte1BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(6).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(6).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::nte2BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(7).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(7).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::nte3BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(8).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(8).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::nte4BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=ne";
    QUrl url(temp);
    QNetworkReply* reply = districtAreaMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::ntw1BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(9).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(9).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::ntw2BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(10).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(10).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::ntw3BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&code=";
    temp.append(districtXml.elementsByTagName("code").at(11).toElement().text());
    temp.append("&type=");
    temp.append(districtXml.elementsByTagName("type").at(11).toElement().text());
    qDebug()<<temp;
    districtLink = temp;
    QUrl url(temp);
    QNetworkReply* reply = districtSearchMan->get(QNetworkRequest(url));
}

void MainWindow::ntw4BtnClicked()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    pt = "pt=s";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=district&p1=nw";
    QUrl url(temp);
    QNetworkReply* reply = districtAreaMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);
}

void MainWindow::resetBlogSearch()
{
    ui->inputField_blogName->setText("");
    ui->inputField_blogNumber->setText("");
    ui->blogareaBtn->setText("市場分區:未選取");
    blogCode = "";
    blogType = "";
}

void MainWindow::blogDetailListUpdated()
{
    ui->loading->setVisible(true);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?";
    if(isSell)
        temp.append("pt=s");
    else
        temp.append("pt=r");
    temp.append("&alic=");
    temp.append(refNo);
    postSii += 10;
    QString sii = "";
    sii.setNum(postSii);
    temp.append("&sii=");
    temp.append(sii);

    QUrl url(temp);
    QNetworkReply* reply = blogDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::blogDetailClicked(QModelIndex index)
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
    refNo = refNoList.at(ui->list_blogDetail->currentIndex().row());
    temp.append(refNo);
    if(isSell)
        temp.append("&pt=s");
    else
        temp.append("&pt=r");
    QUrl url(temp);
    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}


void MainWindow::blogDetailResult(QNetworkReply *reply)
{
    isDetail = false;
    qDebug()<<"Result Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
            //qDebug()<<string;
    postXml.setContent(string.toAscii());
    qDebug()<<"1";
    qDebug()<<"count : "<<postXml.elementsByTagName("Post").count();
    if(postXml.elementsByTagName("Post").count()>0)
    {

    for(int i=0;i<postXml.elementsByTagName("Post").count();i++)
    {

        QString tmp = postXml.elementsByTagName("bigestCName").at(i).toElement().text();
        tmp.append(postXml.elementsByTagName("estCName").at(i).toElement().text());
        if(postXml.elementsByTagName("estCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        tmp.append(postXml.elementsByTagName("blgCName").at(i).toElement().text());
        if(postXml.elementsByTagName("blgCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        if(tmp.length() < 1)
            tmp = postXml.elementsByTagName("address").at(i).toElement().text();
        QString tmpUnit = postXml.elementsByTagName("unit").at(i).toElement().text();
        if(tmpUnit.length() > 0)
        {
        tmp.append("(");
        tmp.append(tmpUnit);
        tmp.append("室)");
    }
        if(tmp != "")
        {

        name.append(tmp);
        }
        else
        {
            tmp = postXml.elementsByTagName("address").at(i).toElement().text();
            if(tmpUnit.length() > 0)
            {
            tmp.append("(");
            tmp.append(tmpUnit);
            tmp.append("室)");
        }
        name.append(tmp);
        }
        suite.append(postXml.elementsByTagName("suiteCount").at(i).toElement().text());
        area.append(postXml.elementsByTagName("scpCName").at(i).toElement().text());
        refNoList.append(postXml.elementsByTagName("refNo").at(i).toElement().text());
        QString tmpPrice_s = postXml.elementsByTagName("price").at(i).toElement().text();
        tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());

        int tmpPrice = tmpPrice_s.toInt();
        qDebug()<<tmpPrice;
        if(tmpPrice > 0)
        {

            if(tmpPrice > 100000)
            {
                tmpPrice = tmpPrice/10000;
                tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
            }
            if(tmpPrice > 9999)
            {
                if(tmpPrice == 10000)
                {
                   tmpPrice_s = "1億";
                }
                else
                {
                    tmpPrice = tmpPrice - 10000;
                    tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
                    tmpPrice_s.prepend("1億");
                    tmpPrice_s.append("萬");
                }

            }
            else if(tmpPrice > 999)
            {
                tmpPrice_s.insert(1,",");
                tmpPrice_s.append("萬");
            }
            else
                tmpPrice_s.append("萬");
            tmpPrice_s.prepend("$");
            price.append(tmpPrice_s);
        }
        else
        {

            tmpPrice_s = postXml.elementsByTagName("rental").at(i).toElement().text();
            tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());
            tmpPrice = tmpPrice_s.toInt();
            tmpPrice_s.prepend("$");
            if(tmpPrice > 99999)
                tmpPrice_s.insert(4,",");
            else if(tmpPrice > 9999)
                tmpPrice_s.insert(3,",");
            else if(tmpPrice > 999)
                tmpPrice_s.insert(2,",");
            price.append(tmpPrice_s);
        }
        QString tmpRoom = postXml.elementsByTagName("roomCount").at(i).toElement().text();
        QString tmpSuite = postXml.elementsByTagName("suiteCount").at(i).toElement().text();
        int tmpSuite_i = tmpSuite.toInt();
        int tmpRoom_i = tmpRoom.toInt();
        if(tmpRoom_i > 0)
        {
        tmpRoom.append("房");
        if(tmpSuite_i > 0)
        {
            tmpRoom.append("(");
            tmpRoom.append(tmpSuite);
            tmpRoom.append("套房)");
        }
        room.append(tmpRoom);
        }
        else
        room.append("");
        thumb.append(postXml.elementsByTagName("thumb").at(i).toElement().text());
        QString tmppps_s = postXml.elementsByTagName("unitPrice").at(i).toElement().text();
        tmppps_s.remove(tmppps_s.length()-5,tmppps_s.length());

        int tmppps = tmppps_s.toInt();
        qDebug()<<tmppps;
        if(tmppps > 0)
            pps.append(postXml.elementsByTagName("unitPrice").at(i).toElement().text());
        else
            pps.append(postXml.elementsByTagName("unitRental").at(i).toElement().text());
        QString tmpSize = postXml.elementsByTagName("area").at(i).toElement().text();
        tmpSize.remove(tmpSize.length()-3,tmpSize.length());
        int tmpSize_i = tmpSize.toInt();
        if(tmpSize_i > 999)
            tmpSize.insert(1,",");
        tmpSize.append("呎");
        if(postXml.elementsByTagName("approx").at(i).toElement().text() == "true")
            tmpSize.prepend("約");
        size.append(tmpSize);
    }

    QUrl url(thumb.at(0));
    QNetworkReply* reply2 = blogDetailImageMan->get(QNetworkRequest(url));
    }
    else
    {
        qDebug()<<"2";
        postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
        ui->list_blogDetail->setModel(postModel);

        postSearchListDelegate* delegate = new postSearchListDelegate(this);

        ui->list_blogDetail->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(10);
        qDebug()<<"3";
    }
}

void MainWindow::blogDetailImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    postThumb[postCount] = QPixmap::fromImage(image);
}
}

    if(postCount == thumb.size()-1)
    {
        postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
        ui->list_blogDetail->setModel(postModel);

        postSearchListDelegate* delegate = new postSearchListDelegate(this);

        ui->list_blogDetail->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(10);
        ui->loading->setVisible(false);

    }
    else
    {
        postCount++;
        QUrl url(thumb.at(postCount));
        QNetworkReply* reply2 = blogDetailImageMan->get(QNetworkRequest(url));
    }

}

void MainWindow::blogListUpdated()
{
    blogLicense = ui->inputField_blogNumber->text();
    blogName = ui->inputField_blogName->text();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Agentsearch.ashx?";
    if(blogLicense!="")
    {
    temp.append("alic=");
    temp.append(blogLicense);
    }
    if(blogName!="")
    {
    temp.append("&name=");
    temp.append(blogName);
    }
    temp.append("&");
    temp.append(blogCode);
    temp.append("&");
    temp.append(blogType);

    blogSii += 10;
    QString sii = "";
    sii.setNum(blogSii);
    temp.append("&sii=");
    temp.append(sii);


    QUrl url(temp);
    QNetworkReply* reply = blogSearchMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::blogDetailChangeToRent()
{
    isSell = false;
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    postCount = 0;
    pt = "pt=r";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=r&alic=";
    temp.append(refNo);
    QUrl url(temp);
    QNetworkReply* reply = blogDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
    ui->loading->setVisible(true);
}

void MainWindow::blogDetailChangeToSell()
{

    isSell = true;
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    postCount = 0;
    pt = "pt=s";
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&alic=";
    temp.append(refNo);
    QUrl url(temp);
    QNetworkReply* reply = blogDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
    ui->loading->setVisible(true);
}

void MainWindow::blogListClicked(QModelIndex index)
{
    blogCount = 0;
    contact = blogXml.elementsByTagName("contact").at(ui->list_blog->currentIndex().row()).toElement().text();
    QString tmp = "致電";
    tmp.append(blogXml.elementsByTagName("nameTc").at(ui->list_blog->currentIndex().row()).toElement().text());
    tmp.append(":");
    tmp.append(blogXml.elementsByTagName("contact").at(ui->list_blog->currentIndex().row()).toElement().text());
    ui->pushButton_3->setText(tmp);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&alic=";
    refNo = license.at(ui->list_blog->currentIndex().row());
    ui->blogDetailImage->setPixmap(blogThumb[ui->list_blog->currentIndex().row()]);
    ui->blogDetailPhone->setText(blogXml.elementsByTagName("contact").at(ui->list_blog->currentIndex().row()).toElement().text());
    ui->blogDetailAddress->setText(blogXml.elementsByTagName("branch").at(ui->list_blog->currentIndex().row()).toElement().text());
    QString tmpName = blogXml.elementsByTagName("nameTc").at(ui->list_blog->currentIndex().row()).toElement().text();
    tmpName.append("(");
    tmpName.append(refNo);
    tmpName.append(")");
    ui->blogDetailName->setText(tmpName);
    ui->blogDetailOtherName->setText(blogXml.elementsByTagName("nameEn").at(ui->list_blog->currentIndex().row()).toElement().text());
    temp.append(refNo);
    QUrl url(temp);
    QNetworkReply* reply = blogDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
    ui->loading->setVisible(true);
}

void MainWindow::blogSearchResult(QNetworkReply *reply)
{
    qDebug()<<"Blog Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
            //qDebug()<<string;
    blogXml.setContent(string.toAscii());
    if(blogXml.elementsByTagName("Agent").count() > 0)
    {
    for(int i=0;i<blogXml.elementsByTagName("Agent").count();i++)
    {
        QString tmpName = blogXml.elementsByTagName("nameTc").at(i).toElement().text();

        tmpName.append("(");
        tmpName.append(blogXml.elementsByTagName("license").at(i).toElement().text());
        tmpName.append(")");
        agentName.append(tmpName);
        agentNameEn.append(blogXml.elementsByTagName("nameEn").at(i).toElement().text());
        QString tmpBranch = blogXml.elementsByTagName("branch").at(i).toElement().text();
        if(tmpBranch.length() > 25)
        {
            tmpBranch.remove(25,tmpBranch.length());
            tmpBranch.append("...");
        }
        agentAddress.append(tmpBranch);
        QString tmp = blogXml.elementsByTagName("postCnt").at(i).toElement().text();
        tmp.prepend("共");
        tmp.append("個盤");
        agentCount.append(tmp);
        license.append(blogXml.elementsByTagName("license").at(i).toElement().text());
        agentThumb.append(blogXml.elementsByTagName("image").at(i).toElement().text());
    }


        QUrl url(agentThumb.at(0));
        QNetworkReply* reply2 = blogImageMan->get(QNetworkRequest(url));
    }
    else
    {
        ui->loading->setVisible(false);

         msgBox4.exec();
    }



}

void MainWindow::blogImageDownloaded(QNetworkReply *reply)
{
    qDebug()<<"Image Download";
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    blogThumb[blogCount] = QPixmap::fromImage(image);
}
}
    //qDebug()<<postCount;
    //qDebug()<<postXml.elementsByTagName("Post").count();

    if(blogCount == agentThumb.count()-1)
    {



        blogSearchListModel *blogModel = new blogSearchListModel(agentName,agentNameEn,agentAddress,agentCount,blogThumb,this);
        ui->list_blog->setModel(blogModel);

        blogSearchListDelegate* delegate = new blogSearchListDelegate(this);

        ui->list_blog->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(9);

        ui->loading->setVisible(false);
    }
    else
    {
        blogCount++;
        QUrl url(agentThumb.at(blogCount));
        QNetworkReply* reply2 = blogImageMan->get(QNetworkRequest(url));

    }

}

void MainWindow::blogSearch()
{
    name.clear();
    suite.clear();
    refNoList.clear();
    area.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    price.clear();
    ui->loading->setVisible(true);
    blogLicense = ui->inputField_blogNumber->text();
    blogName = ui->inputField_blogName->text();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Agentsearch.ashx?";
    if(blogLicense!="")
    {
    temp.append("alic=");
    temp.append(blogLicense);
    }
    if(blogName!="")
    {
    temp.append("&name=");
    temp.append(blogName);
    }
    temp.append("&");
    temp.append(blogCode);
    temp.append("&");
    temp.append(blogType);

    blogCount = 0;
    QUrl url(temp);
    QNetworkReply* reply = blogSearchMan->get(QNetworkRequest(url));
    qDebug()<<temp;
    ui->loading->setVisible(true);
}

void MainWindow::trade1Click()
{

    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = recentTradeXml.elementsByTagName("type").at(0).toElement().text();

    code = recentTradeXml.elementsByTagName("code").at(0).toElement().text();


    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp.append("&type=");
    temp.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url(temp);
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp2.append("&type=");
    temp2.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp3.append("&type=");
    temp3.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp4.append("&type=");
    temp4.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp5.append("&type=");
    temp5.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp6.append("&type=");
    temp6.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(recentTradeXml.elementsByTagName("code").at(0).toElement().text());
    temp7.append("&type=");
    temp7.append(recentTradeXml.elementsByTagName("type").at(0).toElement().text());

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
    changeTab2_2();
}

void MainWindow::trade2Click()
{

    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();
    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp.append("&type=");
    temp.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url(temp);
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp2.append("&type=");
    temp2.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp3.append("&type=");
    temp3.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp4.append("&type=");
    temp4.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp5.append("&type=");
    temp5.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp6.append("&type=");
    temp6.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(recentTradeXml.elementsByTagName("code").at(1).toElement().text());
    temp7.append("&type=");
    temp7.append(recentTradeXml.elementsByTagName("type").at(1).toElement().text());

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
    changeTab2_2();
}

void MainWindow::trade3Click()
{

    estateNumber = 0;
    facilityNumber = 0;
    address_s.clear();
    date_s.clear();
    price_s.clear();
    size_s.clear();
    pps_s.clear();
    type_s.clear();
    address_r.clear();
    date_r.clear();
    price_r.clear();
    size_r.clear();
    pps_r.clear();
    type_r.clear();

    type = recentTradeXml.elementsByTagName("type").at(2).toElement().text();

    code = recentTradeXml.elementsByTagName("code").at(2).toElement().text();

    qDebug()<<"click";
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=0&code=";
    temp.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp.append("&type=");
    temp.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url(temp);
    QNetworkReply* reply = detail360Man1->get(QNetworkRequest(url));

    QString temp2 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=1&code=";
    temp2.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp2.append("&type=");
    temp2.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url2(temp2);
    QNetworkReply* reply2 = detail360Man2->get(QNetworkRequest(url2));

    QString temp3 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=4&code=";
    temp3.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp3.append("&type=");
    temp3.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url3(temp3);
    QNetworkReply* reply3 = detail360Man3->get(QNetworkRequest(url3));

    QString temp4 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=2&code=";
    temp4.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp4.append("&type=");
    temp4.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url4(temp4);
    QNetworkReply* reply4 = detail360Man4->get(QNetworkRequest(url4));

    QString temp5 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detail&tab=3&code=";
    temp5.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp5.append("&type=");
    temp5.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url5(temp5);
    QNetworkReply* reply5 = detail360Man5->get(QNetworkRequest(url5));

    QString temp6 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=estatephoto&code=";
    temp6.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp6.append("&type=");
    temp6.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url6(temp6);
    QNetworkReply* reply6 = detail360Man6->get(QNetworkRequest(url6));

    QString temp7 = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=facilityphoto&code=";
    temp7.append(recentTradeXml.elementsByTagName("code").at(2).toElement().text());
    temp7.append("&type=");
    temp7.append(recentTradeXml.elementsByTagName("type").at(2).toElement().text());

    QUrl url7(temp7);
    QNetworkReply* reply7 = detail360Man7->get(QNetworkRequest(url7));

    ui->Content->setCurrentIndex(15);
    ui->tabBar->setCurrentIndex(1);
    changeTab2_2();
}

void MainWindow::recentTradeResult(QNetworkReply *reply)
{
    qDebug()<<"Recent Trade Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    recentTradeXml.setContent(string.toAscii());
    QString tmp1 = recentTradeXml.elementsByTagName("address").at(0).toElement().text();
    tmp1.append("       ");
    QString tmpArea = recentTradeXml.elementsByTagName("int_garea").at(0).toElement().text();
    int tmpArea_i = tmpArea.toInt();
    if(tmpArea_i > 999)
        tmpArea.insert(1,",");
    tmp1.append(tmpArea);
    tmp1.append("呎       ");
    QString tmpPrice = recentTradeXml.elementsByTagName("consider").at(0).toElement().text();
    int tmpPrice_i = tmpPrice.toInt();
    tmpPrice_i = tmpPrice_i/10000;
    tmpPrice = tmpPrice.setNum(tmpPrice_i);
    tmp1.append("$");
    if(tmpPrice_i > 999)
    {
        tmpPrice.insert(1,",");
    }
    tmp1.append(tmpPrice);
    tmp1.append("萬>");
    QString tmp2 = recentTradeXml.elementsByTagName("address").at(1).toElement().text();
    tmp2.append("       ");
    tmpArea = recentTradeXml.elementsByTagName("int_garea").at(1).toElement().text();
    tmpArea_i = tmpArea.toInt();
    if(tmpArea_i > 999)
        tmpArea.insert(1,",");
    tmp2.append(tmpArea);
    tmp2.append("呎       ");
    tmpPrice = recentTradeXml.elementsByTagName("consider").at(1).toElement().text();
    tmpPrice_i = tmpPrice.toInt();
    tmpPrice_i = tmpPrice_i/10000;
    tmpPrice = tmpPrice.setNum(tmpPrice_i);
    tmp2.append("$");
    if(tmpPrice_i > 999)
    {
        tmpPrice.insert(1,",");
    }
    tmp2.append(tmpPrice);
    tmp2.append("萬>");
    QString tmp3 = recentTradeXml.elementsByTagName("address").at(2).toElement().text();
    tmp3.append("       ");
    tmpArea = recentTradeXml.elementsByTagName("int_garea").at(2).toElement().text();
    tmpArea_i = tmpArea.toInt();
    if(tmpArea_i > 999)
        tmpArea.insert(1,",");
    tmp3.append(tmpArea);
    tmp3.append("呎       ");
    tmpPrice = recentTradeXml.elementsByTagName("consider").at(2).toElement().text();
    tmpPrice_i = tmpPrice.toInt();
    tmpPrice_i = tmpPrice_i/10000;
    tmpPrice = tmpPrice.setNum(tmpPrice_i);
    tmp3.append("$");
    if(tmpPrice_i > 999)
    {
        tmpPrice.insert(1,",");
    }
    tmp3.append(tmpPrice);
    tmp3.append("萬>");
    switch(recentTradeXml.elementsByTagName("Table").count())
    {
    case 0:
        ui->postDetailTrade1->setText("");
        ui->postDetailTrade2->setText("");
        ui->postDetailTrade3->setText("");
        break;
    case 1:
        ui->postDetailTrade1->setText(tmp1);
        ui->postDetailTrade2->setText("");
        ui->postDetailTrade3->setText("");
        break;
    case 2:
        ui->postDetailTrade1->setText(tmp1);
        ui->postDetailTrade2->setText(tmp2);
        ui->postDetailTrade3->setText("");
        break;
    case 3:
        ui->postDetailTrade1->setText(tmp1);
        ui->postDetailTrade2->setText(tmp2);
        ui->postDetailTrade3->setText(tmp3);
        break;

    }




}

void MainWindow::postListClicked(QModelIndex index)
{
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/Post.ashx?ref=";
    refNo = refNoList.at(ui->list_postSearch->currentIndex().row());
    temp.append(refNo);
    temp.append("&");
    temp.append(pt);
    QUrl url(temp);
    QNetworkReply* reply = postDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::postDetailPromotion()
{
    ui->loading->setVisible(true);
    QString tmp = "致電";
    tmp.append(postDetailXml.elementsByTagName("nameTc").at(0).toElement().text());
    tmp.append(":");
    tmp.append(postDetailXml.elementsByTagName("contact").at(0).toElement().text());
    ui->pushButton_3->setText(tmp);
    contact = postDetailXml.elementsByTagName("contact").at(0).toElement().text();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?pt=s&alic=";
    refNo = postDetailXml.elementsByTagName("license").at(0).toElement().text();
    ui->blogDetailImage->setPixmap(agentImage);
    ui->blogDetailPhone->setText(postDetailXml.elementsByTagName("contact").at(0).toElement().text());
    ui->blogDetailAddress->setText(postDetailXml.elementsByTagName("branch").at(0).toElement().text());
    QString tmpName = postDetailXml.elementsByTagName("nameTc").at(0).toElement().text();
    tmpName.append("(");
    tmpName.append(refNo);
    tmpName.append(")");
    ui->blogDetailName->setText(tmpName);
    //ui->blogDetailName->setText(postDetailXml.elementsByTagName("nameTc").at(0).toElement().text());
    ui->blogDetailOtherName->setText(postDetailXml.elementsByTagName("nameEn").at(0).toElement().text());
    temp.append(refNo);
    QUrl url(temp);
    QNetworkReply* reply = blogDetailMan->get(QNetworkRequest(url));
    qDebug()<<temp;
    blogCount = 0;
}

void MainWindow::postDetailFinished(QNetworkReply *reply)
{
    isDetail = true;
    ui->loading->setVisible(false);
    qDebug()<<"Details Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
            //qDebug()<<string;
    postDetailXml.setContent(string.toAscii());
    qDebug()<<"at : "<<postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").at(0).toElement().attribute("Caption");
    QString tmpName = postDetailXml.elementsByTagName("bigestCName").at(0).toElement().text();
    if(postDetailXml.elementsByTagName("bigestCName").at(0).toElement().text().length() > 0)
        tmpName.append(" ");
    tmpName.append(postDetailXml.elementsByTagName("estCName").at(0).toElement().text());
    if(postDetailXml.elementsByTagName("estCName").at(0).toElement().text().length() > 0)
        tmpName.append(" ");
    tmpName.append(postDetailXml.elementsByTagName("blgCName").at(0).toElement().text());
    if(postDetailXml.elementsByTagName("blgCName").at(0).toElement().text().length() > 0)
        tmpName.append(" ");
    QString tmpUnit = postDetailXml.elementsByTagName("unit").at(0).toElement().text();

    qDebug()<<tmpName.length();
    if(tmpName.length() < 2)
    {
        tmpName.append(postDetailXml.elementsByTagName("Address").at(0).toElement().text());
    }
    tmpName.append(postDetailXml.elementsByTagName("floorLevel").at(0).toElement().text());
    if(tmpUnit.length() > 0)
    {
        tmpName.append("(");
        tmpName.append(tmpUnit);
        tmpName.append("室)");
    }
    tmpName.replace("‧",".");

    ui->postDetailName->setText(tmpName);
    ui->postDetailEngName->setText(postDetailXml.elementsByTagName("namee").at(0).toElement().text());
    ui->postDetailPinNumber->setText(postDetailXml.elementsByTagName("refNo").at(0).toElement().text());
    ui->postDetailDistrcit->setText(postDetailXml.elementsByTagName("scpCName").at(0).toElement().text());
    ui->postDetailAddress->setText(postDetailXml.elementsByTagName("Address").at(0).toElement().text());
    refNo = postDetailXml.elementsByTagName("refNo").at(0).toElement().text();
    QString tmp = postDetailXml.elementsByTagName("price").at(0).toElement().text();
    tmp.remove(tmp.length()-3,tmp.length());
    int tmp2 = tmp.toInt();
    if(pt == "pt=s")
    {

        tmp2 = tmp2/10000;
        tmp = tmp.setNum(tmp2);
        if(tmp2 > 9999)
        {
            if(tmp2 == 10000)
            {
               tmp = "1億";
            }
            else
            {
                tmp2 = tmp2 - 10000;
                tmp.setNum(tmp2);
                tmp.prepend("1億");
                tmp.append("萬");
            }

        }
        else if(tmp2 > 999)
        {
            tmp.insert(1,",");
            tmp.append("萬");
        }
        else
            tmp.append("萬");
        //tmp.prepend("$");
        ui->label_15->setText("價格");
    }
    else
    {
        tmp = postDetailXml.elementsByTagName("rental").at(0).toElement().text();
        tmp.remove(tmp.length()-3,tmp.length());
        int tmp2 = tmp.toInt();
        if(tmp2 > 9999)
            tmp.insert(2,",");
        else if(tmp2 > 999)
            tmp.insert(1,",");
        ui->label_15->setText("租價");
    }
    QString tmp3 = postDetailXml.elementsByTagName("unitPrice").at(0).toElement().text();
    tmp3.remove(tmp3.length()-5,tmp3.length());
    int tmp4 = tmp3.toInt();
    if(pt == "pt=s")
    {
        if(tmp4 > 9999)
            tmp3.insert(2,",");
        else if(tmp4 > 999)
            tmp3.insert(1,",");
    }
    else
    {
        tmp3 = postDetailXml.elementsByTagName("unitRental").at(0).toElement().text();
        tmp3.remove(tmp3.length()-5,tmp3.length());
    }
    tmp3.prepend("($");
    tmp3.append("/呎)");

    tmp.append(tmp3);
    tmp.prepend("$");
    ui->postDetailPrice->setText(tmp);

    QString tmpArea_s = postDetailXml.elementsByTagName("area").at(0).toElement().text();
    tmpArea_s = tmpArea_s.remove(tmpArea_s.length()-3,tmpArea_s.length());
    int tmpArea_i = tmpArea_s.toInt();
    if(tmpArea_i > 999)
        tmpArea_s.insert(1,",");
    if(postDetailXml.elementsByTagName("approx").at(0).toElement().text() == "true")
        tmpArea_s.prepend("約");
    tmpArea_s.append("呎");
    ui->postDetailArea->setText(tmpArea_s);

    QString tmpFloor = postDetailXml.elementsByTagName("floorLevel").at(0).toElement().text();


    if(tmpUnit.length()>0)
    {
        tmpFloor.append("(");
        tmpFloor.append(tmpUnit);
        tmpFloor.append("室)");
    }
    ui->postDetailFloor->setText(tmpFloor);
    QString tmpRoom = postDetailXml.elementsByTagName("roomCount").at(0).toElement().text();
    QString tmpSuite = postDetailXml.elementsByTagName("suiteCount").at(0).toElement().text();
    tmpRoom.append("房");
    if(tmpSuite != "0")
    {
        tmpRoom.append("(");
        tmpRoom.append(tmpSuite);
        tmpRoom.append("套房)");
    }
    ui->postDetailRoom->setText(tmpRoom);
    if(postDetailXml.elementsByTagName("cdirection").at(0).toElement().text().length() > 0)
        ui->postDetailDirection->setText(postDetailXml.elementsByTagName("cdirection").at(0).toElement().text());
    else
        ui->postDetailDirection->setText("-");
    if(postDetailXml.elementsByTagName("cview").at(0).toElement().text().length() > 0)
        ui->postDetailView->setText(postDetailXml.elementsByTagName("cview").at(0).toElement().text());
    else
        ui->postDetailView->setText("-");
    if(postDetailXml.elementsByTagName("ccharacteristics").at(0).toElement().text().length() > 0)
        ui->postDetailCh->setText(postDetailXml.elementsByTagName("ccharacteristics").at(0).toElement().text());
    else
        ui->postDetailCh->setText("-");
    ui->postAgentEngName->setText(postDetailXml.elementsByTagName("nameEn").at(0).toElement().text());
    QString tmpName2 = postDetailXml.elementsByTagName("nameTc").at(0).toElement().text();
    tmpName2.append("(");
    tmpName2.append(postDetailXml.elementsByTagName("license").at(0).toElement().text());
    tmpName2.append(")");
    ui->postAgentName->setText(tmpName2);
    QString tmpBtn = "致電";
    tmpBtn.append(postDetailXml.elementsByTagName("nameTc").at(0).toElement().text());
    tmpBtn.append(":");
    tmpBtn.append(postDetailXml.elementsByTagName("contact").at(0).toElement().text());
    ui->pushButton_5->setText(tmpBtn);
    ui->postAgentPhone->setText(postDetailXml.elementsByTagName("contact").at(0).toElement().text());
    ui->postAgentAddress->setText(postDetailXml.elementsByTagName("branch").at(0).toElement().text());
    //ui->postOtherAgentName->setText(postDetailXml.elementsByTagName("ccharacteristics").at(0).toElement().text());
    QUrl url(postDetailXml.elementsByTagName("thumb").at(0).toElement().text());
    QNetworkReply* reply2 = postDetailImageMan->get(QNetworkRequest(url));
    QUrl url2(postDetailXml.elementsByTagName("image").at(0).toElement().text());
    QNetworkReply* reply3 = postDetailAgentImageMan->get(QNetworkRequest(url2));
    pageNumber = ui->Content->currentIndex();
    pageDetail1();
    if(postDetailXml.elementsByTagName("Agent2").count() > 0)
    {
        QString tmp = postDetailXml.elementsByTagName("nameTc").at(1).toElement().text();
        tmp.append("(");
        tmp.append(postDetailXml.elementsByTagName("license").at(1).toElement().text());
        tmp.append(")");

        ui->postOtherAgentName->setText(tmp);
        QString tmpBranch = postDetailXml.elementsByTagName("branch").at(1).toElement().text();
        if(tmpBranch.length() > 20)
            tmpBranch.insert(20,"\n");
        ui->postAgentBranch->setText(tmpBranch);
        ui->postOtherAgentName->setDisabled(false);
    }
    else
    {
        ui->postOtherAgentName->setDisabled(true);
        ui->postOtherAgentName->setText("");
        QString tmpBranch = postDetailXml.elementsByTagName("branch").at(0).toElement().text();
        if(tmpBranch.length() > 20)
            tmpBranch.insert(20,"\n");
        ui->postAgentBranch->setText(tmpBranch);
        //ui->postAgentBranch->setText(postDetailXml.elementsByTagName("branch").at(0).toElement().text());
    }
    QString tmpCount2;
    QString tmpCount = "共";
    tmpCount2.setNum(postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").count());
    tmpCount.append(tmpCount2);
    tmpCount.append("張圖片");

    tmpCount2.setNum(postDetailXml.elementsByTagName("photos2").at(0).toElement().elementsByTagName("Photo").count());
    ui->detailImageNumber->setText(tmpCount2);
    ui->detailImageCount->setText("1");
    ui->postDetailPhotoCount->setText(tmpCount);
    QString temp = "http://hkdata.centamobile.com/NokiaWS1/Handler1.ashx?fun=detailsummary&start=0&end=2&type=";
    temp.append(postDetailXml.elementsByTagName("type").at(0).toElement().text());
    temp.append("&code=");
    temp.append(postDetailXml.elementsByTagName("code").at(0).toElement().text());
    QUrl url3(temp);
    QNetworkReply* reply4 = recentTradeMan->get(QNetworkRequest(url3));
    qDebug()<<temp;
}

void MainWindow::postListUpdated()
{
    ui->loading->setVisible(true);
    keyWord = ui->inputField_conditionSearch->text();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?";
    temp.append(postCode);
    temp.append("&");
    temp.append(postType);
    temp.append("&");
    if(ui->radio_buy->isChecked())
        pt = "pt=s";
    else
        pt = "pt=r";
    temp.append(pt);
    temp.append("&");
    temp.append(postPrice);
    temp.append("&");
    temp.append(postSize);
    temp.append("&");
    if(ui->radio_1->isChecked())
        roomNumber = "rmCnt=1";
    else if(ui->radio_2->isChecked())
        roomNumber = "rmCnt=2";
    else if(ui->radio_3->isChecked())
        roomNumber = "rmCnt=3";
    else if(ui->radio_4->isChecked())
        roomNumber = "rmCnt=4";
    else
        roomNumber = "";
    temp.append(roomNumber);
    temp.append("&key=");
    temp.append(keyWord);
    postSii += 10;
    QString sii = "";
    sii.setNum(postSii);
    temp.append("&sii=");
    temp.append(sii);

    QUrl url(temp);
    QNetworkReply* reply = postSearchMan->get(QNetworkRequest(url));
    qDebug()<<temp;
}

void MainWindow::postSearch()
{
    name.clear();
    suite.clear();
    refNoList.clear();
    area.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    price.clear();
    ui->loading->setVisible(true);
    keyWord = ui->inputField_conditionSearch->text();
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/Symbian/PostSearch.ashx?";
    temp.append(postCode);
    temp.append("&");
    temp.append(postType);
    temp.append("&");
    if(ui->radio_buy->isChecked())
        pt = "pt=s";
    else
        pt = "pt=r";
    temp.append(pt);
    temp.append("&");
    temp.append(postPrice);
    temp.append("&");
    temp.append(postSize);
    temp.append("&");
    if(ui->radio_1->isChecked())
        roomNumber = "rmCnt=1";
    else if(ui->radio_2->isChecked())
        roomNumber = "rmCnt=2";
    else if(ui->radio_3->isChecked())
        roomNumber = "rmCnt=3";
    else if(ui->radio_4->isChecked())
        roomNumber = "rmCnt=4";
    else
        roomNumber = "";
    temp.append(roomNumber);
    temp.append("&key=");
    temp.append(keyWord);

    QUrl url(temp);
    QNetworkReply* reply = postSearchMan->get(QNetworkRequest(url));
    qDebug()<<temp;


}

void MainWindow::postSearchResult(QNetworkReply *reply)
{
    qDebug()<<"Result Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);

    postXml.setContent(string.toAscii());


    if(postXml.elementsByTagName("Post").count() > 0)
    {

    for(int i=0;i<postXml.elementsByTagName("Post").count();i++)
    {

        QString tmp = postXml.elementsByTagName("bigestCName").at(i).toElement().text();
        tmp.append(postXml.elementsByTagName("estCName").at(i).toElement().text());
        if(postXml.elementsByTagName("estCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        tmp.append(postXml.elementsByTagName("blgCName").at(i).toElement().text());
        if(postXml.elementsByTagName("blgCName").at(i).toElement().text().length() > 0)
            tmp.append(" ");
        if(tmp.length() < 1)
            tmp = postXml.elementsByTagName("address").at(i).toElement().text();
        QString tmpUnit = postXml.elementsByTagName("unit").at(i).toElement().text();
        if(tmpUnit.length() > 0)
        {
        tmp.append("(");
        tmp.append(tmpUnit);
        tmp.append("室)");
        }
        if(tmp != "")
        {

        name.append(tmp);
        }
        else
        {
            tmp = postXml.elementsByTagName("address").at(i).toElement().text();
            if(tmpUnit.length() > 0)
            {
            tmp.append("(");
            tmp.append(tmpUnit);
            tmp.append("室)");
            }
        name.append(tmp);
        }
        suite.append(postXml.elementsByTagName("suiteCount").at(i).toElement().text());
        refNoList.append(postXml.elementsByTagName("refNo").at(i).toElement().text());
        area.append(postXml.elementsByTagName("scpCName").at(i).toElement().text());
        QString tmpPrice_s = postXml.elementsByTagName("price").at(i).toElement().text();
        tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());

        int tmpPrice = tmpPrice_s.toInt();
        qDebug()<<tmpPrice;
        if(pt == "pt=s")
        {

            if(tmpPrice > 100000)
            {
                tmpPrice = tmpPrice/10000;
                tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
            }
            if(tmpPrice > 9999)
            {
                if(tmpPrice == 10000)
                    tmpPrice_s = "1億";
                else
                {
                    tmpPrice = tmpPrice - 10000;
                    tmpPrice_s = tmpPrice_s.setNum(tmpPrice);
                    tmpPrice_s.prepend("1億");
                    tmpPrice_s.append("萬");
                }
            }
            else if(tmpPrice > 999)
            {
                tmpPrice_s.insert(1,",");
            }
            tmpPrice_s.prepend("$");
            tmpPrice_s.append("萬");
            price.append(tmpPrice_s);
        }
        else
        {
            tmpPrice_s = postXml.elementsByTagName("rental").at(i).toElement().text();
            tmpPrice_s.remove(tmpPrice_s.length()-3,tmpPrice_s.length());
            tmpPrice = tmpPrice_s.toInt();
            if(tmpPrice > 99999)
                tmpPrice_s.insert(3,",");
            else if(tmpPrice > 9999)
                tmpPrice_s.insert(2,",");
            else if(tmpPrice > 999)
                tmpPrice_s.insert(1,",");
            tmpPrice_s.prepend("$");
            price.append(tmpPrice_s);
        }
        QString tmpRoom = postXml.elementsByTagName("roomCount").at(i).toElement().text();
        QString tmpSuite = postXml.elementsByTagName("suiteCount").at(i).toElement().text();
        int tmpSuite_i = tmpSuite.toInt();
        int tmpRoom_i = tmpRoom.toInt();
        if(tmpRoom_i > 0)
        {
        tmpRoom.append("房");
        if(tmpSuite_i > 0)
        {
            tmpRoom.append("(");
            tmpRoom.append(tmpSuite);
            tmpRoom.append("套房)");
        }
        room.append(tmpRoom);
        }
        else
        room.append("");
        thumb.append(postXml.elementsByTagName("thumb").at(i).toElement().text());
        QString tmppps_s = postXml.elementsByTagName("unitPrice").at(i).toElement().text();
        tmppps_s.remove(tmppps_s.length()-5,tmppps_s.length());

        int tmppps = tmppps_s.toInt();
        qDebug()<<tmppps;
        if(tmppps > 0)
            pps.append(postXml.elementsByTagName("unitPrice").at(i).toElement().text());
        else
            pps.append(postXml.elementsByTagName("unitRental").at(i).toElement().text());
        QString tmpSize = postXml.elementsByTagName("area").at(i).toElement().text();
        tmpSize.remove(tmpSize.length()-3,tmpSize.length());
        int tmpSize_i = tmpSize.toInt();
        if(tmpSize_i > 999)
            tmpSize.insert(1,",");
        tmpSize.append("呎");
        if(postXml.elementsByTagName("approx").at(i).toElement().text() == "true")
            tmpSize.prepend("約");
        size.append(tmpSize);

    }
        QUrl url(thumb.at(0));
        QNetworkReply* reply2 = postImageMan->get(QNetworkRequest(url));
    }
    else
    {
        ui->loading->setVisible(false);

         msgBox3.exec();

    }

}

void MainWindow::postDetailAgentImageFinished(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->postDetailAgentImage->setPixmap(QPixmap::fromImage(image).scaled(QSize(80,80),Qt::KeepAspectRatio));
        agentImage = QPixmap::fromImage(image).scaled(QSize(80,80),Qt::KeepAspectRatio);
    }
    }
}

void MainWindow::postDetailpreviousPage()
{
    ui->Content->setCurrentIndex(pageNumber);
}

void MainWindow::postDetailImageFinished(QNetworkReply *reply)
{
    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
        ui->postDetailImage->setPixmap(QPixmap::fromImage(image).scaled(QSize(70,70)));
    }
    }
}

void MainWindow::postImageDownloaded(QNetworkReply *reply)
{

    if (!reply->error())
    {
    QImage image;
    if (image.loadFromData(reply->readAll()))
    {
    postThumb[postCount] = QPixmap::fromImage(image);
}
}

    if(postCount == thumb.size()-1)
    {
        ui->loading->setVisible(false);

        qDebug()<<"Image Download  postCount : "<<postCount;
        //postModel = new postSearchListModel(name,this);
        postSearchListModel *postModel = new postSearchListModel(name,area,size,room,price,pps,thumb,suite,postThumb,this);
        ui->list_postSearch->setModel(postModel);

        postSearchListDelegate* delegate = new postSearchListDelegate(this);

        ui->list_postSearch->setItemDelegate(delegate);


        ui->Content->setCurrentIndex(4);

    }
    else
    {
        postCount++;
        QUrl url(thumb.at(postCount));
        QNetworkReply* reply = postImageMan->get(QNetworkRequest(url));

    }
}

void MainWindow::resetPostSearch()
{
    ui->radio_buy->setChecked(true);
    ui->radio_unlimit->setChecked(true);
    ui->areaBtn->setText("地區:未選擇");
    ui->price_slider->setValue(0);
    ui->area_slider->setValue(0);
    ui->inputField_conditionSearch->setText("");
    postCode = "";
    postType = "";
}

void MainWindow::currentClicked(QModelIndex index)
{
    QString tmp;
    if(postOrBlog == 0)
    {
    ui->Content->setCurrentIndex(1);
    if(ui->list_area->currentIndex().row()==0)
    {
            ui->areaBtn->setText("地區:未選擇");
            postCode = "";
            postType = "";
        }
        else
        {
            postCode = "";
            postType = "";

            tmp = areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("nameTc").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii();
            tmp.prepend("地區： ");
            ui->areaBtn->setText(tmp);
            postCode = "code=";
            postCode.append(areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("code").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii());
            postType = "type=";
            postType.append(areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("type").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii());
        }
    }
    else
    {
        ui->Content->setCurrentIndex(5);
        if(ui->list_area->currentIndex().row()==0)
        {
                ui->blogareaBtn->setText("市場分區:未選擇");
                blogCode = "";
                blogType = "";
            }
            else
            {
                blogCode = "";
                blogType = "";
                tmp = areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("nameTc").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii();
                tmp.prepend("市場分區： ");
                ui->blogareaBtn->setText(tmp);
                blogCode = "code=";
                blogCode.append(areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("code").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii());
                blogType = "type=";
                blogType.append(areaXml.elementsByTagName("MKT").at(areaType).toElement().elementsByTagName("type").at(ui->list_area->currentIndex().row()-1).toElement().text().toAscii());
            }
    }
}
void MainWindow::changeToHKList()
{
   areaType = 0;
   m_slData.clear();
   ui->list_area->setModel(new QStringListModel(m_slData));
   m_slData.append("取消選擇");
   for(int i =0;i<areaXml.elementsByTagName("MKT").at(0).toElement().elementsByTagName("nameTc").count();i++)
   {
       m_slData.append(areaXml.elementsByTagName("MKT").at(0).toElement().elementsByTagName("nameTc").at(i).toElement().text().toAscii());
       //m_slData.append("123");
       ui->list_area->setModel(new QStringListModel(m_slData));
   }
}

void MainWindow::changeToKLList()
{
    areaType = 1;
    m_slData.clear();
    ui->list_area->setModel(new QStringListModel(m_slData));
    m_slData.append("取消選擇");
    for(int i =0;i<areaXml.elementsByTagName("MKT").at(1).toElement().elementsByTagName("nameTc").count();i++)
    {

        m_slData.append(areaXml.elementsByTagName("MKT").at(1).toElement().elementsByTagName("nameTc").at(i).toElement().text().toAscii());
        //m_slData.append("123");
        ui->list_area->setModel(new QStringListModel(m_slData));
    }
}

void MainWindow::changeToNTWList()
{
    areaType = 3;
    m_slData.clear();
    ui->list_area->setModel(new QStringListModel(m_slData));
    m_slData.append("取消選擇");
    for(int i =0;i<areaXml.elementsByTagName("MKT").at(3).toElement().elementsByTagName("nameTc").count();i++)
    {

        m_slData.append(areaXml.elementsByTagName("MKT").at(3).toElement().elementsByTagName("nameTc").at(i).toElement().text().toAscii());
        //m_slData.append("123");
        ui->list_area->setModel(new QStringListModel(m_slData));
    }
}

void MainWindow::changeToNTEList()
{
    areaType = 2;
    m_slData.clear();
    ui->list_area->setModel(new QStringListModel(m_slData));
    m_slData.append("取消選擇");
    for(int i =0;i<areaXml.elementsByTagName("MKT").at(2).toElement().elementsByTagName("nameTc").count();i++)
    {

        m_slData.append(areaXml.elementsByTagName("MKT").at(2).toElement().elementsByTagName("nameTc").at(i).toElement().text().toAscii());
        //m_slData.append("123");
        ui->list_area->setModel(new QStringListModel(m_slData));
    }
}

void MainWindow::postRent()
{
    postBuy = false;
    ui->priceTxt->setText("租金");
    displayPrice(ui->price_slider->value());
}

void MainWindow::postSell()
{
    postBuy = true;
    ui->priceTxt->setText("價格");
    displayPrice(ui->price_slider->value());
}

void MainWindow::displayPrice(int x)
{
    if(x > 98)
    {
        if(postBuy)
        {
            ui->price_index->setText("$1200萬以上");
            postPrice = "minP=12000000";
        }
        else
        {
            ui->price_index->setText("$15,000以上");
            postPrice = "minR=15000";
        }
    }
    else if(x > 80)
    {
        if(postBuy)
        {
            ui->price_index->setText("$800萬至$1200萬");
            postPrice = "minP=8000000&maxP=12000000";
        }
        else
        {
            ui->price_index->setText("$12,000至$15,000");
            postPrice = "minR=12000&maxR=15000";
        }
    }
    else if(x > 60)
    {
        if(postBuy)
        {
            ui->price_index->setText("$500萬至$800萬");
            postPrice = "minP=5000000&maxP=8000000";
        }
        else
        {
            ui->price_index->setText("$10,000至$12,000");
            postPrice = "minR=10000&maxR=12000";
        }
    }
    else if(x > 40)
    {
        if(postBuy)
        {
            ui->price_index->setText("$300萬至$500萬");
            postPrice = "minP=3000000&maxP=5000000";
        }
        else
        {
            ui->price_index->setText("$8,000至$10,000");
            postPrice = "minR=8000&maxR=10000";
        }
    }
    else if(x > 20)
    {
        if(postBuy)
        {
            ui->price_index->setText("$200萬至$300萬");
            postPrice = "minP=2000000&maxP=3000000";
        }
        else
        {
            ui->price_index->setText("$6,000至$8,000");
            postPrice = "minR=6000&maxR=8000";
        }
    }
    else if(x > 1)
    {
        if(postBuy)
        {
            ui->price_index->setText("$200萬或以下");
            postPrice = "maxP=2000000";
        }
        else
        {
            ui->price_index->setText("$6,000或以下");
            postPrice = "maxR=6000";
        }
    }
    else
    {
        ui->price_index->setText("不限");
        postPrice = "";
    }
}

void MainWindow::displayArea(int x)
{
    if(x > 98)
    {
        ui->area_index->setText("2,000呎以上");
        postSize = "minS=2000";
    }
    else if(x > 80)
    {
        ui->area_index->setText("1,500呎至2,000呎");
        postSize = "minS=1500&maxS=2000";
    }
    else if(x > 60)
    {
        ui->area_index->setText("1,200呎至1,500呎");
        postSize = "minS=1200&maxS=1500";
    }
    else if(x > 40)
    {
        ui->area_index->setText("800呎至1,200呎");
        postSize = "minS=800&maxS=1200";
    }
    else if(x > 20)
    {
        ui->area_index->setText("500呎至800呎");
        postSize = "minS=500&maxS=800";
    }
    else if(x > 1)
    {
        ui->area_index->setText("500呎或以下");
        postSize = "maxS=500";
    }
    else
    {
        ui->area_index->setText("不限");
        postSize = "";
    }
}

void MainWindow::getTopEstates()
{

    QUrl url("http://hkblog.centamobile.com/findpropertyservice/symbian/TopEstates.ashx?estCnt=3");
    QNetworkReply* reply = topEstatesMan->get(QNetworkRequest(url));
}

void MainWindow::areaFinished(QNetworkReply *reply)
{
    ui->loading->setVisible(false);
    qDebug()<<"Area Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
    areaXml.setContent(string.toAscii());
    m_slData.clear();
    ui->list_area->setModel(new QStringListModel(m_slData));
    m_slData.append("取消選擇");
    for(int i =0;i<areaXml.elementsByTagName("MKT").at(0).toElement().elementsByTagName("nameTc").count();i++)
    {
        m_slData.append(areaXml.elementsByTagName("MKT").at(0).toElement().elementsByTagName("nameTc").at(i).toElement().text().toAscii());
        //m_slData.append("123");
        ui->list_area->setModel(new QStringListModel(m_slData));
    }
    ui->Content->setCurrentIndex(2);

}

void MainWindow::topEstatesFinished(QNetworkReply *reply)
{
    ui->loading->setVisible(false);
    qDebug()<<"Estates Download";
    QVariant statusCodeV =
        reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
    QVariant tempQ = QVariant(statusCodeV.toString().length());
    QByteArray bytes = reply->readAll();  // bytes
            const QString string(bytes);
    if(string.length() > 0)
{
    districtXml.setContent(string.toUtf8());

    if(districtXml.elementsByTagName("MKT").at(0).toElement().attribute("category")=="HK")
    {
      ChecktopEstatesWordLength(ui->hkBtn1,districtXml.elementsByTagName("nameTc").at(0).toElement().text());
      ChecktopEstatesWordLength(ui->hkBtn2,districtXml.elementsByTagName("nameTc").at(1).toElement().text());
      ChecktopEstatesWordLength(ui->hkBtn3,districtXml.elementsByTagName("nameTc").at(2).toElement().text());
    }
    if(districtXml.elementsByTagName("MKT").at(1).toElement().attribute("category")=="KL")
    {

      ChecktopEstatesWordLength(ui->klBtn1,districtXml.elementsByTagName("nameTc").at(3).toElement().text());
      ChecktopEstatesWordLength(ui->klBtn2,districtXml.elementsByTagName("nameTc").at(4).toElement().text());
      ChecktopEstatesWordLength(ui->klBtn3,districtXml.elementsByTagName("nameTc").at(5).toElement().text());
    }
    if(districtXml.elementsByTagName("MKT").at(2).toElement().attribute("category")=="NE")
    {
      ChecktopEstatesWordLength(ui->nteBtn1,districtXml.elementsByTagName("nameTc").at(6).toElement().text());
      ChecktopEstatesWordLength(ui->nteBtn2,districtXml.elementsByTagName("nameTc").at(7).toElement().text());
      ChecktopEstatesWordLength(ui->nteBtn3,districtXml.elementsByTagName("nameTc").at(8).toElement().text());
    }
    if(districtXml.elementsByTagName("MKT").at(3).toElement().attribute("category")=="NW")
    {
      ChecktopEstatesWordLength(ui->ntwBtn1,districtXml.elementsByTagName("nameTc").at(9).toElement().text());
      ChecktopEstatesWordLength(ui->ntwBtn2,districtXml.elementsByTagName("nameTc").at(10).toElement().text());
      ChecktopEstatesWordLength(ui->ntwBtn3,districtXml.elementsByTagName("nameTc").at(11).toElement().text());
    }
}
    else
    {


         msgBox2.exec();

    }



}


void MainWindow::ChecktopEstatesWordLength(QPushButton *label,QString string)
{
    string.replace("‧",".");
    if(string.length() > 4)
        label->setFont(QFont("MS Shell Dlg 2",3));
    else if(string.length() > 3)
        label->setFont(QFont("MS Shell Dlg 2",4));
    label->setText(string);
}

//pageControl
void MainWindow::pageWeb()
{
    ui->Content->setCurrentIndex(3);
}
void MainWindow::pageConditionSearch()
{
    name.clear();
    area.clear();
    price.clear();
    room.clear();
    thumb.clear();
    pps.clear();
    size.clear();
    suite.clear();
    refNoList.clear();
    postOrBlog = 0;
    postCount=0;
    postSii = 1;
    blogSii = 1;
    ui->Content->setCurrentIndex(1);
}
void MainWindow::pageArea()
{
    areaType = 0;
    QUrl url("http://hkblog.centamobile.com/findpropertyservice/symbian/AllScopes.ashx");
    QNetworkReply* reply = AreaMan->get(QNetworkRequest(url));
    //ui->Content->setCurrentIndex(2);

}

void MainWindow::pageBlog()
{

    agentName.clear();
    agentNameEn.clear();
    agentAddress.clear();
    agentCount.clear();
    agentThumb.clear();
    license.clear();
    postOrBlog = 1;
    postSii = 1;
    blogSii = 1;
    ui->Content->setCurrentIndex(5);
}

void MainWindow::mainBack()
{
    if(isRecord)
    {
        ui->Content->setCurrentIndex(27);
        ui->tabBar->setCurrentIndex(0);
    }
    else
    {
        changeTab1_2();
    }
}

void MainWindow::pageTNC()
{
    ui->Content->setCurrentIndex(6);
}

void MainWindow::pageDetail1()
{
    imageNumber = 0;
    ui->Content->setCurrentIndex(7);
}

void MainWindow::pageDetail2()
{
    ui->Content->setCurrentIndex(8);
    resetForm();
}

void MainWindow::pagePreview()
{
   ui->Content->setCurrentIndex(12);
}

void MainWindow::page360Detail()
{
    ui->Content->setCurrentIndex(15);
}

void MainWindow::pageChartDetail()
{
    ui->Content->setCurrentIndex(16);
}

void MainWindow::pageSell()
{
    ui->Content->setCurrentIndex(17);
}

void MainWindow::pageRent()
{
    ui->Content->setCurrentIndex(20);
}

void MainWindow::pageFlatDetail()
{
    ui->Content->setCurrentIndex(18);
}

void MainWindow::pageFacility()
{
    ui->Content->setCurrentIndex(19);
}

void MainWindow::pageEstatePreview()
{
    ui->Content->setCurrentIndex(21);
}

void MainWindow::pageFacilityPreview()
{
    ui->Content->setCurrentIndex(22);
}

void MainWindow::pageFloorPlanList()
{
    ui->Content->setCurrentIndex(24);
}

void MainWindow::pageGeoLocationPost()
{
    ui->Content->setCurrentIndex(28);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/PostSearch.ashx?lat=22.284500&long=114.21600&aradius=1000";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geoPostMan->get(QNetworkRequest(url));

}

void MainWindow::pageGeoLocation360()
{
    ui->Content->setCurrentIndex(29);
    QString temp = "http://hkdata.centamobile.com/iPhoneWS1/Handler1.ashx?fun=gps&lat=22.284500&long=114.21600&r=1000";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = geo360Man->get(QNetworkRequest(url));
}

void MainWindow::pageNewPropDetail()
{
    ui->label_62->setVisible(false);
    ui->label_61->setVisible(false);
    ui->Content->setCurrentIndex(32);
}

void MainWindow::pageNewPropImage()
{
    ui->Content->setCurrentIndex(34);
}

void MainWindow::pageNewPropFloorPlan()
{
    ui->Content->setCurrentIndex(33);
}

void MainWindow::pageNewPropVideo()
{
    ui->Content->setCurrentIndex(35);
}

void MainWindow::pageNewPropContact()
{
    ui->Content->setCurrentIndex(36);
}

void MainWindow::pageRequestForm()
{
    ui->Content->setCurrentIndex(39);
}

void MainWindow::pageFaciltyList()
{
   ui->Content->setCurrentIndex(41);
}

void MainWindow::pageCharacter()
{
   ui->Content->setCurrentIndex(42);
}

//Tab1 Control
void MainWindow::changeTab1_1()
{
    districtSii = 1;
    postCount = 0;
    ui->tab1_1->setIcon(QIcon(":/new/prefix1/Image/tab1_l.png"));
    ui->tab1_2->setIcon(QIcon(":/new/prefix1/Image/tab2_n.png"));
    ui->tab1_3->setIcon(QIcon(":/new/prefix1/Image/tab3_n.png"));
    ui->tab1_4->setIcon(QIcon(":/new/prefix1/Image/tab4_n.png"));
    ui->Content->setCurrentIndex(0);
}

void MainWindow::changeTab1_2()
{

    ui->loading->setVisible(true);
    ui->tab1_1->setIcon(QIcon(":/new/prefix1/Image/tab1_n.png"));
    ui->tab1_2->setIcon(QIcon(":/new/prefix1/Image/tab2_l.png"));
    ui->tab1_3->setIcon(QIcon(":/new/prefix1/Image/tab3_n.png"));
    ui->tab1_4->setIcon(QIcon(":/new/prefix1/Image/tab4_n.png"));
    topThreeEstate();
    getRecentRead();
    ui->Content->setCurrentIndex(14);
    ui->tabBar->setCurrentIndex(0);
    isRecord = false;

}


void MainWindow::changeTab1_3()
{
    ui->tab1_1->setIcon(QIcon(":/new/prefix1/Image/tab1_n.png"));
    ui->tab1_2->setIcon(QIcon(":/new/prefix1/Image/tab2_n.png"));
    ui->tab1_3->setIcon(QIcon(":/new/prefix1/Image/tab3_l.png"));
    ui->tab1_4->setIcon(QIcon(":/new/prefix1/Image/tab4_n.png"));
    ui->Content->setCurrentIndex(31);
    QString temp = "http://hkblog.centamobile.com/findpropertyservice/symbian/NewPropSearch.ashx?rankGroup=home";
    qDebug()<<temp;
    QUrl url(temp);
    QNetworkReply* reply = newPropMan->get(QNetworkRequest(url));
    ui->loading->setVisible(true);

}

void MainWindow::changeTab1_4()
{
    ui->tab1_1->setIcon(QIcon(":/new/prefix1/Image/tab1_n.png"));
    ui->tab1_2->setIcon(QIcon(":/new/prefix1/Image/tab2_n.png"));
    ui->tab1_3->setIcon(QIcon(":/new/prefix1/Image/tab3_n.png"));
    ui->tab1_4->setIcon(QIcon(":/new/prefix1/Image/tab4_l.png"));
    ui->Content->setCurrentIndex(26);
}
//Tab1 Control

//Tab2 Control
void MainWindow::changeTab2_1()
{

    ui->tab2_1->setIcon(QIcon(":/new/prefix1/Image/but_360_1l.png"));
    ui->tab2_2->setIcon(QIcon(":/new/prefix1/Image/but_360_2.png"));
    ui->tab2_3->setIcon(QIcon(":/new/prefix1/Image/but_360_3.png"));
    ui->tab2_4->setIcon(QIcon(":/new/prefix1/Image/but_360_4.png"));
    estateNumber = 0;
    facilityNumber = 0;
    page360Detail();
}

void MainWindow::changeTab2_2()
{
    ui->tab2_1->setIcon(QIcon(":/new/prefix1/Image/but_360_1.png"));
    ui->tab2_2->setIcon(QIcon(":/new/prefix1/Image/but_360_2l.png"));
    ui->tab2_3->setIcon(QIcon(":/new/prefix1/Image/but_360_3.png"));
    ui->tab2_4->setIcon(QIcon(":/new/prefix1/Image/but_360_4.png"));
    pageSell();
}

void MainWindow::changeTab2_3()
{
    ui->tab2_1->setIcon(QIcon(":/new/prefix1/Image/but_360_1.png"));
    ui->tab2_2->setIcon(QIcon(":/new/prefix1/Image/but_360_2.png"));
    ui->tab2_3->setIcon(QIcon(":/new/prefix1/Image/but_360_3l.png"));
    ui->tab2_4->setIcon(QIcon(":/new/prefix1/Image/but_360_4.png"));
    pageRent();
}

void MainWindow::changeTab2_4()
{
    ui->tab2_1->setIcon(QIcon(":/new/prefix1/Image/but_360_1.png"));
    ui->tab2_2->setIcon(QIcon(":/new/prefix1/Image/but_360_2.png"));
    ui->tab2_3->setIcon(QIcon(":/new/prefix1/Image/but_360_3.png"));
    ui->tab2_4->setIcon(QIcon(":/new/prefix1/Image/but_360_4l.png"));
    pageFlatDetail();
}
