
var xmlhttp;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false;
  }
 }
@else
 xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttp = new XMLHttpRequest();
 } catch (e) {
  xmlhttp=false;
 }
}
function myXMLHttpRequest() {
  var xmlhttplocal;
  try {
    xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
    xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
    xmlhttplocal=false;
  }
 }

if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
 try {
  xmlhttplocal = new XMLHttpRequest();
 } catch (r) {
  xmlhttplocal=false;
  alert('couldn\'t create xmlhttp object');
 }
}
return(xmlhttplocal);
}

function changeText( div2show, text ) {
    // Detect Browser
    var IE = (document.all) ? 1 : 0;
    var DOM = 0; 
	
    if (parseInt(navigator.appVersion, navigator.appVersion) >=5) 
	{
		DOM=1;
	}

    // Grab the content from the requested "div" and show it in the "container"

    if (DOM) {
        var viewer = document.getElementById(div2show);
        viewer.innerHTML=text;
    }
    else if(IE) {
        document.all[div2show].innerHTML=text;
    }
}

function handleResponse() {
    if(xmlhttp.readyState == 4){
		if (xmlhttp.status == 200){
        var response = xmlhttp.responseText;
        var update = [];
        if(response.indexOf('|') != -1) {
            update = response.split('|');
            changeText(update[0], update[1]);
        }
		}
    }
}

function sndRequest(vote,id_num,ip_num) {
	
	var element = document.getElementById('unit_long'+id_num);
	//new Effect.Fade(element);
    element.innerHTML = '<div style="height: 20px;"><em>Loading ...</em></div>';
	
    xmlhttp.open('get', 'ajax_user_rating.php?j='+vote+'&q='+id_num+'&t='+ip_num);
    xmlhttp.onreadystatechange = handleResponse;
    xmlhttp.send(null);
	
}

/**
 * Dynamic Rating stars
 * @copyright 2006 Beau D. Scott http://beauscott.com
 * @
 */

