/* Sorteren :) */
window.addEvent('domready', function(){
			
	var Lijst = $$('#menuSort');
	var Lijstinside = $$('#menuSort tbody');
	
	var subLijst = $$('.submenuSort');
	var subLijstinside = $$('.submenuSort tbody');
	
	var Count = 0;
	var myRequest = new Request({method: 'get', url: '/other/ajax/updateMenu.php'});
	
	$$('tbody:nth-child(2n)').setStyles({ background: "#eeeeee" });
	$$('tbody:nth-child(2n+1)').setStyles({ background: "#e5e5e5" });
	$$('.beneath tbody:nth-child(2n)').setStyles({ background: "#bebebe" });
	$$('.beneath tbody:nth-child(2n+1)').setStyles({ background: "#c7c7c7" });
	$$('.beneath td:nth-child(last)').setStyles({ border: "none" });
	
	new Sortables( Lijst, {
		constrain: true,
    	clone: false,
    	onSort: function(el) {
			el.setStyles({ background: "#f0ffe5" });
		},
		onComplete: function( el )
		{
			myRequest.send('sort=hoofd&details='+this.serialize( Lijstinside.id ) );
			
			$$('tbody:nth-child(2n)').setStyles({ background: "#eeeeee"});
			$$('tbody:nth-child(2n+1)').setStyles({ background: "#e5e5e5"});
			$$('.beneath tbody:nth-child(2n)').setStyles({ background: "#bebebe"});
			$$('.beneath tbody:nth-child(2n+1)').setStyles({ background: "#c7c7c7"});
		}
	});
	
	new Sortables( subLijst, {
		constrain: true,
    	clone: false,
    	onSort: function( el )
   	 	{
    		el.setStyles({ background: "#bebebe" });
    	},
		onComplete: function( el )
		{
			$$('.beneath tbody:nth-child(2n)').setStyles({ background: "#bebebe"});
			$$('.beneath tbody:nth-child(2n+1)').setStyles({ background: "#c7c7c7"});

			myRequest.send('sort=sub&oi='+el.getParent().id+'&details='+this.serialize( subLijstinside.id ) );
		}
	});
	
	var Tiptips = new Tips( $$('.tooltip'), {
   		className: 'tiptip',
   		onShow: function(el) {
			el.set( 'opacity', '0.8' );
		}
	});
	
});
	
/* Maakt het huidige veld leeg */
function clickClear( thisfield, defaulttext )
{
	if( thisfield.value == defaulttext )
	{
		thisfield.value = "";
	}
}

/* Zet standaardwaarde weer terug */
function clickRecall( thisfield, defaulttext )
{
	if( thisfield.value == "" )
	{
		thisfield.value = defaulttext;
	}
}

function pageToggle( Xv )
{
	if( Xv == true )
	{
		document.getElementById("showHoofd").style.display = ''; 
	}
	else if( Xv == false )
	{
		document.getElementById("showHoofd").style.display = 'none'; 
	}
}

function seoShow()
{
	if( document.getElementById("seoOptions").style.display == 'none' )
	{
		document.getElementById("seoOptions").style.display = ''; 
	}
	else
	{
		document.getElementById("seoOptions").style.display = 'none'; 
	}
}

function Toggle(thediv)
{ 
	document.getElementById("hoofditem").style.display = "none"; 
	if( thediv == 'subitem' ) { document.getElementById("linkonly").style.display = ''; }
	document.getElementById("subitem").style.display = "none"; 
	document.getElementById(thediv).style.display = ''; 
}

function Toggle2(thediv)
{ 
	document.getElementById("linkonly").style.display = "none"; 
	if( thediv !== 'none' ) { document.getElementById(thediv).style.display = ''; }
}

function goDelInst( inst )
{
	window.location="/admin/instellingen/dellang/"+inst;
}

function pageToggle3(thediv)
{ 
	if( thediv == false )
	{
		document.getElementById("showHoofd").style.display = "none"; 
	}
	else 
	{
		document.getElementById("showHoofd").style.display = "";
	}
}

function toggleDelete( delId, sortDel )
{
	if( sortDel == '' )
	{
		document.getElementById("confirmDel").style.display='';
		document.getElementById("confirmDelId").innerText=delId+' ';
	}
	else
	{
		document.getElementById("confirmDel").style.display='';
		document.getElementById("confirmDelId").innerText=delId+' ';
		document.getElementById("sortDel").innerText=sortDel;
		window.mySort = sortDel;
		window.mySortId = delId;
	}
}

function urlencode(str)
{
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/@/g, '%40');
}

function goDelete( sortGo )
{
	if( sortGo == 'bestanden' )
	{
		var conId = document.getElementById("confirmDelId").innerText;
		var sortId = document.getElementById("sortDel").innerText;
		window.location="/admin/bestanden/del/" + sortId + "/" + conId;
	}
	else if( sortGo == 'downloads' )
	{
		var conId = document.getElementById("confirmDelId").innerText;
		var sortId = document.getElementById("sortDel").innerText;
		window.location="/admin/downloads/del/" + sortId + "/" + conId;
	}
	else if( sortGo == 'pages' )
	{
		var conId = document.getElementById("confirmDelId").innerText;
		var sortId = document.getElementById("sortDel").innerText;
		window.location="/admin/pages/del/" + sortId + "/" + conId;
	}
	else if( sortGo == 'beheerder' )
	{
		var conId = document.getElementById("confirmDelId").innerText;
		//var sortId = document.getElementById("sortDel").innerText;
		window.location="/admin/beheerders/del/" + conId;
	}	
	else if( sortGo == 'nieuws' )
	{
		var conId = document.getElementById("confirmDelId").innerText;
		//var sortId = document.getElementById("sortDel").innerText;
		window.location="/admin/modules/nieuws/del/" + conId;
	}
	else
	{
		if( window.mySort == 'gebruiker' )
		{
			window.location = "/admin/modules/downloads/del/gebruiker/" + window.mySortId;
		}
		else
		{
			alert( 'Verwijderen onmogelijk1' );
		}
	}
}

function annuDelete( )
{
	document.getElementById("confirmDel").style.display='none';
}

function showAangepast( )
{
	if( document.getElementById("urlaangepast").style.display == 'none' )
	{
		document.getElementById("urlaangepast").style.display='';
	}
	else
	{
		document.getElementById("urlaangepast").style.display='none';
	}
}

function updateUrl(  )
{
	if( document.getElementById("urlaangepast").style.display != 'none' )
	{
		var updateVar = urlencode( document.getElementById("gewensteUrl").value );
		document.getElementById("updateUrlValue").innerText= updateVar+'.html';
	}
	else
	{
		var updateVar = urlencode( document.getElementById("updateNaam").value.toLowerCase() );

		document.getElementById("gewensteUrl").value=updateVar;
		document.getElementById("updateUrlValue").innerText=updateVar+'.html';
	}
}

function showMenup( x )
{
	if( x == 'menuopt1' )
	{
		document.getElementById("menuopt1").style.display='';
		document.getElementById("menuopt2").style.display='none';
	}
	else if( x == 'menuopt2' )
	{
		document.getElementById("menuopt2").style.display='';
		document.getElementById("menuopt1").style.display='none';
	}
}

function toggleSubItem( xD )
{
	if( xD == 'subitem' )
	{
		document.getElementById("subitem_1").style.display='';
	}	
	else
	{
		document.getElementById("subitem_1").style.display='none';
	}
}
