/*  db: needed to color code in vs, ignored when running
	<script>
*/
/*********************************************************************
'***    Program: selectListItem( objList, strItemValue )
'***    Type: Function
'***
'***    Function: Selects item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemValue  - value to look for. the item with this value gets selected
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function selectListItem( objList, strItemValue ) {
	for (var i=0; i < objList.length; i++) {
		if (objList.options[i].value == strItemValue) {
			// this item needs to get selected
			objList.options[i].selected = true;
			break;
		}
	}
	return;
}

/*********************************************************************
'***    Program: selectListItemByText( objList, strItemText )
'***    Type: Function
'***
'***    Function: Selects item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemText  - text to look for. the item with this text gets selected
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function selectListItemByText( objList, strItemText ) {
	for (var i=0; i < objList.length; i++) {
		if (objList.options[i].text == strItemText) {
			// this item needs to get selected
			objList.options[i].selected = true;
			break;
		}
	}
	return;
}

/*********************************************************************
'***    Program: isAlphaAndDigitString(strToCheck) 
'***    Type: Function
'***
'***    Function: Tests a string for presence of alpha and digit chars only
'***
'***    Parameters: 
'***		strToCheck - sting to check for validity
'***
'***    Returns: True/False
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function isAlphaAndDigitString(strToCheck) {
  var checkOK = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.@%*()#"';
  var checkStr = strToCheck;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
  }
  return (allValid);
}

/*********************************************************************
'***    Program: isAlphaAndDigitEntry(objText) 
'***    Type: Function
'***
'***    Function: Checks a text box object's value for alpha and digit chars only
'***
'***    Parameters: 
'***		objText - object to check value in
'***
'***    Returns: True/False
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function isAlphaAndDigitEntry(objText) {
  return (isAlphaAndDigitString(objText.value));
}

/*********************************************************************
'***    Program: isObjectOnForm(objForm, strObjName)
'***    Type: Function
'***
'***    Function: Checks whether an object exists on a given form 
'***
'***    Parameters: 
'***		objForm - form object to use when looking for an element
'***		strObjName - name of an object to look for. Case sensitive!
'***
'***    Returns: True/False
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function isObjectOnForm(objForm, strObjName) {
	for (intFormIndex = 0; intFormIndex < objForm.elements.length; intFormIndex++) {
		if (objForm.elements[intFormIndex].name == strObjName) {
			return true;
		}
	}
	return false;
}

/*********************************************************************
'***    Program: getSelectedItems( lstWhereToLook )
'***    Type: Function
'***
'***    Function: Enumerates through a list box and returns a comma separated list of selected
'***		items
'***
'***    Parameters: 
'***		lstWhereToLook  - select object to look in
'***
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 9/30/99
'*********************************************************************/
function getSelectedItems( lstWhereToLook ) {
	if (lstWhereToLook == null) {
		return "";
	}

	var strResult = "" ;
	for (intItemIndex = 0; intItemIndex < lstWhereToLook.length; intItemIndex++ ) {
		if (lstWhereToLook[intItemIndex].selected) {
			strResult += "," + lstWhereToLook[intItemIndex].value;
		}
	}
	if (strResult.length > 0) {
		return strResult.substring(1); // all but first comma
	}
	return strResult
}

/*********************************************************************
'***    Program: getSelectedItemCount( lstWhereToLook )
'***    Type: Function
'***
'***    Function: Calculates a number of selected items in a listbox
'***
'***    Parameters: 
'***		lstWhereToLook  - select object to look in
'***
'***    Returns: interger
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 1/9/07
'*********************************************************************/
function getSelectedItemCount( lstWhereToLook ) {
	if (lstWhereToLook == null) {
		return 0;
	}
	var intCount = 0;
	for (intItemIndex = 0; intItemIndex < lstWhereToLook.length; intItemIndex++ ) {
		if (lstWhereToLook[intItemIndex].selected)
			intCount++;
	}
	return intCount;
}

/*********************************************************************
'***    Program: getSelectedItemTexts( lstWhereToLook )
'***    Type: Function
'***
'***    Function: Enumerates through a list box and returns a comma separated list of selected
'***		item text (display value)
'***
'***    Parameters: 
'***		lstWhereToLook  - select object to look in
'***
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 9/30/99
'*********************************************************************/
function getSelectedItemTexts( lstWhereToLook ) {
	if (lstWhereToLook == null) {
		return "";
	}

	var strResult = "" ;
	for (intItemIndex = 0; intItemIndex < lstWhereToLook.length; intItemIndex++ ) {
		if (lstWhereToLook[intItemIndex].selected) {
			strResult += "," + lstWhereToLook[intItemIndex].text;
		}
	}
	if (strResult.length > 0) {
		return strResult.substring(1); // all but first comma
	}
	return strResult
}

/*********************************************************************
'***    Program: getSelectedItemsWithDevider( lstWhereToLook, strDevider )
'***    Type: Function
'***
'***    Function: Enumerates through a list box and returns a "strDevider" separated list of selected
'***		items
'***
'***    Parameters: 
'***		lstWhereToLook  - select object to look in
'***		strDevider  - Devider 
'***			Sample:	  getSelectedItemsWithDevider( lstWhereToLook, "&NewExistingJobReferences=" )	
'***        
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 9/30/99
'*********************************************************************/
function getSelectedItemsWithDevider( lstWhereToLook, strDevider ) {
	if (lstWhereToLook == null) {
		return "";
	}

	if (strDevider == "") {
		strDevider = ","	
	}

	var strResult = "" ;
	for (intItemIndex = 0; intItemIndex < lstWhereToLook.length; intItemIndex++ ) {
		if (lstWhereToLook[intItemIndex].selected) {
			strResult += strDevider + lstWhereToLook[intItemIndex].value;
		}
	}
	//if (strResult.length > 0) {
	//	return strResult.substring(strDevider.length); // all but first comma
	//}
	
	return strResult
}


/*********************************************************************
'***    Program: getCleanKeywords
'***    Type: Function
'***
'***    Function: Analized incoming string for signs of full text search syntax
'***		and attempts to fix syntax issues by adding "AND" operator if
'***		users do not specify full text search syntax.
'***
'***    Parameters: 
'***		strKeywords - string to analyze
'***
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/7/2001
'*********************************************************************/
function getCleanKeywords( strDirtyKeywords ) {

	var sValue = strDirtyKeywords;
        sValue = " " + strDirtyKeywords;
        
        // remove commers
	sValue = sValue.replace(/(,+)/g, "");
        
        // remove leading and trailing spaces
	sValue = sValue.replace(/(^ *)|( *$)/g, "");

        // replace any number of spaces with just one space
	sValue = sValue.replace(/( +)/g, " ");
	
        if ((sValue.toLowerCase().indexOf(" and ") == -1) && (sValue.toLowerCase().indexOf(" or ") == -1) && (sValue.toLowerCase().indexOf(" near ") == -1)) {

		// no "OR"s and "AND"s
		if (sValue.indexOf('"') == -1)  {
	  
			// replace spaces with " and "
			sValue = sValue.replace(/ /g, " and ");
		}
		else {
			// replace expression in quotes+space with itself following "and "
			re = /(".*" )/g;
			sValue = sValue.replace(re, "$1and ");
		}
	}


	return sValue;
}


/*********************************************************************
'***    Program: getCleanCCNo( strDirtyCCNo )
'***    Type: Function
'***
'***    Function: removes spaces and dashes from given string
'***		
'***
'***    Parameters: 
'***		strDirtyCCNo - string (cc no) to clean
'***
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 5/18/2001
'*********************************************************************/
function getCleanCCNo( strDirtyCCNo ) {
	var strNewString = new String(strDirtyCCNo);
	return strNewString.replace(/[ -]/g, "");
}

/*********************************************************************
'***    Program: unselectListItems( objList )
'***    Type: Function
'***
'***    Function: unselects all item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 5/24/2001
'*********************************************************************/
function unselectListItems( objList ) {
	for (var i=0; i < objList.length; i++) {
		// this item needs to get selected
		objList.options[i].selected = false;
	}
	return 0;
}

