// Common functions for screen form control and validation

// $Header: /CVSRepository/DotNet/AWF/JScript/control.js,v 1.1.1.1 2007/01/17 10:58:39 Sarah Wright Exp $

// Synopsis : Check for entry in checkbox, multi select and
// text boxes. Prompt user if no entry 
// Note there is a problem with using this for single select ("select-one")
// because the selectedIndex is the same (0) if nothing is selected or the first
// element is selected.

function CheckForEntry(theForm, sErrorMessage)
{
  var bDataEntered = false;
  var i = 0
  while ((i < theForm.length) && (bDataEntered == false)) {
     switch (theForm.elements[i].type) {
      case "checkbox" :
        if (theForm.elements[i].checked == true) 
          bDataEntered = true;
        break; 
      case "select-multiple" :
        if (theForm.elements[i].selectedIndex != -1) 
          bDataEntered = true;
        break; 
      case "text" :
        if (theForm.elements[i].value != "") 
          bDataEntered = true;
        break; 
    }
    i++
  }
  
  if ((bDataEntered == false) &&
    !(confirm(sErrorMessage))) 
      return(false);
  return(true);
}

// Synopsis : Clear all selections in checkbox, multi select and
// text boxes.  
// Note that this function does not work for select one

function ClearSelection(theForm)
{
    for (var i = 0; i<theForm.length-1; i++) {
      switch (theForm.elements[i].type) {
      case "checkbox" :
        theForm.elements[i].checked = false; 
        break; 
      case "select-multiple" :
        for (var j=0;j<theForm.elements[i].length - 1;j++) 
          theForm.elements[i].options[j].selected = false;
        break; 
      case "text" :
        theForm.elements[i].value = "";
        break; 
    }
  }
}

// Synopsis : Opens a new window - can define width and height

function newWindow(URL, w, h)
{
newwin=window.open(URL,'','left=0,top=0,width=' + w + ',height=' + h + ',resizable=1,status=0,scrollbars=1,toolbar=1,menubar=0');
}

function newWindowMinimum(URL, w, h)
{
var newwin=window.open(URL,'','left=0,top=0,width=' + w + ',height=' + h + ',resizable=0,status=0,scrollbars=0,toolbar=0,menubar=0');
newwin.opener = window;
}

