//opens a window
function openWindow(strUrl, strName, intHeight, intWidth, blnResizeable, blnScrollBars)
{
  var winNewPopUp
  var strResizeable
  var strScrollBars

  strResizeable = (blnResizeable) ? "yes" : "no";
  strScrollBars = (blnScrollBars) ? "yes" : "no";

  if (!winNewPopUp) {
    winNewPopUp = window.open(strUrl,strName,"dependent=yes,directories=no,height=" + intHeight + ",width=" + intWidth + ",location=no,menubar=no,resizable=" + strResizeable + ",scrollbars=" + strScrollBars + ",titlebar=no,toolbar=no,status=yes");
    winNewPopUp.focus();
  }
  if(winNewPopUp.opener == null) {
    winNewPopUp.opener ==window;
  }
}
//opens a window allowing a menu bar to be added
function openWindow(strUrl, strName, intHeight, intWidth, blnResizeable, blnScrollBars, blnMenuBar)
{
  var winNewPopUp
  var strResizeable
  var strScrollBars

  strResizeable = (blnResizeable) ? "yes" : "no";
  strScrollBars = (blnScrollBars) ? "yes" : "no";

  if (!winNewPopUp) {
    winNewPopUp = window.open(strUrl,strName,"dependent=yes,directories=no,height=" + intHeight + ",width=" + intWidth + ",location=no,menubar=" + blnMenuBar + ",resizable=" + strResizeable + ",scrollbars=" + strScrollBars + ",titlebar=no,toolbar=no,status=no");
    winNewPopUp.focus();
  }
  if(winNewPopUp.opener == null) {
    winNewPopUp.opener ==window;
  }
}

//opens a window with the specified features
function openPortalWindow(strUrl, strName, intHeight, intWidth, features) {
  var winNewPopUp

  if (!winNewPopUp) {
    winNewPopUp = window.open(strUrl,strName,"height=" + intHeight + ",width=" + intWidth + "," + features);
    winNewPopUp.focus();
  }
  if(winNewPopUp.opener == null) {
    winNewPopUp.opener ==window;
  }
}

function placeFocus() {
 if (document.forms.length > 0) {
  var field = document.forms[0];
  for (i = 0; i < field.length; i++) {
   if (((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type == "password") || (field.elements[i].type.toString().charAt(0) == "s"))
         && !field.elements[i].disabled) 
   {
    document.forms[0].elements[i].focus();
    break;
   }
  }
 }
}

function clearForm() {
 if (document.forms.length > 0) {
  var field = document.forms[0];
  for (i = 0; i < field.length; i++) {
   if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea")) {
    document.forms[0].elements[i].value = '';
   }
  }
 }
}

function redirectWindow(url) {
  opener.location = url;
  close();
}

var submissions = 0;
function blockResubmit() {
  if (submissions == 0) {
    submissions++;
    return true;
  } else {
    return false;
  }
}

function toggle(targetId){
  if (document.getElementById){
      target = document.getElementById( targetId );
      if (target.style.display == "none"){
          target.style.display = "";
          } else {
              target.style.display = "none";
          }
      }
}

function selectAllOptions(field) {
  for (i = 0; i < field.length; i++) {
    field[i].selected = true;
  }
}

// Validates that an option has been selected. An alert with the specified message is displayed if not.
function validateOptionSelected(elementName, message)
{
    if(document.forms['0'].elements[elementName].selectedIndex == -1){
        alert(message);
        return false;
    }
    return true;
}

