/**
 * Submit User details
 */
$(function() {
  $("#edit-profile-topics-interest-131").click(function(){
    toggleTopicInterest();
  });
});

function toggleTopicInterest() {
  if ($("#edit-profile-topics-interest-131").attr("checked")) {
    $("#edit-profile-topics-interest-104").attr("disabled",true);
    $("#edit-profile-topics-interest-104").attr("checked",false);

    $("#edit-profile-topics-interest-105").attr("disabled",true);
    $("#edit-profile-topics-interest-105").attr("checked",false);

    $("#edit-profile-topics-interest-106").attr("disabled",true);
    $("#edit-profile-topics-interest-106").attr("checked",false);

    $("#edit-profile-topics-interest-129").attr("disabled",true);
    $("#edit-profile-topics-interest-129").attr("checked",false);

    $("#edit-profile-topics-interest-130").attr("disabled",true);
    $("#edit-profile-topics-interest-130").attr("checked",false);
  }
  else {
    $("#edit-profile-topics-interest-104").attr("disabled",false);
    $("#edit-profile-topics-interest-105").attr("disabled",false);
    $("#edit-profile-topics-interest-106").attr("disabled",false);
    $("#edit-profile-topics-interest-129").attr("disabled",false);
    $("#edit-profile-topics-interest-130").attr("disabled",false);
    $("#edit-profile-topics-interest-131").attr("disabled",false);
  }
}

function saveProfile() {
  var profile_email   = $.trim($("#edit-profile-email").val());
  var profile_confirm_email = $.trim($("#edit-profile-confirm-email").val());
  var profile_password = $.trim($("#edit-profile-password").val());
  var profile_confirm_password = $.trim($("#edit-profile-confirm-password").val());
  var profile_name = $.trim($("#edit-profile-name").val());
  var profile_gender = $.trim($("#edit-profile-gender").val());
  var profile_birth_month = $.trim($("#edit-profile-birth-month").val());
  var profile_first_name   = $.trim($("#edit-profile-first-name").val());
  var profile_last_name = $.trim($("#edit-profile-last-name").val());
  var profile_address1 = $.trim($("#edit-profile-address1").val());
  var profile_address2 = $.trim($("#edit-profile-address2").val());
  var profile_city = $.trim($("#edit-profile-city").val());
  var profile_state = $.trim($("#edit-profile-state").val());
  var profile_zip = $.trim($("#edit-profile-zip").val());
  var profile_mobile = $.trim($("#edit-profile-mobile").val());
  var profile_how_long = $.trim($("#edit-profile-how-long").val());
  var profile_product = $.trim($("#edit-profile-product").val());
  var profile_skin_solution = $.trim($("#edit-profile-skin-solution").val());
  var profile_product = $.trim($("#edit-profile-product").val());
  
  var err_msg = 0;

  // validating product review
  if (profile_email  == '' || profile_name =='' || profile_confirm_email == '' || profile_gender == '0' || profile_confirm_password =='' || profile_password =='' || profile_birth_month =='' || profile_first_name  == '' || profile_last_name == '' || profile_address1 == '' || profile_city =='' || profile_state =='' || profile_zip =='' ) {
    errorMessages("There was an error in the information you entered. Please fill in the necessary form fields below.", "profile-error-msg");
  }
  
  if (profile_email == '') {
	  $("#edit-profile-email").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
    if (profile_name == '') {
	  $("#edit-profile-name").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_confirm_email == '') {
	  $("#edit-profile-confirm-email").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_password == '') {
	  $("#edit-profile-password").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_confirm_password == '') {
	  $("#edit-profile-confirm-password").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_gender == '0') {
	  $("#edit-profile-gender").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_birth_month == '0') {
	  $("#edit-profile-birth-month").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_first_name == '') {
	  $("#edit-profile-first-name").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_last_name == '') {
	  $("#edit-profile-last-name").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_address1 == '') {
	  $("#edit-profile-address1").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_city == '') {
	  $("#edit-profile-city").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_state == '') {
	  $("#edit-profile-state").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_zip == '') {
	  $("#edit-profile-zip").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if(err_msg==1){
	  return false;
  }
  
  $.ajax({
    type: "POST",
    url: baseurl + '/createprofile/save',
    data: "profile_email=" + profile_email + "&profile_password=" + profile_password  + "&profile_name=" + profile_name + "&profile_gender=" + profile_gender +"&profile_birth_month="+ profile_birth_month + "&profile_first_name=" + profile_first_name +"&profile_last_name=" + profile_last_name  + "&profile_address1=" + profile_address1 +"&profile_address2=" + profile_address2 + "&profile_city=" + profile_city + "&profile_state=" + profile_state + "&profile_zip=" + profile_zip +"&profile_mobile="+ profile_mobile +"&profile_how_long="+ profile_how_long,
    success: function(msg) {
      return true;
    },
    error: function() {
      return false;
    }
  });
}

function sub_aboutYou() {
  alert("About u");
  var profile_first_name   = $.trim($("#edit-profile-first-name").val());
  var profile_last_name = $.trim($("#edit-profile-last-name").val());
  var profile_address1 = $.trim($("#edit-profile-address1").val());
  var profile_address2 = $.trim($("#edit-profile-address2").val());
  var profile_city = $.trim($("#edit-profile-city").val());
  var profile_state = $.trim($("#edit-profile-state").val());
  var profile_zip = $.trim($("#edit-profile-zip").val());
  var err_msg = 0;

  // validating product review
  if (profile_first_name  == '' || profile_last_name == '' || profile_address1 == '' || profile_city =='' || profile_state =='' || profile_zip =='' ) {
    errorMessages("There was an error in the information you entered. Please fill in the necessary form fields below.", "profile-error-msg");
  }

  if (profile_first_name == '') {
	  $("#edit-profile-first-name").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_last_name == '') {
	  $("#edit-profile-last-name").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if (profile_address1 == '') {
	  $("#edit-profile-address1").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_city == '') {
	  $("#edit-profile-city").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_state == '') {
	  $("#edit-profile-state").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }
  if (profile_zip == '') {
	  $("#edit-profile-zip").css("border", "1px solid #FF433F");
	  var err_msg = 1;
  }

  if(err_msg==1){
	  return false;
  }
  else{
    return true;
  }
}

function hide_previous_button(){
  $("#prev-button").hide();
}

function show_previous_button(){
  $("#prev-button").show();
}
