$(document).ready(function() {
	//	Add hints to input elements.
	$('input[title!=""]').hint();
	
	//pre-submit callback
	function showLoginRequest(formData, jqForm, options){
		$.blockUI({ 
			css: { 
				border: 'none', 
				padding: '15px', 
				backgroundColor: '#000', 
				'-webkit-border-radius': '10px', 
				'-moz-border-radius': '10px', 
				opacity: '.5', 
				color: '#fff' 
			},
			message: '<h1>Logging In...</h1>'
		}); 
		return true;
	}
			
	//post-submit callback
	function showLoginResponse(responseText, statusText){
		$.unblockUI();
		if(responseText.response != 'true'){
			$.prompt(responseText.msg);
		}
		else{
			window.location.href = window.location.href;
		}
	}
	//	Form Execution
	$("#frmLogin").ajaxForm({
		dataType:'json', 
		beforeSubmit:showLoginRequest,
		success:showLoginResponse,
		url:"http://www.md-review.com/resources/library/processors/proc.Login.php",
		type:"post"
	});
	
	//	Obtain a forgot password form and process.
	$("#forgotPass").livequery("click", function(){	
		$.prompt.close();
		function forgotPassCallback(v,m,f){
		      if(v != undefined){
		      	$.blockUI({ 
					css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: '.5', 
						color: '#fff' 
					},
					message: '<h1>Processing...</h1>'
				}); 
		      	$.post("http://www.md-review.com/resources/library/processors/proc.ResetPass.php", {email:f.cp_user_email}, function(data){
		      		$.unblockUI();
					$.prompt(data);
				});
			}
		}
		
		$.prompt('Please enter your email address:<br /><input type="text" id="cp_user_email" name="cp_user_email" />',{
		      callback: forgotPassCallback,
		      buttons: { Submit: 'Submit'}
		});

		return false;
	});
	//	Obtain a forgot password form and process.
	$(".showLogin").livequery("click", function(){	
		function loginCallback(v,m,f){
		      if(v != undefined){
		      	$.blockUI({ 
					css: { 
						border: 'none', 
						padding: '15px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '10px', 
						'-moz-border-radius': '10px', 
						opacity: '.5', 
						color: '#fff' 
					},
					message: '<h1>Processing...</h1>'
				}); 
		      	$.post("http://www.md-review.com/resources/library/processors/proc.Login.php", {cp_user_username:f.cp_user_usernameLB, cp_user_password:f.cp_user_passwordLB}, function(data){
		      		$.unblockUI();
					if(data.response != 'true'){
						$.prompt(data.msg);
					}
					else{
						window.location.href = f.restricted_url;
					}
				},
				"json");
			}
		}
		
		$.prompt('<h2>Client / Physician Login</h2>username:<br/><input title="username" name="cp_user_usernameLB" id="cp_user_usernameLB" type="text"><br/>password:<br/><input title="password" name="cp_user_passwordLB" id="cp_user_passwordLB" type="password"><input name="restricted_url" id="restricted_url" type="hidden" value="' + $(this).attr("href") + '"><br/><a href="#" id="forgotPass">forgot password</a>',{
		      callback: loginCallback,
		      buttons: { Submit: 'Submit'}
		});

		return false;
	});
});