/*********************************************************************
'***    Program: isListItemSelected( objList, strItemValue )
'***    Type: Function
'***
'***    Function: unselects all item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemValue - value of item to test
'***
'***    Returns: Boolean
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 9/13/2001
'*********************************************************************/
function isListItemSelected( objList, strItemValue ) {
	for (var i=0; i < objList.length; i++) {
		// this item needs to get selected
		if (objList.options[i].value == strItemValue) {
			return objList.options[i].selected == 1;
		}
	}
	return false;
}

/*********************************************************************
'***    Program:  isnertFirstElementIntoListObject
'***    Type: Function
'***
'***    Function: Inserts a first element into list object passed into this function as 
'***		parameter.
'***
'***    Parameters: 
'***		objList - object reference. must be a select object
'***		strElementText  - text to use when inserting element
'***		strElementValue - value of new element
'***
'***    Returns: String
'***    Remarks: First element will be selected
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 9/19/2001
'*********************************************************************/
function isnertFirstElementIntoListObject( objList, strElementText, strElementValue ) {
	arrNewLabels = new Array( objList.length );
	var intOption = 0;

	// save all options
	for (intOption = 0; intOption < objList.length; intOption++) {
		arrNewLabels[intOption] = new Option(  objList.options[intOption].text, objList.options[intOption].value );
	}

	// remove all options
	for (objList.length; intOption >= 0; intOption--) {
		objList.options[intOption] = null;
	}


	// add new first option
	objList.options[0] = new Option(strElementText, strElementValue, true, true );

	// add saved options
	for (intOption = 0; intOption < arrNewLabels.length; intOption++) {
		objList.options[intOption+1] = arrNewLabels[intOption];
	}
 
	return true;
}

/*********************************************************************
'***    Program:  getFullURL( strURL, blnSecure )
'***    Type: Function
'***
'***    Function: Returns a URL that begins with "http://" / "https://"
'***		if base url does not already have it
'***
'***    Parameters: 
'***		strURL - URL to check
'***		blnSecure - if true append "https://"
'***
'***    Returns: String
'***    Remarks: 
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 12/20/2001
'*********************************************************************/
function getFullURL(strURL, blnSecure) {
	var strProtocol = (blnSecure) ? "https://" : "http://";
	var strFinalURL = "";
	if (strURL.toLowerCase().indexOf(strProtocol) == -1) {
		strFinalURL = strProtocol + strURL;
	}
	else {
		strFinalURL = strURL;
	}
	return strFinalURL;
}

/*********************************************************************
'***    Program:  validateAndSubmitBulkAction()
'***    Type: Procedure
'***
'***    Function: on View pages that contain FormBulk, validates input
'***
'***    Parameters: none
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 03/27/01
'*********************************************************************/
function validateAndSubmitBulkAction(){
	var blnSelectionMade = false;
	//var strBulkOperation = "";
	var strBulkOperationSelect = false;
	var strBulkOperationName = "";
		
	with (document.FormBulk){
		//strBulkOperation = BulkOperationType.options[BulkOperationType.selectedIndex].value;
		switch (BulkOperationType.options[BulkOperationType.selectedIndex].value) {
			case "DeleteSelected":
				strBulkOperationSelect = true;
				strBulkOperationName = "delete";
				break;
			case "DeleteFilter":
				strBulkOperationSelect = false;
				strBulkOperationName = "delete";
				break;
			case "DisableSelected":
				strBulkOperationSelect = true;
				strBulkOperationName = "disable";
				break;
			case "DisableFilter":
				strBulkOperationSelect = false;
				strBulkOperationName = "disable";
				break;
			case "EnableSelected":
				strBulkOperationSelect = true;
				strBulkOperationName = "enable";
				break;
			case "EnableFilter":
				strBulkOperationSelect = false;
				strBulkOperationName = "enable";
				break;
			case "ExportSelected":
				strBulkOperationSelect = true;
				strBulkOperationName = "export";
				break;
			case "ExportFilter":
				strBulkOperationSelect = false;
				strBulkOperationName = "export";
				break;

		}
		if (strBulkOperationSelect){
			
			if (elements.length > 0) {
				for (var i=0; i < elements.length; i++) {
					if (elements[i].type == "checkbox") {
						if (elements[i].checked) {
							blnSelectionMade = true;
							break;
						}
					}
				}
			}
			if (!blnSelectionMade) {
				alert("Please select at least one item.")
				return false;
			}

		   	if (confirm('Are you sure you want to ' + strBulkOperationName + ' the selected items?')) {
				//Form name on calling page must be named "FormBulk"
				submit();
			}
		}
		else{
		   	if (confirm('Are you sure you want to ' + strBulkOperationName + ' all items that\nqualify the filter condition?\n\nNOTE: This action can ' + strBulkOperationName + ' all items depending on your filter.')) {
				//Form name on calling page must be named "FormBulk"
				submit();
			}
		}
	}
}
/*********************************************************************
'***    Program:  isUserLoggedIn()
'***    Type: function
'***
'***    Function: Returns True if current user is logged in
'***
'***    Parameters: none
'***
'***    Returns: boolean
'***    Remarks: 
'***
'***    Created by: dimab
'***    Changed by: dimab
'***    Last change: 04/02/01
'*********************************************************************/
function isUserLoggedIn() {
	var strCooke = new String(self.document.cookie);
	return (strCooke.indexOf("FormsAuth") >= 0);
}
/*********************************************************************
'***    Program:  isEmployerUserAccountManager()
'***    Type: function
'***
'***    Function: Returns True if current user is logged in
'***
'***    Parameters: none
'***
'***    Returns: boolean
'***    Remarks: 
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 08/10/07
'*********************************************************************/
function isEmployerUserAccountManager() {
	var strCookie = new String(self.document.cookie);
	return ( isUserLoggedIn() && strCookie.indexOf("EmployerManagerSignature") >= 0 );
}
/*********************************************************************
'***    Program:  isCompanyProfileAvailable()
'***    Type: function
'***
'***    Function: Returns True if current user is logged in and Has company profile on account
'***
'***    Parameters: none
'***
'***    Returns: boolean
'***    Remarks: 
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 08/10/07
'*********************************************************************/
function isCompanyProfileAvailable(){
    var strCookie = new String(self.document.cookie);
    return ( isUserLoggedIn() && strCookie.indexOf("CompanyProfileSignature") >= 0 );
} 
/*********************************************************************
'***    Program:  isOneCheckBoxSelected( objCheckBoxArray )
'***    Type: function
'***
'***    Function: Checks whether at least one checkbox is selelcted within a group
'***
'***    Parameters: none
'***
'***    Returns: boolean
'***    Remarks: 
'***
'***    Created by: dimab
'***    Changed by: dimab
'***    Last change: 04/02/01
'*********************************************************************/
function isCheckBoxSelected( objCheckBoxArray ) {
	if (objCheckBoxArray.length) {
		// Array
		for (var i=0; i < objCheckBoxArray.length; i++) {
			if (objCheckBoxArray[i].checked) {
				return true;
			}
		}
		return false;
	}
	else {
		// single checkbox
		return objCheckBoxArray.checked;
	}
}


/*********************************************************************
'***    Program:  isOneCheckBoxSelected( objCheckBoxArray )
'***    Type: function
'***
'***    Function: Checks whether at least one checkbox is selelcted within a group and returns its value,
'***		or empty string
'***
'***    Parameters: none
'***
'***    Returns: boolean
'***    Remarks: 
'***
'***    Created by: dimab
'***    Changed by: dimab
'***    Last change: 05/08/01
'*********************************************************************/
function getSelectedCheckBoxValue( objCheckBoxArray ) {
	if (objCheckBoxArray.length) {
		// Array
		for (var i=0; i < objCheckBoxArray.length; i++) {
			if (objCheckBoxArray[i].checked) {
				return objCheckBoxArray[i].value;
			}
		}
	}
	else {
		// single checkbox
		if ( objCheckBoxArray.checked ) {
			return objCheckBoxArray.value;
		}
	}
	return "";
}



