//Global Functions

//Used so the enter key can mimic any link button click
function clickButton(e, btn)
{
	var evt = e ? e : window.event;
	if( evt.keyCode == 13 )
	{
		var b = document.getElementById(btn);
		if( b )
		{
			b.click();
		}
		return false;
	}
}

//Used so the enter key doesn't submit any form
function noSubmit(e)
{
	var evt = e ? e : window.event;
	if( evt.keyCode == 13 )
	{
		return false;
	}
}

//used to allow only numbers entered into the textbox, backspace and enter are allowed.
function numOnly(e)
{
	//different event for keypress
	var charCode = (e.which) ? e.which : event.keyCode
	return (charCode == 8 || charCode == 13 || (charCode >= 48 && charCode <= 57));
}

function setFocus(box)
{
	setTimeout("document.getElementById('" + box + "').focus();",100);
}

function show(id, rel, autohide, left)
{
	var div = document.getElementById(id);
	if( rel )
	{
		div.style.position = "absolute";
		
		if( isIE() )
		{
			div.style.top = getY(rel) + 10 + "px";
		}
		else
		{
			div.style.top = getY(rel) + "px";
		}
		
		if( left )
		{
		    var offset = 209;
		    if(div.style.width)
		    {
		        offset = div.style.width.replace("px","");
		    }
			div.style.left = getX(rel) - offset + "px";
		}
		else
		{
			div.style.left = getX(rel) + rel.offsetWidth + "px";
		}
		
		if( autohide == null || autohide )
		{
			rel.onmouseout = function()
			{
				hide(id);	
			}
		}
	}
	div.style.display = "block";
}

function hide(id)
{
    var rel = document.getElementById(id);
    if( rel )
    {
        rel.style.display = "none";
    }
}

function sendFriendRequest()
{
    alert("This feature coming soon!");
}

function sendMessage()
{
    alert("This feature coming soon!");
}

/* get's the x position of the div obj*/
function getX(obj)
{
	var curleft = 0;

	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}

	return curleft;
}

/* get's the y position of the div obj*/
function getY(obj)
{
	var curtop = 0;

	if(obj.offsetParent)
	{
		while(obj.offsetParent)
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}

	return curtop;
}

function isIE()
{
	return (navigator.appName.toLowerCase().indexOf("explorer") >= 0 );
}

//AJAX -->
//this is a class for AJAX calls.  callBack is a function varible to run after it's done.
//leave callBack null if it is an execute command.
function AJAXCall(url, callBack, async)
{
	this.Request = null;
	
	if( async == null )
	    async = true;
	
	//This is needed to access variables inside a function
	var self = this;
	
	if(window.XMLHttpRequest)
		this.Request = new XMLHttpRequest();
	else if(window.ActiveXObject)
		this.Request = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return false;
				
	//true for async..
	this.Request.open("POST",url,async);
	
	this.Request.onreadystatechange = function()
	{
		if( self.Request.readyState == 4 )
		{
			if( self.Request.status==200 )
			{
				self.Out(self.Request.responseText);
			}
			else
			{
				//display the error here
				//alert("Error " + request.status);
			}
		}
			
	}

	this.Request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	this.Request.send("");
	
	if( callBack )
	{
		this.Out = callBack;
	}
	else
	{
		this.Out = function(text)
		{
			return;	
		}
	}
}
// --> End AJAX