<!--

/* This Function Moves rows from one list box to another */
function Activate_MoverBox(active_box,dest_box)
{ for(var i=0; i<active_box.options.length; i++) 
	{if(active_box.options[i].selected && active_box.options[i].value != "" && active_box.options[i].value != "#")
		{  
			var luo_option = new Option();
			luo_option.value = active_box.options[i].value;
			luo_option.text  = active_box.options[i].text;
			dest_box.options[dest_box.options.length] = luo_option;
			active_box.options[i].value = "";
			active_box.options[i].text  = "";
   		}
	}
	Remove_Empty_Rows(active_box);
	Remove_Empty_Rows(dest_box);
	dest_box.selectedIndex = -1;
	active_box.selectedIndex = -1;
}

/* This Function Removes An Item From A List Box */
function Remove_Item(id)
{
  for(var i=0; i<document.Instructors.All_Instructors.options.length; i++)
     {
        if(parseInt(document.Instructors.All_Instructors.options[i].value) == parseInt(id))
          {
             document.Instructors.All_Instructors.options[i].value = "";
             document.Instructors.All_Instructors.options[i].text  = "";   
             Remove_Empty_Rows(document.Instructors.All_Instructors);
          }
     }
}
/* This function selects an in the list give the field, and the list box */   
function doSelectChange(el,dest) {
    dest.value = el.options[el.selectedIndex].text
}

function lookupItem(el,dest) {
    var curValue = el.value.toLowerCase()
    var found = false
    var index = dest.selectedIndex
    var numOptions = dest.options.length
    var pos = 0
    // Repeat until found or end of list is reached
    while ((!found) && (pos < numOptions)) {
      // Do comparisons in lowercase
      found = (dest.options[pos].text.toLowerCase().indexOf(curValue)==0) 
      if (found) 
        index = pos
      pos++
    }
    if (found)  // Updated listbox
      dest.selectedIndex = index
}

/* This Function Sorts a List box */
function Sort_ListBox(box)
{	var temp      = new Object();
	var li_count  = box.options.length;
	for(var x=0; x < li_count; x++)
	{
		for(var y=(x+1); y<li_count; y++)
		{   
			if(box.options[x].text > box.options[y].text)
			{
				temp.text = box.options[x].text;
				temp.value = box.options[x].value;
				box.options[x].text  = box.options[y].text;
				box.options[x].value = box.options[y].value;
				box.options[y].text  = temp.text;
				box.options[y].value = temp.value;
      		}
   		}
	}
}


/* This Function removes empty lines from the list box */
function Remove_Empty_Rows(box)
{   var li_count = box.options.length ;
	var li_offset= 0;
    var li_total = 0;
	for(var li_next  = 0; (li_next + li_offset) < (li_count); li_next++) 
	{ while(box.options[li_next + li_offset].value == "")
		{   li_offset++;
			if ((li_next + li_offset) >= li_count) break;
	    }
	  if ((li_next + li_offset) >= li_count) break;
	  box.options[li_total].value = box.options[li_next + li_offset].value;
	  box.options[li_total].text  = box.options[li_next + li_offset].text;
	  li_total++	  
	}	
	box.options.length = (li_count - li_offset);  
}	

/* This Function determines what a user typed in a text box
   and then moves all the entries in a source list box the 
   that match the patterns to the destination box. */
function f_MoverFastEntry(atxt_data, alb_FromBox, alb_ToBox, auo_next_focus)
{   
	var ls_data = atxt_data.value;

	if (ls_data.length > 0)
	{
		var ls_match = /(\b\w+\b)+/;
		var lobj_results = ls_match.exec(ls_data);
		
		while (lobj_results != null)		
		{	ls_data = ls_data.slice(lobj_results[0].length + 1);
 			var lreg_pattern = new RegExp(("^" + lobj_results[0]) ,"i");
 			for(var i=0; i<alb_FromBox.options.length; i++) 
 			{if(lreg_pattern.test(alb_FromBox.options[i].text))
 				{alb_FromBox.options[i].selected = true;}
  			}
			lobj_results = ls_match.exec(ls_data);
		}
	Activate_MoverBox(alb_FromBox,alb_ToBox);
	atxt_data.value = "";
	}
	if (auo_next_focus.toString() == "[object]") auo_next_focus.focus();
}

function f_SelectAll(alb_Selected)
{   for(var i=0; i<alb_Selected.options.length; i++) 
 	{ alb_Selected.options[i].selected = true;
 	}
}

function f_AtleastOneChosen(alb_Selected,keyword)
{   if(alb_Selected.options.length == 0 || alb_Selected.options.length == null)
      { alert("You must choose at least one " + keyword +"...")
        return false;
      }
    else 
	{
	f_SelectAll(alb_Selected); 
	return true; 
	}
}

function f_AtleastOneChosenA(alb_Selected,keyword)
{   if(alb_Selected.options.length == 0 || alb_Selected.options.length == null)
      { alert("You must choose at least one " + keyword +"...")
        return false;
      }
}

