Updated documentation.
[openemr.git] / interface / main / myadmin / libraries / functions.js
blob073f76e0c606b4199d9f6a1ec8e0108fc5607bd1
1 /* $Id$ */
4 /**
5  * Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
6  * This function is called while clicking links
7  *
8  * @param   object   the link
9  * @param   object   the sql query to submit
10  *
11  * @return  boolean  whether to run the query or not
12  */
13 function confirmLink(theLink, theSqlQuery)
15     // Confirmation is not required in the configuration file
16     // or browser is Opera (crappy js implementation)
17     if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
18         return true;
19     }
21     var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
22     if (is_confirmed) {
23         theLink.href += '&is_js_confirmed=1';
24     }
26     return is_confirmed;
27 } // end of the 'confirmLink()' function
30 /**
31  * Displays an error message if a "DROP DATABASE" statement is submitted
32  * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
33  * sumitting it if required.
34  * This function is called by the 'checkSqlQuery()' js function.
35  *
36  * @param   object   the form
37  * @param   object   the sql query textarea
38  *
39  * @return  boolean  whether to run the query or not
40  *
41  * @see     checkSqlQuery()
42  */
43 function confirmQuery(theForm1, sqlQuery1)
45     // Confirmation is not required in the configuration file
46     if (confirmMsg == '') {
47         return true;
48     }
50     // The replace function (js1.2) isn't supported
51     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
52         return true;
53     }
55     // js1.2+ -> validation with regular expressions
56     else {
57         // "DROP DATABASE" statement isn't allowed
58         if (noDropDbMsg != '') {
59             var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
60             if (drop_re.test(sqlQuery1.value)) {
61                 alert(noDropDbMsg);
62                 theForm1.reset();
63                 sqlQuery1.focus();
64                 return false;
65             } // end if
66         } // end if
68         // Confirms a "DROP/DELETE/ALTER" statement
69         //
70         // TODO: find a way (if possible) to use the parser-analyser
71         // for this kind of verification
72         // For now, I just added a ^ to check for the statement at
73         // beginning of expression
75         //var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
76         //var do_confirm_re_1 = new RegExp('ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
77         //var do_confirm_re_2 = new RegExp('DELETE\\s+FROM\\s', 'i');
78         var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
79         var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
80         var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
81         if (do_confirm_re_0.test(sqlQuery1.value)
82             || do_confirm_re_1.test(sqlQuery1.value)
83             || do_confirm_re_2.test(sqlQuery1.value)) {
84             var message      = (sqlQuery1.value.length > 100)
85                              ? sqlQuery1.value.substr(0, 100) + '\n    ...'
86                              : sqlQuery1.value;
87             var is_confirmed = confirm(confirmMsg + ' :\n' + message);
88             // drop/delete/alter statement is confirmed -> update the
89             // "is_js_confirmed" form field so the confirm test won't be
90             // run on the server side and allows to submit the form
91             if (is_confirmed) {
92                 theForm1.elements['is_js_confirmed'].value = 1;
93                 return true;
94             }
95             // "DROP/DELETE/ALTER" statement is rejected -> do not submit
96             // the form
97             else {
98                 window.focus();
99                 sqlQuery1.focus();
100                 return false;
101             } // end if (handle confirm box result)
102         } // end if (display confirm box)
103     } // end confirmation stuff
105     return true;
106 } // end of the 'confirmQuery()' function
110  * Displays an error message if the user submitted the sql query form with no
111  * sql query, else checks for "DROP/DELETE/ALTER" statements
113  * @param   object   the form
115  * @return  boolean  always false
117  * @see     confirmQuery()
118  */
119 function checkSqlQuery(theForm)
121     var sqlQuery = theForm.elements['sql_query'];
122     var isEmpty  = 1;
124     // The replace function (js1.2) isn't supported -> basic tests
125     if (typeof(sqlQuery.value.replace) == 'undefined') {
126         isEmpty      = (sqlQuery.value == '') ? 1 : 0;
127         if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
128             isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
129         }
130         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
131             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
132         }
133         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
134             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
135         }
136     }
137     // js1.2+ -> validation with regular expressions
138     else {
139         var space_re = new RegExp('\\s+');
140         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
141                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
142             return true;
143         }
144         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
145                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
146             return true;
147         }
148         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
149                 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
150                 theForm.elements['id_bookmark'].selectedIndex != 0
151                 ) {
152             return true;
153         }
154         // Checks for "DROP/DELETE/ALTER" statements
155         if (sqlQuery.value.replace(space_re, '') != '') {
156             if (confirmQuery(theForm, sqlQuery)) {
157                 return true;
158             } else {
159                 return false;
160             }
161         }
162         theForm.reset();
163         isEmpty = 1;
164     }
166     if (isEmpty) {
167         sqlQuery.select();
168         alert(errorMsg0);
169         sqlQuery.focus();
170         return false;
171     }
173     return true;
174 } // end of the 'checkSqlQuery()' function
178  * Displays an error message if an element of a form hasn't been completed and
179  * should be
181  * @param   object   the form
182  * @param   string   the name of the form field to put the focus on
184  * @return  boolean  whether the form field is empty or not
185  */
186 function emptyFormElements(theForm, theFieldName)
188     var isEmpty  = 1;
189     var theField = theForm.elements[theFieldName];
190     // Whether the replace function (js1.2) is supported or not
191     var isRegExp = (typeof(theField.value.replace) != 'undefined');
193     if (!isRegExp) {
194         isEmpty      = (theField.value == '') ? 1 : 0;
195     } else {
196         var space_re = new RegExp('\\s+');
197         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
198     }
199     if (isEmpty) {
200         theForm.reset();
201         theField.select();
202         alert(errorMsg0);
203         theField.focus();
204         return false;
205     }
207     return true;
208 } // end of the 'emptyFormElements()' function
212  * Ensures a value submitted in a form is numeric and is in a range
214  * @param   object   the form
215  * @param   string   the name of the form field to check
216  * @param   integer  the minimum authorized value
217  * @param   integer  the maximum authorized value
219  * @return  boolean  whether a valid number has been submitted or not
220  */
221 function checkFormElementInRange(theForm, theFieldName, min, max)
223     var theField         = theForm.elements[theFieldName];
224     var val              = parseInt(theField.value);
226     if (typeof(min) == 'undefined') {
227         min = 0;
228     }
229     if (typeof(max) == 'undefined') {
230         max = Number.MAX_VALUE;
231     }
233     // It's not a number
234     if (isNaN(val)) {
235         theField.select();
236         alert(errorMsg1);
237         theField.focus();
238         return false;
239     }
240     // It's a number but it is not between min and max
241     else if (val < min || val > max) {
242         theField.select();
243         alert(val + errorMsg2);
244         theField.focus();
245         return false;
246     }
247     // It's a valid number
248     else {
249         theField.value = val;
250     }
252     return true;
253 } // end of the 'checkFormElementInRange()' function
255 function checkTableEditForm(theForm, fieldsCnt)
257     for (i=0; i<fieldsCnt; i++)
258     {
259         var id = "field_" + i + "_2";
260         var elm = getElement(id);
261         if (elm.value == 'VARCHAR' || elm.value == 'CHAR') {
262             elm2 = getElement("field_" + i + "_3");
263             val = parseInt(elm2.value);
264             elm3 = getElement("field_" + i + "_1");
265             if (isNaN(val) && elm3.value != "") {
266                 elm2.select();
267                 alert(errorMsg1);
268                 elm2.focus();
269                 return false;
270             }
271         }
272     }
273     return true;
274 } // enf of the 'checkTableEditForm()' function
278  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
279  * checkboxes is consistant
281  * @param   object   the form
282  * @param   string   a code for the action that causes this function to be run
284  * @return  boolean  always true
285  */
286 function checkTransmitDump(theForm, theAction)
288     var formElts = theForm.elements;
290     // 'zipped' option has been checked
291     if (theAction == 'zip' && formElts['zip'].checked) {
292         if (!formElts['asfile'].checked) {
293             theForm.elements['asfile'].checked = true;
294         }
295         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
296             theForm.elements['gzip'].checked = false;
297         }
298         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
299             theForm.elements['bzip'].checked = false;
300         }
301     }
302     // 'gzipped' option has been checked
303     else if (theAction == 'gzip' && formElts['gzip'].checked) {
304         if (!formElts['asfile'].checked) {
305             theForm.elements['asfile'].checked = true;
306         }
307         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
308             theForm.elements['zip'].checked = false;
309         }
310         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
311             theForm.elements['bzip'].checked = false;
312         }
313     }
314     // 'bzipped' option has been checked
315     else if (theAction == 'bzip' && formElts['bzip'].checked) {
316         if (!formElts['asfile'].checked) {
317             theForm.elements['asfile'].checked = true;
318         }
319         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
320             theForm.elements['zip'].checked = false;
321         }
322         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
323             theForm.elements['gzip'].checked = false;
324         }
325     }
326     // 'transmit' option has been unchecked
327     else if (theAction == 'transmit' && !formElts['asfile'].checked) {
328         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
329             theForm.elements['zip'].checked = false;
330         }
331         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
332             theForm.elements['gzip'].checked = false;
333         }
334         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
335             theForm.elements['bzip'].checked = false;
336         }
337     }
339     return true;
340 } // end of the 'checkTransmitDump()' function
344  * This array is used to remember mark status of rows in browse mode
345  */
346 var marked_row = new Array;
350  * Sets/unsets the pointer and marker in browse mode
352  * @param   object    the table row
353  * @param   interger  the row number
354  * @param   string    the action calling this script (over, out or click)
355  * @param   string    the default background color
356  * @param   string    the color to use for mouseover
357  * @param   string    the color to use for marking a row
359  * @return  boolean  whether pointer is set or not
360  */
361 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
363     var theCells = null;
365     // 1. Pointer and mark feature are disabled or the browser can't get the
366     //    row -> exits
367     if ((thePointerColor == '' && theMarkColor == '')
368         || typeof(theRow.style) == 'undefined') {
369         return false;
370     }
372     // 2. Gets the current row and exits if the browser can't get it
373     if (typeof(document.getElementsByTagName) != 'undefined') {
374         theCells = theRow.getElementsByTagName('td');
375     }
376     else if (typeof(theRow.cells) != 'undefined') {
377         theCells = theRow.cells;
378     }
379     else {
380         return false;
381     }
383     // 3. Gets the current color...
384     var rowCellsCnt  = theCells.length;
385     var domDetect    = null;
386     var currentColor = null;
387     var newColor     = null;
388     // 3.1 ... with DOM compatible browsers except Opera that does not return
389     //         valid values with "getAttribute"
390     if (typeof(window.opera) == 'undefined'
391         && typeof(theCells[0].getAttribute) != 'undefined') {
392         currentColor = theCells[0].getAttribute('bgcolor');
393         domDetect    = true;
394     }
395     // 3.2 ... with other browsers
396     else {
397         currentColor = theCells[0].style.backgroundColor;
398         domDetect    = false;
399     } // end 3
401     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
402     if (currentColor.indexOf("rgb") >= 0) 
403     {
404         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
405                                      currentColor.indexOf(')'));
406         var rgbValues = rgbStr.split(",");
407         currentColor = "#";
408         var hexChars = "0123456789ABCDEF";
409         for (var i = 0; i < 3; i++)
410         {
411             var v = rgbValues[i].valueOf();
412             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
413         }
414     }
416     // 4. Defines the new color
417     // 4.1 Current color is the default one
418     if (currentColor == ''
419         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
420         if (theAction == 'over' && thePointerColor != '') {
421             newColor              = thePointerColor;
422         }
423         else if (theAction == 'click' && theMarkColor != '') {
424             newColor              = theMarkColor;
425             marked_row[theRowNum] = true;
426         }
427     }
428     // 4.1.2 Current color is the pointer one
429     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
430              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
431         if (theAction == 'out') {
432             newColor              = theDefaultColor;
433         }
434         else if (theAction == 'click' && theMarkColor != '') {
435             newColor              = theMarkColor;
436             marked_row[theRowNum] = true;
437         }
438     }
439     // 4.1.3 Current color is the marker one
440     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
441         if (theAction == 'click') {
442             newColor              = (thePointerColor != '')
443                                   ? thePointerColor
444                                   : theDefaultColor;
445             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
446                                   ? true
447                                   : null;
448         }
449     } // end 4
451     // 5. Sets the new color...
452     if (newColor) {
453         var c = null;
454         // 5.1 ... with DOM compatible browsers except Opera
455         if (domDetect) {
456             for (c = 0; c < rowCellsCnt; c++) {
457                 theCells[c].setAttribute('bgcolor', newColor, 0);
458             } // end for
459         }
460         // 5.2 ... with other browsers
461         else {
462             for (c = 0; c < rowCellsCnt; c++) {
463                 theCells[c].style.backgroundColor = newColor;
464             }
465         }
466     } // end 5
468     return true;
469 } // end of the 'setPointer()' function
472  * Sets/unsets the pointer and marker in vertical browse mode
474  * @param   object    the table row
475  * @param   interger  the row number
476  * @param   string    the action calling this script (over, out or click)
477  * @param   string    the default background color
478  * @param   string    the color to use for mouseover
479  * @param   string    the color to use for marking a row
481  * @return  boolean  whether pointer is set or not
483  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
484  */
485 function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
486     var theCells = null;
488     // 1. Pointer and mark feature are disabled or the browser can't get the
489     //    row -> exits
490     if ((thePointerColor == '' && theMarkColor == '')
491         || typeof(theRow.style) == 'undefined') {
492         return false;
493     }
495     // 2. Gets the current row and exits if the browser can't get it
496     if (typeof(document.getElementsByTagName) != 'undefined') {
497         theCells = theRow.getElementsByTagName('td');
498     }
499     else if (typeof(theRow.cells) != 'undefined') {
500         theCells = theRow.cells;
501     }
502     else {
503         return false;
504     }
506     // 3. Gets the current color...
507     var rowCellsCnt  = theCells.length;
508     var domDetect    = null;
509     var currentColor = null;
510     var newColor     = null;
512     // 3.1 ... with DOM compatible browsers except Opera that does not return
513     //         valid values with "getAttribute"
514     if (typeof(window.opera) == 'undefined'
515         && typeof(theCells[0].getAttribute) != 'undefined') {
516         currentColor = theCells[0].getAttribute('bgcolor');
517         domDetect    = true;
518     }
519     // 3.2 ... with other browsers
520     else {
521         domDetect    = false;
522     } // end 3
524     var c = null;
525     // 5.1 ... with DOM compatible browsers except Opera
526     for (c = 0; c < rowCellsCnt; c++) {
527         if (domDetect) {
528             currentColor = theCells[c].getAttribute('bgcolor');
529         } else {
530             currentColor = theCells[c].style.backgroundColor;
531         }
533         // 4. Defines the new color
534         // 4.1 Current color is the default one
535         if (currentColor == ''
536             || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
537             || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
538             if (theAction == 'over' && thePointerColor != '') {
539                 newColor              = thePointerColor;
540             } else if (theAction == 'click' && theMarkColor != '') {
541                 newColor              = theMarkColor;
542                 marked_row[theRowNum] = true;
543             }
544         }
545         // 4.1.2 Current color is the pointer one
546         else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
547                  && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
548             if (theAction == 'out') {
549                 if (c % 2) {
550                     newColor              = theDefaultColor1;
551                 } else {
552                     newColor              = theDefaultColor2;
553                 }
554             }
555             else if (theAction == 'click' && theMarkColor != '') {
556                 newColor              = theMarkColor;
557                 marked_row[theRowNum] = true;
558             }
559         }
560         // 4.1.3 Current color is the marker one
561         else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
562             if (theAction == 'click') {
563                 newColor              = (thePointerColor != '')
564                                       ? thePointerColor
565                                       : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
566                 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
567                                       ? true
568                                       : null;
569             }
570         } // end 4
572         // 5. Sets the new color...
573         if (newColor) {
574             if (domDetect) {
575                 theCells[c].setAttribute('bgcolor', newColor, 0);
576             }
577             // 5.2 ... with other browsers
578             else {
579                 theCells[c].style.backgroundColor = newColor;
580             }
581         } // end 5
582     } // end for
584      return true;
585  } // end of the 'setVerticalPointer()' function
588  * Checks/unchecks all tables
590  * @param   string   the form name
591  * @param   boolean  whether to check or to uncheck the element
593  * @return  boolean  always true
594  */
595 function setCheckboxes(the_form, do_check)
597     var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
598                   ? document.forms[the_form].elements['selected_db[]']
599                   : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
600           ? document.forms[the_form].elements['selected_tbl[]']
601           : document.forms[the_form].elements['selected_fld[]'];
602     var elts_cnt  = (typeof(elts.length) != 'undefined')
603                   ? elts.length
604                   : 0;
606     if (elts_cnt) {
607         for (var i = 0; i < elts_cnt; i++) {
608             elts[i].checked = do_check;
609         } // end for
610     } else {
611         elts.checked        = do_check;
612     } // end if... else
614     return true;
615 } // end of the 'setCheckboxes()' function
619   * Checks/unchecks all options of a <select> element
620   *
621   * @param   string   the form name
622   * @param   string   the element name
623   * @param   boolean  whether to check or to uncheck the element
624   *
625   * @return  boolean  always true
626   */
627 function setSelectOptions(the_form, the_select, do_check)
629     var selectObject = document.forms[the_form].elements[the_select];
630     var selectCount  = selectObject.length;
632     for (var i = 0; i < selectCount; i++) {
633         selectObject.options[i].selected = do_check;
634     } // end for
636     return true;
637 } // end of the 'setSelectOptions()' function
640   * Allows moving around inputs/select by Ctrl+arrows
641   *
642   * @param   object   event data
643   */
644 function onKeyDownArrowsHandler(e) {
645     e = e||window.event;
646     var o = (e.srcElement||e.target);
647     if (!o) return;
648     if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
649     if (!e.ctrlKey) return;
650     if (!o.id) return;
652     var pos = o.id.split("_");
653     if (pos[0] != "field" || typeof pos[2] == "undefined") return;
655     var x = pos[2], y=pos[1];
657     // skip non existent fields
658     for (i=0; i<10; i++)
659     {
660         switch(e.keyCode) {
661             case 38: y--; break; // up
662             case 40: y++; break; // down
663             case 37: x--; break; // left
664             case 39: x++; break; // right
665             default: return;
666         }
668         var id = "field_" + y + "_" + x;
669         var nO = document.getElementById(id);
670         if (nO) break;
671     }
673     if (!nO) return;
674     nO.focus();
675     if (nO.tagName != 'SELECT') {
676         nO.select();
677     }
678     e.returnValue = false;
682   * Inserts multiple fields.
683   *
684   */
685 function insertValueQuery() {
686     var myQuery = document.sqlform.sql_query;
687     var myListBox = document.sqlform.dummy;
689     if(myListBox.options.length > 0) {
690         var chaineAj = "";
691         var NbSelect = 0;
692         for(var i=0; i<myListBox.options.length; i++) {
693             if (myListBox.options[i].selected){
694                 NbSelect++;
695                 if (NbSelect > 1)
696                     chaineAj += ", ";
697                 chaineAj += myListBox.options[i].value;
698             }
699         }
701         //IE support
702         if (document.selection) {
703             myQuery.focus();
704             sel = document.selection.createRange();
705             sel.text = chaineAj;
706             document.sqlform.insert.focus();
707         }
708         //MOZILLA/NETSCAPE support
709         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
710             var startPos = document.sqlform.sql_query.selectionStart;
711             var endPos = document.sqlform.sql_query.selectionEnd;
712             var chaineSql = document.sqlform.sql_query.value;
714             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
715         } else {
716             myQuery.value += chaineAj;
717         }
718     }
722   * listbox redirection
723   */
724 function goToUrl(selObj, goToLocation){
725     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
729  * getElement
730  */
731 function getElement(e,f){
732     if(document.layers){
733         f=(f)?f:self;
734         if(f.document.layers[e]) {
735             return f.document.layers[e];
736         }
737         for(W=0;i<f.document.layers.length;W++) {
738             return(getElement(e,fdocument.layers[W]));
739         }
740     }
741     if(document.all) {
742         return document.all[e];
743     }
744     return document.getElementById(e);
748   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
749   */
750 function refreshDragOption(e) {
751     myid = getElement(e);
752     if (myid.style.visibility == 'visible') {
753         refreshLayout();
754     }
758   * Refresh/resize the WYSIWYG-PDF scratchboard
759   */
760 function refreshLayout() {
761         myid = getElement('pdflayout');
763         if (document.pdfoptions.orientation.value == 'P') {
764             posa = 'x';
765             posb = 'y';
766         } else {
767             posa = 'y';
768             posb = 'x';
769         }
771         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
772         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
776   * Show/hide the WYSIWYG-PDF scratchboard
777   */
778 function ToggleDragDrop(e) {
779     myid = getElement(e);
781     if (myid.style.visibility == 'hidden') {
782         init();
783         myid.style.visibility = 'visible';
784         myid.style.display = 'block';
785         document.edcoord.showwysiwyg.value = '1';
786     } else {
787         myid.style.visibility = 'hidden';
788         myid.style.display = 'none';
789         document.edcoord.showwysiwyg.value = '0';
790     }
794   * PDF scratchboard: When a position is entered manually, update
795   * the fields inside the scratchboard.
796   */
797 function dragPlace(no, axis, value) {
798     if (axis == 'x') {
799         getElement("table_" + no).style.left = value + 'px';
800     } else {
801         getElement("table_" + no).style.top  = value + 'px';
802     }
806   * Returns paper sizes for a given format
807   */
808 function pdfPaperSize(format, axis) {
809     switch (format.toUpperCase()) {
810         case '4A0':
811             if (axis == 'x') return 4767.87; else return 6740.79;
812             break;
813         case '2A0':
814             if (axis == 'x') return 3370.39; else return 4767.87;
815             break;
816         case 'A0':
817             if (axis == 'x') return 2383.94; else return 3370.39;
818             break;
819         case 'A1':
820             if (axis == 'x') return 1683.78; else return 2383.94;
821             break;
822         case 'A2':
823             if (axis == 'x') return 1190.55; else return 1683.78;
824             break;
825         case 'A3':
826             if (axis == 'x') return 841.89; else return 1190.55;
827             break;
828         case 'A4':
829             if (axis == 'x') return 595.28; else return 841.89;
830             break;
831         case 'A5':
832             if (axis == 'x') return 419.53; else return 595.28;
833             break;
834         case 'A6':
835             if (axis == 'x') return 297.64; else return 419.53;
836             break;
837         case 'A7':
838             if (axis == 'x') return 209.76; else return 297.64;
839             break;
840         case 'A8':
841             if (axis == 'x') return 147.40; else return 209.76;
842             break;
843         case 'A9':
844             if (axis == 'x') return 104.88; else return 147.40;
845             break;
846         case 'A10':
847             if (axis == 'x') return 73.70; else return 104.88;
848             break;
849         case 'B0':
850             if (axis == 'x') return 2834.65; else return 4008.19;
851             break;
852         case 'B1':
853             if (axis == 'x') return 2004.09; else return 2834.65;
854             break;
855         case 'B2':
856             if (axis == 'x') return 1417.32; else return 2004.09;
857             break;
858         case 'B3':
859             if (axis == 'x') return 1000.63; else return 1417.32;
860             break;
861         case 'B4':
862             if (axis == 'x') return 708.66; else return 1000.63;
863             break;
864         case 'B5':
865             if (axis == 'x') return 498.90; else return 708.66;
866             break;
867         case 'B6':
868             if (axis == 'x') return 354.33; else return 498.90;
869             break;
870         case 'B7':
871             if (axis == 'x') return 249.45; else return 354.33;
872             break;
873         case 'B8':
874             if (axis == 'x') return 175.75; else return 249.45;
875             break;
876         case 'B9':
877             if (axis == 'x') return 124.72; else return 175.75;
878             break;
879         case 'B10':
880             if (axis == 'x') return 87.87; else return 124.72;
881             break;
882         case 'C0':
883             if (axis == 'x') return 2599.37; else return 3676.54;
884             break;
885         case 'C1':
886             if (axis == 'x') return 1836.85; else return 2599.37;
887             break;
888         case 'C2':
889             if (axis == 'x') return 1298.27; else return 1836.85;
890             break;
891         case 'C3':
892             if (axis == 'x') return 918.43; else return 1298.27;
893             break;
894         case 'C4':
895             if (axis == 'x') return 649.13; else return 918.43;
896             break;
897         case 'C5':
898             if (axis == 'x') return 459.21; else return 649.13;
899             break;
900         case 'C6':
901             if (axis == 'x') return 323.15; else return 459.21;
902             break;
903         case 'C7':
904             if (axis == 'x') return 229.61; else return 323.15;
905             break;
906         case 'C8':
907             if (axis == 'x') return 161.57; else return 229.61;
908             break;
909         case 'C9':
910             if (axis == 'x') return 113.39; else return 161.57;
911             break;
912         case 'C10':
913             if (axis == 'x') return 79.37; else return 113.39;
914             break;
915         case 'RA0':
916             if (axis == 'x') return 2437.80; else return 3458.27;
917             break;
918         case 'RA1':
919             if (axis == 'x') return 1729.13; else return 2437.80;
920             break;
921         case 'RA2':
922             if (axis == 'x') return 1218.90; else return 1729.13;
923             break;
924         case 'RA3':
925             if (axis == 'x') return 864.57; else return 1218.90;
926             break;
927         case 'RA4':
928             if (axis == 'x') return 609.45; else return 864.57;
929             break;
930         case 'SRA0':
931             if (axis == 'x') return 2551.18; else return 3628.35;
932             break;
933         case 'SRA1':
934             if (axis == 'x') return 1814.17; else return 2551.18;
935             break;
936         case 'SRA2':
937             if (axis == 'x') return 1275.59; else return 1814.17;
938             break;
939         case 'SRA3':
940             if (axis == 'x') return 907.09; else return 1275.59;
941             break;
942         case 'SRA4':
943             if (axis == 'x') return 637.80; else return 907.09;
944             break;
945         case 'LETTER':
946             if (axis == 'x') return 612.00; else return 792.00;
947             break;
948         case 'LEGAL':
949             if (axis == 'x') return 612.00; else return 1008.00;
950             break;
951         case 'EXECUTIVE':
952             if (axis == 'x') return 521.86; else return 756.00;
953             break;
954         case 'FOLIO':
955             if (axis == 'x') return 612.00; else return 936.00;
956             break;
957     } // end switch