var active_page = 1;

function switchPage(page_radio)
{
	var pagenr = page_radio.value;
	
	if (pagenr != active_page)
	{
		var tekst = tinyMCE.get('tekst').getContent();
		
		// indien nodig een veld aanmaken om de tekst van het veld naartoe te verplaatsen
		if ($('tekst_'+ active_page) == null)
			$(page_radio.form).insert('<input type="hidden" name="tekst_'+ active_page +'" id="tekst_'+ active_page +'" value="" />');
		
		if ($('tekst_'+ pagenr) == null)
			$(page_radio.form).insert('<input type="hidden" name="tekst_'+ pagenr +'" id="tekst_'+ pagenr +'" value="" />');
		
		// de huidige tekst naar het veld schrijven van de pagina waar het bij hoort
		$('tekst_'+ active_page).value = tekst;
		
		// de tekst van de geselecteerde pagina in tinyMCE plaatsen
		tinyMCE.get('tekst').setContent($F('tekst_'+ pagenr));
		
		// de geselecteerde pagina op actief zetten
		active_page = pagenr;
	}
}

function addPage(button, page_name)
{
	var pagenr = 1;
	
	// het eerstvolgende paginanummer opzoeken
	while ($('titel_'+ pagenr) != null)
		pagenr++;
	
	$('cms_news_pages_index').firstDescendant().insert(
		'<tr>'+
		'	<td><input type="radio" name="page" value="'+ pagenr +'" id="page'+ pagenr +'" onclick="switchPage(this);" /><label for="page'+ pagenr +'">'+ page_name +' '+ pagenr +'</label></td>'+
		'	<td><input type="text" name="titel_'+ pagenr +'" id="titel_'+ pagenr +'" value="" size="80"></td>'+
        '</tr>'
	);
	
	$(button.form).insert('<input type="hidden" name="tekst_'+ pagenr +'" id="tekst_'+ pagenr +'" value="" />');
}

function toggleMultipage(checkbox)
{
	if (checkbox.checked)
		$('cms_news_pages_index').show();
	else
		$('cms_news_pages_index').hide();
}

/**
 * Als het links-cms wordt geopend vanuit een ander cms mag dat cms niet gereload worden bij sluiten
 * omdat het formulier daar in nog niet is opgeslagen.
 */
function closeCMS_Links_indexLinks()
{
	if (window.opener.name == 'popup_users') {
		window.close();
	}
	else {
		window.opener.location.href=window.opener.location.href;
		window.close();
	}
}

function showTagcloud(url) {
    var width = 600;
    var height = 450;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_tagcloud', attributes);
    w.focus();
}

function showTextpage(url) {
    var width = 500;
    var height = 400;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_textpage', attributes);
    w.focus();
}

function showAlbums(url) {
    var width = 700;
    var height = 400;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_albums', attributes);
    w.focus();
}

function showBanners(url) {
    var width = 750;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_banners', attributes);
    w.focus();
}

function showPodcasting(url) {
    var width = 750;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_podcasting', attributes);
    w.focus();
}

function showUploader(url) {
    var width = 450;
    var height = 400;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_albums_uploader', attributes);
    w.focus();
}

function showPoll(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_poll', attributes);
    w.focus();
}

function showEvent(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_event', attributes);
    w.focus();
}

function showBlogroll(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_blogroll', attributes);
    w.focus();
}

function showReport(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_report', attributes);
    w.focus();
}

function showTextpages(url) {
    var width = 700;
    var height = 500;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_textpages',attributes);
    w.focus();
}

function showChannels(url) {
    var width = 450;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_channels',attributes);
    w.focus();
}

function showReview(url) {
    var width = 650;
    var height = 450;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_reviews',attributes);
    w.focus();
}

function showUsers(url) {
    var width = 500;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_users',attributes);
    w.focus();
}

function showGroups(url) {
    var width = 500;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_groups',attributes);
    w.focus();
}

function showTags(url) {
    var width = 640;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_tags',attributes);
    w.focus();
}

function showArticles(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_articles',attributes);
    w.focus();
}

function showVideos(url) {
    var width = 650;
    var height = 660;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_videos',attributes);
    w.focus();
}

function searchRelated(url) {
    var width = 450;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_related',attributes);
    w.focus();
}

function editReactie(url) {
    var width = 650;
    var height = 450;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url, 'popup_reactie', attributes);
    w.focus();
}

function openPreview(content) {
    var w = window.open('/cms_preview.php?content='+ escape(content), 'preview', 'width=400, height=300, dependent=yes, alwaysRaised=yes');
    w.focus();
}

function showDocs(section)
{
	switch (section) {
		case 'nieuwsbericht':
			var w = window.open('/docs_nieuwsbericht.php','docs_nieuws','width=400,height=300,scrollbars=yes,dependent=yes, alwaysRaised=yes');
		    w.focus();
			break;
	}
}

function showLinks(url) {
    var width = 450;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +//', top='+ (mouse_y-10) +', left='+ (mouse_x-width-5) +
                     ', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_links',attributes);
    w.focus();
}

function showLinksPage() {
    var width = 450;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +//', top='+ (mouse_y-10) +', left='+ (mouse_x-width-5) +
                     ', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open('/cms_linkspage_categorieen.php','popup_linkspage',attributes);
    w.focus();
}

function showSyndication() {
    var width = 450;
    var height = 300;
    var attributes = 'width='+ width +', height='+ height +//', top='+ (mouse_y-10) +', left='+ (mouse_x-width-5) +
                     ', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open('/cms_rss_feeds.php','popup_syndication',attributes);
    w.focus();
}

function showMessages(url) {
    var width = 650;
    var height = 700;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_messages',attributes);
    w.focus();
}

/**
 * sfGuard admin popups
 */

function showSfGuardUsers(url) {
    var width = 800;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_sfguard_users',attributes);
    w.focus();
}

function showSfGuardPermissions(url) {
    var width = 800;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_sfguard_permissions',attributes);
    w.focus();
}

function showSfGuardGroups(url) {
    var width = 800;
    var height = 600;
    var attributes = 'width='+ width +', height='+ height +', scrollbars=yes, dependent=yes, alwaysRaised=yes, status=yes';

    var w = window.open(url,'popup_sfguard_groups',attributes);
    w.focus();
}