/*
----------- FundSys.net(TM) Copyright SySys(R) Corp 2002 ------------
====================================================================
  Created By: BH
  Last Edited By: BH
  Inception Date: 1/1/2002
  Last Edited Date: 1/1/2002
  Description:  None
  Required Files: image_effects_management.js
  File Dependencies: Manage_form.js
										 Manage_image_effects.js
										 manage_dhtml_layer.js
										 manage_array.js
===================================================================''*/

/*------------------------------------
   GLOBAL VARIABLE LIST
------------------------------------*/
//stores names of forms that have been marked dirty
var dirtyFormList = new Array();  //on page load the form has not changed
/*------------------------------------
   INITILIZE
------------------------------------*/
dirtyFormList.length = 0;


/*'''---------------------------------
'' pageLoad()
--------------------------------------
   Created By: SySys:bh
   Compatibility: All Browsers that support Javascript files
   Description: Dummy function that is only defined and designed to be overidden
----------------------------------'''*/ 
function pageLoad(){}

/*'''---------------------------------
'' pageUnLoad()
--------------------------------------
   Created By: SySys:bh
   Compatibility: All Browsers that support Javascript files
   Description: Dummy function that is only defined and designed to be overidden
----------------------------------'''*/ 
function pageUnLoad(){}

/*'''---------------------------------
'' submit(formName,forceIfNotDirty)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Allows other windows or this window to refresh this page. 
   Parameters
     formName: name of the form that you wish to submit
     forceIfNotDirty: forces the page to submit even if the form field values have not changed
   Dependencies: Manage_form.js:isFormDirty
----------------------------------'''*/ 
function submit(formName,forceIfNotDirty){
  if(forceIfNotDirty || isFormDirty(formName)){
    var frm = eval('document.' + formName);
    frm.submit(); 
  }
}


/*'''---------------------------------
'' isFormDirty(formName) 
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns true if given form's elements have changed since loaded
   Parameters
     formName: name of the form that you wish to check for dirtyness
----------------------------------'''*/ 
function isFormDirty(formName){
  //look for Form name in the 'dirtyFormList' Array
  for(i=0; i<dirtyFormList.length; i++){
    if(dirtyFormList[i] == formName){
      return true;
    }
  }
  return false;
}

/*'''---------------------------------
'' getFormValue(formName, fieldName)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns value of a form field
   Parameters
     formName: name of the form that you wish to check for dirtyness
     fieldName: name of the field in the given form that you want the value from
   Return: Value of given form field 
----------------------------------'''*/ 
function getFormValue(formName, fieldName){
  return eval('document.' + formName + '.' + fieldName + '.value;');
}


/*'''---------------------------------
'' copyFormFieldValues(formName, fieldNameFrom, fieldNameTo)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: copys fields
   Parameters
     formName: name of the form that you wish to check for dirtyness
     fieldNameFrom: name of the field to copy value from
     fieldNameTo: name of the field to copy value to
   Return: na
----------------------------------'''*/ 
function copyFormFieldValues(formName, fieldNameFrom, fieldNameTo){
  eval('document.' + formName + '.' + fieldNameTo + '.value = document.' + formName + '.' + fieldNameFrom + '.value;');
}


/*'''---------------------------------
'' formFieldsMatch(formName, fieldName1, fieldName2)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns true if field values match
   Parameters
     formName: name of the form that you wish to check for dirtyness
     fieldName1: name of the field to copy value from
     fieldName2: name of the field to copy value to
   Return: returns true if field values match
----------------------------------'''*/ 
function formFieldsMatch(formName, fieldName1, fieldName2){
  return eval('document.' + formName + '.' + fieldName1 + '.value == document.' + formName + '.' + fieldName2 + '.value;');
}

/*'''---------------------------------
'' isMaxLen(formName, fieldName, maxLen)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns true if length string in field does not exceed the maxLen parameter
   Parameters
     formName: name of the form that you wish to check 
     fieldName: name of the field in the given form that you want the value from
     maxLen: maximum Length allowed in field
   Return: True/false
----------------------------------'''*/ 
function isMaxLen(formName, fieldName, maxLen){
  var val = eval('document.' + formName + '.' + fieldName + '.value;');
  return val.length <= maxLen;
}

/*'''---------------------------------
'' isMinLen(formName, fieldName, minLen)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns true if length string in field is shorter than the minLen parameter
   Parameters
     formName: name of the form that you wish to check 
     fieldName: name of the field in the given form that you want the value from
     minLen: minimum Length allowed in field
   Return: True/false
----------------------------------'''*/ 
function isMinLen(formName, fieldName, minLen){
  var val = eval('document.' + formName + '.' + fieldName + '.value;');
  return val.length >= minLen;
}


