/* = Performs styling and calculations for amember cart  
---------------------------------------------------------------------
*/

$(document).ready(function() {
   var stripe = function() {
    $('#cart tbody tr:visible:even').removeClass('odd').addClass('even');
    $('#cart tbody tr:visible:odd').removeClass('even').addClass('odd');
  };
  stripe(); 
  
  $('.calc').keyup(function() {
     var quantity = parseInt($('#number_of_users').val());
     quantity = isNaN(quantity) ? 0 : quantity;
     if (quantity < 5) quantity = 5;
     var price = 2.00;
     var cost = quantity * price;
     var totalCost = cost;
     if (totalCost < 0) totalCost = 0;
        
     $('#q-disc').text(String(quantity));
     $('#p-disc').text('$' + price.toFixed(2));
     $('#c-disc').text('$' + cost.toFixed(2));
     $('#c-total').text('$' + totalCost.toFixed(2));
     /* hidden fields */
     $('#cost').attr('value', (cost.toFixed(2)));
    });
    
    // auto-hides and shows staff account section based on radio button selected.
    
    $('fieldset#staff_field').hide();
    $('#memtype input#paysys_idpaypal_r').click(function() {
       $('fieldset#staff_field').hide();
    });
    $('#memtype input#paysys_idccc_staff').click(function() {
       $('fieldset#staff_field').show();
    });
    $('tr#paysys select').change(function() {
       if ($('#paysys select option:selected').attr('value') == 'ccc_staff') {
          $('fieldset#staff_field').show();
       } else {
          $('fieldset#staff_field').hide();
       };
    });
    $('input.submit').click(function() {
       leaders = $('input#number_of_users').val();
       if (leaders<5) {
          alert('Please select 5 or more users');
          return false;
       };
       if ($('input#paysys_idccc_staff').is(':checked')) {
          staff_bu = $('input[@name=business_unit]').val();
          staff_ou = $('input[@name=operating_unit]').val();
          staff_d = $('input[@name=department]').val();
          staff_p = $('input[@name=project_id]').val();
          staff_an = $('input[@name=acct_number]').val();
          if ((staff_bu=="")||(staff_ou=="")||(staff_d=="")||(staff_p=="")) {
             if (staff_an=="") {
                alert("You selected Account Transfer as your payment method, but did not enter your full account info. Please enter either full Operating Account info or your Personal Staff Account number");
                return false;
             };
          };
       };
    });
});