formHelp = {
    'username'    : { name : 'Your Username', text : 'Pick a unique username, make it something easy to remeber as you will need to use it when ever you visit our site.' },
    'password'    : { name : 'Pick a Password', text : 'Make up a secure password. Be sure it isn\'t easy to guess as a lot of your personal details will be kept here..'},
    'passwordb'   : { name : 'Retype your Password', text : 'Just to make sure you typed it correctly.'},
    'email'       : { name : 'Enter your Email address', text : 'Enter your email address. This must be valid as we will send you emails to confirm your booking.'},
    'privPol'     : { name : 'Privacy Policy', text : 'Please read the Privacy Policy. It stipulates how we will use personal details you enter into the web site.'},
    'tosLink'     : { name : 'Terms of Service', text : 'Please read our Terms of Service. If you do not aggree to these terms you should not contiune registration.'}
};

// AJAX for form submition..
function ajaxRegister (form)
{
    // Check the user agreed to the TOS..
    var tick = document.getElementById('tos_check');
    if(!tick.checked)
    { 
        $('#tos_td').css('background-color', '#faa');
        alert('Before you can register you need to read and agree to the Terms of Service and the Privacy Policy');
        return false
    }
    
    return true;
}

$(
  function ()
  {      
      // Init the AJAX to check for the username
      $('#txtUser').change(
          function ()
          {
              $.ajax(
                {
                    url       : '/register',
                    type      : 'POST',
                    data      : { 'username' : $('#txtUser').val(), 'act' : 'checkun'},
                    dataType: 'json',
                    success   : function (msg)
                                {
                                    if (msg.error > 0)
                                    {
                                        alert('Error: ' + msg.msg);
                                    }
                                },
                    error     : function (Req, Msg, E)
                                {
                                }
                }
              );
          }
      );
      
      // Init the hover efects for help Links
      $('.helpLink').hover(
          function ()
          {
              help = formHelp[$(this).attr('name')];
              
              $('#FormHelpTxt').text(help.text);
              $('#FormHelpTitle').text(help.name);
              
              return true;
          },
          function ()
          {              
              $('#FormHelpTitle').text('Form Help');
              $('#FormHelpTxt').text('Highlight an area on the form for specific help.');
          }
      );
      $('.helpMe').focus(
          function (field)
          {
              help = formHelp[$(this).attr('name')];
              
              $('#FormHelpTxt').text(help.text);
              $('#FormHelpTitle').text(help.name);
              
              return true;
          }
      );
      $('.text').focus(
          function (Event)
          {
              $(this).addClass('txtFocus');
          }
      );
      $('input.text').blur(
          function (Event)
          {
              $(this).removeClass('txtFocus');
              
              $('#FormHelpTitle').text('Form Help');
              $('#FormHelpTxt').text('Highlight an area on the form for specific help.');
          }
      );
  }
);
