	/*----------------------------------------------------------------------------*\
	* General Utilities Scripts.
	*	Donald F. Sivori Jr. June 19, 2001
	*	gcr & Associates
	*
	* Module: $$Workfile: genutil.js $ 
	* Revision: $$Revision: 6 $ 
	* Last Change By: $$Author: Dsivori $ 
	* Last Change Date: $$Modtime: 1/19/04 9:21a $
	*	
	*	Description:
	*	GenUtil.js contains various utility functions useful for script development.
	*
	*		* Browser Info
	*	function GetBrowserType()
	*	function IsW3CDomBrowser()
	*		* To Find Things *
	*	function GetFormElemByID(currDoc, elemID )
	*	function GetBlockByID(currDoc, elemID)
	*	function GetImageByID(currDoc, imageID)
	*
	*		* To Change Visibility *
	*	function TogglePopup(popupID, srcElem)
	*	function HidePopup(popupID)
	*	function ShowPopup(popupID)
	*	function ToggleVisibility(popupID)
	*	function ClipRect(top, left, bottom, right)
	*
	*		* To get/Set values on input elements (Text, buttons, lists, etc.) *
	*	function GetSelections(listID)
	*	function GetSelectionsString(listID)
	*	function SetSelected(selectID, selectValue)
	*	function SetNotSelected(selectID, selectValue)
	*	function ClearSelect(selectID)
	*	function GetRadioElem(radioID, radioVal)
	*	function ClearRadioButtons(elemID)
	*	function GetRadioValue(radioID)
	*	function SetRadio(radioID, radioValue, checkedVal)
	*	function SetValue(inputID, inputValue)
	*
	*		* MISC. *
	*	function ConvertToHTML(conString)
	*	function StyleToLayer(styleString)
	*	function StartBlock(blockID, styleString)
	*	function EndBlock(blockID)
	*	function ShowDialog(winURL, winName,winWidth,winHeight)
	*	function ParseDateTime(dateTimeStr)
	\*----------------------------------------------------------------------------*/
 /****************** HISTORY*****************\
 ** $History: genutil.js $
 * 
 * *****************  Version 6  *****************
 * User: Dsivori      Date: 1/19/04    Time: 11:17a
 * Updated in $/SafeTnet/Common/JavaScriptLib
 * Strengthen validation on event id.
 * 
 * *****************  Version 5  *****************
 * User: Dsivori      Date: 1/14/04    Time: 10:04a
 * Updated in $/SafeTnet/Common/JavaScriptLib
 * Remove debug messaages.
 * 
 * *****************  Version 4  *****************
 * User: Dsivori      Date: 1/14/04    Time: 9:58a
 * Updated in $/SafeTnet/Common/JavaScriptLib
 * Remove db version line
 * 
 * *****************  Version 3  *****************
 * User: Dsivori      Date: 1/14/04    Time: 9:57a
 * Updated in $/SafeTnet/Common/JavaScriptLib
 * Add ParseDateTime function.
 * 
 \*******************************************/

	var ns4 = 1;
	var ns6 = 2;
	var ie5 = 3;
	
	var browserType;
	if (document.layers)
		browserType = ns4;
	
	if (document.getElementById && !document.all)
		browserType = ns6;
		
	if (document.all && document.getElementById)
		browserType = ie5;
			
	function GetBrowserType()
	{
	// Determine Browser
		

		return browserType;
	}	
	
	function IsW3CDomBrowser()
	{
		if (document.getElementById)
			return true;
		else
			return false;	
	}
	
	function GetXMLHttpRequest()
	{
		var xmlHttp;
		
		switch (browserType)
		{
		case ie5:
			try
			{
				xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.4.0")
			}
			catch (e)
			{
			try
			{
				xmlHttp = new ActiveXObject("MSXML2.XMLHTTP")
			}
			catch (e)
			{
				try
				{
					var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
				}
				catch (E)
				{
					xmlHttp = false;
				}
			
			}
			
			}
		case ns6:
			if (!xmlHttp)
			{
				try
				{
				xmlHttp = new XMLHttpRequest();
				}
				catch(e)
				{
				xmlHttp = false;
				}
			}
		}
		return xmlHttp;	
	}
	
	/******************************************************************************\
	* Routines to find web document elements by passing their ID.
	\******************************************************************************/
	
	/******************************************************************************\
	* FUNCTION: GetFormElemByID
	* PURPOSE: Traverses document hierarchy, looking onforms to find the 
	*			identified element.
	*
	* PARAMETERS: 
	*	currDoc = current document object.
	*	elemID = string containing element ID.
	*
	* RETURNS:
	*	element object
	*
	* DESCRIPTION:
	\******************************************************************************/
	function GetFormElemByID(currDoc, elemID )
	{
		var blockElem;
		var i;
		
		if (currDoc.getElementById)
		{ // IE or W3C Compliant
			blockElem = currDoc.getElementById(elemID);
		}
		else
		{ // Netscape 4.xx
			// Traverse the document hierarchy to find the element
			// First check forms, then traverse down layers
			for (i=0; i < currDoc.forms.length; i++)
			{
				//alert (currDoc.forms[i].id);
				blockElem = currDoc.forms[i].elements[elemID];
				if (blockElem)
				{
					//alert("Return " + blockElem + elemID);
					return blockElem;
				}
			}
			//if (blockElem == undefined)
			if ( !blockElem )
			{	// Go down a layer
				for (i=0; i < currDoc.layers.length; i++)
				{
					blockElem = GetFormElemByID(currDoc.layers[i].document, elemID);
					if (blockElem)
					{
						//alert("Return " + blockElem.id);
						return blockElem;
					}
				}
				
			}
		}
		
		return blockElem;
	}
	
	/******************************************************************************\
	* FUNCTION: GetBlockByID
	* PURPOSE: Find Layer or DIV element
	*
	* PARAMETERS:
	*	currDoc
	*	elemID
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	
	function GetBlockByID(currDoc, elemID)
	{
		var blockElem;
		var i;
		
		if (currDoc.layers)
		{ // Netscape 4.xx
			// Traverse the document hierarchy to find the element
			for (i=0; i < currDoc.layers.length; i++)
			{
				if (currDoc.layers[i].id == elemID)
				{
					blockElem = currDoc.layers[i];
					return blockElem;
				}
				else
				{
					blockElem = GetBlockByID(currDoc.layers[i].document, elemID);
					if (blockElem != null)
						return blockElem;
				}
			}
		}
		else
		{ // IE or W3C Compliant
			blockElem = currDoc.getElementById(elemID);
		}
		
		
		return blockElem;
	}

	
	/******************************************************************************\
	* FUNCTION: GetImageByID
	* PURPOSE: Find identified image on document.
	*
	* PARAMETERS:
	*	currDoc
	*	imageID
	*
	* RETURNS:
	*	Image object
	*
	* DESCRIPTION:
	\******************************************************************************/
	function GetImageByID(currDoc, imageID)
	{
		var imageElem;
		var i;
		
		if (currDoc.layers)
		{ // Netscape 4.xx
			// Traverse the document hierarchy to find the element
			imageElem = currDoc.images[imageID];
			if (imageElem == null)
			{ // Check down hierarchy
				for (i=0; i < currDoc.layers.length; i++)
				{
					imageElem = GetImageByID(currDoc.layers[i].document, imageID);
					if (imageElem != null)
					{
						break;
					}
				}
			}
		}
		else
		{ // IE or W3C Compliant
			imageElem = currDoc.getElementById(imageID);
		}
		
		return imageElem;
	}

	/******************************************************************************\
	* FUNCTION: TogglePopup
	* PURPOSE: To toggle visibility on positioned elements, and move popup near 
	*		origin of event causing toggle. (LAYER or DIV elements).
	* PARAMETERS:
	*	popupID = ID of object to popup
	*	srcElem = object that initiated popup action, such as a button. This is used
	*				to position the popup.
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function TogglePopup(popupID, srcElem)
	{
		//if (document.layers)
		//	var srcElem = event.target;
		//else
		//	var srcElem = window.event.srcElement ;
		
		// Set visibility values per browser
		if (document.layers)
		{ /* Netscape 4.xx */
			var netscape4 = true;
			var visible = "show";
			var hidden = "hide";
		}
		else
		{
			var netscape4 = false;
			var visible = "visible";
			var hidden = "hidden";
		}
		
		if (document.layers)
		{	
			
			var popElement = GetBlockByID(document, popupID);
			var srcElemStyle = srcElem;
			var top = srcElem.top
			var left= srcElem.left
		}
		else
		{
			var popElement = document.getElementById(popupID).style;
			//alert ( srcElem.type + " " + srcElem.offsetTop + "," + srcElemStyle);
			if (srcElem.style)
			{
				var srcElemStyle = srcElem.style;
				var high = srcElemStyle.height;
				var top = srcElemStyle.top;
				var left = srcElemStyle.left;
				//alert("Style:" + top + "," + left);
			}
			if (!top)
			{
				var high = srcElem.height;
				var top = srcElem.offsetTop + srcElem.clientTop;
				var left = srcElem.offsetLeft  + srcElem.clientLeft;
			}
		}
		
		if (popElement.visibility == visible)
			popElement.visibility = hidden;
		else
		{
			popElement.visibility = visible;
			//popElement.position= "absolute";
			
			// Position popup Element near button 
			/*
			if (netscape4 == false)
			{
				//alert(top + "," + left);
				popElement.zindex = 5;
				popElement.top = top + high;
				if (popElement.top < 0 )
					popElement.top = 0;
				popElement.left = left - popElement.width;
				if (popElement.left < 0)
					popElement.left = 0;
			}
			*/
		}
	}
	
	/******************************************************************************\
	* FUNCTION: HidePopup
	* PURPOSE: Sets visibility attribute to hide the identified element.
	*
	* PARAMETERS:
	*	popupID = ID of layer or div
	*
	* RETURNS:
	*	NONE
	* DESCRIPTION:
	\******************************************************************************/
	function HidePopup(popupID)
	{
		if (document.layers)
		{ /* Netscape 4.xx */
			var hidden = "Hide";
		}
		else
		{
			var hidden = "hidden";
		}
		
		if (document.layers)
			var popElement = GetBlockByID(document, popupID);
		else
			var popElement = document.getElementById(popupID).style;
			
		if (popElement.visibility != hidden)
			popElement.visibility = hidden;
	}
	
	/******************************************************************************\
	* FUNCTION: ShowPopup
	* PURPOSE: Sets visibility attribute to show the identified element.
	*
	* PARAMETERS:
	*	popupID = ID of layer or div
	*
	* RETURNS:
	*	NONE
	* DESCRIPTION:
	\******************************************************************************/
	function ShowPopup(popupID)
	{
		if (document.layers)
		{ /* Netscape 4.xx */
			var visible = "Show";
			var hidden = "Hide";
		}
		else
		{
			var visible = "visible";
			var hidden = "hidden";
		}
		
		if (document.layers)
			var popElement = document.layers[popupID];
		else
			var popElement = document.getElementById(popupID).style;
			
		if (popElement.visibility == hidden)
			popElement.visibility = visible;
	}

	/******************************************************************************\
	* FUNCTION: ToggleVisibility
	* PURPOSE: Toggle visibility attribute to hide or show depending on current state.
	*
	* PARAMETERS:
	*	popupID = ID of layer or div element.
	* RETURNS:
	*	NONE
	* DESCRIPTION:
	\******************************************************************************/
	function ToggleVisibility(popupID)
	{
		if (document.layers)
		{ /* Netscape 4.xx */
			var visible = "Show";
			var hidden = "Hide";
		}
		else
		{
			var visible = "visible";
			var hidden = "hidden";
		}
		
		if (document.layers)
			var popElement = document.layers[popupID];
		else
			var popElement = document.getElementById(popupID).style;
			
		if (popElement.visibility == hidden)
			popElement.visibility = visible;
		else
			popElement.visibility = hidden;
	}

	/******************************************************************************\
	* FUNCTION: ClipRect
	* PURPOSE:	Create clipping rectangle
	* PARAMETERS:
	*	top, left, bottom, right in pixels.
	*
	* RETURNS:
	*	string clipping rectangle
	*
	* DESCRIPTION:
	\******************************************************************************/
	function ClipRect(top, left, bottom, right)
	{
		if (document.layers)
			clipStr = "rect(" + left.toString() + ","  + top.toString() + ","  + 
						right.toString() + "," + bottom.toString() + ")" ;
		else 
			clipStr = "rect(" + top.toString() + " "  + right.toString() + " "  + bottom.toString + " " + left.toString() + ")"  
			
		return clipStr;
	}

	/******************************************************************************\
	* FUNCTION: GetSelections
	* PURPOSE: Return string array of current selections in <SELECT> elem.
	* PARAMETERS:
	*	listID = id of Select elem.
	*
	* RETURNS:
	*	 string array of selected items.
	* DESCRIPTION:
	\******************************************************************************/
	function GetSelections(listID, docID)
	{
		selectList = new Array();
		var selectObj;
		//alert(docID);
		//if (docID == undefined  ) 
		if (!docID)
		{
			docID = document;
		}
		
//		if (document.layers)
//			selectObj = GetFormElemByID(docID,listID)
//		else
			selectObj = GetFormElemByID(docID,listID)
			
		if (selectObj)
		{
			for (i=0; i < selectObj.options.length; i++)
			{
				if (selectObj.options[i].selected)
				{
					selectList[selectList.length] = selectObj.options[i].value ;
					
				}
			}
		}
		return selectList;
	}
	
	/******************************************************************************\
	* FUNCTION: GetSelectionsString
	* PURPOSE: Return string array of current selections in <SELECT> elem. Each 
	*		item value as a sting delimited by "'" and "'"
	*
	* PARAMETERS:
	*	listID = id of Select elem.
	*
	* RETURNS:
	*	 string array of selected items.
	* DESCRIPTION:
	\******************************************************************************/
	function GetSelectionsString(listID)
	{
		selectList = new Array();
		
//		if (document.getElementById)
//			selectObj = document.getElementById(listID)
//		else
			selectObj = GetFormElemByID(document,listID)
			
		if (selectObj)
		{
			for (i=0; i < selectObj.options.length; i++)
			{
				if (selectObj.options[i].selected)
				{
					selectList[selectList.length] = "\'" + selectObj.options[i].value +"\'" ;
				}
			}
		}
		return selectList;
	}
	
	/******************************************************************************\
	* FUNCTION: SetSelected
	* PURPOSE: Set option identified by select id and value to selected
	* PARAMETERS:
	*	selectID
	*	selectValue
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function SetSelected(selectID, selectValue)
	{
		var selectObj;
		
		selectObj = GetFormElemByID(document,selectID)
		if (selectObj)
		{
			for (i=0; i < selectObj.options.length; i++)
			{
				if (selectObj.options[i].value == selectValue)
				{
					selectObj.options[i].selected = true;
				}
			}
		}

			
	}
	
	/******************************************************************************\
	* FUNCTION: SetNotSelected
	* PURPOSE: Set option identified by select id and value to un-selected
	* PARAMETERS:
	*	selectID
	*	selectValue
	*
	* RETURNS:
	\******************************************************************************/
	function SetNotSelected(selectID, selectValue)
	{
		var selectObj;
		
		selectObj = GetFormElemByID(document,selectID)
			
		if (selectObj)
		{
			for (i=0; i < selectObj.options.length; i++)
			{
				if (selectObj.options[i].value == selectValue)
					selectObj.options[i].selected = false;
			}
		}

			
	}

	/******************************************************************************\
	* FUNCTION: ClearSelect
	* PURPOSE: Clear selected on all options of select element.
	*
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function ClearSelect(selectID)
	{
		var selectObj;
		
		selectObj = GetFormElemByID(document,selectID)
			
		if (selectObj)
		{
			for (i=0; i < selectObj.options.length; i++)
			{
				selectObj.options[i].selected = false;
			}
		}
			
	}
	
	/******************************************************************************\
	* FUNCTION: GetRadioElem
	* PURPOSE: Find radio button by ID and value
	* PARAMETERS:
	*	radioID = ID of radio button element
	*	radioVal = Value of radio button to select from buttons with same ID
	*
	* RETURNS:
	*	input object
	* DESCRIPTION:
	\******************************************************************************/
	
	function GetRadioElem(radioID, radioVal)
	{
		var radioElem;
		var radioForm;
		var radioValue = new String();
		var i;
		radioValue = "";
		
		/* find a radio object with the passed ID */
		radioElem = GetFormElemByID(document, radioID );
		
		/* get the parent form of the radio object */
		
		if (radioElem != null)
		{ // element found
			
			if (radioElem.length)
			{ // Retrieved array object.
				for (i=0; i < radioElem.length; i++)
				{
					if (radioElem[i].value == radioVal)
						return radioElem[i];
				}
			}
			else
			{ // single element, look in form for others of same name.
			
				radioForm = radioElem.form;
			
				/* Find each form element with the same radioID, and check for on */
				for (i=0; i < radioForm.elements.length; i++)
				{ // Uncheck each
					if (radioForm.elements[i].id == radioID && radioForm.elements[i].value == radioVal)
						return radioForm.elements[i]
				}
			}
		}
			
		return radioElem;
	}
	
	/******************************************************************************\
	* FUNCTION: ClearRadioButtons
	* PURPOSE: Clear all the radio buttons, set to unchecked, with the passed ID.
	* PARAMETERS:
	*	elemID
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function ClearRadioButtons(elemID)
	{
		if (document.all)
		{
		if (document.form1.all(elemID) )
		{ // element exists
			//alert(elemID + ":" + document.form1.all(elemID).length);
			if (document.form1.all(elemID).length)
			{ // element is array of elements
				for (i=0; i < document.form1.all(elemID).length; i++)
				{ // Uncheck each
					document.form1.all(elemID)(i).checked = false;
				}
			}
			else
			{ // Element is single item
				document.form1.all(elemID).checked = false;
			}
		}
		}
	}

	/******************************************************************************\
	* FUNCTION: GetRadioValue
	* PURPOSE: Return the value of the currently selected radio button
	* PARAMETERS:
	*	radioID
	*
	* RETURNS:
	*	value
	* DESCRIPTION:
	\******************************************************************************/
	function GetRadioValue(radioID)
	{
		var radioElem;
		var radioForm;
		var radioValue = new String();
		var i;
		radioValue = "";
		
		/* find a radio object with the passed ID */
		radioElem = GetFormElemByID(document, radioID );
		
		/* get the parent form of the radio object */
		
		if (radioElem != null)
		{ // element found
			
			if (radioElem.length)
			{ // Retrieved array object.
				for (i=0; i < radioElem.length; i++)
				{
					if (radioElem[i].checked)
						radioValue = radioElem[i].value;
				}
			}
			else
			{ // single element, look in form for others of same name.
			
				radioForm = radioElem.form;
			
				/* Find each form element with the same radioID, and check for on */
				for (i=0; i < radioForm.elements.length; i++)
				{ // Uncheck each
					if (radioForm.elements[i].id == radioID && radioForm.elements[i].checked)
						radioValue=radioForm.elements[i].value;
				}
			}
		}
		else
			alert (radioID + " NOT FOUND");
			
		return radioValue;
	}
	
	/******************************************************************************\
	* FUNCTION: SetRadio	
	* PURPOSE:	Sets the checked property for the radio button identified by ID 
	*			and Value
	* PARAMETERS:
	*	radioID = radio button ID
	*   radioValue = radio button value 
	*	checkedVal = 'CHECKED' or ''
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function SetRadio(radioID, radioValue, checkedVal)
	{
		var radioInput;
		radioInput = GetRadioElem(radioID, radioValue);
		radioInput.checked = checkedVal;
	}

	/******************************************************************************\
	* FUNCTION: ConvertToHTML
	* PURPOSE: Change spaces to '%20' for use in query string or URL.
	* PARAMETERS:
	*	conString = string to be converted.
	*
	* RETURNS:
	*	converted string
	
	* DESCRIPTION:
	\******************************************************************************/
	function ConvertToHTML(conString)
	{
		newStr = new String();
		joinStr = new String();
		reg = new RegExp();
		
		reg = / /gi;
		newStr = conString.replace(reg, "%20");
		return newStr;
		
	}
	
	/******************************************************************************\
	* FUNCTION: StyleToLayer
	* PURPOSE: Convert StyleSheet syntax to sttributes for <LAYER> tag.
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function StyleToLayer(styleString)
	{
		var i;
		newStyle = new String();
		paramArray = styleString.split(";");
		for (i=0; i < paramArray.length; i++)
		{
			newStyle = newStyle + paramArray[i].replace(":","=") + " ";
		}
		return newStyle;
	}
	
	/******************************************************************************\
	* FUNCTION:
	* PURPOSE:
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function StartBlock(blockID, styleString)
	{
		if (document.layers)
		{ // NetScape 4.x
			layerAttr = StyleToLayer(styleString);
			
			document.write("<layer id=\"" + blockID + "\" " + layerAttr +  ">");
		}
		else
		{// W3C compliant
			document.write("<DIV id=\"" + blockID + "\"  style=\"" + styleString + "\">");
	
		}
	
	}
	
	/******************************************************************************\
	* FUNCTION:
	* PURPOSE:
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function EndBlock(blockID)
	{
		//alert("End " + blockID);
		if (document.layers)
		{ // NetScape 4.x
			document.write("</layer >");
		}
		else
		{// W3C compliant
			document.write("</DIV>");
	
		}
	}
	
	/******************************************************************************\
	* FUNCTION: SetValue
	* PURPOSE: 
	*	Find input element identified by inputID and set it's value to inputValue
	*
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function SetValue(inputID, inputValue)
	{
		var inputOBJ;
		inputOBJ = GetFormElemByID(document,inputID);
		inputOBJ.value = inputValue;
	}
	
	/******************************************************************************\
	* FUNCTION: ShowDialog
	* PURPOSE: Display new browser window for dialogs.
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function ShowDialog(winURL, winName,winWidth,winHeight)
	{
		windowFeatures="toolbar=no,scrollbars=yes,status=no,location=no,menubar=yes,directories=no";
		if ( !isNaN(winWidth))
			windowFeatures = windowFeatures + ",resizable=yes" + ",width=" + winWidth + ",height=" + winHeight;
		
		window.open(winURL,winName,windowFeatures);
	}
	
	/******************************************************************************\
	* FUNCTION: ParseDateTime
	* PURPOSE: Parse DateTime strings trying various formats.
	* PARAMETERS:
	*
	* RETURNS:
	*
	* DESCRIPTION:
	\******************************************************************************/
	function ParseDateTime(dateTimeStr)
	{
		//var datePart;
		//var timePart;
		var isValid = new Boolean(true);
		var datePattern = new RegExp();
		var datePatternRes;
		var dateInput = new Date();
		var dateString = new String();
		var dateMonth = new String();
		var dateYear = new Number();
		var dateDay = new Number();
		var minutes = new Number();
		var seconds = new Number();
		var hours = new Number();
		var amPm = new String();
		
		datePattern = new RegExp("^(\\d?\\d)/(\\d?\\d)/(\\d{2,4})\\s(\\d?\\d):?(\\d?\\d):?(\\d?\\d)?\\s*(am|pm)?$","i");
		isValid = datePattern.test(dateTimeStr);
		if (isValid)
		{ // Matches pattern, test for good date
			datePatternRes = datePattern.exec(dateTimeStr);
			dateDay = parseInt(datePatternRes[2]);
			dateMonth = MonthName(parseInt(datePatternRes[1]));
			dateYear = parseInt(datePatternRes[3]);
			hours = parseInt(datePatternRes[4]);
			minutes = parseInt(datePatternRes[5]);
			seconds = parseInt(datePatternRes[6]);
			ampm = ""
			if (datePatternRes[7])
				amPm = datePatternRes[7].toLowerCase();
		}
		else
		{
			datePattern = new RegExp("^(\\d?\\d)-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-(\\d{2,4})\\s(\\d?\\d):?(\\d?\\d):?(\\d?\\d)?\\s*(am|pm)?","i");
			isValid = datePattern.test(dateTimeStr);
			//alert (dateTimeStr + " " + isValid.toString());
			if (isValid)
			{ // Matches pattern, test for good date
				datePatternRes = datePattern.exec(dateTimeStr);
				dateDay = parseInt(datePatternRes[1]);
				dateMonth = datePatternRes[2];
				dateYear = parseInt(datePatternRes[3]);
				hours = parseInt(datePatternRes[4]);
				minutes = parseInt(datePatternRes[5]);
				seconds = parseInt(datePatternRes[6]);
				ampm = ""
				if (datePatternRes[7])
					amPm = datePatternRes[7].toLowerCase();
				//alert (hours + " " + minutes + " " + amPm);
			}
			else
			{
				datePattern = new RegExp("^(\\d?\\d)-(january|february|march|april|may|june|july|august|september|october|november|december)-(\\d{2,4})\\s(\\d?\\d):(\\d?\\d):?(\\d?\\d)?\\s*(am|pm)?$","i");
				isValid = datePattern.test(dateTimeStr);
				if (isValid)
				{ // Matches pattern, test for good date
					datePatternRes = datePattern.exec(dateTimeStr);
					dateDay = parseInt(datePatternRes[1]);
					dateMonth = datePatternRes[2];
					dateYear = parseInt(datePatternRes[3]);
					hours = parseInt(datePatternRes[4]);
					minutes = parseInt(datePatternRes[5]);
					seconds = parseInt(datePatternRes[6]);
					ampm = ""
					if (datePatternRes[7])
						amPm = datePatternRes[7].toLowerCase();
					
				}
				else
				{
					datePattern = new RegExp("^(january|february|march|april|may|june|july|august|september|october|november|december)\\s(\\d?\\d),\\s*(\\d{2,4})\\s(\\d?\\d):(\\d?\\d):?(\\d?\\d)?\\s*(am|pm)?$","i");
					isValid = datePattern.test(dateTimeStr);
					if (isValid)
					{ // Matches pattern, test for good date
						datePatternRes = datePattern.exec(dateTimeStr);
						dateDay = parseInt(datePatternRes[2]);
						dateMonth = datePatternRes[1];
						dateYear = parseInt(datePatternRes[3]);
						hours = parseInt(datePatternRes[4]);
						minutes = parseInt(datePatternRes[5]);
						seconds = parseInt(datePatternRes[6]);
						ampm = ""
						if (datePatternRes[7])
							amPm = datePatternRes[7].toLowerCase();
					}
					else
					{
						datePattern = new RegExp("^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\\s(\\d?\\d),\\s*(\\d{2,4})\\s(\\d?\\d):(\\d?\\d):?(\\d?\\d)?\\s*(am|pm)?$","i");
						isValid = datePattern.test(dateTimeStr);
						if (isValid)
						{ // Matches pattern, test for good date
							datePatternRes = datePattern.exec(dateTimeStr);
							dateDay = parseInt(datePatternRes[2]);
							dateMonth = datePatternRes[1];
							dateYear = parseInt(datePatternRes[3]);
							hours = parseInt(datePatternRes[4]);
							minutes = parseInt(datePatternRes[5]);
							seconds = parseInt(datePatternRes[6]);
							ampm = ""
							if (datePatternRes[7])
								amPm = datePatternRes[7].toLowerCase();
						
							
						}

					}
				}
			}
		}
		
			
		if (dateYear < 100)
		{ // Convert 2 digit years to 4 digit. All other years taken as is.
			if (dateYear < 20)
				dateYear = 2000 + dateYear;
			else
				dateYear = 1900 + dateYear;
		}
		
		if (amPm.length == 2)
		{ // AM-PM time
			if (hours <= 12 && hours > 0)
			{
				if (amPm == "pm")
				{
					hours = hours + 12;
					if (hours >= 24) hours = 0;
				}
				else
					isValid = false;
			}
			else
				isValid = false;
		}
		else
		{ // 24 hour clock
			if (hours > 24 || hours < 0)
				isValid = false;
		}
		
		if (isValid)
		{
			if (minutes > 59 || minutes < 0)
				isValid = false
		}
		
		if (isValid)
		{
			dateString = dateMonth + " " + dateDay.toString() + ", " + dateYear.toString() + " " + hours + ":" + minutes + " " + amPm;
			//alert(dateString);
			dateInput = new Date(Date.parse(dateString));
			isValid = (!isNaN(dateInput) && dateDay == dateInput.getDate());
		}
		if (isValid)
			return dateInput;
		else
			return NaN;
		
	}