/*'''---------------------------------
'' setFormValue(formName, fieldName, value)   
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: sets value of a form field
   Parameters
     formName: name of the form that you wish to check for dirtyness
     fieldName: name of the field in the given form that you want the value from
     value: value to set to field in given form
   Return: None
----------------------------------'''*/ 
function setFormValue(formName, fieldName, value){
  var formField =  eval('document.' + formName + '.' + fieldName);
  formField.value = value;
}

/*'''---------------------------------
'' dirtyFormField(formName, fieldName, dirtyImg)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Marks the given form as dirty
   Parameters
     formName: name of the form that you wish mark dirty
     fieldName: name of the field on the given form that you wish mark dirty
     dirtyImg: optional src of dirty indicator image
   Dependencies: Manage_form.js:isFormDirty
----------------------------------'''*/ 
function dirtyFormField(formName, fieldName, dirtyImg){
  //add the form name to the dirty form list if it does not already exist
  if(!isFormDirty(formName)){
    dirtyFormList.length += 1;
    dirtyFormList[dirtyFormList.length-1] = formName;
  }  
  //mark the hidden isDirty_{fieldName} value to true
//alert('formName: ' + formName + '\nfieldName: ' + fieldName);
  var frmField = eval('document.' + formName + '.isDirty_' + fieldName);
  if(eval('document.' + formName + '.' + fieldName + '.value;')!=null){
    frmField.value = true;
  }  
  //change the dirty image source 
  if(dirtyImg!=null){
    dirtyFieldImg(fieldName, dirtyImg);
  }  
}

/*'''---------------------------------
'' dirtyForm(formName)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Marks the given form as dirty
   Parameters
     formName: name of the form that you wish mark dirty
   Dependencies: Manage_form.js:isFormDirty
----------------------------------'''*/ 
function dirtyForm(formName){
  //add the form name to the dirty form list if it does not already exist
  if(!isFormDirty(formName)){
    dirtyFormList.length += 1;
    dirtyFormList[dirtyFormList.length-1] = formName;
  }  
}

/*'''---------------------------------
'' dirtyFieldImg(fieldName, dirtyImg)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Marks the given form as dirty
   Parameters
     fieldName: name of the form field that you wish mark dirty
   Dependencies: Manage_image_effects.js:setImageSize, setImageSource
----------------------------------'''*/ 
function dirtyFieldImg(fieldName, dirtyImg){
  var img = 'dirtyImg_' + fieldName;
  if(eval('document.' + img)){
    setImageSize(img, 17, 15);
    setImageSource(img, dirtyImg);
  }
}


/*'''---------------------------------
'' markFieldImg(fieldName, markImg)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Marks the given form for review
   Parameters
     fieldName: name of the form field that you wish mark dirty
     markImg: image to change from shim
   Dependencies: Manage_image_effects.js:setImageSize, setImageSource
----------------------------------'''*/ 
function markFieldImg(fieldName, markImg){
  var img = 'validateImg_' + fieldName;
  if(eval('document.' + img)){
    setImageSource(img, markImg);
    setImageSize(img, 10, 12);
  }
}


/*'''---------------------------------
'' hideFieldImg(fieldName, markImg)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Marks the given form for review
   Parameters
     fieldName: name of the form field that you wish mark dirty
     markImg: image to change from shim
   Dependencies: Manage_image_effects.js:setImageSize, setImageSource
----------------------------------'''*/ 
function hideFieldImg(fieldName, markImg){
  var img = 'validateImg_' + fieldName;
  if(eval('document.' + img)){
    setImageSize(img, 1, 1);
    setImageSource(img, markImg);
  }
}



/*'''---------------------------------
'' promptIfDirty(isDirty, message)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: prompts user if the 'isDirty' attribute is true.  
   Parameters
     isDirty: true or false value (usually sent by the 'isFormDirty' function 
     message: message that prompts user if the 'isDirty' attribute is true
   Return:
     Returns true if they cancle (allows forms to submit or confirm cancel).  
     Returns false if user clicks ok  
----------------------------------'''*/ 
function promptIfDirty(isDirty, message){
  if(isDirty){
    return confirm(message);
  }
  return true;
}

