/*
Author: Addam M. Driver
Date: 10/31/2006
*/
var sMax = 5;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;

// Rollover for image Stars //
function rating(num){
	if(!rated){
		s = num.id; // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById(i).style.backgroundImage = "url(/images/stars/redstar.gif)";
				document.getElementById("rateStatus").innerHTML = num.name;	
				holder = a+1;
				a++;
			}else{
				document.getElementById(i).style.backgroundImage = "url(/images/stars/greystar.gif)";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById(i).style.backgroundImage = "url(/images/stars/greystar.gif)";
				document.getElementById("rateStatus").innerHTML = "Rate Me...";
			}
		}else{
			rating(preSet);
			document.getElementById("rateStatus").innerHTML = "<span style='color:red'>Rating Saved!</span>";
		}
	}
}

// When you actually rate something //
function rateIt(me,sectid,contentid){
	if(!rated){
		preSet = me;
		rated=1;
		sendRate(me.id,sectid,contentid);
		rating(me);
		//alert("CALLED");
	}
}



// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel,sectid,contentid){
	(new ajax()).getHTML(document.getElementById('rateStatus'),'/ajax.aspx?page=ratings&ratings=' + sel + '&action=add&sectid=' + sectid + '&contentid=' + contentid,'');
	document.getElementById("rateStatus").innerHTML = "<span style='color:red'>Rating Saved!</span>";
}

function ajax()
{
var divobj;
this.getHTML = getHTML;
var http;
function getHTML(obj,url,params)
{

http=getAjaxObject();
if (http==null && obj==null)
{
 return false;
} 
divobj=obj;
http.onreadystatechange=stateChanged1;
divobj.innerHTML="<img align='center' valign='middle' src='/images/ajax-loader.gif' />";

http.open("POST",url,true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(params);

}

function getAjaxObject()
  {  
var xmlHttp;

  try
    {   
 // Firefox, Opera 8.0+, Safari  
  xmlHttp=new XMLHttpRequest();  
  }
  catch (e)
    {
    // Internet Explorer    
	try
      { 
     xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");     
	 }
    catch (e)
      { 
     try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");    
    }
      catch (e)
        {  
      alert("Your browser does not support AJAX!");  
      return false;
        } 
     }
    }

return xmlHttp;


  }
  



function stateChanged1() 
{ 

if (http.readyState==4 && http.status==200)
{ 


if(http.responseText!="Error") {
divobj.innerHTML=http.responseText;
}

}
}
}
