window.onload = function()
{
	if ( self.init ) init();
}



function initTips()
{
	var tips = document.getElementsByTagName( 'I' );
	if ( tips.length == 0 ) return;
	for ( var i = 0; i < tips.length; i++ ) {
		tips[i].onmouseover = function() {
			this.getElementsByTagName( 'SPAN' )[0].style.display = 'block';
		}
		tips[i].onmouseout  = function() {
			this.getElementsByTagName( 'SPAN' )[0].style.display = 'none';
		}
	}
}



function initFormatOptions()
{
	var divs = document.getElementsByTagName( 'DIV' );
	var popupLink;
	for ( var i = 0; i < divs.length; i++ ) {
		if ( divs[i].className != 'formatOptions' ) continue;
		popupLink = divs[i].getElementsByTagName( 'A' )[0];
		popupLink.onclick = function() {
			var url = this.getAttribute( 'href' );
			openPopup( url );
			return false;
		}
	}
}



function openPopup( url )
{
	popupWidth  = 540;
	popupHeight = 300;
	windowWidth = document.body.offsetWidth;
	windowLeft  = ( windowWidth - 570 ) / 2;
	window.open( url + "", "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=1,resizable=1,copyhistory=yes,width=" + popupWidth + ",height=" + popupHeight + ",left=" + windowLeft + ",top=300" )
}

	

function initDeleteCat()
{
	var allTds = document.getElementsByTagName( 'td' );
	for ( var i = 0; i < allTds.length; i++ ) {
		if ( allTds[i].className.indexOf('delete') == -1 ) continue;
		allTds[i].onclick = deleteCat;
	}
}



function deleteCat()
{
	var catId       = this.parentNode.getElementsByTagName( 'TD' )[0].getAttribute( 'id' ).match( /\d+$/ );
	var catName     = document.getElementById( 'catName-' + catId ).innerHTML;
	var subCatCount = document.getElementById( 'subCatCount-' + catId ).innerHTML;
	var itemCount   = document.getElementById( 'itemCount-' + catId ).innerHTML;
	
	if ( subCatCount > 0 ) {
		var msg = "De categorie '" + catName + "' bevat subcategorieën\nen kan daarom niet gewist worden.\n\n" +
		          "Wis eerst de subcategorieën of verplaats\nze naar een andere categorie.";
	}
	else if ( itemCount > 0 ) {
		var msg = "De categorie '" + catName + "' bevat foto's\nen kan daarom niet gewist worden.\n\n" +
		          "Wis eerst de foto's of verplaats ze\nnaar een andere categorie.";
	}
	else if ( catId <= 1000 ) {
		var msg = "Deze categore kan niet gewist worden.\n\n";
	}
	
	if ( msg ) {
		alert( msg );
	}
	else if ( confirm("Categorie '" + catName + "' wissen?") ) {
		window.location.href = 'overview.php?catDelete=' + catId;
	}
	
}



function toggleLayer( idLayer, idLink )
{
	var objLayer = document.getElementById( idLayer );
	var objLink  = document.getElementById( idLink );
	if ( !objLink || !objLayer ) return;
	
	objLink.style.cursor         = 'default';
	objLink.style.textDecoration = 'none';
	
	objLink.onmouseover = function() {
		objLayer.style.visibility = 'visible';
	}
	objLink.onmouseout  = function() {
		objLayer.style.visibility = 'hidden';
	}
}
