function init() 
{   
rollovers();

} 

function isObject( variable )
{
	return ( typeof variable == 'object' );
}

function isObj( variable )
{
	return isObject(variable);
}

function isValidObject( variable )
{
	return ( isObject(variable) && !isNull(variable) );	
}

function isValidObj( variable )
{
	return isValidObject(variable);
}

function isNull( variable )
{
	return ( variable == null );
}

function isString( variable )
{
	return ( typeof variable == 'string' );
}

function isValidString( variable )
{
	return ( typeof variable == 'string' && variable.length > 0 );
}

function isArray( variable )
{
	return ( typeof variable == 'array' );
}

function isUndefined( variable )
{
	return ( typeof variable == 'undefined' );
}

function isDefined( variable )
{
	return ( typeof variable != 'undefined');
}

function isNumber( variable )
{
	return ( typeof variable == 'number' );
}

function isFunction( variable )
{
	return ( typeof variable == 'function' );
}

function isWholeNumber( variable )
{
	return ( isNumber(variable) && ( parseInt(variable) == parseFloat(variable) ) );
}

function isValidColor( variable )
{
	// Check by length and range of characters (zero or one leading #, 0-f)
	if( variable.length < 3 )//|| variable.length > 7 || variable.length == 5 )
		return false;
	
	validChars = '0123456789ABCDEF';
	variable = variable.toUpperCase();
	
	// Loop through each character, and if an invalid one is found, return false
	for( i = 0; i < variable.length; i++ )
	{
		// A # at position 1 is allowed
		if( i == 0 && variable.charAt(i) == '#' )
			continue;
		
		// If this character is invalid, so is the entire color
		if( validChars.indexOf(variable.charAt(i)) < 0 )
		{
			return false;
		}
	}
	
	return true;
}



// Browser detect stuff 
var nAV = navigator.appVersion.toLowerCase();
var nUA = navigator.userAgent.toLowerCase();
var nP = navigator.platform.toLowerCase();
var isIE = nAV.indexOf('msie')!=-1;
var isIE6 = (nAV.indexOf('msie 6')!=-1 || nAV.indexOf('msie 5')!=-1);
var isIE7 = (nAV.indexOf('msie 7')!=-1);
var isFirefox = (nUA.indexOf('firefox')!=-1);
var isOpera = (nUA.indexOf('opera')!=-1);
var isSafari = (nUA.indexOf('safari')!=-1);
var isWin32 = (nP.indexOf('win')!=-1);
var isMac = (nP.indexOf('mac')!=-1);
if (isOpera) {
  isIE = false;
  isIE6 = false;
  isIE7 = false;
}

function $(sID) 
{
  // If the object does not exist, alert us so that we can fix the
  // code that is using an invalid call to the prototype
  oPrototyped = getObj(sID);
  if( !isValidObject(oPrototyped) )
  	alert( 'Tried to call JavaScript prototyped function "' + sID + '"' );
  
  return oPrototyped;
  //return document.getElementById(sID);
}



function swapShow( e1, e2 )
{
	if( document.getElementById( e1 ).style.display == 'none' )
	{
		document.getElementById( e1 ).style.display='';
		document.getElementById( e2 ).style.display='none';
	}
	else
	{
		document.getElementById( e1 ).style.display='none';
		document.getElementById( e2 ).style.display='';
	}
}



/*
 * Sets the style class for an element
 *
 * @param	Object;	The object to change the class for
 * @param	String;	The classname to set
 * @return	VOID
 */
function setClass( oElement, sClassname )
{
	if( !isValidObject(oElement) || !isString(sClassname) || sClassname.length < 1 )
		return null;
		
	oElement.className = sClassname;	
}


/*
 * Returns an object if one is found with the id
 * passed in the parameters
 *
 * @param	String;	Object ID
 * @return	Object;	Returns the object found, if any
 */
function getObj( elementID )
{
	
	if( !isString(elementID) || elementID.length < 1 )
		return null

	// First use getElementById
	theObj = document.getElementById(elementID);
	//theObj = eval( 'document.getElementById("' + elementID + '")' );
	
	if(document.getElementById(elementID))
		theObj = eval( 'document.getElementById("' + elementID + '")' );
	//else
		//alert("Missing Obj on page: " +elementID);
	
	// If an object wasn't found, try using getElementByName, if available
	if( !isValidObject(theObj) && isFunction(document.getElementsByName) )
	{
		theObj = document.getElementsByName(elementID);
		
		// If theObj.length is 0, then it is not actually a valid object
		if( theObj.length == 0 )
			theObj = null;
	}
	
	if( isValidObject(theObj) )
		return theObj;
	else
		return null;		
	
}

