
	function CheckUncheck(el) {
		
		  var str= el.id;
          var isElement = true;
          var CheckUnkNoneFlag = 0;
          var CheckOtherFlag = 0;
          
          var labels = el.getElementsByTagName('LABEL');
          
          for (var i=0;isElement;i++) {       
          
                  var element = str + '_' + i;  
				
                  if (document.getElementById(element)) {

                        if (document.getElementById(element).checked) {
							if (labels[i].outerText == "unknown" || labels[i].outerText == "None") {
							  CheckUnkNoneFlag = 1;
							  //alert(labels[i].outerText);
							}
							else {
							  CheckOtherFlag = 1;
							}  
                        }
                  }
                  else {
                        isElement = false;
                  }     
           }
           
           if (CheckUnkNoneFlag) {
             if (CheckOtherFlag) {
               // alert('Message Here');
                for (i=0;i < labels.length ;i++)  {
					//document.getElementById(labels[i].htmlFor).checked = false;
                }
             }
             
           }
            
	}
	
	function roundToDecimal(val, decimalPlaces) {
		var pVal = val * Math.pow(10,decimalPlaces);
		sVal = Math.round(pVal)/Math.pow(10,decimalPlaces);
		if (sVal == 0) { return(Math.ceil(sVal)/Math.pow(10,decimalPlaces)); }
		return(sVal);
	}
	
var hgtInChg=false;
var hgtCmChg=false;
var wgtLbsChg=false;
var wgtKgChg=false;
	
function LbToKg(fieldlb, fieldkg, fieldstatus) {	
	if (wgtLbsChg==true) {
		if ((isValidNumField(fieldlb)) && (fieldlb.value != "")) {
			var KGval = fieldlb.value / 2.2;				
			fieldkg.value = (roundToDecimal(KGval,0));		
		}
		else {
			fieldkg.value="";		
		}	
		
		if (fieldstatus != "") {
			if (fieldstatus.options[fieldstatus.selectedIndex].value.length != 0) {
				fieldstatus.selectedIndex = 0;   
			} 
		} 
	}
}


function KgToLb(fieldkg, fieldlb, fieldstatus) {
	if (wgtKgChg==true) {
		if ((isValidNumField(fieldkg)) && (fieldkg.value != "")) {
			var LBval = fieldkg.value * 2.2;			
			fieldlb.value = (roundToDecimal(LBval,0)); //(LBval);			
		}
		else {
			fieldlb.value="";			
		}
		
		if (fieldstatus != "") {
			if (fieldstatus.options[fieldstatus.selectedIndex].value.length != 0) {
				fieldstatus.selectedIndex = 0;   
			} 
		} 
	}
}



function hgtInChange() {
	hgtInChg=true;
	hgtCmChg=false;
}

function hgtCmChange() {
	hgtCmChg=true;
	hgtInChg=false;
}

function wgtLbsChange() {
	wgtLbsChg=true;
	wgtKgChg=false;
}

function wgtKgChange() {
	wgtLbsChg=false;
	wgtKgChg=true;
}


function CmToIn(fieldcm, fieldin, fieldstatus) {	
	if (hgtCmChg==true) {
		if ((isValidNumField(fieldcm)) && (fieldcm.value != "")) {
			var INval = fieldcm.value / 2.54;	
			//alert(INval);		
			fieldin.value = (roundToDecimal(INval,0));	//Math.floor(INval); //(roundToDecimal(INval,0));		
		}
		else {
			fieldin.value="";		
		}	
		
		if (fieldstatus != "") {
			if (fieldstatus.options[fieldstatus.selectedIndex].value.length != 0) {
				fieldstatus.selectedIndex = 0;   
			} 
		} 
	}
}


function InToCm(fieldin, fieldcm, fieldstatus) {	
	//alert(fieldin.value);
	//alert(fieldcm.value);
	//vTotal = (eval(fieldin.value)) * 2.54;
	//alert(vTotal);
	//alert(Math.floor(vTotal));
	//return;
	if (hgtInChg==true) {
		if ((isValidNumField(fieldin)) && (fieldin.value != "")) {
			var Cmval = fieldin.value * 2.54;	
			//alert(Cmval);		
			fieldcm.value = (roundToDecimal(Cmval,0)); //(Math.floor(Cmval,0));		
		}
		else {
			fieldcm.value="";		
		}	
		
		if (fieldstatus != "") {
			if (fieldstatus.options[fieldstatus.selectedIndex].value.length != 0) {
				fieldstatus.selectedIndex = 0;   
			} 
		} 
	}
}

function checkStatusParentFields(el, parentfield1,parentfield2) {
			
		if (el && parentfield1 && parentfield2) {
			if (el.options) {
				if ((parentfield1.value.length != 0) && (parentfield2.value.length != 0) && (el.options[el.selectedIndex].value.length != 0)) {
					parentfield1.value = '';
					parentfield2.value = '';
					return false;
				}
				return true;
			}
		}
	}
	
	
