var id, client1, client2, client3, client4, client5;

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;
	document.getElementById("commentbutton").disabled = false;
	document.getElementById("commentbutton").childNodes[0].nodeValue = 'Add Comment';
}

function show_hits(id) {
	setTimeout("show_hits2(" + id + ")", 1000);
}

function show_hits2(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 = set_hits;
		client1.send('id=' + id);
	}
}

function set_hits() {
	if (client1.readyState == 4) {
		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) {
		document.getElementById('series').innerHTML = client3.responseText;
	}
}

function show_comments(id, page) {
	document.getElementById("commentbutton").childNodes[0].nodeValue = 'Please wait';
	
	client4 = get_http_object();
	
	if ( (client4.readyState == 4) || (client4.readyState == 0) ) {
		client4.open('POST', '/game_comments.php');
		client4.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		client4.onreadystatechange = set_comments;
		client4.send('id=' + id + '&page=' + page);
	}
}

function set_comments() {
	if (client4.readyState == 4) {
		document.getElementById('comments').innerHTML = client4.responseText;
		document.getElementById("commentbutton").childNodes[0].nodeValue = 'Add Comment';
	}
}

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('<param name="WMode" value="transparent">');
	document.write('<embed src="' + src + '" width="' + width + '" height="' + height + '" bgColor="#000000" WMode="transparent" 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="260"><a href="' + src + '" target="_blank"><img src="' + thumb + '" height="188" width="250"></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>');
	
}

function show_flashvote(flashvars) {
	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="600" height="70">');
	document.write('<param name="movie" value="/vote.swf">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="flashVars" value="' + flashvars + '">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="/vote.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="600" height="70" menu="0" flashVars="' + flashvars + '"></embed>');
	document.write('</object>');
}

function add_comments() {
	client5 = get_http_object();
	
	if ( (client5.readyState == 4) || (client5.readyState == 0) ) {
		document.getElementById("commentbutton").disabled = true;
		document.getElementById("commentbutton").childNodes[0].nodeValue = 'Please wait';
		
		var textcomment = document.getElementById('textcomment').value;
		var usercomment = document.getElementById('usercomment').value;
		var textcolor = document.getElementById('textcolor').value;
		var linecolor = document.getElementById('linecolor').value;
		var linestyle = document.getElementById('linestyle').value;
		var usercolor = document.getElementById('usercolor').value;
		
		client5.open('POST', '/game_comment_add.php');
		client5.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		client5.onreadystatechange = add_handler;
		client5.send('id=' + id + '&user=' + usercomment + '&text=' + textcomment + '&fgcolor=' + textcolor + '&bdcolor=' + linecolor + '&bdstyle=' + linestyle + '&fncolor=' + usercolor);
	}
}

function add_handler() {
	if (client5.readyState == 4) {
		switch (client5.responseText) {
		case '1':
			alert('Name and comment text required');
			break;
		case '2':
		case '4':
			alert('Comment disallowed');
			break;
		default:
			document.getElementById('textcomment').value = '';
			show_comments(id, 1);
		}
		document.getElementById("commentbutton").disabled = false;
		document.getElementById("commentbutton").childNodes[0].nodeValue = 'Add Comment';
	}
}