
/*** 
	Code borrowed from shopping
*/

/***
	event helper 
*/

function yg_addEvt(o,e,f,c){ if(o.addEventListener)o.addEventListener(e,f,c);else if(o.attachEvent)o.attachEvent("on"+e,f);else eval("o.on"+e+"="+f)}

/**
   Class that defines a standard ratings component.
*/

// Constants
yg_Ratings.TYPE_STARS = '@@CONST_STARS@@';
yg_Ratings.TYPE_BARS = '@@CONST_BARS@@';
yg_Ratings.LABEL_NONE = '@@CONST_LNONE@@';
yg_Ratings.LABEL_TOP = '@@CONST_LTOP@@';
yg_Ratings.LABEL_RIGHT = '@@CONST_LRGT@@';

// Messages for display above the individual ratings units. The length of the
// array also defines how many units to include in the component.
yg_Ratings.Msgs = new Array(
   "<b>" + ratings_js_strings["navet"] + "</b>",
   "<b>" + ratings_js_strings["mauvais"] + "</b>",
   "<b>" + ratings_js_strings["evite"] + "</b>",
   "<b>" + ratings_js_strings["terrible"] + "</b>",
   "<b>" + ratings_js_strings["moyen"] + "</b>",
   "<b>" + ratings_js_strings["assez"] + "</b>",
   "<b>" + ratings_js_strings["bon"] + "</b>",
   "<b>" + ratings_js_strings["tres"] + "</b>",
   "<b>" + ratings_js_strings["brillant"] + "</b>",
   "<b>" + ratings_js_strings["chef"] + "</b>"
);

// all the instances of this object on a page
yg_Ratings.Instances = new Array();


function yg_Ratings(parentId, dfltRating, symbolType, labelPos, submitId)
{
   // register inst
   this.index = yg_Ratings.Instances.length;
   yg_Ratings.Instances[this.index] = this;

   // rating init
   this.rating = 0;
   this.defaultMsg = '';
   
   if (labelPos == yg_Ratings.LABEL_TOP) {
      this.defaultMsg = '<b>' + ratings_js_strings["rate_it"] + '</b>';
   }

   // default rating override
   if (dfltRating > 0) {
       this.rating = dfltRating;
       //this.defaultMsg = '<strong>' + yg_Ratings.Msgs[dfltRating-1] + '</strong>';
       this.defaultMsg = yg_Ratings.Msgs[dfltRating-1] ;
   }

   // sanity check on symbol type
   if (symbolType != yg_Ratings.TYPE_STARS && symbolType != yg_Ratings.TYPE_BARS) {
      symbolType = yg_Ratings.TYPE_STARS;
   }

   // path = Path for all images.
   // unitY = Image for set units.
   // unitYMouseOver = Image for set units <= the mouse over point.
   // unitYMouseLess = Image for set units > the mouse over point.
   // unitN = Image for unset units.
   // unitNMouseOver = Image for unset units <= the mouse over point.

   var path = "http://www.cinemovies.fr/img/icones/star/";
   
   if (symbolType == yg_Ratings.TYPE_STARS) { 
      
      /* we need more images */
      this.UnitY = path + "yri_star_yellow.gif";
      this.UnitYMouseOver = path + "yri_star_hover.gif";
      this.UnitYMouseLess = path + "yri_star_grey.gif";
      this.UnitN = path + "yri_star_white.gif";
      this.UnitNMouseOver = path + "yri_star_hover.gif";
   } else if (symbolType == yg_Ratings.TYPE_BARS) {
      path = "http://l.yimg.com/us.yimg.com/i/us/sh/karma/";
      this.UnitY = path + "yri_bar_yellow_2.gif";
      this.UnitYMouseOver = path + "yri_bar_hover_2.gif";
      this.UnitYMouseLess = path + "yri_bar_grey_2.gif";
      this.UnitN = path + "yri_bar_white_2.gif";
      this.UnitNMouseOver = path + "yri_bar_hover_2.gif";
   }

   // assume a DIV with ID=parentId exists
   var parentEl = document.getElementById(parentId);

   // create the label element
   var msgEl = document.createElement('span');
   msgEl.className = 'quickrate_msg';
   msgEl.innerHTML = this.defaultMsg;

   // hide the label if we don't want it part of the UI
   if (!labelPos || labelPos == yg_Ratings.LABEL_NONE) {
      msgEl.style.display = 'none';
   // if we want it above the widget then put it there
   } else if (labelPos == yg_Ratings.LABEL_TOP) {
      msgEl.style.display = 'block';
      parentEl.appendChild(msgEl);
   }


   // create form field
   var fieldEl = document.createElement('input');
   fieldEl.name = parentId;
   fieldEl.id = parentId; 
   fieldEl.style.display = 'none';
   fieldEl.type = 'hidden';
   fieldEl.value = dfltRating;
   parentEl.appendChild(fieldEl);

   // attach mouseout event to parent
   yg_addEvt(parentEl, 'mouseout', new Function('return yg_Ratings_mouseOut(' +this.index+ ');'), false);

   // generate quickrate widget stars
   for (var i = 1; i <= yg_Ratings.Msgs.length; i++) {
      var spanEl = document.createElement('span');
      spanEl.className = 'unit';
      var imgEl = document.createElement('img');
      imgEl.src = (i <= dfltRating) ? this.UnitY : this.UnitN;
      spanEl.appendChild(imgEl);
      parentEl.appendChild(spanEl);

      // generate events also
      yg_addEvt(spanEl, 'mouseover', new Function('return yg_Ratings_mouseOver(' +this.index+ ', ' +i+ ');'), false);
      yg_addEvt(spanEl, 'click', new Function('return yg_Ratings_click(' +this.index+ ', ' +i+ ');'), false);
   }

   // if we want the label next to the widget, put it there
   if (labelPos == yg_Ratings.LABEL_RIGHT) {
      parentEl.appendChild(msgEl);
   }

   // store DOM refs in the object
   this.parent = parentEl;
   this.msg = msgEl;
   this.field = fieldEl;
   this.images = parentEl.getElementsByTagName("img");
   this.submitId = submitId;
   this.labelPos = labelPos;
}

