function SummerRegistration(properties) {
  /* expected properties = {
  sessions: [ ["session name", cost], ...],
  num_students: number-of-students-you-can-register,
  grades: [4,5,6],
  view_path: "/location/of/ajax/view", - most likely "{{ site_root }}/classicreg/"
  multiple_sessions: true,
  tshirt: true,
  } */

  this.properties = properties;
  this.busy = false;
  this.tshirts = ['Youth Medium', 'Youth Large', 'Adult Medium', 'Adult Large'];
  
  this.get_student_form = function(i){
    var self = this;
    var out = '<div class="student">';

    out += '<p><label for="student_'+i+'">Student Name: </label>';
    out += '<input id="student_'+i+'" name="student_'+i+'" maxlength="100" /></p>';

    if(self.properties.grades){
      var key = 'student_'+i+'_grade';
      out += '<p><label for="'+key+'">Incoming Grade: </label><select size="1" name="'+key+'" id="'+key+'">';
      $.each(self.properties.grades, function(index, grade){
        out += '<option>'+grade+'</option>';
      });
      out += '</select></p>';
    }

    if(self.properties.tshirt){
      var key = 'student_'+i+'_tshirt';
      out += '<p><label for="'+key+'">T-shirt size: </label><select size="1" name="'+key+'" id="'+key+'">';
      $.each(self.tshirts, function(index, tshirt){
        out += '<option>'+tshirt+'</option>';
      });
      out += '</select></p>';
    }

    out += '<p><label class="session">Sessions:</label><ul>';
    $.each(self.properties.sessions, function(index, session){
      var key = 'student_'+i+'_session';
      var widget = 'radio';
      var id = key;
      if(self.properties.multiple_sessions){
        widget = 'checkbox'
        key = key + '_'+(index+1)
      }else{
        id = key+index;
      }
      if(session.length > 2){
        out += '<li><label><span>' + session[0] + ' ('+session[2]+')</span></label></li>';
      }else{
        out += '<li><label for="'+id+'"><input type="'+widget+'" name="'+key+'" id="'+id+'" value="'+session[0]+'" />';
        out += '<span>'+session[0]+'</span></label></li>';
      }
    });
    out += '</ul></p>';
    

    out += '</div>';
    return out;
  };

  this.is_valid = function(){
    var self = this;
    var error = false;

    $.each(['address','city','state','zip','email','phone'], function(i, val){
      if($("#address #id_"+val).val() == ""){
        error = "All contact fields are required except for cell phone.";
      }
    });

    $("#students .student").each(function(){
      if(self.get_subtotal(this) == 0){
        error = "Every student must have a session selected.";
      }
    });

    if(!error){
      return true;
    }
    alert(error);
    return false;
  };
  this.get_subtotal = function(student){
    var self = this;
    var total = 0;
    $(student).find("input:checked").each(function(){
      var key = $(this).val();
      $.each(self.properties.sessions, function(index, session){
        if(session[0] == key){
          total += session[1];
        }
      });
    });
    if(total > 0 && self.properties.discount_per_student){
      var discount = self.properties.discount_per_student;
      if(discount.grades){
        if($.inArray($(student).find("option:selected").val(), discount.grades)){
          total = total - discount.amount;
        }
      }else{
        total = total - discount.amount;
      }
    }
    return total;
  };

  this.get_total = function(){
    var self = this;
    var total = 0;
    $("#students .student").each(function(){
      total += self.get_subtotal(this);
    });
    return total;
  };

  this.display_students = function(new_total){
    var self = this;
    var out = '';

    var students = $("#students .student");
    var current = students.length;
    if(new_total > current){
      for(i=current+1; i<=new_total; i++){
        out += self.get_student_form(i);
      }
      $("#students").append(out);
    }else if(new_total < current){
      for(i=+new_total+1; i<=current; i++){
        $(students[i-1]).remove();
      }
    }

    if($.isFunction(self.properties.post_resize)){
      self.properties.post_resize();
    }
  };

  this.init = function(){
    var self = this;

    for(i=1; i<=self.properties.num_students; i++){
      $("#studentcount").append("<option>"+i+"</option>");
    }
    $("#studentcount").change(function(){ self.display_students( $("#studentcount").val() ); });
    self.display_students(1);


    $("#regform .submit").click(function(){
      var total = self.get_total();
      if(!self.busy && self.is_valid()){
        self.busy = true;
        $("#regform .total").val("$"+total);
        $("#regform .note").val("From: "+$("#address #id_email").val());
        $.post(self.properties.view_path, $("#regform form").serialize(), function(response){
          $("#paypalform .total").val(total);
          $("#paypalform").submit();
        });
      }
    });

  };
  this.init();
}
