<!--
pic_zero_stars_lo     = new Image(15,15);
pic_zero_stars_lo.src = "/images/stars/nim_low.gif";
pic_zero_stars_hi     = new Image(15,15);
pic_zero_stars_hi.src = "/images/stars/nim_high.gif";

pic_zero_stars        = new Image(92,15);
pic_zero_stars.src    = "/images/stars/stars_1_0.gif";

pic_stars_2_10        = new Image(92,15);
pic_stars_2_10.src    = "/images/stars/stars_2_10.gif";
pic_stars_2_20        = new Image(92,15);
pic_stars_2_20.src    = "/images/stars/stars_2_20.gif";
pic_stars_2_30        = new Image(92,15);
pic_stars_2_30.src    = "/images/stars/stars_2_30.gif";
pic_stars_2_40        = new Image(92,15);
pic_stars_2_40.src    = "/images/stars/stars_2_40.gif";
pic_stars_2_50        = new Image(92,15);
pic_stars_2_50.src    = "/images/stars/stars_2_50.gif";


function createXMLHttpRequest() {

var ua;

if (window.XMLHttpRequest)
  {
  try
    {
    ua = new XMLHttpRequest();
    }
  catch(err)
    {
    ua = false;
    }
  }
else
  {
  if (window.ActiveXObject)
    {
    try
      {
      ua = new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch(err)
      {
      ua = false;
      }
    }
  }

return ua;
}


function sendHttpRequest(host_id, host_rating)
{
req.open('POST', 'twh_response.php?id=' + host_id + '&stars=' + host_rating);
req.onreadystatechange = handleResponse;
req.send(null);
}


function handleResponse()
{
if (req.readyState == 4)
  {
  var response = req.responseText;
  //alert(response);
  }
}



var star_offsets = [18, 37, 56, 75, 94];
var star_offset_texts = ["I'd Rather Die First", "I Hate Them", "I Don't Like Them", "I Like Them", "I Really Like Them", "I Love Them"];


function calc_stars(range)
{
for (var i = 0; i < 5; i++)
  {
  if (range <= star_offsets[i])
    {
    return (i + 1);
    }
  }

return 0;
};


function calc_element_mousecoord(evt, targ)
{
var xcoord = -1;

if (!evt)
  {
  var evt = window.event;
  }

if (evt.offsetX)
  {
  xcoord = evt.offsetX;
  }
else
  {
  if (targ.offsetX != null)
    {
    xcoord = evt.layerX - targ.offsetX;
    }
  else
    {
    if (evt.layerX)
      {
      var tmp_xcoord = getElementOffsetX(targ);
      xcoord         = evt.layerX - tmp_xcoord;
      targ.offsetX   = tmp_xcoord;
      }
    }
  }

return xcoord;
}


function getElementOffsetX(targ)
{
return handleElementOffsetX(targ, true);
}


function handleElementOffsetX(targ, use_abs)
{
var xcoord = 0;

if (targ.offsetLeft != null)
  {
  xcoord += targ.offsetLeft;

  while (targ.offsetParent)
    {
    // When position is absolute and we trust absolute positions, simply return the elements X-coord:
    if (use_abs && targ.offsetParent.style.position == "absolute")
      {
      return xcoord;
      }
    else  // Calculate X-coord by iterating over all parents X-coords:
      {
      xcoord += targ.offsetParent.offsetLeft;
      targ = targ.offsetParent;
      }
    }
  }

return xcoord;
}




var req = createXMLHttpRequest();


function init()
{
for (var i = 0; i < document.images.length; i++)
  {
  if (document.images[i].id.substring(0,8) == "rSTARBAR")
    {
    document.images[i].onclick     = register_stars;
    document.images[i].onmouseover = register_stars;
    document.images[i].onmouseout  = register_stars;
    }
  else
    {
    if (document.images[i].id.substring(0,8) == "zSTARBAR")
      {
      document.images[i].onclick     = register_zero;
      document.images[i].onmouseover = register_zero;
      document.images[i].onmouseout  = register_zero;
      }
    }
  }
}


function register_stars(e)
{
if (!e)
  {
  e = window.event;
  }

var targ;

if (e.target)
  {
  targ = e.target;
  }
else
  {
  if (e.srcElement)
    {
    targ = e.srcElement;
    }
  }

if (targ.nodeType == 3) // defeat Safari bug
  {
  targ = targ.parentNode;
  }

var cur_coord   = calc_element_mousecoord(e, targ);
var star_count  = calc_stars(cur_coord);
var star_bar_id = "zSTARBAR" + targ.id.substring(8);


// Update the textarea element:
//document.forms[0].elements['log'].value = e.type + ' ' + cur_coord + ' ' + star_count + '\n' + document.forms[0].elements['log'].value;

if (e.type == 'mouseover')
  {
  // Dont be a CPU hog, only track mouse movement when inside a star element:
  targ.onmousemove = register_stars;

  targ.title   = "Click to rate the web hoster \"" + star_offset_texts[star_count] + "\"";
  targ.alt     = targ.title;

  // Save the current image (average star count) and use mouse position to light up stars:
  targ.srcORIG = targ.src;
  targ.src     = eval("pic_stars_2_" + star_count + "0.src");


  document.getElementById(star_bar_id).srcORIG = document.getElementById(star_bar_id).src;
  document.getElementById(star_bar_id).src     = pic_zero_stars_lo.src;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_id)
  //    {
  //    document.images[i].srcORIG = document.images[i].src;
  //    document.images[i].src     = pic_zero_stars_lo.src;
  //    }
  //  }
  }

if (e.type == 'mouseout')
  {
  // When we leave the star element, stop mouse movement tracking:
  targ.onmousemove = null;

  // Restore image to display the current average star count image:
  targ.src = targ.srcORIG;

  document.getElementById(star_bar_id).src = document.getElementById(star_bar_id).srcORIG;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_id)
  //    {
  //    document.images[i].src = document.images[i].srcORIG;
  //    }
  //  }
  }

