function toggleDiv(whichDiv){
	var elem, vis;
	
	if(document.getElementById){ // this is the way the standards work
		elem = document.getElementById(whichDiv);
	} else if(document.all){ // this is the way old msie versions work
		elem = document.all[whichDiv];
	} else if(document.layers){ // this is the way nn4 works
		elem = document.layers[whichDiv];
	}
	
	vis = elem.style;
	
	// if the style.display value is blank we try to figure it out here
	if(vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined){
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block':'none';
	}
	
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none':'block';
}

function blank_check(str, name){
	if(str == ''){
		if(name == ''){
			var output = 'You left a field blank.';
		} else {
			var output = 'You left the ' + name + ' field blank.';
		}
		alert(output);
		return false;		
	} else {
		return true;
	}
}

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

function updateFavHtml() { 
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200){ 
			document.getElementById("arfavourite").innerHTML = xmlHttp.responseText;
		}
	}
}

function arFavourite(url){
	xmlHttp = GetXmlHttpObject();

	//Ajax not supported
	if(xmlHttp == null){
		return;
	}
	
	//Url not set
	if(url == null){
		return;
	}
	
	//Loading
	document.getElementById("arfavourite").innerHTML = '<div class="loading_fav">Sending request.</div>';

	xmlHttp.onreadystatechange = updateFavHtml;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateRateHtml() { 
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200){ 
			document.getElementById("rater").innerHTML = xmlHttp.responseText;
		}
	}
}

function rateGame(url){
	xmlHttp = GetXmlHttpObject();

	//Ajax not supported
	if(xmlHttp == null){
		return;
	}
	
	//Url not set
	if(url == null){
		return;
	}
	
	//Switch stars with loading gif
	document.getElementById("rater").innerHTML = '<div class="loading_rater">Sending request.</div>';

	xmlHttp.onreadystatechange = updateRateHtml;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateAffStatus(id) { 
	if(xmlHttp.readyState == 4){
		if (xmlHttp.status == 200){ 
			document.getElementById("affstatus" + id).innerHTML = xmlHttp.responseText;
		}
	}
}

function affEdit(id, url){
	xmlHttp = GetXmlHttpObject();

	//Ajax not supported
	if(xmlHttp == null){
		return;
	}
	
	//Url not set
	if(url == null){
		return;
	}
	
	//Add loading gif
	document.getElementById("affstatus" + id).innerHTML = '<div class="loading_rater">Sending request.</div>';

	xmlHttp.onreadystatechange = updateAffStatus(id);
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function mochiSWF(swfUrl, width, height){
  document.getElementById("mochiswf").innerHTML = '<div class="flash" style="width: ' + width + 'px; height: ' + height + 'px;"><object width="' + width + '" height="' + height + '" type="application/x-shockwave-flash" data="' + swfUrl + '"><param name="movie" value="' + swfUrl + '" /></object></div>';
}
