/* Author: 

*/

	$(function(){
		$('#billingSameAsFrom').attr('checked', false);

		$('#billingSameAsFrom').change(
			function() {
				if ($('#billingSameAsFrom').attr('checked')) {
					$('#billingInformation').slideUp();
				} else {
					$('#billingInformation').slideDown();
				}
			}
		);
	});


    function isNumeric(str){
      var validRegExp = /^[0-9]+\.?[0-9]*$/;

      if (str.search(validRegExp) == -1) {
          return false;
        }
        return true;
    }

    function validateGiftCard() {
		var myForm = document.gift_card_form;
        var error_state = false;
        var error_msg = "Before this form can be submitted:\n";

        if (myForm.toName.value == '') { error_state = true; error_msg += " - Please enter the \"To\" Name\n"; }
        if (myForm.toAddress.value == '') { error_state = true; error_msg += " - Please enter the \"To\" Address\n"; }
        if (myForm.toCity.value == '') { error_state = true; error_msg += " - Please enter the \"To\" City\n"; }
        if (myForm.toState.value == '') { error_state = true; error_msg += " - Please enter the \"To\" State\n"; }
        if (myForm.toZip.value == '') { error_state = true; error_msg += " - Please enter the \"To\" Zip\n"; }
		if (myForm.toEmail.value != '') {
	        if (!isValidEmail(myForm.toEmail.value)) { error_state = true; error_msg += " - Please enter the \"To\" Email\n"; }
		}
        if (myForm.toCountry.value == '') { error_state = true; error_msg += " - Please enter the \"To\" Country\n"; }

        if (myForm.fromName.value == '') { error_state = true; error_msg += " - Please enter the \"From\" Name\n"; }
        if (myForm.fromAddress.value == '') { error_state = true; error_msg += " - Please enter the \"From\" Address\n"; }
        if (myForm.fromCity.value == '') { error_state = true; error_msg += " - Please enter the \"From\" City\n"; }
        if (myForm.fromState.value == '') { error_state = true; error_msg += " - Please enter the \"From\" State\n"; }
        if (myForm.fromZip.value == '') { error_state = true; error_msg += " - Please enter the \"From\" Zip\n"; }
        if (myForm.fromCountry.value == '') { error_state = true; error_msg += " - Please enter the \"From\" Country\n"; }
        if (!isValidEmail(myForm.fromEmail.value)) { error_state = true; error_msg += " - Please enter the \"From\" Email\n"; }
        if (myForm.fromPhone.value == '') { error_state = true; error_msg += " - Please enter the \"From\" Phone\n"; }

        if (!isNumeric(myForm.cardAmount.value)) { error_state = true; error_msg += " - Please enter the Gift Card Dollar Amount\n"; }
		
		if (!myForm.billingSameAsFrom.checked) {
			if (myForm.billName.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" Name\n"; }
			if (myForm.billAddress.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" Address\n"; }
			if (myForm.billCity.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" City\n"; }
			if (myForm.billState.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" State\n"; }
			if (myForm.billZip.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" Zip\n"; }
			if (myForm.billCountry.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" Country\n"; }
			if (!isValidEmail(myForm.billEmail.value)) { error_state = true; error_msg += " - Please enter the \"Billing\" Email\n"; }
			if (myForm.billPhone.value == '') { error_state = true; error_msg += " - Please enter the \"Billing\" Phone\n"; }
		}
		
		if (!myForm.sendToRecipient.checked && !myForm.sendToPurchaser.checked) { error_state = true; error_msg += " - Please select where the gift card will be sent \n"; }
		
        if (myForm.recaptcha_response_field.value == "") { error_state = true; error_msg += " - Please enter the CAPTCHA text\n"; }

        if (error_state) {
            alert(error_msg);
        } else {
			myForm.submit();
		}
        return false;

    }
	
    function validateEmailExclusivesFooter() {
		var myForm = document.footer_signup;
        var error_state = false;
        var error_msg = "Before this form can be submitted:\n";

        if (!isValidEmail(myForm.emailAddress.value)) { error_state = true; error_msg += " - Please enter your email address\n"; }

        if (error_state) {
            alert(error_msg);
        } else {
			myForm.submit();
		}
        return false;

    }
	
    function validateEmailExclusives() {
		var myForm = document.emailExclusives;
        var error_state = false;
        var error_msg = "Before this form can be submitted:\n";

        if (!isValidEmail(myForm.emailAddress.value)) { error_state = true; error_msg += " - Please enter your email address\n"; }
        if (myForm.firstName.value == "") { error_state = true; error_msg += " - Please enter your first name\n"; }
        if (myForm.lastName.value == "") { error_state = true; error_msg += " - Please enter your last name\n"; }
        if (myForm.recaptcha_response_field.value == "") { error_state = true; error_msg += " - Please enter the CAPTCHA text\n"; }

        if (error_state) {
            alert(error_msg);
        } else {
			myForm.submit();
		}
        return false;

    }

	function isValidEmail(strEmail){
	  validRegExp = /^[^@]+@[^@]+\.[a-z]{2,}$/i;
	
	  if (strEmail.search(validRegExp) == -1) {
		  return false;
		}
		return true;
	}


/* Handle placeholder text in footer email signup */

$(function(){
	var signup_text = "Sign up for Email Exclusives";
	
	$('#footer_signup #emailAddress').focus(
		function(){
			if ($(this).val() == signup_text) {
				$(this).val("");
			}
		}
	);
		
	$('#footer_signup #emailAddress').blur(
		function(){
			if ($(this).val() == "") {
				$(this).val(signup_text);
			}
		}
	);
});

function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+\.[a-z]{2,}$/i;

  if (strEmail.search(validRegExp) == -1) {
      return false;
    }
    return true;
}

function validateEmailSignup(myForm) {
	var error_state = false;
	var error_msg = "Before this form can be submitted:\n";

	if (!isValidEmail(myForm.email.value)) { error_state = true; error_msg += " - Please enter your email address\n"; }

	if (error_state) {
			alert(error_msg);
			return false;
	}
}



/* Google Weather */
/* http://www.google.com/ig/api?weather=Lincoln,NE */



