/*
----------- FundSys.net(TM) Copyright SySys(R) Corp 2002 ------------
====================================================================
  Created By: BH
  Last Edited By: WT
  Inception Date: 1/1/2002
  Last Edited Date: 5/14/2003
  Description:  None
  File Dependencies: 
    manage_form.js
    manage_array.js
    detect_browser.js
===================================================================''*/

/*'''---------------------------------
'' getElementObject(elementName)
--------------------------------------
   Created By: WT (7/15/2002)
   Compatibility: IE4+/NS4+
   Description: returns an object based on browser type
   Parameters:
     elementName: page element by reference
   Returns: object
----------------------------------'''*/ 
function getElementObject(elementName){
  if(BD_is_getElementById&&!BD_is_nav4){
    return eval('document.getElementById("' + elementName + '")');
  }
  else{
    if(BD_is_nav4) return eval('document.layers[\'' + elementName + '\']')
    else return eval('document.all[\'' + elementName + '\']');
  }
}

/*'''---------------------------------
'' moveDivToDiv(toDivName, moveDivName, offsetX, offsetY)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: moves one element's top left positions to another
   Parameters
     toDivName: name of the layer that you wish to use for positioning for the "moveDivName" tag
     moveDivName: name of the layer that you wish to move to the "toDivName" tag
     offsetX (optional): pixle offset in the X coordinate
     offsetY (optional): pixle offset in the Y coordinate
   Notes:  In order for the div tag to move they must have a style="postion:absolute" tag
----------------------------------'''*/ 
function moveDivToDiv(toDivName, moveDivName, offsetX, offsetY){
  //optional parameters - define if not passed
  if(offsetX == null){offsetX = 0;}
  if(offsetY == null){offsetY = 0;}
  
  var toDiv = getElementObject(toDivName);
  var moveDiv = getElementObject(moveDivName);
//alert('toDiv id: ' + toDiv.id + '\ntoDiv top: ' + toDiv.offsetTop + '\ntoDiv left: ' + toDiv.offsetLeft + '\nscrollTop: ' + toDiv.scrollTop + '\noffsetY: ' + toDiv.offsetY);
//alert('top pos: ' + parseInt(toDiv.scrollTop) + parseInt(toDiv.offsetTop) + parseInt(offsetY));

  var toDivScrollTop = parseInt(toDiv.scrollTop);
  if(isNaN(toDivScrollTop)) toDivScrollTop = 0;
  var toDivoffsetY = parseInt(toDiv.offsetY);
  if(isNaN(toDivoffsetY)) toDivoffsetY = 0;

  var toDivScrollLeft = parseInt(toDiv.scrollLeft);
  if(isNaN(toDivScrollLeft)) toDivScrollLeft = 0;
  var toDivoffsetX = parseInt(toDiv.offsetX);
  if(isNaN(toDivoffsetX)) toDivoffsetX = 0;

//alert('top: ' + toDivScrollTop + parseInt(toDiv.offsetTop) + toDivoffsetY);
//alert('left: ' + toDivScrollLeft + parseInt(toDiv.offsetLeft) + toDivoffsetX);
  moveDiv.style.top = toDivScrollTop + parseInt(toDiv.offsetTop) + toDivoffsetY;
  moveDiv.style.left = toDivScrollLeft + parseInt(toDiv.offsetLeft) + toDivoffsetX;
}

/*'''---------------------------------
'' changeDIVText(ID, text)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: changes the inner html text of a div tag
   Parameters
     ID: name of DHTML ID
     text: new text to change to
----------------------------------'''*/ 
function changeDIVText(ID, text){
  var tmpObj = getElementObject(ID);
  tmpObj.innerHTML = text;
}

/*'''---------------------------------
'' getDIVText(ID)
--------------------------------------
   Created By: SySys:wt
   Compatibility: IE6
   Description: returns the inner html of a div tag
   Parameters
     ID: name of DHTML ID
----------------------------------'''*/ 
function getDIVText(ID){
  var txt = eval('document.all.' + ID + '.innerHTML;');
  return txt;
}


