function siteLogin(){
	//alert("site login");
	var username = $('#login_username');
	var password = $('#login_password');

	//alert(username.val());
	//alert(password.val());

	if(username.val() == null || username.val() == ''){
		$('#username-status').html("&nbsp;<font color='#FF0000'><b>You must enter a username</b></font>");
		return false;
	}
	else {
		$('#username-status').empty();
	}
	if(password.val() == null || password.val() == ''){
		$('#password-status').html("&nbsp;<font color='#FF0000'><b>You must enter a password</b></font>");
		return false;
	}
	else {
		$('#password-status').empty();
	}

	var data ='username='+username.val()+'&password='+password.val();

	//alert(data);
	$.ajax({ 
		beforeSend: function(){
			$('#f_login_loading').mask('');
		},
		complete: function() {
			$('#f_login_loading').unmask('');
		},
		type: "POST", 
		url: 'http://www.msblmabl.com/ajax/login.php',
		data: data,
		dataType:'XML',
		success: function(xml) {
			//alert("success");
			$(xml).find('login').each(function() {
				
				var status = $(this).find("status").text();
				var firstname = $(this).find("firstname").text();
				var playerid = $(this).find("playerid").text();
				var email = $(this).find("email").text();

				if(status == "success"){
					var logindiv = $('#d_login');
					$('#f_login_error').empty();
					
				// set cookie 
				setCookie(email,playerid);
				// close dialog
				}
				else {
					if(status == "password failure"){
						$('#f_login_error').html("Password does not match. <a href='\"javascript:showResendForm();\"'>Reset Password</a>");
					}
					else {
						$('#f_login_error').html("Username not found. <a href=\"javascript:showResendForm();\">Reset Password</a>");
					}
				}

			});
		
		
		
		}
	});
}



function setCookie(email,playerid){
	//alert("cookie");
	//var cookieName = "MSBLCookie";
	//alert($.cookie('MSBLCookie'));
	$.cookie("MSBLCookie[0]", email, { expires: 90, path: '/', secure: false });
	$.cookie("MSBLCookie[1]", playerid, { expires: 90, path: '/', secure: false });
	//displayCookie();
	//alert('reload');
	window.location = "http://www.msblmabl.com/index.php";
}

function msbl_logoff(){
	//alert("delete cookie");

	$.cookie("MSBLCookie[0]", null, { expires: -1, path: '/', secure: false });
	$.cookie("MSBLCookie[1]", null, { expires: -1, path: '/', secure: false });
	//displayCookie();
	window.location = "http://www.msblmabl.com/index.php";
}


