﻿var qtID=""; /*This is the last quick tip link that was moused over.*/
var qtOpenID=""; /*This is the currenly opened quick tip.*/
var qtIFrame=null; /*This object holds the current quick tip iframe on the page.*/
var overqtIFrame=null;/*This traps when the mouse is over the open event iFrame.*/
var currentOpenTimeout=null;/*This handles all threads that create iframes.*/
var currentCloseTimeout=null;/*This handles all threads that remove iframes.*/

/*Detect if the browser is IE or not.*/
/*If it is not IE, we assume that the browser is NS.*/
var IE = document.all?true:false;

/*************************************************************************************/
/* TO ADD QUICK LINKS TO A PAGE                                                      */
/* The two events must have functions added to them as show below.  The QuickTip.js  */
/* file must be included on the page making the quick tip calls using a script tag.  */
/* This quick tips work in IE & Firefox, Netscape & Opera do not allow mousing over  */
/* the quick tip pop up (they are screwy).                                           */
/*                                                                                   */
/* onmouseout="startexitingQuickTip();"                                              */
/* onmouseover="initQuickTip('event details http link','information id',event)       */
/*************************************************************************************/
       
function initQuickTip(Url,Iid,e){
    removeTimouts();
    /*Set that the user is no longer of a quick tip.*/
    overqtIFrame=null;
    /*Set the quick tip to load and delay the actual load.*/
    qtID=Iid;
    /*Get the position of the mouse on the screen.*/
    var xPos;
    var yPos;
    if(IE==true){
        /*grab the x-y pos if browser is IE*/
        xPos = e.clientX + document.body.scrollLeft;
        yPos = e.clientY + document.body.scrollTop;
    }
    else{
        /*grab the x-y pos if browser is NS*/
        xPos = e.pageX;
        yPos = e.pageY;
    }  
    /*Catch possible negative values*/
    if(xPos < 0){xPos = 0;}
    if(yPos < 0){yPos = 0;}  

    /*Set the new openning timeout.*/
    currentOpenTimeout = setTimeout("loadQuickTip('"+Url+"','"+Iid+"','"+xPos+"','"+yPos+"')", 500);
}

function loadQuickTip(Url,Iid,xPos,yPos){
    /*Only a timeout that has never expired is allowed to enter this function.*/
    if(qtID == Iid && qtOpenID != Iid){       
        /*Remove the old quick tip no matter what.*/
        if(qtIFrame != null){removeQuickTip();}

        /*Make the new quick tip iFrame*/
        makeQuickTip(Url,Iid,xPos,yPos);
    }
}

function startexitingQuickTip(){
    /*The user has exited a quick tip link or is not over a quick tip.*/
    overqtIFrame=null;
    currentCloseTimeout = setTimeout("removeQuickTip()", 500);
}

function removeQuickTip(){
    /*Only a timeout that has never expired is allowed to enter this function.*/
    /*An iFrame can only be removed if a mouse is not over it as well.*/
    if((qtIFrame!=null) && (overqtIFrame==null)){
        /*Remove the iFrame from the page.*/
        document.body.removeChild(qtIFrame);
        qtIFrame=null;
        /*An iFrame has been totally removed from the page.*/
        qtID="";
        qtOpenID="";
    }
}

function overIFrame(){
    /*Flag that the user is over an iFrame.*/
    overqtIFrame=true;
    removeTimouts();
}

