//-----------------------------------------------------------------------------------------------
//-
//-  SendCommand            (url)
//-  UpdateElement          (url, pageElement, waitMessage)
//-  ContinualUpdateElement (url, pageElement, SecondsWait) 
//-
//-  ShowSlice              (url, parentObject, leftOffSet, topOffSet,  SliceWidth, SliceHeight)
//-  HideSlice()
//-  ShowHelp               (url, HelpWidth, HelpHeight, waitMessage)
//-  HideHelp()
//-
//-----------------------------------------------------------------------------------------------
var WaitImg = '<br/><center><img border="0" align="center" src="Public/SiteImages/wait.gif" alt="Wait Please" /></center><br/>';


document.write('<DIV id="HelpPage" style="position:absolute; display:none; border: 0px solid black;background-color:white;z-index:14;"></DIV> ');
document.write('<DIV id="PopUp"    style="position:absolute; display:none; border: 0px solid black;background-color:white;margin:0px 0px 0px 0px;z-index:4;"></DIV> ');
document.write('<DIV id="Hover"    style="position:absolute; display:none; border: 0px solid black;background-color:white;margin:0px 0px 0px 0px;z-index:4;"></DIV> ');


//-----------------------------------------------------------------------------------------------
   function SendCommand(url) {
     var req = GetHTTPObject();
     url += '&RAND=' + parseInt(Math.random()*99999999999);
     req.open("GET", url, true);
     req.send(null);
   }

//-----------------------------------------------------------------------------------------------
  function ContinualUpdateElement(url, pageElement, SecondsWait) {
     window.setInterval('UpdateElement("' + url + '", "' + pageElement + '", "")', SecondsWait * 1000 )
  }
//-----------------------------------------------------------------------------------------------

  function UpdateElement(url, pageElement, waitMessage) {
     if(waitMessage!='') {document.getElementById(pageElement).innerHTML = waitMessage;}
     var req = GetHTTPObject();
     req.onreadystatechange = function() {responseAHAH(req, pageElement);};
     url += '&RAND=' + parseInt(Math.random()*99999999999);

     req.open("GET", url, true);
     req.send(null);
  }
    function responseAHAH(req, pageElement) {
      var output = '';
      if(req.readyState == 4) {
        if(req.status == 200) {
          output = req.responseText;
          //alert(output);
          output = output.replace(/\|SP\|/g, '&nbsp;'); // Decimal 160, non-breaking-space
          document.getElementById(pageElement).innerHTML = output;
    } } }
//-----------------------------------------------------------------------------------------------

function ShowHelp(url, HelpWidth, HelpHeight, waitMessage){
  if (document.getElementById){
    var subobj  = document.getElementById('HelpPage');
    var xpos    = (document.body.offsetWidth/2) - (HelpWidth/2)     //getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) ;
    var ypos    = (document.body.offsetHeight/2) - (HelpHeight/2)  //getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0);

    subobj.style.left   = xpos+"px";
    subobj.style.top    = ypos+"px";
    subobj.style.width  = HelpWidth+"px";
    subobj.style.height = HelpHeight+"px";
    subobj.style.display=(subobj.style.display!="block")? "block" : "none";
    
    UpdateElement(url, 'HelpPage', waitMessage)    
    return false;
  } else {  return true; }
}

function HideHelp(){ document.getElementById('HelpPage').style.display="none"; }

//-----------------------------------------------------------------------------------------------
function ShowSlice(url, parentObject, leftOffSet, topOffSet){
    HideHover()
    UpdateElement(url, 'PopUp', '')    
    PositionDiv('PopUp', parentObject, leftOffSet, topOffSet)
  }
//-----------------------------------------------------------------------------------------------
function ShowHover(url, parentObject, leftOffSet, topOffSet){
    //--Get-display-html before hiding or showing---------------------
    UpdateElement(url, 'Hover', '')    
    PositionDiv('Hover', parentObject, leftOffSet, topOffSet)
  }

//-----------------------------------------------------------------------------------------------
function HideSlice(){ document.getElementById('PopUp').style.display="none"; }
function HideHover(){ document.getElementById('Hover').style.display="none"; }
//-----------------------------------------------------------------------------------------------
function PositionDiv(Section, parentObject, leftOffSet, topOffSet){
	  //--get the x,y cords for position and load in the size of the popup
	  var coors      =  findPos(parentObject);
	     coors[0]   += leftOffSet;
	     coors[1]   += topOffSet;

    var SectionDiv              = document.getElementById(Section);
    SectionDiv.style.left       = coors[0] +"px";
    SectionDiv.style.top        = coors[1] +"px";
    SectionDiv.style.display    = '';
  }

//-----------------------------------------------------------------------------------------------
    
  function GetHTTPObject() {
      var http_request = false;

      if (window.XMLHttpRequest) { // Mozilla, Safari, ...
          http_request = new XMLHttpRequest();
          if (http_request.overrideMimeType) {
              http_request.overrideMimeType('text/xml');  // See note below about this line
          }
      } else if (window.ActiveXObject) { // IE
          try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
          } catch (e) {
              try {  http_request = new ActiveXObject("Microsoft.XMLHTTP"); } 
              catch (e) {}
          }
      }

      if (!http_request) {
          alert('Giving up :( Cannot create an XMLHTTP instance');
          return false;
      }
      return http_request;
  }
//-----------------------------------------------------------------------------------------------
  function findPos(obj) {
  	var curleft = curtop = 0;
  	if (obj.offsetParent) {
  		curleft = obj.offsetLeft
  		curtop = obj.offsetTop
  		while (obj = obj.offsetParent) {
  			curleft += obj.offsetLeft
  			curtop += obj.offsetTop
  		}
  	}
  	return [curleft,curtop];
  }
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
