Addressing SQL syntax issue in messages.php
[openemr.git] / library / dialog.js
blob17367e3e94d7574416cf06672898ea5a70651030
1 // Copyright (C) 2005 Rod Roark <rod@sunsetsystems.com>
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // open a new cascaded window
9 function cascwin(url, winname, width, height, options) {
10  var mywin = window.parent ? window.parent : window;
11  var newx = 25, newy = 25;
12  if (!isNaN(mywin.screenX)) {
13   newx += mywin.screenX;
14   newy += mywin.screenY;
15  } else if (!isNaN(mywin.screenLeft)) {
16   newx += mywin.screenLeft;
17   newy += mywin.screenTop;
18  }
19  if ((newx + width) > screen.width || (newy + height) > screen.height) {
20   newx = 0;
21   newy = 0;
22  }
23  top.restoreSession();
25  // MS IE version detection taken from
26  // http://msdn2.microsoft.com/en-us/library/ms537509.aspx
27  // to adjust the height of this box for IE only -- JRM
28  if (navigator.appName == 'Microsoft Internet Explorer')
29  {
30     var ua = navigator.userAgent;
31     var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
32     if (re.exec(ua) != null)
33     rv = parseFloat( RegExp.$1 ); // this holds the version number
34     height = height + 28;
35  }
37 retval=window.open(url, winname, options +
38  ",width="   + width + ",height="  + height +
39  ",left="    + newx  + ",top="     + newy   +
40  ",screenX=" + newx  + ",screenY=" + newy);
41  if(navigator.userAgent.indexOf("Firefox")!=-1)
42  {
43     // hook the resize code to the window onload event of the newly created window.
44     retval.onload=function()
45         {
46             //find the body element
47             body=$(retval.document).find("body");
48             //change the innerDimensions (the viewport size) of the new window.
49             retval.innerHeight=(body.outerHeight(true)+10);
50             retval.innerWidth=(body.outerWidth(true));
51         };
53   
54 return retval;
56 // recursive window focus-event grabber
57 function grabfocus(w) {
58  for (var i = 0; i < w.frames.length; ++i) grabfocus(w.frames[i]);
59  w.onfocus = top.imfocused;
61  // the following was tried and discarded because it's too invasive and
62  // does not help anyway, but i left it here for the curious.
63  //
64  // for (var i = 0; i < w.document.forms.length; ++i) {
65  //  var e = w.document.forms[i].elements;
66  //  for (var j = 0; j < e.length; ++j) {
67  //   e[j].onfocus = top.imfocused;
68  //  }
69  // }
72 // call this when a "modal" dialog is desired
73 function dlgopen(url, winname, width, height) {
74  if (top.modaldialog && ! top.modaldialog.closed) {
75   if (window.focus) top.modaldialog.focus();
76   if (top.modaldialog.confirm("OK to close this other popup window?")) {
77    top.modaldialog.close();
78    top.modaldialog = null;
79   } else {
80    return false;
81   }
82  }
83  top.modaldialog = cascwin(url, winname, width, height,
84   "resizable=1,scrollbars=1,location=0,toolbar=0");
85  grabfocus(top);
86  return false;