// JavaScript Document

// Validate Account Update Form
function validateUpdateForm()
{
	var newEmail = $('#txtNewEmail').val();
	var newEmailConfirm = $('#txtNewEmailConfirm').val();
	var newPass = $('#txtNewPwd').val();
	var newPassConfirm = $('#txtNewPwdConfirm').val();

	if (newEmail != "" && newEmailConfirm != "" && newPass != "" && newPassConfirm != "")
	{
		return true;
	}
	else if (newEmail == "" || newEmailConfirm == "")
	{
		(newEmail == "") ? $('#txtNewEmailErr').css({visibility:'visible'}) : $('#txtNewEmailConfirmErr').css({visibility:'visible'});
		alert("please enter your email address in both boxes where specified");
		return false;
	}
	else if (newPass == "" || newPassConfirm == "")
	{
		(newPass == "") ? $('#txtNewPwdErr').css({visibility:'visible'}) : $('#txtNewPwdConfirmErr').css({visibility:'visible'});
		alert("please enter your password in both boxes where specified");
		return false;
	}
}

// Validate the Login Forms input fields
function validateLoginForm()
{
	var yourEmail = $('#loginEmail').val();
	var yourPwd = $('#loginPassword').val();
	
	if (yourEmail != "" && yourPwd != "")
	{
		return true;	
	}
	else if (yourEmail == "" && yourPwd == "")
	{
		$('#txtLoginEmail').css({visibility:'visible'});
		$('#txtLoginPwd').css({visibility:'visible'});
		alert("please enter your email address and password to login");
		return false;
	}
	else if (yourEmail == "")
	{
		$('#txtLoginEmail').css({visibility:'visible'});
		alert("please enter your email address in order to login");
		return false;
	}
	else if (yourPwd == "")
	{
		$('#txtLoginPwd').css({visibility:'visible'});
		alert("please enter your password in order to login");
		return false;
	}
}

// Validate the Registration Forms input fields
function validateRegistrationForm()
{
	var firstName = $('#firstName').val();
	var lastName = $('#lastName').val();
	var emailAddr = $('#emailAddress').val();
	var emailAddrConf = $('#reEmailAddress').val();
	var pwd = $('#password').val();
	var pwdConf = $('#rePassword').val();
	
	if (firstName != "" && lastName != "" && emailAddr != "" && emailAddrConf != "" && pwd != "" && pwdConf != "")
	{
		return true;
	}
	else if (firstName == "" && lastName == "" && emailAddr == "" && emailAddrConf == "" && pwd == "" && pwdConf == "")
	{
		$('#txtFirstNameErr').css({visibility:'visible'});
		$('#txtLastNameErr').css({visibility:'visible'});
		$('#txtEmailAddrErr').css({visibility:'visible'});
		$('#txtEmailAddrConfErr').css({visibility:'visible'});
		$('#txtPasswordErr').css({visibility:'visible'});
		$('#txtPasswordConfErr').css({visibility:'visible'});
		alert("all fields marked with a * are required");
		return false;
	}
	else if (firstName == "")
	{
		$('#txtFirstNameErr').css({visibility:'visible'});
		alert("* please enter your first name");
		return false;
	}
	else if (lastName == "")
	{
		$('#txtLastNameErr').css({visibility:'visible'});
		alert("* please enter your last name");
		return false;
	}
	else if (emailAddr == "" || emailAddrConf == "")
	{
		$('#txtEmailAddrErr').css({visibility:'visible'});
		$('#txtEmailAddrConfErr').css({visibility:'visible'});
		alert("* please enter your email address in both boxes where specified");
		return false;
	}
	else if (pwd == "" || pwdConf == "")
	{
		$('#txtPasswordErr').css({visibility:'visible'});
		$('#txtPasswordConfErr').css({visibility:'visible'});
		alert("* please enter your password in both boxes where specified");
		return false;
	}
}

// Validate the Forgotten Password form input fields
function validateForgottenForm()
{
	var forgottenEmail = $('#txtForgottenEmail').val();
	
	if (forgottenEmail != "")
	{
		return true;
	}
	else if (forgottenEmail == "")
	{
		$('#txtForgottenEmailErr').css({visibility:'visible'});
		
		//alert("* your email address is required in order for us to email you your forgotten password");
		return false;
	}
}

// Method to replace a given value with numbers only - keyUp/keyDown events
function numbersOnly(el)
{
	el.value = el.value.replace(/[^0-9]/g, "");
}

// Validate the Feedback Form input fields
function validateFeedback()
{
	var userEmail = $('#userEmail').val();
	var userComment = $('#userComment').val();
	
	if (userEmail != "" && userComment != "")
	{
		return true;
	}
	else if (userEmail == "")
	{
		$('#txtUserEmailErr').css({visibility:'visible'});
		alert("* your email address is required");
		return false;
	}
	else if (userComment == "")
	{
		$('#txtUserCommentErr').css({visibility:'visible'});
		alert("* a comment is required");
		return false;
	}
	
}

