<script language="javascript">

function setSelectionForRadioButtonCollection(radioButtonCollectionName,value){
  var collection = document.getElementsByName(radioButtonCollectionName);
  if(collection != null){
	for(var i = 0; i < collection.length; i++) {
		if(collection[i].checked) {
			collection[i].checked=false;
		}
		if(collection[i].value==value){
			collection[i].checked=true;
		}
	}
  }
}

function show(whichEl)
{
  var theElement=document.getElementById(whichEl);
  theElement.style.display = "block";
}

function hide(whichEl)
{
  var theElement=document.getElementById(whichEl);
  theElement.style.display = "none";
}


function selectLetterFile()
{
    var letterFileSelection = document.getElementById("letterFileId");
	var letterFileVar=document.getElementsByName("letterFile");
	var reasonErrorLabelField = document.getElementById("selectLetterFileParam");
	var reasonErrorField = document.getElementById("selectLetterFileParamReasonError");
	var reasonField = document.getElementById("selectLetterFileParamReason");
	var errorField = document.getElementById("selectLetterFileParamError");
	
	if (reasonErrorLabelField != null) {
		reasonErrorLabelField.style.display = "none";
	}
	if (reasonErrorField != null) {
		reasonErrorField.style.display = "none";
	}
	if (reasonField != null) {
		reasonField.style.display = "none";
	}
	if (errorField != null) {
		errorField.style.display = "none";
	}
	if (letterFileSelection != null && letterFileSelection.style.display == "block")
	{
		if (letterFileVar[1].checked && letterFileVar[2].checked)
		{
			reasonErrorLabelField.style.display = "block"
			reasonErrorField.style.display = "block";
		}
		else if (letterFileVar[1].checked)
		{
		        reasonErrorLabelField.style.display = "block"
			reasonField.style.display = "block";
		}
		else if (letterFileVar[2].checked)
		{
		        reasonErrorLabelField.style.display = "block"
	    	    errorField.style.display = "block";
		}
	}
	
}

function selectReportDetailBy(selectedParam,detFieldId) {
        var detField = document.getElementById(detFieldId);
  
    var reportDetailByName=document.getElementsByName("reportDetailBy");
    var reportDetailBy = document.getElementById("reportDetailBy");
    
    if(detField != null) {
    	if(reportDetailByName[1].checked && reportDetailBy.style.display == "block") {
	    detField.style.display = "block";
    	} else {
    	    detField.style.display = "none";
    	}
    }
}


function selectAllOptionsOnSubmit(theForm)
{
    selectAllOptions('reportUserTarget');
    selectAllOptions('messageTypeTarget');
    
   selectAllOptions('queryToTarget');
    selectAllOptions('enrollmentStatusTarget');
    selectAllOptions('eligibilityFactorTarget');
    
    selectAllOptions('visnTarget');
    selectAllOptions('visnFacilityTarget');
    selectAllOptions('facilityTarget');
    selectAllOptions('vamcTarget');
    selectAllOptions('vamcFacilityTarget');
    selectAllOptions('visnVamcTarget');
    selectAllOptions('visnVamcFacilityTarget');
    selectAllOptions("letterRejectErrorReason");
    selectAllOptions("letterRejectReason");
    selectAllOptions("letterErrorType");
}

function selectAllOptions(selectBoxName) {
    var selectBox = document.getElementById(selectBoxName)
    if(selectBox != null && selectBox.options.length != null) {
	for (var i=0; i<selectBox.options.length; i++) {
	    selectBox.options[i].selected = true;
	}
    }
}

function initReportParamScreen() {
    displayFromAndToDates("block")
    if('scheduledReports' == '<c:out value="${tabName}" />') {
    	displayFromAndToDates("none");
    	selectDayToGenerateReport('<c:out value="${reportInfoForm.generateReport}" />');
    }
    
    selectDisplayFacilityBy('<c:out value="${reportInfoForm.facilityDisplayBy}" />'); 
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','reportDetailBy', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','reportUserId', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','personMergeStatusId', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','userSelection', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','letterFileSelection', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','outlierDaysID', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','randomNumberOfRecordsID', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','enrollmentStatusComponentId', '');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','', 'reportPeriodTypeAllFiscalYearsId');
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','reportPeriodTypeQuarterlyId', '');        
    selectReportFormat('<c:out value="${reportInfoForm.reportFormat}" />','reportPeriodTypeDateRangeId', '');    
    selectLetterFile();
    selectReportDetailBy();
}

