//in use by:

/*
library of javascript functions:

alertdebug(msg)									alert with the given message, prefixed with note that the message is intended for the developers
areSameURL(sURL1, sURL2)                        compares sURL1 and sURL2 to see if they're the same URL regardless of capitalization, arguments, and relative vs. absolute paths
centerPopup(w,h,t)								(IE only) centers popup; called in open function
chkboxcheckedwhenselect(chkfield,selfield)		checks the given checkbox if the given option has been selected by the user
chkboxcheckedwhentxtentered(chkfield,textfield)	checks the given checkbox if any text has been entered in textfield
checkURLdot(string)								checks a URL string for a dot within the last five places
cleartxtwhenoptchecked(optfield,index,			clears the given textfield if the specified option has been selected
		textfield)
closealert(frm)									checks form status and gives an alert if changes have not been submitted
closeconfirm()									notifies the user if s/he just lost the data the entered in the given form
closeok(frm)									sets form status to notify closealert() that form is OK to close
fireEvent(element,event)                        "robust" trigger of  the specified event for the specified element - has some quirks involving IE - see its use in /calendar/c_month_mini.cfm
focusfirst(frm)									(IE only) places the focus on the 1st data entry element in the given form
getBrowserVersion								returns the browser version as a number
getCSSClassProperty(sClass, sProperty)			retrieves a class property out of a CSS style sheet that's been linked into the current page
getFontSize										returns an appropriate font size for the current resolution (8 pt for 800 x 600 or less, 9 pt for 1024 x 768, 10 pt for any higher resolutions)
getImageDimensionString(imgHeight, imgWidth		returns string in the form: ' height="[n] width="[n] ' for imagesizing 
		availHeight, availWidth)					uses getImageHeight and getImageWidth					
getImageHeight(imgHeight, imgWidth,             determines how much an image must be shrunk to fit availHeight & availWidth,
        availHeight, availWidth)                    shrinks the dimensions proportionally and returns the shrunken height
getImageWidth(imgHeight, imgWidth,              determines how much an image must be shrunk to fit availHeight & availWidth,
        availHeight, availWidth)                    shrinks the dimensions proportionally and returns the shrunken width
getRadioValue(sName)							returns the value for the checked radio element of the given name
isIE4()                                         returns true if the current browser it Internet Explorer 4.x; otherwise false
isMac()                                         returns true if the current operating system is Mac OS; otherwise false
javatrim(stringtotrim)							trims all leading and trailing spaces from the given string
javatrimCRLF(stringtotrim)		                trims all leading and trailing CR and LF characters from the given string
jsElapsedTime(lstarttime,msg)					subtracts current time from lstarttime and returns it in an alert prepended by msg
MM_goToURL()									sets the location of the given window(s) to the give URL(s)
openpopupwin(winopenfieldvalue,					opens a popup window, submitting formtosubmit to the new window
		formtosubmit,winname,hopenwin)
popupclosealert(sopener,frm)					notifies the user if the parent (calling) form has been closed before the changes on the subform were submitted
popupcloseconfirm(sopener,frm)					checks the parent (calling) form and then notifies the user if s/he has just lost data entry on subform
popupparentclosealert()							similar to popupclosealert() function
repeatString(n,str)								concatenates str n times
resizePopup()									resizes a popup window to fit its contents
reverseXMLFormat(s)								reverses the effects of the CF XMLFormat() function
selectoptwhentxtentered(optfield,index,			selects the given option if any text has been entered in textfield
		textfield)
setRadioValue(sName, sVal)						sets the radio by the given name with the given value to checked
showToday(sformat)								formats current local datetime as "mm/dd/yyyy hh:mm tt" or "dd/mm/yyyy hh:mm tt" depending on sformat
timeInMins(strHour,strMins,strAMPM)				returns time elements as iMinutesSinceMidnight
												used for time comparisons of same day values (e.g. d_new.cfm
getDateAsMilliseconds(strDate,strHour,strMins,strAMPM)  returns the number of milliseconds since January 1, 1970 for the arguments supplied
dateFourDigitYear(sDate,sDateFormat)						takes dateString and returns it with 4 digit year
viewImage(sfilename,iheight,iwidth)				opens a popup to view embedded image which is not displayed for user preference limited graphics
isWYSIWYGallWhiteSpace(stringHTML)              checks if an string of HTML coming from the WYSIWYG editor was effectively empty 
*/


function alertdebug(msg)
{
	//this function should be called rather than alert for all debug messages
	alert('This is a developer msg:\n' + msg)
}


/*
written:    2/5/02
purpose:    compares sURL1 and sURL2 to see if they're the same URL regardless of capitalization, arguments, relative vs. absolute paths
arguments:  sURL1   first url
            sURL2   second url
ret value:  true or false
*/
function areSameURL(sURL1, sURL2) {
    //drop both urls to lower case
    sURL1 = sURL1.toLowerCase();
    sURL2 = sURL2.toLowerCase();
    
    //strip off any url arguments
    if (sURL1.indexOf("?") > -1) sURL1 = sURL1.substr(0, sURL1.indexOf("?"));
    if (sURL2.indexOf("?") > -1) sURL2 = sURL2.substr(0, sURL2.indexOf("?"));
    
    //strip off any leading periods in relative paths
    do {sURL1 = sURL1.substr(1)} while (sURL1.indexOf(".") == 0);
    do {sURL2 = sURL2.substr(1)} while (sURL2.indexOf(".") == 0);
    
    //if one now fits inside the other, we have a match
    if (sURL1.indexOf(sURL2) > -1 || sURL2.indexOf(sURL1) > -1) {
        return true;
    }
    else {
        return false;
    }
}

