/* makes forms ajax driven */
$.fn.ajaxSubmit = function(e) {		
	/* Change a form's submission type to ajax */
	this.submit(function(){
		// confirm form
		var confirmTxt = $("#confirmTxt").val();

		input_box = confirm(confirmTxt);	
		if (input_box == true)	{
		} else {
			return false;	
		}

		
		
		var params = {};
			$(this)
			.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], option[@selected], textarea")
			.filter(":enabled")
			.each(function() {
			params[ this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;
		});
		
		$.post("/index.php?call=ajax", params, function(xml){
			$.blockUI({ message: '<p><img src="/images/busy.gif" /> <br>The wheels are turning... <br>hang on it will be over to the JI people in seconds!</p>' }); 
			
			var strError = "Error";
			oFocus = null;
			record = xml.getElementsByTagName("status");
			var status = record[0].childNodes[0].nodeValue;
			//alert(status);
			if (status == 1) {
				// release modal
				//setTimeout($.unblockUI, 1000); 
				parseValidationResponses(xml);
				
				record = xml.getElementsByTagName("location");
				var strRedirect = record[0].childNodes[0].nodeValue;
				if (strRedirect =='0') {
				} else {
					window.location = "index.php?"+strRedirect;
				}
				
				
				
				record = xml.getElementsByTagName("jfns");
				//var functionName = record[0].childNodes[0].childNodes[0].nodeValue;
				//if (functionName != 0) {
				//	var req_id = record[0].childNodes[1].childNodes[0].nodeValue;
				//	eval(functionName+"("+req_id+")");
				//}
				setTimeout(function() { 
					$.unblockUI({ 
						onUnblock: function(){ 
							$.blockUI({ message: '<p>Your message has been sent. Thank you.</p>' });
							setTimeout($.unblockUI, 1500); 
						} 
					}); 
				}, 2000); 
				
			} else if (status == 2) {
				setTimeout($.unblockUI, 1500); 
				parseValidationResponses2(xml);
				//alert("Znaleziono błędy:\n" + strError);
				if (oFocus) $("#" + oFocus).get(0).focus();
			} else {
				setTimeout($.unblockUI, 1500); 
				parseValidationResponses(xml);
				//alert("Znaleziono błędy:\n" + strError);
				if (oFocus) $("#" + oFocus).get(0).focus();
			}
		});

		
		return false;
	});			
	return this;
}