var w=0;
var obj=null;
var rateoff=false;

function activate(){
  if (obj.getAttribute('active')==0) obj.setAttribute('active',1);
  else obj.setAttribute('active',0);
}

function getparents(node,n) {
  var ol;
  if (node){
  	ol=node.offsetLeft;
  if (node.offsetParent){
    par=node.offsetParent;
    getparents(par,x);
  }

  }else{
  	ol=0;
  }

  var x=n+ol;
  return x;
}

function rmove (e){
  if (rateoff==false){
    tmp=this.id.split('_');
    obj=document.getElementById(tmp[0]+'_'+tmp[1]+'_o');
    act=obj.getAttribute('active');
    if (act==null || act==1){
      if (e==undefined){
        de=document.documentElement;
        x=event.clientX+de.scrollLeft-w-1;
      }
      else{
        de=document.body;
        x=e.clientX+de.scrollLeft-w+1;
      }
      ow=document.getElementById(tmp[0]+'_'+tmp[1]+'_o').style;
      if (x>=0 && x<126){
        ow.width=x+'px';
        eval("document.rateform."+tmp[0]+'_'+tmp[1]+'_v'+".value=x");
      }
    }
  }
}

function rate(){
  imgs=document.getElementById('rates').getElementsByTagName('img');
  w=getparents(imgs[1],0);
  for (i=1; i<imgs.length; i++){
    if (imgs[i].id){
      imgs[i].onmousemove=rmove;
      document.getElementById(imgs[i].id+'_o').onmousemove=rmove;
      imgs[i].onclick=activate;
      document.getElementById(imgs[i].id+'_o').onclick=activate;
    }
  }
}
