var submitFormModal = function(form_id){

	var myForm = $("#"+form_id)[0];

	$("#notify-x").hide();
	$("#msg-x").html('Processing... Please Wait.');
	$("#msg-x").show();

	//clearUnusedFields();
	$.ajax({
		type: 'POST'
		, url: myForm.action
		, dataType: 'json'
		, data: $("input,select,textarea", myForm)
		, success: function(data){
			if(data.success){
				$("#msg-x").text(data.msg);
				$("#msg-x").fadeIn("fast");
				$("#msg-x").fadeOut(7500);
				if(data.other){
					if(data.other.form){
						if(data.other.url){
							//alert(data.other.url);
							window.location = data.other.url;
						}
						/*if(data.other.form.action){ form.form.action = data.other.form.action; }
						if(data.other.form.fields) {
							$.each(data.other.form.fields, function(f, v) {
								$('#'+f).val(v);
							});
							$("#"+form.form.id).submit();
						}*/
					} else {
						if(data.other.url){ window.location = data.other.url; }
					}
				}
			} else {
				var msg = data.msg; //+ '<ul style="text-align:left">'; //UNCOMMENT TO SHOW SPECIFIC FIELD MESSAGES
				var fields = data.results;
				var cssField = null;
				for(x in fields){
					var showError = true;
					if(fields[x].error){
						if(!fields[x].required && $('#'+fields[x].name).length == 0){
							showError = false;
						}
						if(showError) {
							//msg += '<li>' + fields[x].error + '</li>'; //UNCOMMENT TO SHOW SPECIFIC FIELD MESSAGES
							cssField = (fields[x].type=="checkbox") ? "checkbox_" + fields[x].name : fields[x].name;
							$('#'+cssField).css({'background-color' : '#FFC0CB'});
							//alert(cssField);
						}
					} else {
						cssField = (fields[x].type=="checkbox") ? "checkbox_" + fields[x].name : fields[x].name;
						if(fields[x].type=="text" || fields[x].type=="select") { $('#'+cssField).css({'background-color' : 'white'}); }
						else if(fields[x].type=="checkbox") { $('#'+cssField).css({'background-color' : ''}); }
					}
				}
				msg += '</ul>';
				$("#msg-x").hide();
				$("#notify-x").html(msg);
				$("#notify-x").fadeIn(0);
				//$("#notify-x").fadeOut(7500);
			}
		}
	});

	//initTextFields();
	return false;

};