function updateCaptcha() {
	jQuery.ajax({
		type: 'GET',
		cache: false,
		url: '/cgi-bin/faq/client.pl?action=get_captcha_img&' + new Date().getTime(),
		success: function(responseText){
			jQuery('#pict_key').attr({
 				value: responseText
 			});
 			jQuery('#captcha_img').css({'background':'url(/imgs/pictprotect_faq/'+ responseText + '.png) no-repeat'});
		},
		error: function(){
			alert('error');
		}
	})
};

function checkFileSize() {
	var upload_file_uid = 'file' + Math.floor(Math.random() * 99999);
	
	new AjaxUpload ('file_attachment', {
		action: '/cgi-bin/faq/check_filesize.pl?action=upload&upload_file_uid=' + upload_file_uid,
		name: upload_file_uid,
		autoSubmit: true,
		onChange: function(a, b) {
			//alert(typeof a + typeof b);
		},				
		onComplete: function(a, b, c) {
			//alert(typeof a + typeof b + typeof c);
		}					
	})
};

jQuery(document).ready(function() {
	var Form = jQuery('#myForm');
	var formAction = Form.attr('action');
	
	Form.validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: jQuery("#result"),
				success: function() {
					updateCaptcha();
					if (!jQuery(".result").length) {
						jQuery("#result").wrap("<div class='result'></div>");
					}
				},
				resetForm: false,
				notsuccess: errorAjax,
				timeout: 3000 
			});
			function errorAjax(statusText) {
				alert('error = '+statusText);
			}
		}
	});
	updateCaptcha();
	jQuery('#file_attachment').change(function() {
		checkFileSize()
	})
}); 
