var id, client1, client2, client3, client4, client5;
var star0, star1, star2, star3, star4, star5;

function get_http_object() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject()) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return null;
	}
}

function init(id) {
	this.id = id;
	
	star0 = new Image(20, 20);
	star1 = new Image(20, 20);
	star2 = new Image(20, 20);
	star3 = new Image(20, 20);
	star4 = new Image(20, 20);
	star5 = new Image(20, 20);
	star0.src = '/images/star0.gif';
	star1.src = '/images/star1.gif';
	star2.src = '/images/star2.gif';
	star3.src = '/images/star3.gif';
	star4.src = '/images/star4.gif';
	star5.src = '/images/star5.gif';
	
	show_rate();
}

function show_hits(id) {
	client1 = get_http_object();
	if ( (client1.readyState == 4) || (client1.readyState == 0) ) {
		client1.open('POST', '/game_hits.php');
		client1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		client1.onreadystatechange = handle_hits;
		client1.send('id=' + id);
	}
}

function handle_hits() {
	if ( (client1.readyState == 4) && (client1.status == 200) ) {
		document.getElementById('hits').innerHTML = client1.responseText;
	}
}

function show_series(id) {
	client3 = get_http_object();
	
	if (id > 0) {
		if ( (client3.readyState == 4) || (client3.readyState == 0) ) {
			client3.open('GET', '/cache/database/series/' + id + '.html');
			client3.onreadystatechange = set_series;
			client3.send(null);
		}
	}
}

function set_series() {
	if ( (client3.readyState == 4) && (client3.status == 200) ) {
		document.getElementById('series').innerHTML = client3.responseText;
	}
}

function show_rate() {
	client4 = get_http_object();
	if ( (client4.readyState == 4) || (client4.readyState == 0) ) {
		client4.open('POST', '/game_rate_init.php');
		client4.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		client4.onreadystatechange = handle_rate;
		client4.send('id=' + id);
	}
}

function handle_rate() {
	if ( (client4.readyState == 4) && (client4.status == 200) ) {
		var arr = client4.responseText.split('@');
		document.getElementById('vote').innerHTML = arr[1];
		if (arr[0] == 1) {
			document.getElementById('votebut01').disabled = false;
			document.getElementById('votebut02').disabled = false;
		}
	}
}

function cast_vote(vt) {
	client5 = get_http_object();
	if ( (client5.readyState == 4) || (client5.readyState == 0) ) {
		client5.open('POST', '/game_rate.php');
		client5.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		client5.onreadystatechange = handle_vote;
		client5.send('id=' + id + '&vt=' + vt);
	}
}

function handle_vote() {
	if ( (client5.readyState == 4) && (client5.status == 200) ) {
		if (client5.responseText == 1) {
			show_rate();
		}
	}
}

function show_flash(src, height, width) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + width + '" height="' + height + '">');
	document.write('<param name="movie" value="' + src + '">');
	document.write('<param name="quality" value="high">');
	document.write('<embed src="' + src + '" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '" menu="0"></embed>');
	document.write('</object>');
}

function show_shockwave(src, height, width) {
	document.write('<object classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0" width="' + width + '" height="' + height + '">');
	document.write('<param name="swRemote" value="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'">');
	document.write('<param name="swStretchStyle" value="meet">');
	document.write('<param name="bgColor" value="#000000">');
	document.write('<param name="src" value="' + src + '">');
	document.write('<embed src="' + src + '" width="' + width + '" height="' + height + '" bgColor="#000000" swRemote="swSaveEnabled=\'true\' swVolume=\'true\' swRestart=\'true\' swPausePlay=\'true\' swFastForward=\'true\' swContextMenu=\'true\'" swStretchStyle="meet" type="application/x-director" pluginspage="http://www.macromedia.com/shockwave/download/"></embed>');
	document.write('</object>');
}

function show_frame(src, height, width) {
	document.write('<iframe src="' + src + '" height="' + height + '" width="' + width + '"></iframe>');
}

function show_thumb(title, thumb, src, height, width) {
	document.write('<table cellpadding="3" cellspacing="0"><tr>');
	document.write('<td width="190"><a href="' + src + '" target="_blank"><img src="' + thumb + '" height="135" width="180"></a></td>');
	document.write('<td width="190"><a href="' + src + '" target="_blank"><font size="4">Click here to play<br><strong>' + title + '</strong></a></font></td>');
	document.write('</tr></table>');
	
}