Modularize frontPayment() function in front_payment.php script to allow use with...
[openemr.git] / phpmyadmin / js / indexes.js
blob8caed6bdd5356881ba311aaeea0e944f51873ae9
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used for index manipulation pages
4  *
5  * @version $Id$
6  */
8 /**
9  * Ensures a value submitted in a form is numeric and is in a range
10  *
11  * @param   object   the form
12  * @param   string   the name of the form field to check
13  * @param   integer  the minimum authorized value
14  * @param   integer  the maximum authorized value
15  *
16  * @return  boolean  whether a valid number has been submitted or not
17  */
18 function checkFormElementInRange(theForm, theFieldName, message, min, max)
20     var theField         = theForm.elements[theFieldName];
21     var val              = parseInt(theField.value);
23     if (typeof(min) == 'undefined') {
24         min = 0;
25     }
26     if (typeof(max) == 'undefined') {
27         max = Number.MAX_VALUE;
28     }
30     // It's not a number
31     if (isNaN(val)) {
32         theField.select();
33         alert(errorMsg1);
34         theField.focus();
35         return false;
36     }
37     // It's a number but it is not between min and max
38     else if (val < min || val > max) {
39         theField.select();
40         alert(message.replace('%d', val));
41         theField.focus();
42         return false;
43     }
44     // It's a valid number
45     else {
46         theField.value = val;
47     }
49     return true;
50 } // end of the 'checkFormElementInRange()' function
53 /**
54  * Ensures indexes names are valid according to their type and, for a primary
55  * key, lock index name to 'PRIMARY'
56  *
57  * @return  boolean  false if there is no index form, true else
58  */
59 function checkIndexName()
61     if (typeof(document.forms['index_frm']) == 'undefined') {
62         return false;
63     }
65     // Gets the elements pointers
66     var the_idx_name = document.forms['index_frm'].elements['index'];
67     var the_idx_type = document.forms['index_frm'].elements['index_type'];
69     // Index is a primary key
70     if (the_idx_type.options[0].value == 'PRIMARY' && the_idx_type.options[0].selected) {
71         document.forms['index_frm'].elements['index'].value = 'PRIMARY';
72         if (typeof(the_idx_name.disabled) != 'undefined') {
73             document.forms['index_frm'].elements['index'].disabled = true;
74         }
75     }
77     // Other cases
78     else {
79         if (the_idx_name.value == 'PRIMARY') {
80             document.forms['index_frm'].elements['index'].value = '';
81         }
82         if (typeof(the_idx_name.disabled) != 'undefined') {
83             document.forms['index_frm'].elements['index'].disabled = false;
84         }
85     }
87     return true;
88 } // end of the 'checkIndexName()' function
91 onload = checkIndexName;