var Stars = Class.create();
Stars.prototype = {
	/**
	 * Mouse X position
	 * @var {Number} options
	 */
	_x: 0,
	/**
	 * Mouse X position
	 * @var {Number} options
	 */
	_y: 0,
	/**
	 * Constructor
	 * @param {Object} options
	 */
	initialize: function(options)
	{

		/**
		 * Initialized?
		 * @var (Boolean)
		 */
		this._initialized = false;

		/**
		 * Base option values
		 * @var (Object)
		 */
		this.options = {
			bindField: null,			// Form Field to bind the value to
			maxRating: 5,				// Maximum rating, determines number of stars
			container: null,			// Container of stars
			imagePath: 'images/',		// Path to star images
			callback: null,				// Callback function, fires when the stars are clicked
			actionURL: null,			// URL to call when clicked. The rating will be appended to the end of the URL (eg: /rate.php?id=5&rating=)
			value: 0,					// Initial Value
			locked: false
		};
		Object.extend(this.options, options);
		this.locked = this.options.locked ? true : false;
		/**
		 * Image sources for hover and user-set state ratings
		 */
		this._starSrc = {
			empty: this.options.imagePath + "star-empty.gif",
			full: this.options.imagePath + "star.gif",
			half: this.options.imagePath + "star-half.gif"
		};
		/**
		 * Preload images
		 */
		 
			for(var x in this._starSrc)
			{
				if(this._starSrc[x] != '')
				{
					var y = new Image();
					y.src = this._starSrc[x];
				}
			}
		
			//document.getElem

		/**
		 * Images to show for pre-set values, changes when hovered, if not locked.
		 */
		this._setStarSrc = {
			empty: this.options.imagePath + "star-empty.gif",
			full: this.options.imagePath + "star-ps.gif",
			half: this.options.imagePath + "star-ps-half.gif"
		};

		/**
		 * Preload images
		 */
		for(var z in this._setStarSrc)
		{
			if(this._setStarSrc[z] != '')
			{
				var k = new Image();
				k.src = this._setStarSrc[z];
			}
		}

		this.value = -1;
		this.stars = [];
		this._clicked = false;


		if(this.options.container)
		{
			this._container = $(this.options.container);
			this.id = this._container.id;
		}
		else
		{
			this.id = 'starsContainer.' + Math.random(0, 100000);
			document.write('<span id="' + this.id + '"></span>');
			this._container = $(this.id);
		}
		this._display();
		this.setValue(this.options.value);
		this._initialized = true;
	},
	_display: function()
	{
		var star = null;
		for(var i = 0; i < this.options.maxRating; i++)
		{
			star = null;
			star = new Image();
			star.src = this.locked ? this._starSrc.empty : this._setStarSrc.empty;
			star.style.cursor = 'pointer';
			star.title = 'Rate as ' + (i + 1);
			!this.locked && Event.observe(star, 'mouseover', this._starHover.bind(this));
			!this.locked && Event.observe(star, 'click', this._starClick.bind(this));
			!this.locked && Event.observe(star, 'mouseout', this._starClear.bind(this));
			this.stars.push(star);
			this._container.appendChild(star);
		}
	},
	_starHover: function(e)
	{
		if(this.locked) 
		{
			return;
		}
		if(!e)
		{
			 e = window.event;
		}
		var star = Event.element(e);

		var greater = false;
		for(var i = 0; i < this.stars.length; i++)
		{
			this.stars[i].src = greater ? this._starSrc.empty : this._starSrc.full;
			if(this.stars[i] == star)
			{
				greater = true;
			}
		}
	},
	_starClick: function(e)
	{
		if(this.locked) 
		{
			return;
		}
		
		if(!e)
		{
			e = window.event;
		}
		var star = Event.element(e);
		this._clicked = true;
		for(var i = 0; i < this.stars.length; i++)
		{
			if(this.stars[i] == star)
			{
				this.setValue(i+1);
				break;
			}
		}
	},
	_starClear: function(e)
	{
		if(this.locked && this._initialized) 
		{
			return;
		}
		var greater = false;
		for(var i = 0; i < this.stars.length; i++)
		{
			if(i > this.value)
			{
				greater = true;
			}
			if((this._initialized && this._clicked) || this.value == -1)
			{
				this.stars[i].src = greater ? (this.value + .5 == i) ? this._starSrc.half : this._starSrc.empty : this._starSrc.full;
			} else {
				this.stars[i].src = greater ? (this.value + .5 == i) ? this._setStarSrc.half : this._setStarSrc.empty : this._setStarSrc.full;
			}
		}
	},
	/**
	 * Sets the value of the star object, redraws the UI
	 * @param {Number} value to set
	 * @param {Boolean} optional, do the callback function, default true
	 */
	setValue: function(val)
	{
		var doCallBack = arguments.length > 1 ? !!arguments[1] : true;
		if(this.locked && this._initialized) 
		{
			return;
		}
		this.value = val-1; //0-based
		if(this.options.bindField)
		{
			$(this.options.bindField).value = val;
		}
		
		if(this._initialized && doCallBack)
		{
			if(this.options.actionURL)
			{
				new Ajax.Request(this.options.actionURL + val, {onComplete: this.options['callback'], method: 'get'});
			} else {
				if(this.options.callback)
				{
					this.options['callback'](val);
				}
			}
		}
		this._starClear();
	}
};


/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/
var contents_temp;
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		//contents_temp = document.getElementById("contents").innerHTML;
		
		o.onmousedown	= Drag.start;
		
		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;
		
		
		o.root = oRoot && oRoot !== null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		//document.getElementById("contents").style.visibility = 'hidden';
		
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX !== null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX !== null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX !== null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX !== null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY !== null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY !== null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY !== null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY !== null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;
		
		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;
		
		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX !== null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX !== null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY !== null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY !== null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		//document.getElementById("contents").style.visibility = 'visible';
		
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

////////////////////////////////////////////////////////////////////////////////////
function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
	var cookie_string = name + "=" + escape(value);

	if (exp_y)
	{
		var expires = new Date(exp_y, exp_m, exp_d);
		cookie_string += "; expires=" + expires.toGMTString();
	}

	if (path)
	{
		cookie_string += "; path=" + escape ( path );
	}
	else
	{
		cookie_string += "; path=/";
	}

	if (domain)
	{
		cookie_string += "; domain=" + escape ( domain );
	}

	if (secure)
	{
		cookie_string += "; secure";
	}

	document.cookie = cookie_string;
}

