//<![CDATA[   

	// When the page is ready
	$(document).ready(function(){  
    	$("#noJS_warning").hide();
		
		// if they get here by hitting back, make sure to show everything if they had it checked previously
		$("#form_thankYouMessage").hide();
		$("#form_shippingInfo").hide();
		$("#item01Message").hide();
        $("#item02Message").hide();
		//$("#input_country").attr("disabled", true);
		//$("#s_input_country").attr("disabled", true);
        
		// if they get here by hitting back, make sure to show everything they had exposed before posting
		eventActions();
		
        // check item form fields
        $("#input_item01").change(function(event) { eventActions(); });                     
		$("#input_item01").keyup(function(event) { eventActions(); }); 
        $("#input_item02").change(function(event) { eventActions(); });
		$("#input_item02").keyup(function(event) { eventActions(); });  
		
		$("#matchBilling").mousedown(function(event){
            copyBillingForm(true);	    
     	});  
		
		// add the continue button
		$(".continueButton").html('<input type="image" src="graphics/ca_200811_01_button_continue.jpg" alt="continue" /> <a href="javascript:void(0)" id="your_privacy">Your Privacy</a>');        		      

		// show security notes on link click
		$("#your_privacy").mousedown(function(event){  
		    $("#your_privacy").hide();
		    $("#continue_section").after("<div id='security_statement'><h6>Your Privacy</h6><p>Keeping your personal information private and secure is very important to us.  We use strong encryption technology (128bit SSL) to help ensure that all personal data transmitted between your computer and our web server is secure.  The page you're submitting your personal data to will display a padlock image when loaded.</p></div>");
		    $("#security_statement").hide().show("slow");
        }); 
            
        // Show or hide the qualifying questions if the refnum argument is passed in
		$("#form_questions").hide();
		if(QueryString('refnum') != '') {
			$("#form_questions").show();
			$("#input1_yes").attr("checked", "checked");  // set the value of the first question to yes
			$("#input2_no").attr("checked", "checked");  //set the value of the second question to no
		} else {
		    $("#form_questions").html("");
		}

        // add in hidden input with query string args
        $("#form_donation").before('<input type=hidden name="ETTFMRS_MA_BLK_MAIL_ID" value="' + QueryString('refnum') + '">');     	
   	});       

	function eventActions() {
		// Run these functions when event handlers are triggered
		checkShowShipping();
		checkPlural();
		checkItem01();
		checkItem02();
		calcTotalDonation();
	}	

  	function checkShowShipping() {                                                                           
		// show the shipping address information if any item quantities are being purchased
   	    var anyFilled = false;
   	    if($("#input_item01").val() > 0 && isInteger($("#input_item01").val()) && $("#input_item01").val() != "NaN") {
   	        anyFilled = true;
   	    }
		
   	    if(anyFilled) {
			$("#form_shippingInfo").show("slow");
			$("#hidden_shipSameAsBill").val("N");
   	    } else {
   	        $("#form_shippingInfo").hide("slow");
			$("#hidden_shipSameAsBill").val("Y");
   	    }
   	}

	function checkPlural() {
		// Replace the word Packs with Pack, if they only order 1 action pack
		if($("#input_item01").val() == 1) {
			$(".item01_plural").html('band');
		}
		if(($("#input_item01").val() == 0) || ($("#input_item01").val() > 1)) {
			$(".item01_plural").html('bands');
		}
	}	
	
	function checkItem01() {
   	    if(validItem01()) {
			// the item is valid, so hide the error message
   	        $("#item01Message").hide();
			// this item is valid and not blank.  if the other item is valid or blank, show the thank you message
			if(validItem02() || $("#input_item02").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
		} else { 
			// if this item and the other item are blank, hide the thank you message
			if ($("#input_item01").val() == "" && $("#input_item02").val() == "") {
				$("#form_thankYouMessage").hide();
			}	
			// if the other item is valid & this item is blank, show the thank you message
			if(validItem02() && $("#input_item01").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
			if($("#input_item01").val() != "")  {
				$("#form_thankYouMessage").hide();
				$("#item01Message").html("<p><strong>Error:</strong> Must be a valid whole number</p>");   
   	            $("#item01Message").show("fast"); 
   	        } else {
   	            $("#item01Message").hide();
   	        }   	    
   	    }   	    
    }                   	                       

   	function checkItem02() {
   	    if(validItem02()) {
			// the item is valid, so hide the error message
			$("#item02Message").hide();
			// this item is valid and not blank.  if the other item is valid or blank, show the thank you message
			if(validItem01() || $("#input_item01").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
   	    } else {   
			// if this item and the other item are blank, hide the thank you message
			if ($("#input_item01").val() == "" && $("#input_item02").val() == "") {
				$("#form_thankYouMessage").hide();
			}	
			// if the other item is valid & this item is blank, show the thank you message
			if(validItem01() && $("#input_item02").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}		
			if($("#input_item02").val() != "")  {
				$("#form_thankYouMessage").hide();
   	            $("#item02Message").html("<p><strong>Error:</strong> Must be a valid whole number</p>");     
   	            $("#item02Message").show("fast");
   	        } else {
   	            $("#item02Message").hide();
   	        }   	    
   	    }   	    
    }   

	function validItem01() {
		if($("#input_item01").val() > 0 && isInteger($("#input_item01").val()) && $("#input_item01").val() != "NaN") {
			return true;
		} else {
			return false;
		}
	}
	
	function validItem02() {
		if($("#input_item02").val() > 0 && isInteger($("#input_item02").val()) && $("#input_item02").val() != "NaN") {
			return true;
		} else {
			return false;
		}
	}

	function calcTotalDonation() {
		// if any integers in donation fields, calculate and show, otherwise hide

		// calculate Donation amount
		var totalDonation = 0;	
		if (!isNaN(parseInt($("#input_item01").val()))) { 
			totalDonation += parseInt($("#input_item01").val()) * 2;
		}
		if (!isNaN(parseInt($("#input_item02").val()))) { 
			totalDonation += parseInt($("#input_item02").val());
		}

		// update Donation amount in page
		$(".totalDonationAmount").html(totalDonation);
	}	
	
	function copyBillingForm() { 
		// copy the billing information into the shipping fields
        $("#s_input_fName").val($('#input_fName').val());
    	$("#s_input_lName").val($('#input_lName').val());
        $("#s_input_phone_ac").val($('#input_phone_ac').val());
        $("#s_input_phone_ext").val($('#input_phone_ext').val());
        $("#s_input_phone").val($('#input_phone').val());
        $("#s_input_address").val($('#input_address').val());
        $("#s_input_address2").val($('#input_address2').val());
        $("#s_input_city").val($('#input_city').val());
        $("#s_input_state").val($('#input_state').val());  
        $("#s_input_zip").val($('#input_zip').val());
		$("#s_input_company").val($('#input_company').val());
    } 
	
	function isInteger(s) {   
		var i;
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character is number.
	        var c = s.charAt(i);
	        if (((c < "0") || (c > "9"))) return false;
	    }
	    // All characters are numbers.
	    return true;
	}

	function isFloat(aFieldValue) {
		if (aFieldValue != '')
			return(!isNaN(aFieldValue));
		else
			return false;
	}
	
 //]]>