/* FUNCTION TO VALIDATE A SINGLE OPTION SELECT BOX */
function f_ChooseOne(alb_Selected,keyword)
{   
  if (alb_Selected.selectedIndex < 0)
  {
    alert("You must choose a " + keyword +"...");
    alb_Selected.focus();
    return (false);
  }
  return (true);
}

function f_DeSelectAll(alb_Selected)
{   for(var i=0; i<alb_Selected.options.length; i++) 
 	{ alb_Selected.options[i].selected = false;
 	}
}

/* function that opens page to add new */
function AddNew(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=520,HEIGHT=520,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open(url + "&modType=ADD", "AddNew",newFeatures) 
    newWindow.focus();
}

/* function that opens page to edit record */
function EditRecord(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=520,HEIGHT=520,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open(url + "&modType=EDIT", "EditRecord",newFeatures);
    newWindow.focus();
}

/* function that opens page to copy and add a record */
function CopyRecord(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=520,HEIGHT=520,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open(url + "&modType=COPY", "CopyRecord",newFeatures);
    newWindow.focus();
}

/* function that opens page and deletes record */
function DeleteRecord(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    var agree=confirm("Are you sure you want to delete this record?");
	
    if (agree)
    {
      newFeatures = 'WIDTH=400,HEIGHT=125,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
      newWindow = window.open(url + "&modType=DELETE", "DeleteRecord",newFeatures);
      newWindow.focus();
    } else 
      {
        return false;
      }
}


/* function that opens page to view record list */
function ViewList(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=400,HEIGHT=500,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open(url + "&modType=VIEW", "ViewList",newFeatures) 
    newWindow.focus();
}

/* function that opens page to report errors */
function reportError(url, uid)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=400,HEIGHT=350,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open("ErrorPage.asp?url="+url+"&uid="+uid, "ReportError",newFeatures) 
    newWindow.focus();
}

/* function that opens page to register new user */
function NewUser()
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=550,HEIGHT=400,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open("NewUser.asp?a=1", "AddNew",newFeatures) 
    newWindow.focus();
}

/* function that opens page to get lost password */
function ForgotPassword()
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=550,HEIGHT=180,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open("LostPassword.asp", "LostPassword",newFeatures) 
    newWindow.focus();
}
/* function that checks to make sure only one instructor is chosen 
 function checkView() {
   allSelected = 0
   chosenSelected = 0
   
   for (i=0;i<document.Instructors.All_Instructors.length;i++) { 
       if (document.Instructors.All_Instructors.options[i].selected) {
          allSelected++;
       }
   }
   for (i=0;i<document.Instructors.Chosen_Instructors.length;i++) { 
       if (document.Instructors.Chosen_Instructors.options[i].selected) {
          chosenSelected++;
       }
   }
   if(allSelected == 0 && chosenSelected == 0) {
      alert("You must choose at least one instructor")
      return false
   }
   else
   {
      if(allSelected >= 1 && chosenSelected >= 1 || allSelected > 1 || chosenSelected > 1) {
         alert("You can only choose one instructor")
         return false
      }
      if(allSelected == 0 && chosenSelected == 1) {
         View('ViewFaculty.asp', document.Instructors.Chosen_Instructors[document.Instructors.Chosen_Instructors.selectedIndex].value)
      }
      if(allSelected == 1 && chosenSelected == 0) {
         View('ViewFaculty.asp', document.Instructors.All_Instructors[document.Instructors.All_Instructors.selectedIndex].value)
      }
   }
 }
*/
/* function that opens page to view a record */
function View(url)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=500,HEIGHT=500,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';

       newWindow = window.open(url,"View",newFeatures) 
       newWindow.focus();    
}

/* function that opens page to edit a record */
function Edit(url, id)
{
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=400,HEIGHT=500,status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
    
    newWindow = window.open(url+id+"&modType=EDIT", "Edit",newFeatures) 
    newWindow.focus();
}

/* function that opens page to edit a record */
function Delete(url, id)
{
    var newFeatures = ''; 
    var newWindow = '';
    
}

/* function that opens help window */
function openHelp(id)
  {
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH=350,HEIGHT=250,status=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no';
    
    newWindow = window.open("HelpPage.asp?id="+id, "Help",newFeatures) 
    newWindow.focus();
  }

/* function that opens help window 
function doHelp(id)
  {
    var newFeatures = ''; 
    var newWindow = '';
    
    newFeatures = 'WIDTH='400',HEIGHT='300',status=no,menubar=no,scrollbars=yes,resizable=no,toolbar=no';
    
    newWindow = window.open('helpPage.asp?id='+id, "Help",newFeatures) 
    newWindow.focus();
  }
*/
/* function that highlights form elements */
clr=new Array('#BDC3BD','white','silver');

