// BEGIN backwards compatibility stuff {
/*
if ( Array.indexOf==undefined ){
	Array.prototype.indexOf = function(){
		for( var i=0 ; i<this.length; i++ ){
			if ( this[i]==arguments[0] )
				return i;
		}
		return -1;
	}
}
*/
// } END backwards compatibility stuff

//como comprobar si hay explorer
//if ( navigator.userAgent.indexOf('MSIE')<0 && typeof consola=='undefined' ){

/*

This code should become a plataform library for web applications
We should put this on sourceforge

Function Important for web applications

- includes
- library modularity
- log
- dom manip

*/

//{{{ GLOBAL FUNCTIONS (supposed to be the must used)
function $(){
	if ( arguments.length != 1 ){
		throw 'Argumentos insuficientes al llamar a la funcion $()';
	}
	if ( typeof arguments[0] != 'string' ){
		throw 'Los argumentos para la funcion $() deben ser de tipo string.';
	}

	return document.getElementById( arguments[0] );
}

function $evalObject( strCode ){
	try {
		var r = eval( strCode );
		if ( typeof r != 'object' )
			throw 'typeof evaled code is not an object';
		return r;
	} catch ( ex ){
		alert( 'ERROR al parsear string como Objeto:\n' + ex  + '\n' + 'string=\n' + strCode );
		throw ex;
	}
}

function $AJAXCallback( oParams ){
	this.success = function(request){
		alert('RESPUESTA RECIBIDA:\n' + request.responseText);
	}
	this.failure = function(request){
		alert('ERROR AL HACER PETICION ASINCRONA.' + '\nErrorCode: ' + request.responseCode + '\nError: ' + request.responseText );
	}
	if ( oParams && oParams.success && (typeof oParams.success)=='function' ){
		this.success = oParams.success;
	}
}

function $encodeHttpParams( oParams ){
	var arr = [];
	for(prop in oParams){
		arr.push( encodeURIComponent(prop) + '=' + encodeURIComponent(oParams[prop]) );
	}
	return arr.join('&');
}
//}}}

var GSF = {};

GSF._includedFiles = new Array();
GSF._includedFilesStack = new Array();
GSF._includedCSSFiles = new Array();

// Internet Explorer requiere tratamiento especial por ser una basura
GSF.isIE = ((navigator.appName=='Microsoft Internet Explorer')?true:false);

if ( typeof console!='undefined' && console.log ){
	GSF.consola = console;
} else {
	GSF_CONSOLA = function(){
		var _list = null;

		if ( GSF.isIE ){
			this.log = function( msg ){
				alert( msg );
			}
		} else {
			this.log = function( msg ){
				if ( _list==null ){
					_list = document.createElement('ul');
					document.documentElement.appendChild( _list );
				}
				var li = document.createElement('li');
				li.appendChild( document.createTextNode( msg ) );
				_list.appendChild( li );
			}
		}
	};
	GSF.consola = new GSF_CONSOLA();
}

GSF.log = function( msg ){
	GSF.consola.log( msg );
}

GSF.getXMLHTTPRequest = function(){
	var r = null;
	try {
		r = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(ex){
		try {
			r = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(ex){
			try {
				r =  new XMLHttpRequest();
			} catch(ex){
				throw 'No se puede crear objeto XMLHttpRequest';
			}
		}
	}
	return r;
}

/*
va a servir solo de caracter informativo y documental y para facilitar el
armado le la lista de includes, usando la funcion GSF.getIncludeTags
*/
GSF.include = function( file ){
	if ( typeof GSF._includedFiles[ file ] == 'undefined' ){
		GSF._includedFiles[ file ] = true;
		GSF._includedFilesStack.push( file );
	}
}

GSF.logIncludeTags = function(){
	GSF.log( '<!-- includes count ' + GSF._includedFilesStack.length + ' -->' );
	for ( var i=0; i < GSF._includedFilesStack.length; i++ ){
		GSF.log( '<script src="' + GSF._includedFilesStack[i] + '"></script><script>GSF.include(\'' + GSF._includedFilesStack[i] + '\')</script>' );
	}
}

GSF.includeCSS = function( file ){
	if ( ! GSF._includedCSSFiles[ file ] ){
		document.write('<link rel="stylesheet" type="text/css" href="' + file + '">');
		GSF._includedCSSFiles[ file ] = true;
	}
}

var clog;
var cdir;
if ( typeof console=='undefined' ){
	clog = alert;
	cdir = alert;
} else {
	clog = console.log;
	cdir = console.dir;
}