/*********************************************************************
'***    Program:  removeUnspecifiedValues()
'***    Type: Procedure
'***
'***    Function: on Load Form removes from multiselected list item vith value = "0" ( name = "unspecified" or "-Select-") 
'***
'***    Parameters: FormName 
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 04/18/02
'*********************************************************************/
function removeUnspecifiedValues(objForm) {

	with (objForm){

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == "select-multiple") {               
				removeUnsepcifiedFromList( elements[i] );
			}
		}
	}		
}

/*********************************************************************
'***    Program:  removeUnsepcifiedFromList()
'***    Type: Procedure
'***
'***    Function: on Load Form removes from multiselected list item vith value = "0" ( name = "unspecified" or "-Select-") 
'***
'***    Parameters: FormName 
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 04/18/02
'*********************************************************************/
function removeUnsepcifiedFromList( objList ) {

	for (var i=0; i < objList.length; i++) {
		if (objList.options[i].value == "0") {
			// remove
			objList.options[i] = null;
			return true;
		}
	}
	
	return true;

}



/*********************************************************************
'***    Program:  HasOneTextElementData()
'***    Type: Procedure
'***
'***    Function: Is true if at least one object type="text" contains data.
'***
'***    Parameters: FormName 
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 05/03/02
'*********************************************************************/
function HasOneTextElementData(objForm,strAlertText) {

	with (objForm){

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == "text") {  
				if ( elements[i].value != "" ){ 	
					return true;
				}
			}
		}
		alert(strAlertText);
		return false;
	}		
}

/*********************************************************************
'***    Program:  HasOneTextElementNonZeroData()
'***    Type: Procedure
'***
'***    Function: Is true if at least one object type="text" contains data 
'***              other than 0 or blank
'***
'***    Parameters: FormName 
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 05/03/02
'*********************************************************************/
function HasOneTextElementNonZeroData(objForm,strAlertText) {

	with (objForm){

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == "text") {  
				if ( elements[i].value != "" ){ 
					if ( elements[i].value != 0 ){ 	
						return true;
					}
				}
			}
		}
		alert(strAlertText);
		return false;
	}		
}

/*********************************************************************
'***    Program:  HasOneTextElementNonNumericData()
'***    Type: Procedure
'***
'***    Function: Is true if at least one object type="text" contains 
'***				non-numeric data
'***
'***    Parameters: FormName 
'***
'***    Returns: none
'***    Remarks: 
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 05/03/02
'*********************************************************************/
function HasOneTextElementNonNumericData(objForm,strAlertText) {
	var blnNonNumericDataFound = false;
	with (objForm){

		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == "text") {  
				if ( elements[i].value != "" ){ 
					if ( !isDigitString(elements[i].value) ){ 	
						blnNonNumericDataFound = true;
						break;
					}
				}
			}
		}
		if (blnNonNumericDataFound) {
			alert(strAlertText);
		}
	}	
	return blnNonNumericDataFound;
	
}
/*********************************************************************
'***    Program: isDigitString(strToCheck) 
'***    Type: Function
'***
'***    Function: Tests a string for presence of digit chars only
'***
'***    Parameters: 
'***		strToCheck - sting to check for validity
'***
'***    Returns: True/False
'***    Remarks: none
'***
'***    Created by: jeffl
'***    Changed by: jeffl
'***    Last change: 04/01/02
'*********************************************************************/
function isDigitString(strToCheck) {
  var checkOK = "0123456789.";
  var checkStr = new String(strToCheck);
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
  }
  return (allValid);
}
/*********************************************************************
'***    Program: isMultiSelectListSelected( objList )
'***    Type: Function
'***
'***    Function: True if at least one item is selected
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemValue - value of item to test
'***
'***    Returns: Boolean
'***    Remarks: none
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 05/16/02
'*********************************************************************/
function isMultiSelectListSelected( objList ) {
	for (var i=0; i < objList.length; i++) {
		// if item is selected
		if (objList.options[i].selected) {
			return true;
		}
	}
	return false;
}
/*********************************************************************
'***    Program: setOnChangeInForm
'***    Type: Procedure
'***
'***    Function: goes through the elements of a given form
'***			  and sets onChange/onClick events to setDataChanged(objForm)
'***
'***    Parameters: 
'***		objForm - form 
'***
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 07/12/02
'*********************************************************************/
function setOnChangeInForm(objForm) {
	with (objForm){
		for (var i=0; i < elements.length; i++) {
			if (elements[i].type == "text" || elements[i].type == "textarea" || elements[i].type == "select-one"  || elements[i].type == "select-multiple") {  
				elements[i].onchange = setDataChanged;
				
			}
			if (elements[i].type == "checkbox" || elements[i].type == "radio") {  
				elements[i].onclick = setDataChanged;
			}
		}
	}		
}

/*********************************************************************
'***    Program: isFormDataChanged
'***    Type: Function
'***
'***    Function: returns true if DataChanged textbox value is anything but blank
'***
'***    Parameters: 
'***		objForm - form 
'***
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 07/12/02
'*********************************************************************/
function isFormDataChanged(objForm) {
	var blnReturnValue = false;
	
	if (objForm.DataChanged) {
		if (objForm.DataChanged.value != "") {
			blnReturnValue = true;
		}
	}
	return blnReturnValue;
}

/*********************************************************************
'***    Program: canLeaveForm
'***    Type: Function
'***
'***    Function: returns true if no changes were made to form elements
'***              or user chooses to loose the changes
'***
'***    Parameters: 
'***		objForm - form 
'***
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 07/14/02
'*********************************************************************/
function canLeaveForm(objForm) {
	var blnReturnValue		 = true;
	var strButtonValue		 = "";
	var strButtonValueInPast = "";
	
	if (objForm.submit) {
		strButtonValue = objForm.submit.value
	}
	else {
		strButtonValue = "Add";
	}
	
	if (strButtonValue == "Change") {
		strButtonValueInPast = "changed";
	}
	else {
		strButtonValueInPast = "added";
	}
	
	if (isFormDataChanged(objForm)) {
		if (!confirm("You have entered new information but have not saved it yet.\nYou must press the " + strButtonValue + " button to save your changes.\n\nPress Cancel to return to editing or OK to proceed without saving.")) {
			blnReturnValue = false;
		}	
	}
	return blnReturnValue;
}

/*********************************************************************
'***    Program: setDataChangedInForm
'***    Type: Procedure
'***
'***    Function: changes value of DataChanged hidden element on form
'***
'***    Parameters: 
'***		objForm - form 
'***
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 07/14/02
'*********************************************************************/
function setDataChangedInForm(objForm) {
	if (objForm.DataChanged) {
		objForm.DataChanged.value = 1;
	}
}



/*********************************************************************
'***    Program: escapeKeywords
'***    Type: Function
'***
'***    Function: Analized incoming string for signs of full text search syntax
'***		and attempts to fix syntax issues
'***
'***    Parameters: 
'***		strKeywords - string to analyze
'***
'***    Returns: String
'***    Remarks: none
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 07/19/02
'*********************************************************************/
function escapeKeywords( strDirtyKeywords ) {

	var sValue = strDirtyKeywords;

    sValue = escape(sValue).replace(/\x2B/g,'%2B')


	return sValue;
}

/*********************************************************************
'***    Program: stripTextboxText
'***    Type: Function
'***
'***    Function: removes default text in a text box when user places
'***		the cursor in the text box
'***
'***    Parameters: 
'***		objForm - form and element name
'***
'***    Returns: empty string
'***    Remarks: requires "var blnStrippedText = false" variable declaration in calling page
'***
'***    Created by: jeffl
'***    Changed by: jeffl
'***    Last change: 09/19/02
'*********************************************************************/
function stripTextboxText(objFormElement){
	if (! blnStrippedText) {
		objFormElement.value = "";
		blnStrippedText = true ;
	}	
	return;
}



