var MivaMerchantDesign = {
	init: function () {
		var mivaScreen = document.body.id;
		if (MivaMerchantDesign[mivaScreen]) {
			$(document).ready(function () {MivaMerchantDesign[mivaScreen] (); }); // ---- If the function exists, run it, otherwise, don't do anything. ---- //
		}
		$(document).ready(function () {
		// ---- Allow Named Anchors To Work Without Full URL ---- //
			$('a[href^="\#"]').click(function (e) {
				e.preventDefault();
				document.location.hash = this.href.substr(this.href.indexOf('#') + 1);
			});
		// ---- Back to Top Controls ---- //
			$('a.scrollToTop').click(function (e) {
				$('html, body').animate({scrollTop: '0px'}, 'normal');
			});
		// ---- Clear Default Input Values ---- //
			$('#searchfield, .clearMe').focus(function () {
				if (this.value === this.defaultValue) {
					this.value = '';
				}
			}).blur(function () {
				if (this.value === '') {
					this.value = this.defaultValue;
				}
			});
		// ---- Newsletter Sign-Up Email Validation ---- //
			$('#newsletter-form').submit(function (e) {
				var email = $('#signup-email').val();
				if (!isValidEmailAddress(email)) {
					$('#newsletter-form .warning-message').text('Please enter your email address.').show().delay(3000).fadeOut('slow');
					$('#signup-email').val('');
					e.preventDefault();
				}
			});
		});
	},
	
	SFNT: function () {
	},
	
	CTGY: function () {
	},
	
	PROD: function () {
	},
	
	PRINTP: function () {
	// ---- Run Print Function On Page Load ---- //
		window.print();
	},
	
	PATR: function () {
	},
	
	BASK: function () {
	// ---- Remove Item From Basket (Compatible down to IE6) ---- //
		$('.basket label').click(function () {
			$(this).next('input').attr('checked', 'checked');
			if ($(this).next('input').is(":checked")) {
				$('#bask-form').submit();
			}
		});
	},
	
	ACAD: function () {
	},
	
	ACED: function () {
	},
	
	CTUS: function () {
	// ---- Additional Server Security To Help Against Spambots ---- //
		$('#noscript-warning').remove();
		$('#contact-form').show();
		$.get('../php/token.php', function (tkn) {
			$('#contact-form').append('<input type="hidden" name="mms" value="' + tkn + '" />');
		});
		
	// ---- Form Validation ---- //
		$('#contact-form').validate({
			errorContainer: '#contact-form div.error-message',
			errorLabelContainer: '#contact-form div.error-message ul',
			errorElement: 'li',
			rules: {
				contactName: {required: true, minlength: 2},
				contactEmail: {required: true, email: true},
				contactComment: {required: true, minlength: 2}
			},
			messages: {
				contactName: {required: 'Your Name Is Required', minlength: jQuery.format('Your Name must be a minimum of {0} characters!')},
				contactEmail: {required: 'Your Email Address Is Required', email: 'Your Email Address must be formatted like name@domain.com'},
				contactComment: {required: 'Comments or Questions Are Required', minlength: jQuery.format('Your Message must be a minimum of {0} characters!')}
			},
			highlight: function (element, errorClass) {
				$(element.form).find('label[for=' + element.id + ']').addClass(errorClass);
			},
			unhighlight: function (element, errorClass) {
				$(element.form).find('label[for=' + element.id + ']').removeClass(errorClass);
			}
		});
	},
	
	AFCL: function () {
	// ---- Toggle Show/Hide Password Lookup Form ---- //
		$('#forgot-password').hide();
		$('#show-forgot-password').click(function (e) {
			$('#forgot-password').slideToggle();
			e.preventDefault();
		});
	},
	
	LOGN: function () {
	// ---- Toggle Show/Hide Password Lookup Form ---- //
		$('#forgot-password').hide();
		$('#show-forgot-password').click(function (e) {
			$('#forgot-password').slideToggle();
			e.preventDefault();
		});
	},
	
	ORDL: function () {
	// ---- Toggle Show/Hide Password Lookup Form ---- //
		$('#forgot-password').hide();
		$('#show-forgot-password').click(function (e) {
			$('#forgot-password').slideToggle();
			e.preventDefault();
		});
	},
	
	ORHL: function () {
	// ---- Toggle Show/Hide Password Lookup Form ---- //
		$('#forgot-password').hide();
		$('#show-forgot-password').click(function (e) {
			$('#forgot-password').slideToggle();
			e.preventDefault();
		});
	},
	
	OCST: function () {
	// ---- Toggle Show/Hide Log-In Form ---- //
		$('#login-form').hide();
		$('#ocst-login').click(function (e) {
			$('#login-form').slideToggle();
			e.preventDefault();
		});
		
	// ---- Order Summary Controls ---- //
		$('#order-summary-steps').mvAccordion();
	},
	
	OSEL: function () {
	// ---- Order Summary Controls ---- //
		$('#order-summary-steps').mvAccordion();
	},
	
	OPAY: function () {
	// ---- Order Summary Controls ---- //
		$('#order-summary-steps').mvAccordion();
		
	// ---- Secondary Form Submit Button ---- //
		$('#opay-form-submit').click(function () {
			$('#opay-form').submit();
		});
	},
	
	INVC: function () {
	// ---- Order Summary Controls ---- //
		$('#order-summary-steps').mvAccordion();
	},
	
	ORDP: function () {
	// ---- Launch Printer Dialog ---- //
		window.print();
	},
	
	OUSL: function () {
	// ---- Toggle Show/Hide Log-In Form ---- //
		$('#login-form').hide(); //Hide Log-In Form
		$('#ocst-login').click(function (e) {
			$('#login-form').slideToggle(); //slideToggle Show/Hide Log-In Form
			e.preventDefault(); // cancel default behavior
		});
	// ---- Toggle Show/Hide Basket Contents ---- //
		$('#basket-contents').hide(); //Hide Basket Contents
		$('#show-basket').click(function (e) {
			$('#basket-contents').toggle(); //Show/Hide Basket Contents
			$('#show-basket').text(($('#show-basket').text() === 'Show Basket Contents') ? 'Hide Basket Contents' : 'Show Basket Contents'); //Toggle Link Text
			e.preventDefault(); // cancel default behavior
		});
	}
};
MivaMerchantDesign.init();
