// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

$(document).ready(function(){
  $("#order_payment_method").change(function(){
    // Restores previous tate

    var total = 0

    $(".price ins").each(function(){
      $(this).remove()
    })

    $(".price.member, .price.standard").each(function(){
      total += 60
      if($(this).children("del").html())
        $(this).html($(this).children("del").html())
    })

    // handle changes
    if($(this).val() == "epos"){
      $(".price.standard").each(function(){
        total += 3
      })
    } else if($(this).val() == "cheque"){
      $(".price.member").each(function(){
        $(this).html("<ins>£63.00</ins><del>" + $(this).html() + "</del>")
      })
      total += 3 * $(".price.member, .price.standard").size()
    } else if($(this).val() == "paypal"){
      $(".price.member, .price.standard").each(function(){
        $(this).html("<ins>£66.00</ins><del>" + $(this).html() + "</del>")
        total += 6
      })
    }

    $(".total").html("Total: £" + total + ".00")
    return
  });

  if($(".admit_ticket").length > 0){
    $(window).keyup(function(e){
      if(e.which == 13){
        document.forms[0].submit();
      }
      if(e.which == 27){
        window.location = $('ul.buttons li:last a').attr("href");
      }
    });
  }

  // focus on the first text input field in the first field on the page
  $("input[type=text]:first", document.forms[0]).focus();
})