<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {
    if ((appName=="Netscape")&&(parseInt(appVersion,10)==4)) {
      document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
    }
  } else
    if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH)
  location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
    x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images) {
    if(!d.MM_p)
      d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
    for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0) {
        d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
      }
  }
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d)
    d=document;
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all)
    x=d.all[n];
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
    x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById)
    x=d.getElementById(n);
  return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){
     document.MM_sr[j++]=x;
     if(!x.oSrc)
       x.oSrc=x.src;
     x.src=a[i+2];
   }
}

function confirmcontinue(which) {
	if(confirm("By clicking ok the users information will be updated"))
		return true;
	else
		return false;
}

function addCredit(form) {
	form.Fcredit.value = eval(parseFloat(form.Fcredit.value) + .5);
}

function minusCredit(form) {
	form.Fcredit.value = eval(parseFloat(form.Fcredit.value) - .5);
}
function totalCredit(form,sessionCredit) {
    sessionCredit = parseFloat(sessionCredit);
	form.total_credit.value = eval(parseFloat(form.Fcredit.value) + sessionCredit);
}

function confirmRemove()
{
	var msg = "CAUTION: You have selected the remove user option! This will remove any users \nfrom this course that do not appear in the upload file and could remove\nthose users from the system entirely. Do not use this option if you are\ngoing to upload two different files for this course\nie. uploading a course list then uploading another list containing open \nenrollment students.";
	alert(msg);
}

function checkTextBox(elem,msg)
{
	var valid = true;
	if(elem.value.length == 0)
	{
		valid = false; 
	}
	if (!valid)
	{
		alert(msg)
		return false;
	}
	return true;
}

function checkUserType(which,all)
{
	if(all == "all")
	{
		if(!which.type2.checked && !which.type4.checked && !which.type8.checked && !which.type16.checked && !which.type32.checked)
		{
			alert("Error: You must select the user type for this user.");
			return false;
		}
		if(which.type32.checked)
		{
			if(which.type2.checked || which.type4.checked)
			{
				alert("Error: A user can not be that combination of user types.");
				return false;
			}
		}
		if(which.type4.checked)
		{
			if(which.type2.checked || which.type8.checked || which.type16.checked || which.type32.checked)
			{
				alert("Error: An Office Staff user can not be a combination of any other type.");
				return false;
			}
		}
		if(which.type16.checked)
		{
			if(which.type2.checked)
			{
				alert("Error: A Faculty user can not also be a Human Subject type.");
				return false;
			}
		}
		if(which.type8.checked && !which.type4.checked && !which.type16.checked && !which.type32.checked)
		{
			if(!which.elements['Acourses[]'] || which.elements['Acourses[]'].length == 0)
			{
				alert("Error: Human Subjects and Researchers must be in at least one course.");
				return false;
			}
		}
		if(which.type16.checked || which.type32.checked || which.type4.checked)
		{
			if(which.elements['Acourses[]'] && which.elements['Acourses[]'].length != 0)
        	{
				alert("Error: Faculty, Office Staff, or Administrator users can not be enrolled in courses.");
				return false;
			}
		}
	}
	else if(all == "office_staff")
	{
		if(!which.type2.checked && !which.type8.checked && !which.type16.checked)
		{
			alert("Error: You must select the user type for this user.");
			return false;
		}
		if(which.type8.checked)
		{
			if(!which.elements['Acourses[]'] || which.elements['Acourses[]'].length == 0)
			{
				alert("Error: Human Subjects and Researchers must be in at least one course.");
				return false;
			}
		}
		if(which.type16.checked)
		{
			if(which.elements['Acourses[]'] && which.elements['Acourses[]'].length != 0)
        	{
				alert("Error: Faculty users can not be enrolled in courses.");
				return false;
			}
		}
	}
	else
	{
		if(!which.type2.checked && !which.type8.checked)
		{
			alert("Error: You must select the user type for this user.");
			return false;
		}
		if(which.type8.checked)
		{
			if(!which.elements['Acourses[]'] || which.elements['Acourses[]'].length == 0)
			{
				alert("Error: Human Subjects and Researchers must be in at least one course.");
				return false;
			}
		}
	}
	if(which.type2.checked)
	{
		if(!which.elements['Acourses[]'] || which.elements['Acourses[]'].length == 0)
		{
			alert("Error: Human Subjects and Researchers must be in at least one course.");
			return false;
		}
	}
	return true;
}