/*********************************************************************
'***    Program: countDelimiters(strToCheck,strDelimiter) 
'***    Type: Function
'***
'***    Function: Tests a string for presence of delimiters
'***
'***    Parameters: 
'***		strToCheck - sting to check for validity
'***        strDelimiter - delimiter string
'*** 
'***    Returns: Qty of found delimiters
'***    Remarks: none
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 11/04/02
'*********************************************************************/
function countDelimiters(strToCheck,strDelimiter) {
 
  var checkStr = strToCheck;
  var DelimiterCounter = 0 ;
 
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    if (ch == strDelimiter){
		DelimiterCounter = DelimiterCounter + 1;
    }
  }
  return (DelimiterCounter);
  
}



/*********************************************************************
'***    Program: getCleanKeywordsForJobCompanyName
'***    Type: Function
'***
'***   Function: Analyze incoming string for signs of full text search syntax
'***    	      and attempts to fix syntax issues by removing comers and replacing them with " or" operator.
'***		
'***
'***    Parameters: 
'***		strKeywords - string to analyze
'***
'***    Returns: String
'***    Remarks: none
'***    created by: rburdan
'***    Changed by: 
'***    Last change: 11/15/02
'*********************************************************************/
function getCleanKeywordsForJobCompanyName( strDirtyKeywords ) {

	var sValue = strDirtyKeywords;
        
    // remove leading and trailing spaces
	sValue = sValue.replace(/(^ *)|( *$)/g, "");

    // remove commers and replace them with " or"
	sValue = sValue.replace(/(,+)/g, " or ");
	
    // replace any number of spaces with just one space
	sValue = sValue.replace(/( +)/g, " ");
	

	return sValue;
}

/*********************************************************************
'***    Program: checkAllBoxes
'***    Type: Procedure
'***
'***   Function: puts checkmarks in all checkboxes of the specified array
'***		
'***
'***    Parameters: 
'***		objCheckBoxArray - array of checkboxes
'***
'***    Returns: none
'***    Remarks: none
'***    created by: sofiav
'***    Changed by: 
'***    Last change: 5/7/03
'*********************************************************************/
function checkAllBoxes( objCheckBoxArray ) {
	if (objCheckBoxArray.length) {
		// Array
		for (var i=0; i < objCheckBoxArray.length; i++) {
			objCheckBoxArray[i].checked = true;
		}
	}
	else {
		// single checkbox
		objCheckBoxArray.checked = true;
	}
}

function getVarDate( strDate, strFormat ) {
	var dtmResult = NaN;
	var intMonthPos = -1;
	var intYearPos  = -1;
	var intMonth = 0;
	var intDay = 0;
	var intYear = 0;
	
	if (strFormat != null && strFormat != "" && strDate != "") {
		strFormat = strFormat.toUpperCase();
		
		intMonthPos = strFormat.indexOf("MM");
		intDayPos   = strFormat.indexOf("DD");
		intYearPos  = strFormat.indexOf("YYYY");
		
		if (intDayPos >= 0 && intMonthPos >= 0 && intYearPos >= 0) {
			intMonth = strDate.substr(intMonthPos, 2);
			intDay   = strDate.substr(intDayPos,   2);
			intYear  = strDate.substr(intYearPos,  4);
			
			if (intDay <= 31 && intMonth <= 12 && intYear <= 9999) {
				dtmResult = new Date(intYear, intMonth - 1, intDay).getVarDate();
			}
		}
	}
	return dtmResult;
}

function populateAttachedDocumentsOnParentForm(objForm) {
	var strAttachedDocsHTML = "";
	var divAttachedDocs     = null;
	var objAttachDocs = null;

	if (self.opener != null && !self.opener.closed) {
		if (navigator.appName == "Netscape") {
			strVersion = new String(navigator.appVersion);
			if (strVersion.charAt(0) >= 5) {
				if (eval('self.opener.document.getElementById("AttachDocs")')) {
					objAttachDocs = self.opener.document.getElementById("AttachDocs");
				}
			}
		}
		else {
			if (eval('self.opener.document.all.AttachDocs')) {
				objAttachDocs = self.opener.document.all.AttachDocs;
			}
		}
		if (objAttachDocs != null) {
			if (eval('objForm.AttachedDocsHTML')) {
				with (objForm) {
					objAttachDocs.innerHTML = AttachedDocsHTML.value;
				}
			}
		}
	}
	CloseCurrentWindow();
}

/*********************************************************************
'***    Program: isCurrencyString(strToCheck) 
'***    Type: Function
'***
'***    Function: Tests a string for presence of digit and formatting chars
'***				$,
'***
'***    Parameters: 
'***		strToCheck - sting to check for validity
'***
'***    Returns: True/False
'***    Remarks: none
'***
'***    Created by: sofiav
'***    Changed by: sofiav
'***    Last change: 09/23/04
'*********************************************************************/
function isCurrencyString(strToCheck) {
  var checkOK = "0123456789.,$ ";
  var checkStr = strToCheck;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
  }
  return (allValid);
}


/*********************************************************************
'***    Program: Trim
'***    Type: Procedure
'***
'***   Function: trims string
'***		
'***
'***    Parameters: 
'***		strToTrim - string
'***
'***    Returns: trim string
'***    Remarks: none
'***    created by: rburdan
'***    Changed by: 
'***    Last change: 11/01/04
'*********************************************************************/

function Trim(strToTrim){
	var strName = new String(strToTrim);

	while(''+strName.charAt(strName.length-1)==' ')
	strName=strName.substring(0,strName.length-1);
	return strName
}


/*********************************************************************
'***    Program: 
'***    Type: 
'***
'***    Function: 
'***		
'***
'***    Parameters: objParentListBox - Parent ListBox
'***	       	    objChildListBox  - Child ListBox
'***
'***    Returns: 
'***    Remarks: none
'***    created by:  rburdan
'***    Changed by:  rburdan
'***    Last change: 04/08/05
'*********************************************************************/
function populateChildListBoxHTML(objParentListBox, objChildListBox, strDefaultText, blnShowDefaultTextIfEmpty){
	var strParentValue = new String("");
	var strParentText = new String("");
	var intParentOption = 0;
	var intChildOption = 0;
	var arrParentSelected = new Array();
	var arrParentTextSelected = new Array();
	var strHTML = "";
	var strChildSelectedItems = new String("");
	var strSelect = "";
	var blnChildHasListOptions = false;

	if (strDefaultText == null) {
		strDefaultText = "Select Parent";
	}
	if (blnShowDefaultTextIfEmpty == null) {
		blnShowDefaultTextIfEmpty = false;
	}

	strParentValue = getSelectedItems(objParentListBox);
	strParentText  = getSelectedItemTexts(objParentListBox);
	
	arrParentSelected = strParentValue.split(",");
	arrParentTextSelected = strParentText.split(",");
	
	if (objChildListBox == null) {
		strChildListBoxName = "cg"; 
		strChildListBoxSize = 11;
		strChildSelectedItems = "";
	}
	else {
		strChildListBoxName = objChildListBox.name;
		strChildListBoxSize = objChildListBox.size;
		// Save Selected Items from Child ListBox
		strChildSelectedItems = getSelectedItems(objChildListBox);
	}
	
	strHTML = " <SELECT NAME='" + strChildListBoxName + "' MULTIPLE SIZE='" + strChildListBoxSize + "'> ";
	
	
	strChildSelectedItems = "," + strChildSelectedItems + ","
	
	for (var intIndex = 0; intIndex < arrParentSelected.length; intIndex++) {

        strParentValue = arrParentSelected[intIndex];
        strParentText = arrParentTextSelected[intIndex];
        
		for (intParentOption = 0; intParentOption < arrDroups.length-1; intParentOption++) {
	
			if(arrDroups[intParentOption].id1 == strParentValue){
			
				if( strChildSelectedItems.indexOf("," + arrDroups[intParentOption].id2 + ","  )  >=0 ){
					strSelect = " SELECTED ";
			    }
			
			    strHTML += " <OPTION VALUE='" + arrDroups[intParentOption].id2 + "'" + strSelect  + ">" + arrDroups[intParentOption].name2 + "</OPTION>";
			
				//alert(arrDroups[intParentOption].name2);
				
				intChildOption += intChildOption;
				strSelect = "";	
				
				blnChildHasListOptions = true;
				
			}
		}
	}
	
	strHTML += " </SELECT> ";

	// Replace Child ListBox with a new Data using DIV id="Child_" + strChildListBoxName
	if (eval('document.getElementById("Child_" + strChildListBoxName)')) {
		var objChild = document.getElementById("Child_" + strChildListBoxName);
		objChild.innerHTML = strHTML;
		if (!blnChildHasListOptions && blnShowDefaultTextIfEmpty) {
			objChild.innerHTML = strDefaultText;
		}
	}

	return true;
}