/*'''---------------------------------
'' requireScrollEnd(formName, textAreaName, scrollTrack)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns a message if the user has not scrolled through all content in the textarea field
   Parameters:
     formName: name of the form element 
     textAreaName: name of the text area being tested
     message: message that prompts user if the 'isDirty' attribute is true
     scrollTrack: your global variable that is set to true or false indicating if the entire scroll box has been visited
       set your variable to false.  This function will set it to true if it the text area  has been scrolled
   Returns: message if content has not been scrolled.  blank string if textarea has been scrolled
----------------------------------'''*/ 
function requireScrollEnd(formName, textAreaName, scrollTrack){
  var txtObj = eval('document.' + formName + '.' + textAreaName);
  if((txtObj.scrollHeight - txtObj.scrollTop) == txtObj.clientHeight){
    scrollTrack.value = true;
  }
  return;
}

/*'''---------------------------------
'' scrollTrack [object] 
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: object with a value property used to pass to objects by reference
   Parameters:
     None
   Properties:
     value: holds the value of the object
   Returns: n/a
   Notes: used to pass by reference to the 'requireScrollEnd' function
----------------------------------'''*/ 
function scrollTrack(){
  this.value = false;
}


/*'''---------------------------------
'' moveOptionValues(srcFormFieldName, destFormFieldName, MoveAll)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: Moves item from a soucre select list to a destination list and can track additions user definded form fields
   Parameters:
     srcFormFieldName: form and element name of the source Select List (ex: frmMain.sourceList)
     destFormFieldName:  form and element name of the Destination Select List (ex: frmMain.destinationList)
     MoveAll: true false -- fasle will only move selected items 
----------------------------------'''*/ 
  function moveOptionValues (srcFormFieldName, destFormFieldName, MoveAll) {
    var SelectFrom = eval('document.'+srcFormFieldName);
    var SelectTo = eval('document.'+destFormFieldName);
    var SelectedIndex = SelectFrom.options.selectedIndex;
    if ((SelectedIndex == -1 || SelectedIndex == 0)&& MoveAll == false) {
      alert("Please select an item to move.");
    } else {
      for (i=1; i<SelectFrom.options.length; i++) {
        if (MoveAll == false){
          if(SelectFrom.options[i].selected) {
            var name = SelectFrom.options[i].text;
            var ID = SelectFrom.options[i].value;
            SelectFrom.options[i] = null;
            SelectTo.options[SelectTo.options.length]=new Option (name,ID);
            i=i-1;
          }
        }else {
          var name = SelectFrom.options[i].text;
          var ID = SelectFrom.options[i].value;
          SelectFrom.options[i] = null;
          SelectTo.options[SelectTo.options.length]=new Option (name,ID);
          i=i-1;     
        }
      }
    }
  }//End moveOptionValues
  
/*'''---------------------------------
'' getSelectIDList(srcFormFieldName, destFormFieldName)
--------------------------------------
   Created By: SySys:bh/cg
   Compatibility: IE6
   Description: Gathers a list of all items in a select list and stores the vlaues in a comma seperated list
   Parameters:
     srcFormFieldName: form and element name of the source Select List (ex: frmMain.sourceList)
     destFormFieldName:  form and element name of the Destination text or hidden field(ex: frmMain.IDList)
----------------------------------'''*/   
function getSelectIDList(srcFormFieldName, destFormFieldName){
  var container = eval('document.'+ destFormFieldName);
  var SelectFrom = eval('document.'+ srcFormFieldName);
  for (i=1; i<SelectFrom.options.length; i++) {
    container.value=container.value+ SelectFrom.options[i].value + ',';
  }   
  //remove ending comma
  container.value = container.value.substring(0,container.value.length-1); 
  if(container.value == ''){
    container.value = 0;
  }
}
  
  
/*'''---------------------------------
'' getCheckIDList(FormFieldNamePrefix, FormFieldName)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Gathers a comma separated list of the values of checkboxes that are prefixed with 'FormFieldNamePrefix' and are checked
   Parameters:
     FormFieldNamePrefix: begining of name of checkbox names to evaluate
     FormFieldName:  form object that the checkboxes live in
----------------------------------'''*/   
function getCheckIDList(FormFieldNamePrefix, FormFieldName){
  var list = '';
  var frm = eval('document.'+ FormFieldName);
  for (i=0; i< frm.elements.length; i++) {
    var curName = frm.elements[i].name;
    if(curName.substring(0,FormFieldNamePrefix.length)==FormFieldNamePrefix && frm.elements[i].checked){
      list += frm.elements[i].value + ',';
    }  
  }   
  //remove ending comma
  return list.substring(0,list.length-1); 
}  


