
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>');
	
}

function copyit(theField) {
var tempval=eval('document.'+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand('Copy')
}

















var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

function showgame()
{
     var el = document.getElementById('gamediv');
     var ela = document.getElementById('adsdiv');
     ela.style.display = 'none';
     el.style.display = 'block';

}

charCount = 1;
maxCharCount = 2000;

function displayRemLength(fieldName) {
	remField = document.getElementById(fieldName);
	remField.innerHTML = (maxCharCount - charCount > 0) ? maxCharCount - charCount : 0;
}

function evalEntryLength(curField, maxLimit, discardXtra, errClass, normalClass) {
	maxCharCount = maxLimit;
	var fieldLength = getCharCount(curField);
	
	if (fieldLength > maxLimit) {
		if (errClass != "") {
			curField.className = errClass;
		}
		if (discardXtra) {
			showAllowedLength(curField, maxLimit);
		}
	} else if (normalClass != "") {
		curField.className = normalClass;
	}
}

function getCharCount(curField) {
	charCount = curField.value.length;
	
	return charCount;
}

function showAllowedLength(curField, maxLimit) {
	curField.value = curField.value.substr(0, maxLimit);
	window.status = curField.value;
	}