function validateInteger( strValue ) {
	var objRegExp  = /(^-?\d\d*$)/;
	return objRegExp.test(strValue);
}
				

	function checkNumberStatus(val, obj) {	
			if ((val!="") && (obj.value!="")) {
				obj.value="";		
			}	
		}

		function formatDate(el, format) {
			switch (format) {
				case ('mmddyyyy'):
					if (el.value.length == 8) {       
						if (el.value.indexOf('/') < 0) {           
							var newDate;           
							newDate = el.value.substring(0,2)                        
								+ '/' + el.value.substring(2,4)                        
								+ '/' + el.value.substring(4,8);           
							el.value = newDate;       
						}
					}
					break;
				case ('mmyyyy'):
					if (el.value.length == 6) {       
						if (el.value.indexOf('/') < 0) {           
							var newDate;           
							newDate = el.value.substring(0,2)                        
							+ '/' + el.value.substring(2,6)            
							el.value = newDate;       
						}   
					}   
					break;
			}
			return;
		}
		
	
		function smartSelect_onKeyDown()
		{
			var objSelect = event.srcElement;
			if (objSelect == null) return;
			var intCode = event.keyCode;

			var strSearch = objSelect.getAttribute("search");
			if (strSearch == null) strSearch = "";

			var timerID = objSelect.getAttribute("timer");
			if (timerID == null) timerID = -1;

			var bFind = false;

			if (timerID != -1)
				window.clearTimeout(timerID);

			// backspace key was pushed
			if (intCode == 8) {
				strSearch = strSearch.substr(0,strSearch.length-1);
				bFind=true;
			}
			// delete key was pushed
			else if (intCode == 46) {
				strSearch = "";
				bFind=true;
			}
			if (bFind) {
				objSelect.setAttribute("search", strSearch);
				window.status = "Find In List: " + strSearch;

				event.returnValue=false;
				event.cancelCapture = false;
				event.cancelBubble = false;

				timerID = window.setTimeout("smartSelect_clearSearch(document.getElementById('" + objSelect.id + "'));", 2000);
				objSelect.setAttribute("timer", timerID);

				var len = strSearch.length;
				for(x=0; x < len; x++)	
				{
					if (smartSelect_closetValue(objSelect, strSearch.substr(0,len-x)))
						return;
				}
			}
		}
		
	

		function isValidNumRange(fieldname, rangelow, rangehigh)
		{
			var fieldvalue;
			fieldvalue = parseFloat(fieldname);
			if ((fieldvalue >= parseFloat(rangelow)) && (fieldvalue <= parseFloat(rangehigh))) {
				return (true);
			}
			else { 
				return (false);
			}
		}
		


		function stripDecimals(el, decimal) {
			//Strips off extraneous decimal places
			if (el && el.value.indexOf('.') > -1) {
				var num = el.value.length - el.value.indexOf('.') + 1;
				if (decimal == 0) {
					el.value = el.value.substring(0, el.value.indexOf('.'));
				}
				else{ if (num >= decimal) {
					el.value = el.value.substring(0, el.value.indexOf('.') + decimal + 1);
				}}
			}
		}
	
	

		function validateDate(el, format)
		{
  			var field = el.value;
			var nErrorCode=0;
			var strMonth = '';
			var strDelim1 = '';
			var strDay = '';
			var strDelim2 = '';
			var strYear = '';
			var strMessage = '';
			var strExample = '01/01/2003';

			if (format == 'mmyyyy') strExample = '01/2003';
				
			// check length of date 
			 
			if (field != '')
			{
				if ((format == 'mmddyyyy' && field.length !=10) || (format == 'mmyyyy' && field.length != 7))
				{
					nErrorCode=1;
					strMessage += 'The date (' + field + ') must be in the following format: ' + format + '';
					strMessage += '\nExample: ' + strExample;	
				}
				// parse string
				else 
				{
		      
				switch (format) {
					case ('mmddyyyy'):
						strMonth = field.substring(0, 2);		// month
						strDelim1 = field.substring(2, 3);		// '/'
						strDay = field.substring(3, 5);			// day
						strDelim2 = field.substring(5, 6);		// '/'
						strYear = field.substring(6, 10);		// year
						break;
					case ('mmyyyy'):
						strMonth = field.substring(0, 2);		// month
						strDelim1 = field.substring(2, 3);		// '/'
						strYear = field.substring(3, 7);		// year
						break;
				}
				
				//error checking
				if (strMonth < 1 || strMonth > 12) 
				{
					nErrorCode=1;
					strMessage += '\nMonth must be between 1 and 12.';
				}
				
				// check for alphas
				
				// valid numeric digits
				var digits = '0123456789';
				
				for (var i = 0; i < strMonth.length; i++)
				{
					if (digits.indexOf(strMonth.charAt(i)) < 0)
					{
						nErrorCode=2;
					}
				}
				if (nErrorCode==2) strMessage += '\nMonth must be a number.';

				if (format != 'mmyyyy') {
					for (var i = 0; i < strDay.length; i++)
					{
						if (digits.indexOf(strDay.charAt(i)) < 0)
						{
							nErrorCode=3;
						}
					}
					if (nErrorCode==3) strMessage += '\nDay must be a number.';
				}
				for (var i = 0; i < strYear.length; i++)
				{
					if (digits.indexOf(strYear.charAt(i)) < 0)
					{
						nErrorCode=4;
					}
				}
				if (nErrorCode==4) {
					if (format == 'yyyy') {
						strMessage += '\nPlease enter only the year.';
					}
					else {
						strMessage += '\nYear must be a number.';
					}
				}

 				if (format != 'mmyyyy') {
					if ((strDelim1 != '/') || (strDelim2 != '/'))
					{
						nErrorCode = 1;
						strMessage += '\nMonth, day, and year must be separated by /.'
					}
					if (strDay < 1 || strDay > 31) 
					{
						nErrorCode=1;
						strMessage += '\nDay must be between 1 and 31.';
					}
				}
        			if (strYear < 1900 || strYear > 2099) 
        			{
					nErrorCode=1;
					//strMessage += '\nYear must be in the 20th or 21st Century.';
					strMessage += 'The Year you enter must be in the 20th or 21st Century.';
				}

				if (format != 'mmyyyy') {
        				// months with 30 days
        				if (strMonth==4 || strMonth==6 || strMonth==9 || strMonth==11)
        				{
						//alert(strDay);
						if (strDay==31) 
						{
							nErrorCode=1;
							strMessage += '\nThis month only has 30 days.';
						}
		  			}
				}

        		// February, leap year
				if (strMonth==2)
        			{
					var g=parseInt(strYear/4);
					if (isNaN(g)) 
					{
						nErrorCode=1;
					}
					if (strDay > 29) 
					{
						nErrorCode=1;
						strMessage += '\nLeap year Feb. only has 29 days.';
					}

					if (strDay==29 && ((strYear/4)!=parseInt(strYear/4))) 
					{
						nErrorCode=1;
						strMessage += '\nNon leap year Feb. only has 28 days.';
					}
				}
				}
			}
			// error handler
			if (nErrorCode >=1)
    		{
				alert(strMessage);
				el.value = '';
				el.focus();
				return (false);
			}
    		else
    		{
        		return (true);
    		}
		}
		

		function smartSelect_clearSearch(objSelect) {
			if (objSelect != null) {
				objSelect.setAttribute("search", "");
			}
			window.status = "";
			objSelect.setAttribute("timer", -1);
		}
		
	

			function showHideContainer(containerName, el, vals, reset) {			
			var show = false;
			var cnt;			
			
			if (bToggleContainer==false) {
				bToggleContainer=true;				
				return;			
			}			
			
			if (vals.substring(0,2) == "!=") {			
				//alert('in');
				var vals = vals.substring(2,vals.length);
				var val = vals.split(',');
				show = true;
				if (el) {
					for (var i=0; i<val.length; i++) {
						//alert(val[i]);
						if (el.value == val[i]) {
							if (el.tagName.toLowerCase() == 'input' && el.type != null) {
								if ((el.type.toLowerCase() == 'radio' || el.type.toLowerCase() == 'checkbox') && el.checked)	{
									show = false;
								}
								else	{
									//Leave show what it is.
								}
							}
							else	{
								show = false;
							}
						}
					}
				}				
			}
			else {					
				var val = vals.split(',');							
													
				if (el) {									
					if (el.type.toLowerCase() == 'checkbox') {					
						var checkVal = "";
						var checkValSplit; 
						var checkID = "";	
						var counter = 0;	
						var isElement = true	
																			
						var str= el.id;
						for (var i=0; i < str.length; i++)		{
							var strSub= str.substring(i, i+1);
							if (strSub < "0" || strSub > "9")	{
									checkID = checkID + strSub;
							}			
						}  
												
						for (var i=0;isElement;i++) {		
							var element = checkID + i;						
							if (document.getElementById(element)) {
								if (document.getElementById(element).checked) {
									checkVal = checkVal + document.getElementById(element).value + ',';							
								}
							}
							else {
								isElement = false;
							}
						}						
					
						checkValSplit =  checkVal.split(',');	
						
						for (var x=0; x<val.length; x++) {								  
							for (var i=0; i<checkValSplit.length; i++) {	
							
								if (val[x] == checkValSplit[i]) {										   						
									show = true;																	
								}												
							}						
						}			
														
					}			
					else {					
						for (var i=0; i<val.length; i++) {						
							if (el.value == val[i]) {
								show = true;
								if (el.tagName.toLowerCase() == 'input' && el.type != null) {
									if (el.type.toLowerCase() == 'radio' && !el.checked) show = false;
									if (el.type.toLowerCase() == 'checkbox' && !el.checked) show = false;
								}
							}
							else {
								if (el.tagName.toLowerCase() == 'input' && el.type != null) {
									if (el.type.toLowerCase() == 'checkbox') return;
								}
							}
						}
					}		
												
				}							
					
			}
									
			var containers = containerName.split(',');
			
			for (var j=0; j<containers.length; j++) {
				cnt = document.getElementById(containers[j]);
				
				if (cnt) {
					if (show) {
						cnt.style.display = getDisplayType(cnt);
						//To account for mac issue
						cnt.style.display = 'none';
						cnt.style.display = getDisplayType(cnt);
					}
					else {
						if (cnt.style.display != 'none') {
							cnt.style.display = 'none';
							if (reset) resetContainer(cnt);
						}
					}
				}
			}
			return false;
		}
		
	
		
	

		function passNumValidation(field, statusField, decimal, rangechk, rangelow, rangehigh)
		{
			var fldVal = field.value;  
		
			var ret = true;       
			if (field.value == '' || field.value == null) {
				return ret;
			}
			else {
				if (statusField != '') {
					var fldType = statusField.type;
					if (fldType.indexOf("select-one") >= 0) {
						statusField.selectedIndex = 0; 
					}
				}
			}
			if (!isValidNumField(field)) {
				ret = false;
			}
			if (!isValidNumFmt(field, decimal)) { 
				if (decimal == 0) {
					//must be a whole number
					regError(null, 'wholenumber', 'remDec');
					ret =  false;
				}
				else {
					//required number of decimal
					regError('Does not contain required number of decimals: ' + decimal, '', 'remDec');
					ret =  false;
				}
			}     
			if ((rangechk == 'True') && (!isValidNumRange(fldVal, rangelow, rangehigh))) 
			{
			//alert('invalid range');
			}
			else {
			//alert(rangechk);
			//alert('valid range');
			//alert(fldVal);
			//alert(rangelow);
			//alert(rangehigh);
			}
			return ret;
		}
		

		function smartSelect_onKeyPress()
		{
			objSelect = event.srcElement;
			if (objSelect == null) return;
			var intCode = event.keyCode;
			var charCode = String.fromCharCode(intCode).toUpperCase();

			var strSearch = objSelect.getAttribute("search");
			if (strSearch == null) strSearch = "";

			var timerID = objSelect.getAttribute("timer");
			if (timerID == null) timerID = -1;

			var strFlg = objSelect.getAttribute("flag");
			if (strFlg == null) strFlg = "";
			var bFind = false;

			if (timerID != -1)
				window.clearTimeout(timerID);

			// all characters (default)
			if (strFlg == "") {
				strSearch = strSearch + charCode;
				bFind=true;
			}
			// letters & numbers
			else if (strFlg == "LN" && ((charCode >= "a" && charCode <= "z") || (charCode >= "A" && charCode <= "Z") || (charCode >= "0" && charCode <= "9"))) {
				strSearch = strSearch + charCode;
				bFind=true;
			}
			// letters only
			else if (strFlg == "L" && ((charCode >= "a" && charCode <= "z") || (charCode >= "A" && charCode <= "Z" ))) {
				strSearch = strSearch + charCode;
				bFind=true;
			}
			// numbers only
			else if (strFlg == "N" && (charCode >= "0" && charCode <= "9")) {
				strSearch = strSearch + charCode;
				bFind=true;
			}
			objSelect.setAttribute("search", strSearch);
			window.status = "Find In List: " + strSearch;
			// find value in combo box and locate the correct drop down value
			if (bFind) {
				event.returnValue=false;
				event.cancelCapture = false;
				event.cancelBubble = false;

				timerID = window.setTimeout("smartSelect_clearSearch(document.getElementById('" + objSelect.id + "'));", 2000);
				objSelect.setAttribute("timer", timerID);

				var len = strSearch.length;
				for(x=0; x < len; x++)	
				{
					if (smartSelect_closetValue(objSelect, strSearch.substr(0, len-x)))
						return;
				}
			}
		}
		


		function isValidNumField(el) {			
			var ret = true;
			var val = el.value;
			if (val != '' && val != null) {
				for (var i=0; i < val.length; i++) {
					var digit = val.charAt(i)
					if (digit < '0' || digit > '9') {
						//not a number
						if (digit == ',') {
							//contains commas
							regError(null, 'commas', 'remComm');
							ret = false;
						} 
						else { if (digit == '.') {
							//decimal points okay
							return true;
						}
						else { if (digit == '-' && i == 0) {
							//okay if - is first char
							return true;
						}
						else {
							//not numeric
							regError(null, 'invalidnum', 'clear');
							ret = false;
						}}}
					}
				}
			}
			return ret;       
		}
		
	

		function stripCommas(el) {
			if (el) {
				el.value = el.value.replace(',', '');
			}
		}
	


		function passRangeValidation(el, label, lowVal, highVal, lowLabel, highLabel, unit) 
		{
			
			var msg = '';
			var unitLabel = unit;
			if (label == '') label = 'This field';
			if (lowLabel == '') lowLabel = lowVal;
			if (highLabel == '') highLabel = highVal;
			if (!isDecimal(unit.replace('-', ''))) unitLabel = '';
			if (el.value != '' && el.value != null) {
				if (((lowVal != '' && lowVal != null) || (lowVal == 0)) && ((highVal != '' && highVal != null) || (highVal == 0))) {
					if (!(isValidNumRange(el.value, lowVal, highVal))) {	
					
						switch (el.id) {
							case ('uns_map_init'): label='Map (initial)'; break;
							case ('uns_map_post'): label='Map (final)'; break;
							case ('uns_cvp_init'): label='CVP (initial)'; break;
							case ('uns_cvp_post'): label='CVP (final)'; break;
							case ('uns_pcwp_init'): label='PCWP (initial)'; break;
							case ('uns_pcwp_post'): label='PCWP (final)'; break;
							case ('uns_svr_init'): label='SVR (initial)'; break;
							case ('uns_svr_post'): label='SVR (final)'; break;
							case ('uns_pasyst_init'): label='PA Systolic (initial)'; break;
							case ('uns_pasyst_post'): label='PA Systolic (final)'; break;
							case ('uns_padiast_init'): label='PA Diastolic (initial)'; break;
							case ('uns_padiast_post'): label='PA Diastolic (final)'; break;
							case ('uns_co_init'): label='CO (initial)'; break;
							case ('uns_co_post'): label='CO (final)'; break;
							case ('uns_card_idx_init'): label='Cardiac Index (initial)'; break;
							case ('uns_card_idx_post'): label='Cardiac Index (final)'; break;
														
							default:
						}
							
						if (unitLabel != '') {	
							msg = label + ' must be between ' + lowLabel + ' ' + unitLabel + ' and ' + highLabel + ' ' + unitLabel;
						}
						else {
							msg = label + ' must be between ' + lowLabel + ' and ' + highLabel + ' ' + unitLabel;
						
						}
					}
				}
				else {
					if ((lowVal != '' && lowVal != null) || (lowVal == 0)) {
						if (parseFloat(el.value) < parseFloat(lowVal)) {
							msg = label + ' must be greater than or equal to ' + lowLabel + ' ' + unitLabel;
						}
					}
					if ((highVal != '' && highVal != null) || (highVal == 0)) {
						if (parseFloat(el.value) > parseFloat(highVal)) {
							msg = label + ' must be less than or equal to ' + highLabel + ' ' + unitLabel;
						}
					}
				}
				if (msg != '') {
					//errorMessages(msg);
					regError(msg, '', 'clear');
					return false;
				}
			}
			return true;
		}


		function validateRange(field, label, rangelow, rangehigh, lowLabel, highLabel, unit)
		{
			initError();
			var passed = passRangeValidation(field, label, rangelow, rangehigh, lowLabel, highLabel, unit); 
			if (!passed) {
				modifyField(field, 0);
				return false;
			}
			return true;
		}
	
		function getDisplayType(el) {
			if (el.tagName.toLowerCase() == 'table' || el.tagName.toLowerCase() == 'div') {
				return 'block';
			}
			else {
				return 'inline';
			}
		}
		


		function isDecimal(value)
		{
			return checkNumeric(value, '0123456789.');
		}
		
	


			function triggerAllEvents(tagName) {
				var allForms = document.forms;
				var allEls;
				var trigger = false;
				for (var j=0; j<allForms.length; j++) {
					allEls = document.forms[j].getElementsByTagName(tagName);
					for (var i=0; i<allEls.length; i++) {
						if (allEls[i].tagName.toLowerCase() == tagName) {
							trigger = true;
							if (allEls[i].type != null) {
								if (allEls[i].type.toLowerCase() == 'radio') {
									if (allEls[i].checked != true) trigger = false;
								}
								if (allEls[i].type.toLowerCase() == 'checkbox') {
									if (allEls[i].checked != true) trigger = false;
								}
							}
						}
						if (trigger) {
							if (allEls[i].onchange != null) allEls[i].onchange();
							if (allEls[i].onclick != null) allEls[i].onclick();
							if (allEls[i].onblur != null) allEls[i].onblur();
							trigger = false;
						}
					}
				}
			}
		


		function resetContainer(el) {
		
			if (el) {				
				
				var children = el.children;
				for (var i=0; i<children.length; i++) {				
					if (children[i].tagName.toLowerCase() == 'input') {
						if (children[i].type != null) {						
							if (children[i].type.toLowerCase() == 'radio') {
								children[i].checked = false;
								if (children[i].onclick != null) children[i].onclick();
							}
							else { if (children[i].type.toLowerCase() == 'checkbox') {
								children[i].checked = false;
								if (children[i].onclick != null) children[i].onclick();							
							
							}
							else { if (children[i].type.toLowerCase() == 'submit') {
								// do nothing									
							}
							else {
								children[i].value = '';								
							}}}
						}
					}
					else if (children[i].tagName.toLowerCase() == 'textarea') {
						children[i].value = '';						
					}
					else if (children[i].tagName.toLowerCase() == 'select') {						
						if (children[i].multiple != null && children[i].multiple) children[i].selectedIndex = -1;
						else children[i].selectedIndex = 0;
						if (children[i].onchange != null) children[i].onchange();
					}
					resetContainer(children[i]);
				}
			}
			return;
		}
		


		function validateNumeric(field, statusField, decimal, rangechk, rangelow, rangehigh, label, lowLabel, highLabel, unit)
		{
			initError();
			var ret = true;
			var passed = passNumValidation(field, statusField, decimal, rangechk, rangelow, rangehigh);
			if (!passed) {
				modifyField(field, decimal);
				ret = false;
			}
			if (rangechk == 'True') passed = validateRange(field, label, rangelow, rangehigh, lowLabel, highLabel, unit); 
			if (ret && !passed) ret = passed;
			return ret;
		}
		
	

		function checkNumeric(value, validChars)
		{
			var curChar = '';
			for (var i=0; i<value.length; i++) {
				curChar = value.charAt(i);
				if (validChars.indexOf(curChar) == -1) {
					return false;
				}
			}
			return true;
		}



	

		function modifyField(field, decimal)
		{
			var messages = getErrorMessages();
			var action = getErrorAction();
			var actions = action.split(',');
			if (messages != '' && action != '') {
				alert(messages);
				for (var i=0; i<actions.length; i++) {
					switch (actions[i]) {
						case ('clear'): field.value = ''; field.focus(); break;
						case ('remDec'): stripDecimals(field, decimal); break;
						case ('remComm'): stripCommas(field); break;
						default:
					}
				}
			}
		}
		
	

		var errs;
		function initError() {
			errs = new Array('message', 'code', 'action');
			errs['message'] = new Array();
			errs['code'] = new Array();
			errs['action'] = new Array();
		}
		function addError(message, code, action) {
			var numEls = errs['message'].length;
			errs['message'][numEls] = message;
			errs['code'][numEls] = code;
			errs['action'][numEls] = action;
		}
		function regError(message, code, action) {
			if (message == null) {
				message = errorCodeToMessage(code);
			}
			for(var i=0; i<errs['message'].length; i++) {
				if (errs['message'][i] == message) return;
			}
			addError(message, code, action);
		}
		function errorCodeToMessage(code) {
			var desc = '';
			if (typeof clientErrorMessages != 'undefined') {
				desc = clientErrorMessages(code);
			}
			else {
				switch (code) {
					case ('wholenumber'): 
						desc = 'Must be a whole number'; 
						break;
					case ('commas'): 
						desc = 'Contains commas'; 
						break;
					case ('invalidnum'): 
						desc = 'Not a valid number'; 
						break;
					default: 
						desc = '';
				}
			}
			return desc;
		}
		function getErrorMessages() {
			var messages = '';
			for(var i=0; i<errs['message'].length; i++) {
				if (messages != '' && errs['message'][i] != '') messages += '\n';
				messages += errs['message'][i];
			}
			return messages;
		}
		function getErrorAction() {
			var action = '';
			for(var i=0; i<errs['action'].length; i++) {
				if (action != '') action += ',';
				switch (errs['action'][i]) {
					case ('clear'): 
						action = 'clear';
						return action;
						break;
					case ('remDec'): 
						action += 'remDec';
						break;
					case ('remComm'): 
						action += 'remComm';
						break;
					default: 
				}
			}
			return action;
		}
		

		function smartSelect_closetValue(objSelect, strValue)
		{
			var j = objSelect.selectedIndex;
			var len = objSelect.options.length;
			for(i=0; i < len; i++)
			{
				var strText = objSelect.options[i].text.toUpperCase();
				if (strValue == strText.substr(0,strValue.length))
				{
					if (i != j) {
						var onchange = objSelect.getAttribute("onchange");
						objSelect.selectedIndex=i;
						if ((onchange != null) && (onchange != ""))
							//eval(onchange + " anonymous();");
							objSelect.onchange();
					}
					return true;    
				}        
			}
			return false;
		}
		
	

		function validateDateRange(el, label, format, lowVal, highVal, lowValDisplay, highValDisplay) {
		
			if (label == '') label = 'This date';
			switch (format) {
				case ('mmyyyy'):
					var val = new Date(insertDays(el.value));
					var high = new Date(insertDays(highVal));
					var low = new Date(insertDays(lowVal));
					break;
				default:
					var val = new Date(el.value);
					var high = new Date(highVal);
					var low = new Date(lowVal);
					break;
			}
			if (val != '') {
				if (highVal) {
					if (val.valueOf() > high.valueOf()) {
						alert(label + ' must be before ' + highValDisplay + '.');
						el.value = '';
						el.focus();
						return false;
					}
				}
				if (lowVal) {
					if (val.valueOf() < low.valueOf()) {
						alert(label + ' must be after ' + lowValDisplay + '.');
						el.value = '';
						el.focus();
						return false;
					}
				}
			}
			return true;
		}
		
		function insertDays(someDate) {
			var ret = someDate;
			if (someDate.length == 7) {
				ret = ret.substring(0,3)
	    			+ '01/'
	    			+ ret.substring(3,7);
		}
			return ret;
		}
		
	


		function isValidNumFmt(el, decimal)
		{
			//check if decimal exists in string
			var fieldname = el.value;
			var x = fieldname.length
			var i = (fieldname.indexOf('.')) + 1 
			var z = x - i
		       
			if ((fieldname.indexOf('.')) < 0) { 
				return true;
			}
			else {
				if (decimal == 0) {
					return false;
				} 
				else { 
					if (z > decimal) {
						return false;
					} 
				}    
			}
			return true;
		}
		
		
	function FirstFocus_FindControl( id, name ) {
		if ( typeof(document.getElementById) != "undefined" ) {
			var focusControl = document.getElementById(id);
			if ( focusControl != null ) {
				return focusControl;
			}
		}
		for( var i = 0; i < document.forms.length; i++ ) {
			var theForm = document.forms[i];
			var focusControl = theForm[name];
			if ( focusControl != null ) {
				return focusControl;
			}
		}
		return null;
	}
	
		function loadDropDown(aryList, list, blank, selVal, filter) {		
			if (list.id=='') {
				if (document.forms[0].device_brand) {
					list=document.forms[0].device_brand;
				}
			}		
			clearSelect(list);
			
			var addOption = true;
			var filters = new Array;
			if (filter) filters = filter.split(',');
			var optionEl = new Option();
					
			list.add(optionEl);	//Blank option
						
			if (aryList['value']) {
				for (var i=0; i<aryList['value'].length; i++ ) {
					addOption = true;
					for (var j=0; j<filters.length; j++) {
						if (filters[j] == aryList['value'][i]) addOption = false;
					}
					if (addOption) {
						optionEl = new Option();
						optionEl.value = aryList['value'][i];
						optionEl.text = aryList['text'][i];
						list.add(optionEl);
						if (aryList['value'][i] == selVal) {
							optionEl.selected = true;
						}
					}
				}
				if (list.onchange != null) list.onchange();
			}	
		}
			
			
		function clearSelect(list) {	
			while(list.length != 0) {
				list.remove(0);
			}
		}
		
		
		function checkReadOnly(obj,oldVal) {		
			var selectText = obj.options[obj.selectedIndex].text	
						
			if (selectText.substring(selectText.length-11,selectText.length) == '(Read Only)') {
				alert('You have Read Only access for the selected hospital.');		
				obj.value=oldVal;
				obj.focus();								
			}				
		}
		
		
	
	function getTodaysDate() {
		var today = 	new Date();
		var month = 	today.getMonth() + 1;
		var day = 		today.getDate();
		var year = 		today.getFullYear();
		
		return (month + '/' + day + '/' + year)
	}


   	function validateSSN(el) {
			if (!chkFmtSSN(el) && el.value != '') {
				alert('This SSN is invalid.');
				el.value = '';
				el.focus();
			}
		}
		/*
		'****************************************************************************
		'                              chkFmtSSN               	                    
		'****************************************************************************
		' Purpose:          Validate SSN:  check length to be nine (9), check 	    
		'					whether or not numeric, CHECK PREFIX, and 				
		'					format number.			       							 
		'                                                                           
		' Input Parameters: field  --  	ssn object									
		'                 															
		'        																	
		' Returns:          set field												
		'                                                                           
		' Called Routines:  errorMessages                                           
		'****************************************************************************
		*/
		function chkFmtSSN(field) 
		{
			var save = field.value;
			// valid numeric digits
			var digits = "0123456789";

			// valid other digits
			var front3 = "9CH9FN9EX9ch9fn9ex";
			var front0 = "000";
			
			// check for hyphens
			if (save.length > 9)
			{	
				if (save.charAt(3) != "-")
				{	
					//errorMessages("chkThirdSSN");
					//field.focus();
					return (false);
				}
				else
				{
					if (save.charAt(6) != "-")
					{	
						//errorMessages("chkSeventhSSN");
						//field.focus();
						return (false);
					}
				}		
				// separate ssn parts
				var save1 = save.substring(0, 3);
				//alert (save1);
				var save2 = save.substring(4, 6);
				//alert (save2);
				var save3 = save.substring(7, save.length);
				//alert (save3);
				var SSNval = save1 + save2 + save3;
				var last6 = save2 + save3;
			}
			else
			{
				// separate ssn parts
				var save1 = save.substring(0, 3);
				//alert (save1);
				var save2 = save.substring(3, 5);
				//alert (save2);
				var save3 = save.substring(5, save.length);
				//alert (save3);
				var SSNval = save1 + save2 + save3;
				var last6 = save2 + save3;
			}
			
			// check for alphas
			var allnumeric = true;
			for (var i = 0; i < SSNval.length; i++)
			{
				if (digits.indexOf(SSNval.charAt(i)) < 0)
				{
					allnumeric = false;
				}
			}

			var valid;
			if (allnumeric && SSNval.length == 9)
			{
					//alert("Valid SSN");
					valid = true;
			}
			else
			{
				// check for other digits
				var frontok = false;
				if (front3.indexOf(save1) != -1)
				{
					frontok = true;
				}
				
				var lastok = true;
				for (var i = 0; i < SSNval.length; i++)
				{
					if (digits.indexOf(last6.charAt(i)) < 0)
					{
						lastok = false;
					}
				}
			
				if (frontok && lastok && SSNval.length == 9)
				{
					//alert("Valid OTHER");
					valid = true;
				}
				else
				{
					//alert("Not valid");
					valid = false;
				}
			}
			
			//added this code to check for all repeating numbers (00000000,11111111,ect...)
			if (valid)
			{
				valid = false
				for (var i = 0; i < SSNval.length; i++)
				{
					if (SSNval.charAt(i) != SSNval.charAt(0))
					{
						//set i to 99 to break the loop and set valid to true
						i = 99;
						valid = true;
					}
				}
			}
			
			//added this code to check for 1st 3 numbers = 000 - WO63988
			if (valid)
			{
				valid = false
				if (front0.indexOf(save1) != 0)
				{
					valid = true;
				}
			}
			
			//added this code to check for 1st number = 8 -  WO63988
			if (valid)
			{
				valid = false
				if (SSNval.charAt(0) != 8)
				{
					valid = true;
				}
			}
			
			//added this code to check for 1st number = 9 followed by only CH or FN -  WO63988
			if (valid)
			{
				valid = false
				if (SSNval.charAt(0) == 9)
				{
					if ((save1.indexOf('CH') == 1) || (save1.indexOf('ch') == 1) || (save1.indexOf('FN') == 1) || (save1.indexOf('fn') == 1) || (save1.indexOf('EX') == 1) || (save1.indexOf('ex') == 1))
					{
						valid = true;
					}
				}
				else
				{
					valid = true;
				}
			}
			
			if (valid)
			{
				//alert("Im good.");
				var SSNfmt = save1 + "-" + save2 + "-" + save3;
				//formatted = (SSNfmt);
				return true;
			}
			else
			{
				// check if SSN not equal ""
				if (save != "")
				{
					//errorMessages("notValidSSN");
					var SSNfmt = save1 + "-" + save2 + "-" + save3;
					//field.focus();
					//document.forms[0].fldchar.value = SSNfmt;
					return false;
				}
			}
		}
	
	function showHideContainer1(containerName, el, vals, reset) {
				
			var show = false;
			var cnt;
			if (vals.substring(0,2) == "!=") {
				var vals = vals.substring(2,vals.length);
				var val = vals.split(',');
				show = true;
				if (el) {
					for (var i=0; i<val.length; i++) {
						if (el.value == val[i]) {
							if (el.tagName.toLowerCase() == 'input' && el.type != null) {
								if ((el.type.toLowerCase() == 'radio' || el.type.toLowerCase() == 'checkbox') && el.checked)	{
									show = false;
								}
								else	{
									//Leave show what it is.
								}
							}
							else	{
								show = false;
							}
						}
					}
				}				
			}
			else	{
				var val = vals.split(',');
				if (el) {
					for (var i=0; i<val.length; i++) {
						if (el.value == val[i]) {
							show = true;
							if (el.tagName.toLowerCase() == 'input' && el.type != null) {
								if (el.type.toLowerCase() == 'radio' && !el.checked) show = false;
								if (el.type.toLowerCase() == 'checkbox' && !el.checked) show = false;
							}
						}
						else {
							if (el.tagName.toLowerCase() == 'input' && el.type != null) {
								if (el.type.toLowerCase() == 'checkbox') return;
							}
						}
					}
				}
			}
			var containers = containerName.split(',');
			for (var j=0; j<containers.length; j++) {
				cnt = document.getElementById(containers[j]);
				if (cnt) {
					if (show) {
						cnt.style.display = getDisplayType(cnt);
						//To account for mac issue
						cnt.style.display = 'none';
						cnt.style.display = getDisplayType(cnt);
					}
					else {
						if (cnt.style.display != 'none') {
							cnt.style.display = 'none';
							if (reset) resetContainer(cnt);
						}
					}
				}
			}
			return false;
		}
		

	function isValidEmail(obj){
		//validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
		validRegExp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
		strEmail = obj.value;	  
	    if (strEmail!="") { 
			if (strEmail.search(validRegExp) == -1) {
				alert('Please enter a valid e-mail format.');	
				obj.focus();			
			}
		}	
	}

	function preEnroll() {
			var frm = document.forms[0]
			
			if ((!frm.contact[0].checked) && (!frm.contact[1].checked)) {
				alert('Please enter a type of contact.');				
				return;
			}
			
			if (frm.fname.value=="") {
				alert('Please enter a first name.');
				frm.fname.focus();
				return;
			}
			
			if (frm.lname.value=="") {
				alert('Please enter a last name.');
				frm.lname.focus();
				return;
			}
			
			if (frm.organization.value=="") {
				alert('Please enter an organization.');
				frm.organization.focus();
				return;
			}
			
			if (frm.title1.value=="") {
				alert('Please enter a title.');
				frm.title1.focus();
				return;
			}
			
			if (frm.address.value=="") {
				alert('Please enter an address.');
				frm.address.focus();
				return;
			}
			
			if (frm.email.value=="") {
				alert('Please enter an e-mail address.');
				frm.email.focus();
				return;
			}
			else {
				if (!isValidEmail(frm.email.value)) {
					alert('Please enter a valid e-mail format.');	
					frm.email.focus();
					return;			
				}			
			}
			
			if (frm.phone.value=="") {
				alert('Please enter a phone.');
				frm.phone.focus();
				return;
			}
			frm.submit();
		
		}
		
		
	function checkStatusField(el, status) {
		status = document.getElementById(el.id + '_i')
	
		if (el && status) {
			if ((el.value.length != 0) && (status.options[status.selectedIndex].value.length != 0)) {
				status.selectedIndex = 0;
				return false;
			}
			return true;
		}
	}

	function checkStatusParent(el, parent) {	
		var frm =  document.forms[0]
		var parentField = Left(el.id,el.id.length-2);			
		parent = frm[parentField]; 
		
		if (el && parent) {		
			if (el.options) {			
				if ((parent.value.length != 0) && (el.options[el.selectedIndex].value.length != 0)) {
					parent.value = '';
					return false;
				}
				return true;
			}
		}
	}
			
			
		function isValidZipCode(obj) {			
			var valid
			if (obj.value!="") {
				var re = /^\d{5}([\-]\d{4})?$/;
				
				
				valid = (re.test(obj.value));
				if (valid==false) {
					alert('Zip code format is invalid.  Please enter a valid format.');
					obj.focus();
				}
			}
			
		}