////////////////////////////////////////////////////////////////////////////////////
function get_cookie(cookie_name)
{
	var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

	if (results)
	{
		return (unescape(results[2]));
	}
	else
	{
		return null;
	}
}

////////////////////////////////////////////////////////////////////////////////////

var tmp_div_chat_body;

////////////////////////////////////////////////////////////////////////////////////
function minmax_click()
{
	var test = get_cookie("minmaxcls");
	
	switch (test)
	{
		case "maximise":
			document.getElementById("div_chat_body").style.visibility = "hidden";
			document.getElementById("img_minmax").src = "/images/maximise.jpg";
			
			var _height = get_screen_size("height");
			var _width = get_screen_size("width");
			var _top = (_height - 35) + "px";
			if ((_width - 1100) > 0)
			{
				//var _left = ((_width - 1100) / 2) + "px";
				var _left = "1px";
			}
			else
			{
				var _left = "1px";
			}
			var minmaxcls = "minimise";
		break;
		
		default:
			document.getElementById("div_chat_body").style.visibility = "visible";
			document.getElementById("img_minmax").src = "/images/minimise.jpg";
			var _height = get_screen_size("height");
			var _width = get_screen_size("width");
			//var _top = ((_height - 630) / 2) + "px";
			var _top = "1px";
			var _left = "1px";
			//var _left = ((_width - 374) / 2) + "px";
			var minmaxcls = "maximise";
		break;
	}
	set_cookie ("minmaxcls", minmaxcls);
	set_cookie ("top", _top);
	set_cookie ("left", _left);
	
	document.getElementById("root").style.top = _top;
	document.getElementById("root").style.left = _left;
}

////////////////////////////////////////////////////////////////////////////////////
function get_screen_size(width_height)
{
	var myWidth = 0;
	var myHeight = 0;
	
	if (typeof( window.innerWidth ) == 'number')
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	if (width_height == "width")
	{
		//window.alert( 'Width = ' + myWidth );
		return myWidth;
	}
	else
	{
		//window.alert( 'Height = ' + myHeight );
		return myHeight;
	}
}

////////////////////////////////////////////////////////////////////////////////////
function open_chat()
{
	var _height = get_screen_size("height");
	var _width = get_screen_size("width");
	var _top = "1px";
	var _left = "1px";
	//var _top = ((_height - 630) / 2) + "px";
	//var _left = ((_width - 374) / 2) + "px";
	
	set_cookie ("minmaxcls", "maximise");
	set_cookie ("top", _top);
	set_cookie ("left", _left);
	
	document.getElementById("root").innerHTML = "<p align='center'><img src='/images/ajax-loader-scores.gif' /></p>";
	new Ajax.Updater
	(
		'root',
		'/ajax-showchat.php',
		{
			asynchronous:true,
			method:'get',
			encoding:'UTF-8',
			evalScripts:true
		}
	);
	
	//document.getElementById("div_chat_body").style.visibility = "visible";
	//document.getElementById("img_minmax").src = "/images/minimise.jpg";
	document.getElementById("root").style.top = _top;
	document.getElementById("root").style.left = _left;
}

////////////////////////////////////////////////////////////////////////////////////
function close_chat()
{
	set_cookie ("minmaxcls", "close");
	set_cookie ("top", "1");
	set_cookie ("left", "1");
	document.getElementById("root").innerHTML = "";
}

////////////////////////////////////////////////////////////////////////////////////

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser does not support AJAX!");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

var redirect = false;

//Called from keyup on the search textbox.
//Starts the AJAX request.
function searchSuggest() {
	if (searchReq.readyState == 4 || searchReq.readyState == 0) {
		var str = escape(document.getElementById('s').value);
		var ss = document.getElementById('search_suggest')
		ss.style.display = 'block';
		searchReq.open("GET", 'ajax_search_suggest.php?search=' + str, true);
		searchReq.onreadystatechange = handleSearchSuggest; 
		searchReq.send(null);
	}		
}

