/*
	(c) 2007-2008 | http://olegrorovin.spb.ru/
	Author - Oleg Korovin (mail@olegrorovin.spb.ru)
*/

var LogonBlock = {
	elFrame		: null,
	elRemind		: null,
	bProcessing	: false,
	bIsFormView	: false,

 /***************************************************************************/
	show				: function(event){
		if( LogonBlock.bIsFormView ) return;
		
		LogonBlock.elFrame = $('AuthFrame');
				
		winPopup.show(
			event,
			LogonBlock._show,
			LogonBlock.close,
			LogonBlock.elFrame
		);
	},
	
 /***************************************************************************/
	_show				: function(event){
		LogonBlock.elFrame.className = 'FormView';
		
		LogonBlock.elRemind = $('AuthRemind');
		
		if(LogonBlock.elRemind){
			Styles.removeClass( LogonBlock.elRemind ,'open');
			$('AuthRemindStatus').innerHTML = '';
		}
		
		LogonBlock.bIsFormView = true;
	},

 /***************************************************************************/
	close				: function(event){
		LogonBlock.elFrame.className = 'ButtonView';
		LogonBlock.bIsFormView = false;
		
		return Events.stop(event);
	},

	
 /***************************************************************************/
	showReminder	: function(){
		Styles.addClass( LogonBlock.elRemind , 'open' );
	},

	
 /***************************************************************************/
	send				: function(event,elForm){
		if( !elForm || LogonBlock.bProcessing) return;
		
		var 
			elStatus = $('AuthRemindStatus'),
			oValues = {
				text : trim(elForm.elements['mail'].value)
			};
		
		elStatus.innerHTML = '';
		
		if( !oValues.text ) return;
//		if( !isEmail(oValues.text) ){
//			elStatus.innerHTML = '<span class="error">Не корректный e-mail</span>';
//			return;
//		}
				
		elForm.elements[0].disabled = true;
		elForm.elements[1].disabled = true;
		LogonBlock.bProcessing = true;
		
		sendRequest( 
			getUrl(elForm.action),
			oValues,
			5, 
			function(res,text){
				if(res && res.success){
//					Styles.hide(elForm);
				}
				else{
					res.text = '<span class="error">'+ res.text +'</span>';
				}
				elStatus.innerHTML = res.text;
				elForm.elements[0].disabled = false;
				elForm.elements[1].disabled = false;
				LogonBlock.bProcessing = false;
			}
		);
	}
	
}