// ajax_storing.js v1.0
// copyright 2009
// Soulbytes IT Solutions

$(document).ready(function() {
	
		$('#storingsform').livequery('submit', function() { 

		// Check for emptiness
		if ($("#klant_naam").val() == '') {
			$("#klant_naam").focus();
			alert('Naam klant is een verplicht veld.');
			return false;
		}
		if ($("#klant_adres").val() == '') {
			$("#klant_adres").focus();
			alert('Adres klant is een verplicht veld.');
			return false;
		}
		if ($("#klant_postcode").val() == '') {
			$("#klant_postcode").focus();
			alert('Postcode klant is een verplicht veld.');
			return false;
		}
		if ($("#klant_woonplaats").val() == '') {
			$("#klant_woonplaats").focus();
			alert('Woonplaats klant is een verplicht veld.');
			return false;
		}
		if ($("#klant_contactpersoon").val() == '') {
			$("#klant_contactpersoon").focus();
			alert('Contactpersoon is een verplicht veld.');
			return false;
		}
		if ($("#klant_telefoonnummer").val() == '') {
			$("#klant_telefoonnummer").focus();
			alert('Telefoonnummer is een verplicht veld.');
			return false;
		}
		if ($("#machine_merk").val() == '') {
			$("#machine_merk").focus();
			alert('Machine merk is een verplicht veld.');
			return false;
		}
		if ($("#machine_type").val() == '') {
			$("#machine_type").focus();
			alert('Machine type is een verplicht veld.');
			return false;
		}				
		if ($("#storings_bericht").val() == '') {
			$("#storings_bericht").focus();
			alert('Storings bericht is een verplicht veld.');
			return false;
		}

			
		
		var varRequestMethod = "post";
		var varPostTo = 'inc/functions/ajax_save_storingsformulier.php';
		var frmParams = $('#storingsform').serialize();
		var varAjaxContent = "#storingsformcontainer";
		var varAjaxWait = "#ajaxwait";
		
		$.ajax({
			method: varRequestMethod, url: varPostTo, data: frmParams,   
			beforeSend: function(){$(varAjaxContent).html('').hide("slow"); $(varAjaxWait).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			complete: function(){ $(varAjaxWait).hide("slow");},
			error: function(){ $(varAjaxContent).html('Er is een fout opgetreden tijden het verzenden van uw storingsmelding.').show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');});},
			success: function(html){ $(varAjaxContent).html(html).show('slow',function(){ if(jQuery.browser.msie) this.style.removeAttribute('filter');}); }   
		});

		return false;	

	}); 

		
});