var isIE = false;      // Microsoft Internet Explorer
var isNS4 = false;     // Netscape 4+
var isW3C = false;     // W3C compliant (inc NS6 & 7)
var isUnknown = true;  // in case something else comes along

  if (document.getElementById) {
    isW3C = true ; // NS6+, MSIE 5+, Mozilla, Opera 6 in Opera (W3C) mode
    isUnknown = false;
  }
  if (document.all) {
    isIE = true ; // MSIE (all versions) and Opera 6 in MSIE 5 mode
		coll = "all."
		styleObj = ".style"
    isUnknown = false;
  }
  if (document.layers) {
    isNS4 = true ; // NS 4
    isUnknown = false;
  }

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}


function getObject(obj) {
	var theObj
	if (isIE) {
		theObj = eval("document." + coll + obj + styleObj)
	} else if (isW3C) {
		theObj = eval(document.getElementById(objName).style);
	} else {
		theObj = obj
	}
	return theObj
}

function toggleMenu(obj)
{ 
menuList = new Array('DE','RQ','UT','CU');
//menuList = new Array('DE','RQ','CU');
objName = obj + '_Menu';
currentobj = getObject(objName);
    if (currentobj.style)
    {
      currentobj = currentobj.style;
	}
	if (currentobj.display == 'block') 
	{
	  	changeMenu (obj, 'close');
	} else {
		for (var i = 0; i < menuList.length; i++) 
		{
		currentAction = 'close';
		if (menuList[i] == obj)
		{
		currentAction = 'open';
      	}
		changeMenu (menuList[i], currentAction);
		}
	}
}

function toggleHelp(obj)
{ 

objName = obj;
currentobj = getObject(objName);
    if (currentobj.style)
    {
      currentobj = currentobj.style;
	}
	if (currentobj.display == 'block') {
	  	visStr = 'none';
	} else {
	  	visStr = 'block';
	}
	currentobj.display = visStr;
}

function toggleObjectives(baseName) {
objCounter = 1;
while (findObj(baseName + objCounter)) {
		toggleHelp(baseName + objCounter)
		objCounter++;
	}
}

function navChangeHelp(item, group) {
	if (parent.helpNav.navLoaded) {
		parent.helpNav.menuBoldHelp(item);
		objName = group;
		currentobj = parent.helpNav.getObject(objName);
    	if (currentobj.style) {
      		currentobj = currentobj.style;
		}
		visStr = 'block';
		currentobj.display = visStr;
	}
}

function changeMenu(obj, menuAction)
{ 
menu = 			obj + '_Menu';
arrow = 		obj + '_Arrow';
bottom = 		obj + '_bottom';
bottom2 = 		obj + '_bottom2';
arrowbottom = 	obj + '_ArrowBottom';
obj = findObj(menu);
barobj = findObj(bottom);
barobj2 = findObj(bottom2);
if (obj.style)
	{
     obj = obj.style;
	 barobj = barobj.style;
	 barobj2 = barobj2.style;
	 }
	if(menuAction == 'close') 
	  {
	  	visStr = 'none';
		barStr = '#426684';
		arrowImage = '../images/down_arrow.gif';
		arrowBottom = '../images/down_bottom.gif';
	} else {
      	visStr = 'block';
		arrowImage = '../images/up_arrow.gif';
		arrowBottom = '../images/up_bottom.gif';
		barStr = '#c6d6e6';
	}
obj.display = visStr;
barobj.backgroundColor = barStr;
barobj2.backgroundColor = barStr;
switchArrow(arrow, arrowImage);
switchArrow(arrowbottom, arrowBottom);
}

