var APIScriptLoader=new Object();

var API_GENERIC = 1 ;
var API_GENERIC_SPECIFIC = 2 ;
var API_SPECIFIC = 3 ;

var API_LOCATION_API = 1;
var API_LOCATION_CUSTOM = 0;

// BF20101008:	APIPath should start in site root
APIScriptLoader.APIPath = '/javascript/' ;
APIScriptLoader._Scripts = new Object() ;
APIScriptLoader._LoadedScripts = new Object() ;

APIScriptLoader._IsIE = (/msie/).test( navigator.userAgent.toLowerCase() ) ;

APIScriptLoader.Load = function( scriptName )
{
	// Check if the script has already been loaded.

	if ( scriptName in APIScriptLoader._LoadedScripts ) {
		return ;
	}
	var oScriptInfo = this._Scripts[ scriptName ] ;

	if ( !oScriptInfo )
	{
		alert( 'The script "' + scriptName + '" could not be loaded' ) ;
		return ;
	}

	for ( var i = 0 ; i < oScriptInfo.Dependency.length ; i++ )
	{
		this.Load( oScriptInfo.Dependency[i] ) ;
	}

	var sBaseScriptName = oScriptInfo.BasePath + scriptName.toLowerCase() ;

	if ( oScriptInfo.Compatibility == API_GENERIC || oScriptInfo.Compatibility == API_GENERIC_SPECIFIC )
		this._LoadScript( sBaseScriptName + '.js',oScriptInfo.Location ) ;

	if ( oScriptInfo.Compatibility == API_SPECIFIC || oScriptInfo.Compatibility == API_GENERIC_SPECIFIC )
	{
		if ( this._IsIE )
			this._LoadScript( sBaseScriptName + '_ie.js',oScriptInfo.Location ) ;
		else
			this._LoadScript( sBaseScriptName + '_gecko.js' ,oScriptInfo.Location) ;
	}

	APIScriptLoader._LoadedScripts[ scriptName ] = true ;
}

APIScriptLoader._LoadScript = function( scriptPathFromSource,useAPIPath )
{
	document.write( '<script type="text/javascript" src="' + (useAPIPath ? this.APIPath : '' )  + scriptPathFromSource + '" onerror="alert(\'Error loading \' + scriptPathFromSource);"><\/script>' ) ;

}
APIScriptLoader.AddScript = function( scriptName, scriptBasePath, dependency, compatibility,scriptLocation )
{
	this._Scripts[ scriptName ] =
	{
		BasePath : scriptBasePath || '',
		Dependency : dependency || [],
		Compatibility : compatibility || API_GENERIC,
		Location : scriptLocation || API_LOCATION_API

	} ;
}