/*
written:	11/9/00
purpose:	centers the popup window on the user's screen
notes:		1. Works in IE, versions 4+.
			2. Given a width and height return a string for sizing and centering
			3. 't' as optional overide to set a top of screen t=0
*/
function centerPopup(w,h,t)
{
	var winl = (screen.width - w)/2;
	if (isNetscape()) {
		var wint = (screen.height - h)/3;
	}
	else {
		var wint = (screen.availHeight - h)/3;
	}
    if (winl < 0) winl = 0;
    if (wint < 0) wint = 0;
	if (centerPopup.arguments.length == 3)
	{
		wint = 0;
	}
	
	//added 9/21/04 because Safari is thrown off by non-integer values
	w = Math.floor(w);
	h = Math.floor(h);
	wint = Math.floor(wint);
	winl = Math.floor(winl);
	return 'width='+w+',height='+h+',top='+wint+',left='+ winl;
	//alert('top is ' + wint + ', left is ' + winl);
}


/* checks a checkbox when select list choice is made*/
/* for example: when Reply By selection (address,phone) is changed, checkbox chkEstimatedCost is checked
called by onChange select list*/
function chkboxcheckedwhenselect(chkfield,selfield)
{
	if (selfield.selectedIndex != 0)
	{
		/*check checkbox related to text entered*/
		chkfield.checked=true;		
	}
}


/* checks a checkbox when related text is entered*/
/* for example: when Reply (address,phone) text is entered, checkbox chkEstimatedCost is checked
called by onChange or onBlur of text field*/
function chkboxcheckedwhentxtentered(chkfield,textfield)
{
	if (textfield.value != "")
	{
		/*check checkbox related to text entered*/
		chkfield.checked=true;		
	}
}

/*checks a URL string for a dot not the last character
  disallows any URL with either "<" or ">"
*/

function checkURLdot(str,focusobj)
{
	str = javatrim(str);
	if (str.length > 0)
	{
		if (str.charCodeAt(str.length-1) == 46)
		{
			alert(phTopFrame.parrErrMsg["URLmaynotendwithaperiod"]);
			focusobj.focus();// does not work in IE5.0
			return false;
		}

		if (str.indexOf(".") == -1)
		{
			alert(phTopFrame.parrErrMsg["URLmustincludeaperiod"])
			focusobj.focus();// does not work in IE5.0
			return false;
		}
		if (str.indexOf("<") > -1 || str.indexOf(">") > -1)
		{
			alert(phTopFrame.parrErrMsg["Formattingcodesarenotpermitted"])
			return false;
		}
	}
	return true;
}

/*empties named textfield when radio option is selected
called onChange of radio option*/
function cleartxtwhenoptchecked(optfield,index,textfield)
{
	if (optfield[index].checked==true)
	{
		textfield.value = "";
	}
}


/****alert if form is closed without saving changes**/
function closealert(frm)
{
	var formname=frm.formname.value
	if (frm.operation.value == "noclose")
	{
		alert('You have closed the ' + formname + ' form, \nbut have not submitted your changes.\nAny changes you made have been lost.')
	}
}

// as of 10/15/01 not in use in iCohere
function closeconfirm()
{
	var formname=document.forms[0].formname.value
	if (document.forms[0].operation.value == "noclose")
	{
		alert('You have closed the ' + formname + ' Confirmation page, \nbut have not confirmed your ' + formname + ' entries.\nAny changes you made have been lost.')
	}
}

// as of 10/15/01 not in use in iCohere
function closeok(frm)
{
	if (closeok.arguments.length == 0)
	{
		document.forms[0].hidOperation.value = "normal"
	}
	else
	{
		frm.hidOperation.value = "normal"
	}
}

/*
written:	10/9/02
purpose:	returns the browser version as a number
*/
function getBrowserVersion() {
	var sVersion = navigator.appVersion.toLowerCase();
	if (sVersion.indexOf("msie") > -1) sVersion = sVersion.slice(sVersion.indexOf("msie") + 5);
	return parseFloat(sVersion);
}

