
jQuery(document).ready(function($)
 {
	 
 				

$('#send_button').formValidator({
onSuccess       : function() {
sendEU('#send');
},                         
scope		: '#rightcol',
errorDiv	: '#ERROR',
customErrMsg	:	'Заполните  необходимые поля'
});




function sendEU(datastr){	
			$("#response").css("display", "block");
			$("#response").html("Отправка данных .... ");
			$("#response").fadeIn("slow");
			setTimeout(function(){send(datastr);}, 2000);
		return false;
	}; 

function ajaxJSON(json){
            if(json){
                var obj = (typeof(json) == 'object') ? json : eval('(' + json + ')');
                eval(obj.script);
                if(obj.confirm){
                    obj.success = confirm(obj.confirm);
                }
                return obj;
            }
            return {};
        }
	
	function clear_form_elements(ele) {
    $(ele).find(':input').each(function() {

        switch(this.type) {

            case 'password':

            case 'select-multiple':

            case 'select-one':

            case 'text':

            case 'textarea':

                $(this).val('');

                break;

            case 'checkbox':

            case 'radio':

                this.checked = false;

        }

    });

 

}

function send(datastr){

	function onsuccess(response)
	{
    	result = ajaxJSON(response);
		 if(result.message){
		if(result.success){

		$("#response").fadeIn("slow");
		$("#response").html(result.message);
		setTimeout(function() {$('#response').fadeOut();  }, 5000);

			clear_form_elements('#send');
			$('input:file').MultiFile('reset');
			}
		 else
		 {
		$("#response").fadeOut("fast");
		$("#ERROR").css("display", "block");
		$("#ERROR").fadeIn("slow");
		$("#ERROR").html(result.message);
		 }
		 }
	}

	if( datastr.indexOf('#') != 0 )
	{
		$.ajax({
				type: "POST",
				url: "http://www.simultrans.ru/send.php",
				data: datastr,
				dataType: 'JSON',
				cache: false,

				success: function(response){
                	onsuccess(response);
				}

			});
	}
	else
	{
		formid = datastr;
			var iframe = $('<iframe name="postframe" id="postframe" class="req-min" minlength="1" src="about:none" style="width:0;height:0;border:0px solid #fff;" />');
		$('body').append(iframe);
	    	$(formid).attr('target', 'postframe');
			$(formid).attr('ACTION', 'send.php');
	    	$(formid).submit();

	    	$('#postframe').load( function(){
			iframeContents = $("iframe#postframe")[0].contentDocument.body.innerHTML;
	        	onsuccess(iframeContents);
	        	$('#postframe').remove();
		} );
	}
}


  
 

});
  
  

