﻿//JScript File
Ajax.Commands.UpdateRateReview = function(elementId, ajaxCommand, cmdCounter) {
    this.priority = net.CommandQueue.PRIORITY_IMMEDIATE;
    this.type = net.CommandQueue.TYPE_SINGLEPROCESS;
    this.id = cmdCounter;
    this.ajaxCommand = ajaxCommand;
    var updateRateReviewParams = elementId.toString().split('|');
    this.vendorLocationId = updateRateReviewParams[0];
    this.reviewText = updateRateReviewParams[1];
    this.foodRating = updateRateReviewParams[2];
    this.postToFacebook = 'N';
    if (document.getElementById('postToFacebook') != null) {
        if (document.getElementById('postToFacebook').checked) {
            this.postToFacebook = 'Y';
        }
    }
}

Ajax.Commands.UpdateRateReview.prototype.QueryStringVariables = function() {
    var commandVariables = new Hashtable();
    commandVariables.put("vendorLocationId", this.vendorLocationId);
    commandVariables.put("reviewText", this.reviewText);
    commandVariables.put("foodRating", this.foodRating);
    commandVariables.put("postToFacebook", this.postToFacebook);
    return commandVariables;
}

Ajax.Commands.UpdateRateReview.prototype.ParseResponse = function(docEl) {
    var attrs = docEl.attributes;
    var status = attrs.getNamedItem('status').value;
    var message = attrs.getNamedItem('message').value;
    //Close the thickbox
    TB_remove();
    if (status == 'success') {
        var vendorName = attrs.getNamedItem('vendorName').value;
        var vendorLogoImagePath = attrs.getNamedItem('vendorLogoImagePath').value;
        var reviewText = attrs.getNamedItem('reviewText').value;
        var vendorRatingImagePath = attrs.getNamedItem('vendorRatingImagePath').value;
        var friendlyUrl = attrs.getNamedItem('friendlyUrl').value;
        var consumerHomePageUrl = attrs.getNamedItem('consumerHomePageUrl').value;
        if (document.getElementById('postToFacebook') != null) {
            if (document.getElementById('postToFacebook').checked) {
                ShareVendorRatingAndReviews(vendorName, vendorLogoImagePath, reviewText, vendorRatingImagePath, friendlyUrl, consumerHomePageUrl);
            }
        }
        net.Base.ReleaseQueue();
    } else if (status == 'failure') {
        alert(message);
    }
}