/*
written: 2/24/09
purpose: retrieves a class property out of a CSS style sheet that's been linked into the current page
arguments:  sClass = the name of the desired class (CASE SENSITIVE)
			sProperty = the desired property in javascript format rather than CSS format (i.e. backgroundColor rather than background-color)
returns: the first matching property
notes:
	1. This function loops through the linked style sheets looking for a rule with a class definitions matching sClass; it then returns the desired property.
	2. If more than one linked style sheets have a class by that name, the first match will be returned
*/
function getCSSClassProperty(sClass, sProperty) {
	//loop through this document's style sheets
	for (var i=0; i < document.styleSheets.length; i++) {
		//put the rules collection into rules in a cross-browser fashion
		if (isIE()) {
			var rules = document.styleSheets[i].rules;
		}
		else {
			var rules = document.styleSheets[i].cssRules;
		}
		
		//loop through the rules in the current style sheet
		for (var j=0; j < rules.length; j++) {
			//get the text of the rule in a cross-browser fashion
			if (isIE()) {
				if (rules[j].selectorText == '.' + sClass) {
					return eval('document.styleSheets[' + i + '].rules[' + j + '].style.' + sProperty);
				}
			}
			else {
				if (rules[j].cssText.indexOf('.' + sClass) > -1) {
					return eval('document.styleSheets[' + i + '].cssRules[' + j + '].style.' + sProperty);
				}
			}
		}
	}
	
	//nothing found
	return '';
}

/*
written:	10/21/02
purpose:	returns an appropriate font size for the current resolution (8 pt for 800 x 600 or less, 9 pt for 1024 x 768, 10 pt for any higher resolutions)
*/
function getFontSize() {
	if (screen.width <= 800) {
		return 8;
	}
	else if (screen.width <= 1024) {
		return 9;
	}
	else {
		return 9;
	}
}

/*
written:	07/18/11
purpose:	"robust" triggering of a specified event for a specified element - has some quirks for IE - see its use in /calendar/c_month_mini.cfm
 
 Quote from the internet: You can't call events just like you would normal functions, 
 because there may be more than one function listening for an event, and they can get set in several different ways
*/
function fireEvent(element, event){
  if (isIE())
	{
     // dispatch for IE - currently cannot get it to work if in a pop-up called from a pop-up
     var evt = element.ownerDocument.createEventObject();	//be sure to create the event in the same document as the element
     return element.fireEvent('on'+event, evt);
  }
  else
	{
     // dispatch for firefox + others - especially important that it triggers events in a pop-up called from another pop-up
     var evt = document.createEvent("HTMLEvents");	
     evt.initEvent(event, true, true ); // event type,bubbling,cancelable
     return !element.dispatchEvent(evt);
  }
}

