
	// OCEAN_STD.JS version 1.5
	// **************************************
	// *  Copyright 2011 - Blue C Software  *
	// *  All Rights Reserved               *
	// **************************************


	// (ON-BLUR, ON-CLICK) PATTERN VALIDATOR
	//  pattern = fieldname_mask, field = fieldname
	//  onblur="patternCheck(this);"  onclick="patternCheck(document.form1.fieldname,1)
	function patternCheck (textbox,popup) {
	
		if (!popup) { var popup=0; }
	
		var maskData = eval('document.form1.' + textbox.name + '_mask' + '.value');
		var commentArea = textbox.name + '_comment';
	
		var aryMasks = maskData.split(",");
		var maskCount = aryMasks.length;
	
		textbox.value = textbox.value.toUpperCase();
	
		var curVal = textbox.value;
	
		if (curVal.length>0) {	
			var NUMBER_RULE = "0123456789";
			var LETTER_RULE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		   for (check=0; check<maskCount; check++) {
			
			var mask = aryMasks[check];
			var maxLength = mask.length;
			//alert('using mask: ' + mask);
	
			var cleanValue = '';
		
			for (i=0; i<maxLength; i++) {
		
				temp = "" + curVal.substring(i, i+1);
				rule = "" + mask.substring(i, i+1);
		
				if (rule=="#") {
					if (NUMBER_RULE.indexOf(temp)>-1) { cleanValue += temp; }
				}
		
				else if (rule=="@") {
					if (LETTER_RULE.indexOf(temp)>-1) { cleanValue += temp; }
				}
		
				else if (rule==temp) {
					cleanValue += temp;
				}
		
			}
	
		   	if (cleanValue.length==maxLength) {
				//alert('value ' + cleanValue + ' matches rule: ' + rule);
				break;
			}
		   }
	
	
		   if (cleanValue.length < maxLength) {
			textbox.value='';
			msg ='INVALID ENTRY: ' + curVal;
			if (popup==1) {
				alert(msg);
			} else {
				eval('document.getElementById("' + commentArea + '").innerHTML="<font color=red>"+msg+"</font>"');
			}
	
			textbox.focus();
		   } else {
			textbox.value=cleanValue;
			textbox.style.color='green';
			if (popup==1) {
				alert('value accepted');
			} else {
				eval('document.getElementById("' + commentArea + '").innerHTML=""');
			}
	
		   }
	
		}
		
	}		
	


	
	// STRING TRIM FUNCTIONS 
	function ltrim(s){
		var l=0;
		while(l < s.length && s[l] == ' '){ l++; }
		return s.substring(l, s.length);
	}
	
	function rtrim(s) {
		var r=s.length -1;
		while(r > 0 && s[r] == ' ') { r-=1; }
		return s.substring(0, r+1);
	}

	function trim(s) {
		return rtrim(ltrim(s));
	}




	// CHANGE STRING TO TITLE CASE
	function ucwords(str) {
	    return (str + '').replace(/^(.)|\s(.)/g, function ($1) {
	        return $1.toUpperCase();    });
	}
	

	
	// EXTRACT ONLY NUMBERS FROM A MIXED STRING
	function justNo(string) {
	    var nums='';
	    var temp='';
	    var valid = '0123456789';
	    for (var i=0; i<string.length; i++) {
		temp = "" + string.substring(i, i+1);
		if (valid.indexOf(temp) != "-1") {
		     nums=nums+string.substring(i,i+1)
		}
	    }
	    return nums;
	}
	

	// EXTRACT ONLY LETTERS FROM A MIXED STRING
	function justLetters(string) {
	    string = string.toUpperCase();
	    var lets='';
	    var temp='';
	    var valid = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ';
	    for (var i=0; i<string.length; i++) {
		temp = "" + string.substring(i, i+1);
		if (valid.indexOf(temp) != "-1") {
		     lets=lets+string.substring(i,i+1)
		}
	    }
	    return lets;
	}
	

	// ASSIST HUMAN INPUT FOR DATE 
	function dateSlash(entry,objName) {
		out = " "; // replace space
		add = "/"; // with slash
		temp = "" + entry; // temporary holder
		
		// if date is just MM/DD add current year
		var mToday = new Date();
		var mYear = mToday.getFullYear(); 
		if (temp.length > 2){
		    if (temp.length < 6){
			temp = temp + ' ' + mYear;
		    }
		}
		
		while (temp.indexOf(out)>-1) {
		    pos= temp.indexOf(out);
		    temp = "" + (temp.substring(0, pos) + add + 
		    temp.substring((pos + out.length), temp.length));
		}
			
		objName.value = temp;
	}
	


	// PHONE NUMBER VALIDATOR
	function isPhone(objName,errID) {
	   var strError = ''
	   var xraw = objName.value; 
	   var xtemp = justNo(xraw);

	   objName.value = xtemp;

	   if (xtemp.length>0) {	
		if (xtemp.length < 10) {
        		strError = "Please use all 10 digits.";
		}
	
	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			var tempID = document.getElementById(errID);
			tempID.innerHTML = '';
			return true;
		}
	   }
	}



	// ISBN VALIDATOR
	function isISBN(objName,errID) {
	   var strError = ''
	   var xraw = objName.value; 
	   var xtemp = justNo(xraw);

	   objName.value = xtemp;

	   if (xtemp.length>0) {	
		if (xtemp.length < 10) {
        		strError = "ISBN requires 10 or 13 digits. ";
		}
		if (xtemp.length > 13) {
        		strError = "ISBN requires 10 or 13 digits. ";
		}
	
	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			var tempID = document.getElementById(errID);
			tempID.innerHTML = '';
			return true;
		}
	   }
	}



	// SOCIAL SECURITY NUMBER VALIDATOR
	function isSSN(objName,errID) {
	   var strError = ''
	   var xraw = objName.value; 
	   var xtemp = justNo(xraw);

	   objName.value = xtemp;

	   if (xtemp.length>0) {	
		if (xtemp.length < 9) {
        		strError = "SSN requires 9 digits. ";
		}
	
	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			var tempID = document.getElementById(errID);
			tempID.innerHTML = '';
			return true;
		}
	   }
	}





	// VERIFY DATE
	function checkDate(objName,errID) {
	   var strError = ''
	   if (objName) {
		   if (objName.value.length>0) {
			   if (objName.value.length<6)  {
				objName.value='';
				strError = "Invalid date.";
			   } else {

				var tmpDateStr = objName.value.toUpperCase();
				var tempDash = tmpDateStr.indexOf("-");

				//--- YYYY-MM-DD FORMAT FIX ---
				if (tempDash==4) {
					var YY = tmpDateStr.substr(0,4);
					var MM = tmpDateStr.substr(5,2);
					var DD = tmpDateStr.substr(8,2);
				        tmpDateStr = MM + "/" + DD + "/" + YY;
					objName.value = tmpDateStr;
				}

				//--- DASH TO SLASH FIX ---
				tmpDateStr = tmpDateStr.replace("-","/");
				tmpDateStr = tmpDateStr.replace("-","/");
				tmpDateStr = tmpDateStr.replace("-","/");
				objName.value = tmpDateStr;


				//--- LONGHAND DATE VARIANT FIX ---
				var tmpDateStr = objName.value.toUpperCase();
				tmpDateStr = tmpDateStr.replace("JANUARY ","JAN ");
				tmpDateStr = tmpDateStr.replace("FEBRUARY ","FEB ");
				tmpDateStr = tmpDateStr.replace("MARCH ","MAR ");
				tmpDateStr = tmpDateStr.replace("APRIL ","APR ");
				tmpDateStr = tmpDateStr.replace("JUNE ","JUN ");
				tmpDateStr = tmpDateStr.replace("JULY ","JUL ");
				tmpDateStr = tmpDateStr.replace("AUGUST ","AUG ");
				tmpDateStr = tmpDateStr.replace("SEPTEMBER ","SEP ");
				tmpDateStr = tmpDateStr.replace("SEPT ","SEP ");
				tmpDateStr = tmpDateStr.replace("OCTOBER ","OCT ");
				tmpDateStr = tmpDateStr.replace("NOVEMBER ","NOV ");
				tmpDateStr = tmpDateStr.replace("DECEMBER ","DEC ");
				objName.value = tmpDateStr;
			
				if (objName.value!='00/00/0000') {
					if (isCalDate(objName) == false) {
						objName.value='';
						strError = "Invalid date. (" + objName.value + ")";
				   	}
				} else {
						objName.value='';
				}
		
			   } 
		
		
		 	   if (strError.length > 0) {
				if (!errID) {
		  			alert(strError);
				} else {
						var tempID = document.getElementById(errID);
						tempID.innerHTML = strError;
				}
				objName.focus();
				objName.select();
				return false;
			   } else {
				if (errID) {
					var tempID = document.getElementById(errID);
					tempID.innerHTML = '';
				}
				return true;
			   }
	
		   } else {
	
			if (errID) {
				var tempID = document.getElementById(errID);
				tempID.innerHTML = '';
			}
			return true;
		   }
	   }

	}
	



	// IS THIS A VALID CALENDAR DATE? (required by checkDate) 
	function isCalDate(objName) {
		var strDatestyle = "US"; //United States date style
		//var strDatestyle = "EU";  //European date style
	
		var strDate;
		var strDateArray;
		var strDay;
		var strMonth;
		var strYear;
		var intday;
		var intMonth;
		var intYear;
		var booFound = false;
		var datefield = objName;
		var strSeparatorArray = new Array("-"," ","/",".");
		var intElementNr;
		var err = 0;

		var strMonthArray = new Array(12);
		strMonthArray[0] = "Jan";
		strMonthArray[1] = "Feb";
		strMonthArray[2] = "Mar";
		strMonthArray[3] = "Apr";
		strMonthArray[4] = "May";
		strMonthArray[5] = "Jun";
		strMonthArray[6] = "Jul";
		strMonthArray[7] = "Aug";
		strMonthArray[8] = "Sep";
		strMonthArray[9] = "Oct";
		strMonthArray[10] = "Nov";
		strMonthArray[11] = "Dec";

		strDate = datefield.value;
		if (strDate.length < 1) { return true; }
		for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
			if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
				strDateArray = strDate.split(strSeparatorArray[intElementNr]);
				if (strDateArray.length != 3) {
					err = 1;
					return false;
				} else {
					strDay = strDateArray[0];
					strMonth = strDateArray[1];
					strYear = strDateArray[2];
				}
				booFound = true;
	   		}
		}

		if (booFound == false) {
			if (strDate.length>5) {
				strDay = strDate.substr(0, 2);
				strMonth = strDate.substr(2, 2);
				strYear = strDate.substr(4);
	   		}
		}

		if (strYear.length == 2) {
	   		var testYr=parseInt(strYear);
	   		if (testYr>20) {
				strYear = '19' + strYear;
	   		} else {
				strYear = '20' + strYear;
	   		}
		}

		// US style
		if (strDatestyle == "US") {
			strTemp = strDay;
			strDay = strMonth;
			strMonth = strTemp;
		}

		intday = parseInt(strDay, 10);
		if (isNaN(intday)) {
			err = 2;
			return false;
		}

		intMonth = parseInt(strMonth, 10);
		if (isNaN(intMonth)) {
			for (i = 0;i<12;i++) {
				if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
					intMonth = i+1;
					strMonth = strMonthArray[i];
					i = 12;
		   		}
			}
			if (isNaN(intMonth)) {
				err = 3;
				return false;
			}
		}

		intYear = parseInt(strYear, 10);
		if (isNaN(intYear)) {
			err = 4;
			return false;
		}

		if (intMonth>12 || intMonth<1) {
			err = 5;
			return false;
		}

		if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
			err = 6;
			return false;
		}

		if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
			err = 7;
			return false;
		}

		if (intMonth == 2) {
			if (intday < 1) {
				err = 8;
				return false;
			}
			if (LeapYear(intYear) == true) {
				if (intday > 29) {
					err = 9;
					return false;
				}

			} else {
				if (intday > 28) {
					err = 10;
					return false;
				}
			}
		}

		if (strDatestyle == "US") {
			if (intday<10) {
				datefield.value = strMonthArray[intMonth-1] + " 0" + intday+" " + strYear;
		  	} else {
				datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
		  	}
		} else {
			datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
		}

		return true;
	}




	// IS THIS A LEAP YEAR? (required by isDate)
	function LeapYear(intYear) {
		if (intYear % 100 == 0) {
			if (intYear % 400 == 0) { return true; }
		} else {
			if ((intYear % 4) == 0) { return true; }
		}
		return false;
	}







	// CASE CHANGE AND CLEANSER
	function cleanUp(objName, errID, JustLetters, CaseStyle) {
		var strError = ''
		var xraw = objName.value; 

		var a_valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- ";
		var a_msg = "Only Letters are accepted";
		var b_valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-:/.,# ";
		var b_msg = "Only Letters and Numbers are accepted";
	
		if (JustLetters == true) {
	   		if (CaseStyle!=0) { objName.value = justLetters(xraw); }
			var valid = a_valid
			var msg = a_msg
		} else {
			var valid = b_valid
			var msg = b_msg
		}	
	
		if (xraw.length>0) {
			var ok = "yes";
			var temp;
		
			for (var i=0; i<xraw.length; i++) {
				temp = "" + xraw.substring(i, i+1);
				if (valid.indexOf(temp) == "-1") {var ok = "no";}
			}
			if (ok != "yes") {
				strError = msg;
			}
		}		

		var cleaned = objName.value; 
		//-- CaseStyle 0 = Do Nothing --
		if (CaseStyle == 1) { cleaned = cleaned.toUpperCase(); }
		if (CaseStyle == 2) { cleaned = ucwords(cleaned.toLowerCase()); }
	   	objName.value = cleaned;
		

	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			} 
			objName.focus();
			objName.select();
			return false;
		} else {
			var tempID = document.getElementById(errID);
			if (tempID) { tempID.innerHTML = ''; }
			return true;
		}


	}
	




	// (ON-BLUR) NUMBER VALIDATOR
	function isNumeric(objName, errID, minlength) {
		var strError = ''
		if (minlength == null) {var minlength = 0;}
		var xraw = objName.value; 
		
		if (minlength > 0) {
			if ((xraw.length>0) && (xraw.length < minlength)) {
				strError = "Field too short!    \n";
			}
		}
		
		if (xraw.length>0) {
			eval("thetarget = /([0-9]{" + (1) + ",})/g;");
			var thefullStr = xraw + " ";
			var thecutStr = thefullStr.replace(thetarget,"");
			if (thecutStr.length > 1) {
				strError = strError + "non-numeric values (" + thecutStr + ") are not allowed.      \n";
			}
		
		}

	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			if (errID) {
				var tempID = document.getElementById(errID);
				tempID.innerHTML = '';
			}
			return true;
		}

	}
	
	
	

	// (ON-BLUR) NUMBER RANGE VALIDATOR
	function isRange(objName, errID, minval, maxval) {

		var strError = ''
		if (minval == null) {var minval = 0;}
		if (maxval == null) {var maxval = 0;}

		var xraw = objName.value; 
		var strtemp='';
	
		if (minval > 0) {
			if (xraw < minval) { strError = "value too low!    \n"; }
		}
	
		if (maxval > 0) {
			if (xraw > maxval) { strError = "value too high!    \n"; }
		}
		xraw=Math.round(xraw*100)/100;


		objName.value = xraw;
	 	
		/// only interrogate if there is a value ///
		if (xraw.length>0) {
			eval("thetarget = /([0-9.,]{" + (1) + ",})/g;");
	  		var thefullStr = xraw + " ";
	  		var thecutStr = thefullStr.replace(thetarget,"");
	  		if (thecutStr.length > 1) {
	 			strError = strError + "non-numeric values (" + thecutStr + ") are not allowed.      \n";
	 		}

		}

	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			if (errID) {
				var tempID = document.getElementById(errID);
				tempID.innerHTML = '';
			}
			return true;
		}

	}
	








	// (ON-BLUR) E-MAIL VALIDATOR - NEW 2004 ****
	function emailCheck (objName, errID) {
		var strError = ''
		var xraw = objName.value; 
	
		if (xraw.length > 0) {
		
			var emailPat=/^(.+)@(.+)$/
			var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var validChars="\[^\\s" + specialChars + "\]"
			var quotedUser="(\"[^\"]*\")"
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			var atom=validChars + '+'
			var word="(" + atom + "|" + quotedUser + ")"
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
			var matchArray=xraw.match(emailPat)
		
			if (matchArray==null) {
				strError = "Email address lacks @ or .'s";
			} else {
		
				var user=matchArray[1]
				var domain=matchArray[2]
		
				if (user.match(userPat)==null) {
					strError = "The mailbox name seems invalid.";
				}
			
				var IPArray=domain.match(ipDomainPat)
			
				if (IPArray!=null) {
					for (var i=1;i<=4;i++) {
						if (IPArray[i]>255) {
							strError = "Destination IP address seems invalid.";
						}
					}
				}
			
				var domainArray=domain.match(domainPat)
		
				if (domainArray==null) {
					strError = "The domain name seems invalid.";
				}
		
				var atomPat=new RegExp(atom,"g");
				var domArr=domain.match(atomPat);
				var len=domArr.length;
			
				if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
				    strError = "The address must end in a three or four-letter domain, or two letter country.";
				}
			
				if (len<2) {
			   	    strError="This address is missing a hostname!"
				}
			}
		
		}


	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			var tempID = document.getElementById(errID);
			tempID.innerHTML = '';
			return true;
		}



	}




	//----------- TAB MANAGMENT ----------------
	var tempTab;
	var tempIcon;



	// REMEMBER OPEN TABS
	function rememberOpenTabs() {
		var tabCount = document.form1.TAB.length;
		var tabList = '';
		if (tabCount>0) { 
		  for (chk=0; chk<tabCount; chk++) {
			if (document.form1.TAB[chk].checked) {
				tabList += chk + ',';
			}
		  }
		} else { 
			tabList += '0,';
		} 
		tabList = tabList.substr(0,tabList.length-1);
		document.form1.TAB_LIST.value = tabList;

	}




	// CLOSE ALL TABS
	function closeAllTabs() {

		var tabCount = document.form1.TAB.length;
		if (tabCount>0) { 
		  // -- skip tab 0 by changing chk starting point to 1 ---
		  for (chk=1; chk<tabCount; chk++) {
			var tempTabCloser = eval("document.getElementById('TAB" + chk + "')");
			var tempIconCloser = eval("document.getElementById('ICON" + chk + "')");
			tempTabCloser.style.display = 'none'; 
 			tempIconCloser.innerHTML="[+]";
			document.form1.TAB[chk].checked = false
		  }
		}

	}


	// (ON-LOAD) RESTORE OPEN TABS
	function restoreTabs() {

		closeAllTabs();

		var which = 0;
		if (document.form1.TAB_LIST.value.length<1) { document.form1.TAB_LIST.value = "0"; }
		var aryTABS = document.form1.TAB_LIST.value.split(",");
		for (chk=0; chk<aryTABS.length; chk++) {
			which = aryTABS[chk];
			document.form1.TAB[which].checked = true;

			var tempTab = eval("document.getElementById('TAB" + which + "')");
			var tempIcon = eval("document.getElementById('ICON" + which + "')");
			tempTab.style.display = 'block'; 
 			tempIcon.innerHTML="[-]";
			document.form1.TAB[which].checked = true;

		}
		//--- JUMP TO LAST TAB --
		//eval("window.location.hash='TAB" + which + "';");
	}




	// TOGGLE ONE TAB 
	function toggleTab(which,holdopen) {

		if (holdopen==null) { holdopen=false; }

		//--- OPEN SPECIFIC TAB ---
		tempTab = eval("document.getElementById('TAB" + which + "')");
		tempIcon = eval("document.getElementById('ICON" + which + "')");

		var currStatus = tempTab.style.display;
		if (currStatus=='none') {

			//--- CLOSE ALL OPEN TABS ---
			if (holdopen!=true) { closeAllTabs(); }

			//--- OPEN REQUESTED TAB ---
			tempTab.style.display = 'block'; 
 			tempIcon.innerHTML="[-]";
			document.form1.TAB[which].checked = true;


		} else {

			//--- CLOSE REQUESTED TAB ---
			tempTab.style.display = 'none'; 
 			tempIcon.innerHTML="[+]";
			document.form1.TAB[which].checked = false

		}


		//--- REMEMBER OPEN TABS ---
		rememberOpenTabs();



	}





	// --- Check for Personal Health Information ---
	function phiCheck(objName, errID) {
		var strError = ''
		var xraw = ' ' + objName.value; 
		xraw = xraw.toLowerCase();
		var xloc = 0;

		if (xraw.length > 0) {
			var aryPHIflags = new Array("patient","account","acct","dob","birth","ssn","tin","client","diagnosis","dx","prescription","rx");
			if (aryPHIflags!=null) {
				for (var i=0;i<aryPHIflags.length;i++) {
					xloc = xraw.indexOf(aryPHIflags[i]);
					if (xloc>0) {
						strError = "*** WARNING ***\nSensitive Information Detected in SUBJECT: (" + aryPHIflags[i].toUpperCase() + ")";
						break;
					}
				}
			}


		
		}

	 	if (strError.length > 0) {
			if (!errID) {
	  			alert(strError);
			} else {
  				var tempID = document.getElementById(errID);
    				tempID.innerHTML = strError;
			}
			objName.focus();
			objName.select();
			return false;
		} else {
			if (errID) {
				var tempID = document.getElementById(errID);
				tempID.innerHTML = '';
			}
			return true;
		}
	}





