stars_tmp = new Array();
star_o = new Image();
star_a = new Image();
star_p = new Image();

for (i = 0; i <= 5; i++) {
   stars_tmp[i] = new Image();
}

function voteIt(act, nam, elem, stars_url, form_name, elem_pref) {

    if ('undefined' == typeof(elem_pref))
    {
        elem_pref = '';
    }

    star_o.src = stars_url + "star_light.gif";
    star_a.src = stars_url + "star_active.gif";
    star_p.src = stars_url + "star_passive.gif";

    oRate = new makeObj("rate_" + nam + elem_pref);
    eList = oRate.elem.childNodes.length;
    eImg = oRate.elem.childNodes;

    if (!act) {
      for(i = 0; i <= elem; i++) {
        eImg[i].src = stars_tmp[i].src;
      }
    }

    if (act == 1) {
      for (i = 0; i <= elem; i++) {
        stars_tmp[i].src = eImg[i].src;
        eImg[i].src = star_o.src;
      }

      oRate.elem.className = "hand";
    }

    if (act == 2) {
      oRate.elem.className = "def";

      document.getElementById(nam).value = elem + 1;
      count_score(form_name);

      for (i = 0; i < eList; i++) {
        stars_tmp[i].src = eImg[i].src = ((i <= elem) ? star_a.src : star_p.src);
      }
    }
    
    //AJAX --- update providers personal score (FOR CANDIDATES LIST ONLY)
    if (act == 3) {
        if ('' == elem_pref) {
            tmp_pref = '_all';
        } else {
            tmp_pref = '';
        }
        oRate2 = new makeObj("rate_" + nam + tmp_pref);
        if (null != oRate2.elem) {
            eImg2 = oRate2.elem.childNodes;
        }
        oRate.elem.className = "def";
        document.getElementById(nam).value = elem + 1;
        for (i = 0; i < eList; i++) {
          stars_tmp[i].src = eImg[i].src = ((i <= elem) ? star_a.src : star_p.src);
          if (null != oRate2.elem) {
            eImg2[i].src = eImg[i].src;
          }
        }
        ajax_updatePersonalScore(nam, elem + 1);
    }
}

function makeObj(obj) {
  this.elem = document.getElementById(obj);
  this.css = this.elem ? this.elem.style : null;
  return this;
}

function count_score(form_name) {
  if (document.forms[form_name].elements["score_ids"])
  {
	var ids = document.forms[form_name].elements["score_ids"].value;
	ids = ids.substr(0,ids.length-1);
	var id_array = ids.split(',');
	var weights = document.forms[form_name].elements["score_weights"].value;
	weights = weights.substr(0,weights.length-1);
	var weight_array = weights.split(',');
	var i = 0;
	var count = 0;
	for (i in id_array)
    {
	  element = document.forms[form_name].elements[id_array[i]];
	  weight = weight_array[i];
	  count = count + parseInt(element.value)*parseFloat(weight);
    }
	 document.getElementById("scorevalue").innerHTML = (Math.round(count*100)/100).toFixed(2);
	 if (document.getElementById("avg_score"))
	 {
		document.getElementById("avg_score").value = (Math.round(count*100)/100).toFixed(2);
	 }
  }
}


