/*	
	************************
	Libreria _grLibs: Incluye múltiples funciones, clases, etc. generalmente usadas por los hurones =).
	Autor: Emmanuel Galván Murrieta [GurúRojo]
	Para uso en sitios desarrollados por GurúRojo.
	Versión: 1.1-Xandria. Ene 16, 2010
	
	ESTE ARCHIVO DE PROGRAMACION COMPUTACIONAL SE DISTRIBUYE DE ACUERDO A UNA LICENCIA GNU GPL v3
	http://www.gnu.org/licenses/licenses.es.html#GPL. LA FUNCIONALIDAD ESPERADA DEL CODIGO NO ESTA
	GARANTIZADA BAJO NINGUNA CIRCUNSTANCIA. EL AUTOR SE DESLINDA DE CUALQUIER RESPONSABILIDAD POR
	MAL USO O APLICACION DEL PRESENTE CODIGO.
	************************
*/



/*
 Librería:		GurúAjax
 Versión:		2.15
 Llamada:		str 			= new __invokeGuruAjax();		//Inicializar el objeto
 				str.url			= URL_OBJETIVO					//Argumento requerido, dirección objetivo
				str.method		= POST | GET					//Argumento opcional, default = GET
				str.postData	= VARIABLES_A_PASAR				//Argumento opcional, default = null
				variable		= str._callRequest();			//Hacer la petición
				str.onComplete	= foo							//Evento Registrado
 Return:		obj.fResponse	= Array [0] -> false|true [1] -> error_text|text_response
*/

function __invokeGuruAjax(){
	if(window.XMLHttpRequest){
		__callConnect		= new XMLHttpRequest();
	} else if(window.ActiveXObject){
		try{
			__callConnect	= new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			__callConnect	= new ActiveXObject("Microsoft.XMLHTTP");
		}
	} else {
		__callConnect = false;
	}
	if(__callConnect){
		this.method		= 'GET';
		this.url		= null;
		this.postData	= null;
		this.onComplete	= function(){};
		that			= this;
		
		this.callRequest = function(){
			if(this.url.length >= 1){
				try{
					__callConnect.onreadystatechange = function(){
						if(__callConnect.readyState == 4){
							if(__callConnect.status == 200){
								fResponse	= [true,__callConnect.responseText];
								that.onComplete();							
							} else {
								alert('Error al cargar / Error while loading: bad_response_' + __callConnect.status)
								fResponse	= [false,'bad_response'];
								that.onComplete();
							}
						}
					}
					switch(this.method){
						case 'GET':
							__callConnect.open("GET",this.url,true);
							__callConnect.send(null);							
						break;
						case 'POST':
							__callConnect.open("POST",this.url,true);
							__callConnect.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
							__callConnect.send(this.postData);
						break;
						default:
							alert('Error interno de programa / Internal program error: method_unknown')
							fResponse	= [false,'method_unknown'];
							that.onComplete();
						break;
					}

				} catch (e){
					alert('Error interno del explorador / Internal browser error\r\n\r\n' + e)
					fResponse	= [false,'browser_error'];
					that.onComplete();
				}
			} else {
				alert('Error interno de programa / Internal program error: empty_url')
				fResponse	= [false,'empty_url'];
				that.onComplete();
			}
		}
		
	} else {
		alert('ERROR:\r\n\r\nTu explorador no soporta XmlHttpRequest, que es requerido para este sitio.\nYour browser does not support XmlHttpRequest, which is required for this website.')
		return false;
	}
}



/*
 Librería:		Detectar Resolución de Pantalla
 Versión:		1.1
 Llamada:		__invokeGuruScreenRes();
 Return:		Array: [0] -> Boolean|String (False en error o resolución desconocida, widescreen, square) [1] -> ResX [2] -> ResY
*/

function __invokeGuruScreenRes(){
	return [screen.width,screen.height]
}




/*
 Librería:		Detectar datos del cliente
 Versión:		1.0
 Llamada:		__invokeGuruBrowser();
 Return:		Array [0] -> BROWSER_NAME [1] -> BROWSER_VERSION [2] -> VERSION_IE
*/

function __invokeGuruBrowser(){
	ACN	= navigator.appName
	ACV	= navigator.appVersion;
	if(ACV.indexOf('MSIE') >= 1){
		offset	= ACV.indexOf('MSIE')
		IEVER	= parseFloat(ACV.substr(offset +4,(offset+4 - ACV.indexOf(';'))));
	} else {
		IEVER	= false;
	}
	return [ACN,ACV,IEVER];
}