function checkBatchAdd(which)
{
	if(!which.course.value)
	{
		alert("Error: You must select a course to students to.");
		return false;
	}
	if(!which.type2.checked && !which.type8.checked)
	{
		alert("Error: You must select a user type for the students being added.");
		return false;
	}
	return true;
}

function checkUserForm(which)
{
	if(which.lastName.value == 0)
	{
		alert("Error: You must enter a last name.");
		return false;
	}
	if(!(/^[a-zA-Z'_\-]*$/.test(which.lastName.value)))
	{
		alert("Error: A users last name can not contain numbers.");
		return false;
	}
	if(which.firstName.value == 0)
	{
		alert("Error: You must enter a first name.");
		return false;
	}
	if(!(/^[a-zA-Z'_\-]*$/.test(which.firstName.value)))
	{
		alert("Error: A users first name can not contain numbers.");
		return false;
	}
	if(!checkSSN(which.ssn))
		return false;
	return true;
}

function courseVerify(which)
{
	if(which.name.value == 0)
	{
		alert("Error: You must enter a name.");
		return false;
	}
	if(which.section.value == 0)
	{
		alert("Error: You must enter a Section.");
		return false;
	}
	if(which.cid.value == 0)
	{
		alert("Error: You must enter a Course Call number.");
		return false;
	}
	if(!(/^[0-9]{5}$/.test(which.cid.value)))
	{
		alert("Error: You must enter 5 integer values for the Course Call number.");
		return false;
	}
	if(!(/^[0-9]{2}$/.test(which.section.value)))
	{
		alert("Error: You must 2 integer values for the section. Ex: 02");
		return false;
	}
}

function checkSSN(elem)
{
	if(elem.value.length == 0)
	{
		alert("Error: You must enter an SSN.");
		return false;
	}
  	if(!(/^[0-9]{4}$/.test(elem.value)))
	{
		alert("Error: You must enter integer values for the SSN.");
		return false;
	}
	return true;
}

function checkEmail(which) {
	if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test
		(which.email.value)) {
		return (true)
	}
	if(which.email.value == 0)
	{
		return (true)
	}
	alert("Invalid E-mail Address! Please re-enter.")
	return (false)
}

function checkrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0;i<which.length;i++) {
      var tempobj=which.elements[i];
      if (((tempobj.type=="text"||tempobj.type=="textarea")&&
        tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
        tempobj.selectedIndex==0)) {
        pass=false;
        break;
      }
    }
  }
  if (!pass) {
    shortFieldName=tempobj.name.toUpperCase();
    alert("Please make sure the "+shortFieldName+" field was properly completed.");
    return false;
  } else
    return true;
}

function addrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0;i<which.length;i++) {
      var tempobj=which.elements[i];
	if (tempobj.name.substring(1,9)=="required") {	
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
            tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
            tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
	}
    }
  }
  if (!pass) {
    shortFieldName=tempobj.name.substring(9,30).toUpperCase();
    alert("Please make sure the "+shortFieldName+" field was properly completed.");
    return false;
  } else
    return true;
}

// Compare two options within a list by VALUES
function compareOptionValues(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.value, 36 );  
  var sB = parseInt( b.value, 36 );  
  return sA - sB;
}

// Compare two options within a list by TEXT
function compareOptionText(a, b) 
{ 
  // Radix 10: for numeric values
  // Radix 36: for alphanumeric values
  var sA = parseInt( a.text, 36 );  
  var sB = parseInt( b.text, 36 );  
  return sA - sB;
}

function moveList(src,dest)
{
  srclen = src.length ;
  for ( i=0; i<srclen ; i++)
  {
    if (src.options[i].selected == true )
    {
      destlen = dest.length;
      dest.options[destlen]= new Option(src.options[i].text);
      dest.options[destlen].value = src.options[i].value;
    }
  }
  for ( i=(srclen-1); i>=0; i--)
  {
    if (src.options[i].selected == true )
    {
      src.options[i] = null;
    }
  }
}

