if(typeof(vpExecOnce) == 'undefined') {

VPPPF = {
  VISIBLEPATH_HOST: "https://www.visiblepath.com/pathfinder",
  ADDITIONAL_PARAMETERS: "",

  init: function() {
    
    VPPPF.pathfinder = document.createElement('div');
    VPPPF.pathfinder.id = 'VPPPF_visiblepath';
    VPPPF.pathfinder.className = 'VPPPF_drag';
    VPPPF.pathfinder.style.zIndex = '999';
    VPPPF.pathfinder.style.position = 'absolute';
    VPPPF.pathfinder.style.background = '#F4F4F4';
    VPPPF.pathfinder.style.cursor = 'move';
    VPPPF.pathfinder.style.width = '272px';
    VPPPF.pathfinder.style.border = '2px solid #666666';
    VPPPF.pathfinder.style.bordertop = '2px solid #c0c0c0';
    VPPPF.pathfinder.style.borderleft = '2px solid #c0c0c0';
    VPPPF.pathfinder.style.borderright = '2px outset #c0c0c0';
    VPPPF.pathfinder.style.borderbottom = '2px outset #c0c0c0';
    VPPPF.pathfinder.onmousedown = VPPPF._dragStart;
    VPPPF.pathfinder.innerHTML = '<div id="VPPPF_control" style="text-align: right;padding-right: 5px;font-family: sans-serif;font-variant: small-caps;font-weight: bolder;font-size: 12px;"><a href="javascript:VPPPF.close();" style="text-decoration: none;padding-left: 3px;padding-right: 3px;margin-top: 1px;margin-bottom: 1px;background-color: #e35f3b;color: white;">X</a></div><div id="divLoad" style="display:none"><p class="loading" style="text-align: center;font-family:arial;font-size:10px;font-weight:bolder;margin-top:5px;margin-bottom:5px;"><img src="https://www.visiblepath.com/images/loading.gif" alt="loading..." width="16" height="16" style="display:block;margin:5px auto;"/>Loading data...</p></div><iframe id="VPPPF_iframe" frameborder="0" width="268px" height="550px" onload="VPPPF.hideLoad()"></iframe>';
        VPPPF.pathfinder.style.zIndex=10;
    VPPPF._hideFrame();

    document.body.appendChild(VPPPF.pathfinder);
     
  },

  welcome: function() {
     VPPPF._showLoadingFrame();
    VPPPF._navigate(VPPPF._catUrl("/pathfinderWelcomePage.action"));
    VPPPF._showFrame();
  },

  hideLoad: function() {
    VPPPF._hideLoadingFrame();     
  },

  search: function(query) {
    VPPPF._showLoadingFrame();
    VPPPF._search(query, null);
    VPPPF._showFrame();    
  },

  nameSearch: function(query) {    
    VPPPF._showLoadingFrame();
    VPPPF._search(query, 'CN');
    VPPPF._showFrame();    
  },

  titleSearch: function(query) {    
    VPPPF._showLoadingFrame();
    VPPPF._search(query, 'TL');
    VPPPF._showFrame();
  },

  companySearch: function(query) {
    VPPPF._showLoadingFrame();
    VPPPF._search(query, 'CO');
    VPPPF._showFrame();
  },

  close: function() {
    VPPPF._hideFrame();
    VPPPF._navigate("about:blank");
  },

  searchOnclick: function(e) {
    e = VPPPF._unifyEvent(e);
    VPPPF.search(e.srcElement.innerHTML);
  },

  dragActive: false,
  pathfinder: null,
  x: 0, y: 0, startX: 0, startY: 0,

  _search: function(query, category) {
    var params = "query=" + query + "&category=" + category + "&" + VPPPF.ADDITIONAL_PARAMETERS;
    VPPPF._navigate(VPPPF._catUrl("/pathfinderSearchResult.action", params));
  },

  _navigate: function(dest) {
    var iframe = document.getElementById("VPPPF_iframe");
    iframe.src = dest;
  },

  _catUrl: function(action, parameters) {
    if(!parameters) parameters = VPPPF.ADDITIONAL_PARAMETERS;
    return VPPPF.VISIBLEPATH_HOST + action + "?" + parameters;
  },

  _move: function(e) {
    e = VPPPF._unifyEvent(e);

    if (VPPPF.dragActive) {
      
          var xValue = VPPPF.startX + e.clientX - VPPPF.x;
          var yValue = VPPPF.startY + e.clientY - VPPPF.y;
          if (xValue > 0 && yValue > 0) {
                  VPPPF.pathfinder.style.left = xValue + "px";
              VPPPF.pathfinder.style.top = yValue + "px";
          }
      return false;
    }
  },

  _dragStart: function(e) {
    e = VPPPF._unifyEvent(e);

    VPPPF.dragActive = true;
    VPPPF.startX = parseInt(VPPPF.pathfinder.style.left+0);
    VPPPF.startY = parseInt(VPPPF.pathfinder.style.top+0);
    VPPPF.x = e.clientX;
    VPPPF.y = e.clientY;
        if(document.onmouseup) {
      VPPPF.prevOnmousemove = document.onmousemove;
    }
    document.onmousemove = VPPPF._move;
    if(document.onmouseup) {
      VPPPF.prevOnmouseup = document.onmouseup;
    }
    document.onmouseup = VPPPF._dragEnd;
    return false;
  },

  _dragEnd: function(e) {
    if(VPPPF.prevOnmousemove) {
      document.onmousemove = VPPPF.prevOnmousemove;
    }
    if(VPPPF.prevOnmouseup) {
      document.onmouseup = VPPPF.prevOnmouseup;
    }
    VPPPF.dragActive = false;
  },

  _showFrame: function() {

     VPPPF.pathfinder.style.top = 120 + (nullVar = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )  + 'px';
     VPPPF.pathfinder.style.left = "120px";

     VPPPF.pathfinder.style.position="absolute";
     VPPPF.pathfinder.style.visibility = 'visible';
     VPPPF.pathfinder.style.display = 'block';

  },

 

  _hideFrame: function() {
    VPPPF.pathfinder.style.visibility = 'hidden';
    VPPPF.pathfinder.style.display = 'none';
    
  },

   _hideLoadingFrame: function() {
    var loadframe = document.getElementById("divLoad");
    if ( loadframe  != null ){
        loadframe.style.visibility = 'hidden';
        loadframe.style.display='none';
    }    
  },

   _showLoadingFrame: function() {
    var loadframe = document.getElementById("divLoad");
    if ( loadframe  != null ){
        loadframe.style.visibility = 'visible';
        loadframe.style.display='block';
        loadframe.style.top='1px';
    }    
  },

  _unifyEvent: function(e) {
                if (typeof e == 'undefined') e = window.event;
                if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
                if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
    if (e.target && !e.srcElement) e.srcElement = e.target;
                return e;
  }

}
VPPPF.init();
vpExecOnce = 1;
}

