	/*
	 * Change Flags:
	 *  
	 *   Flag + A = Added this code.
	 *   Flag + D = Deleted this code.
	 *   Flag + C = Changed this code.
	 *   Flag + M = Moved this code.
	 * 
	 *   Flag  Initials  Date		  PIT#    Comment
	 *   ----- --------  ------   ------  --------------------------------------------
     *   $MM1  MFM       5/01/01           Added function ChkDateValid(myDate)      
	 *   $MM2  MFM       5/11/01           Added code to ChkDateValid(myDate) that highlight and blanks out field if date still incorrect.	 										               
	 *   $JE1  JME       6/4/1             Made name of Browser Random in Browselist when opening
	 *									                   Ctop so that multiple instances of Ctop can be opened.
	 *   $JE2  JME       6/4/1             Pass filter code and filter text to Ctop.
	 *   $JE2  JME       6/13/1            Add the updateValue function.
     *   $MM3  MFM       7/06/1            Added function ChkNumericInput(obj)      
     *   $SC1  SPC		 7/21/1			   Added chkValidNumber() (deal with decimal and negative sign
     *									   added ValiateState()
     *   $MM4  MFM       7/31/1            Fixed gettoday(),now adds zero in front of number if less than 10       
	 *   $SC2  SPC		 7/21/1			   Added calculate Age function
     *   $MM5  MFM       9/14/1            Added functions setformfields() and goingnowhere() to disable form 
     *									   elements if user has readonly access.
     *	 $sc3  SPC       9/28/1			   Added VALDECNUM() 
     *   $MM6  MFM		10/22/01           Added check and closing of any open BrowseDoc window handles upon
     *									   each button click to Browselist or Browselist2 
     *   $SC4  SPC      10/23/1			   Added UnescapeString()	
     *   $MM7  MFM		11/26/1            Added code to browselist to blank out field when clicking on ... button
     *                                     this will prevent the saving of invalid data.
	 *   $MM8  MFM      12/12/1    12618   Fix incorrect calculation of DOB (created new calculateAge)
	 *   $JE4  JME      12/17/1            Change BrowseMark to support MSLMarkTop.asp
	 *   $SP1  CSP      12/27/1    12618   A better formula for calculateAge
	 *   $SP2  CSP      01/15/2    12618   Added a trap for empty date in calculateAge
	 *   $MM9  MFM      02/04/2    12763   Fix highlighted and then deleted date problem.
	 *   $MM10 MFM      02/08/2    12907   Added DateFix() and TimeFix() and modified ChkDateValid(myDate)
	 *										these functions format the date or time to our standard format.
     *   $SC5			2/28/2			   Add hidden type for unescapestring funtion 
	 *   $MM11 MFM      3/04/2     12763   Fixed situation where if a date field was highlighted and deleted, chkDateValid()
	 *                                     would popup an error message.
	 *   $MM12 MFM      3/05/2     13030   Fixed Browselist update problem where database has no cd field only txt.
	 *   $SC6 SPC       3/29/2			   Fixed the prompt not to ask question when it is an empty department in the facility screen
	 *   $MM13 MFM      5/02/2             Added a more descriptive error message within ValidDecNum() function. 
	 *   $MM14 MFM      6/05/2     13499   Added an unescape to cVal to prevent error in saving it.
	 *   $MM15 MFM      7/10/2             Added function ChkAlphaNumInput() to prevent any char outside of 1-10 and a-Z
	 *   $RS1  RS       6/28/02            Moved the removal of megasave character (c,#,n,l,d) from QkHlpEdit.asp into SetHelp function
     *   $MM16 MFM		08/02/02   12017   Added check and closing of any open BrowseDoc window handles upon
     *   $MM17 MFM		09/11/02   12911   Added code to to BrowseList in order to get Record Status filtering to work correctly
     *   $MM18 MFM		09/18/02   13918   Added code to to BrowseList for phy_facility.asp
     *   $SP3  CSP      11/12/02   14215   In BrowseList function, Added CodeObj querystring parameter
     *                                        in call to cTop.asp
     *   $SC7  SPC      1/6/2      14243   Added chktimeformat function for phy_add_edit.asp and other use later
     *   $RS2  RS       01/07/02   11151   Increased the width of the Quick Help/Color window.
     *   $EC1  EC       02/21/03           User Group Maintenance Logic added.
     *   $EC2  EC       03/07/03   14736   Fixed User ellipses bug.
     *   $RS3  RS       03/14/03   14740   Changed ChkTimeFormat to clear fields when they contain invalid data (invalid times)
     *   $SC8  SPC		03/21/03   14427   Fixed the time to accept three digits as hmm and fixed the focus by using Onblur()
     *   $EC3  EC       03/26/03   14888   User/Group Pop-Up Changes.
     *   $SC9 SPC       03/27/03   14811    Fixed when the deparment is initiated with Blank do not ask auto-populate question?
     *   $EC4  EC       03/26/03   15578   Changes associated with new UDF design.
     *   $EC5  EC       10/09/03   15907   NPDB CC State Pop-up change.
     *   $EC6  EC       10/17/03   15948   Date change.
     *   $RS4  RS       11/07/03   16010   Added in the HTTPS changes from Paul's version of JavaHead.
     *   $RS5  RS       12/26/03   14490   Added a "cSearch" parameter to the BrowseCommittee function
     *   $JE5  JME      1/6/4      16184   Datetime functions.
     *	 $ST1  ST		01/21/04   16197   Spinner Functions.
     *	 $ST2  ST		01/30/04   16379   Added  BrowseChklist
     *	 $ST3  ST		02.04.04   16473/75   Functions for money and floats.
     *   $RS19 RS       02/05/04   16482   Reverted megasave performance enhancement to former design. (changed getDefaults())
     *	 $ST4  ST		02.13.04			Tiny AOC reference
	 *   $ST5  ST       02.19.04   16581    reload carecodes upon asptcode reselect
   	 *   $ST6  ST       02.20.04   16589    department and sections browse for admit screen
	 *   $ST7  ST       03.19.04   16937    check to clear time, when date is cleared, so that 1/1/1900 is not saved
	 *	 $KS1  KJS      4/1/04	   16877    PIT 16589 changed the set focus after the an ellipses button is used.
	 *                                      This took away functionality to save the history of a providers Staffs Status 
	 *                                      and changed tabbing for many fields.
  	 *	 $ST8  ST		 05.04.04	17174	Fixed the Rptr->Filter->CkLst_Line filter error due to structural changes.
	 *	 $ST9  ST		 05.20.04   13510   Checklist _XX merge variables 
	 *	 $ST10 ST		 06.14.04	17352	Masterdbf browse modification
		 $ST11 ST        06.17.04   17375	Checklist popup to limit by admit.fac_cd if at admit level
     *   $EC7  EC        08/05/04   17407   Handling Quality Provider Rights. See Pit for Details.		 
	 *         WRL       08/30/04   17551   Added 'dotnetname' option within existing BrowseList parameter to support Bridge 2.0
     	 $ST12  ST		 08.31.04   17394	Added Edit and Upload RTF buttons, check for empty filename
     	 $JA1  JA		 09/09/04	17844	Copied function ChkPhoneInputNoArea() from pat_services_edit.asp ChkPhoneInput2()
     	 $JA2  JA		 09/27/04	17964	Modified BrowseChklist to use a new page with support for folders and security.
     	 $JA3  JA		 10/01/04	11354	Added chkExpDate() function to make date fields bold and red when <= today's date.
     	 $JA4  JA		 10/07/04	18003	Modified BrowseList() function to allow for the hidden code field value to be cleared
     										when the text field is cleared and the field loses focus.
     										Added function inCall() to return the call center referral status.
	 *   $RS20 RS        10/13/04   18007   Adjusted the updateDateTime function
	 *   $WRL1 Duke      10/28/04   18066   Added modal option to flags parameter in BrowseList() to support Echo Bridge 2.
	 *   $WRL2 Duke      11/01/04   18066   Minor update to support new button in Bridge UI: "btnRemoveMap"
	 *	 $JA5  JA		 12/20/04	18220	Added oXMLHttp() function to return an XmlHTTP object.
         *   $JB1    JB			02/07/05      18288   Added ChkZipInput() function to check that Zip is input correctly as all numeric
     *	 $JA6  JA		 04/13/05	18632	Added function runPage().
     *	 $JA7  JA		 04/19/05	18718	Made setformfields function work for drop-downs.
		 $ST13 ST		 06.03.05	18695	RTF
		 $JA8  JA		 06/03/05	18629	Rewrote ChkDateValid() function and removed unnecessary DateFix() function.
		 $PB   PB		 06/06/05   18648   added one more parameter to browselist to show the title of popup window for echo connect
											(Made the changes again as in version 131  as they were not included in the later versions.)
		 $PB   PB		 06/07/05   18648   Used the last parameter from browselist function to pass callclass to tbl_browser.
		 $PB   PB        06/15/05	18877   Fixed bug for decimal number spinner for negative numbers.  
		 $JA9  JA		 06/16/05	18865	Fixed bug in ChkTimeFormat() where times with "60" in the minutes portion would pass validation.
		 $JA10 JA		 09/28/08	18957	Added code for custom tooltips.  See QR_start.asp and start_WorklistReportsTab.txt for example.
		 $JA11 JA		 09/13/05	19143	Try to prevent tooltips from extending beyond the right or bottom edge of the screen.
		 $MT1  MT		 10/05/05	19145	Add parameter to ChkDateValid() to check for valid date withOUT popping up alert or changing the orginal date obj.
		 $MT2  MT		 10/05/05	19145	Add 2 parameters to ChkTimeFormat() one to allow disabling the pop up alert and the other to allow sending hour format.
		 $JA12 JA		 10/21/05	18932	Added checkMoney() function.
		 $JA13 JA		 10/28/05	19243	Modified call to rsfldfbrw.asp.
	 *   $RS21 RS        11/22/05   19309   Renamed the "BrowseCommittee" function to "BrowseWithFac" since it was being used by other tables.
	 *   $PB   PB        12/12/05   18992   Added a querystring parameter(type=both) to the call to cTop.asp when dbf name= syslogin and type <> user/group. 
	 *	 $MT3  MT        02/22/06   19645   Added runPageSynchro().  Similar to runPage(), but it runs the oReq.send() in synchronous mode; therefore, the calling page waits until the oReq returns.
     *   $JB2  JB		04/06/06			Added ChkIntInput() function to check that only integers (0-9) are entered
     *   $PB2  PB		09/12/06    20414   Modified the code/text selection box to not blank out the value when the elipse button is selected, only modify the value when the selection is returned.
     *   $PB3  PB		09/19/06    20194   Modified to handle + and ' in the txt value in BrowseMark2 function. This change may apply to BrowseMark in Future if needed.
     *	 $JC1  JC		09/20/06	20451	Modified MinusIt() to decrement by incVal only when incVal > lbound    
     *   $PB4  PB		09/21/06    20404   Added a letterType parameter to BrowseMark function to filter on records from rs_let
     *	 $JC2  JC		12/22/06	20462	Auto complete for Reporter Folders
     * 	 $JC3  JC	    01/16/07    20775	Added code to handle 'Facility ID Seed' and 'Digit Check'.
     */

var BrowseDoc = null;
var CodeObj = null;
var TxtObj = null;
parens1 = 0;
parens2 = 0;		
var gTimeFieldxx = null;		//$JE5A
var gDateTimeFieldxx = null;	//$JE5A

var debug = false; // used by the runPage function.


