function doLogin(email, password){
	error="";
	if (email=="" || password=="")
	{
		if (email=="")
		{
			error+="- Please enter your email<br />";
		}
		if (password=="")
		{
			error+="- Please enter your password";
		}
		$("#status").attr('style', 'color:#FF0000; font-weight:bold');
		$("#status").html(error);
		$("#status").show();
	}
	else {
		$("#loading").show();
		$("#status").show();
		$.ajax({
			url: "index.php",
			type: "POST",
			data: "action=login&email="+email+"&password="+password,
			success: function (response){
				if (response=="INVALID_LOGIN")
				{
					
					$("#status").attr('style', 'color:#FF0000; font-weight:bold');
					$("#status").html("Invalid username/password. Please try again");
					$("#status").show();
					$("#loading").hide();
				}
				else {
					userDetails = evalEncode(response);
					if (userDetails.userID)
					{

						$("#status").attr('style', 'color:#4CC417; font-weight:bold');
						$("#status").html("Successfully logged in, please wait...");
						$("#status").show();
						$("#loading").hide();
						closeLogin();
					}
				}
			}
		});
	}
}


var modalboxGlobalDefaults = {
	localizedStrings : {
		messageCloseWindow : '',
		messageAjaxLoader : 'Please wait',
		errorMessageIfNoDataAvailable : '<strong>No content available!</strong>',
		errorMessageXMLHttpRequest : 'Error: XML-Http-Request Status "500"',
		errorMessageTextStatusError : 'Error: AJAX Request failed'

	}
};


/* <![CDATA[ */
function showFPass(){
   jQuery.fn.modalBox({ 
		directCall : {
			source : 'index.php?action=showFPass'
		},

	});
}
jQuery(document).ready(function(){
	jQuery("a.showFPass").click(function(){
		showFPass();
	});
});


/* <![CDATA[ */
function showLogin(){
   jQuery.fn.modalBox({ 
		directCall : {
			source : 'index.php?action=showLogin'
		},

	});
}
jQuery(document).ready(function(){
	jQuery("a.showLogin").click(function(){
		showLogin();
	});
});

function closeLogin(){
	jQuery.fn.modalBox('close');
	location.reload(true);
}

function addComment(userID, postID, comment){
	comment = comment.replace(/\n/g, "<br/ >");
	$.ajax({
		url: "blog.php",
		data:"action=addComment&postID="+postID+"&userID="+userID+"&comment="+comment,
		success: function (response){
			$("#commentCont_"+postID).html(response);
			$("#comments_"+postID).show();
		}
	});
}



function forgotPass(){
	email = $("#fEmail").val();
	$("#loading").show();
	$("#status").empty();
	$.ajax({
		url: "index.php",
		data: "action=forgotPassword&email="+email,
		success: function (response){
			if (response){
				$("#status").attr('style', 'color:#000000; ');
				$("#status").html('<br />Thank you, instructions on how to reset your password have been emailed to <strong>'+email+'</strong> <br /><br /><a href="javascript:closeLogin()">Close Window</a>');
				$("#status").show();
				$("#emailText").hide();
				$("#resetPassword").hide();
				$("#fEmail").hide();
				$("#backBtn").hide();
				$("#fPassword").hide();
			}
			else {				
				$("#status").attr('style', 'color:#FF0000; font-weight:bold');
				$("#status").html('Sorry, the email address you entered could not be found. Please try again.');
			}
			$("#loading").hide();
		}
	});
}
