/* AJAX Star Rating : v1.0.3 : 2008/05/06 */
/* http://www.nofunc.com/AJAX_Star_Rating/ */

function $(v,o) { return((typeof(o)=='object'?o:document).getElementById(v)); }
function $S(o) { return((typeof(o)=='object'?o:$(o)).style); }
function agent(v) 
{ 
	return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); 
}

function abPos(o) 
{ 
	var o=(typeof(o)=='object'?o:$(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 ScrollTop,ScrollLeft;
	if(agent('msie'))
	{
		if (document.documentElement && document.documentElement.scrollTop)
		{
			ScrollTop = document.documentElement.scrollTop;
			ScrollLeft = document.documentElement.scrollLeft;
		}
		else if (document.body)
		{
			ScrollTop = document.body.scrollTop;
			ScrollLeft = document.body.scrollLeft;
		}
	}

	var o = agent('msie') ? {'X':event.clientX+ScrollLeft,'Y':event.clientY+ScrollTop}:{'X':e.pageX,'Y':e.pageY}; return(v?o[v]:o); 
}

star={};

star.mouse=function(e,o) { if(star.stop || isNaN(star.stop)) { star.stop=0;

	document.onmousemove=function(e) { var n=star.num;

	var p = abPos($('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 
		{
			if(oX>1 && oX<17)
				oX = 17;
			
			if(oX>17 && oX<34)
				oX = 34;
			
			if(oX>34 && oX<50)
				oX = 50;
			
			if(oX>50 && oX<67)
				oX = 67;
			
			if(oX>67 && oX<84)
				oX = 84;
			
			$S('starCur'+n).width=oX+'px';
			$S('starUser'+n).color='#111';
			$('starUser'+n).innerHTML=Math.round(oX/84*100)+'%';
		}
	};
} };

star.update=function(e,o,isIDX) 
{ 
	//alert(isIDX);
	var n=star.num, v=parseInt($('starUser'+n).innerHTML);
	n=o.id.substr(4); $('starCur'+n).value=v;
	var strMLSNo = document.getElementById("mlsno"+n).value;
	var intContactId = document.getElementById("cid"+n).value;	
	document.getElementById("loading"+n).style.display = "";
	setTimeout("UpdateTimer("+n+")", 2800);	
	if(intContactId==0 || intContactId == "")
		window.location.href = WWWROOT+"/idx_register.php?";
	var strURL = WWWROOT+"/idx_post_addeditrating.php?n="+n+"&r="+v+"&c="+intContactId+"&mls="+strMLSNo+"&isIDX="+isIDX;

	AjaxPostNew(strURL, 5);
	//req = new XMLHttpRequest(); req.open('GET','?vote='+(v/100),false); req.send(null);    

};

star.revertonload=function(i) 
{ 

	for(var n=0;n<i;n++)
	{
		var v=parseInt($('starCur'+n).value);

		$S('starCur'+n).width=Math.round(v*84/100)+'px';
		$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
		$('starUser'+n).style.color='#888';
	}
	
	document.onmousemove='';
};

star.clearonclick=function(n) 
{ 
	var v=parseInt($('starCur'+n).value);

	$S('starCur'+n).width=Math.round(v*84/100)+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';
	
	document.onmousemove='';
};

star.revert=function() { var n=star.num, v=parseInt($('starCur'+n).value);

	$S('starCur'+n).width=Math.round(v*84/100)+'px';
	$('starUser'+n).innerHTML=(v>0?Math.round(v)+'%':'');
	$('starUser'+n).style.color='#888';

	document.onmousemove='';

};

function UpdateTimer(val)
{
	document.getElementById("loading"+val).style.display = 'none';
}

function ClearRating(n)
{

	document.getElementById("starCur"+n).value = 1;	
	document.getElementById("starUser"+n).innerHTML = 0+'%';
	star.clearonclick(n);	
	var strMLSNo = document.getElementById("mlsno"+n).value;
	var intContactId = document.getElementById("cid"+n).value;	
	document.getElementById("loading"+n).style.display = "";	
	setTimeout("UpdateTimer("+n+")", 2800);		
	var strURL = WWWROOT+"/idx_post_addeditrating.php?n="+n+"&r=0"+"&c="+intContactId+"&mls="+strMLSNo;
	AjaxPostNew(strURL, 5);
}

function AfterUpdateRating(pContent)
{
	var n = pContent;
	if(document.getElementById("loading"+n))
		document.getElementById("loading"+n).style.display = 'none';
}

