/*********************************************************************
'***    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: 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:  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 = 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.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
}


/*********************************************************************
'***    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;
    }
}
