/*
----------- 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
  File Dependencies: 
    manage_form.js
    manage_array.js
    detect_browser.js
===================================================================''*/

/*'''---------------------------------
'' getElementObject(elementName)
--------------------------------------
   Created By: WT (7/15/2002)
   Compatibility: IE4+/NS4+
   Description: returns element instance as object
   Parameters:
     elmt: page element by name
   Returns: element as 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 + '\'].style');
  }
}

function getElement(elemID) {
    var elem = (document.getElementById) ? document.getElementById(elemID) : ((document.all) ? document.all[elemID] : null);
    if (elem) {
      return elem;
    }else{
      alert("no element");
    }
}


/*'''---------------------------------
'' 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, positionBelowToDiv){
  //optional parameters - define if not passed
  if(!isInteger(offsetX)){offsetX = 0;}
  if(!isInteger(offsetY)){offsetY = 0;}
  if(!positionBelowToDiv){positionBelowToDiv = false;}
  var heightAdjustment = getElmHeight(getElementObject(toDivName))
  
  if(!positionBelowToDiv){heightAdjustment = 0;}

  var toDiv = getElementObject(toDivName);
  var moveDiv = getElementObject(moveDivName);

  eval('moveDiv.style.top = "' + (parseInt(getAbsY(toDiv)) + parseInt(offsetY) + parseInt(heightAdjustment)) + 'px"');
  eval('moveDiv.style.left = "' + (parseInt(getAbsX(toDiv)) + parseInt(offsetX)) + 'px"');

  //alert('toDivName=' + toDivName + '\nmoveDivName=' + moveDivName + '\ntoDivY=' + getAbsY(toDiv) + '\ntoDivX=' + getAbsX(toDiv)) + '\noffsetY=' + offsetY + '\noffsetX=' + offsetX + '\nheightAdjustment=' + heightAdjustment;

}



/*'''---------------------------------
'' 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(elementName, text){
  var elmt = getElementObject(elementName);
  elmt.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 obj = getElementObject(layerName);
  if(obj.style.display=='none'){
    obj.style.display='';  
  }else{
    obj.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){
  if(BD_is_nav4){
    eval('document.layers[\'' + ID + '\'].display = \'inline\';');
    return;
  }
  if(BD_is_ie4){
    eval('document.all[\'' + ID + '\'].style.display = \'inline\';');
    return;
  }
  if(BD_is_getElementById){
    eval('document.getElementById("' + ID + '").style.display = \'inline\';');
    return;
  }
}


/*'''---------------------------------
'' 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){
  if(BD_is_nav4){
    eval('document.layers[\'' + ID + '\'].display = \'none\';');
    return;
  }
  if(BD_is_ie4){
    eval('document.all[\'' + ID + '\'].style.display = \'none\';');
    return;
  }
  if(BD_is_getElementById){
    eval('document.getElementById("' + ID + '").style.display = \'none\';');
    return;
  }
}


/*'''---------------------------------
'' 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){
  if(BD_is_nav4){
    eval('document.layers[\'' + ID + '\'].visibility = \'show\';');
    return;
  }
  if(BD_is_ie4){
    eval('document.all[\'' + ID + '\'].style.visibility = \'visible\';');
    return;
  }
  if(BD_is_getElementById){
    eval('document.getElementById("' + ID + '").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){
  if(BD_is_nav4){
    eval('document.layers[\'' + ID + '\'].visibility = \'hide\';');
    return;
  }
  if(BD_is_ie4){
    eval('document.all[\'' + ID + '\'].style.visibility = \'hidden\';');
    return;
  }
  if(BD_is_getElementById){
    eval('document.getElementById("' + ID + '").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 + '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;
  }
}


/*'''---------------------------------
'' windowHeight()
--------------------------------------
   Created By: WT (10/26/2005)
   Compatibility: IE4+/NS4+
   Description: returns the inner height of a browser window
   Parameters:
   Returns: inner height of browser window
----------------------------------'''*/ 

function windowHeight(){
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myHeight = window.innerHeight; //Non-IE
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myHeight = document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myHeight = document.body.clientHeight;  //IE 4 compatible
  }
  return myHeight;
  //window.alert( 'Height = ' + myHeight );
}

/*'''---------------------------------
'' windowWidth()
--------------------------------------
   Created By: WT (10/26/2005)
   Compatibility: IE4+/NS4+
   Description: returns the inner width of a browser window
   Parameters:
   Returns: inner widthof browser window
----------------------------------'''*/ 

function windowWidth(){
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    myWidth = window.innerWidth; //Non-IE
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    myWidth = document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    myWidth = document.body.clientWidth; //IE 4 compatible
  }
  return myWidth;
  //window.alert( 'Width = ' + myWidth );
}

/*'''---------------------------------
'' isInteger(val)
--------------------------------------
   Created By: WT
   Description: Returns true if value contains all digits
   Parameters:
     value: val to check
   Returns: true or false
----------------------------------'''*/ 
function isInteger(val){
  if (isBlank(val)){return false;}
  for(var i=0;i<val.length;i++){
    if(!isDigit(val.charAt(i))){return false;}
  }
  return true;
}

/*'''---------------------------------
'' isNumeric(val)
--------------------------------------
   Created By: WT
   Description: Returns true if value contains a positive float value
   Parameters:
     val: value to check
   Returns: true or false
----------------------------------'''*/ 
function isNumeric(val){
  return(parseFloat(val,10)==(val*1));
}


//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}


//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
  }
	return true;
}
