/**
 * The ThinkCo global namespace
 * @constructor
 */
window.ThinkCo = window.ThinkCo || {};
ThinkCo.namespace = function ( ns )
{
	if ( !ns || !ns.length ) {
		return null;
	}

	var levels	= ns.split ( "." );
	var nsobj	= ThinkCo;

	for ( var i = ( levels [ 0 ] == "ThinkCo" ) ? 1 : 0; i < levels.length; ++i ) {
		nsobj [ levels [ i ] ] = nsobj [ levels [ i ] ] || {};
		nsobj = nsobj [ levels [ i ] ];
	}

	return nsobj;
};

YAHOO.util.Event.addListener ( window, "load", function ( )
{
	YAHOO.util.Dom.addClass	( 'iRoot', 'enhance' )
} );

/* Add extra functionality for lower versions of IE */
if ( !Array.prototype.push )	{ Array.prototype.push	= function ( ) { for ( var i = 0; i < arguments.length; i++ ) { this [ this.length ] = arguments [ i ]; }	return this.length; } }
if ( !String.prototype.trim )	{ String.prototype.trim	= function ( ) { return this.replace (/^\s*/,'' ).replace( /\s*$/, '' ); } }


/**
 *
 */
String.prototype.normalize = function ( )
{
	return this.replace (/\s+/g, " " );
};

/**
 *
 */
Date.prototype.isLeapYear = function ( )
{
	var year	= this.getFullYear ( )
	return ( ( year % 4 == 0 && year % 100 != 0 ) || year % 400 == 0 );
}

/**
 *
 */
Date.prototype.getDaysInMonth = function ( )
{
	var days	= new Array ( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
	if ( this.isLeapYear ( ) )
	{
		days [ 1 ]	= 29
	}
	return days [ this.getMonth ( ) ]
}

/**
 *
 */
Date.prototype.isValid = function ( YYYY, MM, DD )
{
	DD	= Number ( DD );
	MM	= Number ( MM );
	YYYY	= Number ( YYYY );

	if ( MM >= 0 && MM < 12 && String ( YYYY ).length == 4 && DD > 0 )
	{
		var tmp	= new Date ( YYYY, MM )
		var days	= tmp.getDaysInMonth ( );

		if ( DD <= tmp.getDaysInMonth ( ) )
		{
			return true;
		}
	}
	return false;
}

/**
 *
 */
Date.prototype.getDiffMonths = function ( to )
{
	return this.dateDiff ( "m", to );
}

/**
 *
 */
Date.prototype.getDiffYears = function ( to )
{
	return this.dateDiff ( "y", to );
}

/**
 *
 */
Date.prototype.dateDiff = function ( dp, v_date )
{
	var ms	= v_date - this;
	var ss	= Math.floor ( ms / 1000 );
	var mm	= Math.floor ( ss / 60 );
	var hh	= Math.floor ( mm / 60 );
	var dd	= Math.floor ( hh / 24 );
	var yy	= Math.floor ( dd / 365 );
	var mn	= Math.floor ( dd / 365 * 12 );
	return (dp == "y") ? yy : (dp == "m") ? mn : (dp == "d") ? dd : (dp == "h") ? hh : (dp == "n") ? mm : (dp == "s") ? ss : ms;
};