//Called when the AJAX response is returned.
function handleSearchSuggest() {
	if (searchReq.readyState == 4) {
		var ss = document.getElementById('search_suggest')
		ss.innerHTML = '';

		var str = searchReq.responseText.split("|\n|");
		
		for(i=0; i < str.length - 1; i++) {
			//Build our element string.  This is cleaner using the DOM, but
			//IE doesn't support dynamically added attributes.
			var suggest = '<div onmouseover="javascript:suggestOver(this);" ';
			suggest += 'onmouseout="javascript:suggestOut(this);" ';
			suggest += 'onclick="javascript:setSearch(' + i + ');" ';
			suggest += 'class="suggest_link">' + str[i] + '</div>';
			if(i != str.length - 1)
			{
				//suggest += '<hr />';
			}
			ss.innerHTML += suggest;
		}
		
		if(document.getElementById('suggest_0').value == 'N')
		{
			ss.innerHTML = '';
		}
	}
}

//Mouse over function
function suggestOver(div_value) {
	div_value.className = 'suggest_link_over';
}
//Mouse out function
function suggestOut(div_value) {
	div_value.className = 'suggest_link';
}

//Click function
function setSearch(id) 
{
	redirect = true;
	//document.getElementById('s').value = document.getElementById('suggest_' + id).value;
	game_id = document.getElementById('suggest_id_' + id).value;
	game_name = document.getElementById('suggest_' + id).value;
	window.location = 'index.php?gameid=' + game_id + '&game=' + game_id + '&game_name=' + game_name;
	document.getElementById('search_suggest').innerHTML = '';
	document.getElementById('search_suggest').style.display = 'none';
}

//Blur function
function removeSearch() 
{	
	document.getElementById('search_suggest').innerHTML = '';
	document.getElementById('search_suggest').style.display = 'none';
}



//////////////////////////////////////////////////////////////////////////////////////
function popUp(URL)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=1020,height=620,left = 595,top = 312.5');");
}

//////////////////////////////////////////////////////////////////////////////////////
function body_onload()
{
	var categoryLists = document.getElementsByClassName("category-list");

	for (var i = 0; i < categoryLists.length; i++) 
	{
		if (categoryLists[i].className != "category-list default") 
		{
			categoryLists[i].style.display = 'none';
		}
	}
}

//////////////////////////////////////////////////////////////////////////////////////
function typeToggle(elementId) 
{
	var element = document.getElementById(elementId);
	
	if (element.style.display == "none") 
	{
		Effect.SlideDown(elementId);
	} else {
		Effect.SlideUp(elementId);
	}
}

//////////////////////////////////////////////////////////////////////////////////////

var ajaxComplete = false;

function showCategories(id)
{
	ajaxImage = new Image();
	ajaxImage.src = 'http://www./images/ajax-loader.gif';


	var div = document.getElementById(id);
	
	if(ajaxComplete)
	{
		typeToggle(id);
	} else {
		
		document.getElementById(id).innerHTML = "<p align='center'><img src='http://www./images/ajax-loader.gif' align='center' /><font color='#FFFFFF'>Loading Menu. Please wait...</font></p>";
		new Ajax.Updater
		(
			id,
			'http://www./ajax-category-list.php',
			{ 
				asynchronous:true,
				method:'get',
				encoding:'UTF-8',
				parameters:'',
				evalScripts:true,
				onComplete:function()
				{
					new Effect.SlideDown(id);
					
					ajaxComplete = true;
				}
			}
		);
	}
}
//////////////////////////////////////////////////////////////////////////////////////
function setView(Alink)
{
	if(Alink.innerHTML == "View More")
	{
		Alink.innerHTML = "View Less"
	} else {
		Alink.innerHTML = "View More"
	}
}