/*********************************************************************
'***    Program: 
'***    Type: 
'***
'***    Function: 
'***		
'***
'***    Parameters: 
'***		
'***
'***    Returns: 
'***    Remarks: none
'***    created by: rburdan
'***    Changed by: 
'***    Last change: 04/08/05
'*********************************************************************/

function Group(id1, id2, name2){
	this.id1 = id1;

	this.id2 = id2;
	this.name2 = name2;
	
	return true;
}

/*********************************************************************
'***    Program: unSelectListItem( objList, strItemValue )
'***    Type: Function
'***
'***    Function: un-Selects item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemValue  - value to look for. the item with this value gets un-selected
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function unSelectListItem( objList, strItemValue ) {
	for (var i=0; i < objList.length; i++) {
		if (objList.options[i].value == strItemValue) {
			// this item needs to get selected
			objList.options[i].selected = false;
		}
	}
	return;
}

/*********************************************************************
'***    Program: unSelectListItemByText( objList, strItemText )
'***    Type: Function
'***
'***    Function: un-Selects item in a list box
'***
'***    Parameters: 
'***		objList - listbox (select) object
'***		strItemText  - text to look for. the item with this text gets un-selected
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: Dimab
'***    Changed by: Dimab
'***    Last change: 8/12/99
'*********************************************************************/
function unSelectListItemByText( objList, strItemText ) {
	for (var i=0; i < objList.length; i++) {
		if (objList.options[i].text == strItemText) {
			// this item needs to get unselected
			objList.options[i].selected = false;
		}
	}
	return;
}


/*********************************************************************
'***    Program: isRadioButtonSelectionMade
'***    Type: function
'***
'***   Function: returns true if any radio button of the specified name is 
'***			 selected on the specified form
'***		
'***
'***    Parameters: 
'***		objForm - form object
'***		strRadioName - name of the radiobutton group
'***
'***    Returns: trim string
'***    Remarks: none
'***    created by: rburdan
'***    Changed by: 
'***    Last change: 11/01/04
'*********************************************************************/

function isRadioButtonSelectionMade(objForm, strRadioName) {
	var objButton = null;
	var blnResult = false;
		
	with (objForm) {
		objButton = eval(strRadioName)
		if (objButton != null) {
			for (var i = 0; i < objButton.length; i++) {
				if (objButton[i].checked) {
					blnResult = true;
					break;
				}
			}
		}
	}
		
	return blnResult;
}


/*********************************************************************
'***    Program: SelectedListItemsLimiter(lstWhereToLook, intItemsLimit, strLimitedItemsName)
'***    Type: Function
'***
'***    Function: 
'***
'***    Parameters: 
'***		lstWhereToLook      - listbox object where to look
'***        intItemsLimit       - items limit
'***		strLimitedItemsName - Name of group( like: "Category" or "Employment Type",...)
'*** 
'*** 
'***    Returns: false if user chose more then intItemsLimit items
'***    Remarks: none
'***
'***    Created by: rburdan
'***    Changed by: rburdan
'***    Last change: 07/08/2005
'*********************************************************************/

function SelectedListItemsLimiter(lstWhereToLook, intItemsLimit, strLimitedItemsName) {
	var strCategories = new String("");
	var intCount = 0;
	
	strCategories = getSelectedItemsWithDevider(lstWhereToLook, ",");
	intCount      = countDelimiters(strCategories, ",");
		
	if(intCount > intItemsLimit){
		alert("Please choose less then " + intItemsLimit + " " + strLimitedItemsName);
		lstWhereToLook.focus();
		return false;
	}
	
	return true;
} 

/*********************************************************************
'***    Program: getNumberOfSelectedCheckboxes
'***    Type: Function
'***
'***    Function: calculates a number of selected checkboxes using the current document's DOM
'***
'***    Parameters: none
'*** 
'***    Returns: integer, a number of checkboxes selected
'***    Remarks: none
'***
'***    Created by: dimab
'***    Changed by: dimab
'***    Last change: 04/18/2007
'*********************************************************************/
function getNumberOfSelectedCheckboxes() {
	var intCheckedCount = 0;
	var objElements = document.getElementsByTagName("input");
	for (intItemIndex = 0; intItemIndex < objElements.length; intItemIndex++) {
		if (objElements[intItemIndex].type=="checkbox" && objElements[intItemIndex].checked)
			intCheckedCount++;
	}
	return intCheckedCount;
}

/*********************************************************************
'***    Program: takes an Option Text value and selects, preserves previous selection
'***    Type: Function
'***
'***    Function: selectListboxOptionByText( objForm, objElement, strNewOptionText ) 
'***
'***    Parameters: objForm, - form the element is on
					objElement, - the element on the form, to select item
					strNewOptionText - Option text value to select
'*** 
'***    Returns: integer, a number of checkboxes selected
'***    Remarks: none
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 06/28/2007
'*********************************************************************/
function selectListboxOptionByText( objForm, objElement, strNewOptionText ){
	var strSelectedItems	= new String( "" );
	var strItemValue		= new String( strNewOptionText );	

	with( objForm ){
		//Get all listbox options selected 
		strSelectedItems = 	getSelectedItems( objElement );
		//check if there are any selected items 
		if( !IsStringEmpty( strSelectedItems ) ){
			//check if new value has been specified to select
			if( !IsStringEmpty( strItemValue ) ){
				for( var iOption = 0; iOption < objElement.options.length; iOption++ ){
					selectListItemByText( objElement, strItemValue );
				}
			}
		}
	}
}	

/*********************************************************************
'***    Program: takes an Option Text value and selects, preserves previous selection
'***    Type: Function
'***
'***    Function: IsStringEmpty( strString )
'***
'***    Parameters: strString - string to check for emptyness
'*** 
'***    Returns: If Emptry: true, else : false
'***    Remarks: none
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 06/28/2007
'*********************************************************************/
function IsStringEmpty( strValue ){
    //check string length or nullness, return true either is true, else false
    return ( 0 == new String( ( strValue == null ) ? "" : Trim(strValue) ).length );
}

/*********************************************************************
'***    Program: tickCheckBoxesByName(objCheckBox)
'***    Type: Function
'***
'***    Function: "select all" specified checkboxes
'***
'***    Parameters: array or single objCheckBox
'***		
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 07/12/2007
'*********************************************************************/
function tickCheckBoxesByName( objCheckBox ){
	var blnExists = ( ( typeof(objCheckBox) == "object" )  && ( objCheckBox[0].type == "checkbox" ) );

    if( blnExists ){
        var intCheckBoxCount = objCheckBox.length;

        if( intCheckBoxCount ){
	        if (isCheckBoxSelected( objCheckBox )){
		        for(var i = 0; i < intCheckBoxCount; i++) objCheckBox[i].checked = false;
	        } else{ 
	            for(var i = 0; i < intCheckBoxCount; i++) objCheckBox[i].checked = true; 
	        }
	    } else {
	        if (isCheckBoxSelected( objCheckBox )){objCheckBox.checked = false;} 
	        else{objCheckBox.checked = true; }	    
	    }
	} else {
	    alert("Either the checkbox does not exist or you may have specified an incorrect name!");
	}
return blnExists;
}

