/*-----------------------------------------------------------------------------------------------
form validation
- quickconnect home
-------------------------------------------------------------------------------------------------*/

function qcSubmit(formObj) {
	jQuery(document).ready(function() {
		//html for feedback  container that is appended
		var feedbackHTML = "<div id=\"qCFeedback\"><span></span></div>";
		
		var validCheck = true;
		//check for req input values
		if($('#fname').attr("value") == "" || $('#fname').attr("value") == "Required") {
			validCheck = false;
			//null so add error class
			$('#fname').addClass("error");
			$('#fname').attr("value", "Required");
		}
		if($('#lname').attr("value") == "" || $('#lname').attr("value") == "Required") {
			validCheck = false;
			//null so add error class
			$('#lname').addClass("error");
			$('#lname').attr("value", "Required");
		}
		if($('#phone').attr("value") == "" || $('#phone').attr("value") == "Required") {
			validCheck = false;
			//null so add error class
			$('#phone').addClass("error");
			$('#phone').attr("value", "Required");
		}
		if($('#hP').attr("value") != "") {
			//hP has data so fail it
			validCheck = false;
		}
		if(validCheck) {
			//append feedback
			$('form#qCForm fieldset').append(feedbackHTML);
			$('#qCFeedback span').text("Sending Information...");
			//form data
			//serialize? (see if this works)
			var qCData = $("form#qCForm").serialize();
			//ajax -> !!remove the absolute part of path below when misphase send() issue fixed
			$.ajax({
				type: "POST",
				url: "/quickconnectHandler.php",
				data: qCData,
				success: function(html){
					//show success message   //!!reinstate all success statements once midphase fixed
					$('#qCFeedback').addClass('sent');
					$('#qCFeedback span').text(html);
					//hide box, reset field
					setTimeout("resetQC()",2000);
				}
			});
			//show success message -> when not getting feedback from ajax call
			//$('#qCFeedback').addClass('sent');
			//$('#qCFeedback span').text("Information Sent!");
			//hide box, reset field
			//setTimeout("resetQC()",2000);
		}else{
			//errors in form so do nothing
		}

	});
	//stop from moving to handler
	return false;
}
function resetQC() {
	jQuery(document).ready(function() {
		//reset all input values
		$('#fname').attr("value","");
		$('#lname').attr("value","");
		$('#phone').attr("value","");
		$('#message').attr("value","");
		//remove error classes [cycle through all inputs and rmove]
		$('form#qCForm input').each(
			function(){
				if($(this).hasClass('error')){
					$(this).removeClass('error');
				}
			}
		);
		//remove html for feedback div
		$('#qCFeedback').remove();
		//remove .open class [will close form on contentTemplate]
		contactFormAnim();
	});
}

