var identifier;

var titleid;

// Create A object Of Xml Http 
function createXMLHttp()
{
	if(typeof(XMLHttpRequest) != "undefined" )
	{
	 
		return new XMLHttpRequest();
	}
	else if( window.ActiveXObject )
	{
		var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
						"MSXML2.XMLHttp.2.0","MSXML2.XMLHttp.1.0"];
		for( var i=0 ; i < aVersions.length;i++ )
		{
			try
			{
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			}
			catch( oError )
			{
				//Do Nothing
			}
		}
	}
	throw new Error("MSXML is not installed");
}
/*
TO CLEAR THE RATE AND MAKE THE STARS BLANK
var isRateChanged = false;
function changeImage()
{
isRateChanged = false;
document.getElementById("rated").className="rate0"
}
function showActualImg()
{
    if(isRateChanged==false)
    {
        document.getElementById("rated").className="agg25"
    }
}
*/
function RateMovie(movieId,rateVal,ids, rateUrl)
{
 //alert('')
identifier = ids; 
titleid = movieId;

var strName = movieId +"&rId=" + rateVal;
  
    if (strName.length > 0)
    {
    
        //Append the name to search for to the requestURL
       //var url = rateUrl + strName;
      var url=rateUrl+strName;   
      //alert(url);
        
        //Create the xmlHttp object to use in the request
        //stateChangeHandler will fire when the state has changed, i.e. data is received back
        // This is non-blocking (asynchronous)
        //xmlHttp = GetXmlHttpObject(stateChangeHandler);
        
        //Send the xmlHttp get to the specified url
        //xmlHttp_Get(xmlHttp, url);
		var oXmlHttp = createXMLHttp();   
        oXmlHttp.open( "get", url, true ); 
		oXmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		oXmlHttp.send(null);
    }
    else 
    {
        //Textbox blanked out, clear the results
        // alert(document.getElementById('divShow'));
        // document.getElementById('divShow').innerHTML = '';
    }
    
	oXmlHttp.onreadystatechange = function()
	{	//alert('inside func');
		//If the page is loaded successfully
		if(oXmlHttp.readyState == 4)
		{
		    //alert('inside ready state');
			if(oXmlHttp.status == 200)
			{ //alert('inside success status');
				//If the response is not null and length is not zero then set the latest rating
				if(oXmlHttp.responseText != null)
				{
					var str = oXmlHttp.responseText;
					//alert(str); //alert('success blk');
					//Populate the innerHTML of the div with the results
					if(str != "failed")
					{
                    //alert(str);
					UpdateStar(str);
					}
					else
					{
						location.href = "SignUp.aspx";
					}
				}	
			}
			else
			{
				//displayMsg("An Error Occurred:" + oXmlHttp.statusText)
			}
		}
	}

} 


function UpdateStar(clsname)
{
	//alert(identifier);
	//alert(document.getElementById(identifier));
	//alert(titleid);
	//Append the movieId to the top star class names 'rated' & 'rated2' to get the Ids
	var aId1 = 'rated' + titleid; 
	var aId2 = 'rated2' + titleid; 
	var aId3 = 'rated3' + titleid;
	//alert(document.getElementById(A1));
	//alert(aId2);
	// To change simultaneously with the top star rating which is under the image
	//document.getElementById(aId2).className = clsname; 
	//alert(aId2);
	if (document.getElementById(aId1) != null)
	{
		document.getElementById(aId1).className = clsname;
	}
	if (document.getElementById(aId2) != null)
	{
		document.getElementById(aId2).className = clsname;
	}
	if (document.getElementById(aId3) != null)
	{
		document.getElementById(aId3).className = clsname;
	}
}