// JavaScript Document
	LOGin = function(){ this.init(); }
	var p = LOGin.prototype;
	
	p.req = null;
	p.wait = false;
	p.action = '';
	p.dir = '';
	p.anexAdmin = '';
	p.reqOnError = '';
	
	p.init = function(){
		this.req = new Request();
		this.req.listener = this.response.closure(this);
		this.req.onError = this.onError.closure(this);
		
		var f = function(){
			var e = $('lname');
			if(e){ AddEvent(e, 'keypress', function(e){ if(e.keyCode == 13){ this.login(e); } }.closure(this)); }
			e = $('lpass');
			if(e){ AddEvent(e, 'keypress', function(e){ if(e.keyCode == 13){ this.login(e); } }.closure(this)); }
			e = $('nemail');
			if(e){ AddEvent(e, 'keypress', function(e){ if(e.keyCode == 13){ this.requesNewPassword(e); } }.closure(this)); }
			e = $('aemail');
			if(e){ AddEvent(e, 'keypress', function(e){ if(e.keyCode == 13){ this.reactivate(e); } }.closure(this)); }
		}.closure(this);
		
		AddEvent(window, 'load', f);
	}
	
	p.login = function(e){
		var v = '', o;
		if(e){ StopEvent(e); }
		if(this.wait){ return false; }
		this.wait = true;
		
		$('lresponse').style.display = 'none';
		
		v += 'usu' + SEP_IGUAL + $('lname').value + SEP_AND;
		v += 'pas' + SEP_IGUAL + $('lpass').value + SEP_AND;
		$('lsending').style.display = 'block';
		
		this.action = 'login';
		this.req.pedir(this.dir + 'request/login.php', v);
	}
	p.requesNewPassword = function(e){
		var v = '';
		if(e){ StopEvent(e); }
		if(this.wait){ return false; }
		this.wait = true;
		
		$('nresponse').style.display = 'none';
		
		v += 'email' + SEP_IGUAL + $('nemail').value + SEP_AND;
		$('nsending').style.display = 'block';
		
		this.action = 'newPass';
		this.req.pedir(this.dir + 'request/requestNewPassword.php', v);
	}
	p.reactivate = function(e){
		var v = '';
		if(e){ StopEvent(e); }
		if(this.wait){ return false; }
		this.wait = true;
		
		$('aresponse').style.display = 'none';
		
		v += 'email' + SEP_IGUAL + $('aemail').value + SEP_AND;
		$('asending').style.display = 'block';
		
		this.action = 'reactivate';
		this.req.pedir(this.dir + 'request/reactivate.php', v);
	}
	p.logout = function(e){
		var v = 'nada';
		if(e){ StopEvent(e); }
		if(this.wait){ return false; }
		this.wait = true;
		this.action = 'logout';
		this.req.pedir(this.dir + 'request/logout.php', v);
	}
	p.register = function(e){
		var v = '';
		if(e){ StopEvent(e); }
		if(this.wait){ return false; }
		this.wait = true;
		
		$('rresponse').style.display = 'none';
		
		v += 'nombre' + SEP_IGUAL + trim($('rname').value) + SEP_AND;
		v += 'apellido' + SEP_IGUAL + trim($('rlname').value) + SEP_AND;
		v += 'email' + SEP_IGUAL + trim($('remail').value) + SEP_AND;
		v += 'ciudad' + SEP_IGUAL + trim($('rcity').value) + SEP_AND;
		v += 'provincia' + SEP_IGUAL + trim($('rstate').value) + SEP_AND;
		v += 'pais' + SEP_IGUAL + $('rcountry').__id + SEP_AND;
		v += 'contrasena' + SEP_IGUAL + trim($('rpassword').value) + SEP_AND;
		v += 'cContrasena' + SEP_IGUAL + trim($('rcpassword').value) + SEP_AND;
		v += 'news' + SEP_IGUAL + (($('rnews').checked)? 1:0) + SEP_AND;
		v += 'modo' + SEP_IGUAL + 'com' + SEP_AND;
		$('rsending').style.display = 'block';
		
		this.action = 'register';
		this.req.pedir(this.dir + 'request/register.php', v);
	}
	
	p.response = function(){
		var d = this.req.respuestaXML, e = null, o = null;
		this.wait = false;
		
		if(this.action == 'login'){ $('lsending').style.display = 'none'; }
		else if(this.action == 'newPass'){ $('nsending').style.display = 'none'; }
		else if(this.action == 'register'){ $('rsending').style.display = 'none'; }
		else if(this.action == 'reactivate'){ $('asending').style.display = 'none'; }
		
		if(!d){ return alert(this.req.respuestaHTML); }
		else if(this.action == 'login'){ 
			if(d.getAttribute('tipo') == 'error'){
				e = $('lresponse');
				e.style.display = 'block';
				e.innerHTML = d.firstChild.data;
			}
			else{ document.location = 'admin.php'+this.anexAdmin; }
		}
		else if(this.action == 'newPass'){
			e = $('nresponse');
			if(d.getAttribute('tipo') == 'error'){ e.className = ''; }
			else{
				e.className = 'exito';
				$('nemail').value = '';
			}
			e.style.display = 'block';
			e.innerHTML = d.firstChild.data;
		}
		else if(this.action == 'reactivate'){
			e = $('aresponse');
			if(d.getAttribute('tipo') == 'error'){ e.className = 'responseError'; }
			else{
				e.className = 'responseExito';
				$('aemail').value = '';
			}
			e.style.display = 'block';
			e.innerHTML = d.firstChild.data;
		}
		else if(this.action == 'logout'){
			document.location = 'index.php';
		}
		else if(this.action == 'register'){
			e = $('rresponse');
			if(d.getAttribute('tipo') == 'error'){ e.className = ''; }
			else{
				e.className = 'exito';
				
				o = $('rcountry');
				o.value = o.__msjVacio;
				o.__id = 0;
				
				$('rname').value = $('rlname').value = $('remail').value = $('rcity').value = 
				$('rstate').value = $('rpassword').value = $('rcpassword').value = '';
			}
			
			e.style.display = 'block';
			e.innerHTML = d.firstChild.data;
		}
	}
	p.onError = function(){
		this.wait = false;
		if(this.action == 'login'){ $('lsending').style.display = 'none'; }
		else if(this.action == 'newPass'){ $('nsending').style.display = 'none'; }
		else if(this.action == 'register'){ $('rsending').style.display = 'none'; }
		else if(this.action == 'reactivate'){ $('asending').style.display = 'none'; }
		
		Error.message = this.reqOnError;
		Error.onAcept = Error.onCancel = function(){
			Error.hide();
			Blocker.hide();
		}
		Blocker.show();
		Error.show();
	}
	