lang
[phpmyadmin/crack.git] / libraries / functions.js
blob1add857186c3e932995696d7312a082a9e8e5885
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     // 4. Defines the new color
402     // 4.1 Current color is the default one
403     if (currentColor == ''
404         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
405         if (theAction == 'over' && thePointerColor != '') {
406             newColor              = thePointerColor;
407         }
408         else if (theAction == 'click' && theMarkColor != '') {
409             newColor              = theMarkColor;
410             marked_row[theRowNum] = true;
411         }
412     }
413     // 4.1.2 Current color is the pointer one
414     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
415              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
416         if (theAction == 'out') {
417             newColor              = theDefaultColor;
418         }
419         else if (theAction == 'click' && theMarkColor != '') {
420             newColor              = theMarkColor;
421             marked_row[theRowNum] = true;
422         }
423     }
424     // 4.1.3 Current color is the marker one
425     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
426         if (theAction == 'click') {
427             newColor              = (thePointerColor != '')
428                                   ? thePointerColor
429                                   : theDefaultColor;
430             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
431                                   ? true
432                                   : null;
433         }
434     } // end 4
436     // 5. Sets the new color...
437     if (newColor) {
438         var c = null;
439         // 5.1 ... with DOM compatible browsers except Opera
440         if (domDetect) {
441             for (c = 0; c < rowCellsCnt; c++) {
442                 theCells[c].setAttribute('bgcolor', newColor, 0);
443             } // end for
444         }
445         // 5.2 ... with other browsers
446         else {
447             for (c = 0; c < rowCellsCnt; c++) {
448                 theCells[c].style.backgroundColor = newColor;
449             }
450         }
451     } // end 5
453     return true;
454 } // end of the 'setPointer()' function
457  * Sets/unsets the pointer and marker in vertical browse mode
459  * @param   object    the table row
460  * @param   interger  the row number
461  * @param   string    the action calling this script (over, out or click)
462  * @param   string    the default background color
463  * @param   string    the color to use for mouseover
464  * @param   string    the color to use for marking a row
466  * @return  boolean  whether pointer is set or not
468  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
469  */
470 function setVerticalPointer(theRow, theRowNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
471     var theCells = null;
473     // 1. Pointer and mark feature are disabled or the browser can't get the
474     //    row -> exits
475     if ((thePointerColor == '' && theMarkColor == '')
476         || typeof(theRow.style) == 'undefined') {
477         return false;
478     }
480     // 2. Gets the current row and exits if the browser can't get it
481     if (typeof(document.getElementsByTagName) != 'undefined') {
482         theCells = theRow.getElementsByTagName('td');
483     }
484     else if (typeof(theRow.cells) != 'undefined') {
485         theCells = theRow.cells;
486     }
487     else {
488         return false;
489     }
491     // 3. Gets the current color...
492     var rowCellsCnt  = theCells.length;
493     var domDetect    = null;
494     var currentColor = null;
495     var newColor     = null;
497     // 3.1 ... with DOM compatible browsers except Opera that does not return
498     //         valid values with "getAttribute"
499     if (typeof(window.opera) == 'undefined'
500         && typeof(theCells[0].getAttribute) != 'undefined') {
501         currentColor = theCells[0].getAttribute('bgcolor');
502         domDetect    = true;
503     }
504     // 3.2 ... with other browsers
505     else {
506         domDetect    = false;
507     } // end 3
509     var c = null;
510     // 5.1 ... with DOM compatible browsers except Opera
511     for (c = 0; c < rowCellsCnt; c++) {
512         if (domDetect) {
513             currentColor = theCells[c].getAttribute('bgcolor');
514         } else {
515             currentColor = theCells[c].style.backgroundColor;
516         }
518         // 4. Defines the new color
519         // 4.1 Current color is the default one
520         if (currentColor == ''
521             || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
522             || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
523             if (theAction == 'over' && thePointerColor != '') {
524                 newColor              = thePointerColor;
525             } else if (theAction == 'click' && theMarkColor != '') {
526                 newColor              = theMarkColor;
527                 marked_row[theRowNum] = true;
528             }
529         }
530         // 4.1.2 Current color is the pointer one
531         else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
532                  && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
533             if (theAction == 'out') {
534                 if (c % 2) {
535                     newColor              = theDefaultColor1;
536                 } else {
537                     newColor              = theDefaultColor2;
538                 }
539             }
540             else if (theAction == 'click' && theMarkColor != '') {
541                 newColor              = theMarkColor;
542                 marked_row[theRowNum] = true;
543             }
544         }
545         // 4.1.3 Current color is the marker one
546         else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
547             if (theAction == 'click') {
548                 newColor              = (thePointerColor != '')
549                                       ? thePointerColor
550                                       : ((c % 2) ? theDefaultColor1 : theDefaultColor2);
551                 marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
552                                       ? true
553                                       : null;
554             }
555         } // end 4
557         // 5. Sets the new color...
558         if (newColor) {
559             if (domDetect) {
560                 theCells[c].setAttribute('bgcolor', newColor, 0);
561             }
562             // 5.2 ... with other browsers
563             else {
564                 theCells[c].style.backgroundColor = newColor;
565             }
566         } // end 5
567     } // end for
569      return true;
570  } // end of the 'setVerticalPointer()' function
573  * Checks/unchecks all tables
575  * @param   string   the form name
576  * @param   boolean  whether to check or to uncheck the element
578  * @return  boolean  always true
579  */
580 function setCheckboxes(the_form, do_check)
582     var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
583                   ? document.forms[the_form].elements['selected_db[]']
584                   : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
585           ? document.forms[the_form].elements['selected_tbl[]']
586           : document.forms[the_form].elements['selected_fld[]'];
587     var elts_cnt  = (typeof(elts.length) != 'undefined')
588                   ? elts.length
589                   : 0;
591     if (elts_cnt) {
592         for (var i = 0; i < elts_cnt; i++) {
593             elts[i].checked = do_check;
594         } // end for
595     } else {
596         elts.checked        = do_check;
597     } // end if... else
599     return true;
600 } // end of the 'setCheckboxes()' function
604   * Checks/unchecks all options of a <select> element
605   *
606   * @param   string   the form name
607   * @param   string   the element name
608   * @param   boolean  whether to check or to uncheck the element
609   *
610   * @return  boolean  always true
611   */
612 function setSelectOptions(the_form, the_select, do_check)
614     var selectObject = document.forms[the_form].elements[the_select];
615     var selectCount  = selectObject.length;
617     for (var i = 0; i < selectCount; i++) {
618         selectObject.options[i].selected = do_check;
619     } // end for
621     return true;
622 } // end of the 'setSelectOptions()' function
625   * Allows moving around inputs/select by Ctrl+arrows
626   *
627   * @param   object   event data
628   */
629 function onKeyDownArrowsHandler(e) {
630     e = e||window.event;
631     var o = (e.srcElement||e.target);
632     if (!o) return;
633     if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
634     if (!e.ctrlKey) return;
635     if (!o.id) return;
637     var pos = o.id.split("_");
638     if (pos[0] != "field" || typeof pos[2] == "undefined") return;
640     var x = pos[2], y=pos[1];
642     // skip non existent fields
643     for (i=0; i<10; i++)
644     {
645         switch(e.keyCode) {
646             case 38: y--; break; // up
647             case 40: y++; break; // down
648             case 37: x--; break; // left
649             case 39: x++; break; // right
650             default: return;
651         }
653         var id = "field_" + y + "_" + x;
654         var nO = document.getElementById(id);
655         if (nO) break;
656     }
658     if (!nO) return;
659     nO.focus();
660     if (nO.tagName != 'SELECT') {
661         nO.select();
662     }
663     e.returnValue = false;
667   * Inserts multiple fields.
668   *
669   */
670 function insertValueQuery() {
671     var myQuery = document.sqlform.sql_query;
672     var myListBox = document.sqlform.dummy;
674     if(myListBox.options.length > 0) {
675         var chaineAj = "";
676         var NbSelect = 0;
677         for(var i=0; i<myListBox.options.length; i++) {
678             if (myListBox.options[i].selected){
679                 NbSelect++;
680                 if (NbSelect > 1)
681                     chaineAj += ", ";
682                 chaineAj += myListBox.options[i].value;
683             }
684         }
686         //IE support
687         if (document.selection) {
688             myQuery.focus();
689             sel = document.selection.createRange();
690             sel.text = chaineAj;
691             document.sqlform.insert.focus();
692         }
693         //MOZILLA/NETSCAPE support
694         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
695             var startPos = document.sqlform.sql_query.selectionStart;
696             var endPos = document.sqlform.sql_query.selectionEnd;
697             var chaineSql = document.sqlform.sql_query.value;
699             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
700         } else {
701             myQuery.value += chaineAj;
702         }
703     }
707   * listbox redirection
708   */
709 function goToUrl(selObj, goToLocation){
710     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
714  * getElement
715  */
716 function getElement(e,f){
717     if(document.layers){
718         f=(f)?f:self;
719         if(f.document.layers[e]) {
720             return f.document.layers[e];
721         }
722         for(W=0;i<f.document.layers.length;W++) {
723             return(getElement(e,fdocument.layers[W]));
724         }
725     }
726     if(document.all) {
727         return document.all[e];
728     }
729     return document.getElementById(e);
733   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
734   */
735 function refreshDragOption(e) {
736     myid = getElement(e);
737     if (myid.style.visibility == 'visible') {
738         refreshLayout();
739     }
743   * Refresh/resize the WYSIWYG-PDF scratchboard
744   */
745 function refreshLayout() {
746         myid = getElement('pdflayout');
748         if (document.pdfoptions.orientation.value == 'P') {
749             posa = 'x';
750             posb = 'y';
751         } else {
752             posa = 'y';
753             posb = 'x';
754         }
756         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
757         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
761   * Show/hide the WYSIWYG-PDF scratchboard
762   */
763 function ToggleDragDrop(e) {
764     myid = getElement(e);
766     if (myid.style.visibility == 'hidden') {
767         init();
768         myid.style.visibility = 'visible';
769         myid.style.display = 'block';
770         document.edcoord.showwysiwyg.value = '1';
771     } else {
772         myid.style.visibility = 'hidden';
773         myid.style.display = 'none';
774         document.edcoord.showwysiwyg.value = '0';
775     }
779   * PDF scratchboard: When a position is entered manually, update
780   * the fields inside the scratchboard.
781   */
782 function dragPlace(no, axis, value) {
783     if (axis == 'x') {
784         getElement("table_" + no).style.left = value + 'px';
785     } else {
786         getElement("table_" + no).style.top  = value + 'px';
787     }
791   * Returns paper sizes for a given format
792   */
793 function pdfPaperSize(format, axis) {
794     switch (format) {
795         case '4A0':
796             if (axis == 'x') return 4767.87; else return 6740.79;
797             break;
798         case '2A0':
799             if (axis == 'x') return 3370.39; else return 4767.87;
800             break;
801         case 'A0':
802             if (axis == 'x') return 2383.94; else return 3370.39;
803             break;
804         case 'A1':
805             if (axis == 'x') return 1683.78; else return 2383.94;
806             break;
807         case 'A2':
808             if (axis == 'x') return 1190.55; else return 1683.78;
809             break;
810         case 'A3':
811             if (axis == 'x') return 841.89; else return 1190.55;
812             break;
813         case 'A4':
814             if (axis == 'x') return 595.28; else return 841.89;
815             break;
816         case 'A5':
817             if (axis == 'x') return 419.53; else return 595.28;
818             break;
819         case 'A6':
820             if (axis == 'x') return 297.64; else return 419.53;
821             break;
822         case 'A7':
823             if (axis == 'x') return 209.76; else return 297.64;
824             break;
825         case 'A8':
826             if (axis == 'x') return 147.40; else return 209.76;
827             break;
828         case 'A9':
829             if (axis == 'x') return 104.88; else return 147.40;
830             break;
831         case 'A10':
832             if (axis == 'x') return 73.70; else return 104.88;
833             break;
834         case 'B0':
835             if (axis == 'x') return 2834.65; else return 4008.19;
836             break;
837         case 'B1':
838             if (axis == 'x') return 2004.09; else return 2834.65;
839             break;
840         case 'B2':
841             if (axis == 'x') return 1417.32; else return 2004.09;
842             break;
843         case 'B3':
844             if (axis == 'x') return 1000.63; else return 1417.32;
845             break;
846         case 'B4':
847             if (axis == 'x') return 708.66; else return 1000.63;
848             break;
849         case 'B5':
850             if (axis == 'x') return 498.90; else return 708.66;
851             break;
852         case 'B6':
853             if (axis == 'x') return 354.33; else return 498.90;
854             break;
855         case 'B7':
856             if (axis == 'x') return 249.45; else return 354.33;
857             break;
858         case 'B8':
859             if (axis == 'x') return 175.75; else return 249.45;
860             break;
861         case 'B9':
862             if (axis == 'x') return 124.72; else return 175.75;
863             break;
864         case 'B10':
865             if (axis == 'x') return 87.87; else return 124.72;
866             break;
867         case 'C0':
868             if (axis == 'x') return 2599.37; else return 3676.54;
869             break;
870         case 'C1':
871             if (axis == 'x') return 1836.85; else return 2599.37;
872             break;
873         case 'C2':
874             if (axis == 'x') return 1298.27; else return 1836.85;
875             break;
876         case 'C3':
877             if (axis == 'x') return 918.43; else return 1298.27;
878             break;
879         case 'C4':
880             if (axis == 'x') return 649.13; else return 918.43;
881             break;
882         case 'C5':
883             if (axis == 'x') return 459.21; else return 649.13;
884             break;
885         case 'C6':
886             if (axis == 'x') return 323.15; else return 459.21;
887             break;
888         case 'C7':
889             if (axis == 'x') return 229.61; else return 323.15;
890             break;
891         case 'C8':
892             if (axis == 'x') return 161.57; else return 229.61;
893             break;
894         case 'C9':
895             if (axis == 'x') return 113.39; else return 161.57;
896             break;
897         case 'C10':
898             if (axis == 'x') return 79.37; else return 113.39;
899             break;
900         case 'RA0':
901             if (axis == 'x') return 2437.80; else return 3458.27;
902             break;
903         case 'RA1':
904             if (axis == 'x') return 1729.13; else return 2437.80;
905             break;
906         case 'RA2':
907             if (axis == 'x') return 1218.90; else return 1729.13;
908             break;
909         case 'RA3':
910             if (axis == 'x') return 864.57; else return 1218.90;
911             break;
912         case 'RA4':
913             if (axis == 'x') return 609.45; else return 864.57;
914             break;
915         case 'SRA0':
916             if (axis == 'x') return 2551.18; else return 3628.35;
917             break;
918         case 'SRA1':
919             if (axis == 'x') return 1814.17; else return 2551.18;
920             break;
921         case 'SRA2':
922             if (axis == 'x') return 1275.59; else return 1814.17;
923             break;
924         case 'SRA3':
925             if (axis == 'x') return 907.09; else return 1275.59;
926             break;
927         case 'SRA4':
928             if (axis == 'x') return 637.80; else return 907.09;
929             break;
930         case 'LETTER':
931             if (axis == 'x') return 612.00; else return 792.00;
932             break;
933         case 'LEGAL':
934             if (axis == 'x') return 612.00; else return 1008.00;
935             break;
936         case 'EXECUTIVE':
937             if (axis == 'x') return 521.86; else return 756.00;
938             break;
939         case 'FOLIO':
940             if (axis == 'x') return 612.00; else return 936.00;
941             break;
942     } // end switch