/*<!----------------------------------------------------------------------------------Created by: Duc Vo---------
 *File Name      : dynLibs.js
 *Purpose        : JS Dynamic Library functions.  They are shared accross the site.
 *
 *Company Name   : DVo!nvesCo LLC - Copyright 2003 - All Rights Reserved
 *Compnay Website: www.dvoinvesco.com 
 *Contact Info   : duc@dvoinvesco.com, support@dvoinvesco.com
 *
--------------------------------------------------------------------------------------Created on: 8/03--------->*/
<!----------------------------------------//Hide from Old Broswers
//=======================================================================================
//  Began Library Function Implementations
//=======================================================================================
//Include in HTML file: <SCRIPT LANGUAGE="JAVASCRIPT" SRC="share/js/dynLibs.js"></SCRIPT>

//Global Varaibles
//Detecting Browser Support
  var  NS4   = (document.layers)? true:false;
  var  IE4   = (document.all)? true:false;
  var is4   = ( NS4 ||  IE4);
  var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
  if(isMac &&  IE4)
  {
    // i.e.: mac currently acts like a 3.0 browser so we'll just force it to now to prevent errors
    IE4 = false;
    is4 = false;
  }

  var doc         = document; //handler to the global document object.
  var elm         = NS4 ? document.layers : document.all  //Handling cross browser compatibility.
  var baseDir     = "";
  var selMenu     = '';             //It holds current selected baseMenu name.   

//----------------------------------   resizeWindow   -----------------------------------
//Call when the user resiz their browser window...
//Used mainly for Netscape.
//
function resizeWindow(){
   if ( NS4){
      location.reload();
   }
}

//----------------------------------   dynLayerMoveBy   ---------------------------------
//This function move the current Obj from its current x,y position to the new (x,y)
//positions that are passed in.
//
//Note: css is obtain this way:    
//this.css = (IE4 ? document.getElementById(divID).style : document.layers[divID]); //Pointer to a CSS Object.

function dynLayerMoveBy(x,y) {
    this.x += x
    this.css.left = this.x
    this.y += y
    this.css.top  = this.y
}

//----------------------------------   dynLayerMoveMoveTo   -----------------------------
//This function move the current Obj to the specified location passed in to (x,y).
//
function dynLayerMoveTo(x,y) {
    //alert(x + " == " + y)
    this.x = x
    this.css.left = this.x
    this.y = y
    this.css.top  = this.y
}

//--------------------------------  Image Flipping behavior   ------------------------
//The initImgFlipObj() is define elsewhere in the project where it make most relavent
//In this case, it is define in siteIncludes.js
//The functions below are helper functions that help does the work when its event is called.

//Takes an image name and modify its src to show a new image.
//This function is call with an onmouseover event.
//Event: onMouseOver(imgName)
//
function imgFlip(imgName) {
   if (document.images && imgName != 'null'){
	    document[imgName].src = eval(imgName + '_on.src');
   }
}
	
//Takes an image name and modify its src to show a new image.
//This function is call with an onmouseout event.
//Event: onMouseOut(imgName)
//
function imgUnflip(imgName) {
   if (document.images && imgName != 'null'){
	   document[imgName].src = eval(imgName + '_off.src');
   }
}

//On a mouse click on any button, a new image showed up with the word "GO !!!".
//Event: onMouseClick(imgName)
//
function goImg(imgName)
{
	if(document.images && imgName != 'null')
	{
		document[imgName].src = eval(imgName + "go.src");
	}
}




//-------------------------------   Show DropDown Menu   -----------------------------
//Shows the current Object by setting its DIV/LAYER to be visible.
//

function show(cur){
   if(cur == null) return;

   if(IE4){
      if(cur != null) cur.style.visibility       = "visible";
   }
   else{
      if(cur != null) cur.visibility             = "show";
   }
   
}

//-------------------------------   Hide DropDown Menu   -----------------------------
//Hides the current Object by setting its DIV/LAYER to be hidden.
//

function hide(cur){
   if(cur == null) return;
   
   if(IE4){
      if(cur != null) cur.style.visibility       = "hidden";
   }
   else{
      if(cur != null) cur.visibility             = "hide";
   }
      
}

//-------------------------------   IE ONLY = Display  -----------------------------
//Hides the current Object by setting its DIV to be hidden/show and take away
//the spaces that that DIV took up when hidden...Good for FAQ format in IE.
//
//Possible values for 'dis' are "block" or "none"
//
function displayObj(cur, dis){
   if(IE4 & cur != null) cur.style.display = dis;
}

