﻿namespace('nnet.sd');

nnet.sd.DetailView = $j.klass({
    initialize: function() {
        this.ID = null; // Listing id
        this.Panel = $j(sVars.SD_DetailContainerPanelID);
    },

    startup: function() {
        try {
            this.Panel = $j(sVars.SD_DetailContainerPanelID);
        } catch (e) { logE("sd.DetailView.startup", e); }
    },


    // Call back so not in the context of this class, cant use this.
    callback: function(detailData) {
        try {
            SD.DetailView.set(detailData);
            SD.show(sVars.DETAIL_CONTENT_VIEW_STATE);
            RunEmbeddedJS(detailData);
            ServiceContentLoadingImage.hide();
            document.body.style.cursor = 'default';
            NNet.PageHistory.add();
            NNet.Page.setTitle()
            NNet.Page.setDescription()
        } catch (e) { logE("sd.DetailView.callback", e); }
    },

    // Call back so not in the context of this class, cant use this.
    callbackShowFeedback: function(detailData) {
        try {
            SD.DetailView.callback(detailData);
            SD.DetailView.showFeedback();
        } catch (e) { logE("sd.DetailView.callbackShowFeedback", e); }
    },

    ///<summary>Get Listing HTML for viewing listing on detail panel.</summary>
    ///<param name="lid">Listing id - may be 0</param>
    ///<param name="sid">Service id</param>
    ///<param name="displayFeedback">if true will scroll to feedback section of panel</param>
    ///<returns>object</returns>  
    display: function(lid, sid, displayFeedback) {
        try {
            this.ID = lid;
            ServiceContentLoadingImage.show();
            document.body.style.cursor = 'wait';
            SD.ContentViewState = sVars.DETAIL_CONTENT_VIEW_STATE;
            SD.CurrentServiceId = sid;
            if (displayFeedback) SDCallback.GetViewListing(lid,sid, this.callbackShowFeedback, OnListCallbackError);
            else SDCallback.GetViewListing(lid, sid, this.callback, OnListCallbackError);
        } catch (e) { logE("sd.DetailView.display", e); }
    },

    set: function(html) {
        this.Panel.empty();
        this.Panel.append(html);
    },

    showFeedback: function() {
        $j('#ServiceView').scrollTo('#FeedbackStart', 800);
    },


    displayReviews: function() {
        $j('#ReviewPanel').show();
        $j('#AddReview').show();
        $j('#ShowReviews').hide();
    },

    hideReviews: function() {
        $j('#ReviewPanel').hide();
        $j('#AddReview').hide();
        $j('#ShowReviews').show();
    },

    noReviews: function() {
        $j('#ReviewPanel').hide();
        $j('#AddReview').show();
        $j('#ShowReviews').hide();
    },

    print: function(sid) {
        alert("Not Done Yet");
    },

    email: function(sid) {
        alert("Not Done Yet");
    },

    reportFeedback: function(fid) {
        alert("Not Done Yet");
    },

    feedbackHelpful: function(fid, sid, result) {
        try {
            SDCallback.FeedbackVote(fid, sid, result, this.callback, OnListCallbackError);
        } catch (e) { logE("sd.DetailView.callbackShowFeedback", e); }
    },

    show: function() {
        this.Panel.show();
    },

    hide: function() {
        this.Panel.hide();
    },

    empty: function() {
        this.Panel.empty();
    }

});

