
Ext.onReady(function(){
	Ext.get('forgot_pw_confirm').setVisibilityMode(Ext.Element.DISPLAY);
	Ext.get('login_prompt').setVisibilityMode(Ext.Element.DISPLAY);
	Ext.get('forgot_pw_prompt').setVisibilityMode(Ext.Element.DISPLAY);

})


function returnToLogin(hideDiv){
	Ext.get('login_window').fadeOut({
		callback: function(){
			Ext.get(hideDiv).hide()
			Ext.get('login_prompt').show();
			Ext.get('login_window').fadeIn({
				easing: 'easeIn'
			});
		}
		,easing: 'easeIn'
	});
}


function displayForgotPw(){
	Ext.get('login_window').fadeOut({
		callback: function(){
			Ext.get('login_prompt').hide()			
			Ext.get('forgot_pw_prompt').show();
			Ext.get('login_window').fadeIn({
				easing: 'easeIn'
			});
		}
		, easing: 'easeIn'
	});
	
}

function forgotPw(){
	//alert('forget');
	var loadmask = new Ext.LoadMask(Ext.get('login_window'),{
		msg:'Looking up email..'
	});
	loadmask.show();
	Ext.Ajax.request({
		url:'/default/ajax/forgot-password'
		,params:{
			email:Ext.get('forgot_pw_email').getValue()
		}
		,success:function(response){
			var responsetext=Ext.decode(response.responseText);
			if (responsetext.success){
				Ext.Msg.alert('Email Sent','You have been sent an email from libsyn support with instructions on how to change your password.');
				returnToLogin('forgot_pw_prompt');
			} else {
	 			Ext.Msg.alert('Error', responsetext.data);
			}
		}
		,failure:function(response){
			Ext.Msg.alert('Error', Ext.decode(response.responseText).data);
		}
		,callback: function(){
			loadmask.hide();
		}
	})
}

function changePw(){
	var vars = Form.serialize($('reset_pw_form'));
	
	var url ="/default/ajax/changepw";
	
	
	
	
	
	new Ajax.Request(url, {method:'post',postBody:vars,onSuccess:function(transport){
			var jason = Ext.util.JSON.decode(transport.responseText);
					 if (jason.status== "success"){
		 				Ext.MessageBox.alert('',jason.message,function() {
							location.href='/auth/login';																		
						});
		 				
					 }
					 
					 if (jason.status== "failure"){
		 				Ext.MessageBox.alert('',jason.message,function() {
							//location.href='/auth/login';																		
						});
		 				
					 }
					 
					 
					 	
	},
	onFailure: function(transport) {
			 alert(transport.responseText);
		 }

	});
}