/*'''--------------------------------- 
'' anchorRight(element, offsetX, offsetY)
-------------------------------------- 
   Created By: SySys:bh
   Compatibility: IE6
   Description: Moves an element to align it's right side with the div tag instead of the left side
   Parameters 
     element: element to change (pass this if the function is called from the element)
     offsetX (optional): pixle offset in the X coordinate
     offsetY (optional): pixle offset in the Y coordinate
   Notes:  In order for the div tag to move they must have a style="postion:absolute" tag
----------------------------------'''*/ 
function anchorRight(elementName, offsetX, offsetY){
  var el = eval('document.all.' + elementName);

  //optional parameters - define if not passed
  if(offsetX == null){offsetX = 0;}
  if(offsetY == null){offsetY = 0;}
  
  //make sure element is visable for moving (store state to return after adjustment)
  var vis = el.style.display; //store state of visablity
  el.style.display = '';  //make visable for adjustment
  el.style.left = parseInt(el.offsetLeft) - parseInt(el.offsetWidth) + parseInt(offsetX); 
  el.style.top = parseInt(el.offsetTop) + parseInt(offsetY);
  el.style.display = vis;  //return to previous state
}

/*'''---------------------------------
'' toggleLayerDisplay(layerName)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: flips the display from it's current state to the opposite state (none to blank and vice versa)
   Parameters
     layerName: the name of the ID attribute of the item that you wish to toggle
----------------------------------'''*/ 
function toggleLayerDisplay(layerName){
  var tmpObj = getElementObject(layerName);
  if(tmpObj.style.display == 'none'){
    tmpObj.style.display='';  
  }else{  
    tmpObj.style.display='none';     
  }
}

/*'''---------------------------------
'' collapseAll(prefix) 
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: collapses all span or div tags that have an ID attribute that begins with the 'prefix' parameter value
   Parameters
     prefix: a filter value that defines the set of span or div tags that begin with this value
----------------------------------'''*/ 
function collapseAll(prefix){
  for(var i=0; i < document.all.length; i++){
    var curID = document.all.item(i).id;
    var name = document.all.item(i).style.display;
    if(name != null && curID != null && curID != ''){
      if(curID.indexOf(prefix) == 0){
        document.all.item(i).style.display = 'none';
      }  
    }
  }
}


/*'''---------------------------------
'' expandDIV(ID)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: expands a span or div tag that has an ID attribute that matches the ID parameter
   Parameters
     ID: ID of div tag
----------------------------------'''*/ 
function expandDIV(ID){
  eval('document.all[\'' + ID + '\'].style.display = \'\';');
}


/*'''---------------------------------
'' collapseDIV(ID)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: closes a span or div tag that has an ID attribute that matches the ID parameter
   Parameters
     ID: ID of div tag
----------------------------------'''*/ 
function collapseDIV(ID){
  var tmpObj = getElementObject(ID);
  tmpObj.style.display = 'none';
}


/*'''---------------------------------
'' showDIV(ID)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: closes a span or div tag that has an ID attribute that matches the ID parameter
   Parameters
     ID: ID of div tag
----------------------------------'''*/ 
function showDIV(ID){
  var tmpObj = getElementObject(ID);
  if(BD_is_nav4){
     tmpObj.visibility = 'show';
    return;
  }
  if(BD_is_ie4){
    tmpObj.style.visibility = 'visible';
    return;
  }
  if(BD_is_getElementById){
    tmpObj.style.visibility = 'visible';
    return;
  }
}

/*'''---------------------------------
'' hideDIV(ID)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: closes a span or div tag that has an ID attribute that matches the ID parameter
   Parameters
     ID: ID of div tag
----------------------------------'''*/ 
function hideDIV(ID){
  var tmpObj = getElementObject(ID);
  if(BD_is_nav4){
    tmpObj.visibility = 'hide';
    return;
  }
  if(BD_is_ie4){
    tmpObj.style.visibility = 'hidden';
    return;
  }
  if(BD_is_getElementById){
    tmpObj.style.visibility = 'hidden';
    return;
  }
}




/*'''---------------------------------
'' expandAll(prefix)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: expands all span or div tags that have an ID attribute that begins with the 'prefix' parameter value
   Parameters
     prefix: a filter value that defines the set of span or div tags that begin with this value
----------------------------------'''*/ 
function expandAll(prefix){
  for(var i=0; i < document.all.length; i++){
    var name = document.all.item(i).style.display;
    if(name != null && name != ''){
      var curID = document.all.item(i).id
      if(curID.indexOf(prefix) == 0){
        document.all.item(i).style.display = '';
      }  
    }
  }
}

