var	gJustAnotherId = 0;

function getAnotherId()
	{
		gJustAnotherId++;
		return gJustAnotherId;
	}

function domainEmailAddress( who )
	{
		var	address = who + "@" + gSite_Domain;
		document.write( "<a href='mailto:" + address + "'>" + address + "</a>" );
	}

function confirmLink(theLink, theMessage )
	{
    var isConfirmed = confirm( theMessage );
    if (isConfirmed) 
    	{
        theLink.href += '&isConfirmed=yes';
    	}
    return isConfirmed;
	}

function strltrim( str )
	{
		//Match spaces at beginning of text and replace with a null string
		if( null != str )
			return str.replace(/^\s+/,'');
		return null;
	}


function strrtrim( str )
	{
		//Match spaces at end of text and replace with a null string
		if( null != str )
			return str.replace(/\s+$/,'');
		return null;
	}


function strtrim( str )
	{
		//Match spaces at beginning and end of text and replace
		//with null strings
		if( null != str )
			{
				return strrtrim( strltrim( str ) );
			}
		return null;
	}

function setBorderStyle( elementId, border )
	{
		var	element = document.getElementById( elementId );
		if( element )
			{
				element.style.border = border;
			}
	}

function setInnerHTMLOfId( elementId, text )
	{
		var	element = document.getElementById( elementId );
		if( element )
			{
				element.innerHTML = text;
			}
	}

function setDisplayStyle( elementId, style )
	{
		var	element = document.getElementById( elementId );
		if( element )
			{
				element.style.display = style;
			}
	}

function getDisplayStyle( elementId )
	{
		var	element = document.getElementById( elementId );
		if( element )
			{
				return element.style.display;
			}
		return "block";
	}

function toggleDisplayStyle( elementId, style )
	{
		if( isElementVisible( elementId ) )
			setDisplayStyle( elementId, "none" );
		else
			setDisplayStyle( elementId, style );
	}

function isElementVisible( elementId )
	{
		var	display = getDisplayStyle( elementId );
		if( "none" == display )
			return false;
		if( "" == display )
			return false;
		return true;
	}

function setClassForElementId( elementId, newClass )
	{
		var	element = document.getElementById( elementId );
		if( element )
			{
				element.className = newClass;
			}
	}
	
function showImageTitle( imgElement, dstId )
	{
		if( null == imgElement )
			return;
		setInnerHTMLOfId( dstId, imgElement.title );
	}

function pushGarbage( msg )
	{
		var	msgElement = document.getElementById( 'garbage' );
		if( null == msgElement )
			return;
		
		if( null == msg )
			msg = "&nbsp;";
			
		msg = msg.replace( new RegExp( "<", "gi" ), "&lt;" );
		msg = msg.replace( new RegExp( ">", "gi" ), "&gt;" );
			
		msgElement.innerHTML = msg + "<hr />" + msgElement.innerHTML;
	}

function getTargetFromEvent( e )
	{
		var	theTarget;
		
		if( !e )
			var e = window.event;
		
		if( e.target )
			theTarget = e.target;
		else if( e.srcElement )
			theTarget = e.srcElement;

		if( 3 == theTarget.nodeType )
			theTarget = theTarget.parentNode;
		
		if( null == theTarget )
			{
				pushGarbage( "browser brain damage - the target is null" );
			}
		
		return theTarget;
	}
	
function loadImageIdWithSource( elementId, source )
	{
		loadImageWithSource( document.getElementById( elementId ), source );
	}

function loadImageWithSource( it, source )
	{
		if( null == it )
			return;
		it.src = source;
	}

function reloadVerification( name, src )
	{
		var	it = document.getElementById( name );
		if( null != it )
			{
				src += getAnotherId();
				it.src = src;
			}
		return false;
	}

function digestPassword( theForm )
	{
		theForm.digest.value = calcPasswordDigest( theForm.password.value );
		theForm.password.value = "";
		return true;
	}

var	globalPasswordSalt = null;
function calcPasswordDigest( password ) 
	{ 
		return hex_md5( globalPasswordSalt + password ); 
	}
	
var image_microblog_bottom = new Image();
image_microblog_bottom.src = '/images/microblog-bottom.gif';

var image_microblog_top = new Image();
image_microblog_top.src = '/images/microblog-top.gif';

var image_microblog_my_bottom = new Image();
image_microblog_my_bottom.src = '/images/microblog-my-bottom.gif';

var image_microblog_my_top = new Image();
image_microblog_my_top.src = '/images/microblog-my-top.gif';

var image_microblog_close = new Image();
image_microblog_close.src = '/images/microblog-close.png';


function thoughtBubbleClick( bubbleId, blogID )
	{
		setDisplayStyle( bubbleId, 'none' );
		setDisplayStyle( blogID, 'block' );
	}
	
function microblogClose( bubbleId, blogID )
	{
		setDisplayStyle( bubbleId, 'block' );
		setDisplayStyle( blogID, 'none' );
	}
	
function startMicroblogEdit()
	{
		setDisplayStyle( 'my-microblog-display', 'none' );
		setDisplayStyle( 'my-microblog-entry', 'block' );
	}
	
function microblogEdit_cancel()
	{
		setDisplayStyle( 'my-microblog-display', 'block' );
		setDisplayStyle( 'my-microblog-entry', 'none' );
		return false;
	}
	
function microblogEdit_clear()
	{
		var	theForm = document.microblog_form;
		if( null == theForm )
			return false;
		
		theForm.blog.value = "";
	}
	
function microblogEdit_save()
	{
		var	theForm = document.microblog_form;
		if( null == theForm )
			return false;
			
		setInnerHTMLOfId( 'my-microblog-status', 'updating...' );
		
		var	blog = theForm.blog.value;
		
		var	query = "/cmd/microblog.php";
		query += "?id=" + theForm.profile_id.value;
		query += "&blog=" + encode( blog );
		
		queryForInnerHTMLWithFunction( query, 'my-microblog-status' );
		
		blog = blog.replace( /\n/g, "<br />" );
		
		setInnerHTMLOfId( 'my-microblog-display', blog );
		
		setDisplayStyle( 'my-microblog-display', 'block' );
		setDisplayStyle( 'my-microblog-entry', 'none' );
		return false;
	}