install/includes/js/formutils.js
changeset 348 87e08a6e4fec
child 439 d9dd2b2134c4
equal deleted inserted replaced
347:299a90e28abc 348:87e08a6e4fec
       
     1 /**
       
     2  * Images used for form field validation
       
     3  * @var string img_bad: Shown on field validation failure
       
     4  * @var string img_good: Shown on field validation success
       
     5  * @var string img_neu: Shown when a field's value matches known good regexp but still needs testing (e.g. DB info)
       
     6  */
       
     7 
       
     8 var img_bad = '../images/bad.gif';
       
     9 var img_good = '../images/good.gif';
       
    10 var img_neu = '../images/unknown.gif';
       
    11 
       
    12 /**
       
    13  * Highlights the background of the next-up <tr> tag.
       
    14  * @param object Form field
       
    15  */
       
    16 
       
    17 function set_focus(item)
       
    18 {
       
    19   var hint_id = ( item.type == 'radio' ) ? 'hint_' + item.name + '_' + item.value : 'hint_' + item.name;
       
    20   if ( document.getElementById(hint_id) )
       
    21   {
       
    22     var el = document.getElementById(hint_id);
       
    23     el.style.zIndex = String(getHighestZ() + 2);
       
    24     domObjChangeOpac(0, el);
       
    25     el.style.display = 'block';
       
    26     domOpacity(el, 0, 100, 400);
       
    27   }
       
    28   item = getParentTR(item);
       
    29   if ( item.tagName == 'TR' )
       
    30   {
       
    31     item.style.backgroundColor = '#FFFFE0';
       
    32   }
       
    33 }
       
    34 
       
    35 /**
       
    36  * Clears the background of the next-up <tr> tag.
       
    37  * @param object Form field
       
    38  */
       
    39 
       
    40 function clear_focus(item)
       
    41 {
       
    42   var hint_id = ( item.type == 'radio' ) ? 'hint_' + item.name + '_' + item.value : 'hint_' + item.name;
       
    43   if ( document.getElementById(hint_id) )
       
    44   {
       
    45     var el = document.getElementById(hint_id);
       
    46     // el.style.display = 'none';
       
    47     domOpacity(el, 100, 0, 200);
       
    48     setTimeout(function()
       
    49       {
       
    50         el.style.display = 'none';
       
    51       }, 250);
       
    52   }
       
    53   item = getParentTR(item);
       
    54   if ( item.tagName == 'TR' )
       
    55   {
       
    56     if ( IE )
       
    57     {
       
    58       item.style.backgroundColor = 'transparent';
       
    59     }
       
    60     else
       
    61     {
       
    62       item.style.backgroundColor = null;
       
    63     }
       
    64   }
       
    65 }
       
    66 
       
    67 function getParentTR(item)
       
    68 {
       
    69   var tagName = item.tagName;
       
    70   while ( tagName != 'TR' && tagName != null )
       
    71   {
       
    72     item = item.parentNode;
       
    73     tagName = item.tagName;
       
    74   }
       
    75   if ( tagName == 'TR' && item.className != 'nohighlight' )
       
    76   {
       
    77     return item;
       
    78   }
       
    79   return null;
       
    80 }
       
    81 
       
    82 function init_hint(input, hint)
       
    83 {
       
    84   hint.className = 'fieldtip_js';
       
    85   setTimeout(function()
       
    86     {
       
    87       if ( input.type == 'radio' )
       
    88       {
       
    89         var tr = getParentTR(input).parentNode.parentNode.parentNode;
       
    90         var span_width = $(tr).Width() - 24;
       
    91       }
       
    92       else
       
    93       {
       
    94         var span_width = $(input).Width() - 24;
       
    95       }
       
    96       var span_top = $(input).Top() + $(input).Height();
       
    97       var span_left = $(input).Left();
       
    98       hint.style.top = span_top + 'px';
       
    99       hint.style.left = span_left + 'px';
       
   100       hint.style.width = span_width + 'px';
       
   101       hint.style.display = 'none';
       
   102     }, 100);
       
   103 }
       
   104 
       
   105 var set_inputs_to_highlight = function()
       
   106 {
       
   107   var inputs = document.getElementsByTagName('input');
       
   108   for ( var i = 0; i < inputs.length; i++ )
       
   109   {
       
   110     // Highlighting
       
   111     var tr = getParentTR(inputs[i]);
       
   112     if ( tr )
       
   113     {
       
   114       inputs[i].onfocus = function()
       
   115       {
       
   116         set_focus(this);
       
   117       }
       
   118       inputs[i].onblur = function()
       
   119       {
       
   120         clear_focus(this);
       
   121       }
       
   122     }
       
   123     // Hints
       
   124     var hint_id = ( inputs[i].type == 'radio' ) ? 'hint_' + inputs[i].name + '_' + inputs[i].value : 'hint_' + inputs[i].name;
       
   125     if ( document.getElementById(hint_id) )
       
   126     {
       
   127       var el = document.getElementById(hint_id);
       
   128       if ( el.tagName == 'SPAN' )
       
   129       {
       
   130         init_hint(inputs[i], el);
       
   131       }
       
   132     }
       
   133   }
       
   134 }
       
   135 
       
   136 addOnloadHook(set_inputs_to_highlight);
       
   137 
       
   138 function install_set_ajax_loading()
       
   139 {
       
   140   var base = document.getElementById('enano-body');
       
   141   var hider = document.createElement('div');
       
   142   hider.style.position = 'absolute';
       
   143   hider.style.backgroundColor = '#FFFFFF';
       
   144   hider.style.top = $(base).Top() + 'px';
       
   145   hider.style.left = $(base).Left() + 'px';
       
   146   hider.style.width = $(base).Width() + 'px';
       
   147   hider.style.height = $(base).Height() + 'px';
       
   148   hider.style.backgroundPosition = 'center center';
       
   149   hider.style.backgroundImage = 'url(../images/loading-big.gif)';
       
   150   hider.style.backgroundRepeat = 'no-repeat';
       
   151   hider.id = 'ajax_loader';
       
   152   domObjChangeOpac(0, hider);
       
   153   var body = document.getElementsByTagName('body')[0];
       
   154   body.appendChild(hider);
       
   155   opacity('ajax_loader', 0, 70, 750);
       
   156 }
       
   157 
       
   158 function install_unset_ajax_loading()
       
   159 {
       
   160   if ( document.getElementById('ajax_loader') )
       
   161   {
       
   162     opacity('ajax_loader', 70, 0, 750);
       
   163     setTimeout(function()
       
   164       {
       
   165         var body = document.getElementsByTagName('body')[0];
       
   166         body.removeChild(document.getElementById('ajax_loader'));
       
   167       }, 1000);
       
   168   }
       
   169 }