﻿function SubmitReview(strNameID, strEmailID, strTitleID, strContentID, strRatingID, strOrderRefID, intProductID)
{
    var strName = "";
    var strTitle = "";
    var strEmailAddr = "";
    var strContent = "";
    var strRating = "";
    var strOrderRef = "";
    
    var sErrors = "";
    //gather info
    //"UcStoreProduct1_ProductReviews_UcAddNewReview1_txtCustomerName"
    if((document.getElementById(strNameID)!=null) && (document.getElementById(strNameID).value != ""))
    {
        strName = document.getElementById(strNameID).value;
    }else
    {
        sErrors += "Name,\n";
    }
    if((document.getElementById(strEmailID)!=null) && (document.getElementById(strEmailID).value != ""))
    {
        strEmailAddr = document.getElementById(strEmailID).value;
    }else
    {
        sErrors += "Email Address Invalid,\n";
    }
    if((document.getElementById(strTitleID)!=null) && (document.getElementById(strTitleID).value != ""))
    {
        strTitle = document.getElementById(strTitleID).value;
    }else
    {
        sErrors += "Brief Title (eg 'Very Impressed with this product',)\n";
    }
    if((document.getElementById(strContentID)!=null) && (document.getElementById(strContentID).value != ""))
    {
        strContent = document.getElementById(strContentID).value;
    }else
    {
        sErrors += "Your Review is missing\n";
    }
     if((document.getElementById(strOrderRefID)!=null) && (document.getElementById(strOrderRefID).value != ""))
    {
        strOrderRef = document.getElementById(strOrderRefID).value;
    }
    if($find(strRatingID) != null) 
    {
        try
        {
            strRating = $find(strRatingID).get_Rating();
        }
        catch(err)
        {
        }
    }
    else
    {
        if(((strRating ==null) || (strRating == "")) && (document.getElementById(strRatingID).firstChild.value != null))
        {
            strRating = document.getElementById(strRatingID).firstChild.value;
        }
        else
        {
            sErrors += "Choose a rating\n";
        }
    }
  
    if(sErrors == "")
    {
        // string strCustomerName, string strEmail, string strTitle, string strRating, string strContent, string strOrderRef, int intProductID)
        Reviews.SubmitReview(strName, strEmailAddr, strTitle, strRating, strContent, strOrderRef, intProductID, ReviewSubmitResult);
    }else
    {
        alert("There are problems with the review.  Please enter the following correctly:\n\r" + sErrors);
    }
};
function ReviewSubmitResult(result)
{
if(result != null)
    {
        if(result >-1)
         {
            //TODO: Trigger success
            $find('ModalPopupAddReview').hide();
            $find('mpeReviewSuccess').show();
           //document.getElementById("UcStoreProduct1_ProfileProductOutofStock_mpeSuccess").show();
            
         }else
         {
            //TODO:Trigger failure.
            $find('mpeReviewFailedSave').show();
            //document.getElementById("UcStoreProduct1_ProfileProductOutofStock_mpeFailedSave").show();
         }
     }
};

