// JavaScript Document

function popUp(URL){
winpops=window.open(URL,"","width=200,height=125,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popUp2(URL){
winpops=window.open(URL,"","width=200,height =450,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popUpFavorite(URL){
winpops=window.open(URL,"","width=200,height=100,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}


function popComments(URL){
winpops=window.open(URL,"","width=440,height=400,left=100,top=100,status=0,scrollbars=1,resizable=1,menubar=0,location=0,toolbar=0")
}


function popRecoverPassword(URL){
winpops=window.open(URL,"","width=440,height=200,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}

function popReportGame(URL){
winpops=window.open(URL,"","width=250,height=225,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0")
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Nannette Thacker http://www.shiningstar.net
function confirmDeleteMessage()
{
var agree=confirm("Are you sure you wish to delete this message?");
if (agree)
	return true ;
else
	return false ;
}



function rategame(rating, id, div)
{
$.get("http://www.2play.com/includes/insertrating.php?rank="+rating+"&gameid="+id, function(data){
	
//    $('.resultvote').html(data.split('|')[0]);
	  //   $('.gamerating').html(data.split('|')[1]);
 });
}



$(document).ready(function() {


function $El(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $St(o) { return((typeof(o)=='object'?o:$El(o)).style); }
function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); }
function abPos(o) { var o=(typeof(o)=='object'?o:$El(o)), z={X:0,Y:0}; while(o!=null) { z.X+=o.offsetLeft; z.Y+=o.offsetTop; o=o.offsetParent; }; return(z); }
function XY(e,v) { var o=agent('msie')?{'X':event.clientX+document.body.scrollLeft,'Y':event.clientY+document.body.scrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); }

star={};

star.disabled = false;


star.pad = function pad(num, length){
	a = num.toString().indexOf('.');
	if(a>-1)
	{
var str = "" + num;
while(str.length<length){
str = str+'0';
}
}else
{
	
	str = num+'.00';
}
return str;
};


star.mouse=function(e,o) { if(star.stop || isNaN(star.stop)) { star.stop=0;

	if(star.disabled != true)
	{
	document.onmousemove=function(e) { var n=star.num;

		var p=abPos($El('star'+n)), x=XY(e), oX=x.X-p.X, oY=x.Y-p.Y; star.num=o.id.substr(4);

		if(oX<1 || oX>84 || oY<0 || oY>19) { star.stop=1; star.revert(); }
		
		else {


			$St('starCur'+n).width=oX+'px';
			$St('starUser'+n).color='#111';
			$El('starUser'+n).innerHTML=star.pad(Math.round(((oX/84*100)*10)/100)/2, 4)+'/5.00';
		}
	}; }
} };

star.update=function(e,o) { var n=star.num, v=$El('starUser'+n).innerHTML.replace('/5.00', '');

	star.disabled = true;
	$El('star'+n).onmousedown = '';
	$St('star'+n).cursor = 'auto';
	$St('starCur'+n).backgroundPosition = 'left 20px';
	$St('starUser'+n).color = '#A1A1A1';
	n=o.id.substr(4); $El('starCur'+n).title=v;

/*	req=new XMLHttpRequest(); req.open('GET','/AJAX_Star_Vote.php?vote='+(v/100),false); req.send(null);   
 */
game = $El('star'+n).getAttribute('rel');

	$.get("http://www.2play.com/includes/insertrating.php?rank="+v+"&gameid="+game, function(data){
	
	alert('Thank you for rating! New rating: '+v);

	//    $('.resultvote').html(data.split('|')[0]);
	  //  $('.gamerating').html(data.split('|')[1]);
 });


	star.revert();


};

star.revert=function() { var n=star.num;
	
	
	if($El('starCur'+n).title != 'N/A') 	
		v=$El('starCur'+n).title;
	else
		v = 0;



		$St('starCur'+n).width=(v * 20 * (85/100))+'px';
		
	

		$El('starUser'+n).innerHTML=(v>0?v+'/5.00':'N/A');

	$El('starUser'+n).style.color='#A3A3A3';	
	document.onmousemove='';

};

star.disable = function()
{
	star.disabled = true;
	document.onmousemove = '';
	$El('star'+star.num).onmousedown = 0;
	$St('star'+star.num).cursor = 'auto';
	$St('starCur'+star.num).backgroundPosition = 'left 20px';
};

star.num=0;
   });



