/***********************************************
* Default javascript for: friendshiptours.org
* Author: Benjamin Ramey
* E-mail: ben.ramey@gmail.com
* Created: Tue Dec 18 17:46:35 CST 2007
***********************************************/
$(function() {
  //
  // home page
  //
  if($("body").attr("id") == 'index')
  {
    $("#news-jumper-select").change(function() {
      if($(this).val() != '')
      {
        document.location = '#'+$(this).val();
      }
    });
  }
  //
  // passport info page
  //
  else if($("#passportinfo_form"))
  {
    $("#add_person").click(function() {
      var personHtml = "<fieldset class='person'>"+$("fieldset.person:first").html()+"</fieldset>";
      // insert a new fieldset with passport form after the first one
      $("fieldset.person:last").after(personHtml);
      // this element selected next is the fieldset we just added
      $("fieldset.person:last input.delete_person").attr("disabled",'').click(
        function() {
          DeletePassportPerson($(this));
          return false;
        });
        
      // since we just added a person, we have at least two people, so we want
      // the first person's 'delete person' button enabled
      $("input.delete_person:first").attr('disabled','');
      
      return false;
    });
    // apply delete person function to click on first delete person button
    $("input.delete_person").click(function() {
      DeletePassportPerson($(this));
      return false;
    });
  }
  //
  // credit card page
  //
  else if($("body").attr('id') == 'creditcard')
  {
    $("#cvv_help").click(function() {
      var message = "The security code is on the back of your card above and to the right of your signature - the last three digits located there.\n\n"
        + "For example, a card with the number 1111 2222 3333 4444 will have 4444 123 written on the back.\n\n"
        + "In this example, the number 123 is the security code.\n\n"
        + "The exception to this is an American Express card.  The security code in this case is a a four digit number on the FRONT of the card, above and to the right of the embossed number.";
	    
      alert(message);
    });
  }
});

function DeletePassportPerson(buttonElement)
{
  var numButtons = 0;
  // remove this person
  buttonElement.parents("fieldset").remove();
  
  // count the number of buttons we have (which should be the number of
  // people we have too)
  $("input.delete_person").each(function() { numButtons++; });
  // disable the first delete person (so they can't delete ALL people and
  // submit none)
  if(numButtons < 2)
    $("input.delete_person:first").attr('disabled','disabled');
}