function displayFromAndToDates(action) {
    if(document.getElementById('spaceDateParam')!=null)
      document.getElementById('spaceDateParam').style.display = action;
    if(document.getElementById('fromDateParam')!=null)
      document.getElementById('fromDateParam').style.display = action;
    if(document.getElementById('toDateParam')!=null)
      document.getElementById('toDateParam').style.display = action;
      
    //EED2 report fields
    if(document.getElementById('spaceFromAndToYearParam')!=null)
      document.getElementById('spaceFromAndToYearParam').style.display = action;
    if(document.getElementById('fromYearParam')!=null)
      document.getElementById('fromYearParam').style.display = action;
    if(document.getElementById('toYearParam')!=null)
      document.getElementById('toYearParam').style.display = action;
      
    //EED3 report fields
    if(document.getElementById('spaceAsOfDateParam')!=null)
      document.getElementById('spaceAsOfDateParam').style.display = action;
    if(document.getElementById('asOfDateParam')!=null)
      document.getElementById('asOfDateParam').style.display = action;
    
    //QM10 report fields  
    if(document.getElementById('spaceReportPeriodDateRange')!=null)
      document.getElementById('spaceReportPeriodDateRange').style.display = action;
    if(document.getElementById('reportPeriodDateRange')!=null)
      document.getElementById('reportPeriodDateRange').style.display = action;
}

function selectDisplayFacilityBy(selectedFacilityParam) {
    for (i = 1; i < 8; i++) {
    	if(document.getElementById('facilityParam' + i) != null) {
	    document.getElementById('facilityParam' + i).style.display = "none";
    	}
    }

    if(selectedFacilityParam == null || selectedFacilityParam == '') {
        selectedFacilityParam = '';
        if (document.getElementById('stationNumbersId') != null) {
            document.getElementById('stationNumbersId').style.display = "none"; 
            document.getElementById('stationNumbersTextId').value='';
        }
        return;
    }

    if(document.getElementById('facilityParam' + selectedFacilityParam) != null) {
    	document.getElementById('facilityParam' + selectedFacilityParam).style.display = "block";
        if (document.getElementById('stationNumbersId') != null) {
            document.getElementById('stationNumbersId').style.display = "block";   
        }
    }
}

function selectReportFormat(selectedFacilityParam,detFieldId, sumFieldId) {

    var detField = document.getElementById(detFieldId);
    if(detField != null) {
    	if(selectedFacilityParam == '<%=ReportFormat.DETAIL.getCode()%>') {
	    detField.style.display = "block";
    	} else {
    	    detField.style.display = "none";
    	}
    }
    
    var sumField = document.getElementById(sumFieldId);
    if(sumField != null) {
    	if(selectedFacilityParam == '<%=ReportFormat.SUMMARY.getCode()%>') {
	    sumField.style.display = "block";
    	} else {
    	    sumField.style.display = "none";
    	}
    }
}

function selectReportFormatOption(selectedFacilityParam,detFieldId, sumFieldId) {

    var detField = document.getElementById(detFieldId);
    if(detField != null) {
        if(selectedFacilityParam == '<%=ReportFormat.DETAIL.getCode()%>') {
            detField.checked = true;
        }
    }
    
    var sumField = document.getElementById(sumFieldId);
    if(sumField != null) {
        if(selectedFacilityParam == '<%=ReportFormat.SUMMARY.getCode()%>') {
            sumField.checked = true;
        }
    }
}

function selectDayToGenerateReport(selectedReportRunFrequency) {

    if(selectedReportRunFrequency == '<%=ReportRunFrequency.OTHER.getCode()%>') {
    	displayFromAndToDates("block");
    } else {
    	displayFromAndToDates("none");
    	clearField('fromDate');
    	clearField('toDate');
    	
    	//EED2 fields
    	clearField('fromYear');
    	clearField('toYear');
    	
    	//EED3 fields 
    	clearField('asOfDate');
    	
    	//QM10 fields
    	clearField('reportPeriodStartDate');
    	clearField('reportPeriodEndDate');
    }
    
    for (i = 1; i < 6; i++) {
    	if(document.getElementById('dayToGenerateReportParam' + i) != null) {
	    document.getElementById('dayToGenerateReportParam' + i).style.display = "none";
    	}
    }

    if(selectedReportRunFrequency == null || selectedReportRunFrequency == '') {
       selectedReportRunFrequency = '<%=ReportRunFrequency.MONTHLY.getCode()%>';
    }

    if(document.getElementById('dayToGenerateReportParam' + selectedReportRunFrequency) != null) {
	document.getElementById('dayToGenerateReportParam' + selectedReportRunFrequency).style.display = "block";
    }
}

function clearField(fieldId) {
    if(document.getElementById(fieldId) != null) {
   	document.getElementById(fieldId).value = '';
    }
}


</script>
	