/* Mailing List Form Validation */
function checkEmail()
{
	if (document.forms['email'].Email.value === 'name@address.com') {
		window.alert("Please enter a valid email address.");
		document.forms['email'].Email.value = '';
		document.forms['email'].Email.focus();
		return false;
	}

	if (document.forms['email'].Email.value !== 'name@address.com') {
		var strEmail = document.forms['email'].Email.value;
		var tomatch = /^.+@.+\..{2,3}$/;
		if (!tomatch.test(strEmail)) {
			alert("Please enter a valid email address.");
			document.forms['email'].Email.value = '';
			document.forms['email'].Email.focus();
			return false;
		}
	}

	else {
		document.forms['email'].submit();
		return true;
	}
}

/* Feedback Form Validation */
function checkFeedback()
{
	if (document.forms['feedback'].Name.value === "") {
		alert("Please enter your name.");
		document.forms['feedback'].Name.focus();
		return false;
	}
	if (document.forms['feedback'].addEmail.checked) {
		if (document.forms['feedback'].Email.value === "") {
			alert("Please enter a valid email address.");
			document.forms['feedback'].Email.focus();
			return false;
		}

		if (document.forms['feedback'].Email.value !== "") {
			var strEmail = document.forms['feedback'].Email.value;
			var tomatch = /^.+@.+\..{2,3}$/;
			if (!tomatch.test(strEmail)) {
				alert("Please enter a valid email address.");
				document.forms['feedback'].Email.value = '';
				document.forms['feedback'].Email.focus();
				return false;
			}
		}
	}
	if (document.forms['feedback'].Comments.value === "") {
		alert("Please enter your comments.");
		document.forms['feedback'].Comments.focus();
		return false;
	}
	else {
		return true;
	}
}

/* Gift Certificate Form Validation */
function checkGift() {
	if (document.forms['gift'].Amount.value === "") {
		alert("Please enter a Gift Amount.");
		document.forms['gift'].Amount.focus();
		return false;
	}
	
	if (document.forms['gift'].Amount.value <= 0) {
		alert("Gift Amount must be greater than zero.");
		document.forms['gift'].Amount.value = "";
		document.forms['gift'].Amount.focus();
		return false;
	}

	if (document.forms['gift'].RecipientFirstName.value === "") {
		alert("Please enter the Recipient's First Name.");
		document.forms['gift'].RecipientFirstName.focus();
		return false;
	}
	
	if (document.forms['gift'].RecipientLastName.value === "") {
		alert("Please enter the Recipient's Last Name.");
		document.forms['gift'].RecipientLastName.focus();
		return false;
	}
	
	if (document.forms['gift'].FirstName.value === "") {
		alert("Please enter your First Name.");
		document.forms['gift'].FirstName.focus();
		return false;
	}
	
	if (document.forms['gift'].LastName.value === "") {
		alert("Please enter your Last Name.");
		document.forms['gift'].LastName.focus();
		return false;
	}
		
	if (document.forms['gift'].Phone.value === "") {
		alert("Please enter your Phone Number.");
		document.forms['gift'].Phone.focus();
		return false;
	}
	
	if (document.forms['gift'].Phone.value !== "") {
		if(document.forms['gift'].Phone.value.search(/\d{3}\-\d{3}\-\d{4}/)===-1) {
			alert("The Phone Number must be in ###-###-#### format.");
			document.forms['gift'].Phone.value = "";
			document.forms['gift'].Phone.focus();
			return false; 
		}
	}
	
	if((document.forms['gift'].Delivery[0].checked===false) && 
	(document.forms['gift'].Delivery[1].checked===false)) {
		alert("Please select a Delivery Method.");
		document.forms['gift'].Delivery[0].focus();
		return false; 
	}
	
	if (document.forms['gift'].Delivery[1].checked===true) {
		if (document.forms['gift'].Ship_FirstName.value === "") {
			alert("Please enter the Shipping First Name.");
			document.forms['gift'].Ship_FirstName.focus();
			return false;
		}
		
		if (document.forms['gift'].Ship_LastName.value === "") {
			alert("Please enter the Shipping Last Name.");
			document.forms['gift'].Ship_LastName.focus();
			return false;
		}
	
		if (document.forms['gift'].Ship_Address.value === "") {
			alert("Please enter the Shipping Address.");
			document.forms['gift'].Ship_Address.focus();
			return false;
		}	
	
		if (document.forms['gift'].Ship_City.value === "") {
			alert("Please enter the Shipping City.");
			document.forms['gift'].Ship_City.focus();
			return false;
		}
	
		if (document.forms['gift'].Ship_State.value === "") {
	   		alert("Please select the Shipping State.");
			document.forms['gift'].Ship_State.focus();
			return false;
		}
	
		if (document.forms['gift'].Ship_Zip.value === "") {
			alert("Please enter the Shipping Zip Code.");
			document.forms['gift'].Ship_Zip.focus();
			return false;
		}
	}
	
	else {
		return true;
	}
}

/* Only Numeric Values  */
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	}
	else {
		return true;
	}
}

/* Show Shipping Information */
function showShipping(position) {
	document.getElementById("shipping_info").style.display = "none"
	document.getElementById(position).style.display = "block"
}

/* Hide Shipping Information */
function hideShipping(position) {
	document.getElementById("shipping_info").style.display = "none"
	document.getElementById(position).style.display = "none"
	document.forms['gift'].Ship_FirstName.value = '';
	document.forms['gift'].Ship_LastName.value = '';
	document.forms['gift'].Ship_Address.value = '';
	document.forms['gift'].Ship_Address2.value = '';
	document.forms['gift'].Ship_City.value = '';
	document.forms['gift'].Ship_State.selectedIndex = 0;
	document.forms['gift'].Ship_Zip.value = '';
}

/* New Window Opener */
function openWin(name,t,w,h)
{
	newWin = window.open('','','top=0,left=0,width='+w+',height='+h+'');
	if (!newWin.opener) newWin.opener = self;
	with (newWin.document) 	{
		open();
		write('<html>');
		write('<head>');
		write('<title>' + t + '</title>');
		write('</head>');
		write('<body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" 	onLoad="self.focus()">');
		write('<a href="javascript:self.close();"><img src="images/' + name + '" width="' + w + '" height="' + h + '" border="0" title="Close Window" alt="Close Window"></a>');
		write('</body>');
		write('</html>');
		close();
	}
	return false;
}
