Ratings.Msgs = new Array
(
   "Your Rating : Good",
   "Your Rating : Very Good",
   "Your Rating : Excellent"
);

Ratings.Labels = new Array
(
   "1 Star",
   "2 Stars",
   "3 Stars"  
);

Ratings.Msgs1 = new Array
(
   "Average Rating: Good",
   "Average Rating: Very Good",
   "Average Rating: Excellent"
);

var defaultvalue = 0;

// Path for all images.
var path = "../skin1/images/";
Ratings.starbar = "star_";

Ratings.UnitF = "green.gif";

// Image for set units.
Ratings.UnitY = "yellow.gif";

// Image for set units <= the mouse over point.
Ratings.UnitYMouseOver = "yellow.gif";

// Image for set units > the mouse over point.
Ratings.UnitYMouseLess = "grey.gif";

// Image for unset units.
Ratings.UnitN = "white.gif";

// Image for unset units <= the mouse over point.
Ratings.UnitNMouseOver = "hover.gif";

function RatingsAverage(id,flabel,defaultval,type)
{
//   defaultvalue = defaultval;
   var i, t;
   var attributes;
   var h1, h2;
   var d = document;
   var star = "";
   var style;   
   this.starbar = type + "_";

   this.rating = 0;
   this.defaultMsg = "Average Rating";
  
   if (defaultval > 0) 
       this.defaultMsg = Ratings.Msgs1[defaultval-1];

   if(flabel){    	
     	star += '<span class="rating"';
        if (type == "star")
			star += 'style="font-weight: bold; margin-top: 1.5em; width: 160px;"';
		else
			star += 'style="margin-left: 20px;"';
		star += '>' + flabel + ':</span>';

   }
   attributes = 'class="rating" id="' + id + '" style="' + style + '"';

   star += '<span ' + attributes + ' >';
   if (type == "star")
      star += '<div class="rating"><small>'+this.defaultMsg+'</small></div>';

   for (i = 1; i <= Ratings.Msgs1.length; i++)
   {
      star += '<span>';
      if (i <= defaultval) {
         star += '<img src="' + path + this.starbar + Ratings.UnitF + '" />';
      } else {
         star += '<img src="' + path + this.starbar + Ratings.UnitN + '" />';
      }
      star += '</span>';
   }

  star += '</span>';
 
  document.getElementById('ratedstar').innerHTML = star;
  
   this.parent = document.getElementById(id);
   this.images = this.parent.getElementsByTagName("img");

   if (type == "star")
       this.field = this.parent.childNodes[4];
   else
       this.field = this.parent.childNodes[3];
}

function Ratings(id,flabel,defaultval,type)
{
//   defaultvalue = defaultval;
   var i, t;
   var attributes;
   var h1, h2;
   var d = document;
   var star = "";
   var style;   
   this.starbar = type + "_";

   this.rating = 0;
   this.defaultMsg = "Rate it:";
  
   if (defaultval > 0) 
       this.defaultMsg = Ratings.Msgs[defaultval-1];

   if(flabel){    	
     	star += '<span class="rating"';
        if (type == "star")
			star += 'style="font-weight: bold; margin-top: 1.5em; width: 160px;"';
		else
			star += 'style="margin-left: 20px;"';
		star += '>' + flabel + ':</span>';

   }
   attributes = 'class="rating" id="' + id + '" style="' + style + '"';
   h1 = 'onMouseOut="return Ratings_mouseOut(' + id + ');"';

   star += '<span ' + attributes + ' ' + h1 + '>';
   if (type == "star")
      star += '<div class="rating"><small>'+this.defaultMsg+'</small></div>';

   for (i = 1; i <= Ratings.Msgs.length; i++)
   {
      h1 = 'onMouseOver="return Ratings_mouseOver(' + id + ', ' + i + ');"';
      h2 = 'onClick="return Ratings_click(' + id + ', ' + i + ');"';
      star += '<span class="unit "' + h1 + ' ' + h2 + '>';
      if (i <= defaultval) {
         star += '<img src="' + path + this.starbar + Ratings.UnitY + '" />';
      } else {
         star += '<img src="' + path + this.starbar + Ratings.UnitN + '" />';
      }
      star += '</span>';
   }
   if(defaultval){
	star += '<input type="hidden" name="' +id+  '_" value="' + defaultval + '" />';
   } else {
	star += '<input type="hidden" name="' +id+  '_" value="" />';
   }

  star += '</span>';
  
  document.getElementById('yourrating').innerHTML = star;
 
   this.parent = document.getElementById(id);
   this.images = this.parent.getElementsByTagName("img");

   if (type == "star")
       this.field = this.parent.childNodes[4];
   else
       this.field = this.parent.childNodes[3];
   this.msg = this.parent.getElementsByTagName("small")[0];
   this.id = id;

   this.rating = defaultval;
   this.defaultMsg = Ratings.Msgs[defaultval-1];
   this.update(defaultval, false);

   this.field.value = defaultval;
}

