/****************************************************************
	Project:     ForgeSuite
	Copyright:   2008 Eidix Labs (http://eidix.com/)
	Author:      James Linden (jl@eidix.com)
	Filename:    core/inc/lib_core.js
	Created:     2008-09-27 11:00 EST
****************************************************************/

/*** STRING ****************************************************/

String.prototype.trim = function() {
	return( this.replace( /^\s*/, '' ).replace( /\s*$/, '' ) );
}

String.prototype.ltrim = function() {
	return( this.replace( /^\s*/, '' ) );
}

String.prototype.rtrim = function() {
	return( this.replace( /\s*$/, '' ) );
}

String.prototype.urlencode = function() {
	return( encodeURIComponent( this ).replace( /%20/g, '+' ) );
}

String.prototype.urldecode = function() {
	return( decodeURIComponent( this ).replace( /\+/g, ' ' ) );
}

String.prototype.toInteger = function() {
	return( new Number( this ) );
}

/*** WINDOW ****************************************************/

Window.prototype.width = function() {
	var i = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		i = window.innerWidth;
	}
	else if( document.documentElement && document.documentElement.clientWidth ) {
		i = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth ) {
		i = document.body.clientWidth;
	}
	return( i );
}

Window.prototype.height = function() {
	var i = 0;
	if( typeof( window.innerHeight ) == 'number' ) {
		i = window.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight ) {
		i = document.documentElement.clientHeight;
	}
	else if( document.body && document.body.clientHeight ) {
		i = document.body.clientHeight;
	}
	return( i );
}

Window.prototype.hcenter = function() {
	return( Math.round( window.width() / 2 ) );
}

Window.prototype.vcenter = function() {
	return( Math.round( window.height() / 2 ) );
}