// Prompt user with an 'are you sure' message before removing a Greeting Card
function greetingCardDel(url)
{
	if (confirm("Are you sure you want to remove this Greeting Card from your order?", "Confirm"))
	{
		window.location.href = url;
	}
}

// Method to limit the amount of text in a given input field - keyUp/keyDown events
function limitText(limitField, limitCount, limitNum) 
{
	if (limitField.value.length > limitNum) 
	{
		limitField.value = limitField.value.substring(0, limitNum);
	} 
	else 
	{
		limitCount.value = limitNum - limitField.value.length;
	}
}

// Prompt user with an 'are you sure' message before removing the voucher
function removeVoucher()
{
	if (confirm("Are you sure you want to remove your voucher from your order?", "Confirm"))
	{
		return true;
	}
	
	return false;
}

// Toggle method for the left navigation arrows for collapseable functionality
function toggleNav(showOrHide, navSection, animate, levelDeep) {
	
	switch (navSection) {
		case 'jewellery':
			if (showOrHide == "show") {
				// update the arrow img
				if (levelDeep == null || levelDeep == 0) {
					$('#jewellery-toggle img').attr("src", "images/left-arrow-down-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#jewellery-toggle img').attr("src", "../images/left-arrow-down-btn.jpg");
				}
				
				$('#left-nav-jewellery-body ul').fadeIn();
				$('#left-nav-jewellery-body').animate({
														height: "175px"
													  }, 800, "easeOutCubic");
			}
			else {
				if (levelDeep == null || levelDeep == 0) {
					$('#jewellery-toggle img').attr("src", "images/left-arrow-up-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#jewellery-toggle img').attr("src", "../images/left-arrow-up-btn.jpg");
				}
				
				if (animate) {
					$('#left-nav-jewellery-body ul').fadeOut();
					$('#left-nav-jewellery-body').animate({
															height: "10px"
														  }, 800, "easeOutCubic");
				}
				else {
					$('#left-nav-jewellery-body ul').hide();
					$('#left-nav-jewellery-body').css("height", "10px");
				}
			}
		break;
		case 'fredbennett': {
			if (showOrHide == "show") {
				// update the arrow img
				if (levelDeep == null || levelDeep == 0) {
					$('#fredbennett-toggle img').attr("src", "images/left-arrow-down-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#fredbennett-toggle img').attr("src", "../images/left-arrow-down-btn.jpg");
				}
				
				$('#left-nav-fred-bennett-body ul').fadeIn();
				$('#left-nav-fred-bennett-body').animate({
														height: "155px"
													  }, 1000, "easeOutCubic");
			}
			else {
				if (levelDeep == null || levelDeep == 0) {
					$('#fredbennett-toggle img').attr("src", "images/left-arrow-up-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#fredbennett-toggle img').attr("src", "../images/left-arrow-up-btn.jpg");
				}
				
				if (animate) {
					$('#left-nav-fred-bennett-body ul').fadeOut();
					$('#left-nav-fred-bennett-body').animate({
		   												    height: "10px"
														  }, 1000, "easeOutCubic");
				}
				else {
					$('#left-nav-fred-bennett-body ul').hide();
					$('#left-nav-fred-bennett-body').css("height", "10px");
				}
			}
		}
		break;
		case 'dfordiamond': {
			if (showOrHide == "show") {
				// update the arrow img
				if (levelDeep == null || levelDeep == 0) {
					$('#dfordiamond-toggle img').attr("src", "images/left-arrow-down-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#dfordiamond-toggle img').attr("src", "../images/left-arrow-down-btn.jpg");
				}
				
				$('#left-nav-d-for-diamond-body ul').fadeIn();
				$('#left-nav-d-for-diamond-body').animate({
														height: "135px"
													  }, 1000, "easeOutCubic");
			}
			else {
				if (levelDeep == null || levelDeep == 0) {
					$('#dfordiamond-toggle img').attr("src", "images/left-arrow-up-btn.jpg");
				}
				else if (levelDeep == 1) {
					$('#dfordiamond-toggle img').attr("src", "../images/left-arrow-up-btn.jpg");
				}
				
				if (animate) {
					$('#left-nav-d-for-diamond-body ul').fadeOut();
					$('#left-nav-d-for-diamond-body').animate({
		   												    height: "10px"
														  }, 1000, "easeOutCubic");
				}
				else {
					$('#left-nav-d-for-diamond-body ul').hide();
					$('#left-nav-d-for-diamond-body').css("height", "10px");
				}
			}
		}
		break;
		default:
		break;
	}
}
