function validate() {
    f = document.forms[0].first_name1.value.match(/\w/);
    l = document.forms[0].last_name1.value.match(/\w/);
    
    if( !f || !l ) {
        alert("Please enter a name");
        return false;
    }
    return true;
}

var person_count = 2;

function more_people() {
    var first_name = new Array();
    var last_name  = new Array();
    var address1   = new Array();
    var address2   = new Array();
    var town       = new Array();
    var state      = new Array();
    var zip        = new Array();
    var email      = new Array();
    var phone      = new Array();
    var i;

    if( person_count > 2 ) {
        for( i=3; i<=person_count; i++ ) {
            first_name[i] = document.getElementById('first_name'+i).value;
            last_name[i]  = document.getElementById('last_name'+i).value;
            address1[i]   = document.getElementById('address1_'+i).value;
            address2[i]   = document.getElementById('address2_'+i).value;
            town[i]       = document.getElementById('town'+i).value;
            state[i]      = document.getElementById('state'+i).value;
            zip[i]        = document.getElementById('zip'+i).value;
            email[i]      = document.getElementById('email'+i).value;
            phone[i]      = document.getElementById('phone'+i).value;
        }
    }
    var content_block = '';
    for( i=3; i<=person_count; i++ ) {
        content_block += '<p><b>Person '+i+'</b></p>';
        content_block += '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
        content_block += '<tr><td class="table_underscore">First Name, Last Name:</td>';
        content_block += '<td class="table_underscore" align="right">';
        content_block += '<input type="text" name="first_name'+i+'" id="first_name'+i+'" size="20" maxlength="100" ';
        content_block += 'value="'+first_name[i]+'" />';
        content_block += '<input type="text" name="last_name'+i+'" id="last_name'+i+'" size="20" value="'+last_name[i]+'" />';
        content_block += '</td></tr><tr><td class="table_underscore">Street Address: &nbsp;</td>';
        content_block += '<td class="table_underscore" align="right">';
        content_block += '<input type="text" name="address1_'+i+'" id="address1_'+i+'" size="43" value="'+address1[i]+'" /><br>';
        content_block += '<input type="text" name="address2_'+i+'" id="address2_'+i+'" size="43" value="'+address2[i]+'" />';
        content_block += '</td></tr><tr><td class="table_underscore">Town or City: &nbsp;</td>';
        content_block += '<td class="table_underscore" align="right">';
        content_block += '<input type="text" name="town'+i+'" id="town'+i+'" size="20" maxlength="100" value="'+town[i]+'" />';
        content_block += '</td></tr><tr><td class="table_underscore">';
        content_block += 'State, Zip: &nbsp;</td><td class="table_underscore" align="right">';
        content_block += '<input type="text" name="state'+i+'" id="state'+i+'" size="2" maxlength="15" value="'+state[i]+'" />, &nbsp;';
        content_block += '<input type="text" name="zip'+i+'" id="zip'+i+'" size="10" maxlength="10" value="'+zip[i]+'" />';
        content_block += '</td></tr><tr><td class="table_underscore">';
        content_block += 'Email Address:</td><td class="table_underscore" align="right">';
        content_block += '<input type="text" name="email'+i+'" id="email'+i+'" size="43" maxlength="70" value="'+email[i]+'" />';
        content_block += '</td></tr><tr><td class="table_underscore">';
        content_block += 'Phone:</td><td class="table_underscore" align="right">';
        content_block += '<input type="text" name="phone'+i+'" id="phone'+i+'" size="43" maxlength="70" value="'+phone[i]+'" />';
        content_block += '</td></tr></table><br />';
    }
    person_count++;
    content_block += '<p><b>Person '+person_count+'</b></p>';
    content_block += '<table cellspacing="0" cellpadding="0" border="0" width="100%">';
    content_block += '<tr><td class="table_underscore">First Name, Last Name:</td>';
    content_block += '<td class="table_underscore" align="right">';
    content_block += '<input type="text" name="first_name'+person_count+'" id="first_name'+person_count+'" size="20" maxlength="100" />';
    content_block += '<input type="text" name="last_name'+person_count+'" id="last_name'+person_count+'" size="20" />';
    content_block += '</td></tr><tr><td class="table_underscore">Street Address: &nbsp;</td>';
    content_block += '<td class="table_underscore" align="right">';
    content_block += '<input type="text" name="address1_'+person_count+'" id="address1_'+person_count+'" size="43" /><br>';
    content_block += '<input type="text" name="address2_'+person_count+'" id="address2_'+person_count+'" size="43" />';
    content_block += '</td></tr><tr><td class="table_underscore">Town or City: &nbsp;</td>';
    content_block += '<td class="table_underscore" align="right">';
    content_block += '<input type="text" name="town'+person_count+'" id="town'+person_count+'" size="20" maxlength="100" />';
    content_block += '</td></tr><tr><td class="table_underscore">';
    content_block += 'State, Zip: &nbsp;</td><td class="table_underscore" align="right">';
    content_block += '<input type="text" name="state'+person_count+'" id="state'+person_count+'" size="2" maxlength="15" />, &nbsp;';
    content_block += '<input type="text" name="zip'+person_count+'" id="zip'+person_count+'" size="10" maxlength="10" />';
    content_block += '</td></tr><tr><td class="table_underscore">';
    content_block += 'Email Address:</td><td class="table_underscore" align="right">';
    content_block += '<input type="text" name="email'+person_count+'" id="email'+person_count+'" size="43" maxlength="70" />';
    content_block += '</td></tr><tr><td class="table_underscore">';
    content_block += 'Phone:</td><td class="table_underscore" align="right">';
    content_block += '<input type="text" name="phone'+person_count+'" id="phone'+person_count+'" size="43" maxlength="70" />';
    content_block += '</td></tr></table><br />';
    content_block += '<input type="button" value="Register More People&hellip;" onclick="more_people();" />';

    document.getElementById('more_people').innerHTML = content_block;
}

