document.write('<script type="text/javascript" src="/js/AC_OETags.js"></scr' + 'ipt>');

// ------------------------------------------------------------------------------------

var Dashboard = {

	defaultButtonLoadingString: "One Moment...",
	defaultButtonLoadingImage: "/shared/images/loading_icon/loading_circle_small.gif",
	defaultDarkButtonLoadingImage: "/shared/images/loading_icon/loading_bars_trans.gif",
	toggledButtonID:"",
	businessID:"",
	businessName:"",
	memberID:"",

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	setBusinessID: function(id) {
		Dashboard.businessID = id;
		Dashboard.Business.id = id;
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	setBusinessName: function(n) {
		Dashboard.businessName = n;
		Dashboard.Business.name = n;
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	setMemberID: function(id) {
		Dashboard.memberID = id;
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	toggleButtonLinkLoad: function (id, str, force) {
		if (id != null) {
			Dashboard.toggledButtonID = id;
		} else {
			id = Dashboard.toggledButtonID;
		}
		if (str == null) {
			str = this.defaultButtonLoadingString;
			maybeSaveButton = /^save/i;
			if (maybeSaveButton.test(id)) {
				str = "Saving...";
			}
		}
		if (($(id).oldHTML == null) || (force != null)) {
			if (force == null) {
				$(id).oldHTML = $(id).innerHTML;
			}
			
			if ($(id).hasClassName('blueButtonLink')) {
				img = this.defaultDarkButtonLoadingImage;
				iStyle = "vertical-align:baseline;";
			} else {
				img = this.defaultButtonLoadingImage;
				iStyle = "";
			}
			
			$(id).update("<img src='" + img + "' class='buttonIcon' style='"+iStyle+"'/>"+str);
		} else {
			$(id).update($(id).oldHTML);
			$(id).oldHTML = null;
		}

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	toggleTestModeForBusiness: function(bid) {
		$('businessTestModeProgress').show();
		new Ajax.Request('/dashboard/ajax/toggleTestModeForBusiness.php', {
			method: 'post',
			parameters: {
				business_id:bid
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				$('businessTestModeProgress').hide();
				if (response.status == "success") {

					$('businessTestMode').value = response.mode;

					if ($F('businessTestMode') == "yes") {
						$('businessTestModeToggle').setStyle('background-position:0px 0px;');
						$('businessTestModeProgress').setStyle('right:12px;top:9px;');
					} else {
						$('businessTestModeToggle').setStyle('background-position:0px -28px;');
						$('businessTestModeProgress').setStyle('right:70px;top:9px;');
					}

				} else {
					alert("An error occurred: " + response.reason);
				}
			},
			onFailure: function(transport) {
				$('businessTestModeProgress').hide();
				alert('An unknown error occurred.');
			}
		});

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	canUseFlash: function() {
/*
		var requiredMajorVersion = 8;
		var requiredMinorVersion = 0;
		var requiredRevision = 0;
*/
		var hasReqestedVersion = DetectFlashVer(8, 0, 0);
		return hasReqestedVersion;
	}


}

// ------------------------------------------------------------------------------------

Dashboard.Business = {

	id:null,
	name:null
}

// ------------------------------------------------------------------------------------

Dashboard.Button = {

	toggleLoad: function (id, str, force) {
		Dashboard.toggleButtonLinkLoad(id, str, force);
		$(id).resetButton = function() {
			Dashboard.Button.resetLoad(id);
		};
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	resetLoad: function (id, str, force) {
		Dashboard.toggleButtonLinkLoad(id);
	}

}

// ------------------------------------------------------------------------------------

Dashboard.Overlay = {

	overlayDivElement: 'overlay',

	show: function() {
		if (facebox != null) {
			if ($(Dashboard.Overlay.overlayDivElement) && !$(Dashboard.Overlay.overlayDivElement).visible()) {
				$(Dashboard.Overlay.overlayDivElement).appear({duration:.5,from:0,to:.5});
			}
		}
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	hide: function() {
		if ($(Dashboard.Overlay.overlayDivElement) && $(Dashboard.Overlay.overlayDivElement).visible()) {
			$(Dashboard.Overlay.overlayDivElement).fade({duration:.5,from:0.5,to:0});
		}
	}
}

// ------------------------------------------------------------------------------------

Dashboard.Facebox = {

	defaultLoadingString: "Loading...",

	defaultLoadingImage: "/shared/images/loading_icon/loading_fb_blue.gif",

	contentDivID: "facebox_content",
	faceboxDivID: "facebox",

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	open: function(opts) {

		if (facebox == null) {
			alert("The page has not finished loading. Please try again in a moment.");
			return;
		}
		
		if (opts.overlay) {
			Dashboard.Overlay.show();
		}

		facebox.reveal();
		if ((opts != null) && opts.w && opts.h) {
			this.resize(opts.w, opts.h);
		}
		this.showLoading(opts.loadingString);
		
		Event.observe(document, 'keyup', function(event) {
			if (event.keyCode == Event.KEY_ESC) {
				if ($('cancelButton') && $('cancelButton').onclick) {
					$('cancelButton').onclick();
				} else {
					Dashboard.Facebox.close();
				}
			}
			return false;
		});
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	close: function() {
		Dashboard.Overlay.hide();
		facebox.close();
		Event.stopObserving(document, 'keyup');
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	isOpen: function() {
		return $('facebox').visible();
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	hideFooter: function() {
		$$('#' + this.faceboxDivID + ' .footer')[0].hide();
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	showFooter: function() {
		Dashboard.Overlay.hide();
		$$('#' + this.faceboxDivID + ' .footer')[0].show();
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	showError: function(title, message) {
		$(Dashboard.Facebox.contentDivID).update("<h1>"+title+"</h1><div style=\"font-size:12pt;\">"+message+"</div>");
		Dashboard.Overlay.hide();
		Dashboard.Facebox.showFooter();
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	loadAjax: function(opts) {
		this.open(opts);

		new Ajax.Updater(Dashboard.Facebox.contentDivID, opts.url, {
			method: 'post',
			parameters: opts.parameters,
			evalScripts:true,
			onComplete:function(transport) {
				Dashboard.Facebox.hideFooter();
				if (opts.onComplete) {
					opts.onComplete();
				}
			}
		});

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	showLoading: function (str) {
		if (str == null) {
			str = this.defaultLoadingString;
		}
		$(this.contentDivID).innerHTML = '<div style="text-align:center;font-weight:bold;font-size:12pt;">'+str+'<br><img src="' + this.defaultLoadingImage + '"></div>';

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	resize: function (width, top, animate) {
		if (top == null) {
			top = "150";
		}
		if (animate) {
			new Effect.Morph(this.contentDivID, {
				style: {
					width: width+'px'
				}, // CSS Properties

				duration: 0.4 // Core Effect properties

			});
		} else {
			$(this.contentDivID).setStyle({width:width+'px'});
		
		}
		var elt         = $(this.faceboxDivID);

		// retrieve required dimensions
		var eltDims     = elt.getDimensions();
		var browserDims = document.body.getDimensions();

		// calculate the center of the page using the browser and element dimensions
	//	var y  = (browserDims.height - eltDims.height) / 2;
		var x = (browserDims.width - eltDims.width) / 2;

		// set the style of the element so it is centered
		var styles = { position : 'absolute',
			top      : top+'px',
			left     : x + 'px' };

		elt.setStyle(styles);
		elt.scrollTo();

	}
}

// ------------------------------------------------------------------------------------

Dashboard.LoadingMessage = {

	defaultLoadingString: "One Moment...",

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	show: function(msg) {

		if (!$('moduleLoading')) {

			if (Module.contentContainer == null) {
				return;
			}

			el = Module.contentContainer;
			dimensions = $(el).getDimensions();
			
			$(el).insert({before:'<div id="moduleLoading" style="display:none;float:right;width:'+(dimensions.width - 10) +'px;"><img src="/shared/images/loading_icon/loading_circle_small_white.gif" style="margin-right:5px;vertical-align:text-bottom;"/><span id="loadingMessage">One Moment...</span></div>'});

		}

		a = $$('#moduleLoading #loadingMessage');
		if (a.length == 1) {
			if (msg != null) {
				a[0].update(msg);

			} else {
				a[0].update(this.defaultLoadingString);

			}
		}

		$('moduleLoading').appear({duration:.2});
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	hide: function() {
		if ($('moduleLoading')) {
			$('moduleLoading').hide();
		}
	}

}




// ------------------------------------------------------------------------------------


CharacterCounter = Class.create({
	maxMessageLength: '',
	textField: '',
	counterField: '',

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	initialize: function(opts) {
		this.textField = opts.textField;
		this.counterField = opts.counterField;

		this.changeMaxMessageLength(opts.maxMessageLength);
		new Form.Element.Observer(this.textField, 0.1, this.checkMessageLength.bind(this));

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	availableMessageLength: function() {
		return this.maxMessageLength - this.currentMessageLength();
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	currentMessageLength: function() {
		return $(this.textField).value.length;
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	checkMessageLength: function(e,v) {
		if (v == null) {
			return;
		}
		if (v.length > this.maxMessageLength) {
			$(this.textField).value = v.substring(0, this.maxMessageLength);
		}
		$(this.counterField).update($F(this.textField).length + ' / '+this.maxMessageLength+' characters');

	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	changeMaxMessageLength: function(n, pulse) {
		this.maxMessageLength = n;
		this.checkMessageLength(null, $F(this.textField));
		if ((pulse == null) || (pulse == true)) {
	//		Effect.Pulsate('charcount', {from:0.0});
		}
	},

	// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -

	canInsertText: function(str) {
		return (($F(this.textField).length + str.length) <= this.maxMessageLength);
	}
});

// =============================================================================


var Site = {

	memberAccessUrl: "/member_access2.php"
}

// =============================================================================

var Business = {


}

// =============================================================================

var Member = {

	login: function(user, pwd, b_id) {

		if (user == null) {
			user = $F('login_user');
		}
		if (pwd == null) {
			pwd = $F('login_password');
		}
		if (b_id == null) {
			b_id = 'loginButton';
		}
		if ($('http_referer')) {
			refer = $F('http_referer');
		} else {
			refer = null;

		}

		if ((user == "") || (pwd == "")) {
			alert("Please enter your password as well as an email address or phone number!");
			return;
		}

		Dashboard.toggleButtonLinkLoad(b_id);

		new Ajax.Request('/memberaccess/ajax/do_login.php', {
			method: 'post',
			parameters: {
				user:			user,
				password:			pwd,
				http_referer: 		refer
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				if (response.status == "success") {
					if ($('existingDiv')) {

						if (response.redirect != "") {
							self.location.href = response.redirect;
						} else {
							Dashboard.toggleButtonLinkLoad();
						}
					} else {
						self.location.href = self.location.href;
					}
			} else {
					Dashboard.toggleButtonLinkLoad();
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	showForgottenPassword: function() {
		Effect.BlindDown('forgottenPasswordDiv', {duration:.3});
		Effect.BlindUp('loginDiv', {duration:.3});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	cancelForgottenPassword: function() {
		Effect.BlindDown('loginDiv', {duration:.3});
		Effect.BlindUp('forgottenPasswordDiv', {duration:.3});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	doForgottenPassword: function() {

		if ($F('forgot_email') == "") {
			alert("Please be sure to enter your email address!");
			return;
		}

		Dashboard.toggleButtonLinkLoad('sendButton');
		new Ajax.Request('/memberaccess/ajax/forgotten_password.php', {
			method: 'post',
			parameters: {
				email:$F('forgot_email')
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				Dashboard.toggleButtonLinkLoad();
				if (response.status == "success") {
					$('login_user').value = $F('forgot_email');
					$('login_password').value = '';
					Member.cancelForgottenPassword();
					alert(response.reason);

				} else {
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	register: function() {
		needsFields = 0;
		['areacode','firstname','lastname','email', 'password'].each(function(e) {

			if ($('register_'+e).value == "") {
				needsFields++;
				$('register_'+e).addClassName('highlightedField');
				if ($('register_'+e).onfocus != null) {
					$('register_'+e).onfocus = function() {
						$('register_'+e).removeClassName('highlightedField');
					}
				}
			}
		});

		if (needsFields > 0) {
			alert("To register, you must please complete all the required fields.");
			return;
		}

		emailCheck = /^([\w_\-\.])+\@([\w_\-\.])+(\.([A-Za-z]{2,4}))+$/i;

		if (!emailCheck.test($F('register_email'))) {
			alert("Please enter a valid email address.");
			return;
		}

		Dashboard.toggleButtonLinkLoad('registerButton');
		new Ajax.Request('/memberaccess/ajax/do_register.php', {
			method: 'post',
			parameters: $('registerForm').serialize(),
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				if (response.status == "loginExisting") {
					if (response.redirect != "") {
						self.location.href = response.redirect;
					}
				} else if (response.status == "success") {
					if ($('newDiv')) {
						whichDiv = 'newDiv';
					} else {
						whichDiv = 'facebox_content';
					}
					new Ajax.Updater(whichDiv, '/memberaccess/ajax/show_registration_success.php', {
						method: 'post',
						parameters: {
							email:$F('register_email')
						},
						evalScripts:true,
						onComplete: function(transport) {
						},
						onFailure: function(transport) {
							Dashboard.toggleButtonLinkLoad();
							alert('An unknown error occurred.');
						}
					});
				} else {
					Dashboard.toggleButtonLinkLoad();
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	resendConfirmationCode: function (email) {
		emailCheck = /^([\w_\-\.])+\@([\w_\-\.])+(\.([A-Za-z]{2,4}))+$/i;

		if (!emailCheck.test(email)) {
			alert("Please enter a valid email address.");
			return;
		}
		Dashboard.toggleButtonLinkLoad('resendButton');
		new Ajax.Request('/memberaccess/ajax/resend_confirmation_code.php', {
			method: 'post',
			parameters: {
				email:email
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				Dashboard.toggleButtonLinkLoad();
				if (response.status == "success") {
					if ($('confirmCode')) {
						$('confirmCode').value = "";
					}
					alert("A new confirmation code has been sent to the email address "+email+".");
				} else {
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});

	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	showRegistrationWindow: function () {
		if (!$('newDiv')) {
			Dashboard.Overlay.show();
			Dashboard.Facebox.loadAjax({
				url:		'/memberaccess/ajax/show_register.php',
				w:400,
				h:100
			});
		} else {
			$('register_areacode').focus();
			Effect.Pulsate('newDiv', {pulses:3, duration:1});
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	showLoginWindow: function () {
		if (!$('existingDiv')) {
			Dashboard.Overlay.show();
			Dashboard.Facebox.loadAjax({
				url:		'/memberaccess/ajax/show_login.php',
				w:400,
				h:100
			});
		} else {
			$('login_user').focus();
			Effect.Pulsate('existingDiv', {pulses:3, duration:1});
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	showForgottenPasswordWindow: function () {
		if (!$('existingDiv')) {
			Dashboard.Overlay.show();
			Dashboard.Facebox.loadAjax({
				url:		'/memberaccess/ajax/show_login.php',
				w:400,
				h:100,
				parameters:{
					show_pwd:'yes'
				}
			});
		} else {
			$('loginDiv').hide();
			$('forgottenPasswordDiv').show();
			$('forgot_email').focus();
			Effect.Pulsate('existingDiv', {pulses:3, duration:1});
		}
	}

}

// =============================================================================

Member.Account = {

	showDetails: function () {
		Dashboard.Overlay.show();
		Dashboard.Facebox.loadAjax({
			url:		'/memberaccess/ajax/show_account_details.php',
			w:600,
			h:100,
			parameters:{
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	showPanel: function (which) {

		div_id = "panel_"+which;
		button_id = "flipperButton_"+which;
		$$('.accountDetailsPanel').each(function(e) {
			e.hide();
		})

		$$('.buttonLinkFlipper').each(function(e) {
			e.removeClassName('selectedButtonLinkFlipper');
			e.setStyle({'font-weight':'normal','border-bottom':'1px solid #ccc;'});
		});

		if (which == "details") {
			$('saveDetailsButton').show();
		} else {
			$('saveDetailsButton').hide();

		}

		$(div_id).show();
		$(button_id).addClassName('selectedButtonLinkFlipper');

	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	saveDetails: function () {
		Dashboard.toggleButtonLinkLoad('saveDetailsButton');
		new Ajax.Request('/memberaccess/ajax/save_account_details.php', {
			method: 'post',
			parameters: {
				member_id:$F('member_id'),
				data:$('details_form').serialize()
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				if (response.status == "success") {
					Dashboard.Facebox.close();
					alert("Your account details have been saved.");
				} else {
					Dashboard.toggleButtonLinkLoad();
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	confirmMobileNumber: function () {
		if ($F('MobileConfirmNumber') == "") {
			alert("Please enter your confirmation code.");
			return;
		}
		Dashboard.toggleButtonLinkLoad('confirmMobileNumberButton');
		new Ajax.Request('/memberaccess/ajax/confirm_mobile_number.php', {
			method: 'post',
			parameters: {
				member_id:$F('member_id'),
				confirmation_code:$F('MobileConfirmNumber')
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				if (response.status == "success") {
					Dashboard.Facebox.close();
					alert("Your mobile number has been confirmed.");
				} else {
					Dashboard.toggleButtonLinkLoad();
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	changeEmailAddress: function () {

		if ($F('new_email') == "") {
			alert("Please enter a new email address");
			return;
		}
		emailCheck = /^([\w_\-\.])+\@([\w_\-\.])+(\.([A-Za-z]{2,4}))+$/i;

		if (!emailCheck.test($F('new_email'))) {
			alert("Please enter a valid email address");
			return;
		}

		Dashboard.toggleButtonLinkLoad('changeEmailButton');
		new Ajax.Request('/memberaccess/ajax/do_change_email_request.php', {
			method: 'post',
			parameters: {
				member_id:$F('member_id'),
				new_email:$F('new_email')
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				Dashboard.toggleButtonLinkLoad();
				if (response.status == "success") {
					alert("To complete your change of email address, we have sent an email to the new address you entered ("+$F('new_email')+"). To confirm your change, follow the link included in that message.");
				} else {
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});

	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	removeMobileNumber: function () {
		if (confirm("Are you sure you want to remove your mobile device?")) {
			Dashboard.toggleButtonLinkLoad('removeMobileNumberButton');
			new Ajax.Request('/memberaccess/ajax/remove_mobile_number.php', {
				method: 'post',
				parameters: {
					member_id:$F('member_id')
				},
				onSuccess: function(transport) {
					var response = transport.responseText.evalJSON();

					if (response.status == "success") {
						Dashboard.Facebox.close();
						alert("Your mobile number has been removed.");
					} else {
						Dashboard.toggleButtonLinkLoad();
						alert(response.reason);
					}
				},
				onFailure: function(transport) {
					Dashboard.toggleButtonLinkLoad();
					alert('An unknown error occurred.');
				}
			});
		}
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	changePassword: function () {
		if (($F('password_1') == "") || ($F('password_2a') == "") || ($F('password_2b') == "")) {
			alert("Please enter your old password and your new password.");
			return;
		}
		if ($F('password_2a') != $F('password_2b')) {
			alert("Your new passwords do not match.");
			return;
		}
		goodPassword = /.{6,}/;
		if (!goodPassword.test($F('password_2a'))) {
			alert("Please choose a password of at least 6 characters.");
			return;
		}
		Dashboard.toggleButtonLinkLoad('changePasswordButton');
		new Ajax.Request('/memberaccess/ajax/change_password.php', {
			method: 'post',
			parameters: {
				member_id:$F('member_id'),
				old_password:$F('password_1'),
				new_password:$F('password_2a')
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				Dashboard.toggleButtonLinkLoad();
				if (response.status == "success") {
					alert("Your password has been changed.");
				} else {
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	changeSecurityQuestion: function () {
		if (($F('security_question') == "") || ($F('security_answer') == "")) {
			alert("Please select a question and enter an answer.");
			return;
		}
		Dashboard.toggleButtonLinkLoad('changeSecurityQuestionButton');
		new Ajax.Request('/memberaccess/ajax/change_security_question.php', {
			method: 'post',
			parameters: {
				member_id:$F('member_id'),
				question:$F('security_question'),
				answer:$F('security_answer')
			},
			onSuccess: function(transport) {
				var response = transport.responseText.evalJSON();

				Dashboard.toggleButtonLinkLoad();
				if (response.status == "success") {
					alert("Your security question and answer have been changed.");
				} else {
					alert(response.reason);
				}
			},
			onFailure: function(transport) {
				Dashboard.toggleButtonLinkLoad();
				alert('An unknown error occurred.');
			}
		});
	},

	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

	deactivate: function () {
		if (confirm("Are you sure you want to deactivate your account?")) {
			new Ajax.Request('/memberaccess/ajax/deactivate_account.php', {
				method: 'post',
				parameters: {
					member_id:$F('member_id')
				},
				onSuccess: function(transport) {
					var response = transport.responseText.evalJSON();
		
					if (response.status == "success") {
						self.location.href = "/logout.php";
					} else {
						alert(response.reason);
					}
				},
				onFailure: function(transport) {
					alert('An unknown error occurred.');
				}
			});		
		}
	}
}