// Dual list move function
function moveDualList( srcList, destList, moveAll ) 
{
  // Do nothing if nothing is selected
  if (  ( srcList.selectedIndex == -1 ) && ( moveAll == false )   )
  {
    return;
  }
  newDestList = new Array( destList.options.length );
  var len = 0;
  for( len = 0; len < destList.options.length; len++ ) 
  {
    if ( destList.options[ len ] != null )
    {
      newDestList[ len ] = new Option( destList.options[ len ].text, destList.options[ len ].value, destList.options[ len ].defaultSelected, destList.options[ len ].selected );
    }
  }
  for( var i = 0; i < srcList.options.length; i++ ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[ len ] = new Option( srcList.options[i].text, srcList.options[i].value, srcList.options[i].defaultSelected, srcList.options[i].selected );
       len++;
    }
  }
  // Sort out the new destination list
  //newDestList.sort( compareOptionValues );   // BY VALUES
  //newDestList.sort( compareOptionText );   // BY TEXT
  // Populate the destination with the items from the new array
  for ( var j = 0; j < newDestList.length; j++ ) 
  {
    if ( newDestList[ j ] != null )
    {
      destList.options[ j ] = newDestList[ j ];
    }
  }
  // Erase source list selected elements
  for( var i = srcList.options.length - 1; i >= 0; i-- ) 
  { 
    if ( srcList.options[i] != null && ( srcList.options[i].selected == true || moveAll ) )
    {
       // Erase Source
       //srcList.options[i].value = "";
       //srcList.options[i].text  = "";
       srcList.options[i]       = null;
    }
  }
} // End of moveDualList()

function requireSelect(combo,msg)
{
  for (var i=0;i<combo.options.length;i++)
  {
    if ( combo.options[i].selected )
    {
       return true;
    }
  }
  alert(msg);
  return false;
}

function SelectEm(combo,val)
{
  for (var i=0;i<combo.options.length;i++)
  {
    combo.options[i].selected=val;
  }
}

function SelectAll(combo)
{
  SelectEm(combo,true);
}

function SelectNone(combo)
{
  SelectEm(combo,false);
}

function addTime(form,obj)
{
  var nameArr = obj.name.split("_");
  var dInd = parseInt(nameArr[1],10);
  var tInd = parseInt(nameArr[2],10);
  var start=0;
  var stop=0;
  var timeIndices = Array();
  var range;
  /**
   * Check to see if there is only one time checked.
   * if so we need to set the range to that value.
   * instead of calling split
   */
  if(form.times.value.length==1)
  {
    timeIndices[0]=form.times.value;
    range=1;
  } else {
    timeIndices = form.times.value.split(",");
    range=timeIndices[0]-timeIndices[timeIndices.length-1]+1;
  }
  if(form.date.value == dInd && obj.checked==true)
  {
    uncheckAll(form,false);
    if(timeIndices[0] < tInd)
    {
      start=parseInt(timeIndices[0],10);
      stop=tInd;
    } else {
      start=tInd;
      stop=parseInt(timeIndices[timeIndices.length-1],10);
    }
    if(start > stop)
    {
      var temp=start;
      start=stop;
      stop=temp;
    }
    range=stop-start+1;
    if(onlyOfDuration && (SessionDuration*2 < range))
    {
      alert("Notice: The current project only allows sessions that last "+SessionDuration+" hour[s].");
      uncheckAll(form,true);
      return false;
    } else {
      if(range > limits[dInd])
      {
        alert("Notice: You may only reserve "+limits[dInd]/2+" hour[s] on this day. There is a 2-hour per day limit during the first 8 weeks of the semester.");
        uncheckAll(form,true);
        return false;
      } else {
        checkAllInRange(form,dInd,start,stop);
      }
    }
  } else {
    if(obj.checked == true)
    {
      uncheckAll(form,true);
      obj.checked=true;
      form.date.value=dInd;
      form.times.value=tInd;
    } else {
      if(timeIndices.length != 1 && timeIndices[0] < tInd && tInd < timeIndices[timeIndices.length-1]) {
        alert("Warning: Times must be continuous."); 
        obj.checked=true;
      } else {
        if(timeIndices.length == 1) {
          form.date.value="";
          form.times.value="";
        } else {
          if(timeIndices[0]==tInd){
            start=timeIndices[1];
            stop=timeIndices[timeIndices.length-1];
          } else {
            start=timeIndices[0];
            stop=timeIndices[timeIndices.length-2];
          }
          checkAllInRange(form,dInd,start,stop);
        }
      }
    }
  }
}

