
$(document).ready(function () {
  /*
  $('#indexPlayerLoading').show();
   $.ajax({
    type: 'POST',
    data: 'id=0',
    cache: false,
    url: 'ajax/ajax.indexPlayer.php',
    success: function (html) {
      $('#indexPlayerLoading').fadeOut();
      $('#DOM_Control_PreviewPlayer').html(html);
    }
  });
  
  $('#genres li a').click(function () {
    $('#DOM_Control_PreviewPlayer').empty();
    $('#indexPlayerLoading').show();
    $('#genres li a').each(function () {
      $(this).removeClass('active');
    });
    $(this).addClass('active');
    var genreID = '';
    $(this).attr('id', function () {
      genreID = this.id;
      $.ajax({
        type: 'POST',
        data: 'id=' + genreID,
        cache: false,
        url: 'ajax/ajax.indexPlayer.php',
        success: function (html) {
          $('#indexPlayerLoading').fadeOut();
          $('#DOM_Control_PreviewPlayer').html(html);
        }
      });
    });
    return false;
  });
*/  
   
  $('#indexSignUpCheckBox').click(function () {
    $('#generalCaptchaContainer').toggle();
  });
  
  $('#formGeneralSignUp').submit(function () {
    var errors = false;
    var strForm = $('#formGeneralSignUp').serialize();
    var firstName = $('#general_FName').val();
    var lastName = $('#general_LName').val();
    var displayName = $('#general_DisplayName').val();
    var email = $('#general_Email').val();
    var Password = $('#general_Password').val();
    var User = $('#user_Type').val();
    var musicGenre = $('#genreSelect').val();
    var Gender = $('#general_Gender').val();
    var dobMonth = $('#dob_month').val();
    var dobDay = $('#dob_day').val();
    var dobYear = $('#dob_year').val();
    var inputCheckBox = $('#indexSignUpCheckBox:checked').val();
    var captcha = $('#general_Captcha').val();
    
    if (isEmpty(firstName)) {
      $('#general_FNameTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(lastName)) {
      $('#general_LNameTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(displayName)) {
      $('#general_DisplayNameTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(email) || !isEmail(email)) {
      $('#general_EmailTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(Password)) {
      $('#general_PasswordTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(User) || (User != 'A' && User != 'V')) {
      $('#general_UserTypeTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(Gender) || Gender < 1 || Gender > 2) {
      $('#general_GenderTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(musicGenre) || isNaN(musicGenre) || musicGenre > 24 || musicGenre < 1) {
      $('#general_MusicGenreTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (isEmpty(dobMonth) || isEmpty(dobDay) || isEmpty(dobYear) || isNaN(dobMonth) || isNaN(dobDay) || isNaN(dobYear)) {
      $('#general_BirthdayTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    else if (inputCheckBox == null) {
      $('#general_CheckBoxTxt').css({'color' : '#FF0000'});
      errors = true;
    }
    /*else if (captcha == '' || isEmpty(captcha)) {
      $('#general_Captcha').css({'border' : '1px solid #FF0000'});
      errors = true;
    }*/
    if (!errors) {
      $.ajax({
        type: 'POST',
        data: strForm, 
        url: 'ajax/ajax.Register.php', 
        success: function (html) {
          if (html == 1) {
            $('#generalAlreadyReg').show();
            setTimeout(function () {$('#generalAlreadyReg').hide()}, 4000);
          }
          else if (html == 2) {
            $('#generalError').show();
            setTimeout(function () {$('#generalError').hide()}, 4000);
          }
          else if (html == 3) {
            $('#generalWrongCaptcha').show();
            setTimeout(function () {$('#generalWrongCaptcha').hide()}, 4000);
            Recaptcha.reload();
          }
          else {
            window.location = 'http://www.newartist.com';
          }
        }
      });
    }
    return false;
  });
});

function indexShowSignUp() {
  $('#globalShadow').show();
  $('#indexBoxLoading').show();
  $('#signUpFormPopUp').fadeIn('fast');
  $.ajax({
    type: 'POST', 
    url: 'ajax/ajax.signUpPopUp.php', 
    cache: false,
    success: function (html) {
      $('#indexBoxLoading').fadeOut();
      $('#DOM_Control_signUp').html(html);
    }
  });
}

function indexCloseSignUp() {
  $('#signUpFormPopUp').fadeOut();
  $('#globalShadow').hide();
}

function popUpSignUp() {
  var errors = false;
  var strForm = $('#popUpFormSignUp').serialize();
  var firstName = $('#popUp_FName').val();
  var lastName = $('#popUp_LName').val();
  var displayName = $('#popUp_DName').val();
  var email = $('#popUp_Email').val();
  var Password = $('#popUp_Password').val();
  var User = $('#popUpUser_Type').val();
  var musicGenre = $('#popUpGenreSelect').val();
  var Gender = $('#popUp_Gender').val();
  var dobMonth = $('#popUpdob_month').val();
  var dobDay = $('#popUpdob_day').val();
  var dobYear = $('#popUpdob_year').val();
  var inputCheckBox = $('#popUpSignUpCheckBox:checked').val();
  
  if (isEmpty(firstName)) {
    $('#popUp_FNameTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(lastName)) {
    $('#popUp_LNameTxt').css({'color' : '#FF0000'});
    errors = true;
  }else if (isEmpty(displayName)) {
    $('#popUp_DNameTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(email) || !isEmail(email)) {
    $('#popUp_EmailTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(Password)) {
    $('#popUp_PasswordTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(User) || (User != 'A' && User != 'V')) {
    $('#popUp_UserTypeTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(Gender) || Gender < 1 || Gender > 2) {
    $('#popUp_GenderTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(musicGenre) || isNaN(musicGenre) || musicGenre > 22 || musicGenre < 1) {
    $('#popUp_MusicGenreTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  else if (isEmpty(dobMonth) || isEmpty(dobDay) || isEmpty(dobYear) || isNaN(dobMonth) || isNaN(dobDay) || isNaN(dobYear)) {
    $('#popUp_BirthdayTxt').css({'color' : '#FF0000'});
    errors = true;
  }
  /*else if (inputCheckBox == null) {
    $('#popUp_CheckBoxTxt').css({'color' : '#FF0000'});
    errors = true;
  }*/
  if (!errors) {
    $.ajax({
      type: 'POST',
      data: strForm, 
      url: 'ajax/ajax.Register2.php', 
      success: function (html) {
        $('#popUpSignUpMessage').empty();
        $('#popUpSignUpMessage').show();
        
        if (html == 1) {
          $('#popUpSignUpMessage').html('Oops! Looks like you are already registered.<br />'+
                                          'If you forgot your password please <a href="login.php?ref=forgot">click here</a>.');
        }
        else if (html == 2) {
          $('#popUpSignUpMessage').html('Oops! There seems to be an error in the sign up form.<br />'+
                                          'Please verify all your information and try again.');
        } 
        else {
            window.location = 'http://www.newartist.com';
          }
      }
    });
  }
  return false;
}