﻿var RatingRow = 0;
var PricingRow = 0;

function fnSwapImage(img, imgNewImage) {
  //Change the image.
  img.src = BaseDirectory + "images/ratings/" + imgNewImage;
}

function fnSwapRatings(rowID, imgID, imgName, imgEmpty) {
  //Swap every image less than the current image.
  for (var i = 0; i < 5; i++) {
    //Swap the image.
    if (i <= imgID) {
      fnSwapImage(document.getElementById("img_" + rowID + "_" + i.toString()), imgName);
    }
    else {
      fnSwapImage(document.getElementById("img_" + rowID + "_" + i.toString()), imgEmpty);
    }
  }
}

function fnRestoreRatings(rowID, ratingValue) {
  //Restore the images to their original state.
  for (var i = 0; i < 5; i++) {
    //Swap the image.
    if (i < ratingValue) {
      fnSwapImage(document.getElementById("img_" + rowID + "_" + i.toString()), "full.gif");
    }
    else {
      fnSwapImage(document.getElementById("img_" + rowID + "_" + i.toString()), "empty.gif");
    }
  }
}

function fnSaveRating(locationID, rowID, ratingValue) {
  //Show the save msg.
  document.getElementById("img_" + rowID).style.display = "none";
  document.getElementById("txt_" + rowID).style.display = "block";

  //Show the ratings.
  document.getElementById("img_" + rowID).style.display = "block";
  document.getElementById("txt_" + rowID).style.display = "none";
}

function fnRenderRatings(ratingValue, locationID) {
  //Wrap the images in a DIV.
  document.writeln("<div id=\"img_" + RatingRow.toString() + "\" style=\"display: block\">");

  //Write each rating image.
  for (var i = 0; i < 5; i++) {
    //Check if this is selected.
    if (i < ratingValue) {
      document.write("<img id=\"img_" + RatingRow.toString() + "_" + i.toString() + "\" alt=\"\" src=\"" +
        BaseDirectory + "images/ratings/full.jpg\" align=\"absmiddle\" style=\"cursor: pointer\" " +
        //"onmouseover=\"fnSwapRatings('" + RatingRow.toString() + "', " + i.toString() + ", 'over.jpg', 'empty.jpg')\" " +
        //"onmouseout=\"fnRestoreRatings('" + RatingRow.toString() + "', " + ratingValue.toString() + ")\" " +
        "onclick=\"fnSaveRating('" + locationID + "', '" + RatingRow.toString() + "', " + (i + 1).toString() + ")\" />");
    }
    else {
      document.write("<img id=\"img_" + RatingRow.toString() + "_" + i.toString() + "\" alt=\"\" src=\"" +
        BaseDirectory + "images/ratings/empty.jpg\" align=\"absmiddle\" style=\"cursor: pointer\" " +
        //"onmouseover=\"fnSwapRatings('" + RatingRow.toString() + "', " + i.toString() + ", 'over.jpg', 'empty.jpg')\" " +
        //"onmouseout=\"fnRestoreRatings('" + RatingRow.toString() + "', " + ratingValue.toString() + ")\" " +
        "onclick=\"fnSaveRating('" + locationID + "', '" + RatingRow.toString() + "', " + (i + 1).toString() + ")\" />");
    }
  }

  //Close the DIV.
  document.writeln("</div>");

  //Write a DIV for the save msg.
  document.writeln("<div id=\"txt_" + RatingRow.toString() + "\" style=\"display: none\">");
  document.writeln("  saving...");
  document.writeln("</div>");

  //Increment the row.
  RatingRow++;
}

function fnRenderPrices(priceValue, locationID) {
  //Wrap the images in a DIV.
  document.writeln("<div id=\"img_" + PricingRow.toString() + "\" style=\"display: block\">");

  //Write each pricing image.
  for (var i = 0; i < 5; i++) {
    //Check if this is selected.
    if (i < priceValue) {
      document.write("<img id=\"img_" + PricingRow.toString() + "_" + i.toString() + "\" alt=\"\" src=\"" +
        BaseDirectory + "images/ratings/prc_full.jpg\" align=\"absmiddle\" style=\"cursor: pointer\" " +
        "onclick=\"fnSavePricing('" + locationID + "', '" + PricingRow.toString() + "', " + (i + 1).toString() + ")\" />");
    }
    else {
      document.write("<img id=\"img_" + PricingRow.toString() + "_" + i.toString() + "\" alt=\"\" src=\"" +
        BaseDirectory + "images/ratings/prc_empty.jpg\" align=\"absmiddle\" style=\"cursor: pointer\" " +
        "onclick=\"fnSavePricing('" + locationID + "', '" + PricingRow.toString() + "', " + (i + 1).toString() + ")\" />");
    }
  }

  //Close the DIV.
  document.writeln("</div>");

  //Increment the row.
  PricingRow++;
}

function fnRenderTags(tags) {
  document.writeln(tags);
}