/* focusfirst function (IE only) puts browser focus on first data entry field*/
function focusfirst(frm)
{
	var i
	if (focusfirst.arguments.length == 0)
	{
		for (i=0;i<document.forms[0].elements.length; i++)
		{
			if (document.forms[0].elements[i].type != "hidden")
			{
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
	else
	{
		for (i=0;i<frm.elements.length; i++)
		{
			if (frm.elements[i].type != "hidden")
			{
				frm.elements[i].focus();
				break;
			}
		}
	}	
}


/*
written:    6/26/01
purpose:    returns a string in the format 'height="[n]" width="[n]"' for imbedding in image tags on the fly;
    		eliminates the need to call both getImageHeight and getImageWidth
arguments:  imgHeight   native height of the image
            imgWidth    native width of the image
            availHeight vertical space available for image display
            availWidth  horizontal space available for image display
ret value:  a string in the form of 'height="[n]" width="[n]"'
*/
function getImageDimensionString(imgHeight, imgWidth, availHeight, availWidth) 
{
    return ' height="' + getImageHeight(imgHeight, imgWidth, availHeight, availWidth) + '" width="'+ getImageWidth(imgHeight, imgWidth, availHeight, availWidth) + '"';
}


/*
written:    6/26/01
purpose:    calculates how much an image of the given actuals dimensions must be shrunk (if at all) to fit into
            the given available dimensions, shrinks the image proportionally and returns the new height
arguments:  imgHeight   native height of the image
            imgWidth    native width of the image
            availHeight vertical space available for image display
            availWidth  horizontal space available for image display
ret value:  the calculated image height
*/
function getImageHeight(imgHeight, imgWidth, availHeight, availWidth) {
    var iHeight;
    
    //if image already fits, just return native height
    if (imgHeight <= availHeight && imgWidth <= availWidth) return imgHeight;
    
    //whichever ratio is smallest will be the determining factor
    if (availHeight/imgHeight <= availWidth/imgWidth) {
        return availHeight;    
    }
    else {
        iHeight = Math.round(imgHeight * availWidth/imgWidth);
        if (iHeight > availHeight) iHeight = availHeight;
        return iHeight;
    }
}


/*
written:    6/26/01
purpose:    calculates how much an image of the given actuals dimensions must be shrunk (if at all) to fit into
            the given available dimensions, shrinks the image proportionally and returns the new height
arguments:  imgHeight   native height of the image
            imgWidth    native width of the image
            availHeight vertical space available for image display
            availWidth  horizontal space available for image display
ret value:  the calculated image width
*/
function getImageWidth(imgHeight, imgWidth, availHeight, availWidth) {
    var iWidth;
    
    //if image already fits, just return native height
    if (imgHeight <= availHeight && imgWidth <= availWidth) return imgWidth;
    
    //whichever ratio is smallest will be the determining factor
    if (availHeight/imgHeight <= availWidth/imgWidth) {
        iWidth = Math.round(imgWidth * availHeight/imgHeight);
        if (iWidth > availWidth) iWidth = availWidth;
        return iWidth;
    }
    else {
        return availWidth;
    }
}


/*
written: 5/12/11
purpose: returns the value for the checked radio element of the given name
arguments: sName = name of radio element, assumed to be on the 1st form of the page
*/
function getRadioValue(sName) {
	arr = document.getElementsByName(sName);
	for (i=0;i<arr.length;i++) {
		if (arr[i].checked) return arr[i].value;
	}
}


/*
written:    2/16/01
purpose:    detmines whether the current browser is Internet Explorer 4.x
ret value:  true if the current browser is Internet Explorer 4.x; otherwise false
*/
function isIE4() {
    var sVersion = navigator.appVersion.toLowerCase();
    if (sVersion.indexOf('msie 4') > -1) {
        return true;
    }
    else {
        return false;
    }
}

/*
written:    1/21/02
purpose:    detmines whether the current OS is Mac OS
ret value:  true if the current OS is Mac OS; otherwise false
*/
function isMac() {
    var sPlatform = navigator.platform.toLowerCase();
    if (sPlatform.indexOf('mac') == 0) {
        return true;
    }
    else {
        return false;
    }
}


/* removes leading and trailing spaces */
function javatrim(stringtotrim)
{
	if (stringtotrim == "" || (stringtotrim.indexOf(" ")== -1 && stringtotrim.indexOf("\xA0") == -1))
	{
		return stringtotrim;
	}
	while (stringtotrim.indexOf(" ") == 0 || stringtotrim.indexOf("\xA0")==0)
	{
		stringtotrim=stringtotrim.substring(1,stringtotrim.length)
		if (stringtotrim.length == 0)
		{
			return "";
		}
	}
	
	while (stringtotrim.lastIndexOf(" ") == stringtotrim.length - 1 || stringtotrim.lastIndexOf("\xA0") == stringtotrim.length -1)
	{
		stringtotrim=stringtotrim.substring(0,stringtotrim.length - 1)
		if (stringtotrim.length == 0)
		{
			return "";
		}
	}
	return stringtotrim;
}

/* removes leading and trailing CR LF characters */
function javatrimCRLF(stringtotrim)
{
	if (stringtotrim == "" || (stringtotrim.indexOf("\x0D") == -1 && stringtotrim.indexOf("\x0A") == -1))
	{
		return stringtotrim;
	}
	while (stringtotrim.indexOf("\x0D") == 0 || stringtotrim.indexOf("\x0A") == 0)
	{
		stringtotrim=stringtotrim.substring(1,stringtotrim.length)
		if (stringtotrim.length == 0)
		{
			return "";
		}
	}
	
	while (stringtotrim.lastIndexOf("\x0D") == stringtotrim.length - 1 || stringtotrim.lastIndexOf("\x0A") == stringtotrim.length -1)
	{
		stringtotrim=stringtotrim.substring(0,stringtotrim.length - 1)
		if (stringtotrim.length == 0)
		{
			return "";
		}
	}
	return stringtotrim;
}

/*given a starttime in milliseconds, provides an alert giving elapsed seconds */
function jsElapsedTime(lstarttime, smsg)
{
	if (jsElapsedTime.arguments.length < 2)
	{
		smsg = "Elasped: "
	}
	var now2 = new Date()
	var endtime = now2.getTime()
	alert(smsg + eval((endtime-lstarttime)/1000) + " seconds") 
}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//functions to open or focus on popups
// as of 10/15/01 not in use in iCohere
function openpopupwin(winopenfieldvalue,formtosubmit,winname,hopenwin)
{
	//alert(winopenfieldvalue)
	//alert(formtosubmit)
	//alert(winname)
	//alert(hopenwin)
	
	if (winopenfieldvalue=="")
	{
		hopenwin = window.open('../sharedfiles/blank.htm',winname,'scrollbars=yes,resizable=yes,width=640,height=480');
		formtosubmit.submit()
		return hopenwin
	}
	else
	{
		hopenwin.focus()
		return hopenwin
	}
}

//this goes in all the popup windows and determines who is calling the close
//alert function
// as of 10/15/01 not in use in iCohere
function popupclosealert(sopener,frm)
{
	var popupname=frm.hidPopupName.value
	if (sopener.document.forms[0].hidCalledBy.value=="closewindow")
	{
		 closeok(frm)
	}
	if (sopener.document.forms[0].hidCalledBy.value=="")
	{
		if(frm.hidOperation.value == "noclose")
		{
			alert('utils.You have closed the ' + popupname + ' form, \nbut have not submitted your changes.\nAny changes you made have been lost.')
		}
	}
}

// as of 10/15/01 not in use in iCohere
function popupcloseconfirm(sopener,frm)
{
	var formname=frm.formname.value
	if (sopener.document.forms[0].calledby.value=="closewindow")
	{
		 closeok()
	}
	if(sopener.document.forms[0].calledby.value=="")
	{
		if(frm.operation.value =="noclose")
		{
			alert('You have closed the ' + formname + ' Confirmation page, \nbut have not confirmed your ' + formname + ' entries.\nAny changes you made have been lost.')
		}
	}
		
}


//this goes in the popup windows opened by parent.opener and determines who is calling
//the close alert function
// as of 10/15/01 not in use in iCohere
function popupparentclosealert()
{
	var formname=document.forms[0].formname.value
	if (parent.opener.document.forms[0].calledby.value=="closewindow")
	{
		 closeok()
	}
	if (parent.opener.document.forms[0].calledby.value=="")
	{
		if(document.forms[0].operation.value == "noclose")
		{
			alert('You have closed the ' + formname + ' form, \nbut have not submitted your changes.\nAny changes you made have been lost.')
		}
	}
}

// as of 10/15/01 not in use in iCohere
function popupparentcloseconfirm()
{
	var formname=document.forms[0].formname.value
	if (parent.opener.document.forms[0].calledby.value=="closewindow")
	{
		 closeok()
	 }
	if(parent.opener.document.forms[0].calledby.value=="")
	{
		if(document.forms[0].operation.value =="noclose")
		{
			alert('You have closed the ' + formname + ' Confirmation page, \nbut have not confirmed your ' + formname + ' entries.\nAny changes you made have been lost.')
		}
	}
}

/* concatenates str n times and returns text*/
function repeatString(n,str)
{
   var text = "";
   str = str.toString(); //make sure this is a string
   while (n > 0)
   {
		text += str;
		n--;
   }
   return text;
}

/*
written:	modified for the Mac and placed in this library 8/11/06
purpose:	resizes a popup window to fit its contents
revisions:
	10/20/10 by jeremy to store previous resize values and not continue to widen/shrink windows when moving through messages or calendar items
*/
function resizePopup() {
	//provide default values for piPrevScrollWidth and piPrevScrollHeight
	if (typeof(phTopFrame.piPrevScrollWidth) == 'undefined') phTopFrame.piPrevScrollWidth = 0;
	if (typeof(phTopFrame.piPrevScrollHeight) == 'undefined') phTopFrame.piPrevScrollHeight = 0;
	
	//if the content hasn't changed since the last resize, don't resize again
	if (isIE() == false && document.body.scrollWidth == phTopFrame.piPrevScrollWidth && document.body.scrollHeight == phTopFrame.piPrevScrollHeight) return;	

	//for debugging purposes
	//alert(phTopFrame.document.location.href);
	//alert('document.body.scrollWidth: ' + document.body.scrollWidth + '\n\nphTopFrame.piPrevScrollWidth: ' + phTopFrame.piPrevScrollWidth + '\n\ndocument.body.scrollHeight: ' + document.body.scrollHeight + '\n\nphTopFrame.piPrevScrollHeight: ' + phTopFrame.piPrevScrollHeight);
		
    //IE or other browsers?
    if (!isIE()) {
		//more vertical padding needed on the Mac
		if (isMac()) {
			var iClearance = 75;
			var iMacWidthOffset = 100;
		}
		else {
			var iClearance = 25;
			var iMacWidthOffset = 50;
		}
		
		//adjust height
		if (innerHeight > document.body.scrollHeight + 25) {
			top.resizeBy(0, document.body.scrollHeight - innerHeight + 25);
		}
		else if (document.body.scrollHeight > innerHeight) {
			if (document.body.scrollHeight - innerHeight + outerHeight + screenY + iClearance < screen.height) {
				top.resizeBy(0, document.body.scrollHeight - innerHeight);
			}
			else {
				top.resizeBy(0, screen.height - screenY - outerHeight - iClearance);
			}
		}

		//adjust width
		if (innerWidth > document.body.scrollWidth + iMacWidthOffset + 25) {
			top.resizeBy(document.body.scrollWidth - innerWidth + 25, 0)
		}
		else if (document.body.scrollWidth + iMacWidthOffset > innerWidth) {
			if (document.body.scrollWidth + iMacWidthOffset - innerWidth + outerWidth + screenX + 20 < screen.width) {
				top.resizeBy(document.body.scrollWidth + iMacWidthOffset - innerWidth, 0);
			}
			else {
				top.resizeBy(screen.width - screenX - outerWidth - 20, 0);
			}
		}
	}
	else {
        try{
			var iResizeX = 0;
			var iResizeY = 0;
			
            if (document.body.scrollWidth > document.body.clientWidth) {
                if (window.screenLeft + document.body.scrollWidth + 20 < screen.availWidth) {
                    iResizeX = document.body.scrollWidth - document.body.clientWidth;
                }
                else {
					iResizeX = screen.availWidth - document.body.clientWidth - window.screenLeft - 25;
                }
            }
            else if (document.body.scrollWidth < document.body.clientWidth - 20) {
                iResizeX = document.body.scrollWidth - document.body.clientWidth;
            }
            if (document.body.scrollHeight > document.body.clientHeight) {
                if (window.screenTop + document.body.scrollHeight + 25 < screen.availHeight) {
                    iResizeY = document.body.scrollHeight - document.body.clientHeight;
                }
                else {
                    iResizeY = screen.availHeight - window.screenTop - document.body.clientHeight - 25;
                }
            }
            else if (document.body.scrollHeight < document.body.clientHeight) {
                iResizeY =  document.body.scrollHeight - document.body.clientHeight;
            }

            //will scrollbars be needed after resize? (it's important to set the scrollbars on/off first, then resize)
            if (document.body.scrollWidth <= (document.body.clientWidth + iResizeX) && document.body.scrollHeight <= (document.body.clientHeight + iResizeY)) {
				document.body.scroll = 'no';
			}
			else {
				document.body.scroll = 'yes';
			}
			
			//now resize the window
			top.resizeBy(iResizeX, iResizeY);

			//the next line, though seemingly useless, forces IE to redraw the page correctly and fixes a long standing, annoying bug in which the page shifts unaccountably once you start to use it
			//if this doesn't run it doesn't trigger the fckeditor reload
			//document.body.innerHTML = document.body.innerHTML;
		}
        catch(err){}
    }

	//update piPrevScrollWidth and piPrevScrollHeight
	phTopFrame.piPrevScrollWidth = document.body.scrollWidth; 
	phTopFrame.piPrevScrollHeight = document.body.scrollHeight;
}


/*
written:  4/27/05 by Jeremy
purpose:  reverses the effects of the CF XMLFormat() function
arguments: s string to be de-XMLFormatted
ret value:  s with <, >, ', " and & un-escaped
*/
function reverseXMLFormat(s) {
	var re = new RegExp("&quot;", "g");
	s = s.replace(re,'"');
	var re = new RegExp("&apos;", "g");
	s = s.replace(re, "'")
	var re = new RegExp("&gt;", "g");
	s = s.replace(re,">");
	var re = new RegExp("&lt;", "g");
	s = s.replace(re, "<");
	var re = new RegExp("&amp;", "g");
	s = s.replace(re, "&");
	return s;
}

/* checks an option when related text is entered*/
/* for example: when ExistingBTN text is entered, radio ExistingBTN selected
called by onChange or onBlur of text field*/
function selectoptwhentxtentered(optfield,index,textfield)
{
	if (textfield.value != "")
	{
		/*set radio button related to text entered*/
		optfield[index].checked=true;		
	}
}


/*
written: 5/12/11
purpose: checks the radio element by the given name that has the given value
arguments:	sName = name of radio element, assumed to be on the 1st form of the page
			sVal = desired value 
*/
function setRadioValue(sName, sVal) {
	arr = document.getElementsByName(sName);
	for (i=0;i<arr.length;i++) {
		if (arr[i].value == sVal) {
			arr[i].checked = true;
			return;
		}
	}
}


/*
written: 12/07/00 by Don
purpose: return today's date/ time in one of two formats (now three - Keith)
arguments: user's format mask: "mm/dd/yy" or "dd/mm/yy" (also now "yyyy-mm-dd"  - Keith)
notes: this is set to show a four year date, time is "h:mm tt"
	   use this rather than CF functions for a current local datetime
	   this is designed for display, not for parsing into text boxes
Corrected on 5/28/01 by Keith - Times between 12 Noon and 1 PM were returning "AM"
Enhanced on 5/28/01 by Keith - added format option "yyyy-mm-dd" which has leading zeros on month and day.  Time is in 24-hour clock  
*/
function showToday(sformat,paramToday)
{
	if (paramToday != 'undefined')
	{
		today = paramToday
	}
	else
	{
		try{var today = getServerLocaleDateTime()}  
		catch(err)
		{
			today = new Date();
		}
	}
	if (typeof(today) == 'undefined')
	{
		today = new Date();
	}
	var smonth = today.getMonth() + 1;
	var sday = today.getDate();
	var syear = today.getYear();
	if (parseInt(syear) < 1000)
	{
		syear = 1900 + parseInt(syear);  //for netscape
	}	
	syear = syear.toString()
	syear = syear.substring(2,4)
	if (sformat == 'mm/dd/yy')
	{
		var showdate = "" + smonth + "/" + sday + "/" + syear; 
	}
	else
	{
		if (sformat == 'yyyy-mm-dd')
		{
		   if (sday < 10)
		   {
			   sday = "" + "0" + sday;
		   }
		   else
		   {
			   sday = "" + sday;
		   } 
		   if (smonth < 10)
		   {
			   smonth = "" + "0" + smonth;
		   }
		   else
		   {
			   smonth = "" + smonth;
		   }
		   syear = today.getFullYear();
		   var showdate = "" + syear + "-" + smonth + "-" + sday;  
		}
		else
		{
			var showdate = "" + sday + "/" + smonth + "/" + syear; 
		}
	}
	var shour = "" + today.getHours();
	var sminute= + today.getMinutes();
	if (sminute < 10)
	{
		sminute = "" + "0" + sminute;
	}
	else
	{
		sminute = "" + sminute;
	}
	if (sformat == 'yyyy-mm-dd')
	{
	    daypart = "";
	}
	else
	{ 
		if (shour > 12)
		{
			shour = shour - 12;
			daypart = "PM";
		}
		else
		{
			if (shour == 12)
			{
			    daypart = "PM";
			}
			else
			{
				daypart = "AM";
			}
		}
	}
	return "" + showdate + " " + shour + ":" + sminute + " " + daypart
}


/*
written: 6/9/00 by Stephanie
purpose: return time in minutes since midnight
arguments: strHour, strMins,strAMPM
notes: used for time comparisons between datetimes on the same day
*/
/* not in use */
function timeInMins(strHour,strMins,strAMPM)
{
	var iTimeInMins = 0;
	var iHour = 0;
	if (parseFloat(strHour) == 12)
	{
		iHour = 0;
	}
	else
	{
		iHour = parseFloat(strHour)
	}
	
	if (strAMPM == "PM")
	{
		iTimeInMins = (60*(iHour+12) + parseFloat(strMins));
	}
	else
	{
		iTimeInMins = (60*(iHour) + parseFloat(strMins));
	}
	return iTimeInMins;
}

function stripZeros(sInput)
{
	var result = sInput
	while (result.substring(0,1) == "0")
	{
		result = result.substring(1,result.length)
	}
	return result
}

//returns an integer which is the milliseconds since January 1, 1970 
//to strDate, strHour, strMins, strAMPM
//***** NEEDS MODIFICATION FOR EUROPEAN DATE FORMAT *****//
function getDateAsMilliseconds(sDateFormat,strDate,strHour,strMins,strAMPM)
{
	if (strDate == "")
	{
		return "";
	}
	// convert 2 digit years to 4 digit
	// code from validate isDate
	var delim1 = strDate.indexOf("/")
	var delim2 = strDate.lastIndexOf("/")
	var mm;
	var dd
	var yyyy	
	if (delim1 != -1)
	{
		//there are delimiters; extract component values
		if (sDateFormat == "mm/dd/yy" || sDateFormat == "mm/dd/yyyy")
		{
		    var mm = strDate.substring(0,delim1);
		    var dd = strDate.substring(delim1 + 1,delim2);
		    var yyyy = strDate.substring(delim2 + 1,strDate.length);
		}
		else
		{
		    var dd = strDate.substring(0,delim1);
		    var mm = strDate.substring(delim1 + 1,delim2);
		    var yyyy = strDate.substring(delim2 + 1,strDate.length);
		}
	}
	if (yyyy == "00" || yyyy == "000" || yyyy == "0000")
	{
	    yyyy = parseInt(yyyy)
	}
	else
	{
	    yyyy = parseInt(stripZeros(yyyy))
	}
	
	if (yyyy < 100)
	{   
		//entered value is two digits, which we allow for, use sliding window to determine century
		var today = new Date()
		if (navigator.appName == "Netscape")
		{
		    var thisyear = today.getYear() + 1900
		}
		else
		{
		    var thisyear = today.getYear()
		}
		var centbrk = (" " + (thisyear - 69)).substring(3,5);
		if (thisyear >= 2069)
		{
		    if (yyyy >= centbrk)
			    yyyy = 2000 + yyyy;
			else
		        yyyy = 2100 + yyyy;
		}
		else
		{
		    if (yyyy >= centbrk)
			    yyyy = 1900 + yyyy;
			else
		        yyyy = 2000 + yyyy;
		}
	}
	strDate = mm + "/" + dd + "/" + yyyy;
	var dateAsMil = Date.parse(strDate);
	var timeAsMins = timeInMins(strHour,strMins,strAMPM);
	var timeAsMil = parseInt(timeAsMins) * 1000 * 60;//minutes * 60 * 1000 = milliseconds
	var dateTimeAsMil = dateAsMil + timeAsMil;
	return dateTimeAsMil;
}

function dateFourDigitYear(strDate,sDateFormat)
{
	if (strDate == "")
	{
		return "";
	}
	// convert 2 digit years to 4 digit
	// code from validate isDate
	var delim1 = strDate.indexOf("/")
	var delim2 = strDate.lastIndexOf("/")
	var mm;
	var dd
	var yyyy	
	if (delim1 != -1)
	{
		//there are delimiters; extract component values
		if (sDateFormat == "mm/dd/yy" || sDateFormat == "mm/dd/yyyy")
		{
		    var mm = strDate.substring(0,delim1);
		    var dd = strDate.substring(delim1 + 1,delim2);
		    var yyyy = strDate.substring(delim2 + 1,strDate.length);
		}
		else
		{
		    var dd = strDate.substring(0,delim1);
		    var mm = strDate.substring(delim1 + 1,delim2);
		    var yyyy = strDate.substring(delim2 + 1,strDate.length);
		}
	}
	if (dd.length == 1)
	{
		dd = "0" + dd;
	}
	if (mm.length == 1)
	{
		mm = "0" + mm;
	}
	if (yyyy == "00" || yyyy == "000" || yyyy == "0000")
	{
	    yyyy = parseInt(yyyy)
	}
	else
	{
	    yyyy = parseInt(stripZeros(yyyy))
	}

	if (yyyy < 100)
	{   
		//entered value is two digits, which we allow for, use sliding window to determine century
		var today = new Date()
		if (navigator.appName == "Netscape")
		{
		    var thisyear = today.getYear() + 1900
		}
		else
		{
		    var thisyear = today.getYear()
		}
		var centbrk = (" " + (thisyear - 69)).substring(3,5);
		if (thisyear >= 2069)
		{
		    if (yyyy >= centbrk)
			    yyyy = 2000 + yyyy;
			else
		        yyyy = 2100 + yyyy;
		}
		else
		{
		    if (yyyy >= centbrk)
			    yyyy = 1900 + yyyy;
			else
		        yyyy = 2000 + yyyy;
		}
	}
	if (sDateFormat == "mm/dd/yy") 
	{
		strDate = mm + "/" + dd + "/" + yyyy
	}
	else
	{
		strDate = dd + "/" + mm + "/" + yyyy
	}
	return strDate;
}

var phImageView;
function viewImage(sfilename,iheight,iwidth)
{
    if (screen.availHeight * .2 < 150) {
        if (screen.availHeight * .2 < 100) {
        	var iScreenHeight = screen.availHeight * .6;
            var iScreenWidth = screen.availHeight * .75;
        }
        else {
        	var iScreenHeight = screen.availHeight * .75;
            var iScreenWidth = screen.availWidth * .8;
        }
    }
    else {
    	var iScreenHeight = screen.availHeight * .8;
        var iScreenWidth = screen.availWidth * .9;
    }
	var imgHeight = (getImageHeight(iheight,iwidth,iScreenHeight,iScreenWidth));
	var imgWidth = (getImageWidth(iheight,iwidth,iScreenHeight,iScreenWidth));
 	var winH = imgHeight + 100;
    var winW = imgWidth + 50;
    
    //enforce a minimum height of 200 and width of 200
    if (winH < 200) winH = 200;
    if (winW < 200) winW = 200;

    //for netscape open with scrollbars because they can't be changed dynamically
    if (isNetscape()) {
	    phImageView=window.open('../sharedpages/viewimage.cfm?filename=' + sfilename + '&height=' + imgHeight + '&width=' + imgWidth + '&nativeHeight=' + iheight + '&nativeWidth=' + iwidth + psMkeyString,'imageview','scrollbars,resizable=yes,height=' + winH + ',width=' + winW + centerPopup(winW,winH))
    }
    else {
	    phImageView=window.open('../sharedpages/viewimage.cfm?filename=' + sfilename + '&height=' + imgHeight + '&width=' + imgWidth + '&nativeHeight=' + iheight + '&nativeWidth=' + iwidth + psMkeyString,'imageview','resizable=yes,height=' + winH + ',width=' + winW + centerPopup(winW,winH))
    }
}

//for new show/hide panel includs arrow image 
function changePanel(hideID, imageID, num)
{
	unhide(hideID + num)
	if (document.images[imageID + num].src.indexOf('Closed') > - 1)
	{
		MM_swapImage(imageID + num,'','../images/arrowOpened.png',0)
	}
	else
	{
		MM_swapImage(imageID + num,'','../images/arrowClosed.png',0)
	}	
}

function unhide(hideObject) {
  var item = document.getElementById(hideObject);
  if (item) {
    item.className=(item.className=='hidden')?'unhidden':'hidden';
  }
}

function hide(unhideObject) {
  var item = document.getElementById(unhideObject);
  if (item) {
    item.className=(item.className=='unhidden')?'hidden':'unhidden';
  }
}


function isWYSIWYGallWhiteSpace(stringHTML) {
  // all white space seen in WYSIWYG editor should mean only new lines characters, spaces, hard spaces, paragraph tags, break tags, and certain div tags
  var jsRegExpNL    = new RegExp("\n","g")
  var jsRegExpSpace = new RegExp(" ","gi");
  var jsRegExpNBSP  = new RegExp("&nbsp;","gi");
  var jsRegExpPBs   = new RegExp("<p>","gi");   
  var jsRegExpPEs   = new RegExp("</p>","gi") ;  
  var jsRegExpBRs   = new RegExp("<br />","gi");
  var jsRegExpDiv1  = new RegExp('<div .*name="divDefaultStyle"[^>]*>',"gi")
  var jsRegExpDiv2  = new RegExp('<!--icDefaultStyle-->.*<!--icDefaultStyle-->',"gi")
  var jsRegExpDiv3  = new RegExp('<!--icDefaultStyle-->',"gi")
  var  temp = stringHTML.replace(jsRegExpNL,'') ;  <!--- always do this one first, so as to then get pure HTML --->
  temp = temp.replace(jsRegExpSpace,'') ;
  temp = temp.replace(jsRegExpNBSP,'') ;
  temp = temp.replace(jsRegExpPBs,'') ;
  temp = temp.replace(jsRegExpPEs,'') ;
  temp = temp.replace(jsRegExpBRs,'') ;
  temp = temp.replace(jsRegExpDiv1,'') ;
  temp = temp.replace(jsRegExpDiv2,'') ;
  temp = temp.replace(jsRegExpDiv3,'') ;
  if (temp == "" )  <!--- WYSIWYG editor string still has some sort of CRLF character --->
  {
  	return true ;
  }
  else
  {
  	return false ;
  } 
}
