// ----------------------------------------------------------------------------
// utils.js - updated 2010 September 17
// ----------------------------------------------------------------------------

/*
 * Framebuster
 */
if ( top != self )
   top.location.replace( self.location.href );

/*
 * Add some useful methods to the String object, not part of ECMA.
 */
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;

/*
 * Fix for sucking MSIE not supporting Array.indexOf()
 * Thanks to Soledad Penades (http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/)
 */
if ( !Array.indexOf )
   Array.prototype.indexOf = function( obj )
   {
      for ( var i = 0; i < this.length; ++i )
         if( this[i] == obj )
            return i;
      return -1;
   };

/*
 * Fix for sucking MSIE not supporting window.getComputedStyle()
 * Thanks to snipplr.com
 */
if ( !window.getComputedStyle )
{
   window.getComputedStyle = function( el, pseudo )
   {
      this.el = el;
      this.getPropertyValue = function( prop )
      {
         var re = /(\-([a-z]){1})/g;
         if ( prop == 'float' )
            prop = 'styleFloat';
         if ( re.test( prop ) )
            prop = prop.replace( re, function () { return arguments[2].toUpperCase(); } );
         return el.currentStyle[prop] ? el.currentStyle[prop] : null;
      }
      return this;
   }
}

/*
 * Returns true if we are online; false if we are running a local version of the website.
 */
function IsOnLine()
{
   return window.location.protocol == "http:";
}

/*
 * Returns a decimal string representation of an integer, left-padded with n zeros.
 */
function ZeroPad( x, n )
{
   var s = x.toString();
   for ( var i = s.length; i < n; --n )
      s = "0" + s;
   return s;
}

/*
 * Returns a hexadecimal string representation of an integer, left-padded with n zeros.
 */
function ZeroPadHex( x, n )
{
   var s = x.toString( 16 );
   for ( var i = s.length; i < n; --n )
      s = "0" + s;
   return s;
}

/*
 * Short month names.
 */
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];
}

/*
 * Full month names.
 */
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];
}

/*
 * String representation of a Date object in YYYY mmm DD format.
 */
function DateAsString( d )
{
   return d.getFullYear().toString() + " " + MonthShortName( d.getMonth() ) + " " + ZeroPad( d.getDate(), 2 );
}

/*
 * String representation of a UTC time point in YYYY mmm DD HH:MM:SS format.
 */
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 );
}

/*
 * Returns an array with the x,y pixel position of an object on the current document.
 */
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 );
}

/*
 * Toggles the style.display CSS property of an object with id.
 */
function toggleDisplay( id )
{
   var obj = document.getElementById( id );
   obj.style.display = obj.style.display ? "" : "none";
}

/*
 * Portable routine to set the 'src' attribute of an image selected by its id.
 */
function setImgSrc( imgId, imgSrc )
{
   var obj = document.getElementById( imgId );
   if ( obj )
      obj.src = imgSrc;
}

// ----------------------------------------------------------------------------
// IE detection and identification
// ----------------------------------------------------------------------------

/*
 * Detect the #1 enemy of the WWW.
 */
var isIE = (navigator.appName == "Microsoft Internet Explorer");

/*
 * Secure detection of IE6 - the mother of all web sucking.
 * Thanks to Mindful Technology blog (http://mindfultechnology.wordpress.com/2008/02/11/detect-ie6/)
 */
var isIE6 = (window.external && typeof window.XMLHttpRequest == "undefined");
// Alternate code for secure IE6 detection:
//var isIE6 = ('ActiveXObject' in window && !('XMLHttpRequest' in window));

/*
 * Secure detection of IE7 - which also sucks.
 * Thanks to Maratz.com (http://www.maratz.com/blog/archives/2006/10/31/reliable-ie-7-detection-with-javascript/)
 */
var isIE7 = (!isIE6 && document.all && !window.opera && window.XMLHttpRequest && !document.documentMode);

/*
 * Determine the sucker's document mode.
 */
var IEMode = 0;
if ( isIE6 )
   IEMode = 6;
else if ( isIE7 )
   IEMode = 7;
else if ( isIE )
{
   if ( document.documentMode ) // IE8 or later
      IEMode = document.documentMode;
   else // IE 5-7
   {
      IEMode = 5;
      if ( document.compatMode )
      {
         if ( document.compatMode == "CSS1Compat" )
         IEMode = 7;
      }
   }
}

/*
 * Show a warning cartoon in case we have IE6.
 */
function IE6Warning()
{
   if ( isIE6 || isIE7 || isIE && IEMode < 8 )
      document.getElementById( "IE6Warning" ).style.visibility = "visible";
}

// ----------------------------------------------------------------------------

