/*----------------------------------------------------------------------------------------------
*  File Name:	 util_medicaid.js
*
*  Description:  This file contains functions to be used throughout the IHCP site.
*
*
*|                    | Mod Log    |                |
*| Author             | Date       | Authorization  |  Description
*|--------------------|------------|----------------|--------------------------------------------
*| Brad Coon          | 11/01/02   | IN013082       | Initial Version
*| Brad Coon          | 11/03/04   | CO #427        | Functions for Provider Search
*| Debbie Bowen       | 09/22/05   | CO 289         | Added headerDate() 
*-------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------
*  Function:     AutoTab
*
*  Description:  This function will tab to a defined field when a 
*				 character limit has been reached
*
*  Notes:
*
*  Return Value: None
*
*  Input Parms:  Reference to the field's object
*				 Keyboard/mouse/browser event
*				 Max length before auto tab occurs
*				 Next input field to tab to
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon         | 11/01/02 | IN013082	      | Initial Development
*-------------------------------------------------------------------------------*/

function AutoTab(obj,event,len,nextField) {
	var fieldLen=0;
	
	if (event == "down") {
	
		// Set character length to "fieldLen"
		fieldLen=obj.value.length;
	}
	
	else if (event == "up") {
	
		// Make sure characters entered are greater than 0
		if (obj.value.length != fieldLen) {
		
			// Set character length to "fieldLen"
			fieldLen=obj.value.length;
			
			// Check to see if user has entered required characters
			if (fieldLen == len) {
			
				// Set focus to the next field
				nextField.focus();
				
			} // End If
		} // End If
	} // End Else
	
} // End AutoTab Function



/*--------------------------------------------------------------------------------
*  Function:     isAlphaNumericSpecialPeriod
*
*  Description:  This function checks to see if an alphanumeric or space '-.  was entered
*
*  Notes:
*
*  Return Value: 
*  DataType		Meaning
*  boolean		true = data is valid
*				false = data is not valid
*
*  Input Parms:  field, field name
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon         | 05/26/03 | 		82	      | Initial Development
*-------------------------------------------------------------------------------*/
function isAlphaNumericSpecialPeriod(obj, objName) {
	if (obj.value.length > 0) {
		// Convert text to upper case
		obj.value = obj.value.toUpperCase(); 

		var re = /^[\sa-zA-Z0-9'.-]+$/;

    	if (!re.test(obj.value)) {
		 	alert(objName + " may only contain letters, numbers and dash (-), apostrophe ('), and period (.).");
		 	obj.value = "";
		 	obj.focus();
         	return false;
   		}
	}
	
	return true;
}



/*--------------------------------------------------------------------------------
*  Function:     isNumeric
*
*  Description:  This function checks to see if a numeric was entered
*
*  Notes:
*
*  Return Value: 
*  DataType		Meaning
*  boolean		true = data is valid
*				false = data is not valid
*
*  Input Parms:  field, field name
*
*                        Mod Log
*| Author            | Date     | Authorization   | Description
*|-------------------|----------|-----------------|-------------------------------
*| Brad Coon         | 11/03/04 | CO #427	      | Initial Development
*-------------------------------------------------------------------------------*/
function isNumeric(obj, objName) {
	if (obj.value.length > 0) {

		// Regular Expression to check for numerics throughout input
		var re = /^[0-9]+$/;

    	if (!re.test(obj.value)) {
		 	alert(objName + " may only contain numbers.");
		 	obj.value = "";
		 	obj.focus();
         	return false;
   		}
	}
	
	return true;
}



/*--------------------------------------------------------------------------------
*  Function:     openWindow
*
*  Description:  Open a new window with a specified location and dimensions
*						
*  Notes:
*
*  Return Value: A reference to the new window
*
*  Input Parms: URL for the window
*				Name of window
*				Width of the window
*				Height of the window
*
*|                    | Mod Log    |                 |
*| Author             | Date       | Authorization   | Description
*|--------------------|------------|-----------------|-------------------------------
*| Brad Coon          | 11/03/04   |			     | Initial Development
*
*-------------------------------------------------------------------------------*/
function openWindow(url, name, width, height) {
	// To center the window, determine the distance to the left and top of the computer screen.
	var leftPos = (screen.width - width)/2;
	var topPos = (screen.height - height)/2;
	
	// Define window position and look & feel
	properties = 'height=' + height + ',width=' + width + ',top='+ topPos +',left='+ leftPos +',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable';
	
	// Open the window and get a reference to it
	var newWin = window.open(url, name, properties);
	
	return newWin;
}

/*--------------------------------------------------------------------------------
*  Function:     headerDate
*
*  Description:  The current date display at the top-left of each page
*						
*  Notes:
*
*  Return Value: The formatted date
*
*  Input Parms: None
*
*|                    | Mod Log    |                 |
*| Author             | Date       | Authorization   | Description
*|--------------------|------------|-----------------|-------------------------------
*| Debbie Bowen       | 09/22/05   | CO 289          | Code from Brad Coon CO #668 
*-------------------------------------------------------------------------------*/
function headerDate() {
	var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
  	var date = new Date();
	var year = date.getYear();
	var month = date.getMonth();
	var day = date.getDate();
	
	// Mozilla will print '105 instead of '2005' for the year
	if (year < 1000) {
		year = year + 1900;
	}
	
	date = months[month] + " " + day + ", " + year;
	
  	return date;
}