function checkAllInRange(form,dInd,start,stop)
{
  var elem="";
  if(stop-start>0) {
    /*
     * Initialize the temp storage to the first element
     */
    form.times.value=start;
    form.elements["check_"+dInd+"_"+start].checked=true;
    /*
     * Add a ',' and the index for every additional time
     * only if no break in time is detected.
     */
    for(var i=parseInt(start,10)+1;i<=stop;i++)
    {
      elem="check_"+dInd+"_"+i;
      if(form.elements[elem])
      {
        form.elements[elem].checked=true;
        if(form.times.value=="")
        {
          form.times.value=i;
        } else {
          form.times.value=form.times.value+","+i;
        }
      } else {
        alert("Error: Times must be continuous.\nThere is a time that is not available between the selected ranges.");
        uncheckAll(form,true);
        return false;
      }
    }
  } else {
    if(start==stop) {
      form.date.value=dInd;
      form.times.value=start;
    } else {
      form.times.value="";
      form.date.value="";
    }
  }
}

function uncheckAll(form,clear)
{
  for(var i=0;i<form.elements.length;i++)
  {
    var tempName = form.elements[i].name.split("_");
    if(tempName[0]== "check")
    {
      if(form.elements[i].checked == true)
      {
        form.elements[i].checked = false;
      }
    }
  }
  if(clear)
  {
    form.times.value="";
    form.date.value="";
  }
}

function ValidateModifyProject(form)
{
  if(isNaN(parseFloat(form.Frequiredcredit.value))) {
    alert("Error: The required credit field is not a valid number.\nNote: please enter a valid positive number.");
    return false;
  } else if(parseFloat(form.Frequiredcredit.value) <= 0 || parseFloat(form.Frequiredcredit.value) > 3) {
    alert("Error: The required credit field is not valid.\nNote: please enter the amount of credit each student shall receive upon completion of a session for this project. This should be a number (in hours) less than 3.");
    return false;
  }
  if(isNaN(parseInt(form.Irequiredsubjects_needed.value,10))) {
    alert("Error: The required subjects needed field is not a valid number.\nNote: please enter a valid positive number.");
    return false;
  } else if(parseInt(form.Irequiredsubjects_needed.value,10) <= 0) {
    alert("Error: The required subjects needed field is not a valid number.\nNote: please enter a valid positive number.");
    return false;
  }
  return true;
}

function ValidateTimeForm(form,allowSameTimes)
{
  var shr,smin,smer,ehr,emin,emer;
  shr=parseInt(form.startHour.options[form.startHour.selectedIndex].text,10);
  smin=parseInt(form.startMinute.options[form.startMinute.selectedIndex].text,10);
  smer=form.startMerid[getSelectedRadio(form.startMerid)].value;
  ehr=parseInt(form.endHour.options[form.endHour.selectedIndex].text,10);
  emin=parseInt(form.endMinute.options[form.endMinute.selectedIndex].text,10);
  emer=form.endMerid[getSelectedRadio(form.endMerid)].value;
  if(form.elements['Adates[]'].length == 0)
  {
    alert("Error: Please select at least one date from the calendar.");
    return false;
  }
  /** the merids are the same */
  if( smer == emer )
  {
    /**
     * The start hour is after or
     * The hours are the same and the minutes are less
     */
    if((shr!=12 && ehr!=12) && (ehr < shr) || (ehr == shr && emin < smin))
    {
      alert("Error: the Start Time is before the End Time");
      return false;
    }
    /**
     * the times are the same and that is not allowed
     */
    if(ehr == shr && emin == smin && shr != 12)
    {
      if(!allowSameTimes)
      {
        alert("Error: the Start Time is the same as the End Time");
        return false;
      } else {
        if(!confirm("Are you sure you want to make these days unavailable?"))
          return false;
      }
    }
  }
  /** the start merid is pm and the end merid is am */
  if(smer == "pm" && emer == "am")
  {
    alert("Error: the Start Time is before the End Time");
    return false;
  }
  SelectAll(form.elements['Adates[]']);
  return true;
}