/*'''--------------------------------- 
'' collapseList(list) 
-------------------------------------- 
   Created By: SySys:bh 
   Compatibility: IE6
   Description: collapses all span or div tags that have an ID attribute that is found in the 'list' parameter 
   Parameters 
     list: a filter value that defines a comma separated list of span or div tag IDs to be collapsed 
----------------------------------'''*/ 
function collapseList(list){
  if(list!=null){
    for(var i=0; i < document.all.length; i++){
      var curID = document.all.item(i).id;
      var name = document.all.item(i).style.display;
      if(name != null && curID != null && curID != ''){
        if(list.indexOf(curID) != -1){
          document.all.item(i).style.display = 'none';
        }  
      }
    }
  }
}

/*'''--------------------------------- 
'' expandList(list) 
-------------------------------------- 
   Created By: SySys:bh 
   Compatibility: IE6
   Description: expands all span or div tags that have an ID attribute that is found in the 'list' parameter 
   Parameters 
     list: a comma separated list of span or div tag IDs to be expanded
----------------------------------'''*/ 
function expandList(list){ 
  if(list!=null){
    var lst = split(list,',');
    for(var i=0; i < lst.length; i++){
      eval('document.all.' + lst[i] + '.style.display = \'\';');
    }
  }
}

/*'''--------------------------------- 
'' getIDList(prefix,displayState)
-------------------------------------- 
   Created By: SySys:bh 
   Compatibility: IE6
   Description: returns a comma separated list of all span or div tag IDs begining with 'prefix' that do not have Display set to the 'displayState' parameter value
   Parameters 
     prefix: a filter value that defines the set of span or div tags that begin with this value
     displayState: '' (blank) or 'none'
----------------------------------'''*/ 
function getIDList(prefix,displayState){
  var list = '';   
  for(var i=0; i < document.all.length; i++){
    var curID = document.all.item(i).id;
    var name = document.all.item(i).style.display;
      
    if(name != null && curID != null && curID != ''){
      if(curID.indexOf(prefix) == 0){
        //list += curID + '=' + val + '\n';
        if(document.all.item(i).style.display == displayState){
          list += document.all.item(i).id + ',';
        }  
      }  
    }
  }
  return list.substring(0,list.length - 1);
}


/*'''--------------------------------- 
'' changeClass(element,className)
-------------------------------------- 
   Created By: SySys:wt
   Compatibility: IE6
   Description: changes the class of an element from and event handler
   Parameters 
     element: element to change (pass this if the function is called from the element)
     className: name of the new class
----------------------------------'''*/ 
function changeClass(element,className){
  element.className = className;
}


/*'''---------------------------------
'' positionOfElement(element)
--------------------------------------
   Created By: D. Scott Morris (9/28/01) / Modified BH (3/15/2002)
   Compatibility: ?
   Description: Finds the object's offsetTop and offsetLeft values relative to the BODY tag.
   Parameters:
     obj: object to find position of
   Returns: position object
----------------------------------'''*/   
function positionOfElement(element) {
  //Set position and dimension variables
  var positionLeft	= element.offsetLeft;
  var positionTop		= element.offsetTop;
  var elementWidth	= element.offsetWidth;
  var elementHeight	= element.offsetHeight;
  var elementParent	= element.offsetParent;

  while (elementParent.tagName.toUpperCase() != "BODY") {
    positionLeft	+= elementParent.offsetLeft;
    positionTop		+= elementParent.offsetTop;
    elementParent	= elementParent.offsetParent;
  }

  positionRight	= elementWidth + positionLeft;
  positionBottom = elementHeight + positionTop;

  var po = new positionObject(positionLeft,positionRight,positionTop,positionBottom,elementHeight,elementWidth);
  return po;
}

/*'''---------------------------------
'' positionObject(left,right,top,bottom,height,width)
--------------------------------------
   Created By: D. Scott Morris (9/28/01) / Modified BH (3/15/2002)
   Compatibility: ?
   Description: Sets properties of a new JavaScript object containing the position and dimension information of an element passed into positionOfElement().
   Parameters:
     left:
     right:
     top:
     bottom:
   Returns: position object
----------------------------------'''*/ 
function positionObject(left,right,top,bottom,height,width) {
  //alert('left=' + left + '\n' + 'right=' + right + '\n' + 'top=' + top + '\n' + '\n' + 'bottom=' + bottom + '\n' + 'height=' + height + '\n' + 'width=' + width + '\n')
  this.left	= left;
  this.right	= right;
  this.top	= top;
  this.bottom	= bottom;
  this.width	= width;
  this.height	= height;
}