function Ratings_set(n, oflag)
{
   if (arguments.length < 2)
      oflag = true;   
   this.rating = n;
   this.defaultMsg = Ratings.Msgs[n-1];
   this.update(n, oflag);

   this.field.value = n;
   
   //var msg = "frmRatingStar.aspx?CategoryID=" + document.all['hidCategoryId'].value + "&Rating=" + n;
   
   var playerQuery = window.location.search.substring();
   if(playerQuery.indexOf("&Rating") >= 0)
		playerQuery = playerQuery.substr(0, playerQuery.indexOf("&Rating"));
   msg = "frmCategoryDisplay.aspx" + playerQuery + "&Rating=" + n;
   //alert(msg);
   
   document.location = msg;

 /*  if (document.getElementById('btnSave')) {
      Ratings_showSubmit('btnSave');
      log_quickrate_beacon();
   }*/
}

function Ratings_showSubmit(sBtn) {
	document.getElementById(sBtn).style.display="block";
}


function Ratings_setMsg(m)
{
   var children = this.msg.childNodes;
   var node;

   for (var i = 0; i < children.length; i++)
   {
      node = children[i];

      if (node.nodeType == 3)
      {
         if (m == "")
            node.nodeValue = this.defaultMsg;
         else
            node.nodeValue = m;
      }
   }
}

function Ratings_get()
{
   return this.rating;
}

function Ratings_update(n, oflag)
{

   if (this.starbar == 'star_') {
	   if (oflag) {
		  this.setMsg(this.defaultMsg);
	   } else {
		  this.setMsg(Ratings.Msgs[n - 1]);
	   }
   }

   for (i = 1; i <= Ratings.Msgs.length; i++)
   {
      if (oflag)
      {
         if (i <= this.rating)
            this.images[i - 1].src = path + this.starbar + Ratings.UnitY;
         else
            this.images[i - 1].src = path + this.starbar + Ratings.UnitN;
      }
      else
      {
         if (i <= n)
         {
            if (i <= this.rating)
               this.images[i - 1].src = path + this.starbar + Ratings.UnitYMouseOver;
            else
               this.images[i - 1].src = path + this.starbar + Ratings.UnitNMouseOver;
         }
         else
         {
            if (i <= this.rating)
               this.images[i - 1].src = path + this.starbar + Ratings.UnitYMouseLess;
            else
               this.images[i - 1].src = path + this.starbar + Ratings.UnitN;
         }
      }
   }
   return true;
}

function Ratings_click(obj, n)
{
   obj.set(n, false);
   return true;
}

function Ratings_mouseOver(obj, n)
{
   obj.update(n, false);
   return true;
}

function Ratings_mouseOut(obj)
{
   obj.update(0, true);
   return true;
}

Ratings.prototype.set = Ratings_set;
Ratings.prototype.setMsg = Ratings_setMsg;
Ratings.prototype.get = Ratings_get;
Ratings.prototype.update = Ratings_update;