function highlight(state)
{
    element=event.srcElement;
    if (element.tagName=='INPUT' || 'SELECT' || 'TEXTAREA') 
       {
          etype=element.type;
    if ((etype=='submit' || etype=='reset') && state==1) state=2;
          element.style.backgroundColor=clr[state];
    }
}

/* function that puts a check in a checkbox */
function checkIt(field, id)
{
    field[id].checked = true;
}

/* function that confirms a delete button */
function confirmSubmit()
{
    var agree=confirm("Are you sure you want to delete this course?");
    if (agree)
	location='DeleteCourse.asp?id='+document.courses.fldCourseList.value
    else
	return false ;
}

/* function that validates a phone number format */
function validateUSPhone( strValue ) 
{
  var objRegExp  = /^[1-9]\d{2}\s?\d{3}\-\d{4}$/;
 
  //check for valid us phone with or without space between 
  //area code
  return objRegExp.test(strValue); 
}

/* function that validates an email address */
function validateEmail( strValue) {
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
  //check for valid email
  return objRegExp.test(strValue);
}

/* function for menu text */
function movein(html){
   if (document.getElementById)
   document.getElementById("boxdescription").innerHTML='<b>'+html+'</b>'
   else
   boxdescription.innerHTML='<b>'+html+'</b>'
}

/* function for menu text */
function moveout(){
if (document.getElementById)
document.getElementById("boxdescription").innerHTML='&nbsp;'
else
boxdescription.innerHTML='&nbsp;'
}

/* function to add course */
function AddSimilarCourse()
{
   if (document.courses.fldCourseList.selectedIndex != -1)
      {
        location='EditCourse1.asp?mode=add&id='+document.courses.fldCourseList.value
      }
   else
      {
        alert("You must choose a course...")
      }
}
 
/* function to edit course */
function EditCourse()
{
   if (document.courses.fldCourseList.selectedIndex != -1)
      {
        location='EditCourse1.asp?mode=edit&id='+document.courses.fldCourseList[document.courses.fldCourseList.selectedIndex].value
      }
   else
      {
        alert("You must choose a course...")
      }
 }
 
/* function to edit course  */ 
function ViewCourse()
{
   if (document.courses.fldCourseList.selectedIndex != -1)
      {
        location='CourseDetails.asp?id='+document.courses.fldCourseList[document.courses.fldCourseList.selectedIndex].value
      }
   else
      {
        alert("You must choose a course...")
      }
}

/* function to set focus on field */
function setFocus()
{
   document.login.fldUserName.focus()
}

/* function to refresh the parent page then close */
    function Done() {
      	opener.location.reload(true);
      	self.close();
}

/* FUNCTION TO SET ACTION BEFORE SUBMIT */
function setAction(newAction) {
	document.forms[0].ACTION.value = newAction;
}

/* FUNCTION TO CONFIRM DELETION AND SET NEW ACTION OF FORM*/
function confirmDel(keyword,frm_action) {
	if (confirm("Are you sure you want to delete this " + keyword + "?")) {
		if (frm_action != "") 
		{
			document.forms[0].action = frm_action
		}
		return(true);
	}
	else {
		return(false);
	}
}

/* FUNCTION TO SET NEW ACTION OF FORM*/
function setFrmAction(frm_action) {
	if (frm_action != "") 
	{
			document.forms[0].action = frm_action;
	}
}


/* FUNCTION TO VALIDATE ENTRY OF TEXT FIELD */
	function validateTextFld(fld_name,txt_msg)
	{
		if (fld_name.value == "") 
		{
			alert(txt_msg);
			fld_name.focus();
			return (false);
		}
		return (true);
	}
/* FUNCTION TO TAKE USER TO NEW URL */
	function GotoURL(newURL) {
	window.location.href= newURL
}

function isValidDate(dateStr) {

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(dateStr + " Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;
}

function isValidTime(timeStr) {

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute < 0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

function dateDiff(dateform) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

if (isValidDate(dateform.cDate.value) && isValidTime(dateform.cStartTime.value)) { // Validates first date 
date1temp = new Date(dateform.cDate.value + " " + dateform.cStartTime.value);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits

if (isValidDate(dateform.cenddate.value) && isValidTime(dateform.cEndTime.value)) { // Validates second date 
date2temp = new Date(dateform.cenddate.value + " " + dateform.cEndTime.value);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits

// sets cCreditHours date to cCreditHours of first date and second date

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

timediff = diff.getTime();

weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
timediff -= days * (1000 * 60 * 60 * 24);

hours = Math.floor(timediff / (1000 * 60 * 60)); 
timediff -= hours * (1000 * 60 * 60);

mins = Math.floor(timediff / (1000 * 60)); 
timediff -= mins * (1000 * 60);

secs = Math.floor(timediff / 1000); 
timediff -= secs * 1000;

dateform.cCreditHours.value = hours;

return false; // form should never submit, returns false
}

//-->
