/*
 * Funckia otvori externe okno pre popup fotky z galerie.. 800x750px
 *
 * @param string url
 * @return void
 */
function galeryPoup( url )
{
  xwidth = screen.availWidth/2 - 361;
  xheight = screen.availHeight/2 - 340;
  
  window.open( url, 'image', 'top='+xheight+', left='+xwidth+', width=861, height=640, resizable=1' );
}


/*
 * Funkcia otvara a zatvara polozky BEST v contex menu
 *
 * @param string element
 * @return void
 */
function openCloseContex( img, id )
{
  obj = document.getElementById(id);
  
  obj.style.display = (obj.style.display == 'block' || obj.style.display == '') ? 'none' : 'block';
  
  img.src = obj.style.display == 'block' ? './images/close.png' : './images/open.png';
}

function ajaxSubmit(obj) {
var params = {};
var form = $("#" + $(obj).attr('name'));
var i = 0;
form
.find("input[@checked], input[@type='text'], input[@type='hidden'], input[@type='password'], input[@type='submit'], option[@selected], textarea")
.filter(":enabled")
.each(function() {
	params[ this.name || this.id || this.parentNode.name+(i++) || this.parentNode.id+(i++) ] = this.value;
	});
$.ajax({
  	type: "POST",
  	url: "ajax.php?method=" + $(obj).attr('id'),
  	data: params,
  	beforeSend: function(msg){
  		form.parent().fadeOut('slow');
  		},
  	success: function(msg){
  		 
  		form.parent().fadeIn('slow'); 
    	form.parent().html(msg);
    	$("#form_builder_form_change_knowledge").knowledge_select();
  	}
});
}

function ajaxInsert(pic){

$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
var picture = $("#img_"+pic);

var attached_files = $("#attached_files");	
$.ajax({
  	type: "GET",
  	url: "ajax_insert.php?pict=" + pic,
  /*	beforeSend: function(msg){
  		},*/
  	success: function(msg){
			/*picture.children("span").html("img_"+msg);
			attached_files.append(picture);*/
			$("#blog_photos").html(msg);	
  	},
	error: function (data, status, e)
	{
		alert("Error: " + e + "Status: " + status);
	}
});	
}

function ajaxDelete(pic){

$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
var picture = $("#img_"+pic);

$.ajax({
  	type: "GET",
  	url: "ajax_delete.php?pict=" + pic,
  /*	beforeSend: function(msg){
  		},*/
  	success: function(msg){
			/*picture.remove();
			ajaxFileUpload(null,0);*/
			$("#blog_photos").html(msg);
  	},
	error: function (data, status, e)
	{
		alert("Error: " + e + "Status: " + status);
	}
});	
}

function ajaxFileUpload(obj, album)
{
$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});
		
var wrapperDiv = $("#attached_files");
$.ajaxFileUpload(
	{
	url:"ajax_upload.php?album=" + album,
	secureuri:false,
	fileElementId: $(obj).attr('id'),
	dataType: 'html',
	success: function (data, status)
	{
		$("#blog_photos").html(data);
	},
	error: function (data, status, e)
	{
		alert("Error: " + e);
	}
	}
)
}