function parseDec(val,places,sep) {
	// This function takes two arguments:
	//   (string || number)  val
	//            (integer)  places
	//             (string)  sep
	// val is the numeric string or number to parse
	// places represents the number of decimal
	// places to return at the end of the parse.
	// sep is an optional string to be used to separate
	// the whole units from the decimal units (default: '.')

	val = '' + val;
		// Implicitly cast val to (string)
	
	if (!sep) {
		sep = '.';
		// If separator isn't specified, then use a decimal point '.'
	}
	
	if (!places) { places = 0; }
	places = parseInt(places);
		// Make sure places is an integer

	if ((parseInt(val)==NaN)||(parseInt(val)==null)) {  //PB 

		// If val is null, zero, NaN, or not specified, then
		// assume val to be zero.  Add 'places' number of zeros after
		// the separator 'sep', and then return the value.  We're done here.
		val = '0';
		if (places > 0) {
			val += sep;
			while (val.substring((val.indexOf(sep))).length <= places) {
				val += '0';
			}
		}
		return val;
	}
	
	if ((val.indexOf('.') > -1) && (sep != '.')) {
		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
			// If we're using a separator other than '.' then convert now.
	}
		
	if (val.indexOf(sep) > -1) {
		// If our val has a separator, then cut our value
		// into pre and post 'decimal' based upon the separator.
		pre = val.substring(0,val.indexOf(sep));
		post = val.substring(val.indexOf(sep)+1);
	} else {
		// Otherwise pre gets everything and post gets nothing.
		pre = val;
		post = '';
	}
	
	if (places > 0) {
		// If we're dealing with a decimal then...
		
		post = post.substring(0,(places+1));
			// We care most about the digit after 'places'
		
		if (post.length > places) {
			// If we have trailing decimal places then...
			
			//alert (parseInt(post.substring(post.length - 1)));

			if ( parseInt(post.substring(post.length - 1)) > 4 ) {
				post = '' + Math.round(parseInt(post) / 10);
				//post = '' + post.substring(0,post.length - 2) + (1/Math.pow(10,places));
				//post = ('' + post.substring(0,post.length - 2)) + (parseInt(post.substring(post.length - 1)) + 1);
			} else {
				post = '' + Math.round(parseInt(post));
			}
		}
		
		if (post.length > places) {
			post = '' + Math.round(parseInt(post.substring(0,places)));
		} else if (post.length < places) {
			while (post.length < places) {
				post += '0';
			}
		}
	
	} else {

		if (parseInt((post.substring(0,1))) > 4) {
			pre = '' + (parseInt(pre) + 1);
		} else {
			pre = '' + (parseInt(pre));	
		}
		post = '';
	}
	
	sep = (post.length > 0) ? sep : '';
		// Should we use a separator?

	val = pre + sep + post;
		// Rebuild val

	return val;
}

function parseMoney(val,sep) {

	// Specialized version of parseDec useful for
	// parsing money-related data.  Arguments:
	//   (string || number)  val
	//             (string)  sep
	// val is the monetary value to be parsed,
	// sep is an optional decimal separator (default: '.')
	
	return parseDec(val,2,sep);
}

function sepToDec(val,sep) {

	val = '' + val;

	if ((val.indexOf(sep) > -1) && (sep != '.')) {
		val = val.substring(0,val.indexOf(sep)) + '.' + val.substring(val.indexOf(sep)+1);
	}
	
	return val;
}

function decToSep(val,sep) {

	val = '' + val;
	sep = '' + sep;

	if ((val.indexOf('.') > -1) && (sep.length > 0)) {
		val = val.substring(0,val.indexOf('.')) + sep + val.substring(val.indexOf('.')+1);
	}

	return val;
}


//$ST1
function checknumber(num){
	var x=parseFloat(num);

	var anum=/(^\-{0,}\d+$)|(^\-{0,}\d+\.\d+$)/           //PB
	if (anum.test(x))
		testresult=true;
	else{
		testresult=false;
	}

	return (testresult);
}

function AddIt(oSpinner,cDataFld,ubound,decVal,incVal)
{
	var number;
	number = parseFloat(document.BaseDoc[cDataFld].value);
	
	if (checknumber(number))
	{
		if (number < parseFloat(ubound))
		{
			number = number+incVal;
			document.BaseDoc[cDataFld].value = parseDec(number,decVal);
		}
	}
	else
	{
		document.BaseDoc[cDataFld].value=0;
	}
}

function MinusIt(oSpinner,cDataFld,lbound,decVal,incVal)
{
	var number;
	number = parseFloat(document.BaseDoc[cDataFld].value);
	if (checknumber(number))
	{
		if (number > lbound)	//  JC1
		{
		number =  number-incVal;
		document.BaseDoc[cDataFld].value = parseDec(number,decVal);
		}
	}
	else
	{
		document.BaseDoc[cDataFld].value=0;
	}
}
//$ST1

function updateDateTime(time_obj,date_obj,datetime_obj) {	//$JE5A
	if (date_obj.value != "")
	{
		if (ChkTimeFormat(time_obj)) 
		{
			datetime_obj.value = date_obj.value + " " + time_obj.value; 
		}
		else //time is invalid or blank
		{   
			datetime_obj.value = date_obj.value; 
			return false;
		}
	}
	else
	{
		datetime_obj.value = "";
	}
	return true;
}

function setDateTimeField(calDateField,TimeField,DateTimeField) {	//$JE5A
	gTimeFieldxx = TimeField;
	gDateTimeFieldxx = DateTimeField;
	setDateField(calDateField);
}

function AfterDate(calDateField) {							//$JE5A
	if (gTimeFieldxx != null) {
		gDateTimeFieldxx.value = calDateField.value + " " + gTimeFieldxx.value; 
		gTimeFieldxx = null;
		gDateTimeFieldxx = null;
	}
}

function SetHelp(e, dbf_name, tcfieldname)
{
	if (e.button == 2)
	   {
		var fieldname;
		if (typeof(tcfieldname) == 'undefined') {
			fieldname = e.srcElement.name;
			fieldname = fieldname.substr(1);  //$RS1
		} else {
			fieldname = tcfieldname;  //$RS1
		}
		window.open("QkHlpEdit.asp?dbfname="+dbf_name+"&fieldname="+fieldname,"QuickHelpEdit","width=450, height=165,scrollbars=yes,resizable=yes");  //$RS2
	   }

	return;
}

function gettoday(ocont)
{ //$MM4
	var ldRet = "";
	if (trim(ocont.value).length > 0) { 
		ldRet = "";		                  
	} else {                            
		ldRet = new Date();
		
		var lcMonth = "";
		var lcDay = "";
		
		if((ldRet.getMonth()+1) <= 9)           
		{
		  lcMonth = "0" + (ldRet.getMonth()+1); 
		}
		else
		{
		  lcMonth = (ldRet.getMonth()+1); 
		}
		
		if(ldRet.getDate() <= 9)
		{
		  lcDay = "0" + (ldRet.getDate()); 
		}
		else
		{
		  lcDay = (ldRet.getDate()); 
		}
		
		ldRet = lcMonth  + "/" + lcDay + "/" + ldRet.getYear();
	} 
	return ldRet;
}

function MouseDown(e)
{
	return;
}

function trim(inStr)
{   var lcStr = new String(inStr);
	var lnlen = -1;
	for (i=lcStr.length-1;i>-1;i--) {
		if (lcStr.substr(i,1) != " ") {
			lnlen = i+1;
			i = -1;
		}
	}
	if (lnlen > -1) {
		lcStr = lcStr.substr(0,lnlen);
	} else {
		lcStr = "";
	}
	return lcStr;
}

function checkzip(ZIP, STATEField, CITYField, COUNTYField)
{
	self.parent.inv.window.navigate('valzip.asp?zipcode='+ZIP+'&city='+CITYField+'&state='+STATEField+'&county='+COUNTYField);
}

function rtfedit(link, table_name, field_or_rtf, ed_type)
{


}

function getdefaults()
{	
	for (i=0;i<document.BaseDoc.length;i++) {
		if (document.BaseDoc[i].name.substr(0,1) != "#" &&
			document.BaseDoc[i].type.toUpperCase() != "BUTTON" &&
			document.BaseDoc[i].name.substr(0,1) != "@" ) {			
			document.BaseDoc["#defaultvalues"].value = document.BaseDoc["#defaultvalues"].value + document.BaseDoc[i].name+"="+document.BaseDoc[i].defaultValue+"&&";
		}
	}
	//var test = document.BaseDoc["#defaultvalues"].value ;
	//alert(test);
}

function getalldefaults()  //$EC4
{	
	
	for (i=0;i<document.all.length;i++) {
	    if(document.all[i].name > "" && document.all[i].name != "undefined") {
   	      var fieldName = new String(document.all[i].name);
   	      var fieldType = new String(document.all[i].type);
		  if (fieldName.substr(0,1) != "#" && fieldType.toUpperCase() != "BUTTON" && fieldName.substr(0,1) != "@" && fieldType.toUpperCase() != "UNDEFINED") {
			document.all["#defaultvalues"].value = document.all["#defaultvalues"].value + document.all[i].name+"="+document.all[i].defaultValue+"&&";
			var test = document.all["#defaultvalues"].value ;
			//alert(test);
		  }   	      
	    }  
	}
		
}

function getdefaults_sp( cChar )
{	
    var docName = "" ;
	for (i=0;i<document.BaseDoc.length;i++) {
		if (document.BaseDoc[i].name.substr(0,1) != "#" &&
			document.BaseDoc[i].type.toUpperCase() != "BUTTON" &&
			document.BaseDoc[i].name.substr(0,1) == cChar ) {
			docName = document.BaseDoc[i].name ;
			docName = docName.substr(1) ;
			document.BaseDoc["#defaultvalues2"].value = document.BaseDoc["#defaultvalues2"].value + docName +"="+document.BaseDoc[i].defaultValue+"&&";
			var test = document.BaseDoc["#defaultvalues2"].value ;
		}
	}
}

function setformfields(access_char) { //$MM5

	if (access_char == 'R') {

 		for (i=0;i<document.BaseDoc.length;i++) {
	
			switch (document.BaseDoc.elements[i].type.toUpperCase()) {
				case "BUTTON": 
				    document.BaseDoc.elements[i].disabled=true;	 			
		 			break;
				case "CHECKBOX":
					document.BaseDoc.elements[i].disabled=true;
		 			break;
				case "RADIO":
					document.BaseDoc.elements[i].disabled=true;
		 			break;		 			
				case "TEXT":
					document.BaseDoc.elements[i].disabled=true;
		 			break;
				case "TEXTAREA":
					document.BaseDoc.elements[i].disabled=true;
		 			break;
		 		case "SELECT-ONE":
		 			document.BaseDoc.elements[i].disabled = true;
		 			break;
			}
		}
		for (var i=0; i < document.links.length; i++) {
			document.links[i].onclick = 'goingnowhere()'
			document.links[i].ondblclick = 'goingnowhere()'
		}
	}		
}

function goingnowhere() { //$MM5
	return;
} 
       
function Checkit(oChkBox,cDataFld)
{
	if (oChkBox.checked) {
		document.BaseDoc[cDataFld].value = true;
	} else {
		document.BaseDoc[cDataFld].value = false;
	}
	
}

function BrowseWithFac(cInput, cDbf, cCdFld, cCd, cTxt, cSearch ) {

    var cFac_cd = document.BaseDoc.cFac_Cd.value  ;
    
		CodeObj = cInput;
		if (trim(cCdFld).length > 0) {
			TxtObj = cCdFld;
		} else {
			TxtObj = null;
		}
	
		var ldDate = new Date();																																											
		var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));
		BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&facCode="+cFac_cd,
		Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
}

