//Global Javascript Functions

home = new Image();
home.src='../btn_home_over.jpg';

inventory=new Image();
inventory.src='../btn_inventory_over.jpg';
	
explore=new Image();
explore.src='../btn_explore_over.jpg';

forum=new Image();
forum.src='../btn_forum_over.jpg';

profile=new Image();
profile.src='../btn_profile_over.jpg';

donate=new Image();
donate.src='../btn_donate_over.jpg';

news=new Image();
news.src='../btn_news_over.jpg';

function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'width=500,height=600,scrollbars=yes');
	return false;
}

login_over = new Image();
login_over.src='../loginbutton_over.jpg';

function popup(mylink, windowname)
{
	if (! window.focus)return true;
	var href;
	if (typeof(mylink) == 'string')
	   href=mylink;
	else
	   href=mylink.href;
	window.open(href, windowname, 'width=500,height=600,scrollbars=yes');
	return false;
}

/* Load JQuery Functions once the entire document is loaded */
$(document).ready(function () {
	


/****************************************************
*******     AJAX user search for userlist     *******
****************************************************/

$(function() 
{
	function format(mail) {
		return mail.name + " &#091;" + mail.id + "&#093;";
	}
	$("#friends").autocomplete("rpc.php", 
	{
		minChars: 1,
		width: 220,
		matchContains: true,
		max: 20,
		selectFirst: false,
		dataType: "json",
		parse: function(data) {
			return $.map(data, function(row) 
			{
				return {
					data: row,
					value: row.name,
					result: row.name + " [" + row.id + "]"
				}
			});
		},
		formatItem: function(item) 
		{
			return format(item);
		},
		formatResult: function(data,value) 
		{
			 return value;
		}
	}).result(function(event, data, formatted) 
	{
		var result = data.id;
		$("#searchcontent").append("<p> * * Sending you to  " + data.name + " [" + data.id + "]\'s profile</p>");
		window.location.href = "viewuser.php?u="+result;
	});
});





/**************************************************
*******     Input Check / error handler     *******
**************************************************/

$(function() 
{
	var chk_qty= $('input[name=qty]');
	var chk_user= $('input[name=userid]');
	
	//Submit the new Form
	$('#submitdata').submit(function() 
	{	
		//Some basic error checking
		if (chk_qty.val()=='') {
            chk_qty.addClass('highlight');
            return false;
        } else {
			chk_qty.removeClass('highlight');
			return true;
		}
		
		if (chk_user.val()=='') {
            chk_user.addClass('highlight');
            return false;
        } else chk_user.removeClass('highlight');
	
		return false;
	});
});




});
