                    
function validateMyAccUnsubForm() {
  if($("#global-myacc-unsub-form input[type=radio]:checked").length==0) {
    alert("Please select a reason");
    return false;
  } else {
    return true;
  }
}

$(document).ready(function() {
 
  var extend_vf = $.extend(true, {}, validatorFactory);
  
  $("#global-myacc-unsub-form input[type=radio]").click(function() {
     $(".global-myacc-unsub-other").css("display",$(this).val()==100 ? "block" : "none");
  });                            
  $("#global-myacc-unsub-form").show();                               
          
  
  var rules_details = {  
    "updatedetails_title": {
      required: true,
      notEqualToValue: "Choose"
    },
    "updatedetails_firstName": "required",
    "updatedetails_lastName": "required",
    "updatedetails_newEmail": {
      required: true,
      email: true
    },
    "updatedetails_newEmailConfirmation": {
      required: true,
      email: true,
      equalTo: "#updatedetails_newEmail"
    }
  };

  var rules_signin = {  
    "updatedetails_oldPassword": "required",
    "updatedetails_newPassword": {
       required : true,
       minlength: 6,
       notEqualToOld : true
    },
    "updatedetails_newPasswordConfirmation": {
       required: true,
       equalTo: "#updatedetails_newPassword"
    },
    "updatedetails_passwordReminder": "required"
  };
 
  var messages_details = { 
    "updatedetails_title": "Choose your title", 
    "updatedetails_firstName": "Please type your first name",
    "updatedetails_lastName": "Please type your last name",
    "updatedetails_newEmail": {
      required: "Your email address is required",
      email: "Your email address you provided is a valid email"
    },
    "updatedetails_newEmailConfirmation": {
      required: "Please retype your email address",
      email: "Your email address you provided is a valid email",
      equalTo: "The two emails don't match"
    }
  };
   
  var messages_signin = {
    "updatedetails_oldPassword": "Password incorrect",
    "updatedetails_newPassword": {
       required: "Insert the new password",
       minlength: "The new password must be at least 6 characters long",
       notEqualToOld : "The new password must be different from the old one"
    },
    "updatedetails_newPasswordConfirmation": {
       required: "Please retype your password",
       equalTo: "The two password don't match"
    },
    "updatedetails_passwordReminder": "You must provide a password reminder hint"
  };      
        
  var form_fields_details = [
    "updatedetails_title", 
    "updatedetails_firstName", 
    "updatedetails_lastName", 
    "updatedetails_newEmail", 
    "updatedetails_newEmailConfirmation", 
    {
      "id" : "updatedetails_optInSiteMarketing",
      "callback" : function(field) {
        return ( field + '=' + $('#' + field).is(':checked') );
      }
    }, 
    {
      "id" : "updatedetails_optInThirdPartyMarketing",
      "callback" : function(field) {
         return ( field + '=' + $('#' + field).is(':checked') );
      }
    }
  ];

  var form_fields_signin = [
    "updatedetails_oldPassword",
    "updatedetails_newPassword",
    "updatedetails_newPasswordConfirmation",
    "updatedetails_passwordReminder"
  ];  
  
  var details = validatorFactory.getSubmitHandler("/system/userupdatedetails", "userupdatedetails", form_fields_details, function(){
    location.href = "/my-account/action/update-account-details/success/true";
  });
  
  var validator = validatorFactory.getValidator("#updateDetails", rules_details, messages_details, details.getHandler()); 
  
  var signin = extend_vf.getSubmitHandler("/system/userupdatedetails", "userupdatedetails", form_fields_signin, function(){
    location.href = "/my-account/action/change-sign-in-details/success/true";
  });
         
  var validator = extend_vf.getValidator("#updatePassword", rules_signin, messages_signin, signin.getHandler());            
  
  $.validator.addMethod("notEqualToOld", function(value, element) {
    return !($("#updatedetails_oldPassword").val() == value ); 
  });
       
  $("select.error, input[type=checkbox].error").live({
    mouseenter: function() {
      $(this).nextAll("label.error").children("div.message").addClass("show-tooltip");
    }, 
    mouseleave: function() {
      $(this).nextAll("label.error").children("div.message").removeClass("show-tooltip");
    }  
  });
      
 });

