
// START: ajaxpage

var loadedobjects = "";
var rootdomain = "http://"+window.location.hostname;

function ajaxpage(url, containerid){
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, containerid)
}
page_request.open('GET', url, true)
page_request.send(null)
}

function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
if(containerid == 'addtofavorites'){
alert(page_request.responseText);
}
else if(containerid == 'tellafriend'){
alert(page_request.responseText);
document.getElementById('yourname').value='Your Name';
document.getElementById('friendname').value='Friend\'s Name';
document.getElementById('friendemail').value='Friend\'s Email';
}
else if(containerid == 'updatelinks'){
return true;
}
else if(containerid == 'reportgame'){
return true;
}
else {
document.getElementById(containerid).innerHTML=page_request.responseText;
}
}

}

// END: ajaxpage

// START: makePOSTRequest

function makePOSTRequest(url, parameters, div) {
http_request = false;
if (window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
result = http_request.responseText;
document.getElementById(div).innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
};
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}

// END: makePOSTRequest

function SubmitComment(){
var MyTextArea = document.getElementById('post_text');
var MyGameId = document.getElementById('post_gameid');
var MyUserId = document.getElementById('post_userid');
var containerid = "ajaxcomment";
if(MyTextArea.innerHTML == "" || MyTextArea.innerHTML == null){
alert('Please enter a comment before submitting');
MyTextArea.innerHTML = "";
MyTextArea.focus();
}
else {
var posturl = baseurl + "arcade/includes/postcomment.php";
var poststr = "?comment=" + escape(encodeURI( MyTextArea.innerHTML )) +
              "&gameid=" + escape(encodeURI( MyGameId.value )) +
              "&userid=" + escape(encodeURI( MyUserId.value ));
var url = posturl + poststr;
ajaxpage(url, containerid);
document.getElementById('postcomment').style.display = 'none';             
}              
}

function AddToFavorites(gameid,userid){
var url = baseurl + 'arcade/includes/addtofavorites.php?gameid=' + gameid + '&userid=' + userid;
var containerid = 'addtofavorites';
ajaxpage(url, containerid);
}

function LinkOut(linkid){
var url = baseurl + 'arcade/includes/linkout.php?linkid=' + linkid;
var containerid = 'updatelinks';
ajaxpage(url, containerid);
}


