
function move_up(editlevel,ploegid,gallerystructid,id)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=move_up' + "&id=" + id + "&gallerystructid=" + gallerystructid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			edit_album(editlevel,ploegid,gallerystructid);
		}
	}
}


function save_changes(id,loadid,saveid,gallerystructid)
{
	check_acces();
	document.getElementById(saveid).style.display= 'none';
	document.getElementById(loadid).style.display= '';

	var waarde = document.getElementById(id).value;
	var definitief = urlencode(waarde);

	if(id =='showonwebsite')
	{
		if(document.getElementById(id).checked == true)
		{
			definitief='1';
		}
		else
		{
			definitief='0';
		}
	}

	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=save_field' + "&id=" + id + "&waarde=" + definitief + "&gallerystructid=" + gallerystructid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById(loadid).style.display= 'none';
			document.getElementById(saveid).style.display= '';
			
	
		}
	}
}


function init_uploadify(accountid,gallerystructid,editlevel,ploegid) 
{
	var link= 'photogalleryupload.php?give=' + accountid + '-' + gallerystructid;	

	$("#uploadify").uploadify({
		'uploader'       : 'uploadify/uploadify.swf',
		'script'         : link,
		'cancelImg'      : 'images/cancel.png',
		'folder'         : 'gallery/',
		'queueID'        : 'fileQueue',
		'auto'           : true,
		'multi'          : true,
		'onComplete'	 : function(event, queueID, fileObj, response, data) {
			      edit_album(editlevel,ploegid,gallerystructid);

		     }	
		
	});

}

	

function uitvoer_albums(editlevel,ploegid,website)
{
	if(document.getElementById('albumsearch'))
	{
		document.getElementById('albumsearch').style.display = '';	
	}
	var aantal='';
	var search='';
	if(document.getElementById('albums_aantal')){
		aantal = document.getElementById('albums_aantal').value;
	}
	if(document.getElementById('album_search')){
		search = document.getElementById('album_search').value;
	}	
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=uitvoer_albums' + "&editlevel=" + editlevel + "&ploegid=" + ploegid + "&website=" + website + "&aantal=" + aantal + "&search=" + search;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('photogallerycontainer').innerHTML = httpObj.responseText;	
		}
	}
}
function gallery_delete_album(editlevel,ploegid,gallerystructid)
{
	check_acces();
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=delete_album' + "&gallerystructid=" + gallerystructid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			uitvoer_albums(editlevel,ploegid);
		}
	}
}
function gallery_delete_image(editlevel,ploegid,picid,gallerystructid)
{	
	check_acces();
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=delete_image' + "&picid=" + picid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			
			edit_album(editlevel,ploegid,gallerystructid)
		}
	}
}
function edit_album(editlevel,ploegid,gallerystructid)
{
	check_acces();	
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=edit_album' + "&editlevel=" + editlevel + "&ploegid=" + ploegid + "&gallerystructid=" + gallerystructid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('editalbumcontainer').innerHTML = httpObj.responseText;	
		}
	}
}

function gallery_add_pictures(editlevel,ploegid,gallerystructid,accountid)
{
	check_acces();
	if(document.getElementById('albumsearch'))
	{
		document.getElementById('albumsearch').style.display = 'none';	
	}
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=add_pictures' + "&editlevel=" + editlevel + "&ploegid=" + ploegid + "&gallerystructid=" + gallerystructid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('photogallerycontainer').innerHTML = httpObj.responseText;	
			init_uploadify(accountid,gallerystructid,editlevel,ploegid);
			var uploadifyUploader=document.getElementById("uploadifyUploader"); 	
			edit_album(editlevel,ploegid,gallerystructid);
		}
	}
}
function gallery_view_album(editlevel,ploegid,gallerystructid,accountid,website)
{
	if(document.getElementById('albumsearch'))
	{
		document.getElementById('albumsearch').style.display = 'none';	
	}
	document.getElementById('photogallerycontainer').innerHTML='<img style="margin-top:10px;" src="images/loading.gif">';
	var aantal='';
	var search='';
	if(document.getElementById('albums_aantal')){
		aantal = document.getElementById('albums_aantal').value;
	}
	if(document.getElementById('album_search')){
		search = document.getElementById('album_search').value;
	}
	
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=view_album' + "&editlevel=" + editlevel + "&ploegid=" + ploegid + "&gallerystructid=" + gallerystructid + "&website=" + website + "&aantal=" + aantal + "&search=" + search;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('photogallerycontainer').innerHTML = httpObj.responseText;	
			$(function() {
				$('#photogallerycontainer a').lightBox({
				imageLoading: 'jquery/lightbox/images/loading2.gif',
				imageBtnClose: 'jquery/lightbox/images/close.gif',
				imageBtnPrev: 'jquery/lightbox/images/prev.gif',
				imageBtnNext: 'jquery/lightbox/images/next.gif',
				containerResizeSpeed: 250,
				containerBorderSize:0,
				overlayOpacity:0.9
				}); 
			});
		}
	}
}
function gallery_add_album(editlevel,ploegid,accountid)
{
	check_acces();
	openlightbox();
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=add_album' + "&editlevel=" + editlevel + "&ploegid=" + ploegid + "&accountid=" + accountid;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			document.getElementById('blackbox').innerHTML = httpObj.responseText;	
		}
	}
}

function gallery_insert_album(editlevel,ploegid,addploegid,showonwebsite,albumname, accountid)
{
	check_acces();
	if(document.getElementById('showonwebsite').checked == true)
	{
		var showonwebsite='1';
	}
	else
	{
		var showonwebsite='0';
	}

	openlightbox();
	var httpObj = ajaxFunction();
	var query = "photogalleryajax.php?qrnd=" + Math.random() + '&action=insert_album' + "&addploegid=" + addploegid + "&showonwebsite=" + showonwebsite + "&albumname=" + albumname;
	httpObj.open("GET",query, true);
	httpObj.send(null);
	httpObj.onreadystatechange = function()
	{
		if(httpObj.readyState == 4)
		{
			var gallerystructid = httpObj.responseText.replace(/^\s\s*/, "").replace(/\s\s*$/, "");	
			closelightbox();
			gallery_add_pictures(editlevel,ploegid,gallerystructid,accountid);
		}
	}
}


