// $Id: lookup_campaignFinance.js,v 1.19 2007/12/07 18:18:59 dharris Exp $

// validation of campaign finance lookup fields?
function submitCampaignFinanceLookup(lookupToolName) {
  createDynamicSubmitFormElements(lookupToolName);
  //add lightbox check
  var elAuthorized = document.getElementById("authorized");
  if (elAuthorized == null || elAuthorized.value) {
    if (submitFormError != "") {
      alert(submitFormError);
      submitFormError = "";
      return;
    }
	  document.campaignFinanceForm.submit(); 	
  }else{
	  requireLoginPopup("home.do");
  }
}

// see drawStandardCycleSubmissionControls function in lookupSupport.js for more
// per lookup tool specific functionality

// called when the controlType control value is changed
function checkLookupControlType(lookupToolName, control) {
  var lastUnderScore = control.id.lastIndexOf("_");
  var controlIndex = control.id.substring(lastUnderScore + 1);
  if (controlIndex == 0) {
    
    updateMultiECIDSelectorOption(true);
    
    var foundAdditionalRows = false;
    for (n = 1; !foundAdditionalRows && n < oCriteriaRows[lookupToolName].length; n++) {
      if (oCriteriaRows[lookupToolName][n])
        foundAdditionalRows = true;
    }
    if (foundAdditionalRows) {
      if (control.options[control.selectedIndex].value != firstControlTypeValue) {
        var indexOfFirstControlTypeValue = 0;
        for (n = 0; n < control.options.length; n++) {
          if (control.options[n].value == firstControlTypeValue) {
            indexOfFirstControlTypeValue = n;
            break;
          }
        }
        if (confirm("Changing this option will clear the information you have already entered and start a new report. Proceed?")) {
          var oldControlId = control.id;
          var oldControlSelIndex = control.selectedIndex;
          var oldControlValue = control.options[control.selectedIndex].value;
          resetTool(lookupToolName);
          var newControl = document.getElementById(oldControlId);
          newControl.selectedIndex = oldControlSelIndex; // set the index on the new control to what was selected
          firstControlTypeValue = oldControlValue;
        } else {
          // find the index of what used to be selected and select it (reverting to previous setting)
          control.selectedIndex = indexOfFirstControlTypeValue;
          return false;
        }
      }
    } else {
      firstControlTypeValue = control.options[control.selectedIndex].value;
    }
  }
}

