/* ************************************************************************* */
/*	>> SPORTING EVENTS REGISTRATION											 */
/* ************************************************************************* */

/* <<<<<<<<<< APPROVE REGISTRATION >>>>>>>>>> */
function approveRego() {
	var vForm = document.RegoForm;
	if ( confirm('Click \'OK\' to continue processing this registration.') ) {
		vForm.submit();
	}
}

/* <<<<<<<<<< DENY REGISTRATION >>>>>>>>>> */
function denyRego() {
	var vForm = document.RegoForm;

	if ( confirm('Click \'OK\' to deny this registration. \nNOTE: all user details above will be permanently deleted from the database.') ) {
		vForm.Approve.value = 'N';
		vForm.submit();
	}
}


/* ************************************************************************* */
/*	>> USER MANAGER															 */
/* ************************************************************************* */

/* <<<<<<<<<< GET ODT EVENT ADMIN USER LIST >>>>>>>>>> */
function getODTEventAdminUserList() {
	var vForm		= document.AdminForm;

	var vRegionId	= vForm.RegionId.value;
	var vSportId	= vForm.SportId.value;

	var vUrl		= 'admin.php?pg=sports/editUserList&R=' + vRegionId + '&S=' + vSportId;

	var vCompId		= 0;
	if (vForm.CompId!=null) {
		vCompId		= vForm.CompId.value;
		vUrl		= vUrl + '&C=' + vCompId;
	}

	window.location =  vUrl;

}


/* <<<<<<<<<< DELETE USER >>>>>>>>>> */
function deleteUser() {
	var vForm			= document.AdminForm;

	if ( confirm('All details for this user will be deleted.  This action is irreversible. \nClick \'OK\' to continue.') ) {
		vForm.Command.value = 'deleteUser';
		vForm.submit();
	}

}


/* <<<<<<<<<< DELETE USER LIST >>>>>>>>>> */
function deleteUserList(formName) {
	var vForm			= document.AdminForm;

	if ( confirm('All details for the selected users will be deleted.  This action is irreversible. \nClick \'OK\' to continue.') ) {
		vForm.Command.value = 'deleteUserList';
		vForm.submit();
	}
  else {
    for (i=0; i < eval(formName).elements.length; i++) {
      if (eval(formName).elements[i].type == "checkbox") {
        eval(formName).elements[i].checked = false;
      }
    }
  }
}


/* ************************************************************************* */
/*	>> SPORTS DRAW MANAGER													 */
/* ************************************************************************* */
/* <<<<<<<<<< GO TO DATE >>>>>>>>>> */
function goToDate(pPage, pSportId, pGradeId) {

//  var vYear = findObject('Year');
  var vYearObject = document.getElementsByName('Year')[0];
  var vYear = vYearObject.options[vYearObject.selectedIndex].value;

//  var vMonth  = findObject('Month');
  var vMonthObject = document.getElementsByName('Month')[0];
  var vMonth = vMonthObject.options[vMonthObject.selectedIndex].value;

  window.location = 'admin.php?pg=' + pPage + '&S=' + pSportId + '&G=' + pGradeId + '&D=' + vYear + '-' + vMonth + '-01';
}


/* <<<<<<<<<< SET ALL DATES >>>>>>>>>> */
function setAllDates(pForm) {
	var vUpdateKeys		= pForm.UpdateKeys.value;

	var vKeys			= vUpdateKeys.split('|');

	for (var i=0; i<vKeys.length; i++) {
		vDField = findObject('DATE_' + vKeys[i]);
		vDField.value = pForm.SetDate.value;
	}
}


/* <<<<<<<<<< SET ALL TIMES >>>>>>>>>> */
function setAllTimes(pForm) {
	var vUpdateKeys		= pForm.UpdateKeys.value;

	var vKeys			= vUpdateKeys.split('|');

	for (var i=0; i<vKeys.length; i++) {
		vHField = findObject('H_' + vKeys[i]);
		vMField = findObject('M_' + vKeys[i]);
		vHField.value = pForm.Hour.value;
		vMField.value = pForm.Minute.value;
	}
}


/* <<<<<<<<<< CHECK UNCHECK ALL DRAWS >>>>>>>>>> */
function checkUncheckAllDraws() {
	var vForm			= document.AdminForm;
	var vCheckboxKeys	= vForm.CheckboxKeys.value;

	var vKeys			= vCheckboxKeys.split('|');
	var vCheckValue		= vForm.CheckAll.checked;

	for (var i=0; i<vKeys.length; i++) {
		vDField			= findObject('ID_' + vKeys[i]);
		vDField.checked	= vCheckValue;
	}
}

/* <<<<<<<<<< CHECK UNCHECK ALL GRADES >>>>>>>>>> */
function checkUncheckAllGrades() {
  var vForm     = document.AdminForm;
  var vGradeCheckboxKeys = vForm.GradeCheckboxKeys.value;

  var vGradeKeys     = vGradeCheckboxKeys.split('|');
  var vGradeCheckValue   = vForm.GradeCheckAll.checked;

  for (var i=0; i<vGradeKeys.length; i++) {
    vGField     = findObject('IDG_' + vGradeKeys[i]);
    vGField.checked = vGradeCheckValue;
  }
}

/* <<<<<<<<<< RESTORE EVENT >>>>>>>>>> */
function restoreEvent(pDrawId) {
	var vForm = document.AdminForm;
	vForm.Command.value = 'restoreEvent';
	vForm.RestoreId.value = pDrawId;
	vForm.submit();
}

function clearNewSport() {
  document.getElementById('NewSport').value = '';
}

function clearOldSport() {
  document.getElementById('SportId').selectedIndex = 0;
}

function confirmNotice() {
  var vForm = document.CreateNoticeForm;
  var noticeType = document.getElementById('noticeType').options[document.getElementById('noticeType').selectedIndex].value;
  switch(Number(noticeType)) {
    case 0:
      vMessage = 'Are you sure you want to continue with this action of creating a notice\nClick \'OK\' to continue with this action.';
      break;
    case 1:
      vMessage = 'You are about to post a Results notice for one or more events, are you sure you want to make this posting of a Results notice?\nClick \'OK\' to continue with this posting of a Results notice.';
      break;
    case 2:
      vMessage = 'You are about to Transfer one or more events, are you sure you want to make this Transfer?\nClick \'OK\' to continue with this Transfer.';
      break;
    case 3:
      vMessage = 'You are about to Postpone one or more events, are you sure you want to make this Postponement?\nClick \'OK\' to continue with this Postponement.';
      break;
    case 4:
      vMessage = 'You are about to Cancel one or more events, are you sure you want to make this Cancellation?\nClick \'OK\' to continue with this Cancellation.';
      break;
    default:
      vMessage = 'Are you sure you want to continue with this action\nClick \'OK\' to continue with this action.';
      break;
  }
  if ( confirm(vMessage) ) {
    vForm.submit();
  }
}
