var atkPage;
var atkSpecpage;

function displayTemplateSection()
{
	var group_switch = document.getElementsByName('group_tmpl_id_switch');
	var page_switch = document.getElementsByName('tmpl_id_switch');
	
	var group_switch_v;
	for (var i = 0; i < group_switch.length; i++)
		if (group_switch[i].checked){group_switch_v = group_switch[i].value; break;};
	
	var page_switch_v;
	for (var i = 0; i < page_switch.length; i++)
		if (page_switch[i].checked){page_switch_v = page_switch[i].value; break;};
	
	var display = group_switch_v == -1 || page_switch_v == -1 ? true : false;
	for (var i = 1; i <= 3; i++)
	{
		var tmpl_section = document.getElementById('TrTmplSection' + i);
		tmpl_section.style.display = display ? '' : 'none';
	}
	
	var tmpl_section_title = document.getElementById('TrTmplSectionTitle');
	tmpl_section_title.innerHTML = page_switch_v == -1 
		? '(used for this Page only)' 
		: '(used for all Pages of the Group)';
}

function displaySpecPages(display)
{
	var div = document.getElementById('DivSpecPages');
	div.style.display = display ? '' : 'none';
	
	displayMsgTagForm();
}

function displayMsgTagForm()
{
	var div = document.getElementById('DivMessageTagForm');
	
	var pageType = document.getElementsByName('type_page');
	var specpageType = document.getElementsByName('type_specpage');
	
	for (var i = 0; i < pageType.length; i++)
		if (pageType[i].checked){atkPage = pageType[i].value;break;}
	
	for (var i = 0; i < specpageType.length; i++)
		if (specpageType[i].checked){atkSpecpage = specpageType[i].value;break;}
	
	div.style.display = atkPage == 'special' && atkSpecpage && atkSpecpage != 'logout' ? '' : 'none';
	
	displayTagsHelp();
}

function displayProtectionTypes(display)
{
	var div = document.getElementById('DivProtectionTypes');
	div.style.display = display ? '' : 'none';
	
	displayMsgTagForm();
}

function displayMenu()
{
	var div = document.getElementById('DivGroupMenu');
	var cb = document.getElementById('group_menu_enabled');
	div.style.display = cb.checked ? '' : 'none';
	
	displayMsgTagForm();
}

function displayTagsHelp()
{
	var div = document.getElementById('DivTagsHelp');
	
	var protection;
	
	var group_protection = document.getElementsByName('group_protection');
	for (var i = 0; i < group_protection.length; i++)
		if (group_protection[i].checked){protection = group_protection[i].value;break;}
	
	var protection_level = document.getElementsByName('protection_level');
	if (protection_level.length)
	{
		for (var i = 0; i < protection_level.length; i++)
			if (protection_level[i].checked){protection_level_v = protection_level[i].value;break;}
		
		if (protection_level_v == 'page')
		{
			var protection_type = document.getElementsByName('protection_type');
			for (var i = 0; i < protection_type.length; i++)
				if (protection_type[i].checked){protection = protection_type[i].value;break;}
		}
	}
	
	div.style.display = protection == 'public' && (atkPage == 'ordinary' || atkSpecpage != 'profile') ? 'none' : '';
}