if (e.type == 'mousemove')
  {
  // When we move, update the stars count to follow the mouse pointer:
  targ.src     = eval("pic_stars_2_" + star_count + "0.src");

  targ.title   = "Click to rate the web hoster \"" + star_offset_texts[star_count] + "\"";
  targ.alt     = targ.title;
  }

if (e.type == 'click')
  {
  // Make current displayed star count static (instead of average star count):
  targ.src     = eval("pic_stars_2_" + star_count + "0.src");
  targ.srcORIG = targ.src;

  var star_bar_id = "zSTARBAR" + targ.id.substring(8);

  document.getElementById(star_bar_id).srcORIG = pic_zero_stars_lo.src;
  document.getElementById(star_bar_id).src     = pic_zero_stars_lo.src;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_id)
  //    {
  //    document.images[i].srcORIG = pic_zero_stars_lo.src;
  //    document.images[i].src     = pic_zero_stars_lo.src;
  //    }
  //  }

  // Send the click to the backend for recording statistics:
  sendHttpRequest(targ.id.substring(8), star_count);
  //alert("rated " + star_count + " for Hoster ID " + targ.id.substring(8));
  }

return false;
}


function register_zero(e)
{
if (!e)
  {
  e = window.event;
  }

var targ;

if (e.target)
  {
  targ = e.target;
  }
else
  {
  if (e.srcElement)
    {
    targ = e.srcElement;
    }
  }

if (targ.nodeType == 3) // defeat Safari bug
  {
  targ = targ.parentNode;
  }


var star_bar_id = targ.id.substring(8);


if (e.type == 'mouseover')
  {
  // Save the current image (average star count) and use mouse position to light up stars:
  targ.srcORIG = targ.src;
  targ.src     = pic_zero_stars_hi.src;

  targ.title   = "Click to rate the web hoster \"" + star_offset_texts[0] + "\"";
  targ.alt     = targ.title;

  star_bar_id  = "rSTARBAR" + star_bar_id;

  document.getElementById(star_bar_id).srcORIG = document.getElementById(star_bar_id).src;
  document.getElementById(star_bar_id).src     = pic_zero_stars.src;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_id)
  //    {
  //    document.images[i].srcORIG = document.images[i].src;
  //    document.images[i].src     = pic_zero_stars.src;
  //    }
  //  }
  }

if (e.type == 'mouseout')
  {
  // Restore image to display the current average star count image:
  targ.src    = targ.srcORIG;
  star_bar_id = "rSTARBAR" + star_bar_id;

  document.getElementById(star_bar_id).src = document.getElementById(star_bar_id).srcORIG;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_id)
  //    {
  //    document.images[i].src = document.images[i].srcORIG;
  //    }
  //  }
  }

if (e.type == 'click')
  {
  // Make current displayed star count static (instead of average star count):
  targ.src          = pic_zero_stars_hi.src;
  targ.srcORIG      = targ.src;
  var star_bar_zero = "rSTARBAR" + star_bar_id;

  document.getElementById(star_bar_zero).srcORIG = pic_zero_stars.src;
  document.getElementById(star_bar_zero).src     = pic_zero_stars.src;
  //for (var i = 0; i < document.images.length; i++)
  //  {
  //  if (document.images[i].id == star_bar_zero)
  //    {
  //    document.images[i].srcORIG = pic_zero_stars.src;
  //    document.images[i].src     = pic_zero_stars.src;
  //    }
  //  }

  // Send the click to the backend for recording statistics:
  sendHttpRequest(star_bar_id, 0);
  }

return false;
}

// -->
