// JavaScript Document
function giftCardValidation(frmGiftCard)
{

if (frmGiftCard.qty.value == "")
  {
    alert("Please enter quantity of gift cards you would like to purchase.");
    frmGiftCard.qty.focus();
    return (false);
  }
if (frmGiftCard.amount.value == "")
  {
    alert("Please enter amount for each gift card.");
    frmGiftCard.amount.focus();
    return (false);
  }
if (frmGiftCard.total.value == "")
  {
    alert("Please enter total amount of gift card(s).");
    frmGiftCard.total.focus();
    return (false);
  }

if (frmGiftCard.purchaser.value == "")
  {
    alert("Please enter name of person we may contact for credit card information to finalize your purchase.");
    frmGiftCard.purchaser.focus();
    return (false);
  }
if (frmGiftCard.phone1.value == "")
  {
    alert("Please enter phone number.");
    frmGiftCard.phone1.focus();
    return (false);
  }
if (frmGiftCard.email.value == "")
  {
    alert("Please enter email address.");
    frmGiftCard.email.focus();
    return (false);
  }
if (! IsValidEmail(document.frmGiftCard.email.value))
	{
		alert("Invalid Email.  Please re-enter email address.");
		document.frmGiftCard.email.focus();
		return (false);
	}  
if (frmGiftCard.billname.value == "")
  {
    alert("Please enter exact name on credit card that will be used.");
    frmGiftCard.billname.focus();
    return (false);
  }
if (frmGiftCard.billaddress.value == "")
  {
    alert("Please enter billing address for credit card used.");
    frmGiftCard.billaddress.focus();
    return (false);
  }
if (frmGiftCard.billcity.value == "")
  {
    alert("Please enter city.");
    frmGiftCard.billcity.focus();
    return (false);
  }
if (frmGiftCard.billstate.value == "")
  {
    alert("Please enter state.");
    frmGiftCard.billstate.focus();
    return (false);
  }
if (frmGiftCard.billzip.value == "")
  {
    alert("Please enter zip code.");
    frmGiftCard.billzip.focus();
    return (false);
  }
if (frmGiftCard.shipname.value == "")
  {
    alert("Please enter name of recipient of gift card.");
    frmGiftCard.shipname.focus();
    return (false);
  }
if (frmGiftCard.shipaddress.value == "")
  {
    alert("Please enter shipping address.");
    frmGiftCard.shipaddress.focus();
    return (false);
  }
if (frmGiftCard.shipcity.value == "")
  {
    alert("Please enter city.");
    frmGiftCard.shipcity.focus();
    return (false);
  }
if (frmGiftCard.shipstate.value == "")
  {
    alert("Please enter state.");
    frmGiftCard.shipcity.focus();
    return (false);
  }
else if (frmGiftCard.shipzip.value == "")
  {
    alert("Please enter zip code.");
    frmGiftCard.shipzip.focus();
    return (false);
  }
return (true);
}

function IsValidEmail(emailstr) {
       if(emailstr.length == 0)
         return true;
        var whitespace = " \t\n\r";

                for (i = 0; i < emailstr.length; i++)
                {   
                        // Check that current character isn't whitespace.
                        var c = emailstr.charAt(i);
                                if (whitespace.indexOf(c)>=0)
                                return false;
                }
                
                // now, check for something that *remotely* looks like an email address
                var atIndex = emailstr.indexOf("@")
        if (atIndex <= 0)
                return false;
               
 var username = emailstr.substring(0,atIndex-1);
                var domain = emailstr.substring(atIndex + 1, emailstr.length);

                if (!(domain.indexOf(".") > 0 && domain.lastIndexOf(".") < domain.length - 1))
                        return false;
        
        return true;
}