/*********************************************************************
'***    Function: selectAllListOptionsWithToggle( objListBox, blnOnOffToggle )
'***
'***    Parameters: 
'***		objListBox, - listbox (select-multiple) object
'***		blnOnOffToggle - select unselect toggle
'***
'***    Returns: Void
'***    Remarks: no toggle specified functions as select all
'***             with toggle, functions as select/unselect all
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 08/22/2008
'*********************************************************************/
function selectAllListOptionsWithToggle( objListBox, blnOnOffToggle ){
    
    blnOnOffToggle = ( typeof(blnOnOffToggle) == "boolean" ) ? blnOnOffToggle : true;
    var blnIsMultiSelect = (typeof(objListBox) == "object") && 
                            (objListBox.type == "select-multiple");    
    if( blnIsMultiSelect ){
        var objOptions = objListBox.options;

        for (var i=0, optLen = objOptions.length; i < optLen; i++) {
            objOptions[i].selected = blnOnOffToggle;
        }
    }
}

/*********************************************************************
'***    Function: isAllListBoxOptionSelected( objListBox )
'***
'***    Parameters: 
'***		objListBox, - listbox (select-multiple) object
'***
'***    Returns: boolean {all options selected: true | false, otherwise }
'***    Remarks: checks whether all multi-select listbox options are selected
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 08/22/2008
'*********************************************************************/
function isAllListBoxOptionSelected( objListBox ){

    var blnIsMultiSelect = (typeof(objListBox) == "object") && 
                            (objListBox.type == "select-multiple");
    var blnSelected = false;
    if( blnIsMultiSelect ){
        var objOpts = objListBox.options;
        var intOptLen = objOpts.length;
        var intSelOptCount = 0;
	    
	    //for each option, if it is selected increment count
	    for (var i=0; i < intOptLen; i++) {
            //increment count for each option selected
            if(objOpts[i].selected) intSelOptCount++;
	    }
	    //if selected option count == options.length
	    //then every option is selected
	    blnSelected = ( intOptLen == intSelOptCount );
	    objListBox = objOpts = null;
    }
return blnSelected;
}

/*********************************************************************
'***    Function: resetPageSection
'***
'***    Parameters: strDivID - div to show/hide
'***		        strImgID - image to click on to show/hide div
'***
'***    Returns: 
'***
'***    Created by: rburdan
'***    Changed by: 
'***    Last change: 12/03/2008
'*********************************************************************/
function resetPageSection( strDivID, strImgID ){

    var objDiv = document.getElementById(strDivID);
    
    if(objDiv.style.visibility == "visible"){
        blnVisible = false;
    }
    else{
        blnVisible = true;
    }
    
    showHidePageSection( strDivID, strImgID, blnVisible);
}

/*********************************************************************
'***    Function: resetPageSection
'***
'***    Parameters: strDivID   - div to show/hide
'***		        strImgID   - image to click on to show/hide div
'***                blnVisible - set show/hide
'***    Returns: 
'***
'***    Created by: rburdan
'***    Changed by: 
'***    Last change: 12/03/2008
'*********************************************************************/
function showHidePageSection( strDivID, strImgID,  blnVisible ){
    blnVisible = (typeof(blnVisible) == "boolean") ? blnVisible : false;
    
    var objDiv = document.getElementById(strDivID);
    var objImg = document.getElementById(strImgID);

    if( objDiv != null ){

        objDiv.style.visibility = (blnVisible) ? "visible" : "hidden";
        objDiv.style.position   = (blnVisible) ? "static" : "absolute"; 

        if( objImg != null )
            objImg.src = (blnVisible) ? "/Media/Images/hide.gif" : "/Media/Images/show.gif"; 
        
    }
}

/*********************************************************************
'***    Function: ifCheckBoxSelectedSubmit
'***
'***    Parameters: objForm    - object Html Form
'***		        strMessage - message string
'***                
'***    Returns: 
'***
'***    Created by: rburdan
'***    Changed by: 
'***    Last change: 12/12/2008
'*********************************************************************/
function ifCheckBoxSelectedSubmit(objForm, strMessage){

    if(strMessage == null){
        strMessage = "Please select at least one job";
    }
    
	if (! isCheckBoxSelected(objForm.JobID) ) {
		alert(strMessage);
	}
	else {
		objForm.submit();
	}
}

/*********************************************************************
'***    Program: stripTextboxTextEx
'***    Type: Function
'***
'***    Function: removes default text in a text box when user places
'***		the cursor in the text box
'***
'***    Parameters: 
'***		objForm - form and element name
'***
'***    Returns: empty string
'***    Remarks: requires "
'***
'***    Created by: jeffl
'***    Changed by: rburdan
'***    Last change: 12/22/08
'*********************************************************************/
function stripTextboxTextEx(objFormElement){
	objFormElement.value = "";
	return;
}

/*********************************************************************
'***    Program: SelectAllCheckBox()
'***    Type: Function
'***
'***    Function: select all checkbox
'***
'***    Parameters: 
'***		none
'***
'***    Created by: jzhou
'***    Changed by: dimab
'***    Last change: 12/26/2008
'*********************************************************************/
function SelectAllCheckBoxesWithHighlight(){
	var blnFirstCheckValue = IsFirstCheckBoxChecked();
	var aDivs = document.getElementsByTagName('input');

	for(var i = 0; i < aDivs.length; i++) {
	
		if(aDivs[i].type == "checkbox" && aDivs[i].disabled == false) {
			
			// highligh row, only do this if we are looking at a row!
			if (aDivs[i].parentNode.parentNode.nodeName.toLowerCase() == "tr") {
				aDivs[i].checked = ! blnFirstCheckValue;
				aDivs[i].parentNode.parentNode.className = (aDivs[i].checked ? "highlight" : "");
			}
		}
	}
}

/*
	same as above, but does not highlight rows 
*/
function SelectAllCheckBoxes(){
	var blnFirstCheckValue = IsFirstCheckBoxChecked();
	var aDivs = document.getElementsByTagName('input');

	for(var i = 0; i < aDivs.length; i++) {
		if(aDivs[i].type == "checkbox" && aDivs[i].disabled == false)
			aDivs[i].checked = ! blnFirstCheckValue;
	}
}
/*********************************************************************
'***    Function: determines if 1st checkbox found on the page is checked
'***
'***    Parameters: none
'***    Returns: boolean
'***
'***    Created by: dimab
'***    Changed by: 
'***    Last change: 12/28/2008
'*********************************************************************/
function IsFirstCheckBoxChecked(){
	var aDivs = document.getElementsByTagName('input');
	
	for(var i = 0; i < aDivs.length; i++) {
		if(aDivs[i].type == "checkbox")
			return aDivs[i].checked;
	}
	return false;
}
/*********************************************************************
'***    Function: highlights selected checkboxes on a page
'***
'***    Parameters: none
'***    Returns: void

	assumes:
	1. that each is located in a <td> within <tr>
	2. class "highlight" is available in current css

'***
'***    Created by: dimab
'***    Changed by: 
'***    Last change: 12/28/2008
'*********************************************************************/
function HighlightSelectedCheckBoxes(){
	var aDivs = document.getElementsByTagName('input');

	for(var i = 0; i < aDivs.length; i++) {
		if(aDivs[i].type == "checkbox")
			aDivs[i].parentNode.parentNode.className = (aDivs[i].checked ? "highlight" : "");
	}
}

