// JScript source code

function fillRoundCombo(cmbRound, cmbCompetition) {
  var sCompetitionID = 'All';
  var oOption;
  
  if (cmbCompetition.selectedIndex != -1) {
    sCompetitionID = cmbCompetition.value;
  }
  // clear combo
  cmbRound.innerHTML = '';
  oOption = document.createElement("OPTION");
  oOption.text = 'All Rounds';
  oOption.value = 'All';
  cmbRound.options.add(oOption);

  if (sCompetitionID != 'All') {
    var xmlCompetition = xmlCompRound.XMLDocument;
    var oNodes = xmlCompetition.selectNodes("/response/competition[@competitionID='" + sCompetitionID + "']/round");
    
    for( var i=0; i < oNodes.length; i++ ) {
      oOption = document.createElement("OPTION");
      oOption.text = oNodes[i].getAttribute("roundNumber") + " (" +
        dateToString(convertISOtoDate(oNodes[i].getAttribute("date"))) + ")";
      oOption.value = oNodes[i].getAttribute("roundNumber");
      cmbRound.options.add(oOption);      
    }
  }
}

function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) 
{

	var i, j;
	var prompt;
	// empty existing items
	for (i = selectCtrl.options.length; i >= 1; i--) 
	{
		selectCtrl.options[i] = null; 
	}
	
	prompt = (itemArray != null) ? goodPrompt : badPrompt;
	
	if (prompt == null) 
	{
		j = 0;
	}
	else 
	{
		selectCtrl.options[0] = new Option(prompt);
		j = 1;
	}

	if (itemArray != null) 
	{
	  // add new items
	  for (i = 0; i < itemArray.length; i++) 
	  {
		    selectCtrl.options[j] = new Option(itemArray[i][0]);
		    if (itemArray[i][1] != null) 
		    {
			      selectCtrl.options[j].value = itemArray[i][1]; 
		    }
		    j++;
	  }
	}
	// select first item (prompt) for sub list
	//selectCtrl.options[1].selected = true;
}

function checkForAllResults(selectedForm, notAllItem, notAllItemName)
{
	var iNumListBoxes = 0;
	var iNumAllSelected = 0;
	var notAllItemValue = 'null';
	
	
	for(i=0;i < selectedForm.length;i++)
	{
		if (selectedForm[i].type == "select-one")
		{
			if (selectedForm[i].name == notAllItem)
			{
				notAllItemValue = selectedForm[i].value;
			}
			iNumListBoxes++;
			if (selectedForm[i].value == "All")
			{
				iNumAllSelected++;
			}
		}
	}
	
	if (notAllItemValue == 'All' | notAllItemValue == '')
	{
		alert('Please select a value for ' + notAllItemName);
		return false;
	}
	else 
	{
		if (iNumListBoxes == iNumAllSelected & iNumAllSelected > 0)
		{
			alert('It is not possible to return all results. Please select one of the options.');
			return false;
		} else {
			return true;
		}
	}
	
}

