$(document).ready(function() { 
   	    var options = { 
       // target:        '#status',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
 
        // other available options: 
        url: 'http://biznesguide.ru/fm/main/checkdata_ajax/2'        // 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:   300 
    };
	
	// bind to the form's submit event 
    $('#myForm').submit(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $(this).ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
		}); 
	});

// pre-submit callback 
	function showRequest(formData, jqForm, options) { 
	  
		$('#status').html("<img src='http://biznesguide.ru/fm/img/loading.gif' width='16' height='16'><br><p>Ваши данные обрабатывается...</p>");
		$('#error').html('');
		return true; 
	}

// post-submit callback 
	function showResponse(responseText, statusText)  { 
		var data = eval('(' + responseText + ')');
		$('#'+data.captcha).attr('src','http://biznesguide.ru/fm/send/'+data.captcha+'/'+Math.round(Math.random(0)*1000));
		if (data.status == "OK") {
			$('#status').html('Ваше сообщение отправленно!');
			$('#error').html('');
			$('#myForm').clearForm();
		}
		else {
			$('#status').html('<u>Пожалуйста, проверьте введенные данные!</u>');
			$('#error').html(data.error);
			$('input[name=keystring]').attr('value','');
		}
	} 