/*********************************************************************
'***    Function: showHideDiv
'***
'***    Parameters: strDivID   - div to show/hide
'***                blnVisible - set show/hide
'***    Returns: 
'***
'***    Created by: rburdan
'***    Changed by: 
'***    Last change: 01/02/2009
'*********************************************************************/
function showHideDiv( strDivID,  blnVisible ){
	
    blnVisible = (typeof(blnVisible) == "boolean") ? blnVisible : false;
    
    var objDiv = document.getElementById(strDivID);

    if( objDiv != null ){
        objDiv.style.visibility = (blnVisible) ? "visible" : "hidden";
        objDiv.style.position   = (blnVisible) ? "static" : "absolute"; 
    }
}
    
/*********************************************************************
'***    Function: AjaxGet
'***
'***    Parameters: 

			url - url to request
			resultId - id where result is shown (must be visible)
			errorMessage - custom error message in case of http error

'***    Returns: void
'***	Remarks: requires reference to prototype.js
'***
'***    Created by: dimab
'***    Changed by: 
'***    Last change: 14/03/2009
'*********************************************************************/
function AjaxGet( url, resultId, errorMessage ) {
	if (errorMessage == null)
		errorMessage = "error";
		
	new Ajax.Request( url,
		{ method:'get',	
			onSuccess: function(transport) {
				var e = document.getElementById(resultId);
				if (e != null)
					e.innerHTML = transport.responseText;
			},
			onFailure: function() {
				var e = document.getElementById(resultId);
				if (e != null)
					e.innerHTML = errorMessage;
			}
		});
}

/*********************************************************************
'***    Function: AjaxGetWithCallback
'***
'***    Parameters: 
        strURL      - url to issue ajax get
        containerId - elem to update with respnse result
        msgErr      - error msg to set to element if op. failed
        onSuccessFunc - callback func. if op. is successful
'***
'***    Returns: void
'***    Remarks: 
'***    - get all current resume's experience items
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/15/2009
'*********************************************************************/
function AjaxGetWithCallback(strURL, containerId, msgErr, onSuccessFunc, onCompleteFunc) {
    msgErr = (msgErr == null) ? "request failed!" : msgErr;
    
    new Ajax.Request( strURL, {
        method: 'get',
        onSuccess: function(transport) {
            if( typeof(onSuccessFunc) == "function" ) {
                onSuccessFunc(transport);
            }
            else {//add by vadymn to make onSuccessFunc parameter optional
				var e = document.getElementById(containerId);
				if (e != null)
					e.innerHTML = transport.responseText;
            }
        },
        onComplete: function(transport) {
            onCompleteFunc(transport);
        },        
        onFailure: function(transport) {
            //set error message
            var el = document.getElementById(containerId);
            if (el != null)
                el.innerHTML = msgErr;
        }
    });
}

/*********************************************************************
'***    Function: AjaxFormSubmit(
'***
'***    Parameters: 
        formID          - form element id submitting the data
        onCompleteFunc  - func ref. to call when op. is complete
        onSuccessFunc   - func ref. to call when op. is successful
        onFailureFunc   - func ref. to call when op. failed
'***
'***    Returns: void
'***    Remarks: 
        - serializes elements as <name> : <value> page
        - submits url on form.action, or current page url
        - calls func ref as callback based on response state
        - depends on prototype.js ajax library
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function AjaxFormSubmit(formID, onCompleteFunc, onSuccessFunc, onFailureFunc) {
    //build options with callback functions
    var options = {
        //call call back when operation is complete
        onComplete: function(transport) {
            onCompleteFunc(transport);
        },
        //call call back function if operation is sucessful
        onSuccess: function(transport) {
            onSuccessFunc(transport);
        },
        //call call back function if operation failed
        onFailure: function(transport) {
            onFailureFunc(transport);
        }
    };

    //extended form element request serializes form elements as {<name> : <value>} pair
    //submits to form action url, if no action url foud, it uses current page url
    $(formID).request(options);
}

/*********************************************************************
'***    Function: getLoadedXmlDoc
'***
'***    Parameters:
'***        xmlData - response xml string to check for error 
'***    Returns: boolean
'***	Remarks:
'***		returns XmlDocument
'***    Format:
'***    Sample XML Error Response
        <response>
            <returnCode>-1</returnCode>
                <result>
                    <error>
                        <number>100</number>
                        <description>Resume Experience was not found.</description>
                        <source/>
                    </error>
                    <error>...<//error>
                </result>
            </response>
'***    Sample XML Success Response
        <response>
            <returnCode>0</returnCode>
            <result>Resume Experience record has been changed.<result>
        </response>
            
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/13/2009
'*********************************************************************/
function getLoadedXmlDoc(xmlData) {
    var xmlDoc = null;

    //return null if response is empty
    if ((xmlData == null) || (xmlData == ""))
        return xmlDoc;

    //to respect different browser implementation, try
    try {//Internet Explorer
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xmlData);
    }
    catch (e) {//Firefox, Mozilla, Opera, etc.
        try {
            var parser = new DOMParser();
            xmlDoc = parser.parseFromString(xmlData, "text/xml");
            parser = null;
        }
        catch (e) {
            //return null if unable to parse
            xmlDoc = null;
        }
    }
    return xmlDoc;
}

/*********************************************************************
'***    Function: responseHasError
'***
'***    Parameters:
'***        xmlData - response xml string to check for error 
'***    Returns: boolean
'***	Remarks:
'***		returns true if response has error, false otherwise
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/12/2009
'*********************************************************************/
function responseHasError(xmlData) {
    //get a response error code
    var intCode = getResponseCode(xmlData);

    //if code is not 0, error exist, else no error detected
    return (intCode != 0) ? true : false;
}

/*********************************************************************
'***
'***    Function: getResponseErrorMessage
'***
'***    Parameters:
'***				xmlData - response xml to with error messages
'***				
'***    Returns: string
'***	Remarks:
'***		returns "" if no error, error description content if has error
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/12/09
'*********************************************************************/
function getResponseErrorMessage(xmlData) {

    var msgDesc = "";

    try {
        var xmlDoc = getLoadedXmlDoc(xmlData);
        var nodeList = xmlDoc.getElementsByTagName("description");

        //extract the all error descriptions from node list using a loop.
        if (nodeList != null) {
            var i = 0;
            //uncomment loop to get multiple description errors
            //for(i = 0; i < nodeList.length - 1;i++)
            msgDesc += nodeList[i].firstChild.nodeValue + "\n";
        }

        xmlDoc = nodeList = null;
    }
    catch (e) {
        // parsing error message
        msgDesc = "parsing error. unable to parse response";
    }
    return msgDesc;
}

/*********************************************************************
'***
'***    Function: getResponseSuccessMessage
'***
'***    Parameters:
'***				xmlData - response xml string
'***				
'***    Returns: string
'***	Remarks:
'***		returns success message if successful
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/12/09
'*********************************************************************/
function getResponseSuccessMessage(xmlData) {

    var msgDesc = "";

    try {
        //if no response error, grab text from result node
        if (!responseHasError(xmlData)) {
            var xmlDoc = getLoadedXmlDoc(xmlData);
            var objNode = xmlDoc.getElementsByTagName("result");
            //extract the result message, make sure node is not empty (e.g. <result />)
            if (objNode != null && ( objNode[0].firstChild != null) )
                msgDesc = objNode[0].firstChild.nodeValue + "\n";

            xmlDoc = objNode = null;
        }
    }
    catch (e) {
        // parsing error message
        msgDesc = "parsing error. unable to parse response";
    }
    return msgDesc;
}

/*********************************************************************
'***
'***    Function: getResponseMessage
'***
'***    Parameters:
'***        xmlData - response xml string
'***				
'***    Returns: string
'***	Remarks:
'***		returns response message
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/13/09
'*********************************************************************/
function getResponseMessage(xmlData, msgDefault) {
    var msgText = "";
    if (responseHasError(xmlData))
        msgText = getResponseErrorMessage(xmlData);
    else
        msgText = getResponseSuccessMessage(xmlData);

    //if message is empty use specified default message
    if (msgText == "")
        msgText = ((msgDefault == null) ? "" : msgDefault);

    return msgText;
}

