/*
   +----------------------------------------------------------------------+
   | XMLHttpRequest javascript file
   +----------------------------------------------------------------------+
   | Este codigo esta sujeto a la licencia GPL.                           |
   | Si no tienes una copia de dicha licencia, puedes hacer:              |
   | http://www.google.com -> Buscar "GPL" -> Voy a tener suerte.         |
   | Y no pongas excusas como "No tengo Internet", se cayo Google,        | 
   | o se me rompió el teclado.                                           |
   +----------------------------------------------------------------------+
   | Publicado en: MaestrosDelWeb.com                                     |
   |        http://www.maestrosdelweb.com                                 |
   +----------------------------------------------------------------------+
   | Autor: Daniel "Pichongol" Lopez <pichongol@yahoo.com>                |
   |        http://pichongol.blogspot.com                                 |
   +----------------------------------------------------------------------+
   +----------------------------------------------------------------------+
   | Chequea http://pichongol.blogspot.com por nuevas versiones,          |
   | dudas y consultas                                                    |
   +----------------------------------------------------------------------+
*/

/**** Objeto XMLHttpRequest *****/
var xmlHttp=null;
try {
	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
	try {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	 }
	catch(e) {}
}

/**** Forma nativa ****/
if (xmlHttp==null)
	xmlHttp=new XMLHttpRequest();


/********* Realiza la peticion y entrega el resultado como texto *************/
function ajaxPerform(sync, xmlMessage, responser, method){
	xmlHttp.open(method, responser, sync);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    
    xmlHttp.send(xmlMessage);
    return xmlHttp.responseText;
}

// envia el formulario
function buildPOST(theForm) { 
    var qs = '';
    for (e=0;e<theForm.elements.length;e++) { 
        if (theForm.elements[e].name!='') { 
            var name = theForm.elements[e].name; 
            qs+=(qs=='')?'':'&';
            qs+= name+'='+escape(theForm.elements[e].value);
        } 
    }
    return qs;
}

/*** auxiliares ***/
var iaux=1;
var intervalID;
var redirect;

function remote_login(method,form,responser,pageLoginOk){
	
	redirect = pageLoginOk;
	
	xmlMessage = buildPOST(form);
	xmlMessage+="&action=login";

	var result = ajaxPerform(false, xmlMessage, responser, method);

	if(result!="yes"){
		document.getElementById("login_err_msg").innerHTML = msg[result];
		document.getElementById("login_err_msg").style.visibility = "visible";
	}
	else {
		document.getElementById("progress_div").style.visibility = "visible";
		intervalID = setInterval("drawPointRedirect()", 1000);
	}

	return false;
}

function drawPointRedirect(){
	document.getElementById("progress_"+iaux).className = 'progress_solid';

	if( iaux==7 ) redireccionaOk();
	iaux++;
}

function hide(element){
	document.getElementById("login_msg_td").innerHTML = "";
}

function redireccionaOk(){
	document.location = redirect;
	clearInterval(intervalID);
	document.getElementById("login").style.visibility = "hidden";
}

