if(window.ie){
	l = 'domready';
} else {
	l = 'load';
};

window.addEvent(l, 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();
	    };
	};
});

//open the task modal to create a new task
function resetPasswordModal(){

	document.mochaDesktop.newWindow({
		id: 'sendEmail',
		title: 'Recover Password',
		loadMethod: 'xhr',
		contentURL: 'default/auth/reset-password/',
		modal: true,
		width: 400,
		height: 400,
		x:0,
		y: window.getScrollTop() + 100,
		closable: true,
		onContentLoaded: setActiveAuth,
		headerStartColor:  [250, 250, 250],  
	          headerStopColor:   [200, 220, 240],
	          closeColor: [180, 200, 220]
	});
};

//called once the event modal is loaded
function setActiveAuth(){
	//ajaxify the form
	$('form-resetPass').addEvent('submit', function(e){
		new Event(e).stop();
		resetPassPost();
	});
};

function resetPassPost(){
	$('resetPassMessage').addClass('loader');
	$('form-resetPass').send({
		onComplete:resetPass		
	});
};

function resetPass(json){
	eval('result='+json);
	$('resetPassMessage').removeClass('loader');
	
	if(result.success == true){
		$('resetPassMessage').removeClass('error');
		$('resetPassMessage').innerHTML = result.html;
		$('resetPassword').style.display = 'none';
	} else {
		//boourns
		$('resetPassMessage').addClass('error');
		$('resetPassMessage').innerHTML = result.errors;
	}
	
};
