/**
 Object: load
 Version: 1.0
 Autor: Александр Хрищанович
 Description: Объект load для динамического включения javascript файлов через ajax
*/
var load = {
	includedFiles : new Array( ),
	thisObject : this,
	request : null
};

/* Получение XMLHTTP объекта для ajax запроса на сервер */
load.getXMLHttpObject= function( ) {

	var result = false;
	var i;
	var XMLHttpObjects = [
		function( ) { return new XMLHttpRequest( ) },
		function( ) { return new ActiveXObject( 'Msxml2.XMLHTTP' ) },
		function( ) { return new ActiveXObject( 'Microsoft.XMLHTTP' ) }
	];
    
	for( i=0; i<XMLHttpObjects.length; i++ ) {
		try{
			result = XMLHttpObjects[i]( );
			break;
		} catch ( e ) { }	
	}

	return result;

}

/* Включение запрошенного файла с сервера */
load.include = function( urlFile, callBackFunctionStart, callBackFunctionEnd ) {

	callBackFunctionStart( );

	if ( this.includedFiles[urlFile] ) {
		callBackFunctionEnd( this.includedFiles[urlFile] );
	}
	else {

		var context = this;
		
		var TempFunction = function( ) {
			if ( context.request.readyState == 4 ) {
				if ( context.request.status == 200 ) {
					context.includedFiles[urlFile] = context.request.responseText;
					callBackFunctionEnd( context.includedFiles[urlFile] );
					return true;
				}
				if ( context.request.status == 404 ) {
					context.includedFiles[urlFile] = false;
					callBackFunctionEnd( context.includedFiles[urlFile] );
					return true;
				}
			}
		}
		
		this.load( urlFile, TempFunction );

	}


}

load.load = function( urlFile, callBackFunction ) {
	
	this.request = this.getXMLHttpObject( );

	this.request.onreadystatechange = callBackFunction;		
	this.request.open( 'GET', urlFile, true );
	this.request.send( null );
	
	return false;
		
}