/*'''---------------------------------
'' sumCheckedValues(FormFieldNamePrefix, FormFieldName)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: sums the values of checkboxes that are prefixed with 'FormFieldNamePrefix' and are checked
   Parameters:
     FormFieldNamePrefix: begining of name of checkbox names to evaluate
     FormFieldName:  form object that the checkboxes live in
----------------------------------'''*/   
function sumCheckedValues(FormFieldNamePrefix, FormFieldName){
  var total = 0;
  var list = '';
  var frm = eval('document.'+ FormFieldName);
  for (i=0; i< frm.elements.length; i++) {
    var curName = frm.elements[i].name;
    if(curName.substring(0,FormFieldNamePrefix.length)==FormFieldNamePrefix && frm.elements[i].checked){
      total += parseInt(frm.elements[i].value);
    }  
  }  
  return total; 
} 

/*'''---------------------------------
'' checkAllNameList(formName, fieldNameList)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: Checks all Check Boxes in prefix list
   Parameters:
     formName: name of form to search for check boxes
     fieldNameList:  List of names of checkboxes to check
----------------------------------'''*/    
function checkAllNameList(formName, fieldNameList){
  var frm = eval('document.'+ formName);
  var list = fieldNameList.split(",");
  //loop throug form elements
  for (i=0; i< frm.elements.length; i++) {
    //loop through list
    for (y=0; y < list.length; y++){
      if(frm.elements[i].name.indexOf(list[y]) != -1){
        frm.elements[i].checked = true;
      }
    }  
  }
}

/*'''---------------------------------
'' isRadioGroupChecked(formName, fieldName)
--------------------------------------
   Created By: SySys:wt
   Compatibility: IE6
   Description: returns true if one item in a radio group is checked
   Parameters:
     formName: name of form to search for check radio button
     fieldName: name of form field (radio group) to check
----------------------------------'''*/    
function isRadioGroupChecked(formName, fieldName){
  var frm = eval('document.'+ formName + '.' + fieldName);
  //loop through array of radio items
  for (i=0; i < frm.length; i++){
    //if one of the radio buttons is checked return true
    if(frm[i].checked){
      return true;
    }
  }
  return false;
}

/*'''---------------------------------
'' uncheckAllNameList(formName, fieldNameList)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: unChecks all Check Boxes in prefix list
   Parameters:
     formName: name of form to search for check boxes
     fieldNameList:  List of names of checkboxes to check
----------------------------------'''*/    
function uncheckAllNameList(formName, fieldNameList){
  var frm = eval('document.'+ formName);
  var list = fieldNameList.split(",");
  //loop throug form elements
  for (i=0; i< frm.elements.length; i++) {
    //loop through list
    for (y=0; y < list.length; y++){
      if(frm.elements[i].name.indexOf(list[y]) != -1){
        frm.elements[i].checked = false;
      }
    }  
  }
}

/*'''---------------------------------
'' checkAll(formName, fieldNamePrefix)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: Checks all Check Boxes in prefix list
   Parameters:
     formName: name of form to search for check boxes
     fieldNamePrefix:  prefix for all names of checkboxes to check
----------------------------------'''*/    
function checkAll(formName, fieldNamePrefix){
  var frm = eval('document.'+ formName);
  //loop throug form elements
  for (i=0; i< frm.elements.length; i++) {
    if(frm.elements[i].name.indexOf(fieldNamePrefix) != -1){
      frm.elements[i].checked = true;
    }
  }
}

/*'''---------------------------------
'' uncheckAll(formName, fieldNamePrefix)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: unChecks all Check Boxes in prefix list
   Parameters:
     formName: name of form to search for check boxes
     fieldNamePrefix:  prefix for all names of checkboxes to check
----------------------------------'''*/    
function uncheckAll(formName, fieldNamePrefix){
  var frm = eval('document.'+ formName);
  //loop throug form elements
  for (i=0; i< frm.elements.length; i++) {
    if(frm.elements[i].name.indexOf(fieldNamePrefix) != -1){
      frm.elements[i].checked = false;
    }
  }
}

/*'''---------------------------------
'' fieldType(formField)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: returns type of the given element as a single lower case character (see below)
   Parameters:
     formField: form field to check
   Returns: lowercase alpha value indicating the type of form element that the item is
     t=input type=text
     s=select
     r=radio
     c=checkbox
----------------------------------'''*/   
function fieldType(formField){



//alert(formField.Name);
  if(formField[0]!=null&&formField[0].type=='radio'){
    return 'r';
  }else if(formField[0]!=null&&formField[0].type=='checkbox'){
    return 'c';
  }else if(formField.selectedIndex!=null){
    return 's';
  }
  return 't';
}
 


