﻿preload('goldvotestar','images/goldvotestar.gif')
preload('whitevotestar','images/whitevotestar.gif')	
	
var mousex = 0
var mousey = 0
	
document.onmousemove = mouseMove	

function mouseMove(e)
{
  if (document.all)
  {
    mousex = window.event.clientX
    mousey = window.event.clientY
  }
  else{
    mousex = e.pageX
    mousey = e.pageY
  }
}


function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function pop(url,id,args)
{
    window.open(url,id,args)
}

function highlightvotestars(id,n)
{
  for(var i = 1;i <= n; i ++)
  {
   star = document.getElementById("votestar_" + id + "_" + i)
   if(star) star.src = goldvotestar.src
  }
}

function incrementStarCount(id,n,ptr)
{
  location.href = "default.aspx?mode=increment&id=" + id + "&star=" + n + "&ptr=" + ptr
}


function unhighlightvotestars(id)
{
  for(var i = 1;i <= 5; i ++)
  {
   star = document.getElementById("votestar_" + id + "_" + i)
   if(star) star.src = whitevotestar.src
  }
}


function showBreakdown(id)
{
  sd = document.getElementById("signdiv_" + id)
  bd = document.getElementById("bdowndiv_" + id)
  if(bd && sd)
  {
    bd.style.top = getY(sd) - 12 + 'px'
    bd.style.left = getX(sd) + 'px'
    bd.style.visibility = 'visible'
  }
}



function hideBreakdown(id)
{
  bd = document.getElementById("bdowndiv_" + id)
  if(bd)
  {
    bd.style.visibility = 'hidden'
  }
}

function mouseIsAboveElement(id,x,y,w,h)
{
  var ret = false
  el = document.getElementById(id)
  if(el)
  {
    var elx = getX(el)
    var ely = getY(el)
    //alert("mousex " + mousex + " elx " + elx + " width " + w + " mousey "  + mousey + " ely " + ely + " height " + h)
    if(mousex > elx && mousex < elx + w && mousey > ely && mousey < ely + h) ret = true 
  }
  return ret
}

// Calculates the absolute page x coordinate of any element 
function getX(element) { 

	var x = 0; 

	do { 

		if (element.style.position == 'absolute') { 

			return x + element.offsetLeft; 

		} 

		else { 

			x += element.offsetLeft; 

			if (element.offsetParent) 

				if (element.offsetParent.tagName == 'TABLE') 

					if (parseInt(element.offsetParent.border) > 0) { 

						x += 1; 

					} 
		} 

	} while ((element = element.offsetParent)); 

	return x; 

} 

// Calculates the absolute page y coordinate of any element 
function getY(element) { 

	var y = 0; 

	do { 

		if (element.style.position == 'absolute') { 

			return y + element.offsetTop; 

		} 

		else { 

			y += element.offsetTop; 

			if (element.offsetParent) 

				if (element.offsetParent.tagName == 'TABLE') 

					if (parseInt(element.offsetParent.border) > 0) { 

						y += 1; 

					} 

		} 

	} while ((element = element.offsetParent)); 

	return y; 

} 