
$(document).ready(function() {
	//open modal automatically if we come to this page from dashboard
	if(window.location.hash){
	    str = window.location.hash.substr(1);
	   
	    if(str == 'password'){ 
	    	resetPasswordModal();
	    };
	};
	
	var hashVal = window.location.hash;
	if(hashVal){
		$.post("default/auth/update-target", { hashVal: hashVal } );
	}

});

//open the task modal to create a new task
function resetPasswordModal(){
	
		var addModal = new rdModal({
			'id' : 'sendEmail',
			'ajaxPath' : 'default/auth/reset-password/',
			'width' : 400,
			'height' : 400,
			'title' : 'Recover Password',
			'onLoad': setActiveAuth
		}).open();

};

function updateHash(hasVal){
	 var oF = new rdAjaxPost({
			'cAction': $('#form-resetPass').attr('action'),
			'oData': $('#form-resetPass').serialize(),
			'receive_custom' : function(){
				$('#resetPassMessage').removeClass('loader');
				if(!result.errors){
					$('#resetPassMessage').removeClass('error').html(result.html);
					$('#resetPassword').css('display','none');
				} else {
					//boourns
					$('#resetPassMessage').addClass('error').html(result.errors);
				}
	    	},
			'cLogID' : 'nolog'
		}).send();
}


//called once the event modal is loaded
function setActiveAuth(){
	//ajaxify the form
	$('#form-resetPass').submit(function(event){
		event.preventDefault();
		resetPassPost();
	});
};

function resetPassPost(){
	$('#resetPassMessage').addClass('loader');
	
	 var oF = new rdAjaxPost({
			'cAction': $('#form-resetPass').attr('action'),
			'oData': $('#form-resetPass').serialize(),
			'receive_custom' : function(){
				$('#resetPassMessage').removeClass('loader');
				if(!result.errors){
					$('#resetPassMessage').removeClass('error').html(result.html);
					$('#resetPassword').css('display','none');
				} else {
					//boourns
					$('#resetPassMessage').addClass('error').html(result.errors);
				}
	    	},
			'cLogID' : 'nolog'
		}).send();

};