function BrowseChkList(cInput, cDbf, cCdFld, cCd, cTxt, cType, cSearch, callFrom ) {
	if (cType == undefined && top.eLEFTSIDE.BaseDoc1["sch_type"] != null)
		cType = top.eLEFTSIDE.BaseDoc1["sch_type"].value;

	var cFac_cd = "";
	if (document.BaseDoc["cFac_cd"] != null)
		cFac_cd = document.BaseDoc["cFac_Cd"].value;
    
		CodeObj = cInput;
		if (trim(cCdFld).length > 0) {
			TxtObj = cCdFld;
		} else {
			TxtObj = null;
		}
	
		var ldDate = new Date();																																											
		var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));
		BrowseDoc = window.open("chkListBrowseTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&type="+cType+"&facCode="+cFac_cd+"&callFrom="+callFrom,
		Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
}

// $ST11
function BrowsePopChkList(cInput, cDbf, cCdFld, cCd, cTxt, cType, cSearch ) {

    var cFac_cd = document.BaseDoc.cFac_Cd.value  ;
    var cL_Admit = document.BaseDoc['#l_admit'].value;
		CodeObj = cInput;
		if (trim(cCdFld).length > 0) {
			TxtObj = cCdFld;
		} else {
			TxtObj = null;
		}
	
		var ldDate = new Date();																																											
		var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));
		BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&type="+cType+"&facCode="+cFac_cd+"&l_admit="+cL_Admit+"&popUpType=ADMIT",
		Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
}

function BrowseList2(cInput, cDbf, cCdFld, cCd, cTxt, cFiltFld, cFiltValFld, cboth, InSearch, InVal)
/*BrowseList2('#field_desc',cfield_table,'cfield_name','field_name','field_desc',' ',' ','false',' ',' ') ;*/
{
	if (BrowseDoc != null) {  //$MM6A
	  if(!BrowseDoc.closed) { //$MM6A
	    BrowseDoc.close()     //$MM6A
	  }
	}
	CodeObj = cInput;
	TxtObj = cCdFld;
	var cFiltVal = " " ;
    if ( cFiltFld != " " ) {
		cFiltVal=document.BaseDoc[cFiltValFld].value;
	}	
	BrowseDoc = window.open("rsfldbrw2.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&cFiltFld="+cFiltFld+"&cFiltVal="+cFiltVal+"&both="+cboth+"&InSearch="+InSearch+"&InVal="+InVal,"GenBrowser","width=300, height=500,scrollbars=yes,resizable=yes");
	//pmslbrow2.asp
}


//       browselist('text field name','table name','hidden CD field name',’table CD field name’,'table TXT field name',this.value)
/*Last parameter used as Title of the pop-up window for echo-connect
Also used to pass call class to tblbrowser in case of eyecom.        */
					
