$(document).ready(function() {
  $("#contact-form").validate({
    rules: {
      email: {
        email: true
      },
	  phone : {
        containsDigits: 8
      }
    },
    submitHandler: function() {
   	var data = "name="+$('#name').val();
	data += "&email="+$('#email').val();
	data += "&typeofinquiry="+$('#typeofinquiry').val();
	data += "&example="+$('#example').val();
	data += "&message="+$('#message').val();
	data += "&location="+$('#location').val();
	data += "&findme="+$('#findme').val();
	data += "&phone="+$('#phone').val()+"";
	
	//	alert(data);
	var XMLresponse = $.ajax({
	   type: "POST",
	   url: '/mail/send_query.php',
	   data: data,
	   async: false
	   }).responseText;
   	   	$('#name').val('');
		$('#email').val('');
		$('#example').val('');
		$('#message').val('');
		$('#location').val('');
		$('#phone').val('');

	   var confirmBox = $("#confirm").overlay({
            expose: {
              color: '#333',
              loadSpeed: 200,
              opacity: 0.9,
			  closeOnEsc:true,
			  closeOnClick: true
            }
          }).data('overlay');
        confirmBox.load();
	   return false;
	}
  });
  
  
  if ($.validator) {
	  $.validator.addMethod('containsDigits', function(value, element, requiredCount) {
      var digitCount = 0;
      for (var i = 0; i < value.length; i++) {
        var c = value.charAt(i);
        if (/\d/.test(c)) {
          digitCount++;
        }
      }
      return this.optional(element) || digitCount >= requiredCount;
    }, $.format('Phone number must have {0} digits.'));
  }
});