//////////////////////////////////////////////////////////////////////////////////////
function setViews(Alink, text)
{
	if(text == 'expand')
	{
		if(Alink.innerHTML == "Click to expand")
		{
			Alink.innerHTML = "Close&nbsp;"
		} else {
			Alink.innerHTML = "Click to expand"
		}
	} else {
		if(Alink.innerHTML == "View More")
		{
			Alink.innerHTML = "View Less&nbsp;"
		} else {
			Alink.innerHTML = "View More"
		}
	}
}
//////////////////////////////////////////////////////////////////////////////////////

function setFriendRequest(text)
{
	if(document.getElementById('add_friend'))
	{
		document.getElementById('add_friend').innerHTML = text;
	}
}

function setFriendRequestStatus(text)
{
	if(document.getElementById(text.substring(text.indexOf('-')+1)))
	{
		document.getElementById(text.substring(text.indexOf('-')+1)).innerHTML = text.substring(0, text.indexOf('-'));
	}
}

function get_twitter_details()
{
	var twitter = document.getElementById('twitter_user');
	
	if(twitter.style.display == 'block')
	{
		twitter.style.display = 'none';
	} else {
		twitter.style.display = 'block';
	}
}

function twitter_settings(box)
{
	if(box.checked == true)
	{
		document.getElementById('twitter-post').checked = false;
		document.getElementById('twitter-status').checked = false;
		document.getElementById('twitter-post').disabled = true;
		document.getElementById('twitter-status').disabled = true;
	} else {
		document.getElementById('twitter-post').disabled = false;
		document.getElementById('twitter-status').disabled = false;
	}
}

function set_twitter_update(text)
{
	document.getElementById('twitter_status').innerHTML = text;
	
	if(document.getElementById('twitter_loading'))
	{
		var loader = document.getElementById('twitter_loading');
		loader.style.display = 'none';
	}
	
	if(document.getElementById('twitter_status_update'))
	{
		var textbox = document.getElementById('twitter_status_update');
		textbox.value = '';
	}
}
//////////////////////////////////////////////////////////////////////////////////////


function select_messages(type, num)
{
	
	for(i = 0; i <= num; i++)
	{
		switch(type)
		{
			case 'all':
				if($('messageRead' + i))
				{
					$('messageRead' + i).checked = true;
				}
				
				if($('messageView' + i))
				{
					$('messageView' + i).checked = true;
				}
			break;
			
			case 'read':
				if($('messageView' + i))
				{
					$('messageView' + i).checked = true;
				}
				
				if($('messageRead' + i))
				{
					$('messageRead' + i).checked = false;
				}
			break;
			
			case 'unread':
				if($('messageView' + i))
				{
					$('messageView' + i).checked = false;
				}
				
				if($('messageRead' + i))
				{
					$('messageRead' + i).checked = true;
				}
			break;
			
			case 'none':
				if($('messageView' + i))
				{
					$('messageView' + i).checked = false;
				}
				
				if($('messageRead' + i))
				{
					$('messageRead' + i).checked = false;
				}
			break;
		}
	}
}

function mark_messages(type, num)
{
	
	confirmation = true;
		
	if(type == 'delete')
	{
		confirmation = confirm('Are you sure you want to delete the selected messages?');
	}
		
	for(i = 0; i <= num; i++)
	{	
		if($('messageView' + i))
		{
			if($('messageView' + i).checked == true)
			{
				var id = $('messageView' + i).value;
			} else {
				id = '';
			}
		}
				
		if($('messageRead' + i))
		{
			if($('messageRead' + i).checked == true)
			{
				var id = $('messageRead' + i).value;
			} else {
				id = '';
			}
		}
		
		if(confirmation && id != '')
		{
			new Ajax.Updater
			(
				'messages_id',
				'/ajax-mark-message.php',
				{
					//onComplete: Effect.Appear('scores'),
					asynchronous:true,
					method:'get',
					encoding:'UTF-8',
					parameters:'mark=' + type + '&id=' + id,
					evalScripts:true
				}
			);
		}
		
		if(type == 'delete' && id != '' && confirmation)
		{
			if($('messageRead' + i) && $('messageRead' + i).checked == true)
			{
				new Effect.Fade('message' + i);
			} else if($('messageView' + i) && $('messageView' + i).checked == true)
			{
				new Effect.Fade('message' + i);
			}
		}
	}
}
