
function Reaction()
{    
};

Reaction.prototype = 
{ 
  lastRating : null,

  setReactionUrl : function(reactionSort, id, tab)
  {
    if (!id || !reactionSort)
      return;
    
    Iframe = document.getElementById("reactionFrame");
    var IframeUrl = Iframe.src.split("?");
    
    //variable to prevent cache 
    var now = new Date();
    
    if (IframeUrl[0])
    {
      if (tab == 1)
        Iframe.src = IframeUrl[0] + "?sort="+ reactionSort + "&id="+ id + "&start=0&numberofrows=0&antiCache="+now;
      else if (tab == 2)
        Iframe.src = IframeUrl[0] + "?sort="+ reactionSort + "&id="+ id + "&start=0&numberofrows=0&beoordeling=mijn&antiCache="+now;
    }
      
    //open dialog
    var reactionDialog = document.getElementById("reactionDialog");
    Spif.ClassNameAbstraction.replace(reactionDialog, "hidden", "shown");
  },
  
  checkReactionForm : function()
  {
    var name = null;
    var email = null;
    
    if (document.getElementById("reaction_name") != null)
      name = document.getElementById("reaction_name").value;
     
    if (document.getElementById("reaction_email") != null)
      email = document.getElementById("reaction_email").value; 
    
    var error = proxies.Validation.checkReactionForm(name, email);
    if (error == "" || error == null || error == "\n")
    {
      return true
    }
    else
    {
      alert(error);
      return false 
    }
  },
  
  getRating : function (evt) 
  {
    el = document.getElementById("giveRating");
    var percentage = (evt.clientX - findPos(el)[0]) / el.offsetWidth;
    return Math.ceil(percentage * 5);
  },
  
  setRating : function (evt)
  {
    el = document.getElementById("giveRating");
    //get rating
    var rating = this.getRating(evt)
    //set right class
    el.className = "ratingBox rated-"+(rating*2);
    //rumble the alement, otherwise className change won't have effect on layout
    el.parentNode.appendChild(el);
    document.getElementById("rating").value = rating*2;
  },
  
  getLastRating : function()
  {
    if (!this.mouseIn)
    {
      el = document.getElementById("giveRating");
      var className = el.className;
      this.lastRating = className.split("-")[1];
//document.title = this.lastRating;
      this.mouseIn = true;
    }
  },
  
  getPotentialRating : function(evt)
  {
    this.getLastRating();
    this.setRating(evt);
  },
  
  setOldRating : function ()
  {
    //el = document.getElementById("giveRating");
    //el.className = "ratingBox rated-"+this.lastRating;
  }
}
  
var reaction = new Reaction();  
    


