﻿function colorStars(listingId, starPosition, activeStar) {
    var MAX_STAR = 5;
    var starImage = baseUrl + "/Images/star/yellow-star.png";
    
    if (!activeStar) {
        starImage = baseUrl + "/Images/star/green-star.png";
    }
    
    var emptyStarImage = baseUrl + "/Images/star/empty-star.png";
    
    for (var i = 1; i <= starPosition; i++) {
        var starImg = document.getElementById("ml-" + listingId + "-" + i);
        var starRvImg = document.getElementById("rv-" + listingId + "-" + i);
        if (starImg != null)
            starImg.src = starImage;
            
        if (starRvImg != null)
            starRvImg.src = starImage;
    }
    
    for (var i = starPosition + 1; i <= MAX_STAR; i++) {
        var starImg = document.getElementById("ml-" + listingId + "-" + i);
        var starRvImg = document.getElementById("rv-" + listingId + "-" + i);
        if (starImg != null)
            starImg.src = emptyStarImage;
            
        if (starRvImg != null)
            starRvImg.src = emptyStarImage;
    }
}

function voteListing(listingId, starPosition, hasSignedIn) {
    if (!hasSignedIn) {
        alert("You must sign in to rate. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    rateListing_Request(listingId, starPosition);
}

function voteArticle(articleId, starPosition, hasSignedIn) {
    if (!hasSignedIn) {
        alert("You must sign in to rate. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    rateArticle_Request(articleId, starPosition);
}

function voteThreadResponse(threadResponseId, starPosition, hasSignedIn) {
    if (!hasSignedIn) {
        alert("You must sign in to rate. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    rateThreadResponse_Request(threadResponseId, starPosition);
}

function voteListingReview(listingReviewId, hasSignedIn, isHelpful) {
    if (!hasSignedIn) {
        alert("You must sign in to rate. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    rateListingReview_Request(listingReviewId, isHelpful);
}

function flagThreadResponse(threadResponseId, hasSignedIn, flagTypeId) {
    if (!hasSignedIn) {
        alert("You must sign in to flag. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    flagThreadResponse_Request(threadResponseId, flagTypeId);
}

function flagListingReview(listingReviewId, hasSignedIn, flagTypeId) {
    if (!hasSignedIn) {
        alert("You must sign in to flag. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    flagListingReview_Request(listingReviewId, flagTypeId);
}

function flagListing(listingId, hasSignedIn, flagTypeId) {
    if (!hasSignedIn) {
        alert("You must sign in to flag. If you do not have an account, you can sign up now. It's easy and free.");
        return;
    }
    
    flagListing_Request(listingId, flagTypeId);
}