function switchArrow(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

function menuBoldItem(obj) {
        if(canImportSCT == 'true') {
          menuItems = new Array ('item_assessmentplan','item_assessmentprocess','item_courseplan','item_observations','item_studentperf','item_groupperf','item_questresp','item_reports','item_querybuilder','item_adminsetup','item_instsetup','item_extunitsetup','item_unitsetup','item_deptsetup','item_goalsetup','item_imports','item_importData');
        } else {
          menuItems = new Array ('item_assessmentplan','item_assessmentprocess','item_courseplan','item_observations','item_studentperf','item_groupperf','item_questresp','item_reports','item_querybuilder','item_adminsetup','item_instsetup','item_extunitsetup','item_unitsetup','item_deptsetup','item_goalsetup','item_imports');
        }
	for (i=0; i < menuItems.length; i++)
	{
		newWeight = 'normal';
		if (menuItems[i] == obj) {
			newWeight = 'bold';
			}
		if (isIE) {
			var theObj = getObject(menuItems[i]);
			theObj.fontWeight = newWeight;
			} 
		else if (isW3C) {
			document.getElementById(menuItems[i]).style.fontWeight = newWeight;
			}
	}
}

function menuBoldHelp(obj) {
	menuItems = new Array ('item_helpContactAdmin', 'item_helpUserRoles', 'item_helpLogin', 'item_helpLogout', 'item_helpCreatingUsers', 'item_helpCreatingUserPermissions', 'item_helpResettingForgottenPassword', 'item_helpResettingUserPassword', 'item_helpEnteringSerial', 'item_helpMovingBetweenForms', 'item_helpMovingBetweenFields', 'item_helpUsingButtons', 'item_helpEnteringDates', 'item_helpWorkingWithText', 'item_helpUsingSpellCheck', 'item_helpEditingDeletingData', 'item_helpPrintingScreenInfo', 'item_helpUsingFilter', 'item_helpDocumentingDeptObjectives', 'item_helpDocumentingAssessMethods', 'item_helpRelatingDocsToPlanAssessMethods', 'item_helpRelatingCoursesObj', 'item_helpRelatingGoalsObj', 'item_helpCreatingCustomFieldsObj', 'item_helpTrackingAssessProcess', 'item_helpDocumentingCourseOutcomes', 'item_helpDocumentingCourseAsseessMethods', 'item_helpRelatingDocToCourseAssessMethods', 'item_helpRelatingCourseObjToDeptObj', 'item_helpRelatingGoalsToObjectives', 'item_helpCreatingCustomFieldsCourse', 'item_helpDocumentObserv', 'item_helpDocumentRemedyFollowUp', 'item_helpRelatingDataToObserv', 'item_helpCreatingCustomFieldsObserv', 'item_helpRecordingInvidData', 'item_helpEnteringIndivMeasures', 'item_helpAttachIndivSamples', 'item_helpCreatingCustomFieldsIndivData',  'item_helpCreatingGroups', 'item_helpCreatingMeasures', 'item_helpNoGroupSpecified', 'item_helpQuestionnaireDesign', 'item_helpQuestionnaireResponses', 'item_helpCompleteAQuestionnaire', 'item_helpViewingStandardReports', 'item_helpUsingQueryBuilder', 'item_helpiWebfolioImport', 'item_helpHistoryRollback', 'item_helpAdminCreatingUsers', 'item_helpAdminCreatingUserPermissions', 'item_helpEnteringDynamicLabels', 'item_helpViewingSystemInfo', 'item_helpEnteringSchoolCode', 'item_helpEnteringLogo', 'item_helpEnteringSerialAdmin', 'item_helpEnteringAdminEmail', 'item_helpCreatingGoalTypes', 'item_helpAssignCustomAttributes', 'item_helpRecordingInstInfo', 'item_helpDocumentInstGoals', 'item_helpInstitutionCustomAttribute', 'item_helpRelatingDocsToInst', 'item_helpRelatingInstGoalsTo', 'item_helpCreatingCustomFieldsInst', 'item_helpRecordingIntUnitInfo', 'item_helpDocumentUnitGoals', 'item_helpInternalCustomAttribute', 'item_helpRelatingDocsToInternal', 'item_helpLinkingDeptsToUnit', 'item_helpRelatingInternalTo', 'item_helpCreatingUnitCustomFields', 'item_helpRecordingDeptInfo', 'item_helpDocumentDeptGoals', 'item_helpDeptCustomAttribute', 'item_helpRelateDeptGoalsTo', 'item_helpCreatingDeptPrograms', 'item_helpCreatingDeptPrograms', 'item_helpTrackFacultyInfo', 'item_helpRecordingDeptCourses', 'item_helpCreatingCustomFieldsDept', 'item_helpRecordingExtUnitInfo', 'item_helpDocumentExtUnitGoals', 'item_helpExternalCustomAttribute', 'item_helpRelateDocToExtUnits', 'item_helpRelateExtUnitTo', 'item_helpCreatingCustomFieldsExternal');
	for (i=0; i < menuItems.length; i++)
	{
		newWeight = 'normal';
		if (menuItems[i] == obj) {
			newWeight = 'bold';
			}
		if (isIE) {
			var theObj = getObject(menuItems[i]);
			theObj.fontWeight = newWeight;
			} 
		else if (isW3C) {
			document.getElementById(menuItems[i]).style.fontWeight = newWeight;
			}
	}
}

function swapFormOn(obj) {
	if (isW3C) {
		document.getElementById(obj).style.backgroundColor = "#E6EFF6";
	} else if (isIE) {
		var theObj = getObject(obj);
		theObj.backgroundColor = "#E6EFF6";
	}
}

function swapFormOff(obj) {
if (isW3C) {
		document.getElementById(obj).style.backgroundColor = "#ffffff";
	} else if (isIE) {
		var theObj = getObject(obj);
		theObj.backgroundColor = "#ffffff";
	}
}

function swapFormReadOnly(obj) {
	if (isW3C) {
		document.getElementById(obj).style.backgroundColor = "#E6E6E6";
	} else if (isIE) {
		var theObj = getObject(obj);
		theObj.backgroundColor = "#E6E6E6";
	}
}

function openPopup(filename,winname,winheight,winwidth,winscroll) {
	open(filename,winname,'HEIGHT=' + winheight + ',WIDTH=' + winwidth + ',scrollbars=' + winscroll)
	
}

function convertDate(dateent) {
    // Checks for the following valid date formats: 
    // MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY 
    // Also separates date into month, day, and year variables 
	// call the fuction with onBlur(this) from the date text field

    var dateStr1 = dateent;
    var dateStr = dateent.value;

    if(!(dateStr.length == 0)) {
        // To require a 2 digit year entry, use this line instead:
		dateStr = dateStr.replace("-","/");
		dateStr = dateStr.replace(".","/");
		dateStr = dateStr.replace("-","/");
		dateStr = dateStr.replace(".","/");
		if ((dateStr.indexOf("/") < 0) && ((dateStr.length == 6) || (dateStr.length == 8))){
			dateStr = dateStr.substr(0,2) + "/" + dateStr.substr(2,2) + "/" + dateStr.substr(4,dateStr.length);
		}
        var datePat = /^(\d{1,2})(\/|-|.)(\d{1,2})\2(\d{2}|\d{4})$/; 
        // To require a 4 digit year entry, use this line instead: 
        // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; 

        var matchArray = dateStr.match(datePat); // is the format ok? 

        if (matchArray == null) {
            msg = "Date entered is not in a valid format.\n";
            msg += "The list of valid date formats are available in the help file.\n";
            msg += "Please enter the date in a valid format or select the date using the date picker.\n";
            alert(msg);
            dateStr1.focus();
            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.");
            dateStr1.focus();
            return false; 
        }
 
        if (day < 1 || day > 31) {
            alert("Day must be between 1 and 31."); 
            dateStr1.focus();
            return false; 
        }

        if ((month==4 || month==6 || month==9 || month==11) && day==31) {
            alert("Month "+month+" doesn't have 31 days!");
            dateStr1.focus();
            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!"); 
                dateStr1.focus();
                return false; 
            } 
        } 
		
		datePiece  = dateStr.split("/");
		for (i=0; i<2; i++) {
			if (datePiece[i].length == 1) {
				datePiece[i] = "0" + datePiece[i];
			}
		}
		if ((datePiece[2].length == 2) && (datePiece[2] >= 37)) {
				datePiece[2] = "19" + datePiece[i];
		}
		else if ((datePiece[2].length == 2) && (datePiece[2] < 37)) {
				datePiece[2] = "20" + datePiece[i];
		}
		
		dateStr = (datePiece[0] + "/" + datePiece[1] + "/" + datePiece[2]);
		
		dateent.value = dateStr;
        return true; // date is valid 
    }
    return true;
}