// JavaScript Document
	LOGin = function(){ this.init(); }
	var p = LOGin.prototype;
	
	p.req = null;
	p.wait = false;
	p.action = '';
	p.urlH = URL_HOME;//HOME
	p.reqOnError = '';//HOME
	
	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)); }
		}.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;
		if(!!(o = $('lremember')))v += 'rec' + SEP_IGUAL + ((o.checked)? 1:0) + SEP_AND;
		$('lsending').style.display = 'block';
		
		this.action = 'login';
		this.req.pedir(URL_ROOT + '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(URL_ROOT + 'request/requestNewPassword.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(URL_ROOT + '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 += 'cemail' + SEP_IGUAL + trim($('rcemail').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').value + SEP_AND;
		v += 'contrasena' + SEP_IGUAL + trim($('rpassword').value) + SEP_AND;
		v += 'cContrasena' + SEP_IGUAL + trim($('rcpassword').value) + SEP_AND;
		
		for(i in IDIOMAS){
			if($('rlang'+i).checked){
				v += 'idioma' + SEP_IGUAL + i + SEP_AND;
				break;
			}
			
		}
		
		v += 'news' + SEP_IGUAL + (($('rnews').checked)? 1:0) + SEP_AND;
		$('rsending').style.display = 'block';
		
		this.action = 'register';
		this.req.pedir(URL_ROOT + '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'; }
	
		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 if(d.getAttribute('grupo') == 'pro'){ document.location.href = URL_ROOT + 'pro/admin.php'; }
			else{ document.location.href = d.getAttribute('url'); }
		}
		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 == 'logout'){
			document.location.href = this.urlH;
		}
		else if(this.action == 'register'){
			e = $('rresponse');
			if(d.getAttribute('tipo') == 'error'){
				e.className = '';
				e.style.display = 'block';
				e.innerHTML = d.firstChild.data;
			}
			else{ 
				document.location.href = d.getAttribute('url'); 
			}
		}
	}
	
	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'; }
		
		Error.message = this.reqOnError;
		Error.onAcept = Error.onCancel = function(){
			Error.hide();
			Blocker.hide();
		}
		Blocker.show();
		Error.show();
	}
	