    var lastColorUsed;
    var blocked;
    var isIE;
    var isNN;
    var isN4;

    blocked = false;

    //when checking if the browser is IE be sure to exclude the Mac IE browser
    //because it doesnt have the same support as the PC side
    isIE = ((document.all) && (navigator.platform == 'Win32'));

    function highlight(row, enable) {
	    //enable is true when the mouse goes over a row, and false when it leaves the row
	    if (enable) {
		    row.lastColorUsed = row.style.backgroundColor;
		    row.style.backgroundColor = '#FFFFCC';
	    }
	    else { row.style.backgroundColor = row.lastColorUsed; }
    }

    function popUpBlocked(winReference) {
	    //only used in this include
	    var isNull, isUndefined;
    	
	    isUndefined = ( typeof(winReference) == "undefined" );
	    isNull = ( winReference == null );
    	
	    if ( !isUndefined && !isNull ) {
		    if ( !winReference.closed ) { return false; }
		    else { return false; }
	    }else if ( isUndefined ) { return true; }
	    else if ( isNull ) { return true; }	
    }

    function post(cid,messageid,level,action) {
	    //used only in coursepage.aspx, functions_coursepage.aspx, classes_chatuser.aspx, and the other bb pages
	    window.open('messages.aspx?cid=' + cid + '&messageid=' + messageid + '&level=' + level + '&action=' + action,'messages','menubar=no,scrollbars=yes,resizable=yes,status=no,height=600,width=800');
    }


    function closeFocusRefresh() {
	    //used in the footer, messages.aspx and login
	    window.close();
	    window.opener.focus();
	    window.opener.location = removePound(window.opener.location);
    }
    function reloadParent() {
    	if (window.opener)
    	{
    		// traditional popup
		    if (reloadParent.arguments.length == 0) { window.opener.location = removePound(window.opener.location); }
		    else { window.opener.location = reloadParent.arguments[0]; }
    	} else {
    		// modal popup
    		if (reloadParent.arguments.length == 0) { parent.location.reload(); }
    		else { parent.location.href = reloadParent.arguments[0]; }
    	}
    }

    function email(queryString) {pop('email.aspx?' + queryString,'','','','email');}
    
    
    function quickHelp(event,key) {
	    var xVal;
	    var yVal;
	    var helpWin;
	    if (!document.layers) {
		    xVal = event.screenX;
		    yVal = event.screenY;
	    }
	    else {
		    xVal = event.pageX;
		    yVal = event.pageY;
	    }
	    xVal = (xVal - 200);
	    yVal = (yVal - 75);
	    helpWin = window.open('help_content.aspx?key=' + key, 'quickHelp', 'menubar=no,scrollbars=yes,resizable=yes,status=no,height=150,width=400,top=' + yVal + ',screenY=' + yVal + ',left=' + xVal + ',screenX=' + xVal);
	    helpWin.moveTo(xVal,yVal);
	    helpWin.focus();
    	
	    return true;
	}

	function moveItemToClick(theObj, event) {
	    var xVal;
	    var yVal;
	    xVal = event.offsetX ? (event.offsetX) : event.pageX - document.body.offsetLeft;
	    yVal = event.offsetY ? (event.offsetY) : event.pageY - document.body.offsetTop;
	    theObj.style.position = 'absolute';
	    theObj.style.top = yVal + 'px';
	    theObj.style.left = xVal + 'px';
	}

    function checkAll() {
	    var myString;
	    for (i=0; i < document.forms[0].length; i++) {
		    if (document.forms[0][i].type == 'checkbox') {
			    //make sure to only check those boxes that have a name of "*checkbox_moddel*"
			    myString = document.forms[0][i].name;
			    if (document.forms[0][i].name.indexOf('checkbox_moddel') != -1) {
				    document.forms[0][i].checked = document.forms[0].checkAllBox.checked;
			    }
		    }
	    }
    }

    function clickFooterLink() {
	    //this is used in header.ascx to tie the header close link to the footer close link, that way they have the same functionality
	    //it only works in IE for now, so we just use the normal close link for FireFox/Netscape/Mac.  make sure to verify that the DIV
	    //is an object before trying to refernece it or you will get an error on pages like print_content.aspx that dont contain the DIV at the bottom
	    if ((isIE) && (document.getElementById('closeDiv'))) {
		    document.getElementById('closeDiv').click();
	    }
	    else {
		    closeAndFocus();
	    }
    }

    function closeOnLogout() {
	    //this is used to close the window on logout; only used in login.aspx
	    if (navigator.appName == 'Microsoft Internet Explorer') { top.window.close(); }
    }

    function popExport(filename) {
	    //this is used by a lot of scripts to open the export window
	    if (!filename) { filename = ''; }
	    pop('export.aspx?file=' + filename,'yes','500','700','export');
    }

    function selectRow(evt, clientID) {
	    //only call the toggle if they have clicked on a TD tag, not a checkbox
	    //FireFox does not expose window.event, so the event object must be passed as a parameter
        //http://www.webswapp.com/codesamples/viewsource.aspx?file=~/codesamples/aspnet20/gridview_multiplerows_selection/vb.aspx
        //http://www.w3schools.com/js/tryit.asp?filename=try_dom_event_srcelement
        var e = evt || window.event;
        var src = e.target || e.srcElement;
        if (src) {
		    if (src.tagName=="TD") {
    		    var row = src.parentNode;
    		    var chk = row.cells[0].firstChild.firstChild;
			    chk.checked = !chk.checked;
		    }
	    }
    }

    function findY(objName) {
	    //function to locate an object by name, and return its Y (vertical) location on the page
	    //function will return zero if the element is not found
	    var curtop = 0;
	    var obj = document.getElementById(objName);
    	
	    if (obj.offsetParent) {
		    while (obj.offsetParent) {
			    curtop += obj.offsetTop
			    obj = obj.offsetParent;
		    }
	    }
	    else if (obj.y) { curtop += obj.y; }
	    return curtop;
    }

    function getWinHeight() {
	    //function to return the height of the current window; returns zero if the
	    //appVersion cannot be determined as Netscape or Microsoft correctly
	    var winH = 0;
	    if (parseInt(navigator.appVersion)>3) {
		    if (navigator.appName=="Netscape") { winH = window.innerHeight; }
		    if (navigator.appName.indexOf("Microsoft")!=-1) { winH = document.body.offsetHeight; }
	    }
	    return winH;
    }

    function setListingHeight() {
	    //function to set the size of the DIV that contains the datagrid; the function will not execute
	    //if the DIV cannot be found.  note, the  "60" listed below will just give us a little buffer so that the window
	    //scrollbars do not activate even when the DIV scrollbars are turned on
	    if ((isIE) && (document.getElementById('listDiv'))) {
		    var currDivHeight = (findY('footerStart') - findY('listDiv'));
		    var newDivHeight = (getWinHeight() - findY('listDiv') - (findY('footerStop') - findY('footerStart')) - 60);

		    if ((currDivHeight > newDivHeight) && (newDivHeight > 0)) {
			    if (newDivHeight < 200) { document.getElementById('listDiv').style.height = '200px'; }
			    else { document.getElementById('listDiv').style.height = newDivHeight + 'px';	}
		    }
	    }
    }

    function goToCoursepage(cid) {
	    //used on courseindex.aspx
	    window.location = 'coursepass.aspx?cid=' + cid;
    }

    function handleEnterOnIndex(myfield,e,elementID) {
	    //used on courseindex.aspx, rename.aspx and resourceindex.aspx
	    var keycode;
	    if (window.event) { keycode = window.event.keyCode; }
	    else { if (e) { keycode = e.which; } }
	    if (keycode == 13) { document.getElementById(elementID).click(); return false; }
	    else { return true; }
    }

    function setColor(myCell,hexCell,color) {
	    //used on colors.aspx
	    myCell.style.backgroundColor = color;
	    document.getElementById('hex').innerHTML = color;
    }
    	
    function returnColor(myBox,myColor,modalid) {
	    //used on colors.aspx
	    //window.opener.document.getElementById(myBox).value = myColor;
	    //window.close();
	    //window.opener.focus();
	    parent.document.getElementById(myBox).value = myColor;
	    parent.closeModal(modalid);
    }

    function reload() {
	    //used in chat_history.aspx; normally wont be called
	    document.location.href = document.location.href;
    }

    function popLogout(cid) {
	    //used in chat_frame.aspx
	   // pop('chat_logout.aspx?cid=' + cid,'yes','','','logout');
	   pop('print_frame.aspx?page=chat_logout.aspx','yes','','','logout');
    }
    function setDocumentView() {
	    //used in documentview.aspx
	    isIE=document.all;
	    isNN=!document.all && document.getElementById;
	    isN4=document.layers;
	    if (isIE||isNN) { document.oncontextmenu=checkV; }
	    else { document.captureEvents(Event.MOUSEDOWN || Event.MOUSEUP); document.onmousedown=checkV; }
    }

    function checkV(e) {
	    //used in documentview.aspx
	    if (isN4) { if (e.which==2||e.which==3) { blockClick(); return false; } }
	    else { blockClick(); return false; }
    }

    function left(str, n){
	    if (n <= 0)
	        return "";
	    else if (n > String(str).length)
	        return str;
	    else
	        return String(str).substring(0,n);
    }

    function right(str, n){
        if (n <= 0)
           return "";
        else if (n > String(str).length)
           return str;
        else {
           var iLen = String(str).length;
           return String(str).substring(iLen, iLen - n);
        }
    }

    function removePound(myURL) {
	    if (right(myURL,1) != "#") { return myURL; }
	    else { return left(myURL,String(myURL).length-1); }
    }

    function getRandomPass() {
	    var chars = "0123456789abcdefghiklmnopqrstuvwxyz";
	    var randomstring = '';
	    for (var i=0; i<8; i++) {
		    var rnum = Math.floor(Math.random() * chars.length);
		    randomstring += chars.substring(rnum,rnum+1);
	    }
	    return randomstring;
    }
	
    function closeAndUpdate(txtid, txtval, valueid, valueval, modalid)
    {
    	if(parent.document.getElementById(txtid))
        {
        	if(txtval && txtval.length > 0)
            parent.document.getElementById(txtid).value = unescape(txtval);
        }
        if(parent.document.getElementById(valueid))
        {
        	if(valueval && valueval.length > 0)
            parent.document.getElementById(valueid).value = valueval;
        }
    
	    parent.closeModal(modalid);
    }
    
    function txtAreaMaxLength(item,maxL)
    {
        if(item.value.length > maxL)
        {
            item.value = item.value.substring(0, maxL-1);
        }
    }
    function calendar(event,month,day,year,mval,dval,yval) {
		var xVal;
		var yVal;
		var calWin;
		
		if (!document.layers) {
			xVal = event.screenX;
			yVal = event.screenY;
		}
		else {
			xVal = event.pageX;
			yVal = event.pageY;
		}
		xVal = (xVal + 10);
		yVal = (yVal - 160);
		
		calWin = window.open('calendar.aspx?mval=' + mval + '&dval=' + dval + '&yval=' + yval + '&month=' + month + '&day=' + day + '&year=' + year, 'calendar', 'menubar=no,scrollbars=yes,resizable=yes,status=no,height=400,width=400,top=' + yVal + ',screenY='+ yVal + ',left=' + xVal + ',screenX=' + xVal);
		calWin.focus();
		return true;
	}
	
	function clearDate(element) {
		eval("document.forms[0]." + element + ".value = ''");
	}
	
	function getPage()
	{
	    var mylocation = window.location.pathname;
	    var parts = mylocation.split('/');
	    return parts[parts.length - 1];
	}
	function getEResCookieCrumb(param)
	{
	    var wholecookie = document.cookie;
	    var cookiebites = wholecookie.split(';');
	    var aCookie, valStart, cVal, crumbs, crumb, kvseparator;
	    var foundValue = "";
	    
	    for(var i=0; i<cookiebites.length; i++)
	    {
	        aCookie = cookiebites[i];
	        valStart = aCookie.indexOf('=');
	        cVal = aCookie.substring(valStart + 1);
	        crumbs = cVal.split('&');
	        for(var j=0; j<crumbs.length; j++)
	        {
	            crumb = crumbs[j];
	            kvseparator = crumb.indexOf('=');
	            if (kvseparator > 0)
	            {
	                if(crumb.substring(0, kvseparator) == param)
	                {
	                    foundValue = crumb.substring(kvseparator + 1);
	                    i = cookiebites.length + 1;
	                    j = crumbs.length + 1;
	                }
	            }
	        }
	        
	    }
	    return foundValue;
	    
	}
	
	function getQueryValue(param)
	{
	    var value = "";
	    var query = window.location.search.substring(1);
	    var keyvalpairs = query.split('&');
	    for(var i=0; i<keyvalpairs.length; i++)
	    {
	        var pos = keyvalpairs[i].indexOf('=');
	        if(pos > 0)
	        {
	            if(keyvalpairs[i].substring(0, pos) == param)
	            {
	                value = keyvalpairs[i].substring(pos+1);
	                i = keyvalpairs.length + 1;
	            }
	            
	        }
	    }
	    return value;
	}

	function getHelpTopic() {
	    var page;
	    var helperEl;
	    var topicHelper = '';
	    var topic = '';
	    var queryVar;
	    helperEl = document.getElementById('topicHelper');
	    if (helperEl) topicHelper = helperEl.value;
	    if (topicHelper.length > 0) { topic = topicHelper; }
	    else {
	        page = getPage();
	        switch (page) {
	            case 'accounts.aspx': topic = 'AccountList'; break;
	            case 'associations.aspx': /*Use TopicHelper*/break;
	            case 'attach.aspx': topic = 'AttachDocumentFiles'; break;
	            case 'barcode.aspx': /*Use TopicHelper*/break;
	            case 'bbimport.aspx': /*Use TopicHelper*/break;
	            case 'browsertest.aspx': /*TODO*/break;
	            case 'ccc_cancel.aspx': topic = 'CancelOrder'; break;
	            case 'ccc_list.aspx': topic = 'CCCConnectRequests'; break;
	            case 'ccc_request.aspx': topic = 'SearchCCCConnect'; break;
	            case 'chat_processing.aspx': topic = 'ChatRoom'; break;
	            case 'communications.aspx': topic = 'PermissionRequestSettings'; break;
	            case 'comm_list.aspx': /* Use TopicHelper */break;
	            case 'configuration.aspx':
	                queryVar = getQueryValue('page');
	                if (queryVar == 'qdates') topic = 'QuickDates';
	                else if (queryVar == 'color') topic = 'FontsAndColors';
	                else if (queryVar == 'email') topic = 'EmailAlerts';
	                else if (queryVar == 'copyright') topic = 'CopyrightVisibility';
	                else if (queryVar == 'proxy') topic = 'ProxyRules';
	                else if (queryVar == 'trusted') topic = 'TrusteSites';
	                else topic = 'SystemSettingsTab';
	                break;
	            case 'copyadmin.aspx': topic = 'CopyrightManagementList'; break;
	            case 'copydetail.aspx': /* Use TopicHelper */break;
	            case 'copyright.aspx': topic = 'PaymentSettings'; break;
	            case 'copy_list.aspx': topic = 'CopyrightPaymentList'; break;
	            case 'courseindex.aspx':
	                queryVar = getQueryValue('page');
	                if (queryVar == 'search') { topic = 'SearchForCoursePages'; }
	                else if (queryVar == 'dept') { topic = 'CoursePagesByDepartment'; }
	                else if (queryVar == 'instr') { topic = 'CoursePagesByInstructor'; }
	                else if (queryVar == 'docs') { topic = 'SearchForDocuments'; }
	                else topic = 'EreservesIndex';
	                break;
	            case 'coursepage.aspx':
	                queryVar = getQueryValue('page');

	                if (queryVar == 'docs') { topic = 'Documents'; }
	                else if (queryVar == 'chat') { topic = 'ChatRoom'; }
	                else if (queryVar == 'bb') { topic = 'DiscussionBoards'; }
	                else if (queryVar == 'ir') { topic = 'InternetResource'; }
	                else if (queryVar == 'pm') { topic = 'PageManagement'; }
	                else topic = 'CourseInfo';
	                break;
	            case 'coursepass.aspx': topic = 'CopyrightAcceptancePage'; break;
	            case 'courses.aspx': topic = 'FacultyCourseReservesPage'; break;
	            case 'crosslistings.aspx': topic = 'CrosslistingsList'; break;
	            case 'csvimport.aspx': /*Use TopicHelper*/break;
	            case 'currentview.aspx': topic = 'SaveCurrentView'; break;
	            case 'customforms.aspx': topic = 'CustomFormsManagementList'; break;
	            case 'default.aspx': topic = 'EreservesHome'; break;
	            case 'departments.aspx': /* Use TopicHelper */break;
	            case 'documents.aspx': /* Use TopicHelper */break;
	            case 'documentview.aspx':
	                queryVar = getQueryValue('page');
	                if (queryVar == 'history') { topic = 'DocumentHistory'; }
	                else if (queryVar == 'assoc') { topic = 'CurrentAssociations'; }
	                else topic = 'DocumentInfoStudent'; break;
	            case 'email.aspx': topic = 'GenerateEmailMessage'; break;
	            case 'email_alerts.aspx': topic = 'EmailAlertList'; break;
	            case 'error.aspx': /*TODO*/break;
	            case 'export.aspx': topic = 'DataExport'; break;
	            case 'folders.aspx': topic = 'FolderList'; break;
	            case 'groups.aspx': /* uses topicHelper */break;
	            case 'homeitems.aspx': /* uses topicHelper */break;
	            case 'import.aspx': topic = 'ImportData'; break;
	            case 'languages.aspx': topic = 'LanguageList'; break;
	            case 'letters.aspx': /* uses topicHelper */break;
	            case 'login.aspx': topic = 'AdminLogin'; break;
	            case 'marc.aspx': topic = 'MARCRecords'; break;
	            case 'messages.aspx': /*Use TopicHelper*/break;
	            case 'newsitems.aspx': topic = 'NewsAnnouncementList'; break;
	            case 'print_content.aspx': /*Use TopicHelper*/break;
	            case 'print_controls.aspx': /*Use TopicHelper*/break;
	            case 'print_frame.aspx': /*Use TopicHelper*/break;
	            case 'publishers.aspx': topic = 'PublisherList'; break;
	            case 'rename.aspx': topic = 'OverwriteOrRenameFile'; break;
	            case 'reorder.aspx': topic = 'ReorderDocuments'; break;
	            case 'reports.aspx': topic = 'StatisticReport'; break;
	            case 'reserverequest.aspx': topic = 'ReserveRequestList'; break;
	            case 'resources.aspx': topic = 'ResourceList'; break;
	            case 'toolkit.aspx': topic = 'MainMenu'; break;
	            case 'upload.aspx': topic = 'UploadfFiles'; break;

	            default:
	                topic = ""; break;

	        }
	    }
	    return topic;
	}
