function createHelpTips()
{
  $('div.helpTip').each(function()
  {
    $(this).before('<span class="helpTipReveal">?</span>');
  });
}

function activateHelpTips()
{
  $('span.helpTipReveal').bind(
    'mouseover',function(){
      $('div#'+$(this).next().attr('id')).show();
    }
  ).bind(
    'mouseout',function(){
      $('div#'+$(this).next().attr('id')).hide();
    }
  );
}

function activateInlineValidation( root )
{
  $('form.general input[type=text],form.general input[type=password],form.general select,form.general textarea').bind('blur',
  function()
  {
    var action = $('body').attr('id');
    var field  = $(this).attr('name');
    
    //alert('field:'+field);

      $.post( root+'ajax.php',
      {
        ajax     :  'true',
        panel	 :  'ajax_validation',
        action   :  action,
        field    :  field,
        value    :  $(this).attr('value')
      },
      function( data )
      {
        if ( data=='false' )
        {
          $('input[name="'+field+'"],select[name="'+field+'"],textarea[name="'+field+'"]').parent('li').addClass('warning');
        }
        else
        {
          $('input[name="'+field+'"],select[name="'+field+'"],textarea[name="'+field+'"]').parent('li').removeClass('warning');
          $('input[name="'+field+'"],select[name="'+field+'"],textarea[name="'+field+'"]').nextAll('span[class=warning]').remove();
        }
      });
    
  });
}

function primeAjax( root )
{
  createHelpTips();
  activateHelpTips();
  activateInlineValidation( root );
}

$(document).ready(function()
{
  //var root = deriveRoot();
  
  // Prepare UI Ajax
  primeAjax( '/' );
  
});
