<!--

// General

function back() {
  history.go(-1);
}

function backToMenu() {
  this.location.href = "menu.php";
}

function gotoParams(newUrl, params) {
  if (!params) {
    var locStr = window.location.href;
    var count  = locStr.indexOf('?')
    var params = locStr.substr(count + 1);
  }

  window.location.href = newUrl + '?' + params;
}

function checkDate(dayIn, monthIn, yearIn) {
  var myMonth    = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
  var myDateStr  = dayIn + ' ' + myMonth[monthIn] + ' ' + yearIn;

  // Using form values, create a new date object using the setFullYear function
  var myDate = new Date();
  myDate.setFullYear(yearIn, monthIn, dayIn);

  return myDate.getMonth() == monthIn;
}

function postWith(url, params) {
  var form = document.createElement('form');
  form.method = "post";
  form.action = url;
  for (var key in params) {
    var input = document.createElement("input") ;
    input.setAttribute("name", key) ;
    input.setAttribute("value", params[key]);
    form.appendChild(input) ;
  }
  document.body.appendChild(form) ;
  form.submit() ;
  document.body.removeChild(form) ;
}



// Popups and edit forms

function showEditAddress(personNo) {
  window.open('member_address.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showEditCourses(personNo) {
  window.open('member_courses_edit.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showMemberCourses(personNo) {
  window.open('member_courses_show.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showEditEmailAddress(personNo) {
  window.open('member_email.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showEditInstruments(personNo) {
  window.open('member_instruments.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showEditOccupation(personNo) {
  window.open('member_occupation.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showEditTelephone(personNo) {
  window.open('member_telephone.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=680,height=540');
}

function showEditTransferNotes(transferNo) {
  window.open('transfer_notes.php?transferNo='+transferNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=480,height=540');
}

function showMemberDetails(personNo) {
  window.open('member_details.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800');
}

function showMemberAutobio(personNo) {
  window.open('member_autobio.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600');
}

function showMemberLessons(personNo) {
  if (yearSelection = document.getElementById('year')) {$year = yearSelection.value;}
                                                  else {$year = 2011;}

  window.open('member_ss_lessons.php?personNo='+personNo+'&year='+$year, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540'); 
}

function showMemberOrdHistory(personNo) {
  window.open('member_ord_history.php?personNo='+personNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=540');
}

function showCongChronicles(congNo) {
  window.open('cong_chronicles.php?congNo='+congNo, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=600');
}

function editMemberCourses(personNo) {
  this.location.href = 'member_courses_edit.php?personNo=' + personNo;
}



// Login

function initFocus() {
  if (document.loginform) {
    if (document.loginform.MemberNo) {
      document.loginform.MemberNo.focus();
    }
  }
}

function loginAcceptBoxClick() {
  if (document.loginform) {
    document.loginform.submit.disabled = !document.loginform.acceptbox.checked;
  }
}

function showObligationPopup() {
  window.open('Obligation to Confidentiality.pdf', '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=512,height=384');
}



// Membership Details Editing
function setOccupationRadioClick() {
  if (document.editform) {
    document.editform.occupation.disabled      = document.editform.occupChoice[1].checked;
    document.editform.occupationOther.disabled = document.editform.occupChoice[0].checked;
  }
}



// Transfer Listing

function submitTransferListForm() {
  if (document.selectform) {
    var myDay   = document.selectform.fromDay.value;
    var myMonth = document.selectform.fromMonth.value - 1;
    var myYear  = document.selectform.fromYear.value;

    var date1ok = checkDate(myDay, myMonth, myYear);

    myDay   = document.selectform.toDay.value;
    myMonth = document.selectform.toMonth.value - 1;
    myYear  = document.selectform.toYear.value;

    var date2ok = checkDate(myDay, myMonth, myYear);

    if (date1ok && date2ok) {
      document.selectform.submit();
    } else {
      dateMsg.innerHTML = "";
      if (!date1ok) dateMsg.innerHTML = "<br />From Date is invalid.";
      if (!date2ok) dateMsg.innerHTML = dateMsg.innerHTML + "<br />To Date is invalid.";
    }
  }  
}



// Password Change

function submitPasswordForm() {
  if (document.passwordchangeform) {
    if (verifyPasswordChange()) {
      document.passwordchangeform.submit();
    } else {
      passMsg.innerHTML = "<b>Unable to submit form</b>: Please make sure your password meets the above criteria and that you have retyped it correctly. <br /><br />";
    }
  }
}

function verifyPasswordChange() {
  // Get the password values
  var pass1 = document.passwordchangeform.newPassword1.value;
  var pass2 = document.passwordchangeform.newPassword2.value;

  // Password field values must match
  var match = (pass1 == pass2);

  // Password must only contain valid characters
  var passReg = /^[0-9A-Za-z]{8,20}$/;
  var valid = pass1.match(passReg);

  return (match && valid);
}



// Member Select

function selectMember(areaType, areaNo) {
  var params = '';
  if ((areaType != '') && (areaNo != 0)) {
    params = '?areaType=' + areaType + '&areaNo=' + areaNo;
  }

  window.open('select_member.php' + params, 'member_select', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=640,height=600');
}



// Other Form

function onSubmitForm(defaultAction) {
  if (!document.selectform.formatbox) {
    return;
  }

  if (document.selectform.formatbox.value == 'CSV') {
    document.selectform.action = defaultAction + '?format=csv';
  } else {
    document.selectform.action = defaultAction;
  }

  return true;
}

function serviceTypeCheckboxClick() {
  if (document.selectform) {
    document.selectform.serviceTypeNo.disabled = !document.selectform.useCustom.checked;
  }
}

function submitMainForm(action) {
  if (document.mainform) {
    document.mainform.action = action;
    document.mainform.submit();
  }
}

function setCheckedValue(radioObj, newValue) {
  if (!radioObj)
    return;

  var radioLength = radioObj.length;

  if (radioLength == undefined) {
    radioObj.checked = (radioObj.value == newValue.toString());
    return;
  }

  for (var i = 0; i < radioLength; i++) {
    radioObj[i].checked = false;
    if (radioObj[i].value == newValue.toString()) {
      radioObj[i].checked = true;
    }
  }
}

function softReset() {
  // Does not currently work
  CongregationNo.selectedIndex = 1;
  DistrictAreaNo.selectedIndex = 1;
  BishopAreaNo.selectedIndex = 1;
  ApostleAreaNo.selectedIndex = 1;
}

function printCeritificates() {

}

function sundaySchoolChecks() {
  document.selectform.submit.disabled = !(document.selectform.sun1.checked || 
                                          document.selectform.sun2.checked ||
                                          document.selectform.sun3.checked ||
                                          document.selectform.sun4.checked ||
                                          document.selectform.ri1.checked  ||
                                          document.selectform.ri2.checked  ||
                                          document.selectform.ri3.checked  ||
                                          document.selectform.conf.checked ||
                                          document.selectform.fin.checked);
}

-->
