function checkInvite(src) {
  if (src < 2) {
    form = $('Form_InviteForm');
    if (form['Name'+src].value.length > 0 && form['Name'+src].value != 'Friend\'s Name' &&
        form['Email'+src].value.length > 0 && form['Email'+src].value != 'Friend\'s Email') {
      sib = $('Name'+(src+1)).previousSibling;
      if (sib.nodeType != 1 || sib.tagName.toLowerCase() != 'h3') {
        sib = sib.previousSibling;
      }
      sib.style.display = 'block';
      $('Name'+(src+1)).style.display = 'block';
      $('Email'+(src+1)).style.display = 'block';
      form['Name'+(src+1)].style.display = 'block';
      form['Email'+(src+1)].style.display = 'block';
    }
  }
}

Behaviour.register({
  '#Form_InviteForm input[type=text]' : {
    onfocus: function() {
      def_val = 'Friend\'s Name';
      if (this.name.substring(0,1) == 'E') {
        def_val = 'Friend\'s Email';
      }
      if (this.value == def_val) {
        this.value = '';
      }
    },
    onblur: function() {
      def_val = 'Friend\'s Name';
      src = 0;
      if (this.name.substring(0,1) == 'E') {
        def_val = 'Friend\'s Email';
        src = parseInt(this.name.substring(5));
      }
      else {
        src = parseInt(this.name.substring(4));
      }
      if (this.value == '') {
        this.value = def_val;
      }
      if (src < 2) {
        checkInvite(src);
      }
    },
    onkeypress: function() {
      src = 0;
      if (this.name.substring(0,1) == 'E') {
        src = parseInt(this.name.substring(5));
      }
      else {
        src = parseInt(this.name.substring(4));
      }
      if (src < 2) {
        checkInvite(src);
      }
    }
  },
  '#Form_PrivateRSVPForm_Guests' : {
    onchange: function() {
      form = this.form;
      for (i = 0; i < this.value; i++) {
        $('Guest'+i).style.display = 'block';
        this.form['Guest'+i].style.display = 'block';
      }
      for (i = this.value; i < 5; i++) {
        $('Guest'+i).style.display = 'none';
        this.form['Guest'+i].style.display = 'none';
      }
    }
  },
  '#Form_PrivateRSVPForm input[type=text]' : {
    onfocus: function() {
      def_val = 'Name of Guest';
      if (this.value == def_val) {
        this.value = '';
      }
    },
    onblur: function() {
      def_val = 'Name of Guest';
      if (this.value == '') {
        this.value = def_val;
      }
    }
  },
  '#Form_PublicRSVPForm input' : {
    onfocus: function() {
      def_val = 'Name';
      if (this.name.substring(0,1) == 'E') {
        def_val = 'Email';
      }
      else if (this.name.substring(0,1) == 'P') {
        def_val = 'Phone';
      }
      if (this.value == def_val) {
        this.value = '';
      }
    },
    onblur: function() {
      def_val = 'Name';
      if (this.name.substring(0,1) == 'E') {
        def_val = 'Email';
      }
      else if (this.name.substring(0,1) == 'P') {
        def_val = 'Phone';
      }
      if (this.value == '') {
        this.value = def_val;
      }
    }
  }
});