/**
form_2.js
**/
// prepare the form when the DOM is ready 
$(document).ready(function() {
    var options = { 
//	target:        '#formmsg',   // target element(s) to be updated with server response
	success:       showResponse,  // post-submit callback 
	beforeSubmit: validate // Validate the form before submitting
	

	/*
        target:        '#output2',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
	*/
    };
	
	
//	$("#recordPhone").mask("(999) 999-9999");
//	$("#recordZip").mask("99999");
//   $("#date").mask("99/99/9999");
   $("#phone").mask("(999) 999-9999");
 //  $("#tin").mask("99-9999999");
 //  $("#ssn").mask("999-99-9999");

	// validate each field
	$("#commentForm").validate();
	

    // bind form using 'ajaxForm' 
//    $('#commentForm').ajaxForm(options); 
	
			
});
 

 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxSubmit method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
		if(statusText=="success") {
		  window.location="thanks.php";
//		  alert("Your information has been submitted");
		} else {
		  alert("An Error occurred while submiting your information. Please try again");
		}
} 




function validate(formData, jqForm, options) { 
    // jqForm is a jQuery object which wraps the form DOM element 
    // 
    // To validate, we can access the DOM elements directly and return true 
    // only if the values of both the username and password fields evaluate 
    // to true 
 
    var form = jqForm[0]; 
    if (!form.email.value || !form.phone.value || 
	    !form.zip.value || !form.state.value  ||
	    !form.city.value || !form.address.value  ||	    
		!form.lname.value || !form.fname.value 	    ) { 
        alert('Please enter a value for all the required fields'); 
        return false; 
    } 
 
}