/* alias of 'getObj' */
function getO( elementID ) { return getObj( elementID ); }


/*
 * Creates a copy of an object (oFromObject) and returns
 * a new object with those properties.
 */
function getObjectCopy( oFromObject )
{
	oToObject = oFromObject;

	return oToObject;
}

// This string prototype allows you to append .trim() to any string to trim the value
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

function display_big_hilite()
{
	getObj("hilite_left").innerHTML="<IMG SRC='images/layout/footer_big_hl_left.png' HSPACE=0 VSPACE=0 STYLE='padding-left: 4px;'>";
	getObj("hilite_right").innerHTML="<IMG SRC='images/layout/footer_big_hl_right.png' HSPACE=0 VSPACE=0>";
	getObj("big_hilite").style.display=""; 
	getObj("short_hl").style.display="none";
	
}

function hide_big_hilite()
{
	getObj("big_hilite").style.display="none"; 
	getObj("short_hl").style.display="";	
	getObj("hilite_left").innerHTML="<IMG SRC='images/layout/footer_hilite_left.gif' HSPACE=0 VSPACE=0 STYLE='padding-left: 4px;'>";
	getObj("hilite_right").innerHTML="<IMG SRC='images/layout/footer_hilite_right.gif' HSPACE=0 VSPACE=0>";
}

function expandCloseInvite()
{
	// First figure out if it's currently expanded or not based on which chevron graphic is in the span	
	// Check for presence of the expanded invite first
	if(getObj('invite_chevron').innerHTML.indexOf("down") != -1)
	{
		getObj('invite_chevron').innerHTML = "<IMG SRC='images/layout/chevron.gif' BORDER=0 WIDTH='16' HEIGHT='16' VSPACE=1 />";
	}
	else
	{
		getObj('invite_chevron').innerHTML = "<IMG SRC='images/layout/chevron_down.gif' BORDER=0  WIDTH='16' HEIGHT='16' VSPACE=1 />";
	}
	
}

function sendInviteMessage()
{
	emailInviteObj = getObj('invite_email');
	if(getObj('optional_invite_message'))
		user_msg = getObj('optional_invite_message').value
	else
		user_msg = "";
	if(getObj('additional_invites'))
		additional_invite_emails = getObj('additional_invites').value
	else
		additional_invite_emails = "";	
	
	if(emailInviteObj == null)
	{
		alert("Unable to invite user");
		return false;
	}
	else if(emailInviteObj.value.trim().length == 0)
	{
		alert("Please enter the email address of someone you would like to invite.");
		return false	
	}
	else
		email = emailInviteObj.value;
	
	AjaxRequest.post(	
		{
			'url':'/exchange/background.html',
			'parameters':{ 'email_address':email, 'additional_invite_emails':additional_invite_emails,
						 'user_message':user_msg, 'send_user_invite':true },
			'onSuccess': function(oResponse)
					 {
					 	// reduce the number of remaining invites by 1
					 	emailInviteObj.value = "";
					 	remaining_invites = Number(getObj('invites_remaining_count').innerHTML)-Number(oResponse.responseText);
					 	getObj('invites_remaining_count').innerHTML = getObj('invites_remaining_count2').innerHTML = remaining_invites;
					 	if(remaining_invites == 0)
					 		getObj('invite_area').innerHTML = "<SPAN ID='invite_sent'>Invitation Sent</SPAN><BR />"+
					 							"0 invites remaining. <BR />Use the network a bit and some more invites will show up";
					 	getObj('invite_sent').innerHTML = getObj('invite_sent2').innerHTML =  "Invitation Sent!";
					 	setTimeout('resetInviteSentConfirm()',5000);
					 },
			'onError': function(oResponse)
					 {
					 	alert("Unable to send invite");
					 }
		} 
	);

}

function openInvitePreview(email)
{
	getObj('invite_first_email').innerHTML = email;
	getObj('org_invite').style.display='none';
	getObj('previewInvite').style.display='';
}

function showPreviewLink()
{
	if(getObj('invite_sent').innerHTML.indexOf("preview invite") == -1)
		getObj('invite_sent').innerHTML = "<A HREF='' onClick='openInvitePreview(getObj(\"invite_email\").value); "+
						"return false;'>preview invite</A>";
}

function resetInviteSentConfirm()
{
	getObj('invite_sent').innerHTML = "";
	getObj('invite_sent2').innerHTML = "";
	getObj('org_invite').style.display='';
	getObj('previewInvite').style.display='none';
	getObj('additional_invites').value = "";
}