function ajaxFileUpload_product()
	{
		//starting setting some animation when the ajax starts and completes
		$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		/*
			prepareing ajax file upload
			url: the url of script file handling the uploaded files
                        fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
			dataType: it support json, xml
			secureuri:use secure protocol
			success: call back function when the ajax complete
			error: callback function when the ajax failed

                */
		$.ajaxFileUpload
		(
			{
				url:'/product/product_image_upload.php',
				secureuri:false,
				fileElementId:'product_image_file',
				maxSizeId:'maxsize',
				dataType: 'json',
				success: function (data, status)
				{
					if(data.error_code != '0')
					{
							$('#product_image_file_help').text(data.error);
						}else
						{
							// FIXME не работает. сперва картинка потом диалог
							$('#product_image_file_help').text("Файл успешно загружен.");
							$('#product_load_image').attr({'src':'/userfiles/products/alco/thumbs/'+data.filename});
							$('#product_load_image').attr({'title':''});
							$('#product_load_image').attr({'alt':''});
							$('#product_load_image').unbind('click');
							$('#product_load_image').css({'cursor':'default'});
							$('#product_load_image').fitimage({ placeholder: "/images/blank.gif" });
							$('#product_image').dialog('close');
						}
				},
				error: function (data, status, e)
				{
					$('#product_image_file_help').text('Ошибка: '+e);
				}
			}
		);

		return false;

	}

$(function(){
	$('#product_image').dialog({
		bgiframe: true,
		autoOpen: false,
		height: 320,
		width: 400,
		modal: true,
		resizable: false,
		zIndex: 10000,
		buttons: {
			'Сохранить': function() {
				$('#product_image_file_help').text('');
				if($('#product_image_file').val()==""){
					$('#product_image_file_help').text("Необходимо указать имя файла");
					$('#product_image_file').focus();
					return (false);
				}

				if($('#product_image_file').val().search(/^.*?\.(jpeg|jpg|png)$/gi) == -1){
					$('#product_image_file_help').text("Формат файла должен быть jpeg или png");
					$('#product_image_file').focus();
					return (false);
				}
				$('#product_image_file_help').text("Загружаем файл...");
				ajaxFileUpload_product();
			}
		}
	});

	$('#product_load_image').click(function(){
		$('#product_image').dialog('open').load('/product/image_load.html',function(){



		});

	});


});
