function finishRegistration()
{
  //called when the finish button is pressed
  if (validateStep2())
  {
    jQuery('#registrationForm').submit();
  }
}

function showBusinessFields()
{
  jQuery('#step1').find('.business').each(function(){
    jQuery(this).fadeIn(1)
  })
}
function showNewCity(){
  var ckeckhasaddress = jQuery('#personalAccount_nocity').is(':checked');
  if(ckeckhasaddress){
    jQuery('#cityChooser').hide();
    jQuery('#nocityChooser').show();
  }else{
    jQuery('#cityChooser').show();
    jQuery('#nocityChooser').hide();
  }
}
function initSignUp()
{
  //hide all the pages from the form
  jQuery('#registrationForm').find('.registrationStep').each(function(){
    jQuery(this).fadeOut(1, function(){
      jQuery('#registrationForm').find('#step1').fadeIn(1)
    })
  })
	
  //bind action to show the extra fields for a business account
  jQuery('#personalAccount_UserForm_account_type_enum_id').change(function(){
    if(jQuery('#personalAccount_UserForm_account_type_enum_id').val() == 1)
    {
      //personal account
      jQuery('#personalAccount_BusinessAccountForm_business_name').val('none');
      /*
      jQuery('#step1').find('.business').each(function(){
        jQuery(this).fadeOut(1)
      })
      */
    }
    else
    {
      //business account
      //jQuery('#personalAccount_BusinessAccountForm_business_name').val('');
      //showBusinessFields()
    }
  })
	
  //if the form is already in business, show the business fields
  if(jQuery('#personalAccount_UserForm_account_type_enum_id').val() == 2)
  {
    //showBusinessFields();
  }
  else
  {
    //store a dummy value for business name if it's empty
    if (jQuery('#personalAccount_BusinessAccountForm_business_name').val() == '')
    {
      jQuery('#personalAccount_BusinessAccountForm_business_name').val('none');
    }
  }
  //now we'll bind the enter key to all the input fields
  bindEnterInSignUp();
}

function gotoStep(currentStep)
{
  validateStep(currentStep)
}

function validateStep(currentStep)
{
  if (currentStep == null)
  {
    openForm(1)
  }
  switch(currentStep)
  {
    case 1:
      if (validateStep1())
      {
        openForm(2);
      }
      break;
    case 2:
      if (validateStep2())
      {
        if(jQuery('#personalAccount_UserForm_account_type_enum_id').val() == 2)
        {
          openForm(7)
        }
        else
        {
          openForm(3)
        }
      }
      break;
    case 3:
      openForm(4)
      break;
    case 4:
      openForm(5)
      break;
    case 5:
      openForm(6)
      break;
    case 7:
      openForm(8)
      break;
    case 8:
      openForm(3)
      break;
  }
}

function openForm(step)
{
  jQuery('#registrationForm').find('.registrationStep').each(function(){
    jQuery(this).fadeOut(1, function(){
      jQuery('#registrationForm').find('#step' + step).fadeIn(1)
    })
  })
}

var minusernameCharacters = 5;
var minpasswordCharacters = 6;
//TODO: read this constant from the UserForm class

function isValidEmailAddress(emailAddress)
{
  var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  return pattern.test(emailAddress);
}

var currentUsername = '';

function enableCheckButton()
{
  jQuery('#checkUsernameButton').removeAttr("disabled");
}


