//<![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_singleDonation").hide();
		$("#form_thankYouMessage").hide();
		$("#donationSingleMessage").hide();
        $("#donationMonthlyMessage").hide();
        validSingleDonation();
		validMonthlyDonation();
		checkCountry();
		checkDonationStatus();
                                 
        // donation 
        $("#input_monthlyDonation").change(function(event) { checkMonthlyDonation(); });                     
		$("#input_monthlyDonation").keyup(function(event) { checkMonthlyDonation(); }); 
		$("#form_selectSingleDonation").click(function(event) { showSingleDonation(); });
        $("#input_singleDonation").change(function(event) { checkSingleDonation(); });                     
		$("#input_singleDonation").keyup(function(event) { checkSingleDonation(); });  
		
		// Country Selection.  Change State/Zip/Phone based on country
		//$("#forNorthAmerica").hide();
		//$("#forWorld").hide();
		$("#input_country").change(function(event) { checkCountry() });
		
		// add in continue button
		$(".continueButton").html('<input type="image" src="graphics/ca_oct08_1_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 checkCountry() {
		// North America section, show state, zip, phone fields (with validation) if Country is US or Canada
		if(($("#input_country").val()=='United States') || ($("#input_country").val()=='Canada')) {
			$("#forWorld").hide("slow");
			$("#input_state_world").val("");
			$("#input_zip_world").val("");
			$("#input_phone_world").val("");
			$("#forNorthAmerica").show("slow");
		}
		// Invalid Country (if country is set to xx), hide the state/zip/phone
		else if($("#input_country").val()=='xx') {
			$("#forNorthAmerica").hide("slow");
			$("#forWorld").hide("slow");
			$("#input_state").val("xx");
			$("#input_zip").val("");
			$("#input_phone_ac").val("");
			$("#input_phone_ext").val("");
			$("#input_phone").val("");
			$("#input_state_world").val("");
			$("#input_zip_world").val("");
			$("#input_phone_world").val("");
		}
		// World Section (any valid country not USA or Canada) section, show text-only state, zip, phone fields (with no validation)
		else {
			$("#forNorthAmerica").hide("slow");
			$("#input_state").val("xx");
			$("#input_zip").val("");
			$("#input_phone_ac").val("");
			$("#input_phone_ext").val("");
			$("#input_phone").val("");
			$("#forWorld").show("slow");
		}
	}
	
	// if the singleDonation field is not blank, show it (and hide the button)
	function checkDonationStatus() {
		if($("#input_singleDonation").val() != "") {
			showSingleDonation();
		}
	}
				
    function checkMonthlyDonation() {
		//alert("check md - value: "+$("#input_monthlyDonation").val());
   	    if(validMonthlyDonation()) {
			// the donation is valid, so hide the error message
   	        $("#donationMonthlyMessage").hide();
			// the monthly donation is valid and not blank.  if the single donation is valid or blank, show the thank you message
			if(validSingleDonation() || $("#input_singleDonation").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
		} else { 
			// if the monthly donation & the single donation are blank, hide the thank you message
			if ($("#input_monthlyDonation").val() == "" && $("#input_singleDonation").val() == "") {
				$("#form_thankYouMessage").hide();
			}	
			// if the single Donation is valid & the monthly donation is blank, show the thank you message
			if(validSingleDonation() && $("#input_monthlyDonation").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
			if($("#input_monthlyDonation").val() != "")  {
				$("#form_thankYouMessage").hide();
				$("#donationMonthlyMessage").html("<p><strong>Error:</strong> Must be a valid whole number</p>");   
   	            $("#donationMonthlyMessage").show("fast"); 
   	        } else {
   	            $("#donationMonthlyMessage").hide();
   	        }   	    
   	    }   	    
    }                   	                       

   	function checkSingleDonation() {
   	    if(validSingleDonation()) {
			$("#donationSingleMessage").hide();
			// if the single donation is valid, and the monthly donation is valid or blank, show the thank you message
			if(validMonthlyDonation() || $("#input_monthlyDonation").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}
   	    } else {   
			// if the monthly donation & the single donation are blank, hide the thank you message
			if ($("#input_monthlyDonation").val() == "" && $("#input_singleDonation").val() == "") {
				$("#form_thankYouMessage").hide();
			}	
			// if the monthly Donation is valid & the single donation is blank, show the thank you message
			if(validMonthlyDonation() && $("#input_singleDonation").val() == "") {
				$("#form_thankYouMessage").show("slow");
			}		
			if($("#input_singleDonation").val() != "")  {
				$("#form_thankYouMessage").hide();
   	            $("#donationSingleMessage").html("<p><strong>Error:</strong> Must be a valid whole number</p>");     
   	            $("#donationSingleMessage").show("fast");
   	        } else {
   	            $("#donationSingleMessage").hide();
   	        }   	    
   	    }   	    
    }   

	function validMonthlyDonation() {
		if($("#input_monthlyDonation").val() > 0 && isInteger($("#input_monthlyDonation").val()) && $("#input_monthlyDonation").val() != "NaN") {
			return true;
		} else {
			return false;
		}
	}
	
	function validSingleDonation() {
		if($("#input_singleDonation").val() > 0 && isInteger($("#input_singleDonation").val()) && $("#input_singleDonation").val() != "NaN") {
			return true;
		} else {
			return false;
		}
	}
	
	function showSingleDonation() {
		$("#form_singleDonation").show();
		$("#form_selectSingleDonation").hide("slow");
	}

 //]]>