$(document).ready(function() {
  jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
    return this.optional(element) || phone_number.length > 9 &&
      phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
  }, "Please specify a valid phone number");
  
  
  var v = $("#formJoin").validate({
    onfocusout: false,
		onkeyup: false,
		onclick: false,
		onsubmit: true,
    focusInvalid: true,
    errorElement: "span",
    errorContainer: "#jq-errors",
    errorClass: "toast",
    rules: {
      FirstName:              "required",
      LastName:               "required",
      Email:                  "required",
      Phone: {
        required: true,
        phoneUS: true
      },
      MailingStreet:          "required",
      MailingCity:            "required",
      MailingState:           "required",
      MailingPostalCode:      "required",
      MailingCountry:         "required", 
      Veteran_of__c:          "required",
      Rank__c:                "required",
      Branch_of_Service__c:   "required",
      Current_Status__c:      "required",
      Service_Type__c:        "required",
      Most_Recent_Unit__c:    "required"
    },
    messages: {
      FirstName:              "<br />First name is required.<br />",            
      LastName:               "Last name is required.<br />",             
      Email:                  "Email is required.<br />",                 
      Phone:                  "Please specify a valid phone number.<br />",                 
      MailingStreet:          "Street Address is required.<br />",        
      MailingCity:            "City is required.<br />",                  
      MailingState:           "State is required.<br />",                 
      MailingPostalCode:      "Zip code is required.<br />", 
      MailingCountry:         "Country is required.<br />",             
      Veteran_of__c:          "Please tell us whether you are a veteran of OIF, OEF, or both.<br />",                          
      Rank__c:                "Rank is required.<br />",                          
      Branch_of_Service__c:   "Branch of Service is required.<br />",                          
      Current_Status__c:      "Current Status is required.<br />",                          
      Service_Type__c:        "Type of Service is required.<br />",                          
      Most_Recent_Unit__c:    "Last Unit is required.<br />"                        
    },
		//errorPlacement: function(error, element) {
				//error.appendTo("div.messages");
		//},
		 showErrors: function(errorMap, errorList) {
  		$("#jq-errors").html("Your form contains "
                                     + this.numberOfInvalids() 
                                     + " errors, see details below.");
  		this.defaultShowErrors();
  	},
  	errorPlacement: function(error, element) {
				error.appendTo( $("#jq-errors") );

		}
  });
  $('#spokesperson').click(function(){
    $('#spokesperson_list').slideToggle();	
  });
  $('#topic').click(function(){
    $('#topic_list').slideToggle();	
  });
  $('#media').click(function(){
    $('#media_list').slideToggle();	
  });
  
  
  var v = $("#formJoinTwo").validate({
    onfocusout: false,
		onkeyup: false,
		onclick: false,
		onsubmit: true,
    focusInvalid: true,
    errorElement: "span",
    errorContainer: "#jq-errors",
    errorClass: "toast",
    rules: {
      FileName: "required"
    },
    messages: {
      FileName: "<br />Please upload your paperwork before clicking submit."                        
    },
		//errorPlacement: function(error, element) {
				//error.appendTo("div.messages");
		//},
		 showErrors: function(errorMap, errorList) {
  		$("#jq-errors").html("Your form contains "
                                     + this.numberOfInvalids() 
                                     + " errors, see details below.");
  		this.defaultShowErrors();
  	},
  	errorPlacement: function(error, element) {
				error.appendTo( $("#jq-errors") );

		}
  });
});
