jQuery(function() {

  jQuery("#edit-next").click(function() {
    changetext();
  });
  
  jQuery("#edit-donation-amount-amount-one-off-amounts-other").keyup(function() {
    changetext();
  });
  
  jQuery("span, input.webform-button--previous").click(function() {
       jQuery('.donation-amount-info').text("");
  });
  
  
  /* For ball donations (hide reason) */
  /*Removed at UK's request
    if(getUrlParameter('reason') != "")
    {
      jQuery("#edit-reason-for-donating-radios-other-").prop("checked", true); //Check the "Other" radio button
      jQuery("#edit-reason-for-donating-radios-other-").parent().addClass("checked")//Same as above
      //jQuery("#edit-reason-for-donating-radios-other-").parent().click()
      jQuery("#edit-reason-for-donating-other").val(getUrlParameter('reason')); //Fill the "Enter other..." text field with the query string reason value
      jQuery(".form-item-reason-for-donating").prev().hide(); //Hide the title "Reason for donating"
      jQuery(".form-item-reason-for-donating").hide(); //Hide the Reason for donating radio boxes
    } 
*/
  
  /*Dirty solution to clean up the state to code*/
  /*Removed at UK's request
  jQuery("#edit-next--2").click(function() {
    switch(jQuery("#edit-contact-address-state-province").val())
    {
        case 'New South Wales': 
		  jQuery("#edit-contact-address-state-province").val("NSW");
		break;
        case 'Australian Capital Territory': 
		  jQuery("#edit-contact-address-state-province").val("ACT");
		break;
        case 'Western Australia': 
		  jQuery("#edit-contact-address-state-province").val("WA");
		break;
        case 'South Australia': 
		  jQuery("#edit-contact-address-state-province").val("SA");
		break;
        case 'Queensland': 
		  jQuery("#edit-contact-address-state-province").val("QLD");
		break;
        case 'Northern Territory': 
		  jQuery("#edit-contact-address-state-province").val("NT");
		break;
        case 'Victoria': 
		  jQuery("#edit-contact-address-state-province").val("VIC");
		break;
        case 'Tasmania': 
		  jQuery("#edit-contact-address-state-province").val("TAS");
		break;
    }
  });
  */
  function changetext()
  {
    if(Drupal.wateraidDonationForms.model.get("frequency") == "recurring")
      jQuery('.donation-amount-info').text("You will be making a monthly donation of $" + Drupal.wateraidDonationForms.model.get("amount") + ".");
    else
      jQuery('.donation-amount-info').text("You are donating $" + Drupal.wateraidDonationForms.model.get("amount") + ".");
  

  }
  
  changetext();
	//Hide the text if on the first step
	if(jQuery('#edit-step-1').is(':visible')) {		
		jQuery('.progress-bar__donation-amount-info').addClass('hidden');
	}
  /*Foramt phone*/
  /*jQuery("#edit-contact-phone").change(function() {
    console.log("change");
  });*/
  
  //Making the asterisk red on the title while it's not compulsory (fixing bug with double donation)
  //jQuery("label[for=edit-contact-name-title]").html(jQuery("label[for=edit-contact-name-title]").html().substr(0, jQuery("label[for=edit-contact-name-title]").text().length - 1) + "<span style='color: #E22A1B;'>" + jQuery("label[for=edit-contact-name-title]").html().substring(jQuery("label[for=edit-contact-name-title]").text().length - 1) + "</span>");
  
  //Adding a red asterisk to the title label while we fix the double donation bug
  jQuery("label[for=edit-contact-name-title]").html(jQuery("label[for=edit-contact-name-title]").html() + "<span style='color: #E22A1B;'> *</span>")
});