var defHelpContent = "<p><strong>Discover Adult Dating at the world's largest adult and swingers sex personals site, SexInTheUK.com! </strong></p><p><SPAN>You can make new friends, find the   hottest adult date, wildest couples and sexiest groups. Whether you are straight   or gay, looking for sexy women or men, you'll find everything you want on   SexInTheUK. Indulge your fantasies and join the hottest adult dating site in the world.</SPAN></p>";

var locationHelp = 'The more information you put here about your location, '+                                                                                
        'the more precise the search will be of members in your area.<br>' +                                                                                 
        '<p style="margin: 10px 0;">Examples:<br>'+                                                                                                          
        '"<span style="font-weight: bold; color: #6C300A;">London Thornton</span>" or<br>'+                                                                  
        '"<span style="font-weight: bold;color: #6C300A;">10 Thornton Place, London</span>"<br>'+                                                            
        ' or just "<span style="font-weight: bold;color: #6C300A;">W1H 1FG</span>"</p>'+                                                                     
        'We don\'t use the postal address to contact members directly!';

var help = {
  screenname: {inputDef: "choose a screenname", content: "<p><b>Enter a screenname that you would like others to know you by.</b></p><p>A screenname should be at least 3 characters long, and not longer than 20.</P><p>You can choose almost anything.  examples include 'kitten', 'BigBoy', and 'look4you', so choose something good.</P>"},  
  frmCountry: {content: "<b>Select the country you live in.</b>"},  
  //location: {inputDef: "town", content: "<b>Select the town or city nearest to you.</b><p>This is shown on-screen and can help others see quickly where you are in the ##COUNTRY##.</P>"},  
  location: {content: locationHelp},  
//  postcode: {inputDef: "postcode", content: "<b>Your Location</b><P>Please let us know your postcode (or the first main part of it)  <P><P>This is NEVER SHOWN TO ANYONE, but is used to calculate and show people near you, in a 10, 25, 50 mile radius of your postcode.</font></P>"},
  sexuality_gender: {content: "<p>Select your matching preference so we can show the most relevant profiles.</p>"},
  "sexuality_": {content: "<b>Orientation</b><P>Select your sexuality</P>"},
  frmDay: {content: "<b>Set you Date of Birth</b><P>This will calculate your age and starsign for you.</P>"},
  frmMonth: {content: "<b>Set you Date of Birth</b><P>This will calculate your age and starsign for you.</P>"},
  frmYear: {content: "<b>Set you Date of Birth</b><P>This will calculate your age and starsign for you.</P>"},
  frmEmail: {inputDef: "your email address", content: "<b>Email Address</b><p>Enter the email address we should mail your password and account details to. This will only be used by us, and will never be shown or given to anyone else.</P><P><font color=RED>Please type this carefully, as without it you will not receive your password and will be unable to access the site</FONT></P>"},
  discount_code: {
    inputDef: "enter your discount code",
    content:  help_discount_code
  }
};

function ShowHelp(element) 
{
  var helpContent = '';
  
  if (element)
  {
    var info = help[element.name];
  
    if (info.inputDef && element.value == info.inputDef) 
    {
      element.value = '';
    }
    
    helpContent = info.content;      
    
    if (element.name == 'location') 
    {
      var sel = regForm.frmCountry;//country select
      
      var countryName   = 'selected country'; 
      try { countryName = sel.options[sel.selectedIndex].text; } catch (e) {};            
  
      helpContent = helpContent.replace(/##COUNTRY##/g, countryName);         
    }
  }
  else 
  {
    helpContent = defHelpContent;
  }
  
  helpDiv.innerHTML = helpContent;
}

function RemoveHelp(element)
{
  var info = help[element.name]; 
  
  if (info.inputDef && !element.value) 
  {
    element.value = info.inputDef;
  }
  
  helpDiv.innerHTML = defHelpContent;
}

/**
  Also init window.helpDiv and window.regForm 
*/
function InitHelp()
{
  window.helpDiv = document.getElementById('help_info');
  window.regForm = document.getElementById('registration_form');

  function createOnFocus(input) 
  {
    return function () { ShowHelp(input); }    
  }
  
  function createOnBlur(input) 
  {
    return function () { RemoveHelp(input); }
  }    

  var input;
  for (var i in help)
  {    
    input = regForm[i];
    
    if (!input.value && input.name != 'location') { input.value = help[i].inputDef; }
    input.onfocus = createOnFocus(input);  
    input.onblur  = createOnBlur(input);  
  } 
}

var popUpFeat = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
var footerPopUpFeat = popUpFeat + ',width=600,height=565';

jQuery(document).ready(function() {                                                                                                 
  InitHelp();
  ShowHelp();
});