function BrowseList(cInput, cDbf, cCdFld, cCd, cTxt, cSearch, cCVO, cFilterCd, cFilterTxt, callFrom, flags,title_text )
 {
   CodeObj = cInput;  // $SP3C - moved this line to here
   
   if (cDbf == "RS_FLDFLT") // $ST8
   {
	var sch_type = document.BaseDoc['sch_type'].value;
   }
   
   if ( callFrom == "DEPARTMENT" ) { //$SC6A
     if ( cSearch != "undefined"  && cSearch != null && trim(cSearch).length != 0) {
        cSearch = "WWNOT_EMPTY" ; //Handle problem in phy_facility.asp in department field, this needs because if none empty the browser should list all items but it will not if the cText <> "", maybe this has behaved as the other pages 's need
     }
   }
  var OrgCd = "";
  if (cDbf == "V2ZZZSECFILE" ) { //$SC9A
     if ( document.BaseDoc['#nOrgCd'].value == "" || document.BaseDoc['#nOrgCd'].value == "undefined"  ) { //$SC9A
        OrgCd = null; 
     } else {
        OrgCd =  document.BaseDoc['#nOrgCd'].value; 
     }  
  }
	if (flags!=undefined && flags.indexOf("dotnetname")>-1)  // PIT 17551
	{
		for (i=0; i<document.BaseDoc.elements.length; i++ )
		{
			s = document.BaseDoc.elements[i].id+"_";
			if (s.indexOf("_"+cInput+"_")>-1
					&& s.indexOf("_Existing_")==-1 			// PIT 17831
					&& s.indexOf("_btnRemoveMap_")==-1 )	// PIT 18066
			{
				cInput = document.BaseDoc.elements[i].id;
			    CodeObj = cInput;  
			}
		}
	}
	

   //if (flags==undefined || flags.indexOf("noclear")==-1)  // PIT 17551
   //{
     //document.BaseDoc[cInput].value = "";  
   //} 

	if (BrowseDoc != null) {  //$MM6A
	  if(!BrowseDoc.closed) { //$MM6A
	    BrowseDoc.close()     //$MM6A
	  }
	}
   
	if (trim(cCdFld).length > 0) {
		TxtObj = cCdFld;
	} else {
		TxtObj = null;
	}
	if ((cDbf == "REC_ARR" || cDbf == "REC_ARR2") && trim(cFilterCd).length > 0 ) {  //$MM17A //$MM18A
		// place holder
	} else {   //$MM17A
		 if ( cDbf == "V2ZZZSECFILE" ) { //$SC9A
			if (cSearch == "FROMBUTTON" )
			    {
			      cSearch = "";
			    } else {
			      if (typeof(cSearch) != 'undefined' && cSearch != null && trim(cSearch).length == 0) 
			         {
			         //UpdFldSecFile('', '', true ); 
			         AskToUpdate('','', OrgCd);
			         return;
			         }
			    }  
	     } else {
	    	  if (typeof(cSearch) != 'undefined' && cSearch != null && trim(cSearch).length == 0)
			  	 {
				  UpdFld('','');
				  return;
				 }
         }	 
		if (typeof(cSearch) != 'undefined' && cSearch != null && trim(cSearch) == 'xxx')
			{
			cSearch = '';
			}
	}
	if ((cDbf == "DRNAME")&&(title_text!="eyecom")) {
		   BrowseDoc = window.open("../vfpcgi.exe?IDCFile=DrnmBrw.idc", "GenBrowser","top=10,left=10,width=500, height=300,scrollbars=yes");
	} else if (cDbf.toUpperCase() == "RS_FIELD") {
		BrowseDoc = window.open("rsfldbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&Frm=RS_FIELD"+"&cFcd="+ escape(cFilterCd)+"&cFtxt="+ escape(cFilterTxt)+"&callFrm="+callFrom, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf.toUpperCase() == "RSFIELDI") {
		BrowseDoc = window.open("rsfieldibrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&Frm=RS_FIELD"+"&cFcd="+ escape(cFilterCd)+"&cFtxt="+ escape(cFilterTxt)+"&callFrm="+callFrom, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf.toUpperCase() == "RSFIELDL") {
		BrowseDoc = window.open("rsfldbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf.toUpperCase() == "RSFIELDS") {
		BrowseDoc = window.open("rsfldsbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf == "RS_FIELDL") {
		BrowseDoc = window.open("rsfldbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf == "RS_FLDFLT") {
		BrowseDoc = window.open("rsfldfbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&sch_type="+sch_type + "&masterDbf=" + flags,  // $ST8
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf == "RS_FLDSRT") {
		BrowseDoc = window.open("rsfldsbrw.asp?InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch, 
			"GenBrowser","top=10,left=10,width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (cDbf == "CHKLIST") { //$JA2
		BrowseChkList(cInput, cDbf, cCdFld, cCd, cTxt, cFilterTxt, cSearch); //$JA2
	} else if (cDbf == "SYSLOGIN") { //start $EC1
		var ldDate = new Date();																																												//$JE1A
		var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));	//$JE1A
		if ( callFrom == "GROUP" ) { 
		  BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
			+"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
			+"&CodeObj="+escape(CodeObj)+"&type=group&callclass="+title_text,
			Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
		}
		else if ( callFrom == "USER" ) { //$EC3
		  BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
			+"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
			+"&CodeObj="+escape(CodeObj)+"&type=user&callclass="+title_text,
			Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
		}  //End $EC1	
		else {  //$EC2
		  var ldDate = new Date();																																												//$JE1A
		  var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));	//$JE1A
		  // $SP3C - added CodeObj parameter
		  BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
			  +"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
			  +"&CodeObj="+escape(CodeObj)+"&type=both&call_class="+title_text ,
			  Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); //$JE1C,JE2C		
		
		}		
//	} else if (cDbf == "proc_tab") {
//		BrowseDoc = window.open("PROCTop.asp?dbf_name=PROC_TAB&InCode="+cCd+"&InText="+cTxt, 
//			"GenBrowser2","top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes");
	} else {
		var ldDate = new Date();																																												//$JE1A
		var Browsername = "GenB" + (new String(ldDate.getDate()))+(new String(ldDate.getHours()))+(new String(ldDate.getMinutes()))+(new String(ldDate.getSeconds()))+(new String(ldDate.getMilliseconds()));	//$JE1A
		// $SP3C - added CodeObj parameter

		if (flags!=undefined && flags.indexOf("modal")>-1) { // PIT 18066
			BrowseDoc = window.showModalDialog(
				"CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
				+"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
				+"&CodeObj="+escape(CodeObj) + "&OrgCd="+OrgCd + "&callFrom="+callFrom+ "&title_text="+title_text,  
				self,"center:yes;dialogWidth:550px;dialogHeight:500px;scrollbars:yes;resizable:no;help:no"); //$JE1C,JE2C,$SC9A
		} else if ( (typeof(flags)!='undefined') && (flags.indexOf("faceditmode")>-1) ) {	// $JC3
			flags = flags.substr(12);
			BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
				+"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
				+"&CodeObj="+escape(CodeObj) + "&OrgCd="+OrgCd + "&callFrom="+callFrom+"&callclass="+title_text
				+"&facEditMode="+flags,  
				Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); 
		} else {
			BrowseDoc = window.open("CTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt
				+"&InSearch="+cSearch+"&cCVO="+cCVO+"&FilterCode="+cFilterCd+"&FilterText="+cFilterTxt
				+"&CodeObj="+escape(CodeObj) + "&OrgCd="+OrgCd + "&callFrom="+callFrom+"&callclass="+title_text,  
				Browsername,"top=10,left=10,width=550, height=500,scrollbars=yes,resizable=yes"); //$JE1C,JE2C,$SC9A
		}			
	} 

 }




function AskToUpdate(cd, txt, cOrgCd) //$SC9A
{
  	var ldepart = false ;
    var cPrompt = "Do you want to automatically create a deparment history record?" ;  	
    if ( cOrgCd != "" ) {
   	      ldepart = VBConfirm(cPrompt, 4, "Department History"," "," ");
   	      
   	}   
   	UpdFldSecFile(cd,txt,ldepart); // for department history in facility screen
}

function BrowseTblMaint(cInput, cDbf, cCdFld, cCd, cTxt, cSearch, cCVO)
 { 	CodeObj = cInput;
	if (trim(cCdFld).length > 0) {
		TxtObj = cCdFld;
	} else {
		TxtObj = null;
	}

	if (typeof(cSearch) != 'undefined' && trim(cSearch).length == 0)
		{
		UpdFld('','');
		return;
		}

	if (typeof(cSearch) != 'undefined' && trim(cSearch) == 'xxx')
		{
		cSearch = '';
		}

 BrowseDoc = new window.open("TMTop.asp?dbf_name="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&cCVO="+cCVO,
			"GenBrowser","width=650, height=600,scrollbars=yes,resizable=yes");
	
 }

function BrowseMark(cInput, cDbf, cCd, cTxt, cSearch, cFullName,cLetterType)
 {
	CodeObj = cInput;
	if (event.srcElement.type != 'button' && typeof(cSearch) != 'undefined' && trim(cSearch) != null && cSearch.length == 0) //$JA1 
	{
		TxtObj = CodeObj;
		CodeObj = '#' + CodeObj;
		if (document.BaseDoc[TxtObj] != null && document.BaseDoc[CodeObj] != null)
			UpdFld('', '');
		return;
	}
	if ((trim(cDbf).toUpperCase() == "SCHOOL") || (trim(cDbf).toUpperCase() == "HOSPITAL")) {
		BrowseDoc = window.open("hospmark.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch,"GenBrowser","width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (trim(cDbf).toUpperCase() == "DRNAME") {
		BrowseDoc = window.open("SuperDuperMulti_frames.asp?InSearch="+cSearch,"DRPICKER","top=50,left=100,width=550,height=450,resizable=yes,toolbar=no");
	} else if (trim(cDbf).toUpperCase() == "PVITEM"){
		BrowseDoc = window.open("FilterTop.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch,"GenBrowser","width=500, height=500,scrollbars=yes,resizable=yes");
	} else {
		BrowseDoc = window.open("mslmarktop.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&FullName="+cFullName+"&LetterType="+cLetterType,"GenBrowser","width=600, height=500,scrollbars=yes,resizable=yes");
	}
 }
 
 function BrowseMark2(cInput, cDbf, cCd, cTxt, cSearch, cFullName, cMasterDbf,help_index) // $ST10
 {
	CodeObj = cInput;
	if ((trim(cDbf).toUpperCase() == "SCHOOL") || (trim(cDbf).toUpperCase() == "HOSPITAL")) {
		BrowseDoc = window.open("hospmark.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch,"GenBrowser","width=500, height=500,scrollbars=yes,resizable=yes");
	} else if (trim(cDbf).toUpperCase() == "DRNAME") {
		BrowseDoc = window.open("SuperDuperMulti_frames.asp?InSearch="+cSearch,"DRPICKER","top=50,left=100,width=550,height=450,resizable=yes,toolbar=no");
	} else if (trim(cDbf).toUpperCase() == "PVITEM"){
		BrowseDoc = window.open("FilterTop.asp?dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch,"GenBrowser","width=500, height=500,scrollbars=yes,resizable=yes");
	} else {
	cTxt =  cTxt.replace(/\+/g,"%2b");
	cTxt =  cTxt.replace(/\'/g,"%27");
	BrowseDoc = window.open("mslmarktop.asp?help_index="+help_index+"&dbfname="+cDbf+"&InCode="+cCd+"&InText="+cTxt+"&InSearch="+cSearch+"&FullName="+cFullName+"&masterdbf="+cMasterDbf,"GenBrowser","width=600, height=500,scrollbars=yes,resizable=yes");
	}
 }


function getDateudf(d1, naddday ) {
	var cDte 
	cDte = d1.getDate() + naddday ;
	cDte = (d1.getMonth()+1)+"/"+cDte+"/"+d1.getYear();   		
    return cDte;
}

function jtrim(inStr)
	{
		var lcStr = new String(inStr);
		var lnlen = lcStr.length-1;
		var lFnd = false;
		while (lnlen > -1) {
			if (lcStr.substr(lnlen,1) != " ") {
				lcStr = lcStr.substr(0,lnlen+1);
				lFnd = true;
				break;
			}
			lnlen--;
		}
		if (!lFnd) {
			lcStr = " ";
		}
		return lcStr;
}

function BrowseCols(cInput, cDbf, cCdFld, cCd, cTxt, cSearch, cFields, cString)
 {
 	if (BrowseDoc != null) {  //$MM6A
	  if(!BrowseDoc.closed) { //$MM6A
	    BrowseDoc.close()     //$MM6A
	  }
	}
	
	CodeObj = cInput;
	TxtObj = cCdFld;
	BrowseDoc = window.open("colbrow.asp?dbfname="+cDbf+"&InCode="+cCd+"&Srchtxt="+cString+"&SelectFields="+cFields+"&InText="+cTxt+"&InSearch="+cSearch,"GenBrowser","width=300, height=500,scrollbars=yes,resizable=yes");
 }

function UpdMark(cVal)
 {
	document.BaseDoc[CodeObj].focus();
	document.BaseDoc[CodeObj].value = cVal;
 }

function UpdFld(cVal,cTxt)
 {
// alert(CodeObj);
	cVal = unescape(cVal); //$MM
	
	if (cVal.length == 0 && TxtObj == "citem_text") { //$MM12A
		cVal = cTxt; 
	} 
	
	if (TxtObj != null && TxtObj.length > 0) {
		document.BaseDoc[TxtObj].value = cVal;
	} else {
		cTxt = cVal;
	}
	
	// document.BaseDoc[CodeObj].focus();
	
	if (CodeObj.toUpperCase() == '#ASPTCODE') // $ST4
	{	document.BaseDoc[CodeObj].value = cVal;
		document.all.carecode.src="patient_carecode_edit.asp?cd="+cVal+"&link="+cTxt;	
	}
	else 
	{	document.BaseDoc[CodeObj].focus(); //$KS1
		if (CodeObj.toUpperCase() == 'CCD' || CodeObj.toUpperCase() == 'CSTATE' || CodeObj.toUpperCase() == 'CDFSTATE'  || CodeObj.toUpperCase() == 'CCC_STATE') 
		{   
			document.BaseDoc[CodeObj].value = cVal;
		}
		else {
			document.BaseDoc[CodeObj].value = cTxt;
		}
	}
	if (typeof(UpdateVariable) == 'function') {
		UpdateVariable();
	}
	
	var loc = new String(self.location.href);
	if(loc.toLowerCase().indexOf("phy_educate_edit")>0 || loc.toLowerCase().indexOf("phy_carry_edit")>0 || loc.toLowerCase().indexOf("phy_train_edit")>0)
	{	
		fix(CodeObj);
	}
 }
 
 

function ChkDateInput(oObj, event) {//prevent user from typing anything but below values

	var key = (window.event) ? event.keyCode : event.which;
	if ((String.fromCharCode(key) == '0') || 
		(String.fromCharCode(key) == '1') || 
		(String.fromCharCode(key) == '2') || 
		(String.fromCharCode(key) == '3') || 
		(String.fromCharCode(key) == '4') ||
		(String.fromCharCode(key) == '5') || 
		(String.fromCharCode(key) == '6') || 
		(String.fromCharCode(key) == '7') || 
		(String.fromCharCode(key) == '8') ||
		(String.fromCharCode(key) == '9'))
	{
		if ((oObj.value.length == 2) || (oObj.value.length == 5)) {
			oObj.value = oObj.value + '/'
		}
		if (oObj.value=="  /  /  ") {
			oObj.value = ''
		}
	} else if(!(
		(key == null) ||
		(key == 0) ||
		(key == 8) ||
		(key == 9) ||
		(key == 13) ||
		(key == 27))){
		try{
			event.returnValue=false;
		}
		catch(Error)
		{
			event.preventDefault();
		}
	}
}

//$MM15A
function ChkAlphaNumInput(oObj) {
	if ((event.keyCode > 47 && event.keyCode < 58) || (event.keyCode > 96 && event.keyCode < 123)) 
	{
	  //Allow 1 to 10 and a to Z
	} else {
	  event.returnValue=false;
	}
}

// $JB2
function ChkIntInput(oObj) {
	if (event.keyCode > 47 && event.keyCode < 58)
	{
	  //Allow 1 to 10
	} else {
	  event.returnValue=false;
	}
}

//$MM3
function ChkNumericInput(oObj, event) { //prevent user from typing anything but below values

	var key = (window.event) ? event.keyCode : event.which;	
	if ((String.fromCharCode(key) == '0') || 
		(String.fromCharCode(key) == '1') || 
		(String.fromCharCode(key) == '2') || 
		(String.fromCharCode(key) == '3') || 
		(String.fromCharCode(key) == '4') ||
		(String.fromCharCode(key) == '5') || 
		(String.fromCharCode(key) == '6') || 
		(String.fromCharCode(key) == '7') || 
		(String.fromCharCode(key) == '8') ||
		(String.fromCharCode(key) == '9') ||
        (key == 46) ||
        (key == null) ||
        (key == 0) ||
        (key == 8) ||
        (key == 9) ||
        (key == 13) ||
        (key == 27)) 
	{
        //Numeric data OK
	} else {
		if(window.event)
		{
			event.returnValue=false;
		}
		else
		{
			event.preventDefault();
		}
	}
}

//$MT1 - added "alertnset" paremeter with following valid values:
//		 true, false, 'true', 'false'
//       Default value is true .
//		 If value is false, do NOT pop up an alert and do NOT modify the "myDate" object.
function ChkDateValid(myDate, alertnset, event)
{
	if(alertnset==undefined || alertnset==null)
	{
		alertnset=true;
	}
	
	var alertandset = String(alertnset).toLowerCase();
	
	var dte = new String(myDate.value);
	if (dte == "")
		return;

	var valid = true;
	var dteArr = dte.split("/");
	
	if (dteArr.length != 3)
	{
		valid = false;
	}
	else
	{
		var mo = parseInt(dteArr[0], 10);
		if (isNaN(mo) || mo < 1 || mo > 12) // is month valid
			valid = false;
			
		var dt = parseInt(dteArr[1], 10);
		if (valid && (isNaN(dt) || dt < 1 || dt > 31)) // is day of month valid (numbers invalid for a particular month will be handled by javascript date object)
			valid = false;
			
		var yr = parseInt(dteArr[2], 10);
		if (valid && dteArr[2].length == 2) // if two-digit year, prefix it with 20
			dteArr[2] = "20" + dteArr[2];
		
		yr = parseInt(dteArr[2], 10);
		if (valid && (isNaN(yr) || yr < 1800 || yr > 3000)) // is year in reasonable range
			valid = false;
	}	

	if(alertandset=='true')
	{	
		if (valid) // reformat date using mm/dd/yyyy
		{
			var fmtDate = new Date(dteArr.toString().replace(/,/g, "/"));
			dte = "";
			if ((fmtDate.getMonth() + 1) < 10)
				dte += "0";
			dte += (fmtDate.getMonth() + 1).toString() + "/";
		
			if (fmtDate.getDate() < 10)
				dte += "0";
			dte += fmtDate.getDate() + "/" + fmtDate.getFullYear();
		
			myDate.value = dte;
		}
		else // clear date field and alert user
		{
			alert("Invalid Date");
			myDate.value = "";
			try{
				event.returnValue = false;
			}
			catch(Error)
			{
				event.preventDefault();
			}
			myDate.focus();
		}
	}
	
	return valid;

}

function TimeFix(time_obj,fldName){ //$MM10
  
	var S_time = trim(time_obj.value);
	var H_temp_S = "";
	var M_temp_S = "";
	var flag_AM_PM = 'N';

	if(S_time.indexOf("PM") != -1) {
		S_time = trim(S_time.substr(0,S_time.indexOf("PM")));
		flag_AM_PM = 'Y';
		//alert(S_time);		
	}

	if(S_time.length == 4 || S_time.length == 5) {
		if(S_time.indexOf(":") != -1 && S_time.indexOf(":") < 3) {
			if(S_time.indexOf(":") == 1) {
				H_temp_S = "0" + S_time.substr(0,1);		    
			} else {
				H_temp_S = S_time.substr(0,2);	
			}
			var S_time2 = S_time.substr(S_time.indexOf(":")+1);
			if(S_time.indexOf(":") != -1 && S_time2.length < 3) {
				if(S_time2.length == 1) {
					M_temp_S = "0" + S_time2.substr(0,1);		    
				} else {
					M_temp_S = S_time2.substr(0,2);	
				}
			} else {
			  alert("Error: Incorrect time format.");
			  time_obj.value = '';
			  document.BaseDoc['#cTime'].focus();
			}			
		} else {
		  alert("Error: Incorrect time format.");
		  time_obj.value = '';
		  document.BaseDoc['#cTime'].focus();		  
		}
	} else {
	  alert("Error: Incorrect length in time field.");
	  time_obj.value = '';
	  document.BaseDoc['#cTime'].focus();	  
	}

	if(time_obj.value.length > 0) {
		time_obj.value = H_temp_S +":"+ M_temp_S;
		if(flag_AM_PM == 'Y') {
			time_obj.value = time_obj.value + ' PM'
		}

		if((time_obj.value.length == 4 || time_obj.value.length == 5) && time_obj.value.indexOf(":") != "-1"){
			time_obj.value = time_obj.value + ' AM';										
		}
	}
}

function ChkNumEntryOnly(thisvalue, docField)  {
	var nNum ;
	var lok = true ;
	var i ;

	i = 0 ;
	while ( i <= thisvalue.length && lok == true ) {
		nNum = new  Number( thisvalue.substr( i,1) ) ;
		if ( !(nNum >= 0 && nNum <= 9 ) ) {
			alert("Please enter a valid number");
			document.BaseDoc[docField].focus() ;
			lok = false ;
   		}  
		i++ ;  
	}//while
	return lok ;
}

//$MT2 - Added following parameters:
//		a.)  "alertnset" - default is true .
//		      valid values:  true, false, 'true', 'false'.
//            if it is false, do NOT pop up alert message and do NOT modify the "time_obj" obj. 
//		b.)  "hr24fmat" - default is 'false'.  Allows for setting the desired format without having to have a document form with a #HOUR24 field.
//		      valid values:  true, false, 'true', 'false'
function ChkTimeFormat(time_obj, alertnset, hr24fmat)  //$SC7
{
	var lhour24;
	if(hr24fmat==undefined || hr24fmat==null)
	{
		if(document.BaseDoc['#HOUR24']==undefined || document.BaseDoc['#HOUR24']==null)
		{
			lhour24 = 'false';
		}
		else
		{
			lhour24 = document.BaseDoc['#HOUR24'].value; 
		}
	}
	else
	{
		lhour24 = String(hr24fmat).toLowerCase();
	}
	
	if(alertnset==undefined || alertnset==null)
	{
		alertnset=true;
	}
	
	var alertandset = String(alertnset).toLowerCase();
		
  
   //var lhour24 = document.BaseDoc['#HOUR24'].value; 
   var theTime = new String( time_obj.value );
   var orgTime = time_obj.value;
   var lok = false;
   var nNum;
   var i;
   var nHr, nMin, nSec;  
   var docField = time_obj.name;
   var nLen;
   var amPm;
   var nPos;
   var ex;
 	 
 	 amPm = "";
     if( trim(theTime) == "" ) 
     {
        return lok;
     }
   	 nHr = "00";
	 nMin = "00";
	 theTime = theTime.toUpperCase();
  	 i = 0 ;
	
	 if( theTime.lastIndexOf("AM") > -1 ||  theTime.lastIndexOf("PM") > -1 ) 
	 {
	    if (lhour24 == 'true') {
		  if(alertandset=='true')
		  {
			alert("Invalid Military Time format!");
			time_obj.value = "";
			time_obj.focus();
		  }
	      lok = false;
	      return lok; 
	    }  
	 }
	
	 if( theTime.lastIndexOf("AM") > -1)
	 { 
	    theTime = theTime.substr(0, theTime.lastIndexOf("AM"));
	    amPm = "AM";
	 } 
	 if( theTime.lastIndexOf("PM") > -1)
	 { 
	    theTime = theTime.substr(0, theTime.lastIndexOf("PM"));
	    amPm = "PM";
	 }
	 theTime = trim(theTime);
	
     if ( theTime.length == 1 )
     {
        //alert("1" + theTime );
       	nNum = new Number(theTime);
	    if ( nNum >= 0 && nNum <=9 ) 
	    {
		   nHr = theTime;
		   lok = true;
		}
     } 
     
     if ( theTime.length == 2 )
     {
        nNum = new Number(theTime);
       	if ( nNum >= 0 && nNum <=24 ) 
	    {
		   nHr = theTime;
		   lok = true;
		}   
     }
     if (theTime.length == 3)  //$SC8A
     {
        nPos = theTime.indexOf(":");
        if ( nPos>-1 )
        {         
          nHr = theTime.substr(0, nPos);
          nMin = theTime.substr(nPos + 1); //add 1 to : character
        } else {
	        nHr = theTime.substr(0,1);
            nMin = theTime.substr(1,2); 
	   }
          if ( ( Number(nHr) >= 0 && Number(nHr) <=24 ) && ( Number(nMin) >= 0 && Number(nMin) < 60 ) ) 
	       {
		      lok = true;
		   }   
	 } // thetime.length == 3
     if (theTime.length >= 4)
     {
        nPos = theTime.indexOf(":");
        if ( nPos>-1 )
        {         
          nHr = theTime.substr(0, nPos);
          nMin = theTime.substr(nPos + 1); //add 1 to : character
        } else { 
			nHr = theTime.substr(0,2);
            nMin = theTime.substr(2,2); //
	    }
         
       	  if ( ( Number(nHr) >= 0 && Number(nHr) <=24 ) && ( Number(nMin) >= 0 && Number(nMin) <=59 ) ) 
	       {
		      lok = true;
		   }   
	 }
     if ( lok == false )  //still ok so far?
     {
		if(alertandset=='true')
		{
         alert("Invalid Time Entry!");   
         //document.BaseDoc[docField].focus();
         
         time_obj.value="";  //$RS3
         time_obj.focus();
        }
     } else {
        if( lhour24 == 'false' )
         {
           if( Number(nHr) >= 13 ) 
           {
              lok = false;
              if(alertandset=='true')
              {
				alert("Invalid entry for AM/PM time!");
				document.BaseDoc[docField].focus();
				time_obj.value="";  //$RS3
				time_obj.focus();
			  }
		   }
		 }
     }		 
     var NewTime ;
     if (new Number(nMin) == 0) 
     {
        nMin = "00";
     }   
     
     if ( Number(nHr)==24 ) 
	  {
		NewTime = "00:00";
	  } else {  
		NewTime = nHr + ":" + nMin ;
	 }
      
     if( lok == true ) // if ok to continue?
     {
       // now format the time
       if( lhour24 == 'false' )
       {
          if( amPm != "" )
          {     
			  NewTime = NewTime + " " + amPm;
          } else {
			 if( Number(nHr) <= 11 ) // assum not using 12am which is midnight, but also allow to enter midnight time manually so this should be ok
			 { 
			    NewTime = NewTime + " AM";
		 	 } else {
			    NewTime = NewTime + " PM";
			 }  
	 
	      }//if entry already has am/pm		  
       }//lhour24
       if(alertandset=='true')
       {
		  document.BaseDoc[docField].value = NewTime;
	   }
	   
     }// still ok ?
     
    return lok ;
}

function ChkValidNumber(thisvalue, docField, cNegative)  {
	var nNum ;
	var lok = true ;
	var i ;
	if (thisvalue == "" || thisvalue == " " ) {
		document.BaseDoc[docField].value = "0.00" ;
		return lok ;
	}
 
	i = 0 ;
	while ( i <= thisvalue.length && lok == true ) {
 
		nNum = new  Number( thisvalue.substr( i,1) ) ;
		//alert("num !"+nNum) ;
		//check for decimal 
		if (thisvalue.substr( i,1) == "."  ) {
			lok = true ;
		} else {   
			//check for ok to have negative number
			if ( thisvalue.substr( i,1)== "-" ) {
				if ( cNegative == "FALSE" ) {
					alert("Negative number is not allowed in this entry!") ;
					document.BaseDoc[docField].focus() ;
			     
					lok = false ;
				}   
			} else { 
				// check for number only
				if ( !(nNum >= 0 && nNum <= 9 ) ) {
					alert("Please enter a valid number") ;
					document.BaseDoc[docField].focus() ;
					lok = false ;
		  		}  
			}
		}	 
		i++ ;  
	}			//while
	if ( !(thisvalue.indexOf(".") >-1 ) && lok == true ) {
		document.BaseDoc[docField].value = thisvalue +".00" ;
	}      
  
	return lok ;
}
  

function updateValue(nme,val) {						// $JE3A
	document.BaseDoc[nme].value = val;	
} 

function ChkPhoneInput(oObj, event) {
	var key = (window.event) ? event.keyCode : event.which;
	if ((String.fromCharCode(key) == '0') || 
		(String.fromCharCode(key) == '1') || 
		(String.fromCharCode(key) == '2') || 
		(String.fromCharCode(key) == '3') || 
		(String.fromCharCode(key) == '4') ||
		(String.fromCharCode(key) == '5') || 
		(String.fromCharCode(key) == '6') || 
		(String.fromCharCode(key) == '7') || 
		(String.fromCharCode(key) == '8') ||
		(String.fromCharCode(key) == '9'))
	{

		if (oObj.value.length == 1) {
			if (parens1 != 1) {
			oObj.value = '(' + oObj.value;
			}
		parens1 = 0;
		}
		else if (oObj.value.length == 4) {
			if (parens2 != 1) {
				oObj.value = oObj.value + ') ';
			}
			parens2 = 0;
		}
		else if (oObj.value.length == 6 || oObj.value.length == 2) {
		parens2 = 0;
		}
		else if (oObj.value.length == 9) {
			oObj.value = oObj.value + '-';
		}
		else if (oObj.value.length > 14) {
			oObj.value = '';
		}
		else if (oObj.value.length == 5 && parens2 == 1) {
			oObj.value = oObj.value + ' ';
			parens2 = 0;
		}
	} 
	else if (String.fromCharCode(key) == '(' && oObj.value.length == 0) {
		parens1 = 1;
	}
	else if (String.fromCharCode(key) == ')' && oObj.value.length == 4) {
		parens2 = 1;
	}
	else if (String.fromCharCode(key) == ' ' && oObj.value.length == 5) {
	return;
	}
	else if (String.fromCharCode(key) == '-' && oObj.value.length == 9) {
	return;
	}
	else if (!window.event && key == 0)
	{
		return;
	}
	else if(!(
		(key == null) ||
		(key == 0) ||
		(key == 8) ||
		(key == 9) ||
		(key == 13) ||
		(key == 27))){
		if(window.event)
		{
			event.returnValue=false;
		}
		else
		{
			event.preventDefault();
		}
	}
}
function ValidateZip (zip) {
   if (((zip.length == 5) && (zip.indexOf('-') == -1) && (zip.indexOf(' ') == -1)) || 
      ((zip.length == 10) && (zip.indexOf('-') == 5)) ||
      ((zip.length == 6) && (zip.indexOf('-') == -1) && (zip.indexOf(' ') == -1)) ||
      ((zip.length == 7) && (zip.indexOf('-') == -1) && (zip.indexOf(' ') == 3)))
   {
      return true;
   }
   else
   {
      return false;
   }
}

function ChkZipInput(oObj) {
	if ((String.fromCharCode(event.keyCode) == '0') || 
		(String.fromCharCode(event.keyCode) == '1') || 
		(String.fromCharCode(event.keyCode) == '2') || 
		(String.fromCharCode(event.keyCode) == '3') || 
		(String.fromCharCode(event.keyCode) == '4') ||
		(String.fromCharCode(event.keyCode) == '5') || 
		(String.fromCharCode(event.keyCode) == '6') ||
		 
		(String.fromCharCode(event.keyCode) == '7') || 
		(String.fromCharCode(event.keyCode) == '8') ||
		((String.fromCharCode(event.keyCode) == '-') && (oObj.value.length == 5)) ||
		((String.fromCharCode(event.keyCode) == ' ') && (oObj.value.length == 3)) ||
		((event.keyCode > 96) && (event.keyCode < 123) && ((oObj.value.length == 0) || (oObj.value.length == 2) || (oObj.value.length == 4) || (oObj.value.length == 5))) ||
		((event.keyCode > 64) && (event.keyCode < 91) && ((oObj.value.length == 0) || (oObj.value.length == 2) || (oObj.value.length == 4) || (oObj.value.length == 5))) ||		
		(String.fromCharCode(event.keyCode) == '9'))
	{
    } 
	else {
		event.returnValue=false;
	}
}

//$SC1A
function ValidateState( cState,docfield ) {
 var lok 
 var st =  cState.toUpperCase() ;
   st = trim(st) ;
   if ( st == 'CA'  || st ==  'AZ' || st ==  'AK' || st ==  'AL' || st ==  'AR' ||
        st ==  'AZ' || st ==  'CA' || st ==  'CO' || st ==  'CT' || st ==  'DC' ||
        st ==  'DE' || st ==  'FL' || st ==  'GA' || st ==  'GU' || st ==  'HI' || 
        st ==  'IA' || st ==  'ID' || st ==  'IL' || st ==  'IN' || st ==  'KS' || 
        st ==  'KY' || st ==  'LA' || st ==  'MA' || st ==  'MD' || st ==  'ME' || 
        st ==  'MI' || st ==  'MN' || st ==  'MO' || st ==  'MS' || st ==  'MT' || 
        st ==  'NC' || st ==  'ND' || st ==  'NE' || st ==  'NH' || st ==  'NJ' || 
        st ==  'NM' || st ==  'NV' || st ==  'NY' || st ==  'OH' || st ==  'OK' || 
        st ==  'OR' || st ==  'PA' || st ==  'PR' || st ==  'RI' || st ==  'SC' 
        || st ==  'SD' || st ==  'TN' || st ==  'TX' || st ==  'UT' || st ==  'VA'
        || st ==  'VI' || st ==  'VT' || st ==  'WA' || st ==  'WI' || st ==  'WY'
        || st ==  'FC' || st ==  '' || st ==  ' ' || st ==  'WV' ){
        lok == true ;
    } else {     
       	alert("Please enter a valid state code!");
		document.BaseDoc[docfield].focus();		
	}
	return lok ;
}

function EditRtf(cRTF, cRTFPATH) {
    //alert("hey");
    // Turn all of the back slashes into forward slashes.
	var cRTFNAME = trim(new String(cRTF));
    //   problems with regular expressions for literal backslash in IE5.0
    //        tried various approaches
	//	var re = new RegExp("\x5C","g");
	//	cRTFNAME = cRTFNAME.replace(re, "/");
	
	//\\HLS_SQL\Atlantic\rtf
	
	cRTFNAME = ReplaceAll(cRTFNAME, "\\", "/");
	//alert(cRTFNAME);
	//alert(cRTFPATH);
	cRTFPATH = unescape(cRTFPATH);
	//alert(cRTFPATH);
	
	// If the value in cRTFNAME is not an HTTP address or a network path,
	// then make it so by adding the RPT path to it.
    if (cRTFNAME.indexOf("//") == -1 && cRTFNAME.toUpperCase().indexOf("HTTP") == -1) {
		// Remove leading slash from RTF, if there is one.
		if (cRTFNAME.length > 0 && cRTFNAME.substr(0,1) == "/") {
			cRTFNAME = cRTFNAME.substring(1);
		}
		// Get path of RTF.
		cRTFNAME = cRTFPATH + "/" + cRTFNAME;
	}

	
	// If this is a network directory path, then turn all of the forward slashes
	// into back slashes.
    if (cRTFNAME.toUpperCase().indexOf("HTTP") == -1) {
		// Turn all of the forward slashes into back slashes.
		var re2 = new RegExp("/","g");
		cRTFNAME = cRTFNAME.replace(re2, "\\");
	}
	try {
		//alert(cRTFNAME);
		window.open(trim(cRTFNAME),'listedit','width=600,toolbar=yes,menubar=yes,height=400,scrollbars=yes,resizable=yes',true);
		window.open("VarTop.asp?InCode='+DBF_NAME+'&InText='+full_name+'", "GenBrowser","width=700, height=500,scrollbars=yes,resizable=yes");
	} catch (e) {
		alert(e.message);
	}
}

function EditRtf2(cRTFNAME) {
	window.open(trim(cRTFNAME.value),'listedit','width=600,toolbar=yes,menubar=yes,height=400,scrollbars=yes,resizable=yes',true);
	cText = Request.QueryString("INSEARCH");
	if (trim(cText) == "undefined")
		{ cText = ""; }
    Response.Write("<form name='BaseDoc1' ACTION='rsfldbrw.asp' method='GET'>");
    Response.Write("Search:");
	Response.Write("<input STYLE='font-size:10px;' TYPE='TEXT' NAME='INSEARCH' TABINDEX='1' SIZE='15' MAXSIZE='40' VALUE='" + cText + "' >");
	Response.Write("<input STYLE='font-size:10px;' TYPE='SUBMIT' NAME='btnSearch' TABINDEX='2' VALUE='GO'>");
    Response.Write("</form>");
  window.open("rsfldbrw.asp?InCode='+DBF_NAME+'&InText='+full_name+'", "GenBrowser","width=500, height=500,scrollbars=yes,resizable=yes");

}  

// $ST9 Reporter -> Chklist changes
function EditRtf3(cRTF, cRTFPATH, sch_type, DBF_NAME, full_name) {
	if (cRTF == "")
	{
		alert("No Merge RTF Name stored!");
	}
	else
	{
    // Turn all of the back slashes into forward slashes.
	var cRTFNAME = trim(new String(cRTF));
    //   problems with regular expressions for literal backslash in IE5.0
    //        tried various approaches
	//	var re = new RegExp("\x5C","g");
	//	cRTFNAME = cRTFNAME.replace(re, "/");
	
	//\\HLS_SQL\Atlantic\rtf
	
	cRTFNAME = ReplaceAll(cRTFNAME, "\\", "/");
	//alert(cRTFNAME);
	//alert(cRTFPATH);
	cRTFPATH = unescape(cRTFPATH);
	//alert(cRTFPATH);
	
	// If the value in cRTFNAME is not an HTTP address or a network path,
	// then make it so by adding the RPT path to it.
    if (cRTFNAME.indexOf("//") == -1 && cRTFNAME.toUpperCase().indexOf("HTTP") == -1) {
		// Remove leading slash from RTF, if there is one.
		if (cRTFNAME.length > 0 && cRTFNAME.substr(0,1) == "/") {
			cRTFNAME = cRTFNAME.substring(1);
		}
		// Get path of RTF.
		cRTFNAME = cRTFPATH + "/" + cRTFNAME;
	}

	
	// If this is a network directory path, then turn all of the forward slashes
	// into back slashes.
    if (cRTFNAME.toUpperCase().indexOf("HTTP") == -1) {
		// Turn all of the forward slashes into back slashes.
		var re2 = new RegExp("/","g");
		cRTFNAME = cRTFNAME.replace(re2, "\\");
	}
	try {
		
		window.open(trim(cRTFNAME),'listedit','width=600,toolbar=yes,menubar=yes,height=400,scrollbars=yes,resizable=yes',true);
		var thePage = "VarTop.asp?sch_type="+sch_type+"&InCode="+DBF_NAME+"&InText="+full_name;
		window.open(thePage, "GenBrowser","width=700, height=500,scrollbars=yes,resizable=yes");
	} catch (e) {
		alert(e.message);
	}
	}
}

function ReplaceAll(inString, oldValue, newValue) {
	var outString = "";
	for (h=0;h<inString.length;h++) {
		if (inString.substr(h,1) == oldValue) {
			outString += newValue;
		} else {
			outString += inString.substr(h,1);
		}
	}
	return outString;
}
    
//$SC?A     
function CheckRadio(oRadioBox,cDataFld, cValue)
{

	if (oRadioBox.checked) {
		document.BaseDoc[cDataFld].value = cValue ;
	} else {
		document.BaseDoc[cDataFld].value = cValue ;
	}
}

//$MM8A
//$SP1C - problems with previous code - year calc not exact
function calculateAge(docfield) {
	var cRetVar = "";
	if (trim(document.BaseDoc[docfield].value).length > 0) {    //$SP2A
		var dBirth = new Date(document.BaseDoc[docfield].value);
		var dToday = new Date();
		var nBirthMonth = dBirth.getMonth();
		var nBirthDay   = dBirth.getDate();
		var nBirthYear  = dBirth.getFullYear();
		var nTodayMonth = dToday.getMonth();
		var nTodayDay   = dToday.getDate();
		var nTodayYear  = dToday.getFullYear();
	
		if (nBirthMonth < nTodayMonth) {
			cRetVar = nTodayYear - nBirthYear;
		} else {
			if (nBirthMonth == nTodayMonth) {
				if (nBirthDay <= nTodayDay) {
					cRetVar = (nTodayYear - nBirthYear);
				} else {
					cRetVar = (nTodayYear - nBirthYear) - 1;
				}
			} else {
				cRetVar = (nTodayYear - nBirthYear) - 1;
			}
		}
	}
	document.BaseDoc['#age'].value = cRetVar ;
	return cRetVar;
}


function ValidDecNum(thisValue, nSize, docfield ) {
  var nNum ;
  var lok = true ;
  var i ;
  var amount = new String(thisValue) ;
  if (thisValue == "" || thisValue == " " ) {
     document.BaseDoc[docfield].value = "0.00" ;
  }
 i = 0 ;
 while ( i <= thisValue.length && lok == true ) {
     nNum = new  Number( thisValue.substr( i,1) ) ;
     if (thisValue.substr( i,1) == "."  ) {
        lok = true ;
     } else {   
       if ( !(nNum >= 0 && nNum <= 9 ) ) {
         lok = false ;
       }        
     }
     if ( lok == false ) {
        alert("Please enter a valid number") ;
        //document.BaseDoc.nAMOUNT.value = "" ;
     }
     i++ ;  
  }//while

 //check for max value entries
if ( lok ) { 
  nNum = thisValue ;
	if ( document.BaseDoc[docfield].value == 0 ||    document.BaseDoc[docfield].value == "" ){
	   return ;
	} else {
			if (thisValue.indexOf(".") > -1 ) {
			    nNum = thisValue.substring( 0, thisValue.indexOf(".")) ;
			    if ( nNum.length > (nSize - 3 ) ) {
			       alert("Invalid number entry.\nNumber must be up to " + (nSize - 3 ) + " digits without a decimal point.\nOr\n" + (nSize - 3 ) + " digits with a decimal point.\nExample 99999.99 "); //$MM13A
			       document.BaseDoc[docfield].focus(); 
			    }   
			} else {
			     if ( nNum.length > (nSize - 3) ) {
			       alert("Invalid number entry.\nNumber must be up to " + (nSize - 3 ) + " digits without a decimal point.\nOr\n" + (nSize - 3 ) + " digits with a decimal point.\nExample 99999.99 "); //$MM13A
			       document.BaseDoc[docfield].focus() ;
			    }
			}    
	} 
 } //lok   
}//function

function UnescapeString(){ //$SC?A
 		for (i=0;i<document.BaseDoc.length;i++) {
			switch (document.BaseDoc.elements[i].type.toUpperCase()) {
				case "TEXT":
					document.BaseDoc.elements[i].value = unescape( document.BaseDoc.elements[i].value ) ;
		 			break;
				case "TEXTAREA":
					document.BaseDoc.elements[i].value =  unescape( document.BaseDoc.elements[i].value ) ; 
		 			break;
		 	   case "HIDDEN":
					document.BaseDoc.elements[i].value =  unescape( document.BaseDoc.elements[i].value ) ; 
		 			break;
			}//switch
		}//for
 }

function UnconvertSpecChar( cString ) { //$sc15
  //cString = ReplaceAll(cString,"&lsquo") ;
 	var re1 = new RegExp("&39","g");
	cString = cString.replace(re1, "'");
	re1 = new RegExp('&quot;','g');
   	cString = cString.replace(re1, '"');
	return cString ;
}

function ChkPhoneInputNoArea(oObj) { //&JA1
	if ((String.fromCharCode(event.keyCode) == '0') || 
		(String.fromCharCode(event.keyCode) == '1') || 
		(String.fromCharCode(event.keyCode) == '2') || 
		(String.fromCharCode(event.keyCode) == '3') || 
		(String.fromCharCode(event.keyCode) == '4') ||
		(String.fromCharCode(event.keyCode) == '5') || 
		(String.fromCharCode(event.keyCode) == '6') || 
		(String.fromCharCode(event.keyCode) == '7') || 
		(String.fromCharCode(event.keyCode) == '8') ||
		(String.fromCharCode(event.keyCode) == '9'))
	{

        if (oObj.value.length == 3) {
			oObj.value = oObj.value + '-';
		}
		else if (oObj.value.length > 8) {
			oObj.value = '';
		}
	} 
	else if (String.fromCharCode(event.keyCode) == '-' && oObj.value.length == 3) {
	return;
	}
	else {
		event.returnValue=false;
	}
}

function chkExpDate(dte) //$JA3
// This function will change a date field to bold red when it is <= today, otherwise it will make it black and non-bold.
// To use it effectively, call this function from the body's onload event, and the date field's ondblclick, onfocus, and onkeyup events
// See phy_credent_edit.asp and phy_carry_edit.asp for examples.
{
	if (dte != null) // check for existence of object before attempting anything else
	{
		try // just in case some sort of invalid date or characters sneak through and cause an error...
		{
			var expDate = new Date(dte.value);
			var curDate = new Date();
			if (expDate != "Nan" && dte.value.length == 10 && expDate.valueOf() < curDate.valueOf()) //must be a valid number, field must contain 10 chars
			{
				dte.style.color = "red";
				dte.style.fontWeight = "bold";
			}
			else
			{
				dte.style.color = "black";
				dte.style.fontWeight = "normal";
			}
		}
		catch (ee) {} // do nothing if an error occurs
	}
}

function inCall() //$JA4
// This function will check the call/referal status from the call center frame, if present and return -1 if no call is started
// or the referral type if a call is started.
{
	var retVal = -1; //$JA1
	
	try // in case callcenter frame doesn't exist.
	{
		if (parent.top.cc_inside.note.tStart != null)
		{
			retVal = parent.top.cc_inside.note.ref_type;
		} 
	}
	catch(ee) {} // Do nothing if callcenter frame doesn't exist.
	
	return retVal;
}

function oXMLHttp() // $JA5
// This function will return an XmlHTTP object that can be used to hit pages without refreshing the page or using a hidden frame.
{
	var x;
	try
	{
		x = new ActiveXObject("Msxml2.XMLHTTP"); // IE (newer xml object version)
	}
	catch(e)
	{
		try
		{
			x = new ActiveXObject("Microsoft.XMLHTTP"); // IE (older xml object version)
		}
		catch(ee)
		{
			try
			{
				x = new XMLHttpRequest; // Non-IE
			}
			catch(eee)
			{
				x = null;
			}
		}
	}
	return x;
	
}


// hits a page and runs the code in "todo" after successful completion.
// the post string and todoError are optional.
//		if post is not to be used, it can be omitted or passed as null
// todoError is code that will run in the event the server returns an HTTP error message
//   if omitted, a messagebox will display containing the url, HTML error number and description.

// the oReq object is available to whatever code runs inside the "todo" and "todoError" functions;
// this object is of the type XMLHttp
function runPage(url, todo, post, todoError) 
{
	try{
		var oReq = new  XMLHttpRequest();
	}
	catch(Error){
		var oReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (post != null)
	{
		oReq.open("POST", url, true); // use asynchronous mode to prevent UI lockups
		oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	else{
		try{
		oReq.open("GET", url, true); // use asynchronous mode to prevent UI lockups		
		}
		catch(Error)
		{
			alert(Error);
		}
	}
	oReq.onreadystatechange = 
		function() {
			if(oReq.readyState == 4){
				if(oReq.status == "200")
					eval(todo);
				else{
					if (debug)
					{
						var x = window.open();
						x.document.write(oReq.responsetext);
					}
					else
					{
						if (todoError == null)
							alert("An error occurred while trying to access the URL: " + url + "\n" + oReq.status + " - " + oReq.statusText);
						else
							eval(todoError);
					}
				}
			}
		}
			
	oReq.send(post);
}

function runPageSynchro2(url, todo, post, todoError) 
{
	try{
		var oReq = new  XMLHttpRequest();
	}
	catch(Error){
		var oReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (post != null)
	{
		oReq.open("POST", url, false); // use asynchronous mode to prevent UI lockups
		oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	else{
		try{
		oReq.open("GET", url, false); // use asynchronous mode to prevent UI lockups		
		}
		catch(Error)
		{
			alert(Error);
		}
	}
	oReq.onreadystatechange = 
		function() {
			if(oReq.readyState == 4){
				if(oReq.status == "200")
					eval(todo);
				else{
					if (debug)
					{
						var x = window.open();
						x.document.write(oReq.responsetext);
					}
					else
					{
						if (todoError == null)
							alert("An error occurred while trying to access the URL: " + url + "\n" + oReq.status + " - " + oReq.statusText);
						else
							eval(todoError);
					}
				}
			}
		}
			
	oReq.send(post);
}

// hits a page in synchronous mode and returns the XMLHttp object representing the completed request.
// the post string is optional.
//		if post is not to be used, it can be omitted or passed as null
function runPageSynchro(url, post) 
{
	var oReq = oXMLHttp();
	
	if (post != null)
	{
		oReq.Open("POST", url, false); // use Synchronous mode
		oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	else
		oReq.Open("GET", url, false); // use Synchronous mode
		
	oReq.send(post);
		
	return oReq;
}

// start of custom tooltip code

var hideTimer = null;
var showTimer = null;
var opacity = 0;
var _toolTipTxt = "";
var _toolTipX = 0;
var _toolTipY = 0;
fadeSpeed = 1;
fadeStep = 10;
fadeStop = 94;

function showTTNow(txt)
{
	if (!txt)
		txt = _toolTipTxt;
	else
		_toolTipTxt = txt;
		
	if (!document.getElementById("toolTipDiv"))
	{
		// tooltip
		var oDiv = document.createElement("DIV");
		oDiv.id = "toolTipDiv";
		oDiv.style.position = "absolute";
		oDiv.style.border = "1x solid #000000";
		oDiv.style.backgroundColor = "lightyellow";
		oDiv.style.padding = "3px";
		oDiv.style.color = "black";
		oDiv.onmouseover = showTTNow;
		oDiv.onmouseout = hideTT;
		oDiv.style.display = "none";
		oDiv.style.filter = "alpha(opacity=0)";
		oDiv.style.cursor = "default";
		oDiv.style.zIndex = 500;
		document.body.appendChild(oDiv);
		
		// drop shadow
		var oDiv2 = document.createElement("DIV");
		oDiv2.id = "toolTipShadow";
		oDiv2.style.position = "absolute";
		oDiv2.style.display = "none";
		oDiv2.style.borderRight = "6px solid black";
		oDiv2.style.borderBottom = "6px solid black";
		oDiv2.style.filter = "alpha(opacity=50) blur(add=false, direction=315, strength=6)";
		oDiv2.style.zIndex = 499;
		document.body.appendChild(oDiv2);

		
	}

	var oDiv = document.getElementById("toolTipDiv");
	oDiv.style.left = _toolTipX;
	oDiv.style.top = _toolTipY;
	oDiv.innerHTML = txt;
	
	var oDiv2 = document.getElementById("toolTipShadow");
	oDiv2.style.left = _toolTipX + 5;
	oDiv2.style.top = _toolTipY + 5;
	oDiv2.style.height = oDiv.offsetHeight;
	oDiv2.style.width = oDiv.offsetWidth;

	fadeIn();

	fixToolTipPosition();

	if (hideTimer)
	{
		clearTimeout(hideTimer);
		hideTimer = null;
	}
	
	showTimer = null;
}

function hideTT(now)
{
	if (showTimer)
	{
		clearTimeout(showTimer);
		showTimer = null;
	}
	if (now)
	{
		if (document.getElementById("toolTipDiv"))
			fadeOut();
	}
	else
	{
		clearTimeout(hideTimer);
		hideTimer = setTimeout("hideTT(true);", 1000);
	}
}

function showTT(txt)
{
	if (_toolTipTxt != txt && txt != "")
	{
		_toolTipTxt = txt;
		_toolTipX = event.clientX;
		_toolTipY = event.clientY + 25 + document.body.scrollTop;
	}
	if (hideTimer)
	{
		clearTimeout(hideTimer);
		hideTimer = null;
		if (document.getElementById("toolTipDiv") && document.getElementById("toolTipDiv").style.display == "")
		{
			showTTNow();
			fixToolTipPosition();
		}
	}
	if (!showTimer)
		showTimer = setTimeout("showTTNow();", 1000);
}

function fadeIn(op)
{
	if (!op && document.getElementById("toolTipDiv").style.display == "")
	{
		fixToolTipPosition();
		return;
	}
		
	if (!op)
	{
		setTimeout("fadeIn(1);", fadeSpeed);
		document.getElementById("toolTipDiv").style.display = "";
	}
	else
	{
		document.getElementById("toolTipDiv").style.filter = "alpha(opacity=" + op + ")";
		op += fadeStep;
		if (op <= fadeStop)
			setTimeout("fadeIn(" + op + ");", fadeSpeed);
		else
		{
			var oDiv = document.getElementById("toolTipDiv");
			oDiv.style.filter = "alpha(opacity=" + fadeStop + ")";

			var oDiv2 = document.getElementById("toolTipShadow");
			oDiv2.style.height = oDiv.offsetHeight;
			oDiv2.style.width = oDiv.offsetWidth;
			oDiv2.style.display = "";
			
			fixToolTipPosition();
		}
	}
}

function fadeOut(op)
{
	
	if (!op)
	{
		setTimeout("fadeOut(" + fadeStop + ");", fadeSpeed);
		document.getElementById("toolTipShadow").style.display = "none";

	}
	else
	{
		document.getElementById("toolTipDiv").style.filter = "alpha(opacity=" + op + ")";
		op -= fadeStep;
		if (op >= 0)
			setTimeout("fadeOut(" + op + ");", fadeSpeed);
		else
		{
			document.getElementById("toolTipDiv").style.filter = "alpha(opacity=0)";
			document.getElementById("toolTipDiv").style.display = "none";
			if (!showTimer)
				_toolTipTxt = "";
		}
	}
}

function fixToolTipPosition()
{
	var oDiv = document.getElementById("toolTipDiv");
	var oDiv2 = document.getElementById("toolTipShadow");
	
	if (!oDiv || !oDiv2)
		return;
	
	var bottomEdge = document.body.clientHeight + document.body.scrollTop;
	var rightEdge = document.body.clientWidth + document.body.scrollLeft;

	// make sure it's on the screen vertically
	if (oDiv.offsetHeight + _toolTipY > bottomEdge - 5)
	{
		_toolTipY = bottomEdge - oDiv.offsetHeight - 5;
		oDiv.style.top = _toolTipY
		oDiv2.style.top = _toolTipY + 5;
	}
	
	// make sure it's on the screen horizontally.
	if (oDiv.offsetWidth + _toolTipX > rightEdge - 5)
	{
		_toolTipX = rightEdge - oDiv.offsetWidth - 5;
		oDiv.style.left = _toolTipX;
		oDiv2.style.left = _toolTipX + 5;
	}

	oDiv2.style.height = oDiv.offsetHeight;
	oDiv2.style.width = oDiv.offsetWidth;
}

// end of custom tooltip code


function ChkDecInput(oObj,dec_num,len)  //prevent user from typing anything but below values
		{
			
			if ((String.fromCharCode(event.keyCode) == '0') || 
				(String.fromCharCode(event.keyCode) == '1') || 
				(String.fromCharCode(event.keyCode) == '2') || 
				(String.fromCharCode(event.keyCode) == '3') || 
				(String.fromCharCode(event.keyCode) == '4') ||
				(String.fromCharCode(event.keyCode) == '5') || 
				(String.fromCharCode(event.keyCode) == '6') || 
				(String.fromCharCode(event.keyCode) == '7') || 
				(String.fromCharCode(event.keyCode) == '8') ||
				(String.fromCharCode(event.keyCode) == '9') ||
				(event.keyCode == 8) ||
				((event.keyCode == 46)&&(dec_num=="dec")) ||
				(event.keyCode == 37) ||
				(event.keyCode == 39) ||
				(event.keyCode == 45) ||
				(event.keyCode == 43) ||
				(event.keyCode == 190)) 
				{
					var ip = new String(oObj.value);
					var ipArr=ip.split(".");
					if ((event.keyCode==46)&&(ipArr.length==2))
						event.returnValue=false;
					if((ip.indexOf("+")>-1)||(ip.indexOf("-")>-1))
						{
						if((event.keyCode==43)||(event.keyCode==45))
							event.returnValue=false;
						}
					if (ip.length>=len)
						if((event.keyCode!=190)&&(event.keyCode!=8)&&(event.keyCode!=37)&&(event.keyCode!=39)&&(event.keyCode!=43)&&(event.keyCode!=45))
						{
						if(((ip.indexOf("+")>-1)||(ip.indexOf("-")>-1))&&(ip.length==len))
							;
						else
							event.returnValue=false;
						}
							
				} else {
					event.returnValue=false;
				}
		}
function ValidateDecInput(inputFld,ubound,lbound,decplaces)
		{	
			
			var ip = new String(inputFld.value);
			
			if (ip.indexOf(".")==0) 
				ip="0"+ip;
			if((decplaces==2)&&(ip=="")) ip="0.00";//#.## format
			if((decplaces==1)&&(ip=="")) ip="0.0"; //#.# format
			if((decplaces==0)&&(ip=="")) ip="0"; //# format
			
			var valid=true;
			
			var ipArr=ip.split(".");
				var num=new String(ipArr[0]);
								
			if (ipArr.length>1)
				var dec=new String(ipArr[1]);
			else
				{
				if (decplaces==2) 
					var dec=new String("00");
				else if(decplaces==1)
					var dec=new String("0");
				else if	(decplaces==0)
					var dec=new String("");
				}
			
			if ((decplaces==2)&&(dec.length==1)) dec+="0";
			if ((decplaces==2)&&(dec.length==0)) dec+="00";
						
			if((ip.indexOf("-")>0)||(ip.indexOf("+")>0))
				valid=false;
			if((inputFld.value>ubound)||(inputFld.value<lbound))
				valid=false;			
			if(valid==false)
			{
				alert("Invalid input value, Please enter a value between " +lbound+" and "+ubound);
				if(decplaces==2)
					inputFld.value = "0";
				else if(decplaces==1)
					inputFld.value = "0";
				else
					inputFld.value = "0";
				event.returnValue = false;
				inputFld.focus();
			}
			else
			{
				var dum=num.replace(/^0+/,"")+dec.replace(/0+$/,"");
				if(dum=="") inputFld.value="0";
				else
				{
					if(decplaces>0)
						inputFld.value=num+"."+dec;
					else
						inputFld.value=num;
				}
			}
		}
		


function checkMoney(o, includeDollarSign)
{
	var newVal = parseFloat(o.value.replace(/\$/g, "")); // convert to floating point for comparison
	
	if (isNaN(newVal)) // if blank, make it 0
		newVal = 0;
		
	if (newVal > 99999.99)
	{
		alert("Amount cannot be greater than between $99999.99");
		o.value = "";
		o.focus();
		return;
	}
	if (includeDollarSign)
		o.value = "$" + newVal.toFixed(2); // convert to monetary format
	else
		o.value = newVal.toFixed(2); // convert to monetary format
}
var eyesched;

function doIt2 (dr_id) {
    eyesched= window.open("eyeSched_top.asp?dr_id=" + dr_id, "tinyWindow", 'resizable,width=1000,height=620') 
}


/**********************************************************************************	JC2
 AutoComplete() used to create an unordered list of possible choices in word completion.
 Parameter Input: 1)elem: Test field ID.  2)hints: Array of strings, which are the folder names.
 Keyboard Input:KEYDN = scrolls down the list of words
				KEYUP = scrolls up the list of words
				TAB or ENTER = select the currently highlighted word
				ESCAPE = Remove display of word list
				
 Requirement: <div id="autohint"><ul></ul></div> below <body> tag  (positioning will place
				the <div> and <ul>s in the correct place.
			  <input type="text" name="<yourTextfieldName> id="<yourtextfieldID>" />
			  Constructed array of strings.
Example: QR_new.asp
**********************************************************************************/
function getHint(myObj)
{
	if (myObj.highlighted > -1)
	{
		myObj.elem.value = myObj.choices[myObj.highlighted];
		hideDiv(myObj);
		// Put focus back to the correct field
		setTimeout("document.getElementById('" + myObj.elem.id + "').focus()",0);
	}
}
	
function hideDiv(myObj)
{
	myObj.div.style.display = 'none';
	myObj.highlighted = -1;
}
		
		
function showHighlight(myObj)
{
	var uoList = myObj.div.getElementsByTagName('LI');	
	for (i in uoList)
	{
		var li = uoList[i];
		if (myObj.highlighted == i)
			li.className = "selected";
		else
			li.className = "";
	}
}

function placeDiv(myObj)
{
	var e = myObj.elem;		
	var x = 0;
	var y = e.offsetHeight;
	//Walk DOM, add up all offset positions.
	while (e.offsetParent && e.tagName.toUpperCase() != 'BODY')
	{
		x += e.offsetLeft;
		y += e.offsetTop;
		e = e.offsetParent;
	}

	x += e.offsetLeft;
	y += e.offsetTop;
	myObj.div.style.left = x + 'px';
	myObj.div.style.top = y + 'px';	
}

function getChoices(myObj)
{
	myObj.choices = new Array();
	for (i in myObj.hints) 
	{
		var hint = myObj.hints[i];
		// get all word that begin with the inputString
		if(hint.toLowerCase().indexOf(myObj.inputString.toLowerCase()) == "0")
		{
			myObj.choices[myObj.choices.length] = unescape(hint);
		}
	}
}
	
function createDiv(myObj)
{
	var ul = document.createElement('ul');

	//Create an array of LI's for the words.
	for (i in myObj.choices)
	{
		var word = myObj.choices[i];
		var li = document.createElement('li');
		var a = document.createElement('a');
		a.href="javascript:false";
		a.innerHTML = word;
		li.appendChild(a);

		if (myObj.highlighted == i)
			li.className = "selected";

		ul.appendChild(li);
	}
	myObj.div.replaceChild(ul,myObj.div.childNodes[0]);

	/**	mouseover handler for the dropdown ul		**/
	/** move the highlighted hint with the mouse	**/
	ul.onmouseover = function(ev)
	{
		//Walk up DOM from target until you find the LI.
		var target = window.event.srcElement;	// IE
		
		while (target.parentNode && target.tagName.toUpperCase() != 'LI')
		{
			target = target.parentNode;
		}
		var lis = myObj.div.getElementsByTagName('LI');

		for (i in lis)
		{
			var li = lis[i];
			if(li == target)
			{
				myObj.highlighted = i;
				break;
			}
		}
		showHighlight(myObj);
	};

	/**	click handler for the dropdown ul		**/
	/** insert the clicked hint into the input	**/
	ul.onclick = function(ev)
	{
		getHint(myObj);
		hideDiv(myObj);
		// Cancel event
		window.event.returnValue = false;	// IE
		return false;
	};

	myObj.div.className = "hint_list";
	myObj.div.style.position = 'absolute';
}

function AutoComplete(elem, hints)
{
	var ENTER = 13;
	var ESCAPE = 27;
	var KEYDN = 40;
	var KEYUP = 38;
	var TAB = 9;
	
	var myObj = this;
	this.elem = elem;
	this.hints = hints;
	this.choices = new Array();
	this.inputString = null;
	this.highlighted = -1;
	this.div = document.getElementById("autohint");
	elem.setAttribute("autocomplete","off");

	if(!elem.id)
	{
		var id = "autohint" + idCounter;
		idCounter++;
		elem.id = id;
	}

	/** Tab key = use the highlighted hints, if there is one			**/
	/** Esc key = get rid of the autohint dropdown						**/
	/** Up/down arrows = Move the highlight up and down in the hints	**/
	elem.onkeydown = function(ev)
	{
		var key = window.event.keyCode;		// IE
		switch(key)
		{
			case ENTER:
			case TAB:
				getHint(myObj);
				break;

			case ESCAPE:
				hideDiv(myObj);
				break;
				
			case KEYDN:
				if (myObj.highlighted < (myObj.choices.length - 1))
				{
					myObj.highlighted++;
				}
				showHighlight(myObj);
				break;
			
			case KEYUP:
				if (myObj.highlighted > 0)
				{
					myObj.highlighted--;
				}
				showHighlight(myObj);
				break;
		}
	};

	/**	If the text is of sufficient length, and has been changed	**/
	/** then display a list of eligible hints						**/
	elem.onkeyup = function(ev) 
	{
		var key = window.event.keyCode;		// IE
		switch(key)
		{
			case ENTER:
			case ESCAPE:
			case KEYDN:
			case KEYUP:
			case TAB:			
				return;
			default:
				if (this.value != myObj.inputString && this.value.length > 0)
				{
					myObj.inputString = this.value;
					getChoices(myObj);
					createDiv(myObj);
					placeDiv(myObj);
					myObj.div.style.display = 'block';
				}
				else
				{
					hideDiv(myObj);
				}
		}
	}
}

var idCounter = 0;		//for unique ID's
/************* END AutoComplete()  JC2  ************************/


