// JQuery Document
// Author: Wayne Southey - Planethome Designs

$(document).ready(function(){


 //$("#Phone").mask("(99)9999 9999"); 
// $("#Fax").mask("(99)9999 9999"); 						   
// $("#Postcode").mask("9999");	
 
 
 //$("#contactform").validate();
 
if ( $("#form_apply1").length > 0 ) {
	
	$("#co_tabs > ul").tabs();
	
	$('label.required').append('&nbsp;<strong>*</strong>&nbsp;');
	
	$("#form_apply1").validate({
		   errorLabelContainer: "#form_error",
		   wrapper: "li",
		   submitHandler: function(form) {
				//disable submit until complete to prevent resubmit
				$('#submit').attr("disabled",true);   
				$(form).ajaxSubmit(options);
		   }
	});
	//Options for ajax call
    var options = { 
        success:       showResponse,  // post-submit success callback 
		error:         showError, 	  // Error callback	
		dataType:  		'xml',
 		url:           "email_contact_ajax.php"   // override for form's 'action' attribute 
     };    
}
 
});

function showRequest(formData, jqForm, options) { 
		
		var queryString = $.param(formData); 
	 	// see  jqForm 
		return true; 
	} 
	 
	// post-submit callback 
	function showResponse(responseXML)  { 
		//responses from for in message (contains error message or blank)
	 	var message = $('message', responseXML).text(); 
		//rcode 0 succcess or 1 failure
		var rcode = $('rcode', responseXML).text(); 
		if (rcode==0) { 
		$('#contact_form').html("<div id='message'></div>");  
     		$('#message').html("<h2>Thank you, your request has been sent!</h2>")  
     			.append("<p>We will be in touch soon.</p>")  
    			.hide()  
    			.fadeIn(1000, function() {  
   	 	   $('#message').append("<img id='checkmark' src='images/check.png' />");  
  		   }); 
		} else {
			//Error in form 
			$('#form_error').html("<div class='error_message'>" + message + "</div>");
			$('#submit').attr("disabled",false); 
			$('#form_error').css("display","inline");
		}
		
	}
function showError (textStatus, errorThrown) {
  // typically only one of textStatus or errorThrown 
  // will have info
  	alert("Error: Your message could not be sent - communication error"); // the options for this ajax request
}