function yg_Ratings_set(n, oflag)
{
   // The n parameter is the unit to set (starting at 1). Set oflag to true
   // when the mouse is outside of the ratings component, or you're not sure.
   if (arguments.length < 2)
      oflag = true;   
   this.rating = n;
   this.defaultMsg = '<strong>' + yg_Ratings.Msgs[n-1] + '</strong>';
   this.update(n, oflag);

   // un-hides hidden submit button, if it exists
   // i.e. 'btnSave'
   var submitEl = document.getElementById(this.submitId);
   if (submitEl) {
      submitEl.style.display = 'inline';
   }

   this.field.value = n;
}

function yg_Ratings_setMsg(m)
{
   if (m != "") {
      this.msg.innerHTML = m;
   } else {
      this.msg.innerHTML = this.defaultMsg;
   }
}

function yg_Ratings_get()
{
   return this.rating;
}

function yg_Ratings_update(n, oflag)
{
   // The oflag parameter is true when the mouse is outside of the ratings
   // component. The n parameter is the 
   if (oflag) {
      this.setMsg(this.defaultMsg);
   } else {
      this.setMsg(yg_Ratings.Msgs[n - 1]);
      //if(event.type=="click") this.field.value=n;
   }

   for (var i = 1; i <= yg_Ratings.Msgs.length; i++)
   {
      if (oflag)
      {
         if (i <= this.rating)
            this.images[i - 1].src = this.UnitY;
         else
            this.images[i - 1].src = this.UnitN;
      }
      else
      {
         if (i <= n)
         {
            if (i <= this.rating)
               this.images[i - 1].src = this.UnitYMouseOver;
            else
               this.images[i - 1].src = this.UnitNMouseOver;
         }
         else
         {
            if (i <= this.rating)
               this.images[i - 1].src = this.UnitYMouseLess;
            else
               this.images[i - 1].src = this.UnitN;
         }
      }
   }

   return true;
}

function yg_Ratings_click(index, n)
{
   var obj = yg_Ratings.Instances[index];
   obj.set(n, false);
   return true;
}

function yg_Ratings_mouseOver(index, n)
{
   var obj = yg_Ratings.Instances[index];
   obj.update(n, false);
   return true;
}

function yg_Ratings_mouseOut(index)
{
   var obj = yg_Ratings.Instances[index];
   obj.update(0, true);
   return true;
}

yg_Ratings.prototype.set = yg_Ratings_set;
yg_Ratings.prototype.setMsg = yg_Ratings_setMsg;
yg_Ratings.prototype.get = yg_Ratings_get;
yg_Ratings.prototype.update = yg_Ratings_update;


function yg_Replies()
{
}

function yg_Replies_attach(review_id, nn_html)
{
	this.review_id = review_id;
	
	element = document.getElementById(this.review_id);
	element.innerHTML =
			'<tr>' +
			'<td>' +
			'<form name="submit_reply" method="POST" action="">' +
			'<input type="hidden" name="review_id" value="'+this.review_id+'">' +
			'<table border="0" cellpadding="5" cellspacing="0" width="95%">'+
			'  <tr>'+
			'<td width="25%"  valign="top" align="right"><b>' + ratings_js_strings["reply"] +'</b>&#160;<font color="#ff0000">*</font> </td>'+
			'<td width="75%"><textarea id="reply_content_ta" style="float:left; width: 100%;" cols="75" rows="5" name="reply_content" class="textfield"></textarea></td>'+
			' </tr>'+ 
			' <tr>' + 
			'<td width="25%"  valign="top" align="right"><b>' + coreid_nickname_strings["nickname"]  + ' :</b></td>'+
			'<td width="75%">'+ nn_html + '</td>' +
			'</tr>' +
			'  <tr>'+
			'<td width="25%"  valign="top" align="right">&nbsp; </td>'+
			'<td width="75%">'+
			'<input type="submit" name="submit_reply" value="' + ratings_js_strings["submit"] + '" class="but_iagree">'+
			'<input type="reset" value="' + ratings_js_strings["cancel"] + '" onClick="hideReplyForm(\'' +review_id + '\'); " class="but_iagree">'+
			'</td>'+
			' </tr>'+
			'</form>'+
			'</td>'+
 			'</tr>'+
                        ' ';

	var ta = document.getElementById('reply_content_ta');
	ta.focus();
}

function yg_Replies_detach(review_id)
{
        if(document.getElementById)
        {
          element = document.getElementById(review_id);
	  element.innerHTML = "";
        }
        else
        { 
         alert(document.getElementById(this.review_id));
         return;
        }
      
}

yg_Replies.prototype.attach = yg_Replies_attach;
yg_Replies.prototype.detach = yg_Replies_detach;

var replyController = new yg_Replies();

function addReplyForm(review_id, nn_htm)
{
	replyController.attach(review_id, nn_htm);
	return false;
}

function hideReplyForm(review_id)
{
	replyController.detach(review_id);
}

