var CurrentTimestamp;

function SetTimeStamp( time )
{
    CurrentTimestamp = time;
}

function createXMLHttpRequest() 
{

   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   alert("XMLHttpRequest not supported");
   return null;
   
 }
 
 function GetElementContents( name )
 {
	Target = document.getElementById( name );	
	if (!Target) return '';
	
	return Target.innerHTML;
 }

 function SetElement( name, text )
 {
 	Target = document.getElementById( name );	
	if (!Target) return;
	
	Target.innerHTML = text;
 }
 
 function AddElement( name, text )
 {
 	Target = document.getElementById( name );	
	if (!Target) return;
	
	Target.innerHTML = Target.innerHTML + text;
 }
 
 function ShowElement( name, show )
 {
	Target = document.getElementById( name );	
	if (!Target) return;
	
	if ( !show )
	{
		Target.style.display = "none";
	}
	else
	{
		Target.style.display = "";
	}
 }

function GetElapsedTime( intime )
{
    var timeunit = CurrentTimestamp - intime;

    if (timeunit < 0) timeunit = 0;
    if ( timeunit < 60 ) return timeunit + ' seconds ago';

    timeunit = Math.floor( timeunit / 60 );

    if ( timeunit < 60 )
    {
        if ( timeunit == 1 ) return timeunit + ' minute ago';
        return timeunit + ' minutes ago';
    }

    timeunit = Math.floor( timeunit / 60 );

    if ( timeunit < 48 )
    {
        if ( timeunit == 1 ) return timeunit + ' hour ago';
        return timeunit + ' hours ago';
    }

    timeunit = Math.floor( timeunit / 24 );

	if (timeunit == 1) return timeunit + ' day ago';
    return timeunit + ' days ago';
}

function UpdateElapsedTime ( objname, intime )
{
	var elem = document.getElementById( objname );
	if ( elem )
	{
		elem.innerHTML = GetElapsedTime( intime );
	}
}

function MakeGetSafe ( str )
{
	s = new String( str );
	s = s.replace( /&/g, "[[ampersand]]" );
	s = s.replace( /=/g, "[[equals]]" );
	s = s.replace( /\+/g, "[[plus]]" );
	s = s.replace( /\?/g, "[[questionmark]]" );
	return s
}
