function GetScrollX () {
  return window.pageXOffset ? window.pageXOffset : 
         (window.document.body.scrollLeft ? window.document.body.scrollLeft : window.document.documentElement.scrollLeft);
}

function GetScrollY () {
 return window.pageYOffset ? window.pageYOffset : 
        (window.document.body.scrollTop ? window.document.body.scrollTop : window.document.documentElement.scrollTop);
}

function ScrollTo (x, y) {
  window.scroll (x, y);  
}

function SubmitPosition (theForm) {
  theForm.action = theForm.action + "&xoffset=" + GetScrollX () + "&yoffset=" + GetScrollY ();
  theForm.submit ();
}

function OpenPopupByUrl (theUrl) {
  //assign the window a name so popup windown can return 
  window.name = "main";
  
  var hasOnOk     = theUrl.toLowerCase ().indexOf ("onok=") > 0;
  var hasOnCancel = theUrl.toUpperCase ().indexOf ("oncancel=") > 0;
  var fullUrl     = theUrl;
  if (hasOnOk) {
    fullUrl += "&onok_xoffset=" + GetScrollX () + "&onok_yoffset=" + GetScrollY ();
  };
  if (hasOnCancel) {
    fullUrl += "&oncancel_xoffset=" + GetScrollX () + "&oncancel_yoffset=" + GetScrollY ();
  };
  //random () makes the Url unique, to keep browsers from using cache version
  fullUrl += "&dummy=" + Math.random ();
  newWin=window.open (fullUrl, window.name + "_POPUP", "menubar=no,titlebar=no,dependent=yes,scrollbars=yes,width=660,height=800");
  return false;
}

function OpenPopupByUrl2 (theUrl) {
  //assign the window a name so popup windown can return 
  window.name = "main";
  
  var hasOnOk     = theUrl.toLowerCase ().indexOf ("onok=") > 0;
  var hasOnCancel = theUrl.toUpperCase ().indexOf ("oncancel=") > 0;
  var fullUrl     = theUrl;
  if (hasOnOk) {
    fullUrl += "&onok_xoffset=" + GetScrollX () + "&onok_yoffset=" + GetScrollY ();
  };
  if (hasOnCancel) {
    fullUrl += "&oncancel_xoffset=" + GetScrollX () + "&oncancel_yoffset=" + GetScrollY ();
  };
  //random () makes the Url unique, to keep browsers from using cache version
  fullUrl += "&dummy=" + Math.random ();
  newWin=window.open (fullUrl, window.name + "_POPUP", "menubar=no,titlebar=no,dependent=yes,scrollbars=yes,width=500,height=500");
  return false;
}

function OpenPopupByForm (theForm, buttonName, additionalKw, additionalValue) {
  var markTarget  = theForm.target;
  var markAction  = theForm.action;
  var theAction   = theForm.action;
  var hasOnOk     = theAction.toLowerCase ().indexOf ("onok=") > 0;
  var hasOnCancel = theAction.toUpperCase ().indexOf ("oncancel=") > 0;
  
  if (buttonName != "") {     
    theAction += "&" + buttonName + "=1";
  };
  if (additionalKw != "") {
    theAction += "&" + additionalKw + "=" + additionalValue;
  }
  if (hasOnOk) {
    theAction += "&onok_xoffset=" + GetScrollX () + "&onok_yoffset=" + GetScrollY ();
  };
  if (hasOnCancel) {
    theAction += "&oncancel_xoffset=" + GetScrollX () + "&oncancel_yoffset=" + GetScrollY ();
  };
  
  ////assign the window a name so popup windown can return 
  window.name = "main";  
  var newWin  = window.open ("", window.name + "_POPUP", "dependent,scrollbars=yes,width=700,height=550");
  theForm.target = newWin.name;
  theForm.action = theAction;  
  theForm.submit ();
  theForm.target = markTarget;
  theForm.action = markAction;
  return true;
}

function ClosePopup (theForm, buttonName) {
  if (buttonName != "") {     
    theForm.action = theForm.action + "&" + buttonName + "=1";
  };  
  if (window.name.indexOf ("_POPUP") < 0) {
    //non-popup
    theForm.submit ();
  } else {
    //popup
    theForm.target = window.opener.name;
    theForm.submit ();
    window.close ();
  };
  return true;
}

function OpenWinByUrl (theUrl) {
  //assign the window a name so popup windown can return 
  window.name = "main";
  
  //random () makes the Url unique, to keep browsers from using cache version
  
  newWin=window.open (theUrl, window.name + "_POPUP", "menubar=no,titlebar=no,dependent=yes,scrollbars=yes,width=660,height=600");  
}