$(document).ready(function(){
	$("a.rfp-link-open").click(function () {
		$("#rfp").fadeIn("slow");
		$("#homepage").hide();
	});
	
	$("a.rfp-link-close").click(function () {
	    $("#rfp").hide();
		$("#homepage").fadeIn("slow");
		$('form#commentform .error').remove();
	});
	
	$('form#commentform').submit(function() {
		$('form#commentform .error').remove();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
				var text = $(this).attr("name");
				if(text == 'fullname') { text = 'Full Name'; }
				if(text == 'email') { text = 'Email Address'; }
				if(text == 'phone') { text = 'Phone'; }
				if(text == 'message') { text = 'Message / Comments'; }
				$(this).parent().append('<span class="error">' + text + ' is a required field.</span>');
				hasError = true;
			}
		});
		if(!hasError) {
			var fullname = $("#fullname").attr("value");
			var email = $('#email').attr('value');
			var phone = $('#phone').attr('value');
			var company = $('#company').attr('value');
			var message = document.getElementById('message').value;
			
			var dataString = "fullname=" + fullname + "&email=" + email + "&phone=" + phone + "&company=" + company + "&message=" + message;

			$.ajax({
					type: "POST",
					url: "app/ajax.php",
					data: dataString,
					success: function(){
					$('div#rfp-wrap').fadeOut("fast");
					$('div.success').fadeIn("slow");
				}
			});
		}
		return false;
	});
	
});