  $(document).ready(function(){
		// Code used to validate and submit comment form using AJAX
	$('.swap').each(function(){
		var t=$(this);
		var src1= t.attr('src'); // initial src
		var newSrc = src1.substring(0, src1.lastIndexOf('.')); // let's get file name without extension
		t.hover(function(){
			$(this).attr('src', newSrc+ '_selected.' + /[^.]+$/.exec(src1)); //last part is for extension   
		}, function(){
			$(this).attr('src', newSrc + '.' + /[^.]+$/.exec(src1)); //removing '-over' from the name
		});
	});	
	
    $("#commentForm").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted below'
					: 'You missed ' + errors + ' fields.  They have been highlighted below';
				$("div.error span").html(message);
				$("div.error").show();
 
			} else {
				$("div.error").hide();
			}
		},
		rules: {
				name: "required",
				email: {
					required: true,
					email: true
				},
				phone: "required"
		},
		messages: {
			email: "Email Required",
			name: "Name Required",
			phone: "Phone Required"
		},
		submitHandler: function() {
			var name = $('#name').val();
			var number = $('#phone').val();
			var email = $('#email').val();
			var lead_type = $('#lead_type').val();
			
			$.ajax({ 
				url: "business/ajax_contact.php?name=" + name + "&number=" + number + "&email=" + email + "&lead_type=" + lead_type, 
				
				context: document.body, 
				success: function(){
					// If it is successful in communicating with ajax_contact.php, hide the comment form, and replace it with the HTML below
					
					$('#commentForm').hide();
					$('#commentForm').html("<table class='custom_table' width='100%' style='margin-top: 150px;margin-right: 5px; margin-left: 5px;'><tr><td align='center'><strong>Thank You For Contacting Us!</strong></td></tr><tr><td>&nbsp;</td></tr><tr><td  align='center'>A representative from Daily Classifieds will contact you within 48 hours!</td></tr></table>").slideDown();
				}
	      });
			
		}
	});
	
	$("#demoForm").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted below'
					: 'You missed ' + errors + ' fields.  They have been highlighted below';
				$("div.error span").html(message);
				$("div.error").show();
 
			} else {
				$("div.error").hide();
			}
		},
		rules: {
				fname: "required",
				femail: {
					required: true,
					email: true
				},
				fwebsite: "required"
		},
		messages: {
			femail: "Email Required",
			fname: "Name Required",
			fwebsite: "Website Required"
		}
	});
	
  });

