// ----------------------------------------------------------------------------
// utils.js - updated 2008 mar 10
// ----------------------------------------------------------------------------

function String_isEmpty()
{
   return this.length == 0;
}

function String_has( s )
{
   return this.indexOf( s ) >= 0;
}

function String_beginsWith( s )
{
   return !this.isEmpty() && this.indexOf( s ) == 0;
}

function String_endsWith( s )
{
   return !this.isEmpty() && !s.isEmpty() && this.indexOf( s ) == this.length - s.length;
}

function String_isHttpDocument()
{
   return this.beginsWith( "http://" );
}

String.prototype.isEmpty = String_isEmpty;
String.prototype.has = String_has;
String.prototype.beginsWith = String_beginsWith;
String.prototype.endsWith = String_endsWith;
String.prototype.isHttpDocument = String_isHttpDocument;

function IsOnLine()
{
   return window.location.protocol == "http:";
}

function BaseURL()
{
   return IsOnLine() ? "http://astro-photographer.org/" : "/home/juan/Documents/DSA/";
}

function ZeroPad( x, n )
{
   var s = x.toString();
   for ( var i = s.length; i < n; --n )
      s = "0" + s;
   return s;
}

function ZeroPadHex( x, n )
{
   var s = x.toString( 16 );
   for ( var i = s.length; i < n; --n )
      s = "0" + s;
   return s;
}

function MonthShortName( m ) // 0 = jan, 1 = feb, ..., 11 = dec
{
   var shortNames = [ "jan", "feb", "mar", "apr",
                      "may", "jun", "jul", "aug",
                      "sep", "oct", "nov", "dec" ];
	return shortNames[m];
}

function MonthName( m ) // 0 = jan, 1 = feb, ..., 11 = dec
{
   var names = [ "january", "february", "march", "april",
                 "may", "june", "july", "august",
                 "september", "october", "november", "december" ];
	return names[m];
}

function DateAsString( d )
{
   return d.getFullYear().toString() + " " + MonthShortName( d.getMonth() ) + " " + ZeroPad( d.getDate(), 2 );
}

function UTCAsString( d )
{
   return d.getUTCFullYear().toString() + " " + MonthShortName( d.getUTCMonth() ) + " " + ZeroPad( d.getUTCDate(), 2 ) + " " +
	   ZeroPad( d.getUTCHours(), 2 ) + ":" + ZeroPad( d.getUTCMinutes(), 2 ) + ":" + ZeroPad( d.getUTCSeconds(), 2 );
}

function findPos( obj )
{
   var dx = 0;
   var dy = 0;

   while ( obj )
   {
      dx += obj.offsetLeft;
      dy += obj.offsetTop;
      obj = obj.offsetParent;
   }

   return new Array( dx, dy );
}

function toggleDisplay( id )
{
	var obj = document.getElementById( id );
	obj.style.display = obj.style.display ? "" : "none";
}

// Detect IE6
var isIE6 = (window.external && typeof window.XMLHttpRequest == "undefined");

function IE6Warning()
{
   if ( isIE6 )
      document.getElementById( "IE6Warning" ).style.visibility = "visible";

      /*window.setTimeout( 'DoIE6Warning()', 1000 );*/
}

function DoIE6Warning()
{
   document.getElementById( "IE6Warning" ).style.visibility = "visible";
}

// ----------------------------------------------------------------------------