var NacreData = window.NacreData = {
  total : 0,
  update_total : function() {
    jQuery(".running_total").html(NacreData.total);
  },
  addup : function() {  
   var work_hours = parseFloat( jQuery("#work").val() );
   if( work_hours > 0 ) {

      var reg_converted = 0;
      var reg_cost      = 0;

      /* Work Hours are calculated against full-cost registrations only, so
      any low-income registrations are first converted to full-cost */

      if( parseInt( jQuery("#full_low").val() ) > 0 ) {
        reg_converted = 1;
        var full = jQuery("#full_regular").val();
        full    += jQuery("#full_low").val();
        jQuery("#full_low").val("");
        jQuery("#full_regular").val(full);
        reg_cost += parseInt( jQuery("#full_regular").val() ) * 40;
      }
      
      if( parseInt( jQuery("#saturday_low").val() ) > 0 ) {
        reg_converted = 1;
        var full = parseInt( jQuery("#saturday").val() );
        full    += parseInt( jQuery("#saturday_low").val() );
        jQuery("#saturday_low").val("");
        jQuery("#saturday").val(full);
        reg_cost += parseInt( jQuery("#saturday").val() ) * 20;
      }
      
      if( parseInt( jQuery("#sunday_low").val() ) > 0 ) {
        reg_converted = 1;
        var full = parseInt( jQuery("#sunday").val() );
        full    += parseInt( jQuery("#sunday_low").val() );
        jQuery("#sunday_low").val("");
        jQuery("#sunday").val(full);
        reg_cost += parseInt( jQuery("#sunday").val() ) * 20;
      }
      
      if( parseInt( jQuery("#full_member").val() ) > 0 ) {
        reg_cost += parseInt( jQuery("#full_member").val() ) * 35;
      }
      if( parseInt( jQuery("#full_donate").val() ) > 0 ) {
        reg_cost += parseInt( jQuery("#full_donate").val() ) * 75;
      }
      if( parseInt( jQuery("#friday").val() ) > 0 ) {
        reg_cost += parseInt( jQuery("#friday").val() )      * 10;
      }
      
      if( 1 == reg_converted ) {
        alert("Work Hours are calculated against full-cost registrations only; Your registration categories have been adjusted" );
      }

      var work_value = work_hours * 8;
      if( work_value > reg_cost ) {
        alert("Work hours can only be applied against registration costs; Lodging and Meals are fixed costs which Heartwood has less flexibility in adjusting; Your hours have been adjusted." );
        work_hours = reg_cost / 8;
        jQuery("#work").val(work_hours);
      }
    }

    NacreData.total = 0;
    var need_howto  = 0;
    jQuery("#howto").html('<b>In the following blanks, please enter the number of people for which that item applies (number of registrations, meals, beds, etc.)</b>' );

    var full_member = parseInt( jQuery("#full_member").val() );
    if( full_member > 0 ) {
      NacreData.total  = full_member * 35;
      if( full_member > 30 ) {
        need_howto = 1;
      }
    }
    
    var full_regular = parseInt( jQuery("#full_regular").val() );
    if( full_regular > 0 ) {
      NacreData.total += full_regular * 40;
      if( full_regular > 30 ) {
        need_howto = 1;
      }
    }
    
    var full_donate = parseInt( jQuery("#full_donate").val() );
    if( full_donate > 0 ) {
      NacreData.total += full_donate * 75;
      if( full_donate > 30 ) {
        need_howto = 1;
      }
    }
    
    var full_low = parseInt( jQuery("#full_low").val() );
    if( full_low > 0 ) {
      NacreData.total += full_low * 25;
      if( full_low >= 25 ) {
        need_howto = 1;
      }
    }
    
    var friday = parseInt( jQuery("#friday").val() );
    if( friday > 0 ) {
      NacreData.total += friday * 10;      
    }
    
    var saturday = parseInt( jQuery("#saturday").val() );
    if( saturday > 0 ) {
      NacreData.total += saturday * 20;
      if( saturday >= 20 ) {
        need_howto = 1;
      }
    }
    if( parseInt( jQuery("#saturday_low").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#saturday_low").val() ) * 15;
    }
    
    var sunday = parseInt( jQuery("#sunday").val() );
    if( sunday > 0 ) {
      NacreData.total += sunday * 20;
      if( sunday >= 20 ) {
        need_howto = 1;
      }
    }
    if( parseInt( jQuery("#sunday_low").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sunday_low").val() )          * 15;
    }
    if( parseInt( jQuery("#membership").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#membership").val() )          * 20;
    }
    if( parseInt( jQuery("#fri_cabin").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#fri_cabin").val() )           * 8;
    }
    if( parseInt( jQuery("#sat_cabin").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sat_cabin").val() )           * 8;
    }
    if( parseInt( jQuery("#sun_cabin").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sun_cabin").val() )           * 8;
    }
    if( parseInt( jQuery("#fri_suite").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#fri_suite").val() )           * 17;
    }
    if( parseInt( jQuery("#sat_suite").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sat_suite").val() )           * 17;
    }
    if( parseInt( jQuery("#sun_suite").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sun_suite").val() )           * 17;
    }
    if( parseInt( jQuery("#full_meals").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#full_meals").val() )          * 55;
    }
    if( parseInt( jQuery("#full_meals_child").val() ) > 0 ) {
      NacreData.total += (parseInt( jQuery("#full_meals_child").val() )    * 30);
    }
    if( parseInt( jQuery("#friday_dinner").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#friday_dinner").val() )       * 9;
    }
    if( parseInt( jQuery("#friday_dinner_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#friday_dinner_child").val() ) * 7;
    }
    if( parseInt( jQuery("#saturday_breakfast").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#saturday_breakfast").val() )  * 5;
    }
    if( parseInt( jQuery("#sat_breakfast_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sat_breakfast_child").val() ) * 3;
    }
    if( parseInt( jQuery("#saturday_lunch").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#saturday_lunch").val() )      * 7;
    }
    if( parseInt( jQuery("#sat_lunch_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sat_lunch_child").val() )     * 5;
    }
    if( parseInt( jQuery("#saturday_dinner").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#saturday_dinner").val() )     * 9;
    }
    if( parseInt( jQuery("#sat_dinner_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sat_dinner_child").val() )    * 7;
    }
    if( parseInt( jQuery("#sunday_breakfast").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sunday_breakfast").val() )    * 5;
    }
    if( parseInt( jQuery("#sun_breakfast_child").val() ) > 0 ) { 
      NacreData.total += parseInt( jQuery("#sun_breakfast_child").val() ) * 3;
    }
    if( parseInt( jQuery("#sunday_lunch").val() )  > 0 ) {
      NacreData.total += parseInt( jQuery("#sunday_lunch").val() )        * 7;
    }
    if( parseInt( jQuery("#sun_lunch_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sun_lunch_child").val() )     * 5;
    }
    if( parseInt( jQuery("#sunday_dinner").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sunday_dinner").val() )       * 9;
    }
    if( parseInt( jQuery("#sun_dinner_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#sun_dinner_child").val() )    * 7;
    }
    if( parseInt( jQuery("#monday_breakfast").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#monday_breakfast").val() )    * 5;
    }
    if( parseInt( jQuery("#mon_breakfast_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#mon_breakfast_child").val() ) * 3;
    }
    if( parseInt( jQuery("#monday_lunch").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#monday_lunch").val() )        * 7;
    }
    if( parseInt( jQuery("#mon_lunch_child").val() ) > 0 ) {
      NacreData.total += parseInt( jQuery("#mon_lunch_child").val() )     * 5;
    }
    if( parseInt( jQuery("#work").val() ) > 0 ) {
      NacreData.total -= (parseFloat( jQuery("#work").val() )                * 8);
    }
    if( parseInt( jQuery("#donation").val() ) > 0 ) {
      NacreData.total += parseFloat( jQuery("#donation").val() );
    } 
    
    NacreData.update_total();
    
    if( 1 == need_howto ) {
      NacreData.howto();
    }
  },
  howto : function() {
    jQuery("#howto").css( 'border', 'solid #f00' );
    jQuery("#howto").css( 'padding', '8px;' );
    jQuery("#howto").css( 'font-size', '1.5em' );
    var html = jQuery("#howto").html();
    html += " &mdash; not the dollar amount (dollar amounts will be calculated for you)";
    jQuery("#howto").html(html);
    jQuery("#howto").focus();
  }
};

jQuery(document).ready(
  function() {
    jQuery("#full_member").change( NacreData.addup );
    jQuery("#full_regular").change( NacreData.addup );
    jQuery("#full_donate").change( NacreData.addup );
    jQuery("#full_low").change( NacreData.addup );
    jQuery("#friday").change( NacreData.addup );
    jQuery("#saturday").change( NacreData.addup );
    jQuery("#saturday_low").change( NacreData.addup );
    jQuery("#sunday").change( NacreData.addup );
    jQuery("#sunday_low").change( NacreData.addup );
    jQuery("#membership").change( NacreData.addup );
    jQuery("#fri_cabin").change( NacreData.addup );
    jQuery("#sat_cabin").change( NacreData.addup );
    jQuery("#sun_cabin").change( NacreData.addup );
    jQuery("#fri_suite").change( NacreData.addup );
    jQuery("#sat_suite").change( NacreData.addup );
    jQuery("#sun_suite").change( NacreData.addup );
    jQuery("#full_meals").change( NacreData.addup );
    jQuery("#full_meals_child").change( NacreData.addup );
    jQuery("#friday_dinner").change( NacreData.addup );
    jQuery("#friday_dinner_child").change( NacreData.addup );
    jQuery("#saturday_breakfast").change( NacreData.addup );
    jQuery("#sat_breakfast_child").change( NacreData.addup );
    jQuery("#saturday_lunch").change( NacreData.addup );
    jQuery("#sat_lunch_child").change( NacreData.addup );
    jQuery("#saturday_dinner").change( NacreData.addup );
    jQuery("#sat_dinner_child").change( NacreData.addup );
    jQuery("#sunday_breakfast").change( NacreData.addup );
    jQuery("#sun_breakfast_child").change( NacreData.addup );
    jQuery("#sunday_lunch").change( NacreData.addup );
    jQuery("#sun_lunch_child").change( NacreData.addup );
    jQuery("#sunday_dinner").change( NacreData.addup );
    jQuery("#sun_dinner_child").change( NacreData.addup );
    jQuery("#monday_breakfast").change( NacreData.addup );
    jQuery("#mon_breakfast_child").change( NacreData.addup );
    jQuery("#monday_lunch").change( NacreData.addup );
    jQuery("#mon_lunch_child").change( NacreData.addup );
    jQuery("#work").change( NacreData.addup );
    jQuery("#reg_form").submit( NacreData.addup );
  }
);