//  Function to open a window
function windowOpen(window_url) {
  firsthalf='toolbar=yes,status=no,scrollbars=yes,menubar=yes,resizable=yes'
  secondhalf=',directories=no,location=no,width=550,height=400'
  whole = firsthalf + secondhalf
  helpWin = window.open(window_url,'',whole);
  if (document.images) { 
     if (helpWin) helpWin.focus()
  }
}

//  Function to disable the submit button after it is clicked.
function onesubmit() {
  document.forms[0].submitbutton.value = "Processing";
  document.forms[0].submitbutton.disabled = true;
  return true;
  }

//  Function to disable a second submit button after it is clicked.
function onesubmit2() {
  document.forms[1].submitbutton.value = "Processing";
  document.forms[1].submitbutton.disabled = true;
  return true;
  }

//  Function to validate search criteria in Course Section Search. If 
//  successful, invoke onesubmit function.
function Crs_Srch_Validate()
{
  var SubjIx  = document.forms[0].Subject.selectedIndex;
  var Time1Ix = document.forms[0].StartTime1.selectedIndex;
  var Time2Ix = document.forms[0].StartTime2.selectedIndex;
  if (!document.forms[0].Mon.checked &&
      !document.forms[0].Tue.checked &&
      !document.forms[0].Wed.checked &&
      !document.forms[0].Thu.checked &&
      !document.forms[0].Fri.checked &&
      !document.forms[0].Sat.checked &&
      !document.forms[0].Sun.checked &&
      !document.forms[0].TBA.checked &&
      !document.forms[0].All.checked &&
       document.forms[0].Subject.options[SubjIx].value == "ALL" &&
       document.forms[0].StartTime1.options[Time1Ix].value == "ALL" &&
       document.forms[0].StartTime2.options[Time2Ix].value == "ALL")   
  {
    alert("Please select at least one of the first 4 options.");
    return false; 
  }
  else
  if (!document.forms[0].Mon.checked &&
      !document.forms[0].Tue.checked &&
      !document.forms[0].Wed.checked &&
      !document.forms[0].Thu.checked &&
      !document.forms[0].Fri.checked &&
      !document.forms[0].Sat.checked &&
      !document.forms[0].Sun.checked &&
      !document.forms[0].TBA.checked &&
      !document.forms[0].All.checked)
  {
    alert("At least one 'Day' option must be selected.");
    return false; 
  }
  else
  if (document.forms[0].StartTime1.options[Time1Ix].value != "ALL" && 
      document.forms[0].StartTime2.options[Time2Ix].value != "ALL" &&
      document.forms[0].StartTime1.options[Time1Ix].value > 
      document.forms[0].StartTime2.options[Time2Ix].value)
  {
   alert("The first Start Time can not be greater than the second Start Time.");
   return false;
  }
  else
  {
  onesubmit();
  }
}

//  Function to modify a Course section literal into a WebCT link 
function launchWebCT(ctitle, WebctInUseNoCP, WebctURL, DCode){
  var openNewWindow = " This link will open a new window.";
  if (WebctInUseNoCP == "true" && DCode == "WC") {
     document.write('<a href="'+ WebctURL + '" target="WebCT"'+
     '" title="' + ctitle + openNewWindow +
     '" onMouseOver="window.status=(\'' + ctitle + openNewWindow +'\'); ' +
     'return true;" onMouseOut="window.status=\'\'; return true">' +
      ctitle + '</a>' ); }
  else { 
     document.write(ctitle);
     }
  }

//  Function to convert an email address into a link 
function sendEmail(emailaddr){
  if (emailaddr == "Unavailable" ||
      emailaddr == "Unavailable by student request") { 
     document.write(emailaddr);
     }
  else { 
     document.write('<a href="mailto:' + emailaddr + '">' + emailaddr + 
     '</a>'); }
     }
