var oLoginForm = Class.create();

oLoginForm.prototype = {
   coverLayer: null,
   respCont  : null,
   imgProgressbar: null,

   initialize: function() {
   
		this.coverLayer = $('coverLayer');
		
		if (!this.imgProgressbar) {
			this.imgProgressbar = new Image();
			this.imgProgressbar.id = 'progressBar';
			this.imgProgressbar.src = '/user/images/tpls/progressbar.gif';
			this.imgProgressbar.style.position = 'absolute';
			this.imgProgressbar.style.visibility = 'hidden';
			this.imgProgressbar.style.zIndex = '3';
			this.imgProgressbar.style.left = parseInt(document.body.scrollWidth/2) -  parseInt(parseInt(this.imgProgressbar.width)/2);
			this.imgProgressbar.style.top = parseInt(screen.height/2)-200;
		}
		
		this.respCont = $('outerLoginBox');
		this.respCont.style.width = 300;
		this.respCont.style.left = parseInt(document.body.scrollWidth/2) -  parseInt(parseInt(this.respCont.style.width)/2);
		this.respCont.style.top = parseInt(screen.height/2)-250;
		this.respCont.style.zIndex = 3;
		
   },
   
   onLoading: function(){
		this.disableBody();
		this.respCont.style.visibility = 'hidden';
		this.respCont.style.display = 'none';
		this.showProgressBar();
	},

	onComplete: function(response) {
		this.hideProgressBar();
		Element.update('innerLoginBox', response.responseText)
		this.respCont.style.visibility = 'visible';
		this.respCont.style.display = 'block';
		var thObj = this;
		Event.observe('fLoginForm', 'submit', function(){
												thObj.tryLogin()
											  });
	},

   showProgressBar: function(){
   		document.body.appendChild(this.imgProgressbar);
   		this.imgProgressbar.style.visibility = 'visible';
   },
   
   hideProgressBar: function(){
   		document.body.removeChild(this.imgProgressbar);
   		this.imgProgressbar.style.visibility = 'hidden';
   },
   
   disableBody: function() {
   	  this.coverLayer.style.display = 'block';
	  this.coverLayer.style.height = document.body.scrollHeight;
      this.coverLayer.style.visibility = 'visible';
	  this.zIndex = -2;
	  document.body.normalize()
   },
   
   enableBody: function() {
   		this.coverLayer.style.display = 'none';
   		this.coverLayer.style.visibility = 'hidden';
		this.zIndex = 2;
   },
   
   hideLoginForm: function() {
   		this.respCont.style.visibility = 'hidden';
		this.enableBody();
   },
   
   showLoginForm: function() {
   	  var oThis = this;
	  $('btnClose').onclick = function() {
	  	 oThis.hideLoginForm();
	  }
  	 
	  var myAjax = new Ajax.Request( 
	 	'/ru/participants/loginform/', 
		{ 
			method: 'get',
			onLoading : function(){
				oThis.onLoading();
			},
			onComplete: function(r){
				oThis.onComplete(r);
				$('fLoginForm').elements['handle'].focus();
			}
		}); 
   },
   
   tryLogin : function(evt){
		var oThis = this;
		var url = '/ru/participants/loginform/?act=checklogin';
		var myAjax = new Ajax.Request( 
	  			url, 
				{ 
				  method: 'post', 
				  postBody: Form.serialize('fLoginForm'),
				  onLoading : function(){
					 oThis.onLoading();
				  },
				  onComplete: function(r){
					 oThis.onComplete(r);
				 }
				}); 
				
		return false;
   }
}; 
