function GetXmlHttpObject() {
	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;
}

xmlhttp=GetXmlHttpObject();

function rateGame(ratinglink) {
	xmlhttp.onreadystatechange=ratingStateChanged;
	xmlhttp.open("GET", ratinglink,true);
	xmlhttp.send(null);
}

function ratingStateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("media_information_rating_box").innerHTML=xmlhttp.responseText;

	}
}

function get_radio_value()
{
for (var i=0; i < document.comment_form.rating.length; i++)
   {
   if (document.comment_form.rating[i].checked)
      {
      var rad_val = document.comment_form.rating[i].value;
      }
   }
   return rad_val;
}


function addComment(url) {
	xmlhttp.onreadystatechange=commentStateChanged;
	xmlhttp.open('POST',url,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var radio_value = get_radio_value();
	var text = document.comment_form.commenttext.value;
	if (text == "") {
		alert("Please fill in all fields!");
		return false;
	}
	
	var postVars = "commenttext="+text+"&params="+document.comment_form.params.value+"&rating="+radio_value
	xmlhttp.send(postVars);
	return false;
}

function commentStateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("comments_box").innerHTML=xmlhttp.responseText;

	}
}

function toggle(obj) {	
	var el = document.getElementById(obj);
	if ( el.style.display != 'block' ) {
		el.style.display = 'block';
	}
	else {
		el.style.display = 'none';
	}
}


function modFav(favlink) {
	xmlhttp.onreadystatechange=favStateChanged;
	xmlhttp.open("GET", favlink ,true);
	xmlhttp.send(null);
}



function favStateChanged() {
	if (xmlhttp.readyState==4) {
		document.getElementById("favorites_box").innerHTML = xmlhttp.responseText;
	}
}

function doConfirm(message, url) {
	conf = confirm(message);
	if (conf == true) {
		document.location = url;
	}
}