function ValidateDuration(form)
{
  var timeIndices = form.times.value.split(",");
  return false;
}

function ValidateSubjectCount(form,limit)
{
  if(form.subjectLimit.value.length == 0)
  {
    alert("Error: Please enter the number of subjects needed.\nNote: The subject limit must be lower than "+limit+".");
    return false;
  } else if(isNaN(parseInt(form.subjectLimit.value,10))) {
    alert("Error: subject limit is not a valid number.\nNote: The subject limit must be a whole number.");
    return false;
  } else if(parseInt(form.subjectLimit.value,10) > limit) {
    alert("Error: This room can only hold "+limit+" students.\nPlease lower the amount needed or select another room.");
    return false;
  } else if(parseInt(form.subjectLimit.value,10) == 0) {
    return confirm("Warning: If you set the subject limit to 0 then no subjects will be able to sign-up for this session in advance. This is only useful when conducting research with packets.\n\nClick [OK] if this session is for research involving take-home packets.\nClick [Cancel] if you want subjects to see this session (you need to change the subjects needed field to the number of subjects that are allowed to sign up in advance.)");
  } else {
    return true;
  }
}


function ValidateCheckedTimes(form)
{
  var retval = false;
  var timeIndices = form.times.value.split(",");
  var dateIndex=form.date.value;
  if(isNaN(form.date.value) || form.times.value.length == 0)
  {
    alert("You must select at least one time.");
	return false;
  }
  if(onlyOfDuration && (SessionDuration*2 != timeIndices.length))
  {
    alert("Notice: The current project only allows sessions that last "+SessionDuration+" hour[s].");
    return false;
  } else {
    if(onlyOfDuration && timeIndices.length > limits[dateIndex])
    {
      alert("Notice: You may only reserve "+limits[dateIndex]/2+" hour[s] on this day.");
      return false;
    }
  }
  form.times.value=times[timeIndices[0]];
  for(i=1;i<timeIndices.length;i++)
  {
    form.times.value=form.times.value+","+times[timeIndices[i]];
  }
  form.date.value=dates[dateIndex];
  form.start.value=times[timeIndices[0]];
  var end=times[timeIndices[timeIndices.length-1]].split(":");
  if(end[1]=="00")
  {
    end[1]="30";
  } else {
    end[0]=eval(end[0]+"+1");
    end[0]=(end[0]<10) ? "0"+end[0] : end[0];
    end[1]="00";
  }
  form.end.value=end[0]+":"+end[1];
  return true;
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}

function requireRadio(elem,msg)
{
  var selected = false;
  for(var i=0; i < elem.length; i++)
  {
    if (elem[i].checked)
    selected = true; 
  }
  if (!selected && !elem.checked )
  {
    alert(msg)
    return false;
  }
  return true;
}

function popCalendar( root, obj )
{
    dateList = obj;
    childWin = window.open( root+'/cal.php', 'calwin', 'top=250px,left=250px,width=250px,height=220px,scollbars=false' );
}

function closeCalendar()
{
  if(childWin)
    childWin.close();
}

function addOption(text,value)
{
    obj = dateList;
    if (obj!=null && obj.options!=null)
    {
        obj.options[obj.options.length] = new Option(text, value, false);
    }
}

function removeSelected(obj)
{
  var len = obj.length-1;
  for ( i=len; i>=0; i--)
  {
    if(obj.options[i].selected)
      obj.options[i] = null;
  }
}

function removeOption(index)
{
    obj = dateList;
    if(obj!=null && obj.length >= index)
    {
        obj.options[index] = null;
    }
}



//-->