function checkPhoneNumber(obj) { 
 var valid 
 var re = /^\d{3}-\d{3}-\d{4}$/;
 valid = (re.test(obj.value));
 	
 if (obj.value!="") {
	if (valid==false) { 
	alert('Number format is invalid.  Please enter a valid format (###-###-####).');
	obj.focus();
	} 
 }
}

function checkFaxPhone(ctl1,ctl2) {	
	if (ctl1.value==ctl2.value) {
		alert('Phone and fax numbers may not be identical.');	
		ctl1.value="";
		ctl1.focus();
	}
}

function openEnrollment() {
	var strURL = "";
	if (document.domain=="localhost") {
		strURL = 'http://localhost/enrollment';			
	}
	if (document.domain=="tipintermacs") {
		strURL = 'https://tipintermacs/enrollment';					
	}
	if (document.domain=="qaintermacs") {
		strURL ='http://qaintermacs/enrollment';							
	}
	if (document.domain=="demointermacs") {
		strURL ='http://demointermacs/enrollment';						
	}
	
	if (strURL=="") {
		strURL='https://www.intermacs.org/enrollment';		
	}
	
	window.open(strURL);
		
}	


function Left(str, n){	
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

var bToggleContainer = true;
var valErr=false;

//function createReminderSelect() {
//	var frm=document.forms[0];
	
//	if (frm.ae_reminder_0.checked==false) {		
//		if ((frm.rehospitalization_0.checked) || (frm.death_0.checked)) {		
//			frm.ae_reminder_0.checked=true;
//		}
//	}	
//}

function createReminderSelect() {	
	var frm=document.forms[0];	
	
	if (frm.ae_reminder_0.checked) {
		frm.hidReminder.value='Y';
	}
	else {
		frm.hidReminder.value='';
	}
}	

	function createReminderTriggers() {
			var frm = document.forms[0];
			var display = false;	
								
			if (frm.death_0.checked==true) {
				display=true;
			}
			
			if (frm.rehospitalization_0.checked==true) {
				display=true;
			}			
			
			if ((display==true) && (frm.ae_reminder_0.checked==false)) {
				frm.ae_reminder_0.checked=true;											
			}	
			else {	
				if (display==false) {
					if ((frm.hidReminder.value=='') && (frm.ae_reminder_0.checked)) {										
						frm.ae_reminder_1.checked=true;		
					
					}	
				}						
			}			
		}
		
		
function createCheckReminder() {
	var frm = document.forms[0];	
	var valRemErr=false;		
	
	if (frm.ae_reminder_1.checked) {
		if (frm.death_0.checked) {
			alert('Section is required when selecting yes for is the patient deceased.');	
			frm.death_0.focus();	
			valRemErr=true;				
		}	
				
		if ((frm.rehospitalization_0.checked) && (valRemErr==false)) {
			alert('Section is required when selecting yes for rehospitalization.');	
			frm.rehospitalization_0.focus();
			valRemErr=true;						
		}	
		
		if (valRemErr==true) {
			frm.ae_reminder_0.checked=true;		
			//bToggleContainer=false;	
			valRemErr=false;			
		}	
	}				
}

function checkInfection() {
	var frm=document.forms[0];
	//var valErr=false;
	//alert('CAE');	
	//alert('Death value=' + frm.PatientReportDetail_PatientDeath_primary_cod.value);
			//if (frm.PatientReportDetail_ae_infection_0.checked==false) {
			//	frm.PatientReportDetail_ae_infection_0.checked=true;
			
			//}		
	if (frm.PatientReportDetail_ae_infection_1.checked) {					
		if ((frm.PatientReportDetail_PatientDeath_primary_cod.value==21) && (valErr==false)) {			  
			alert('Infection has been selected as the primary cause of death.');	
			frm.PatientReportDetail_PatientDeath_primary_cod.focus();	
			valErr=true;
		}
					
		if ((frm.PatientReportDetail_PatientDeath_secondary_cod.value==21) && (valErr==false)) {			  
			alert('Infection has been selected as the secondary cause of death.');	
			frm.PatientReportDetail_PatientDeath_secondary_cod.focus();	
			valErr=true;
		}
					
		if ((frm.PatientReportDetail_PatientDeath_secondary_cod2.value==21) && (valErr==false)) {			  
			alert('Infection has been selected as the secondary cause of death.');	
			frm.PatientReportDetail_PatientDeath_secondary_cod2.focus();	
			valErr=true;
		}				
								
		if ((frm.PatientReportDetail_PatientReHospitalization_admission_reason_7.checked==true) && (valErr==false)) {			
			alert('Infection has been selected as rehospitalization reason for admission.');
			frm.PatientReportDetail_PatientReHospitalization_admission_reason_7.focus();	
			valErr=true;			
		}
		
		if (valErr==true) {
			frm.PatientReportDetail_ae_infection_0.checked=true;	
			bToggleContainer=false;	
			valErr=false;		
		}	
	}	
}


function checkNeuro() {
			var frm=document.forms[0];
			//var valErr=false;
	if (frm.PatientReportDetail_ae_neuro_1.checked)  {					
			if (frm.PatientReportDetail_PatientDeath_primary_cod.value==100) {			  
				alert('CNS has been selected as the primary cause of death.');	
				frm.PatientReportDetail_PatientDeath_primary_cod.focus();	
				valErr=true;
			}
				
			if ((frm.PatientReportDetail_PatientDeath_secondary_cod.value==100) && (valErr==false)) {			  
				alert('CNS has been selected as the secondary cause of death.');	
				frm.PatientReportDetail_PatientDeath_secondary_cod.focus();	
				valErr=true;
			}
				
			if ((frm.PatientReportDetail_PatientDeath_secondary_cod2.value==100) && (valErr==false)) {			  
				alert('CNS has been selected as the secondary cause of death.');	
				frm.PatientReportDetail_PatientDeath_secondary_cod2.focus();	
				valErr=true;	
			}	
			
			if ((frm.PatientReportDetail_PatientReHospitalization_admission_reason_15.checked==true) && (valErr==false)) {
				alert('Neurological dysfunction has been selected as rehospitalization reason for admission.');
				frm.PatientReportDetail_PatientReHospitalization_admission_reason_15.focus();	
				valErr=true;				
			}	
			
			if (valErr==true) {
				frm.PatientReportDetail_ae_neuro_0.checked=true;	
				bToggleContainer=false;		
				valErr=false;		
			}	
		
		}
	}

function checkDeath() {
	//alert('Check Death');
	var frm=document.forms[0];
	//var valErr=false;
	if (frm.PatientReportDetail_death_1.checked)  {	
		if (frm.PatientReportDetail_DeviceMalfunction_ae_device_px_death_0.checked==true) {
			alert('Device malfunction adverse event cause patient death has already been indicated.');		
			frm.PatientReportDetail_DeviceMalfunction_ae_device_px_death_0.focus();
			valErr=true;
		}
				
		if ((frm.PatientReportDetail_PatientExplant_explant_reason.value==2) && (valErr==false)) {
			alert('Explant reason has already been indicated as death.');
			frm.PatientReportDetail_PatientExplant_explant_reason.focus();
			valErr=true;			   
		}
				
		if ((frm.PatientReportDetail_AEInfection_contribute_death_0.checked==true) && (valErr==false)) {
			alert('Infection contributing to death has already been indicated.');
			frm.PatientReportDetail_AEInfection_contribute_death_0.focus();
			valErr=true;		
		}								
				
    	if ((frm.PatientReportDetail_NeurologicalDysfunction_ae_neuro_px_death_0.checked==true) && (valErr==false)) {
			alert('Neurological dysfunction adverse event contributing to the patient death has already been indicated.');
			frm.PatientReportDetail_NeurologicalDysfunction_ae_neuro_px_death_0.focus();	
			valErr=true;		
		}			
		
		//if (frm.PatientReportDetail_ae_reminder_0.checked) {
		//	alert('Device malfunction has been selected as the explant reason.');	
		//	frm.PatientReportDetail_PatientExplant_explant_reason.focus();	
		//	valErr=true;				   
		//}	
				
		if (valErr==true) {
			frm.PatientReportDetail_death_0.checked=true;	
			bToggleContainer=false;		
			valErr=false;		
		}	
		else {		
			//alert(frm.PatientReportDetail_hidDeath.value);
				
			//if ((frm.PatientReportDetail_hidDeath.value=='n') && (frm.PatientReportDetail_death_0.checked)) {
			//	document.getElementById('con_death').style.display=="none"
			//	frm.PatientReportDetail_death_1.checked	
			
			//}		
		}			
	}
}

function checkDevice() {
	var frm=document.forms[0];
	//var valErr=false;
	
	if (frm.PatientReportDetail_ae_device_1.checked) {	
		if ((frm.PatientReportDetail_PatientDeath_device_func_norm_1.checked==true) && (valErr==false)) {
			alert('Yes has been selected for was device functioning normally.');	
			frm.PatientReportDetail_PatientDeath_device_func_norm_1.focus();	
			valErr=true;			
		}		
				    
		if ((frm.PatientReportDetail_PatientDeath_primary_cod.value==12) && (valErr==false)) {			  
			alert('Device malfunction has been selected as the primary cause of death.');	
			frm.PatientReportDetail_PatientDeath_primary_cod.focus();	
			valErr=true;	
		}
					
		if ((frm.PatientReportDetail_PatientDeath_secondary_cod.value==12) && (valErr==false)) {			  
			alert('Device malfunction has been selected as the secondary cause of death.');	
			frm.PatientReportDetail_PatientDeath_secondary_cod.focus();	
			valErr=true;	
		}
					
		if ((frm.PatientReportDetail_PatientDeath_secondary_cod2.value==12) && (valErr==false)) {			  
			alert('Device malfunction has been selected as the secondary cause of death.');	
			frm.PatientReportDetail_PatientDeath_secondary_cod2.focus();	
			valErr=true;		
		}
		//put back in!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!			
		//if (((frm.PatientReportDetail_PatientExplant_explant_reason.value==3) || (frm.PatientReportDetail_PatientExplant_explant_reason.value==4)) && (valErr==false))) {
		//	alert('Device malfunction has been selected as the explant reason.');	
		//	frm.PatientReportDetail_PatientExplant_explant_reason.focus();	
		//	valErr=true;				   
		//}	
		
			if ((frm.PatientReportDetail_PatientReHospitalization_admission_reason_13.checked==true) && (valErr==false)) {
				alert('Device malfunction has been selected as rehospitalization reason for admission.');
				frm.PatientReportDetail_PatientReHospitalization_admission_reason_13.focus();	
				valErr=true;				
			}	
		
		
		if (valErr==true) {
			frm.PatientReportDetail_ae_device_0.checked=true;	
			bToggleContainer=false;	
			valErr=false;			
		}		
	}		
}

	
function checkExplant() {
	var frm = document.forms[0];	
	//var valErr=false;		
	
	if ((frm.PatientReportDetail_explant_1.checked) && (valErr==false)) {
		if (frm.PatientReportDetail_DeviceMalfunction_device_explant_0.checked==true) {
			alert('Device explanted has been selected.');	
			frm.PatientReportDetail_DeviceMalfunction_device_explant_0.focus();
			valErr=true;		
		}	
		
		if (valErr==true) {
			frm.PatientReportDetail_DeviceMalfunction_device_explant_0.checked=true;	
			bToggleContainer=false;	
			valErr=false;			
		}	
	}				
}


function checkReHosp() {
	var frm = document.forms[0];	
	
	if (frm.PatientReportDetail_rehospitalization_1.checked)  {	 
		if (frm.PatientReportDetail_AEInfection_ae_infection_intervention.value==2) {
			alert('Surgical therapy has been selected.');	
			frm.PatientReportDetail_DeviceMalfunction_ae_infection_intervention.focus();
			valErr=true;			
		}		
				
		if ((frm.PatientReportDetail_NeurologicalDysfunction_surg_intervention_0.checked==true) && (valErr==false)) {
			alert('Surgical procedure required has been selected.');	
			frm.PatientReportDetail_DeviceMalfunction_surg_intervention_0.focus();
			valErr=true;	
		}
				
		if ((frm.PatientReportDetail_DeviceMalfunction_surg_proc_0.checked==true) && (valErr==false)) {
			alert('Surgical procedure required has been selected.');	
			frm.PatientReportDetail_DeviceMalfunction_surg_proc_0.focus();
			valErr=true;	
		}	
		
		if (valErr==true) {
			frm.PatientReportDetail_rehospitalization_0.checked=true;	
			bToggleContainer=false;		
			valErr=false;		
		}		
	}				
}

function checkReminder() {
	var frm = document.forms[0];	
	//var valErr=false;		
	
	if (frm.PatientReportDetail_ae_reminder_1.checked) {
		if (frm.PatientReportDetail_death_0.checked)  {
			alert('Section is required when selecting yes for is the patient deceased.');	
			frm.PatientReportDetail_death_0.focus();
			valErr=true;		
		}	
				
		if (frm.PatientReportDetail_rehospitalization_0.checked)  {
			alert('Section is required when selecting yes for rehospitalization.');	
			frm.PatientReportDetail_rehospitalization_0.focus();
			valErr=true;		
		}	
		
		if (valErr==true) {
			frm.PatientReportDetail_ae_reminder_0.checked=true;
			bToggleContainer=false;		
			valErr=false;		
		}	
	}				
}
function deathSelect(obj) {
	//alert('death select');
	var frm=document.forms[0];		
	if (frm.PatientReportDetail_hidDeathCheck.value=='') {
		if (obj.value=='Y') {
			frm.PatientReportDetail_hidDeath.value='Y';
		}
		else {
			frm.PatientReportDetail_hidDeath.value='';
		}
	}
	else {
		alert('Death information has already been entered.  Please return to patient overview page for details.');	
		frm.PatientReportDetail_hidDeath.value='';
		frm.PatientReportDetail_death_1.checked=true;		
	}	
}

function infectionSelect(obj) {
	var frm=document.forms[0];	
	if (obj.value=='Y') {
		frm.PatientReportDetail_hidAEInfection.value='Y';
	}
	else {
		frm.PatientReportDetail_hidAEInfection.value='';
	}
	
}

function neuroSelect(obj) {
	var frm=document.forms[0];	
	if (obj.value=='Y') {
		frm.PatientReportDetail_hidAENeuro.value='Y';
	}
	else {
		frm.PatientReportDetail_hidAENeuro.value='';
	}
}	

function deviceSelect(obj) {
	var frm=document.forms[0];	
	if (obj.value=='Y') {
		frm.PatientReportDetail_hidAEDevice.value='Y';
	}
	else {
		frm.PatientReportDetail_hidAEDevice.value='';
	}
}	

function explantSelect(obj) {
	var frm=document.forms[0];		
	
	if (frm.PatientReportDetail_hidExplantCheck.value=='') {
		if (obj.value=='Y') {
			frm.PatientReportDetail_hidExplant.value='Y';
		}
		else {
			if (frm.PatientReportDetail_hidMultipleDevice.value=='1') {
				alert('A new device for this patient has been entered since explant.');
				frm.PatientReportDetail_hidExplant.value='Y';
				frm.PatientReportDetail_explant_0.checked=true;		
			}
			else {
				frm.PatientReportDetail_hidExplant.value='';
			}
		}
	}
	else {
		alert('Explant information has already been entered.  Please return to patient overview page for details.');	
		frm.PatientReportDetail_hidExplant.value='';
		frm.PatientReportDetail_explant_1.checked=true;		
	}	
}	

function rehospSelect(obj) {
	var frm=document.forms[0];	
	if (obj.value=='Y') {
		frm.PatientReportDetail_hidExplant.value='Y';
	}
	else {
		frm.PatientReportDetail_hidExplant.value='';
	}
}	

function reminderSelect(obj) {
	var frm=document.forms[0];	
	if (obj.value=='Y') {
		frm.PatientReportDetail_hidReminder.value='Y';
	}
	else {
		frm.PatientReportDetail_hidReminder.value='';
	}
}	

	function checkDeathTriggers() {
			var frm = document.forms[0];
			var display = false;	
		
		    if (frm.hidDeathCheck!='') {					
				if (frm.PatientReportDetail_PatientExplant_explant_reason.value==2) {
					display=true;								   
				}
				
				if (frm.PatientReportDetail_AEInfection_contribute_death_0.checked==true) {
					display=true;					
				}
				
				if (frm.PatientReportDetail_DeviceMalfunction_ae_device_px_death_0.checked==true) {
					display=true;					
				}
				
				if (frm.PatientReportDetail_NeurologicalDysfunction_ae_neuro_px_death_0.checked==true) {
					display=true;					
				}
				
				if ((display==true) && (frm.PatientReportDetail_death_0.checked==false)) {		
					frm.PatientReportDetail_death_0.checked=true;		
					//document.location = '#ae_death_nav';		
					frm.PatientReportDetail_death_0.focus();	
					document.getElementById('con_death').style.display="block";	
				}	
				else {
					if (display==false) {
						if ((frm.PatientReportDetail_hidDeath.value=='') && (frm.PatientReportDetail_death_0.checked)) {
							document.getElementById('con_death').style.display="none";
							frm.PatientReportDetail_death_1.checked=true;
						
							resetContainer(document.getElementById('con_death'));					
						}	
					}						
				}		
			}	
		}			
		
		function checkInfectionTriggers() {
			var frm = document.forms[0];
			var display = false;
			
			if (frm.PatientReportDetail_PatientDeath_primary_cod.value==21) {			  
				display=true;
			}
				
			if (frm.PatientReportDetail_PatientDeath_secondary_cod.value==21) {			  
				display=true;
			}
				
			if (frm.PatientReportDetail_PatientDeath_secondary_cod2.value==21) {			  
				display=true;
			}				
			//alert('adm=' + frm.PatientReportDetail_PatientReHospitalization_admission_reason_7.checked);							
			if (frm.PatientReportDetail_PatientReHospitalization_admission_reason_7.checked==true) {				
				display=true;				
			}
			
			if ((display==true) && (frm.PatientReportDetail_ae_infection_0.checked==false)) {				
				frm.PatientReportDetail_ae_infection_0.checked=true;				
				//document.location = '#ae_infect_nav';	
				frm.PatientReportDetail_ae_infection_0.focus();
				document.getElementById('con_aeinfection').style.display="block";		
			}	
			else {
				if (display==false) {
					if ((frm.PatientReportDetail_hidAEInfection.value=='') && (frm.PatientReportDetail_ae_infection_0.checked)) {
						document.getElementById('con_aeinfection').style.display="none";						
						frm.PatientReportDetail_ae_infection_1.checked=true;
						//document.location = '#ae_infect_nav'	
						//alert(document.location);
						resetContainer(document.getElementById('con_aeinfection'));				
					}	
				}						
			}					
		
		}
				
		function checkNeuroTriggers() {
			var frm = document.forms[0];
			var display = false;
			
			if (frm.PatientReportDetail_PatientDeath_primary_cod.value==100) {			  
				display=true;
			}
				
			if (frm.PatientReportDetail_PatientDeath_secondary_cod.value==100) {			  
				display=true;
			}
				
			if (frm.PatientReportDetail_PatientDeath_secondary_cod2.value==100) {			  
				display=true;
			}	
			
			if (frm.PatientReportDetail_PatientReHospitalization_admission_reason_15.checked==true) {
				display=true;				
			}	
			
			if ((display==true) && (frm.PatientReportDetail_ae_neuro_0.checked==false)) {							
				frm.PatientReportDetail_ae_neuro_0.checked=true;
				//document.location = '#ae_neuro_nav';	
				frm.PatientReportDetail_ae_neuro_0.focus();	
				document.getElementById('con_aeneuro').style.display="block";			
			}	
			else {
				if (display==false) {
					if ((frm.PatientReportDetail_hidAENeuro.value=='') && (frm.PatientReportDetail_ae_neuro_0.checked)) {
						
						frm.PatientReportDetail_ae_neuro_1.checked=true;	
						document.getElementById('con_aeneuro').style.display="none";
						resetContainer(document.getElementById('con_aeneuro'));	
						//document.location = '#ae_death_nav';
															
					}	
				}						
			}						
		}
		
		
		function checkDeviceTriggers() {
				var frm = document.forms[0];
				var display = false;
				if (frm.PatientReportDetail_PatientDeath_device_func_norm_1.checked==true) {
					display=true;				
				}		
			    
				if (frm.PatientReportDetail_PatientDeath_primary_cod.value==12) {			  
				display=true;
				}
				
				if (frm.PatientReportDetail_PatientDeath_secondary_cod.value==12) {			  
				display=true;
				}
				
				if (frm.PatientReportDetail_PatientDeath_secondary_cod2.value==12) {			  
				display=true;
				}
				
				if ((frm.PatientReportDetail_PatientExplant_explant_reason.value==3) || (frm.PatientReportDetail_PatientExplant_explant_reason.value==4)) {
				display=true;			   
				}
				
				
				if (frm.PatientReportDetail_PatientReHospitalization_admission_reason_13.checked==true) {
					display=true;				
				}
				
				if ((display==true) && (frm.PatientReportDetail_ae_device_0.checked==false)) {
					frm.PatientReportDetail_ae_device_0.checked=true;
					//	document.location = '#ae_device_nav';		
					frm.PatientReportDetail_ae_device_0.focus();
					document.getElementById('con_aedevice').style.display="block";			
				}	
				else {
					if (display==false) {
						if ((frm.PatientReportDetail_hidAEDevice.value=='') && (frm.PatientReportDetail_ae_device_0.checked)) {
							document.getElementById('con_aedevice').style.display="none";						
							frm.PatientReportDetail_ae_device_1.checked=true;	
							resetContainer(document.getElementById('con_aedevice'));				
						}	
					}						
				}								
						
		}
		
		function checkExplantTriggers() {
			var frm = document.forms[0];
			var display = false;
		
			if (frm.PatientReportDetail_DeviceMalfunction_device_explant_0.checked==true) {
				frm.PatientReportDetail_explant_0.checked=true;
				//document.location = '#ae_explant_nav';	
				frm.PatientReportDetail_explant_0.focus();	
				document.getElementById('con_explant').style.display="block";	
				display=true;			
			}
			else {
				if (display==false) {
					if ((frm.PatientReportDetail_hidExplant.value=='') && (frm.PatientReportDetail_explant_0.checked)) {
						document.getElementById('con_explant').style.display="none";						
						frm.PatientReportDetail_explant_1.checked=true;		
						resetContainer(document.getElementById('con_explant'));			
					}	
				}						
			}			
		}
		
		
		function checkRehospTriggers() {
			var frm = document.forms[0];
			var display = false;	
		
			if (frm.PatientReportDetail_AEInfection_ae_infection_intervention.value==2) {
				display=true;				
			}		
			
			if (frm.PatientReportDetail_NeurologicalDysfunction_surg_intervention_0.checked==true) {
				display=true;
			}
			
			if (frm.PatientReportDetail_DeviceMalfunction_surg_proc_0.checked==true) {
				display=true;
			}			
			
			if ((display==true) && (frm.PatientReportDetail_rehospitalization_0.checked==false)) {
				frm.PatientReportDetail_rehospitalization_0.checked=true;
				//document.location = '#ae_rehosp_nav';		
				frm.PatientReportDetail_rehospitalization_0.focus();
				document.getElementById('con_rehospitalization').style.display="block";							
			}	
			else {	
				if (display==false) {
					if ((frm.PatientReportDetail_hidRehosp.value=='') && (frm.PatientReportDetail_rehospitalization_0.checked)) {
						document.getElementById('con_rehospitalization').style.display="none";						
						frm.PatientReportDetail_rehospitalization_1.checked=true;	
						resetContainer(document.getElementById('con_rehospitalization'));			
					}	
				}						
			}			
		}
		
		function checkReminderTriggers(val) {
			var frm = document.forms[0];
			var display = false;	
								
			if (frm.PatientReportDetail_death_0.checked==true) {
				display=true;
			}
			
			if (frm.PatientReportDetail_rehospitalization_0.checked==true) {
				display=true;
			}			
			
			if ((display==true) && (frm.PatientReportDetail_ae_reminder_0.checked==false)) {
				frm.PatientReportDetail_ae_reminder_0.checked=true;
				//document.location = '#ae_rehosp_nav';		
				//frm.PatientReportDetail_ae_reminder_0.focus();
				if (val=='death') {
					document.getElementById('con_death').style.display="block";					
				}
				else {
					document.getElementById('con_ae_reminder').style.display="block";					
				}								
			}	
			else {	
				if (display==false) {
					if ((frm.PatientReportDetail_hidReminder.value=='') && (frm.PatientReportDetail_ae_reminder_0.checked)) {
						document.getElementById('con_ae_reminder').style.display="none";						
						frm.PatientReportDetail_ae_reminder_1.checked=true;		
						resetContainer(document.getElementById('con_ae_reminder'));
					}	
				}						
			}			
		}
		
		
function populatePhase(obj, valPhase) {
	var frm = document.forms[0];
	
	if (frm.tissue_obtain_0) {
		if (frm.lv_tissue_obtain_0.checked==true)  {	
			if (valPhase==2) {
				frm.tissue_phase_1.checked=true;		
				frm.tissue_phase_0.disabled=true;
			}
			else {
				frm.tissue_phase_0.checked=true;	
				frm.tissue_phase_1.disabled=true;		
			}	
		}	
	}		
	
	//if (frm.rv_tissue_obtain_0)  {	
	//	if (frm.rv_tissue_obtain_0.checked==true)  {	
	//		if (valPhase==2) {
	//			frm.rv_tissue_phase_1.checked=true;	
	//			frm.rv_tissue_phase_0.disabled=true;		
	//		}
	//		else {
	//			frm.rv_tissue_phase_0.checked=true;		
	//			frm.rv_tissue_phase_1.disabled=true;			
	//		}	
	//	}	
	//}
}
	
function bloodTissuePhase(obj, valPhase) {
	var frm = document.forms[0];
	//alert(obj.id);
	//alert(valPhase);
	
	if (obj.id=='lv_tissue_phase') {			
		if ((frm.lv_tissue_phase_0.checked==true) && (valPhase== 2)) {
			alert('1');	
			frm.lv_tissue_phase_1.checked=true;	
		}
		
		if ((frm.lv_tissue_phase_1.checked==true) && (valPhase== 1)) {
			alert('2');	
			frm.lv_tissue_phase_0.checked=true;		
		}
	}
}

function addNewDevice() {
	var frm = document.forms[0];
	frm.submit();
}

function checkExplantTransplantDates() {
	var frm = document.forms[0];
	
	if ((frm.PatientReportDetail_PatientExplant_explant_dt.value!="") && (frm.PatientReportDetail_PatientExplant_tx_dt.value!="")) {
		var valExplant = new Date(frm.PatientReportDetail_PatientExplant_explant_dt.value);	
		var valTx = new Date(frm.PatientReportDetail_PatientExplant_tx_dt.value);	
	
		if (valTx < valExplant) {
			alert('Transplant date may not preceed explant date.');
			frm.PatientReportDetail_PatientExplant_tx_dt.value="";
		}
	}
}

function checkRehospDates() {
	var frm = document.forms[0];
	
	if ((frm.PatientReportDetail_PatientReHospitalization_discharge_dt.value!="") && (frm.PatientReportDetail_PatientReHospitalization_admission_dt.value!="")) {
		var valAdmission = new Date(frm.PatientReportDetail_PatientReHospitalization_admission_dt.value);	
		var valDischarge = new Date(frm.PatientReportDetail_PatientReHospitalization_discharge_dt.value);	
	
		if (valDischarge < valAdmission) {
			alert('Discharge associated with this hospitalization date may not preceed date of admission date.');
			frm.PatientReportDetail_PatientReHospitalization_discharge_dt.value="";
		}
	}
}


function getAge(_data) { 
	var frm = document.forms[0];  
    var _milliseconds_in_a_day = 1000*60*60*24;
    var birth = new Date(_data)
    var today = new Date();
    var days_since_birth = Math.ceil((today - birth)/_milliseconds_in_a_day) - 1;
    var age = Math.floor(days_since_birth/365);
    alert(_data);
    if (_data != "") {
		if (age >=19) {
			document.getElementById('conAcademicProg').style.display = "none"
			document.getElementById('conAcademicLevel').style.display  = "none"
			document.getElementById('conWorkIncome').style.display  = "block"
			frm.hidAdult.value="y"
			//document.getElementById('conWorkNoStatus').style.display  = "block"
			//document.getElementById('conWorkYesStatus').style.display  = "block"    
		}
		else {
			document.getElementById('conAcademicProg').style.display  = "block"
			document.getElementById('conAcademicLevel').style.display = "block"
			document.getElementById('conWorkIncome').style.display  = "none"
			//document.getElementById('conWorkNoStatus').style.display  = "none"
			//document.getElementById('conWorkYesStatus').style.display  = "none"
			frm.hidAdult.value="n"
		} 
  
   }
}
				
		
function saveForm() {
	var frm = document.forms[0];
	frm.hidSubmit.value="";
	frm.submit();
}


function submitForm() {
	var frm = document.forms[0];
	frm.hidSubmit.value="1";
	frm.submit();

}



	function convertLength(fieldInput, inUnit, fieldInput2, fieldOut1, fieldOut2, outUnit,decimal, rangechk, rangelow, rangehigh, conDecimals, reset)
		{
			if (passNumValidation(fieldInput, '', decimal, rangechk, rangelow, rangehigh))
			{
				var vCM

				//**************************************************
				//  Get number of decimals for rounding output
				//**************************************************
				if (conDecimals != "") 
				{
					var vDec = Math.pow(10, conDecimals)
				}
				else
				{
					var vDec = Math.pow(10, decimal)
				}

				//**************************************************
				//  Convert to cm first
				//**************************************************
				if (inUnit != 0)
				{
					vCM = convertToCM(fieldInput, fieldInput2,inUnit );
				}
				else
				{
					vCM = eval(fieldInput.value)
				}

				//**************************************************
				//  Convert from cm to the desired output unit
				//**************************************************

				///				INCHES
				if (outUnit == 1)
				{
					if (!isNaN(vCM)) {
						fieldOut1.value = Math.round( (vCM / 2.54) * vDec)/vDec;
					}
					else {
						if (reset) fieldOut1.value = '';
					}
				}

				///				FEET AND INCHES
				else if (outUnit == 5)
				{
					var allin = (vCM / 2.54);

					var FTval = parseInt((allin / 12));
					var INval = Math.round( ( (allin - (FTval * 12) ) * vDec))/vDec;
		
					if (INval == 12)
					{
						FTval = (FTval + 1);
						INval = "0";
					}
					if (!isNaN(FTval)) {
						fieldOut1.value = FTval;
					}
					else {
						if (reset) fieldOut1.value = '';
					}
					if (!isNaN(INval)) {
						fieldOut2.value = INval;
					}
					else {
						if (reset) fieldOut2.value = '';
					}
				}

				///				CENTIMETERS
				else		
				{
					if (!isNaN(vCM)) {
						alert(vCM);
					    alert(vDec);
						fieldOut1.value = Math.round(vCM * vDec )/ vDec;
						alert(fieldOut1.value);
						if (fieldOut1.value > 225) fieldOut1.value = 225;
					}
					else {
						if (reset) fieldOut1.value = '';
					}
				}
			}
		}
		
		
		
			function convertToCM(fieldInput, fieldInput2, inUnit)
		{
			var vTotal, FtVal, InVal
			if (inUnit == 1)			// input is inches
			{

				if (fieldInput2.value == "")
				{ 
					FtVal = 0;
				}
				else
				{
					if (fieldInput.id == fieldInput2.id)
					{
						FtVal = 0
					}					
					else
					{
						FtVal = eval(fieldInput2.value) * 12;
					}
				}

				vTotal = (eval(FtVal) + eval(fieldInput.value)) * 2.54;
			}
			else if (inUnit == 2)		// input is feet
			{
				FtVal = eval(fieldInput.value) * 12;
				if (fieldInput2.value == "")
				{ 
					InVal = 0;
				}
				else
				{
					InVal = eval(fieldInput2.value);
				}

				vTotal = (eval(FtVal) + eval(InVal)) * 2.54;
			}
			else
			{
				// This will be used when other units of measure are needed.
			}

			return vTotal;
		}		
		
	