	var savedsrc = "";
	var cursrc = "";


//window.onresize = new Function("window.location=window.location.href;");
if ( window.onload != undefined && window.onload != null )
	old_onload = window.onload;
else
	old_onload = null;
window.onload = function()
{
	document.onmousemove = handlerate;
	document.onmouseup = global_mouseup;
	document.onmousedown = global_mousedown;
	if ( old_onload )
		old_onload();
}


	function dorate(idc)
	{
		rateimg = idc.src;
		messagebox( "<br/><br/>Wait...<br/><img src='/spinffe.gif'><br/><br/>", null, null  );

		//alert( rateimg );
		//return;
		rating = 0;
		if ( rateimg.indexOf( "_10" ) != -1 ) rating = 1;
		if ( rateimg.indexOf( "_20" ) != -1 ) rating = 2;
		if ( rateimg.indexOf( "_30" ) != -1 ) rating = 3;
		if ( rateimg.indexOf( "_40" ) != -1 ) rating = 4;
		if ( rateimg.indexOf( "_50" ) != -1 ) rating = 5;
		if ( rating == 0 )
		{
			// why?
			return false;
		}

		tag = idc.id;
		fid = tag.substring( 5 );

		var request = getajax();
		var mytime= "&ms="+new Date().getTime();

		parms = "action=ratefantasy&fid=" + fid + "&rating=" + rating + mytime;
        request.open("POST", "/controller.9", true);
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        request.setRequestHeader("Content-length", parms.length);
        request.setRequestHeader("Connection", "close");

        request.onreadystatechange = function(){
			if (request.readyState != 4) return;
            if (request.status == 200) {
	            if (request.responseText){
	            	if ( request.responseText != "ALREADY_RATED" )
	            	{
	            		//alert( "*" + request.responseText + "*" );
	            		idc.src = "/" + request.responseText;
	            		bumpratingcount(fid);
	            		//savedsrc = idc.src;
	            		messagebox( "<br/><br/>Rating recorded.<br/><br/><br/>", null, ""  );
	            	}
	            	else
						//messagebox( request.responseText, null, ""  );
						messagebox( "<br/><br/>You've already rated this fantasy.<br/><br/><br/>", null, ""  );

					return false;
                }
			  }
			  else
			  {
					messagebox( "An error occurred.  Please try your request again.", null, ""  );
					return false;
			  }
		}

    	request.send(parms);
	}

	function ajaxrate()
	{
	}

	function saverating( ctrl )
	{
		//savedsrc = ctrl.src;
		cursrc = "";
		ctrl.style.cursor = "pointer";
	}

	function restorerating( ctrl )
	{
		if ( savedsrc.indexOf("rate") == -1 )
		{
			// we have some type of bug where periodically, the ctrl img src is "" upon
			// mouseover; we can't find it, so we just have extra sanity checks in places
			// in the interim.
			//alert( "*"+savedsrc+"*" );
			return;
		}

		ctrl.src = savedsrc;
		cursrc = savedsrc;
		savedsrc = "";
		ctrl.style.cursor = "default";
	}

	function trace(str)
	{
		if ( document.getElementById("debug") )
			document.getElementById("debug").innerHTML = str;
	}

	function global_mouseup(ev)
	{
		chatdragging=false;
		chatsizing=false;
	}
	function global_mousedown(ev)
	{
	}

	function handlerate(ev)
	{
		if (!ev)
			ev = window.event;

		if (ev.target)
		  {
		  targ=ev.target;
		  }
		else if (ev.srcElement)
		  {
		  targ=ev.srcElement;
		  }
		if (targ.nodeType==3) // defeat Safari bug
		  {
		  targ = targ.parentNode;
		  }

		if ( document.getElementById("debug") )
			document.getElementById("debug").innerHTML = targ.id;

		//if ( chatdragging )
		if ( 0 )	// no chat dragging
		//if ( targ.id == "chatbar2" )
		{

			{
				w = document.getElementById("chatwindow");
				if ( w )
				{
					x = mouseX(ev);
					y = mouseY(ev);
					w.style.left = x - 100;
					w.style.top = y - 15;
				}
				return false;
			}
		}

		//if ( chatsizing )
		if ( 0 )	// no chat sizing
		{
				w = document.getElementById("chatcontainer");
				if ( w )
				{
					x = mouseX(ev);
					y = mouseY(ev);
					w.style.width = x;
					w.style.height = y;
					rebuild_tabs();
				}
				return false;
		}

		if ( targ.id.substr(0,5) == "rater" )
		{
			idc = targ.id;
			ctrl = targ;
			// ctrl = document.getElementById(idc);
			if ( ctrl )
			{
				if ( savedsrc == "" )
				{
					if ( ctrl.src.indexOf( "rate_" ) != -1 )
					{
						savedsrc = ctrl.src;	// save the current rating the first time we hit this
					}
					else
					{
						return;
					}
				}
			}

			rbx_left = getabsleft( idc );
			rbx_top = getabstop( idc);
			rbx_width = ctrl.clientWidth;
			rbx_height = ctrl.clientHeight;
			rbx_right = rbx_left + rbx_width;
			rbx_bottom = rbx_top + rbx_height;
			rating_steps = 5;
			rating_block_step_px = Math.round(rbx_width / rating_steps);

			rate = Math.floor((mouseX(ev) - rbx_left) / rating_block_step_px) + 1;
			if ( rate > 5 )
				rate = 5;
				//alert(rate);
			target_src = "/rate_" + rate + "0.gif";
			if ( cursrc != target_src )
			{
				ctrl.src = target_src;
				cursrc = target_src;
			}
			//trace( Math.floor((mouseX(ev) - rbx_left) / rating_block_step_px) );
		}
		else
		{
			// not on a rater
			savedsrc = "";
		}
	}

	//document.onmousemove = handlerate;

