/* combine : /javascript/desktop/common/jdw_popup.js*/
avoidLeft = 10000;
avoidRight = 1;
avoidTop = 10000;
avoidBottom = 1;

function findObj(n,d) { //v3.0
  var p,i,x;
  if (!d)
    d = document;
  if (((p=n.indexOf("?"))>0) && (parent.frames.length)) {
    d = parent.frames[n.substring(p+1)].document;
    n = n.substring(0,p);
  }
  if (n.length < 2)
    return null;
  x = d[n];
  if (!x && d.all)
    x = d.all[n];
  //for (i=0; !x && i<d.forms.length; i++)
  //x = eval("document.forms[" + i + "]." + n);
  //for (i=0; !x && d.layers && i<d.layers.length; i++)
  //x = findObj(n,d.layers[i].document);
  if (!x) {
    if ((navigator.appName == "Netscape") && (navigator.appVersion.indexOf("4.") < 0))
      x = document.getElementById(n);
  }
  return x;
}

function mapCoords(x,y,obj) {
  var xAdjust = 250;
  var yAdjust = 300;

  if (obj != null) {
    if (navigator.appName == "Netscape") {
      if (obj.clip) {
        xAdjust = obj.clip.width + 25;
        yAdjust = obj.clip.height + 25;
      }
    } else {
      xAdjust = obj.scrollWidth + 25;
      yAdjust = obj.scrollHeight + 25;
    }
  }

  if (navigator.appName == "Netscape") {
    var xMax,yMax;

    yMax = window.innerHeight - yAdjust;
    if (y > yMax)
      y = yMax;
    else
      y = y - 25;
    if (y < 1)
      y = 1;

    xMax = window.innerWidth - xAdjust;
    if (x > xMax)
      x = xMax;
    else
      x = x - 50;
    if (x < 1)
      x = 1;

    x += window.pageXOffset;
    y += window.pageYOffset;

    //to avoid opening over edit fields...
    var xMove = 0;
    if ((x <= avoidRight) && ((x+xAdjust) >= avoidLeft)) {
      xMove = (x+xAdjust) - avoidLeft;
      if (xMove > (avoidRight - x))
        xMove = x - avoidRight;
    }
    var yMove = 0;
    if ((y <= avoidBottom) && ((y+yAdjust) >= avoidTop)) {
      yMove = (y+yAdjust) - avoidTop;
      if (yMove > (avoidBottom - y))
        yMove = y - avoidBottom;
    }
    if (Math.abs(1.5*yMove) > Math.abs(xMove))
      x = x - xMove;
    else
      y = y - yMove;
  } else { //if (event)
    var xMax,yMax;
    var ind50 = (navigator.appVersion.indexOf("MSIE 5") >= 0);

    yMax = window.document.body.offsetHeight - yAdjust;
    if (! ind50)
      yMax += window.document.body.scrollTop;

    if (y > yMax)
      y = yMax;
    else
      y = y - 25;
    if (y < 1)
      y = 1;

    xMax = window.document.body.offsetWidth - xAdjust;
    if (! ind50)
      xMax += window.document.body.scrollLeft;

    if (x > xMax)
      x = xMax;
    else
      x = x - 50;
    if (x < 1)
      x = 1;

    if (ind50) {
      y += window.document.body.scrollTop;
      x += window.document.body.scrollLeft;
    }
  }
  return ((y<<16) | x);
}

/*
 * Variable arguments.
 *
 * Hide all the objects(DIVs) passed in as arguments except the last
 * one.
 */
function DoPopups() { //v3.0
  var args=DoPopups.arguments;
  var obj = null;
  if (args.length > 0)
    obj = findObj(args[args.length-1]);

  var xy = mapCoords(xLoc,yLoc,obj);

  var x = xy & 0x0000FFFF;
  var y = xy >> 16;

  var i,v,d;
  for (i=0; i<args.length; i++) {
    if (i == (args.length-1))
      v = 'show';
    else
      v = 'hide';

    if ((obj=findObj(args[i])) != null) {
      if (obj.style) {
        obj = obj.style;
        if (v == 'show') {
          v = 'visible';
          d = 'inline';
        }
        else if (v == 'hide') {
          v = 'hidden';
          d = 'none';
        }
      }
      if (navigator.appName == "Netscape") {
        obj.top = 0;
        obj.left = 0;
      } else {
        //PC 09/10/01. Change to make all hidden layers in IE move to the top left of the screen
        //And stop the scroll bars appearing.
        if (v == 'hidden') {
          obj.posTop = 0;
          obj.posLeft = 0;
        } else {
          obj.posTop = y;
          obj.posLeft = x;
        }
      }
      obj.visibility = v;
      obj.display = d;
    }
  }
}

function doAdvancedSearchPopup() {
    var width = '600';
    var height = '350';
  //if we have arguments then the advance search link has been clicked.
  //using the url passed in means we overwrite whatever is in the
  //advancedSearchUrl which may have been populated by the results of a
  //previous search.
  if(doAdvancedSearchPopup.arguments.length > 0) {
    advancedSearchPopupUrl = doAdvancedSearchPopup.arguments[0];
  }
  if(doAdvancedSearchPopup.arguments.length > 1) {
      width = doAdvancedSearchPopup.arguments[1];
  }
  if(doAdvancedSearchPopup.arguments.length > 2) {
      height = doAdvancedSearchPopup.arguments[2];
  }
  if(advancedSearchPopupUrl != null && advancedSearchPopupUrl != "") {
    var win = window.open(advancedSearchPopupUrl,'SearchWindow','dependant,resizeable,scrollbars=no,width=' + width + ',height=' + height + ',left=50,top=50');
    if (win) {
      win.focus();
    }
  }
}

var win=null; // spotts:36A1-HPR:1.6.2.2.8.3:2004/01/14:relocate from bottomNavigation_inc.jsp and faq_view.jsp
function fnNewWindow(mypage,myname,w,h,scroll){
  var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  var settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
  win = window.open(mypage,myname,settings);
}

var winPop = null; // spotts:36A1-HPR:1.6.2.2.8.3:2004/01/14:relocate from bottomNavigation_inc.jsp
function fnNewPopup(mypage,w,h){
  var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  var settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no, resizable=no, location=no, menubar=no';
  winPop = window.open(mypage,'myname',settings);
}

function MOREINFO(strUrl) {

    newWindow = window.open(strUrl, 'MoreInfoWindow',
            'dependant,resizeable,scrollbars=yes,width=600,height=600,left=50,top=50');

    if (newWindow) {
        newWindow.focus();
    }
}

function EXTRAINFO(strUrl,width,height) {

    newWindow = window.open(strUrl, 'ExtraInfoWindow',
        'dependant,scrollbars=no,width='+width+',height='+height+',left=100,top=100');

    if (newWindow) {
        newWindow.focus();
    }
}

// this one used by Hyperlinks
function OpenWindow(url,name,params) {
  var w = window.open(url, name, params);
  if (w)
    w.focus();
}/* complete : /javascript/desktop/common/jdw_popup.js*/


