var xmlHttp;

var MOVIE;
var AREA;

function rateMovie(user,area,movie,rating,review)
{

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var url="/user/movie_ajax.amp";
url=url+"?movie="+movie;
url=url+"&user="+user;
url=url+"&area="+area;
url=url+"&rating="+rating;
url=url+"&review="+review;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=movieStateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
MOVIE=movie;
AREA=area;
}

function movieStateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {

        var counts=xmlHttp.responseXML.getElementsByTagName("data");
	
        for(var i=0;i < counts.length;i++){
                var title = counts[i].getElementsByTagName('title')[0].firstChild.data;
                var this_rating = counts[i].getElementsByTagName('rating')[0].firstChild.data;
                var avg_rating = counts[i].getElementsByTagName('avg_rating')[0].firstChild.data;
                var total_ratings = counts[i].getElementsByTagName('total_ratings')[0].firstChild.data;
                var this_review = counts[i].getElementsByTagName('review')[0].firstChild.data;
                var site_host = counts[i].getElementsByTagName('site_host')[0].firstChild.data;
                var site_name = counts[i].getElementsByTagName('site_name')[0].firstChild.data;
                var fb_redirect = counts[i].getElementsByTagName('fb_redirect')[0].firstChild.data;
        }
	//window.alert('TOTAL: ' + avg_rating);
        //window.alert(title + 'rating: ' + this_rating + this_review + site_host + site_name + fb_redirect);
        //document.getElementById('DIV_ALL').style.display = 'none';
        document.getElementById('DIV_MOVIE_RATING').style.display = 'none';
        //document.getElementById('IMG_' + MOVIE).src = '/images/movie_star_' + avg_rating + '.png';
        //document.getElementById('RATINGS_' + MOVIE).innerHTML = total_ratings + ' rating(s)';
	
	//window.alert(MOVIE);

	var MOVIE_POSTER;
	var FLEX_APP;

	if (AREA == '010')
	{		
		MOVIE_POSTER = 'http://www.godavis.biz/images/movies/0' + MOVIE + '01.jpg';
		FLEX_APP = 'Y';
	}
	else
	{
		MOVIE_POSTER = 'http://www.godavis.biz/images/movies/0' + MOVIE + '01.jpg';
		//MOVIE_POSTER = 'http://www.godavis.biz/images/movies/' + MOVIE + '.jpg';
		FLEX_APP = 'N';
	}

        postToFacebook(
		'none',
		'',
		'Gave' + ' ' + this_rating + ' ' + 'Stars to the movie ',
		title,
		'[SITE_NAME]',
		'<b>My Review:</b> ' + this_review,
		'',
		'Add your own Review/Rating',
		fb_redirect,
		MOVIE_POSTER,
		fb_redirect,
		'Additional Comments:',
		'I Gave' + ' ' + this_rating + ' ' + 'Stars to: ' + title + '.',
		FLEX_APP);

        //postToFacebook('/movies.amp','82796312089','Gave' + ' ' + this_rating + ' ' + 'Stars to the movie: ','<A HREF="http://' + site_host + '/movies.amp&anchorValue=movie_' + MOVIE + '">' + title + '</A>','<A HREF="http://' + site_host + '">' + site_name + '</A>','My Review: ' + this_review,'','Add Your Own Review!','http://' + site_host + '/movies.amp&anchorValue=movie_' + MOVIE','','','Your Review:',this_review);

	//<img src="http://godavis.biz/images/movies/' + MOVIE + '.jpg">
	//http://' + site_host + '/movies.amp&anchorValue=movie_' + MOVIE
        //redirect_url,template_id,VERB,NOUN,SITE_NAME,BODY,FULL_BODY,ACTION_LINK_TEXT,ACTION_LINK,IMAGE,IMAGE_HREF,MESSAGE_PROMPT,USER_MESSAGE
 }
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 	xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
	window.alert('IE1');
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
	window.alert('IE1');
  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}