	function randomString(length) {
	    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
	    
	    if (! length) {
	        length = Math.floor(Math.random() * chars.length);
	    }
	    
	    var str = '';
	    for (var i = 0; i < length; i++) {
	        str += chars[Math.floor(Math.random() * chars.length)];
	    }
	    return str;
	}
	
$(function()
{

//************* első kép feltöltése - törlése
			var btnUpload=$('#uploadPicture1');
			var status=$('#status1');
			new AjaxUpload(btnUpload, {
			action: 'pages/upload-file.php',
			name: 'uploadfile',
			onSubmit: function(file, ext)
			{
			 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
		     // extension is not allowed 
			status.text('Only JPG, PNG or GIF files are allowed');
			return false;
			}status.text('Uploading...');
			},
			
			onComplete: function(file, response)
			{
				//On completion clear the status
				status.text('');
				$('#picture1').val(file);
				$('#uploadPicture1').hide();
				$('#deletePicture1').show();
				$('<div class="box1" ></div>').appendTo('#files1').html('<input type="hidden" id ="picture1" name="picture1" value="'+response+'"/><img src="images/uploads/'+response+'" alt="" width="130" height="130" /><br><div class="clear"></div>');

			}});

			$('#deletePicture1').click(function() {
				var string = 'filename='+$('#picture1').val();
				$.ajax({
					   type: "POST",
					   url: "delete-file.php",
					   data: string,
					   cache: false,
					   success: function(){
							$('.box1').remove();
							$('#uploadPicture1').show();
							$('#deletePicture1').hide();
					  }
					   
				});
			});

//************* második kép feltöltése - törlése
			var btnUpload=$('#uploadPicture2');
			var status=$('#status2');
			new AjaxUpload(btnUpload, {
			action: 'pages/upload-file.php',
			name: 'uploadfile',
			onSubmit: function(file, ext)
			{
				if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
					// extension is not allowed 
					status.text('Only JPG, PNG or GIF files are allowed');
					return false;
			}status.text('Uploading...');
			},
			
			onComplete: function(file, response)
			{
				//On completion clear the status
				status.text('');

				$('#uploadPicture2').hide();
				$('#deletePicture2').show();
				$('<div class="box2" ></div>').appendTo('#files2').html('<input type="hidden" id ="picture2" name="picture2" value="'+response+'"/><img src="images/uploads/'+response+'" alt="" width="130" height="130" /><br><div class="clear"></div>');

			}});

			$('#deletePicture2').click(function() {
				
				var string = 'filename='+$('#picture2').val();
				$.ajax({
					   type: "POST",
					   url: "delete-file.php",
					   data: string,
					   cache: false,
					   success: function(){
							$('.box2').remove();
							$('#uploadPicture2').show();
							$('#deletePicture2').hide();
					  }
					   
				});
			});
//************* harmadik képp feltöltése - törlése
			var btnUpload=$('#uploadPicture3');
			var status=$('#status3');
			new AjaxUpload(btnUpload, {
			action: 'pages/upload-file.php',
			name: 'uploadfile',
			onSubmit: function(file, ext)
			{
			 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
		     // extension is not allowed 
			status.text('Only JPG, PNG or GIF files are allowed');
			return false;
			}status.text('Uploading...');
			},
			
			onComplete: function(file, response)
			{
				//On completion clear the status
				status.text('');

				$('#uploadPicture3').hide();
				$('#deletePicture3').show();
				$('<div class="box3" ></div>').appendTo('#files3').html('<input type="hidden" id ="picture3" name="picture3" value="'+response+'"/><img src="images/uploads/'+response+'" alt="" width="130" height="130" /><br><div class="clear"></div>');

			}});

			$('#deletePicture3').click(function() {
				
				var string = 'filename='+$('#picture3').val();
				$.ajax({
					   type: "POST",
					   url: "delete-file.php",
					   data: string,
					   cache: false,
					   success: function(){
							$('.box3').remove();
							$('#uploadPicture3').show();
							$('#deletePicture3').hide();
					  }
					   
				});
			});
			
//************* negyedik kép feltöltése - törlése
			var btnUpload=$('#uploadPicture4');
			var status=$('#status4');
			new AjaxUpload(btnUpload, {
			action: 'pages/upload-file.php',
			name: 'uploadfile',
			onSubmit: function(file, ext)
			{
			 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
		     // extension is not allowed 
			status.text('Only JPG, PNG or GIF files are allowed');
			return false;
			}status.text('Uploading...');
			},
			
			onComplete: function(file, response)
			{
				//On completion clear the status
				status.text('');

				$('#uploadPicture4').hide();
				$('#deletePicture4').show();
				$('<div class="box4" ></div>').appendTo('#files4').html('<input type="hidden" id ="picture4" name="picture4" value="'+response+'"/><img src="images/uploads/'+response+'" alt="" width="130" height="130" /><br><div class="clear"></div>');

			}});

			$('#deletePicture4').click(function() {
				
				var string = 'filename='+$('#picture4').val();
				$.ajax({
					   type: "POST",
					   url: "delete-file.php",
					   data: string,
					   cache: false,
					   success: function(){
							$('.box4').remove();
							$('#uploadPicture4').show();
							$('#deletePicture4').hide();
					  }
					   
				});
			});
});