//-------------------------------   get an Image String   ----------------------------
//Construct an image string and return it to the caller.
//
//All these variables must be String: either 'value' or '' or can be obmited if they're
//at the end.
//
//return: type=string
//
//Valid Syntax: getImgStr('misc/space.gif','1','1','','','0') 
//The rest are obmitted--they are 'undefined'.
//
//Prototype: getImgStr('','','','','','','','','')
//
//url  : partial URL of an image
//b    : image Border
//w    : image Width
//h    : image Height
//id   : image ID
//name : image Name
//map  : imageMap name
//alt  : alternate text for the image.
//cls  : style sheet class.
//hspc : horizontal spacing (padding top and bottom)
//vspc : vertical spacing (padding left and right)
//align: image alignment (valid: Top, Left, Right, Middle)
//str  : additional attributes or for JS event handlers...
//
function getImgStr(url, b, w, h, id, name, map, alt, cls, hspc, vspc, align, str){
   imgStr = "<IMG SRC='" + baseDir + "share/img/" + url + "' " +
            (b    ? " BORDER="  + b    : " BORDER=0") +
            (w    ? " WIDTH="   + w    : "") + 
            (h    ? " HEIGHT="  + h    : "") +
            (id   ? " ID="      + id   : "") +
            (name ? " NAME="    + name : "") + 
            (map  ? " USEMAP=#" + map  : "") +
            (alt  ? " ALT="     + "'"+ alt + "'"  : "") +
            (cls  ? " CLASS="   + cls  : "") +
            (hspc ? " HSPACE="  + hspc : "") +
            (vspc ? " VSPACE="  + vspc : "") +
            (align? " ALIGN="   + align: "") +
            " " + str +
            ">";
   //alert(imgStr)
   return imgStr;
}

//--------------------------   getImgCoordFrLeft & getImgCoordFrTop   -------------------
//Helper functions: IEgetImgLfPos and IEgetImgRtPos  (for IE only!)
//
//These functions will return the real left and top position of an image on screen.
//They are needed to find where an image's top left position is on the screen relative to
//all other objects.  The positions can then be use for other purposes.  
//
//They are specifically needed to position our DHTML Objs relative to an image 
//position on screen.
//
//These functions requires a reference to an image object.  Obtain an image object by:
//  imgObj = document.images("IMGID") //NOTE--> IE: IMGID is an ID; NS: IMGID is a NAME value.
//then pass this object to these functions and it will return the values.
//

function getImgCoordFrLeft(imgObj){
    if( NS4) return eval(imgObj).x
    else return IEgetImgLfPos(imgObj)
}

function getImgCoordFrTop(imgObj){
    if( NS4) return eval(imgObj).y
    else return IEgetImgRtPos(imgObj)
}

//------------------------------   IEgetImgLfPos and IEgetImgRtPos   --------------------
//IE4+ ONLY!
//We get the offsetLeft from each parent (most likely they are tables).  That is, our
//image lives inside many tables so the real left position of the image in relation to
//the left and top of the browser is a total of its parent's offsetLeft and Top.
//

function IEgetImgLfPos(imgObj){
    xPos = eval(imgObj).offsetLeft
    tmpElem = eval(imgObj).offsetParent  //The number of parent objects of this image.
    while(tmpElem != null){
        xPos += tmpElem.offsetLeft
        tmpElem = tmpElem.offsetParent
    }    
    return xPos
}
function IEgetImgRtPos(imgObj){
    yPos = eval(imgObj).offsetTop
    tmpElem = eval(imgObj).offsetParent
    while(tmpElem != null){
        yPos += tmpElem.offsetTop
        tmpElem = tmpElem.offsetParent
    }
    return yPos
}


//------------------------------   Window Popup   ----------------------------------------------
//This method will open a page in a new popup window.
//This window will not be resizable or scrollable.
//Caller can specify the page's URl, the popup name, and the page's Width and Height;
//The popup name is used by other pages to reference and to add new content to the this popup.
//
//Note: 
// - scrollbars are optional and can be switch on or off.
// - status bar can also be switch on or off
// - Resize can be called through JS calls: window.resizeBy(w_offset,h_offset) or window.resizeTo(w,h)
//
var newwindow = null;
function popup(popup_url,name,width,height, top, left, scrollbars, resizable, status) {
    popupFeatures  = '' +
                     'scrollbars=' + (scrollbars ? 'yes':'no') + ',' +
                     'resizable='  + (resizable  ? 'yes':'no') + ',' +
                     'status='     + (status     ? 'yes':'no') + ',' +
                     'menubar=no,location=no,toolbar=no,directories=no,' +
                     (IE4 ? 'top=' : 'screenX=')       + (top  ? top  : 100)  + ',' +  //Window Top position
                     (IE4 ? 'left=': 'screenY=')       + (left ? left : 100)  +  ',' +  //Window Left position
                     'width=' + width + ',' +
                     'height=' + height + 
                     '';
                     //alert(popupFeatures)
    
    //When reusing a window, we want to close it before openning a new one so that we can get the correct
    //(width, height) for the new window.  This is because the window size do not change once it is opened.
    //We can call resizeTo(w,h) but this did not work right either.
    //  - A window is reuse when it is using the same 'name' to open the window.
    //
    if(newwindow && !newwindow.closed) newwindow.close();
    newwindow = window.open(popup_url, name, popupFeatures);
}

//End hiding script
//------------------>


