// Form swaps class on input fields whcih changes the input color

//Create an associative array to hold the default hint values
//The  index is the ID of the element and the value is the hint

$(document).ready(function() {


	var hintArr = new Array()
	hintArr["fname"] = "First Name";
	hintArr["lname"] = "Last Name";

	$("input.initval").each(function(){
		id = $(this).attr("id");
		hint = hintArr[id];
		$(this).attr("value", hint);

	});

	$('.initval').focus(function() {
		if($(this).hasClass("initval")){
			$(this).attr("value", "").removeClass("initval");
		}
	});



	$('#contact-form input').blur(function() {
		currentval = $(this).attr("value");		
		if( currentval == undefined || currentval == ""){
			id = $(this).attr("id");
			hint = hintArr[id];
			if(hint != "" && hint != undefined){
				$(this).addClass("initval").attr("value", hint);
			}
		}
	});
	$("#contact-form h4").hide();


	jQuery.validator.addMethod("defval", function(value, element) {
		if(value == "First Name"){
			return false;
		} else if( value == "Last Name"){
			return false;
		} else {
			return true;
		}
		}, "Required");



		$("#contact-form").validate({
			groups: {
				username: "fname lname"
			},
			errorPlacement: function(error, element) {
				if (element.name == "fname" || element.name == "lname" )
				error.insertAfter("lname");
				else
				error.insertAfter(element);
			},
			rules: { 
				fname: {defval: true},
				lname: {defval: true}

			}, 
			messages: {
				fname: "Required",
				lname: "Required",
				captcha: "Required Anti-Spam",
				email: {
					required: "Required",
					email: "Invalid e-mail address"
				}

			},
			errorElement: "h4"

		});
	});
