// This clicks on the image with the link to (link + '.html')
// 'link' has the form 'link-y'. This assumes that the gCurrTab is correctly set.
//		links are 0-based
function LoadLink( link )
{	
	// Remove the selected border from the currently selected item
	$(".items img").removeClass( "selectedborder" );
	
	// Add the border to the newly selected item
	//		sidebars ahve the form 'sidebar_Tab-X_2'
	var linkIndex = link.split( '-' )[1];

	$('#sidebar_' + gCurrTab + '_' + linkIndex ).addClass( "selectedborder" );			
	
	// Get handle to element that wraps the image and make it semi-transparent
	var wrap = $("#main_" + gCurrTab).fadeTo( "medium", 0.5 );
	
	// This will not propagate because gCurrLink is already set to this link
//alert( '#sidebar_' + gCurrTab + '_' + linkIndex  );
	$('#sidebar_' + gCurrTab + '_' + linkIndex ).click();
}

// 'tab' has the form 'Tab-x'; tabs are 0-based.
function LoadTab( tab )
{
	var first = tab.indexOf( '-' );
	var index = tab.slice( first + 1 );
	var api = $("ul.tabs").tabs();
	api.click( index );
}

function ClickLink( link )
{
	location.hash = link;
}

function ClickLinkPath( linkPath )
{
	var link = gTabs.FindLink( linkPath );
	
	if( link != -1 )
		location.hash = '#' + link;
}

function BadEntry( noteId )
{
	$('#' + noteId).html( '<strong><em>We\'re sorry. The username and password given are not in our database. Both are case-sensitive. Please try again.</em></strong>' );
}

// ***** Cookies ******/
// Sets value in a cookie; For detailed info see: http://www.quirksmode.org/js/cookies.html
//	cookieName and cookieValue are the name and value for the name:value pair for this particular cookie. The name and value should be unescaped (ie., clean)
//	If you set no expiration date on a cookie, it expires when the browser closes. If you set an expiration date, the cookie is saved across browser sessions. If you set an expiration date in the past, the cookie is deleted. Use Greenwich Mean Time (GMT) format to specify the date.
//	Each cookie also has a domain and a path. The domain tells the browser to which domain the cookie should be sent. If you don't specify it, it becomes the domain of the page that sets the cookie. the purpose of the domain is to allow cookies to cross sub-domains.
// The path gives you the chance to specify a directory where the cookie is active. So if you want the cookie to be only sent to pages in the directory cgi-bin, set the path to /cgi-bin. Usually the path is set to /, which means the cookie is valid throughout the entire domain.
// If you set a cookie as secure, the stored cookie information can be accessed only from Secure Hypertext Transfer Protocol (HTTPS).
function SetCookie( cookieName, cookieValue, expires, path, domain, secure ) 
{
	var cookieText = escape(cookieName) + '=' + escape(cookieValue)
	+ (expires ? '; expires=' + expires.toGMTString() : '')
	+ (path ? '; path=' + path : '')
	+ (domain ? '; domain=' + domain : '')
	+ (secure ? '; secure' : '');
	
	document.cookie = cookieText;
};

// Gets a value from a cookie. Form is cookieName:cookieValue;
//		The name and the value have been escaped.
function GetCookie( cookieName ) 
{
	// This gets the cookie with cookieName
	var savedName = escape( cookieName );
	var posName = document.cookie.indexOf( savedName + '=');
	if (posName != -1) 
	{
		// We have located the cookie. Now get its value
		var posValue = posName + ( savedName + '=' ).length;
		var endPos = document.cookie.indexOf(';', posValue);
		if (endPos != -1) 
			value = unescape( document.cookie.substring( posValue, endPos ) );
		else 
			value = unescape( document.cookie.substring( posValue ) );
	}
	
	return (value);
};

function ClearCookie( cookieName )
{
	var now = new Date();
	var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);	
	SetCookie( cookieName, 'noValue', yesterday );	
}