/*'''---------------------------------
'' elementsOverlap(Element1, Element2)
--------------------------------------
   Created By: D. Scott Morris (9/28/01) / Modified BH (3/15/2002)
   Compatibility: ?
   Description: Checks to see if two objects overlap.
   Parameters:
     Element1: DIV or Form element
     Element2: DIV or Form element
   Returns: true/false if overlaps
----------------------------------'''*/ 
function elementsOverlap(Element1, Element2){
  var posObj1 = positionOfElement(Element1);
  var posObj2 = positionOfElement(Element2);
  
  //Initialize variables
  var overlapsHorizontally = false;
  var overlapsVertically = false;

  //Test both objects for overlap of left/right axis
  if ((posObj1.left >= posObj2.left && posObj1.left <= posObj2.right) || (posObj1.right >= posObj2.left && posObj1.right <= posObj2.right)) {
    overlapsHorizontally = true;
  }

  //	Test both objects for overlap of top/bottom axis
  if ((posObj1.top >= posObj2.top && posObj1.top <= posObj2.bottom) || (posObj1.bottom >= posObj2.top && posObj1.bottom <= posObj2.bottom)) {
    overlapsVertically = true;
  }
  return overlapsHorizontally && overlapsVertically;
}

/*'''---------------------------------
'' getAbsX(elmt) / getAbsY(elmt)
--------------------------------------
   Created By: WT (7/15/2002)
   Compatibility: IE4+/NS4+
   Description: returns true page offset (x,y) of any element
   Parameters:
     elmt: page element by reference
   Returns: top or left position of element in page
----------------------------------'''*/ 
function getAbsX(elmt) { return (elmt.x) ? elmt.x : getAbsPos(elmt,"Left"); }
function getAbsY(elmt) { return (elmt.y) ? elmt.y : getAbsPos(elmt,"Top"); }

//PRIVATE
function getAbsPos(elmt,which) {
 iPos = 0;
 while (elmt != null) {
  iPos += elmt["offset" + which];
  elmt = elmt.offsetParent;
 }
 return iPos;
}

/*'''---------------------------------
'' getElmHeight(elmt)
--------------------------------------
   Created By: WT (7/31/2002)
   Compatibility: IE4+/NS4+
   Description: returns element height
   Parameters:
     elmt: page element by reference
   Returns: height of element
----------------------------------'''*/ 
function getElmHeight(elmt){
  if(BD_is_getElementById&&!BD_is_nav4){
    return eval(elmt).offsetHeight;
  }else{
    if (BD_is_nav4) return eval(elmt).clip.height
    else return eval(elmt).clientHeight;
  }
}

/*'''---------------------------------
'' shiftDIV(element, xdelta, ydelta)
--------------------------------------
   Created By: WT (7/31/2002)
   Compatibility: IE4+/NS4+
   Description: changes element position
   Parameters:
     elmt: page element by name
     xdelta: amount of pixels to move in x direction (pos/neg integer): 0 for no move
     ydelta: amount of pixels to move in y direction (pos/neg integer): 0 for no move
   Returns: void
----------------------------------'''*/ 
function shiftDIV(element, xdelta, ydelta){
  var elmObj = getElementObject(element);
  var elm_y = parseInt(getAbsY(elmObj)+ydelta);
  var elm_x = parseInt(getAbsX(elmObj)+xdelta);
  //shift x position
  if(BD_is_nav6up){
    eval('elmObj.style.left = "' + (elm_x+20) + 'px"');
  }
  else {
    (BD_is_nav4) ? elmObj.left = elm_x : elmObj.style.pixelLeft = elm_x;
  }
  //shift y position
  if(BD_is_nav6up){
    eval('elmObj.style.top = "' + elm_y + 'px"');
  }
  else {
    (BD_is_nav4) ? elmObj.top = elm_y : elmObj.style.pixelTop = elm_y;
  }
}