3.3.9.1 release
[phpmyadmin/madhuracj.git] / js / functions.js
blob697c344be6da40178796f0584108b27c9a7bf3d3
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * general function, usally for data manipulation pages
4  *
5  * @version $Id$
6  */
8 /**
9  * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow
10  */
11 var sql_box_locked = false;
13 /**
14  * @var array holds elements which content should only selected once
15  */
16 var only_once_elements = new Array();
18 /**
19  * selects the content of a given object, f.e. a textarea
20  *
21  * @param   object  element     element of which the content will be selected
22  * @param   var     lock        variable which holds the lock for this element
23  *                              or true, if no lock exists
24  * @param   boolean only_once   if true this is only done once
25  *                              f.e. only on first focus
26  */
27 function selectContent( element, lock, only_once ) {
28     if ( only_once && only_once_elements[element.name] ) {
29         return;
30     }
32     only_once_elements[element.name] = true;
34     if ( lock  ) {
35         return;
36     }
38     element.select();
41 /**
42  * Displays an confirmation box before to submit a "DROP DATABASE" query.
43  * This function is called while clicking links
44  *
45  * @param   object   the link
46  * @param   object   the sql query to submit
47  *
48  * @return  boolean  whether to run the query or not
49  */
50 function confirmLinkDropDB(theLink, theSqlQuery)
52     // Confirmation is not required in the configuration file
53     // or browser is Opera (crappy js implementation)
54     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
55         return true;
56     }
58     var is_confirmed = confirm(PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
59     if (is_confirmed) {
60         theLink.href += '&is_js_confirmed=1';
61     }
63     return is_confirmed;
64 } // end of the 'confirmLinkDropDB()' function
66 /**
67  * Displays an confirmation box before to submit a "DROP/DELETE/ALTER" query.
68  * This function is called while clicking links
69  *
70  * @param   object   the link
71  * @param   object   the sql query to submit
72  *
73  * @return  boolean  whether to run the query or not
74  */
75 function confirmLink(theLink, theSqlQuery)
77     // Confirmation is not required in the configuration file
78     // or browser is Opera (crappy js implementation)
79     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
80         return true;
81     }
83     var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
84     if (is_confirmed) {
85         if ( typeof(theLink.href) != 'undefined' ) {
86             theLink.href += '&is_js_confirmed=1';
87         } else if ( typeof(theLink.form) != 'undefined' ) {
88             theLink.form.action += '?is_js_confirmed=1';
89         }
90     }
92     return is_confirmed;
93 } // end of the 'confirmLink()' function
96 /**
97  * Displays an confirmation box before doing some action
98  *
99  * @param   object   the message to display
101  * @return  boolean  whether to run the query or not
102  */
103 function confirmAction(theMessage)
105     // TODO: Confirmation is not required in the configuration file
106     // or browser is Opera (crappy js implementation)
107     if (typeof(window.opera) != 'undefined') {
108         return true;
109     }
111     var is_confirmed = confirm(theMessage);
113     return is_confirmed;
114 } // end of the 'confirmAction()' function
118  * Displays an error message if a "DROP DATABASE" statement is submitted
119  * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
120  * sumitting it if required.
121  * This function is called by the 'checkSqlQuery()' js function.
123  * @param   object   the form
124  * @param   object   the sql query textarea
126  * @return  boolean  whether to run the query or not
128  * @see     checkSqlQuery()
129  */
130 function confirmQuery(theForm1, sqlQuery1)
132     // Confirmation is not required in the configuration file
133     if (PMA_messages['strDoYouReally'] == '') {
134         return true;
135     }
137     // The replace function (js1.2) isn't supported
138     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
139         return true;
140     }
142     // js1.2+ -> validation with regular expressions
143     else {
144         // "DROP DATABASE" statement isn't allowed
145         if (PMA_messages['strNoDropDatabases'] != '') {
146             var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
147             if (drop_re.test(sqlQuery1.value)) {
148                 alert(PMA_messages['strNoDropDatabases']);
149                 theForm1.reset();
150                 sqlQuery1.focus();
151                 return false;
152             } // end if
153         } // end if
155         // Confirms a "DROP/DELETE/ALTER/TRUNCATE" statement
156         //
157         // TODO: find a way (if possible) to use the parser-analyser
158         // for this kind of verification
159         // For now, I just added a ^ to check for the statement at
160         // beginning of expression
162         var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i');
163         var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
164         var do_confirm_re_2 = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
165         var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
167         if (do_confirm_re_0.test(sqlQuery1.value)
168             || do_confirm_re_1.test(sqlQuery1.value)
169             || do_confirm_re_2.test(sqlQuery1.value)
170             || do_confirm_re_3.test(sqlQuery1.value)) {
171             var message      = (sqlQuery1.value.length > 100)
172                              ? sqlQuery1.value.substr(0, 100) + '\n    ...'
173                              : sqlQuery1.value;
174             var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
175             // statement is confirmed -> update the
176             // "is_js_confirmed" form field so the confirm test won't be
177             // run on the server side and allows to submit the form
178             if (is_confirmed) {
179                 theForm1.elements['is_js_confirmed'].value = 1;
180                 return true;
181             }
182             // statement is rejected -> do not submit the form
183             else {
184                 window.focus();
185                 sqlQuery1.focus();
186                 return false;
187             } // end if (handle confirm box result)
188         } // end if (display confirm box)
189     } // end confirmation stuff
191     return true;
192 } // end of the 'confirmQuery()' function
196  * Displays a confirmation box before disabling the BLOB repository for a given database.
197  * This function is called while clicking links
199  * @param   object   the database 
201  * @return  boolean  whether to disable the repository or not
202  */
203 function confirmDisableRepository(theDB)
205     // Confirmation is not required in the configuration file
206     // or browser is Opera (crappy js implementation)
207     if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
208         return true;
209     }
211     var is_confirmed = confirm(PMA_messages['strBLOBRepositoryDisableStrongWarning'] + '\n' + PMA_messages['strBLOBRepositoryDisableAreYouSure']);
213     return is_confirmed;
214 } // end of the 'confirmDisableBLOBRepository()' function
218  * Displays an error message if the user submitted the sql query form with no
219  * sql query, else checks for "DROP/DELETE/ALTER" statements
221  * @param   object   the form
223  * @return  boolean  always false
225  * @see     confirmQuery()
226  */
227 function checkSqlQuery(theForm)
229     var sqlQuery = theForm.elements['sql_query'];
230     var isEmpty  = 1;
232     // The replace function (js1.2) isn't supported -> basic tests
233     if (typeof(sqlQuery.value.replace) == 'undefined') {
234         isEmpty      = (sqlQuery.value == '') ? 1 : 0;
235         if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
236             isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
237         }
238         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
239             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
240         }
241         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
242             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
243         }
244     }
245     // js1.2+ -> validation with regular expressions
246     else {
247         var space_re = new RegExp('\\s+');
248         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
249                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
250             return true;
251         }
252         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
253                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
254             return true;
255         }
256         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
257                 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
258                 theForm.elements['id_bookmark'].selectedIndex != 0
259                 ) {
260             return true;
261         }
262         // Checks for "DROP/DELETE/ALTER" statements
263         if (sqlQuery.value.replace(space_re, '') != '') {
264             if (confirmQuery(theForm, sqlQuery)) {
265                 return true;
266             } else {
267                 return false;
268             }
269         }
270         theForm.reset();
271         isEmpty = 1;
272     }
274     if (isEmpty) {
275         sqlQuery.select();
276         alert(PMA_messages['strFormEmpty']);
277         sqlQuery.focus();
278         return false;
279     }
281     return true;
282 } // end of the 'checkSqlQuery()' function
284 // Global variable row_class is set to even
285 var row_class = 'even';
287 /** 
288 * Generates a row dynamically in the differences table displaying
289 * the complete statistics of difference in  table like number of 
290 * rows to be updated, number of rows to be inserted, number of 
291 * columns to be added, number of columns to be removed, etc.
293 * @param  index         index of matching table
294 * @param  update_size   number of rows/column to be updated
295 * @param  insert_size   number of rows/coulmns to be inserted
296 * @param  remove_size   number of columns to be removed
297 * @param  insert_index  number of indexes to be inserted
298 * @param  remove_index  number of indexes to be removed
299 * @param  img_obj       image object 
300 * @param  table_name    name of the table
303 function showDetails(i, update_size, insert_size, remove_size, insert_index, remove_index, img_obj, table_name)
304 {   
305     // The path of the image is split to facilitate comparison
306     var relative_path = (img_obj.src).split("themes/"); 
307     
308     // The image source is changed when the showDetails function is called.
309     if (relative_path[1] == 'original/img/new_data_hovered.jpg') {    
310         img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";
311         img_obj.alt = PMA_messages['strClickToUnselect'];  //only for IE browser
312     } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
313         img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";
314         img_obj.alt = PMA_messages['strClickToUnselect'];
315     } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {
316         img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
317         img_obj.alt = PMA_messages['strClickToSelect'];
318     } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {    
319         img_obj.src = "./themes/original/img/new_data_hovered.jpg";
320         img_obj.alt = PMA_messages['strClickToSelect'];
321     } 
322     
323     var div = document.getElementById("list");    
324     var table = div.getElementsByTagName("table")[0]; 
325     var table_body = table.getElementsByTagName("tbody")[0];
326     
327     //Global variable row_class is being used
328     if (row_class == 'even') {
329         row_class = 'odd';
330     } else {
331         row_class = 'even'; 
332     }
333     // If the red or green button against a table name is pressed then append a new row to show the details of differences of this table. 
334     if ((relative_path[1] != 'original/img/new_struct_selected_hovered.jpg') && (relative_path[1] != 'original/img/new_data_selected_hovered.jpg')) { 
335         
336         var newRow = document.createElement("tr");    
337         newRow.setAttribute("class", row_class);
338         newRow.className = row_class; 
339         // Id assigned to this row element is same as the index of this table name in the  matching_tables/source_tables_uncommon array  
340         newRow.setAttribute("id" , i);
341             
342         var table_name_cell = document.createElement("td");
343         table_name_cell.align = "center";
344         table_name_cell.innerHTML = table_name ;
345         
346         newRow.appendChild(table_name_cell);
347        
348         var create_table = document.createElement("td");
349         create_table.align = "center";
350            
351         var add_cols = document.createElement("td");
352         add_cols.align = "center";
353         
354         var remove_cols = document.createElement("td");
355         remove_cols.align = "center";
356         
357         var alter_cols = document.createElement("td");
358         alter_cols.align = "center";
359         
360         var add_index = document.createElement("td");
361         add_index.align = "center";
362         
363         var delete_index = document.createElement("td");
364         delete_index.align = "center";
365         
366         var update_rows = document.createElement("td");
367         update_rows.align = "center";
368         
369         var insert_rows = document.createElement("td");
370         insert_rows.align = "center";
371         
372         var tick_image = document.createElement("img");
373         tick_image.src = "./themes/original/img/s_success.png"; 
375         if (update_size == '' && insert_size == '' && remove_size == '') {
376           /**
377           This is the case when the table needs to be created in target database. 
378           */
379             create_table.appendChild(tick_image);
380             add_cols.innerHTML = "--";
381             remove_cols.innerHTML = "--";         
382             alter_cols.innerHTML = "--";
383             delete_index.innerHTML = "--";
384             add_index.innerHTML = "--";
385             update_rows.innerHTML = "--";
386             insert_rows.innerHTML = "--";
388             newRow.appendChild(create_table);
389             newRow.appendChild(add_cols);
390             newRow.appendChild(remove_cols);
391             newRow.appendChild(alter_cols);
392             newRow.appendChild(delete_index);
393             newRow.appendChild(add_index);
394             newRow.appendChild(update_rows);
395             newRow.appendChild(insert_rows);
396             
397         } else if (update_size == '' && remove_size == '') {
398            /**
399            This is the case when data difference is displayed in the 
400            table which is present in source but absent from target database 
401           */
402             create_table.innerHTML = "--";
403             add_cols.innerHTML = "--";
404             remove_cols.innerHTML = "--";         
405             alter_cols.innerHTML = "--";
406             add_index.innerHTML = "--";
407             delete_index.innerHTML = "--";
408             update_rows.innerHTML = "--";
409             insert_rows.innerHTML = insert_size;
410             
411             newRow.appendChild(create_table);
412             newRow.appendChild(add_cols);
413             newRow.appendChild(remove_cols);
414             newRow.appendChild(alter_cols);
415             newRow.appendChild(delete_index); 
416             newRow.appendChild(add_index);
417             newRow.appendChild(update_rows);
418             newRow.appendChild(insert_rows);
419             
420         } else if (remove_size == '') {
421             /**
422              This is the case when data difference between matching_tables is displayed. 
423             */
424             create_table.innerHTML = "--";
425             add_cols.innerHTML = "--";
426             remove_cols.innerHTML = "--";         
427             alter_cols.innerHTML = "--";
428             add_index.innerHTML = "--";
429             delete_index.innerHTML = "--";
430             update_rows.innerHTML = update_size;
431             insert_rows.innerHTML = insert_size;
432             
433             newRow.appendChild(create_table);
434             newRow.appendChild(add_cols);
435             newRow.appendChild(remove_cols);
436             newRow.appendChild(alter_cols);
437             newRow.appendChild(delete_index);
438             newRow.appendChild(add_index);
439             newRow.appendChild(update_rows);
440             newRow.appendChild(insert_rows);
441             
442         } else {
443             /**
444             This is the case when structure difference between matching_tables id displayed
445             */
446             create_table.innerHTML = "--";
447             add_cols.innerHTML = insert_size;
448             remove_cols.innerHTML = remove_size;         
449             alter_cols.innerHTML = update_size;
450             delete_index.innerHTML = remove_index;
451             add_index.innerHTML = insert_index;
452             update_rows.innerHTML = "--";
453             insert_rows.innerHTML = "--";
454            
455             newRow.appendChild(create_table);
456             newRow.appendChild(add_cols);
457             newRow.appendChild(remove_cols);
458             newRow.appendChild(alter_cols); 
459             newRow.appendChild(delete_index);
460             newRow.appendChild(add_index);
461             newRow.appendChild(update_rows);
462             newRow.appendChild(insert_rows);
463         }
464         table_body.appendChild(newRow);
465       
466     } else if ((relative_path[1] != 'original/img/new_struct_hovered.jpg') && (relative_path[1] != 'original/img/new_data_hovered.jpg')) {
467       //The case when the row showing the details need to be removed from the table i.e. the difference button is deselected now.
468         var table_rows = table_body.getElementsByTagName("tr");
469         var j;
470         var index; 
471         for (j=0; j < table_rows.length; j++) 
472         {   
473             if (table_rows[j].id == i) { 
474                 index = j;
475                 table_rows[j].parentNode.removeChild(table_rows[j]);     
476             }
477         }
478         //The table row css is being adjusted. Class "odd" for odd rows and "even" for even rows should be maintained.
479         for(index; index < table_rows.length; index++)
480         {
481             row_class_element = table_rows[index].getAttribute('class');
482             if (row_class_element == "even") {
483                 table_rows[index].setAttribute("class","odd");  // for Mozilla firefox
484                 table_rows[index].className = "odd";            // for IE browser
485             } else {
486                 table_rows[index].setAttribute("class","even"); // for Mozilla firefox  
487                 table_rows[index].className = "even";           // for IE browser       
488             }
489         }    
490     }     
494  * Changes the image on hover effects
496  * @param   img_obj   the image object whose source needs to be changed
498  */
500 function change_Image(img_obj)
502      var relative_path = (img_obj.src).split("themes/"); 
503     
504     if (relative_path[1] == 'original/img/new_data.jpg') {    
505         img_obj.src = "./themes/original/img/new_data_hovered.jpg";  
506     } else if (relative_path[1] == 'original/img/new_struct.jpg') {
507         img_obj.src = "./themes/original/img/new_struct_hovered.jpg";
508     } else if (relative_path[1] == 'original/img/new_struct_hovered.jpg') {
509         img_obj.src = "./themes/original/img/new_struct.jpg";
510     } else if (relative_path[1] == 'original/img/new_data_hovered.jpg') {    
511         img_obj.src = "./themes/original/img/new_data.jpg";  
512     } else if (relative_path[1] == 'original/img/new_data_selected.jpg') {    
513         img_obj.src = "./themes/original/img/new_data_selected_hovered.jpg";  
514     } else if(relative_path[1] == 'original/img/new_struct_selected.jpg') {    
515         img_obj.src = "./themes/original/img/new_struct_selected_hovered.jpg";  
516     } else if (relative_path[1] == 'original/img/new_struct_selected_hovered.jpg') {    
517         img_obj.src = "./themes/original/img/new_struct_selected.jpg";  
518     } else if (relative_path[1] == 'original/img/new_data_selected_hovered.jpg') {    
519         img_obj.src = "./themes/original/img/new_data_selected.jpg";  
520     }
524  * Generates the URL containing the list of selected table ids for synchronization and 
525  * a variable checked for confirmation of deleting previous rows from target tables 
527  * @param   token   the token generated for each PMA form 
529  */
531 function ApplySelectedChanges(token)
533     var div =  document.getElementById("list");
534     var table = div.getElementsByTagName('table')[0];
535     var table_body = table.getElementsByTagName('tbody')[0];
536     // Get all the rows from the details table
537     var table_rows = table_body.getElementsByTagName('tr');
538     var x = table_rows.length;
539     var i;
540     /**
541      Append the token at the beginning of the query string followed by  
542     Table_ids that shows that "Apply Selected Changes" button is pressed            
543     */
544     var append_string = "?token="+token+"&Table_ids="+1;
545     for(i=0; i<x; i++){
546            append_string += "&";    
547            append_string += i+"="+table_rows[i].id; 
548     }
549     
550     // Getting the value of checkbox delete_rows
551     var checkbox = document.getElementById("delete_rows");
552     if (checkbox.checked){
553         append_string += "&checked=true";
554     } else {
555          append_string += "&checked=false";
556     }
557     //Appending the token and list of table ids in the URL 
558     location.href += token;
559     location.href += append_string;
562 /** 
563 * Displays error message if any text field 
564 * is left empty other than port field.
566 * @param  string   the form name
567 * @param  object   the form
569 * @return  boolean  whether the form field is empty or not
571 function validateConnection(form_name, form_obj)
572 {   
573     var check = true;
574     var src_hostfilled = true;
575     var trg_hostfilled = true;
577     for (var i=1; i<form_name.elements.length; i++)
578     {
579         // All the text fields are checked excluding the port field because the default port can be used.
580         if ((form_name.elements[i].type == 'text') && (form_name.elements[i].name != 'src_port') && (form_name.elements[i].name != 'trg_port')) {
581             check = true;
582             check = emptyFormElements(form_obj, form_name.elements[i].name);
584             if (check==false) {
585               element = form_name.elements[i].name;
586               if (form_name.elements[i].name == 'src_host') {
587                 src_hostfilled = false;
588                 continue;
589               }
590               if (form_name.elements[i].name == 'trg_host') {
591                 trg_hostfilled = false;
592                 continue;
593               }
594               if ((form_name.elements[i].name == 'src_socket' && src_hostfilled==false) || (form_name.elements[i].name == 'trg_socket' && trg_hostfilled==false))
595                 break;
596               else
597                 continue;
598               break;
599             }
600         } 
601     }
602     if (!check) {
603         form_obj.reset();
604         element.select();
605         alert(PMA_messages['strFormEmpty']);
606         element.focus();
607     }
608     return check;
610     
612  * Check if a form's element is empty
613  * should be
615  * @param   object   the form
616  * @param   string   the name of the form field to put the focus on
618  * @return  boolean  whether the form field is empty or not
619  */
620 function emptyCheckTheField(theForm, theFieldName)
622     var isEmpty  = 1;
623     var theField = theForm.elements[theFieldName];
624     // Whether the replace function (js1.2) is supported or not
625     var isRegExp = (typeof(theField.value.replace) != 'undefined');
627     if (!isRegExp) {
628         isEmpty      = (theField.value == '') ? 1 : 0;
629     } else {
630         var space_re = new RegExp('\\s+');
631         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
632     }
634     return isEmpty;
635 } // end of the 'emptyCheckTheField()' function
640  * @param   object   the form
641  * @param   string   the name of the form field to put the focus on
643  * @return  boolean  whether the form field is empty or not
644  */
645 function emptyFormElements(theForm, theFieldName)
647     var theField = theForm.elements[theFieldName];
648     var isEmpty = emptyCheckTheField(theForm, theFieldName);
651     return isEmpty;
652 } // end of the 'emptyFormElements()' function
656  * Ensures a value submitted in a form is numeric and is in a range
658  * @param   object   the form
659  * @param   string   the name of the form field to check
660  * @param   integer  the minimum authorized value
661  * @param   integer  the maximum authorized value
663  * @return  boolean  whether a valid number has been submitted or not
664  */
665 function checkFormElementInRange(theForm, theFieldName, message, min, max)
667     var theField         = theForm.elements[theFieldName];
668     var val              = parseInt(theField.value);
670     if (typeof(min) == 'undefined') {
671         min = 0;
672     }
673     if (typeof(max) == 'undefined') {
674         max = Number.MAX_VALUE;
675     }
677     // It's not a number
678     if (isNaN(val)) {
679         theField.select();
680         alert(PMA_messages['strNotNumber']);
681         theField.focus();
682         return false;
683     }
684     // It's a number but it is not between min and max
685     else if (val < min || val > max) {
686         theField.select();
687         alert(message.replace('%d', val));
688         theField.focus();
689         return false;
690     }
691     // It's a valid number
692     else {
693         theField.value = val;
694     }
695     return true;
697 } // end of the 'checkFormElementInRange()' function
700 function checkTableEditForm(theForm, fieldsCnt)
702     // TODO: avoid sending a message if user just wants to add a line
703     // on the form but has not completed at least one field name
705     var atLeastOneField = 0;
706     var i, elm, elm2, elm3, val, id;
708     for (i=0; i<fieldsCnt; i++)
709     {
710         id = "field_" + i + "_2";
711         elm = getElement(id);
712         if (elm.value == 'VARCHAR' || elm.value == 'CHAR' || elm.value == 'BIT' || elm.value == 'VARBINARY' || elm.value == 'BINARY') {
713             elm2 = getElement("field_" + i + "_3");
714             val = parseInt(elm2.value);
715             elm3 = getElement("field_" + i + "_1");
716             if (isNaN(val) && elm3.value != "") {
717                 elm2.select();
718                 alert(PMA_messages['strNotNumber']);
719                 elm2.focus();
720                 return false;
721             }
722         }
724         if (atLeastOneField == 0) {
725             id = "field_" + i + "_1";
726             if (!emptyCheckTheField(theForm, id)) {
727                 atLeastOneField = 1;
728             }
729         }
730     }
731     if (atLeastOneField == 0) {
732         var theField = theForm.elements["field_0_1"];
733         alert(PMA_messages['strFormEmpty']);
734         theField.focus();
735         return false;
736     }
738     return true;
739 } // enf of the 'checkTableEditForm()' function
743  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
744  * checkboxes is consistant
746  * @param   object   the form
747  * @param   string   a code for the action that causes this function to be run
749  * @return  boolean  always true
750  */
751 function checkTransmitDump(theForm, theAction)
753     var formElts = theForm.elements;
755     // 'zipped' option has been checked
756     if (theAction == 'zip' && formElts['zip'].checked) {
757         if (!formElts['asfile'].checked) {
758             theForm.elements['asfile'].checked = true;
759         }
760         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
761             theForm.elements['gzip'].checked = false;
762         }
763         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
764             theForm.elements['bzip'].checked = false;
765         }
766     }
767     // 'gzipped' option has been checked
768     else if (theAction == 'gzip' && formElts['gzip'].checked) {
769         if (!formElts['asfile'].checked) {
770             theForm.elements['asfile'].checked = true;
771         }
772         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
773             theForm.elements['zip'].checked = false;
774         }
775         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
776             theForm.elements['bzip'].checked = false;
777         }
778     }
779     // 'bzipped' option has been checked
780     else if (theAction == 'bzip' && formElts['bzip'].checked) {
781         if (!formElts['asfile'].checked) {
782             theForm.elements['asfile'].checked = true;
783         }
784         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
785             theForm.elements['zip'].checked = false;
786         }
787         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
788             theForm.elements['gzip'].checked = false;
789         }
790     }
791     // 'transmit' option has been unchecked
792     else if (theAction == 'transmit' && !formElts['asfile'].checked) {
793         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
794             theForm.elements['zip'].checked = false;
795         }
796         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
797             theForm.elements['gzip'].checked = false;
798         }
799         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
800             theForm.elements['bzip'].checked = false;
801         }
802     }
804     return true;
805 } // end of the 'checkTransmitDump()' function
809  * This array is used to remember mark status of rows in browse mode
810  */
811 var marked_row = new Array;
814  * enables highlight and marking of rows in data tables
816  */
817 function PMA_markRowsInit() {
818     // for every table row ...
819     var rows = document.getElementsByTagName('tr');
820     for ( var i = 0; i < rows.length; i++ ) {
821         // ... with the class 'odd' or 'even' ...
822         if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
823             continue;
824         }
825         // ... add event listeners ...
826         // ... to highlight the row on mouseover ...
827         if ( navigator.appName == 'Microsoft Internet Explorer' ) {
828             // but only for IE, other browsers are handled by :hover in css
829             rows[i].onmouseover = function() {
830                 this.className += ' hover';
831             }
832             rows[i].onmouseout = function() {
833                 this.className = this.className.replace( ' hover', '' );
834             }
835         }
836         // Do not set click events if not wanted
837         if (rows[i].className.search(/noclick/) != -1) {
838             continue;
839         }
840         // ... and to mark the row on click ...
841         rows[i].onmousedown = function(event) {
842             var unique_id;
843             var checkbox;
844             var table;
846             // Somehow IE8 has this not set
847             if (!event) var event = window.event
848                         
849             checkbox = this.getElementsByTagName( 'input' )[0];
850             if ( checkbox && checkbox.type == 'checkbox' ) {
851                 unique_id = checkbox.name + checkbox.value;
852             } else if ( this.id.length > 0 ) {
853                 unique_id = this.id;
854             } else {
855                 return;
856             }
858             if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
859                 marked_row[unique_id] = true;
860             } else {
861                 marked_row[unique_id] = false;
862             }
864             if ( marked_row[unique_id] ) {
865                 this.className += ' marked';
866             } else {
867                 this.className = this.className.replace(' marked', '');
868             }
870             if ( checkbox && checkbox.disabled == false ) {
871                 checkbox.checked = marked_row[unique_id];
872                 if (typeof(event) == 'object') {
873                     table = this.parentNode;
874                     i = 0;
875                     while (table.tagName.toLowerCase() != 'table' && i < 20) {
876                         i++;
877                         table = table.parentNode;
878                     }
880                     if (event.shiftKey == true && table.lastClicked != undefined) {
881                         if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }
882                         i = table.lastClicked;
884                         if (i < this.rowIndex) {
885                             i++;
886                         } else {
887                             i--;
888                         }
890                         while (i != this.rowIndex) {
891                             table.rows[i].onmousedown();
892                             if (i < this.rowIndex) {
893                                 i++;
894                             } else {
895                                 i--;
896                             }
897                         }
898                     }
900                     table.lastClicked = this.rowIndex;
901                 }
902             }
903         }
905         // ... and disable label ...
906         var labeltag = rows[i].getElementsByTagName('label')[0];
907         if ( labeltag ) {
908             labeltag.onclick = function() {
909                 return false;
910             }
911         }
912         // .. and checkbox clicks
913         var checkbox = rows[i].getElementsByTagName('input')[0];
914         if ( checkbox ) {
915             checkbox.onclick = function() {
916                 // opera does not recognize return false;
917                 this.checked = ! this.checked;
918             }
919         }
920     }
922 window.onload=PMA_markRowsInit;
925  * marks all rows and selects its first checkbox inside the given element
926  * the given element is usaly a table or a div containing the table or tables
928  * @param    container    DOM element
929  */
930 function markAllRows( container_id ) {
931     var rows = document.getElementById(container_id).getElementsByTagName('tr');
932     var unique_id;
933     var checkbox;
935     for ( var i = 0; i < rows.length; i++ ) {
937         checkbox = rows[i].getElementsByTagName( 'input' )[0];
939         if ( checkbox && checkbox.type == 'checkbox' ) {
940             unique_id = checkbox.name + checkbox.value;
941             if ( checkbox.disabled == false ) {
942                 checkbox.checked = true;
943                 if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
944                     rows[i].className += ' marked';
945                     marked_row[unique_id] = true;
946                 }
947             }
948         }
949     }
951     return true;
955  * marks all rows and selects its first checkbox inside the given element
956  * the given element is usaly a table or a div containing the table or tables
958  * @param    container    DOM element
959  */
960 function unMarkAllRows( container_id ) {
961     var rows = document.getElementById(container_id).getElementsByTagName('tr');
962     var unique_id;
963     var checkbox;
965     for ( var i = 0; i < rows.length; i++ ) {
967         checkbox = rows[i].getElementsByTagName( 'input' )[0];
969         if ( checkbox && checkbox.type == 'checkbox' ) {
970             unique_id = checkbox.name + checkbox.value;
971             checkbox.checked = false;
972             rows[i].className = rows[i].className.replace(' marked', '');
973             marked_row[unique_id] = false;
974         }
975     }
977     return true;
981  * Sets/unsets the pointer and marker in browse mode
983  * @param   object    the table row
984  * @param   integer  the row number
985  * @param   string    the action calling this script (over, out or click)
986  * @param   string    the default background color
987  * @param   string    the color to use for mouseover
988  * @param   string    the color to use for marking a row
990  * @return  boolean  whether pointer is set or not
991  */
992 function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
994     var theCells = null;
996     // 1. Pointer and mark feature are disabled or the browser can't get the
997     //    row -> exits
998     if ((thePointerColor == '' && theMarkColor == '')
999         || typeof(theRow.style) == 'undefined') {
1000         return false;
1001     }
1003     // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise.
1004     if (theAction == "over" || theAction == "click") {
1005         theRow.style.cursor='pointer';
1006     } else {
1007         theRow.style.cursor='default';
1008     }
1010     // 2. Gets the current row and exits if the browser can't get it
1011     if (typeof(document.getElementsByTagName) != 'undefined') {
1012         theCells = theRow.getElementsByTagName('td');
1013     }
1014     else if (typeof(theRow.cells) != 'undefined') {
1015         theCells = theRow.cells;
1016     }
1017     else {
1018         return false;
1019     }
1021     // 3. Gets the current color...
1022     var rowCellsCnt  = theCells.length;
1023     var domDetect    = null;
1024     var currentColor = null;
1025     var newColor     = null;
1026     // 3.1 ... with DOM compatible browsers except Opera that does not return
1027     //         valid values with "getAttribute"
1028     if (typeof(window.opera) == 'undefined'
1029         && typeof(theCells[0].getAttribute) != 'undefined') {
1030         currentColor = theCells[0].getAttribute('bgcolor');
1031         domDetect    = true;
1032     }
1033     // 3.2 ... with other browsers
1034     else {
1035         currentColor = theCells[0].style.backgroundColor;
1036         domDetect    = false;
1037     } // end 3
1039     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
1040     if (currentColor.indexOf("rgb") >= 0)
1041     {
1042         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
1043                                      currentColor.indexOf(')'));
1044         var rgbValues = rgbStr.split(",");
1045         currentColor = "#";
1046         var hexChars = "0123456789ABCDEF";
1047         for (var i = 0; i < 3; i++)
1048         {
1049             var v = rgbValues[i].valueOf();
1050             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
1051         }
1052     }
1054     // 4. Defines the new color
1055     // 4.1 Current color is the default one
1056     if (currentColor == ''
1057         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
1058         if (theAction == 'over' && thePointerColor != '') {
1059             newColor              = thePointerColor;
1060         }
1061         else if (theAction == 'click' && theMarkColor != '') {
1062             newColor              = theMarkColor;
1063             marked_row[theRowNum] = true;
1064             // Garvin: deactivated onclick marking of the checkbox because it's also executed
1065             // when an action (like edit/delete) on a single item is performed. Then the checkbox
1066             // would get deactived, even though we need it activated. Maybe there is a way
1067             // to detect if the row was clicked, and not an item therein...
1068             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
1069         }
1070     }
1071     // 4.1.2 Current color is the pointer one
1072     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
1073              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
1074         if (theAction == 'out') {
1075             newColor              = theDefaultColor;
1076         }
1077         else if (theAction == 'click' && theMarkColor != '') {
1078             newColor              = theMarkColor;
1079             marked_row[theRowNum] = true;
1080             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
1081         }
1082     }
1083     // 4.1.3 Current color is the marker one
1084     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
1085         if (theAction == 'click') {
1086             newColor              = (thePointerColor != '')
1087                                   ? thePointerColor
1088                                   : theDefaultColor;
1089             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
1090                                   ? true
1091                                   : null;
1092             // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
1093         }
1094     } // end 4
1096     // 5. Sets the new color...
1097     if (newColor) {
1098         var c = null;
1099         // 5.1 ... with DOM compatible browsers except Opera
1100         if (domDetect) {
1101             for (c = 0; c < rowCellsCnt; c++) {
1102                 theCells[c].setAttribute('bgcolor', newColor, 0);
1103             } // end for
1104         }
1105         // 5.2 ... with other browsers
1106         else {
1107             for (c = 0; c < rowCellsCnt; c++) {
1108                 theCells[c].style.backgroundColor = newColor;
1109             }
1110         }
1111     } // end 5
1113     return true;
1114 } // end of the 'setPointer()' function
1117  * Sets/unsets the pointer and marker in vertical browse mode
1119  * @param   object    the table row
1120  * @param   integer   the column number
1121  * @param   string    the action calling this script (over, out or click)
1122  * @param   string    the default background Class
1123  * @param   string    the Class to use for mouseover
1124  * @param   string    the Class to use for marking a row
1126  * @return  boolean  whether pointer is set or not
1128  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
1129  */
1130 function setVerticalPointer(theRow, theColNum, theAction, theDefaultClass1, theDefaultClass2, thePointerClass, theMarkClass) {
1131     // 1. Pointer and mark feature are disabled or the browser can't get the
1132     //    row -> exits
1133     if ((thePointerClass == '' && theMarkClass == '')
1134         || typeof(theRow.style) == 'undefined') {
1135         return false;
1136     }
1138     var tagSwitch = null;
1140     // 2. Gets the current row and exits if the browser can't get it
1141     if (typeof(document.getElementsByTagName) != 'undefined') {
1142         tagSwitch = 'tag';
1143     } else if (typeof(document.getElementById('table_results')) != 'undefined') {
1144         tagSwitch = 'cells';
1145     } else {
1146         return false;
1147     }
1149     var theCells = null;
1151     if (tagSwitch == 'tag') {
1152         theRows     = document.getElementById('table_results').getElementsByTagName('tr');
1153         theCells    = theRows[1].getElementsByTagName('td');
1154     } else if (tagSwitch == 'cells') {
1155         theRows     = document.getElementById('table_results').rows;
1156         theCells    = theRows[1].cells;
1157     }
1159     // 3. Gets the current Class...
1160     var currentClass   = null;
1161     var newClass       = null;
1163     // 3.1 ... with DOM compatible browsers except Opera that does not return
1164     //         valid values with "getAttribute"
1165     if (typeof(window.opera) == 'undefined'
1166         && typeof(theCells[theColNum].getAttribute) != 'undefined') {
1167         currentClass = theCells[theColNum].className;
1168     } // end 3
1170     // 4. Defines the new Class
1171     // 4.1 Current Class is the default one
1172     if (currentClass == ''
1173         || currentClass.toLowerCase() == theDefaultClass1.toLowerCase()
1174         || currentClass.toLowerCase() == theDefaultClass2.toLowerCase()) {
1175         if (theAction == 'over' && thePointerClass != '') {
1176             newClass              = thePointerClass;
1177         } else if (theAction == 'click' && theMarkClass != '') {
1178             newClass              = theMarkClass;
1179             marked_row[theColNum] = true;
1180         }
1181     }
1182     // 4.1.2 Current Class is the pointer one
1183     else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() &&
1184              (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
1185             if (theAction == 'out') {
1186                 if (theColNum % 2) {
1187                     newClass              = theDefaultClass1;
1188                 } else {
1189                     newClass              = theDefaultClass2;
1190                 }
1191             }
1192             else if (theAction == 'click' && theMarkClass != '') {
1193                 newClass              = theMarkClass;
1194                 marked_row[theColNum] = true;
1195             }
1196     }
1197     // 4.1.3 Current Class is the marker one
1198     else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) {
1199         if (theAction == 'click') {
1200             newClass              = (thePointerClass != '')
1201                                   ? thePointerClass
1202                                   : ((theColNum % 2) ? theDefaultClass2 : theDefaultClass1);
1203             marked_row[theColNum] = false;
1204         }
1205     } // end 4
1207     // 5 ... with DOM compatible browsers except Opera
1209     if (newClass) {
1210         var c = null;
1211         var rowCnt = theRows.length;
1212         for (c = 0; c < rowCnt; c++) {
1213             if (tagSwitch == 'tag') {
1214                 Cells = theRows[c].getElementsByTagName('td');
1215             } else if (tagSwitch == 'cells') {
1216                 Cells = theRows[c].cells;
1217             }
1219             Cell  = Cells[theColNum];
1221             // 5.1 Sets the new Class...
1222             Cell.className = Cell.className.replace(currentClass, newClass);
1223         } // end for
1224     } // end 5
1226      return true;
1227  } // end of the 'setVerticalPointer()' function
1230  * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div)
1232  * @param   string   container_id  the container id
1233  * @param   boolean  state         new value for checkbox (true or false)
1234  * @return  boolean  always true
1235  */
1236 function setCheckboxes( container_id, state ) {
1237     var checkboxes = document.getElementById(container_id).getElementsByTagName('input');
1239     for ( var i = 0; i < checkboxes.length; i++ ) {
1240         if ( checkboxes[i].type == 'checkbox' ) {
1241             checkboxes[i].checked = state;
1242         }
1243     }
1245     return true;
1246 } // end of the 'setCheckboxes()' function
1249 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
1250 //   copy the checked from left to right or from right to left
1251 //   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
1252 function copyCheckboxesRange(the_form, the_name, the_clicked)
1254     if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
1255         if (the_clicked !== 'r') {
1256             if (document.forms[the_form].elements[the_name].checked == true) {
1257                 document.forms[the_form].elements[the_name + 'r'].checked = true;
1258             }else {
1259                 document.forms[the_form].elements[the_name + 'r'].checked = false;
1260             }
1261         } else if (the_clicked == 'r') {
1262             if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
1263                 document.forms[the_form].elements[the_name].checked = true;
1264             }else {
1265                 document.forms[the_form].elements[the_name].checked = false;
1266             }
1267        }
1268     }
1272 // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
1273 //  - this was directly written to each td, so why not a function ;)
1274 //  setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\');
1275 function setCheckboxColumn(theCheckbox){
1276     if (document.getElementById(theCheckbox)) {
1277         document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
1278         if (document.getElementById(theCheckbox + 'r')) {
1279             document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
1280         }
1281     } else {
1282         if (document.getElementById(theCheckbox + 'r')) {
1283             document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
1284             if (document.getElementById(theCheckbox)) {
1285                 document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
1286             }
1287         }
1288     }
1293   * Checks/unchecks all options of a <select> element
1294   *
1295   * @param   string   the form name
1296   * @param   string   the element name
1297   * @param   boolean  whether to check or to uncheck the element
1298   *
1299   * @return  boolean  always true
1300   */
1301 function setSelectOptions(the_form, the_select, do_check)
1303     var selectObject = document.forms[the_form].elements[the_select];
1304     var selectCount  = selectObject.length;
1306     for (var i = 0; i < selectCount; i++) {
1307         selectObject.options[i].selected = do_check;
1308     } // end for
1310     return true;
1311 } // end of the 'setSelectOptions()' function
1314   * Inserts multiple fields.
1315   *
1316   */
1317 function insertValueQuery() {
1318     var myQuery = document.sqlform.sql_query;
1319     var myListBox = document.sqlform.dummy;
1321     if(myListBox.options.length > 0) {
1322         sql_box_locked = true;
1323         var chaineAj = "";
1324         var NbSelect = 0;
1325         for(var i=0; i<myListBox.options.length; i++) {
1326             if (myListBox.options[i].selected){
1327                 NbSelect++;
1328                 if (NbSelect > 1)
1329                     chaineAj += ", ";
1330                 chaineAj += myListBox.options[i].value;
1331             }
1332         }
1334         //IE support
1335         if (document.selection) {
1336             myQuery.focus();
1337             sel = document.selection.createRange();
1338             sel.text = chaineAj;
1339             document.sqlform.insert.focus();
1340         }
1341         //MOZILLA/NETSCAPE support
1342         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
1343             var startPos = document.sqlform.sql_query.selectionStart;
1344             var endPos = document.sqlform.sql_query.selectionEnd;
1345             var chaineSql = document.sqlform.sql_query.value;
1347             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
1348         } else {
1349             myQuery.value += chaineAj;
1350         }
1351         sql_box_locked = false;
1352     }
1356   * listbox redirection
1357   */
1358 function goToUrl(selObj, goToLocation) {
1359     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
1363  * getElement
1364  */
1365 function getElement(e,f){
1366     if(document.layers){
1367         f=(f)?f:self;
1368         if(f.document.layers[e]) {
1369             return f.document.layers[e];
1370         }
1371         for(W=0;W<f.document.layers.length;W++) {
1372             return(getElement(e,f.document.layers[W]));
1373         }
1374     }
1375     if(document.all) {
1376         return document.all[e];
1377     }
1378     return document.getElementById(e);
1382   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
1383   */
1384 function refreshDragOption(e) {
1385     myid = getElement(e);
1386     if (myid.style.visibility == 'visible') {
1387         refreshLayout();
1388         TableDragInit();
1389     }
1393   * Refresh/resize the WYSIWYG-PDF scratchboard
1394   */
1395 function refreshLayout() {
1396         myid = getElement('pdflayout');
1398         if (document.pdfoptions.orientation.value == 'P') {
1399             posa = 'x';
1400             posb = 'y';
1401         } else {
1402             posa = 'y';
1403             posb = 'x';
1404         }
1406         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
1407         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
1411   * Show/hide the WYSIWYG-PDF scratchboard
1412   */
1413 function ToggleDragDrop(e) {
1414     myid = getElement(e);
1416     if (myid.style.visibility == 'hidden') {
1417         init();
1418         myid.style.visibility = 'visible';
1419         myid.style.display = 'block';
1420         document.edcoord.showwysiwyg.value = '1';
1421     } else {
1422         myid.style.visibility = 'hidden';
1423         myid.style.display = 'none';
1424         document.edcoord.showwysiwyg.value = '0';
1425     }
1429   * PDF scratchboard: When a position is entered manually, update
1430   * the fields inside the scratchboard.
1431   */
1432 function dragPlace(no, axis, value) {
1433     if (axis == 'x') {
1434         getElement("table_" + no).style.left = value + 'px';
1435     } else {
1436         getElement("table_" + no).style.top  = value + 'px';
1437     }
1441  * Returns paper sizes for a given format
1442  */
1443 function pdfPaperSize(format, axis) {
1444     switch (format.toUpperCase()) {
1445         case '4A0':
1446             if (axis == 'x') return 4767.87; else return 6740.79;
1447             break;
1448         case '2A0':
1449             if (axis == 'x') return 3370.39; else return 4767.87;
1450             break;
1451         case 'A0':
1452             if (axis == 'x') return 2383.94; else return 3370.39;
1453             break;
1454         case 'A1':
1455             if (axis == 'x') return 1683.78; else return 2383.94;
1456             break;
1457         case 'A2':
1458             if (axis == 'x') return 1190.55; else return 1683.78;
1459             break;
1460         case 'A3':
1461             if (axis == 'x') return 841.89; else return 1190.55;
1462             break;
1463         case 'A4':
1464             if (axis == 'x') return 595.28; else return 841.89;
1465             break;
1466         case 'A5':
1467             if (axis == 'x') return 419.53; else return 595.28;
1468             break;
1469         case 'A6':
1470             if (axis == 'x') return 297.64; else return 419.53;
1471             break;
1472         case 'A7':
1473             if (axis == 'x') return 209.76; else return 297.64;
1474             break;
1475         case 'A8':
1476             if (axis == 'x') return 147.40; else return 209.76;
1477             break;
1478         case 'A9':
1479             if (axis == 'x') return 104.88; else return 147.40;
1480             break;
1481         case 'A10':
1482             if (axis == 'x') return 73.70; else return 104.88;
1483             break;
1484         case 'B0':
1485             if (axis == 'x') return 2834.65; else return 4008.19;
1486             break;
1487         case 'B1':
1488             if (axis == 'x') return 2004.09; else return 2834.65;
1489             break;
1490         case 'B2':
1491             if (axis == 'x') return 1417.32; else return 2004.09;
1492             break;
1493         case 'B3':
1494             if (axis == 'x') return 1000.63; else return 1417.32;
1495             break;
1496         case 'B4':
1497             if (axis == 'x') return 708.66; else return 1000.63;
1498             break;
1499         case 'B5':
1500             if (axis == 'x') return 498.90; else return 708.66;
1501             break;
1502         case 'B6':
1503             if (axis == 'x') return 354.33; else return 498.90;
1504             break;
1505         case 'B7':
1506             if (axis == 'x') return 249.45; else return 354.33;
1507             break;
1508         case 'B8':
1509             if (axis == 'x') return 175.75; else return 249.45;
1510             break;
1511         case 'B9':
1512             if (axis == 'x') return 124.72; else return 175.75;
1513             break;
1514         case 'B10':
1515             if (axis == 'x') return 87.87; else return 124.72;
1516             break;
1517         case 'C0':
1518             if (axis == 'x') return 2599.37; else return 3676.54;
1519             break;
1520         case 'C1':
1521             if (axis == 'x') return 1836.85; else return 2599.37;
1522             break;
1523         case 'C2':
1524             if (axis == 'x') return 1298.27; else return 1836.85;
1525             break;
1526         case 'C3':
1527             if (axis == 'x') return 918.43; else return 1298.27;
1528             break;
1529         case 'C4':
1530             if (axis == 'x') return 649.13; else return 918.43;
1531             break;
1532         case 'C5':
1533             if (axis == 'x') return 459.21; else return 649.13;
1534             break;
1535         case 'C6':
1536             if (axis == 'x') return 323.15; else return 459.21;
1537             break;
1538         case 'C7':
1539             if (axis == 'x') return 229.61; else return 323.15;
1540             break;
1541         case 'C8':
1542             if (axis == 'x') return 161.57; else return 229.61;
1543             break;
1544         case 'C9':
1545             if (axis == 'x') return 113.39; else return 161.57;
1546             break;
1547         case 'C10':
1548             if (axis == 'x') return 79.37; else return 113.39;
1549             break;
1550         case 'RA0':
1551             if (axis == 'x') return 2437.80; else return 3458.27;
1552             break;
1553         case 'RA1':
1554             if (axis == 'x') return 1729.13; else return 2437.80;
1555             break;
1556         case 'RA2':
1557             if (axis == 'x') return 1218.90; else return 1729.13;
1558             break;
1559         case 'RA3':
1560             if (axis == 'x') return 864.57; else return 1218.90;
1561             break;
1562         case 'RA4':
1563             if (axis == 'x') return 609.45; else return 864.57;
1564             break;
1565         case 'SRA0':
1566             if (axis == 'x') return 2551.18; else return 3628.35;
1567             break;
1568         case 'SRA1':
1569             if (axis == 'x') return 1814.17; else return 2551.18;
1570             break;
1571         case 'SRA2':
1572             if (axis == 'x') return 1275.59; else return 1814.17;
1573             break;
1574         case 'SRA3':
1575             if (axis == 'x') return 907.09; else return 1275.59;
1576             break;
1577         case 'SRA4':
1578             if (axis == 'x') return 637.80; else return 907.09;
1579             break;
1580         case 'LETTER':
1581             if (axis == 'x') return 612.00; else return 792.00;
1582             break;
1583         case 'LEGAL':
1584             if (axis == 'x') return 612.00; else return 1008.00;
1585             break;
1586         case 'EXECUTIVE':
1587             if (axis == 'x') return 521.86; else return 756.00;
1588             break;
1589         case 'FOLIO':
1590             if (axis == 'x') return 612.00; else return 936.00;
1591             break;
1592     } // end switch
1594     return 0;
1598  * rajk - for playing media from the BLOB repository
1600  * @param   var     
1601  * @param   var     url_params  main purpose is to pass the token 
1602  * @param   var     bs_ref      BLOB repository reference
1603  * @param   var     m_type      type of BLOB repository media
1604  * @param   var     w_width     width of popup window
1605  * @param   var     w_height    height of popup window
1606  */
1607 function popupBSMedia(url_params, bs_ref, m_type, is_cust_type, w_width, w_height)
1609     // if width not specified, use default
1610     if (w_width == undefined)
1611         w_width = 640;
1613     // if height not specified, use default
1614     if (w_height == undefined)
1615         w_height = 480;
1617     // open popup window (for displaying video/playing audio)
1618     var mediaWin = window.open('bs_play_media.php?' + url_params + '&bs_reference=' + bs_ref + '&media_type=' + m_type + '&custom_type=' + is_cust_type, 'viewBSMedia', 'width=' + w_width + ', height=' + w_height + ', resizable=1, scrollbars=1, status=0');
1622  * rajk - popups a request for changing MIME types for files in the BLOB repository
1624  * @param   var     db                      database name
1625  * @param   var     table                   table name
1626  * @param   var     reference               BLOB repository reference
1627  * @param   var     current_mime_type       current MIME type associated with BLOB repository reference
1628  */
1629 function requestMIMETypeChange(db, table, reference, current_mime_type)
1631     // no mime type specified, set to default (nothing)
1632     if (undefined == current_mime_type)
1633         current_mime_type == "";
1635     // prompt user for new mime type
1636     var new_mime_type = prompt("Enter custom MIME type", current_mime_type);
1638     // if new mime_type is specified and is not the same as the previous type, request for mime type change
1639     if (new_mime_type && new_mime_type != current_mime_type)
1640         changeMIMEType(db, table, reference, new_mime_type);
1644  * rajk - changes MIME types for files in the BLOB repository
1646  * @param   var     db              database name
1647  * @param   var     table           table name
1648  * @param   var     reference       BLOB repository reference
1649  * @param   var     mime_type       new MIME type to be associated with BLOB repository reference
1650  */
1651 function changeMIMEType(db, table, reference, mime_type)
1653     // specify url and parameters for mootools AJAx request
1654     var mime_chg_url = 'bs_change_mime_type.php';
1655     var params = { bs_db: db, bs_table: table, bs_reference: reference, bs_new_mime_type: mime_type };
1657     // create AJAX object with above options and execute request
1658     var chgRequest = new Request({ method: 'post', url: mime_chg_url, data: params, evalScripts: true });
1659     chgRequest.send();