/*'''---------------------------------
'' noValue(formField){
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: chooses the proper methods to determin if an element has a value chosen
   Parameters: 
     formField: form field object to be tested for a value
   Returns: true/false
   Dependencies: Manage_form.js:fieldType, selectedValue
   Notes:
     HTML input elements each need to check different properties.  
     The Default Non-selected values for Select elements is -1
     Radio elements are not checked for values (returns false)
----------------------------------'''*/ 
function noValue(formField){
  //determin element type
  if(fieldType(formField)=='r'){
    return false;
  }
  //Select
  if(fieldType(formField)=='s'){
    //select elements index value (-1 is the default for not selected)
    if(selectedValue(formField)==-1){
      return true;
    }
    return false;
  }else{
    return isEmpty(formField.value);
  }
}


/*'''---------------------------------
'' selectedValue(formField)
--------------------------------------
   Created By: SySys:cg
   Compatibility: IE6
   Description: returns the value of the selected item of the given select element
   Parameters:
     formField: form field to check
   Returns: value of selected index
----------------------------------'''*/   
function selectedValue(formField){
  if(formField.selectedIndex!=-1){
    return formField.options[formField.selectedIndex].value;
  }else{
    return null;
  }  
}
  
function selectIndexAll(formName, fieldName, discludeIndecies){
  var field = eval('document.' + formName + '.' + fieldName);
  for(var i=0; i<field.options.length;i++){
    field.options[i].selected=true;
  }
  //disclude indecies
  if(discludeIndecies!=null){
    var disclude = new Array();
    disclude = split(discludeIndecies);
    for(var i=0; i<disclude.length;i++){
      field.options[disclude[i]].selected=false;
    }
  }
}  
  
/*'''---------------------------------
'' selectedOption(formField)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: returns the option text value of the selected item of the given select element
   Parameters:
     formField: form field to check
   Returns: value of selected index
----------------------------------'''*/   
  function selectedOption(formField){
    return formField.options[formField.selectedIndex].text;
  }



/*'''---------------------------------
'' displayOverlapSelects(display,ElementFloat)
--------------------------------------
   Created By: D. Scott Morris (9/28/01) / Modified BH (3/15/2002)
   Compatibility: ?
   Description: Loops through JavaScript menu arrays, identifies which form elements need
				to be hidden or shown, and hides/shows the form elements.  This technique 
				DOES NOT WORK in Netscape 4.7x browsers due to JavaScript DOM constraints,
				and IS NOT NEEDED in Netscape 6.
   Parameters:
     display:
     formObj:
     ElementFloat:
   Returns: true/false if overlaps
----------------------------------'''*/ 
function displayOverlapSelects(display,ElementFloat){
  //	This script works only for IE4+ browsers....
  if(document.all) {
    //oMenuPos = positionOfElement(ElementFloat);
    //	Check for the existence of forms
    if(document.forms.length > 0){
	  	//	Start with first form, and then move on to next
      //for (var FormObject = 0; FormObject <= (document.forms.length - 1); FormObject++) {
      for (var FormObject = 0; FormObject <= (document.forms.length - 1); FormObject++) {
      //	Loop through the collection of form elements
        for (var i = 0; i < document.forms[FormObject].elements.length; i++) {
          //	Set oElement = to the current form element object being looped through
          oElement = document.forms[FormObject].elements[i];
          //	Exclude all 'hidden' input types
          if (oElement.type.toLowerCase() != "hidden") {
            //	Exclude all 'hidden' input types
            var elementType = oElement.type.toLowerCase();
            //	List inputs we don't want hidden.
            switch (elementType) {
            //	Hidden, text and password fields need not be hidden
              case "hidden": break;
              case "text": break;
              case "password": break;

              //	For all other input types, run the following code....
              default:
              //	Set the position for the dropdown select box, using positionOfEement()
              //oDropdownBoxPos = positionOfElement(oElement);

              //	Test to see if ElementFloat overlaps the current oElement using elementsOverlap()
              if (elementsOverlap(oElement,ElementFloat)) {
                //	(oElement.hidByMenuID != null) ? alert("hidByMenuID = " + oElement.hidByMenuID) : alert("hidByMenuID = null");
                //	If they do overlap, then hide or show the form element.
                if(display){
                  if (oElement.hidByMenuID == ElementFloat.id) {
                    //	'display' is set false - show the element
                    oElement.style.visibility = "visible";
                    //	Remove the tag to the object that hid the element.
                    oElement.hidByMenuID = null;
                  }
                } else {
                  if (oElement.hidByMenuID == null) {
                    //	'display' is set true - hide the element
                    oElement.style.visibility = "hidden"
                    //	Tag the object that hid the element
                    oElement.hidByMenuID = ElementFloat.id;
                  }
                }
              }
              break;
            }
          }
        }
      }
    }
  }
}

    
