/***********************************************
* Cool DHTML tooltip script- � Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetxpoint=10 //Customize x offset of tooltip
var offsetypoint=10 //Customize y offset of tooltip
var myevent;
var ie=document.all
var ns6=document.getElementById && !document.all
var agt=navigator.userAgent.toLowerCase();
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;
var enabletip=false
if (ie||ns6)
var contentobj=document.all? document.all["contents"] : document.getElementById? document.getElementById("contents") : ""
var tipTextObj=document.all? document.all["tooltipText"] : document.getElementById? document.getElementById("tooltipText") : ""
var last_e;
var dynamicTipObj=document.all? document.all["dynamicTooltip"] : document.getElementById? document.getElementById("dynamicTooltip") : ""

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		// This following line is correct
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth)
{	
	if (typeof(thetext) == 'undefined') return;
	
	if (typeof(contentObj) == 'undefined' || contentObj == undefined)
	{
		contentobj=document.all? document.all["contents"] : document.getElementById? document.getElementById("contents") : ""
	}
	if (typeof(tipTextObj) == 'undefined' || tipTextObj == undefined)
	{
		tipTextObj=document.all? document.all["tooltipText"] : document.getElementById? document.getElementById("tooltipText") : ""
	}
		
  if (ns6||ie)
  {
    //if (thetext.indexOf("~") >= 0) tipTextObj.innerHTML = dynamicTipObj.innerHTML;
    //else
//	{
	  tipTextObj.innerHTML = thetext;	  
	  if (typeof thecolor!="undefined") tipTextObj.style.color=thecolor;
    //}
    if (typeof thewidth=="undefined")
	{
	  contentobj.style.width=tipTextObj.clientWidth+"px";
	  contentobj.style.height=tipTextObj.clientHeight+"px";
    }
	else
	{
      contentobj.style.width=thewidth+"px";
    }
    enabletip=true;
    return false
  }
}


function positiontip(e)
{
  if (enabletip)
  {
	if (e) last_e = e;
	else if (event) last_e = event;
	else return;
	
	if ((typeof(e) != "undefined" && e == null) || (typeof(event) != "undefined" && event == null)) return;
	
	var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
	var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
	//Find out how close the mouse is to the corner of the window
    var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
    var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

    
    var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
    if (rightedge<contentobj.offsetWidth)
	{
//move the horizontal position of the menu to the left by it's width
      contentobj.style.left=ie? ietruebody().scrollLeft+event.clientX-contentobj.offsetWidth+"px" : window.pageXOffset+e.clientX-contentobj.offsetWidth+"px"
    }
	else if (curX<leftedge)
	{
      contentobj.style.left="5px"
    }
	else
	{
	//position the horizontal position of the menu where the mouse is positioned
      contentobj.style.left=curX+offsetxpoint+"px"
    }

	var targ;

	if (e && e.target) targ = e.target
	else if (event && event.srcElement) targ = event.srcElement
	if (targ.nodeType == 3) // defeat Safari bug
	   targ = targ.parentNode

	if (targ.width && targ.height)
	{
		contentobj.style.left=(findPos(targ)[0] + targ.width + 1) + "px";
		var pixelTop = findPos(targ)[1] - contentobj.style.height.substr(0, contentobj.style.height.length - 2) - 1;
		if (pixelTop < (ie ? ietruebody().scrollTop : window.pageYOffset) + 5) pixelTop = (ie ? ietruebody().scrollTop : window.pageYOffset) + 5;
		contentobj.style.top=pixelTop + "px";
	}
	else
	{
		var pixelLeft = curX + 5;
		contentobj.style.left=pixelLeft + "px";
		var pixelTop = curY - contentobj.style.height.substr(0, contentobj.style.height.length - 2) - 5;
		if (pixelTop < (ie ? ietruebody().scrollTop : window.pageYOffset) + 5) pixelTop = (ie ? ietruebody().scrollTop : window.pageYOffset) + 5;
		contentobj.style.top=pixelTop + "px";
	}
	 
	contentobj.style.visibility="visible"
	tipTextObj.style.visibility="visible"
	
	// mitt eget
	if (rightedge<contentobj.offsetWidth)
	{
		contentobj.style.left= curX - contentobj.offsetWidth + rightedge - 2*offsetxpoint + "px"
	}
	// slut mitt eget
  }
//for debugging purposes
//if (!e) e = window.event;
//document.getElementById("mousePositionIndicator").innerHTML = callingEvent.clientX + "x, " + callingEvent.clientY + "y";
}


function hideddrivetip(){
	if (ns6||ie){
		enabletip=false
		if (contentobj)
		{
			contentobj.style.visibility="hidden"
			contentobj.style.left="-1000px"
			contentobj.style.backgroundColor=''
			contentobj.style.width=''
		}
	}
}
// Recalculate rating

function calcRating(href, bonus, base_num, pct)
{
    // Get character level
    var level = prompt("Please enter the level for the calculation (1-70):");
    level = parseInt(level);

    if(level <= 0 || level > 70 || isNaN(level))
        level = 70;

    // Calculate new value
    var val;
    if (level <= 60)
        val = (base_num * ((1 / 52) * level - ( 8 / 52)));
    else if (level <= 70)
        val =  (base_num / ((262 / 82)  - ( 3 / 82) * level));
    else
        val =  (base_num * ((1 / 52) * level  + ( 12 / 52)));
    
    val = bonus/val;
    // Format it
    
    if (pct) {
        val = val.toFixed(2);
        val += '%';
    }
    else
        val = val.toFixed(0);   

    href.innerHTML = val + ' @ L' + level;
}

document.onmousemove=positiontip
