

function checkForm_giftcert_order()
{
	if (document.forms["giftcert_order"].recipient_name.value == "") {
		alert("Recipient's name field empty.");
	} else if (validateEmail(document.forms["giftcert_order"].recipient_email.value)) {
		alert("Invalid Recipient email address.");
	} else if (document.forms["giftcert_order"].giftcert_message.value == "") {
		alert("Message field empty.");
	} else if (document.forms["giftcert_order"].sender_name.value == "") {
		alert("Sender's name field empty.");
	} else if (validateEmail(document.forms["giftcert_order"].sender_email.value)) {
		alert("Invalid Sender email address.");
	} else {
		document.forms["giftcert_order"].submit();
	}
}
function validateEmail(email)
{
	var result = true;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0)
	{
		var pindex = theStr.indexOf(".",index);
		if ((pindex > index+1) && (theStr.length > pindex+1))
			result = false;
	}
	return result;
}

function checkValue()
{
	var minValue = 25.00;
	var maxValue = 750.00;
	var ok = false;
	
	if (document.giftcert_order.giftcert_price.options[document.giftcert_order.giftcert_price.selectedIndex].text == "Other amount")
	{
		if (document.giftcert_order.other_amount.value == "")
		{
			alert("You must enter an amount for the Gift Certificate");
		} else {
			if (isNaN(document.giftcert_order.other_amount.value))
			{
				alert("You must enter a valid number!");
			} else {
				if (document.giftcert_order.other_amount.value.indexOf(".") != -1)
				{
						alert("Do not enter any decimal places!");
				} else {
					if (document.giftcert_order.other_amount.value < minValue || document.giftcert_order.other_amount.value > maxValue)
					{
						alert("You cannot order a Gift Certificate below the minimum value of $"+minValue+" or above the maximum value of $"+maxValue+"!");
					} else {
						document.giftcert_order.prod_price.value = document.giftcert_order.other_amount.value;
						ok = true;
					}
				}
			}
		}
	} else {
		if (document.giftcert_order.other_amount.value != "")
		{
			alert("You cannot have an other amount and a selected amount!");
		} else {
			document.giftcert_order.prod_price.value = document.giftcert_order.giftcert_price.options[document.giftcert_order.giftcert_price.selectedIndex].value;
			ok = true;
		}
	}
	
	if (ok == true)
	{
		checkForm_giftcert_order();
	}
}