/*********************************************************************
'***
'***    Function: getResponseErrorCode
'***
'***    Parameters:
'***				xmlData - response xml to check for error
'***				
'***    Returns: XML string
'***	Remarks:
'***		returns true if response has error
'***
'***    Created  by: niloa
'***    Changed  by: niloa
'***    Last change: 03/13/09
'*********************************************************************/
function getResponseCode(xmlData) {
    var intCode = 0;
    try {
        //load xml data
        var xmlDoc = getLoadedXmlDoc(xmlData);
        //get return code node
        var objNode = xmlDoc.getElementsByTagName("returnCode")[0].childNodes[0];
        if (objNode != null)
            intCode = objNode.nodeValue;
    }
    catch (e) {
        intCode = -100; //parsing error
    }
    return intCode;
}

/*********************************************************************
'***    Function: showElementById
'***
'***    Parameters: 
'***    elemId - element id to show
'***
'***    Returns: void
'***    Remarks: 
'***    - makes elem visible via its display property
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function showElementById(elemId) {
    //get the element
    var el = document.getElementById(elemId);

    //if found, set display property to none (hide)
    if (el != null)
        el.style.display = "block";
}

/*********************************************************************
'***    Function: hideElementById
'***
'***    Parameters: 
'***    elemId - element id to hide
'***
'***    Returns: void
'***    Remarks: 
'***    - makes elem invisible via its display property
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function hideElementById(elemId) {
    //get the element
    var el = document.getElementById(elemId);
    //if found, set display property to none (hide)
    if (el != null)
        el.style.display = "none";
}
/*********************************************************************
'***    Function: setElementClassById
'***
'***    Parameters: 
'***    elemId - element id to show
'***    className - existing css class name to use
'***
'***    Returns: void
'***    Remarks: 
'***    - sets elem css class via its className property
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function setElementClassById(elemId, className) {
    //get element by id
    var el = document.getElementById(elemId);
    if (el != null)
        el.className = className;
}

/*********************************************************************
'***    Function: toggleElementClassById
'***
'***    Parameters: 
'***    elemId     - element id to show
'***
'***    Returns: void
'***    Remarks: 
'***    - alternates element class
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function toggleElementClassById(elemId, className1, className2) {
    var el = document.getElementById(elemId);

    //make sure element exist
    if (el != null) {

        //if current class is not className1, change it
        if (el.className != className1)
            setElementClassById(elemId, className1);

        //otherwise, set it to className2
        else
            setElementClassById(elemId, className2);
    }
}

/*********************************************************************
'***    Function: toggleElementDisplayById
'***
'***    Parameters: 
'***    elemId     - element id to show
'***
'***    Returns: void
'***    Remarks: 
'***    - makes elem visible via its display property
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/17/2009
'*********************************************************************/
function toggleElementDisplayById(elemId) {
    var el = document.getElementById(elemId);

    //make sure element exist
    if (el != null) {

        //if element is invisible, display it
        if (el.style.display == "none")
            showElementById(elemId);

        //if element is visible, hide it
        else
            hideElementById(elemId);
    }
}

/*********************************************************************
'***    Function: ValidateWordLengthsInText
'***    Validates specified text by examining the length of each word (determines words using spaces)
'***	Measures each word’s length against the specified value maxLength, see returns section for return values.
'***
'***    Parameters: text – (string) text to analyze
'***                maxLength – (int) maximum length allowed
'***
'***    Returns: true – if all words pass validation (word length <= maxLength)
'***             false – at least one word fails validation

'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 01/30/2009
'*********************************************************************/
function ValidateWordLengthsInText( text, maxLength ) {

    var SplittedText = text.split(" ");

    
    for ( i=0; i<=SplittedText.length-1; i++ ) {
        if ( SplittedText[i].length > maxLength ) return false;

    }
	return true;
}


/*********************************************************************
'***    Function: showRemainingChars
'***
'***    Parameters: 
'***    elFieldId - field element id to retrieve text
'***    elMsgId - message container element id 
'***    maxCharCount - maximun characters allowed
'***
'***    Returns: void
'***    Remarks: 
'***    - calculates and updates unused chars for a form field element
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 04/16/2009
'*********************************************************************/
function showRemainingChars(elFieldId, elMsgId, maxCharCount) {

    if (elFieldId == null)
        elFieldId = 'Summary';

    if (elMsgId == null)
        elMsgId = 'charsRemain';

    //max chars allowed
    if (maxCharCount == null)
        maxCharCount = 300;

    with (document) {
        var elField = getElementById(elFieldId);
        var elMsg = getElementById(elMsgId);

        //remaining chars -1 to compensate for lag time
        var intCharsRemain = Math.max(0, (maxCharCount - elField.value.length));
        if (intCharsRemain > maxCharCount)
            intCharsRemain = 0;

        //chars over the limit +1 to compensate for lag time
        var charsOver = (elField.value.length - maxCharCount);
        var msg = "remaining characters: " + intCharsRemain;
        if (charsOver > 0)
            msg += " (" + charsOver + " over limit and will be truncated)";

        //refresh remaining chars section (subtract -1 due to keypress event delay)
        elMsg.innerHTML = msg;
    }
}

/*********************************************************************
'***    Function: truncateText
'***
'***    Parameters: 
'***    elFieldId - field element id to retrieve text
'***    elMsgId - message container element id 
'***    maxCharCount - maximun characters allowed
'***
'***    Returns: void
'***    Remarks: 
'***    - shortens Form field element text to specified length
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 04/16/2009
'*********************************************************************/
function truncateFieldValue(elFieldId, elMsgId, maxCharCount) {

    if (elFieldId == null)
        elFieldId = 'Summary';

    if (elMsgId == null)
        elMsgId = 'charsRemain';

    //max chars allowed
    if (maxCharCount == null)
        maxCharCount = 300;

    //get values and message elements
    var elField = document.getElementById(elFieldId);
    var elMsg = document.getElementById(elMsgId);

    var intCharsRemain = Math.max(0, maxCharCount - elField.value.length);

    //if value's over the limit, shorten to fit, and set messages
    if (elField.value.length > maxCharCount) {
        elField.value = String(Trim(elField.value)).slice(0, maxCharCount);
        var msg = "remaining characters: " + intCharsRemain +
                        " (truncated to maximum length of " + maxCharCount + ")";
        elMsg.innerHTML = msg;
    }
}

/*********************************************************************
'***    Function: isLeapYear( intYear )
'***
'***    Parameters: 
'***        intYear - year to check for leap year
'***	Return: boolean (true - is a leap year, false - not a leap year)
'***
'***    Remarks:     
'***        //A year is a leap year not only if it is divisible by 4 
'***        //it also has to be divisible by 400 if it is a centurial year. 
'***        //e.g. 1700, 1800 and 1900 were not leap years, but 2000 was.
'***
'***	Use example:
'***		isLeapYear( 2008 ) --> true - is a leap year
'***		isLeapYear( 2009 ) --> false - not a leap year
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 10/07/2009
'*********************************************************************/
function isLeapYear(year) {
    year = parseInt(year);
    if (isNaN(year)) return false;
    return ((year % 4 == 0) && (!(year % 100 == 0) || (year % 400 == 0)));
}

/*********************************************************************
'***    Function: getDaysInMonth( month, year )
'***
'***    Parameters: 
'***		month - month number
'***        year - year to check for leap year
'***	Return: integer
'***
'***    Remarks: get the correct number of days in month for year
'***    considering leap years for february days
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 10/07/2009
'*********************************************************************/
function getDaysInMonth(month, year) {
    month = parseInt(month,10);
    year = parseInt(year);

    if (isNaN(month) || isNaN(year))
        return 0;

    if ((month < 1) || (month > 12) || (year <= 0))
        return 0;

    //check leap year to set Feb days: 28 or 29
    var daysInFeb = isLeapYear(year) ? 29 : 28;
    var days = [0, 31, daysInFeb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    return days[month];
}