function makeQuickTip(Url,Iid,xPos,yPos){
    /*This function dynamically adds an iFrame to the page.*/
    qtIFrame = document.createElement("IFRAME");
    qtIFrame.setAttribute("id", "adxqtiframe");
    qtIFrame.setAttribute("name", "adxqtiframe");
    qtIFrame.setAttribute("src", Url+"="+Iid);
    qtIFrame.setAttribute("width", "380px");
    qtIFrame.setAttribute("height", "300px");
    qtIFrame.setAttribute("scrolling", "auto");
    qtIFrame.setAttribute("frameBorder", "no");
    qtIFrame.setAttribute("marginWidth", "0");
    qtIFrame.setAttribute("marginHeight", "0");
    qtIFrame.onmouseover = overIFrame;
    qtIFrame.onmouseout = startexitingQuickTip;
    /*Position the iframe correctly.*/
    qtIFrame.style.position = "absolute";
    qtIFrame.className = "quicktipborder";
    
    /*Get the available on screen space*/
    var browserWidth=getBrowserWidth();
    /*This is the right of the quick tip.*/
    var xPosRight=parseInt(xPos)+parseInt(380);
    
    if(xPosRight > browserWidth){
        /*Move the quick tip on screen*/
        var newLeft = parseInt(xPos)-parseInt(380);
        qtIFrame.style.left = newLeft+"px";
    }
    else{
        /*Leave it where it is.*/
        qtIFrame.style.left = xPos+"px";
    }
    
    /*The y position will get set later.*/
    qtIFrame.style.top = yPos+"px";
    
    document.body.appendChild(qtIFrame);
    
    /*Set the quick tip parameters*/
    qtID=Iid;
    qtOpenID=Iid;
}

function setIFrameSize(){
    /*This is the actual quick tip area in the iframe.*/
    var qt = frames["adxqtiframe"].document;
    var qtFrame = document.getElementById("adxqtiframe");
    
    var y;
    if(qt != null){
        /*Get the size of the quick tip inside the iframe.*/
        qt = frames["adxqtiframe"].document.getElementById("adx_qt_div");
        y=qt.clientHeight+20;
    }
    else{
        /*Just use the default size of the iframe*/
        y=300;
    }
    
    if(y>400){
        /*The iFrame is not allowed to have more than a 400px height.*/
        qtFrame.height = "400px";
        y=400;/*This is used for the next block of code*/
    }
    else{
        /*The iFrame size is less than 400px this is valid.*/
        qtFrame.height = y+"px";
    }

    /*This holds how far this page has scrolled*/
    var scrollY=getScrollY();
    
    /*This is that available vertical space on screen.*/
    var browserHeight=getBrowserHeight();
    
    /*This is the top of the quick tip.*/
    var yPosTop=parseInt(qtFrame.style.top.replace(/px/,""));
    var yPosTopNoScroll = parseInt(yPosTop)-parseInt(scrollY);
    
    /*This is the bottom of the quick tip.*/
    var yPosBottom = parseInt(yPosTopNoScroll)+parseInt(y);
    
    if(yPosBottom > browserHeight){
        /*Move the quick tip on screen*/
        var newTop = parseInt(yPosTopNoScroll)-parseInt(y)+parseInt(scrollY);
        qtFrame.style.top = newTop+"px";
    }
    else{
        /*Leave it where it is.*/
    }
}

function removeTimouts(){
    /*Remove any closing timeouts*/
    if(currentCloseTimeout != null){
        clearTimeout(currentCloseTimeout);
        currentCloseTimeout=null;
    }
    /*Remove any openning timeouts.*/
    if(currentOpenTimeout != null){
        clearTimeout(currentOpenTimeout);
        currentOpenTimeout=null;
    }
}

function getBrowserWidth(){
    var myWidth=0;
    
    if(typeof(window.innerWidth) == 'number'){
        /*Non-IE*/myWidth = window.innerWidth;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
        /*IE 6+ in 'standards compliant mode'*/myWidth = document.documentElement.clientWidth;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
        /*IE 4 compatible*/myWidth = document.body.clientWidth;
    }
    return myWidth;
}

function getBrowserHeight(){
    var myHeight=0;
    
    if(typeof(window.innerWidth) == 'number'){
        /*Non-IE*/myHeight = window.innerHeight;
    }
    else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
        /*IE 6+ in 'standards compliant mode'*/myHeight = document.documentElement.clientHeight;
    }
    else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
        /*IE 4 compatible*/myHeight = document.body.clientHeight;
    }
    return myHeight;
}

function getScrollY() {
  var scrOfY = 0;
  if(typeof(window.pageYOffset)=='number'){
    /*Netscape compliant*/scrOfY = window.pageYOffset;
  }
  else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
    /*DOM compliant*/scrOfY = document.body.scrollTop;
  }
  else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
    /*IE6 standards compliant mode*/scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}