// Show or Hide items
function hideElementID(uid, section, blockID) {
var id_minus = section + blockID + "minus";
var id_plus = section + blockID + "plus";
var id_block = section + blockID;
var id_block2 = section + blockID + "-2";
document.getElementById(id_minus).style.display='none';
document.getElementById(id_plus).style.display='inline';
document.getElementById(id_block).style.display='none';
if (section=='articles')
	document.getElementById(id_block2).style.display='none';
saveElementChange(uid, section, blockID, 'no');
}

function showElementID(uid, section, blockID) {
var id_minus = section + blockID + "minus";
var id_plus = section + blockID + "plus";
var id_block = section + blockID;
var id_block2 = section + blockID + "-2";
document.getElementById(id_minus).style.display='inline'
document.getElementById(id_plus).style.display='none'
document.getElementById(id_block).style.display='block';
if (section=='articles')
	document.getElementById(id_block2).style.display='inline';
saveElementChange(uid, section, blockID, 'yes');
}

function changeElementID(section, blockID) {
var id_block=section+blockID;
if (document.getElementById(id_block).style.display=='inline')
	document.getElementById(id_block).style.display='none';
else
	document.getElementById(id_block).style.display='inline';
}

function changeElementID2(section, blockID) {
var id_block=section+blockID;
if (document.getElementById(id_block).style.display=='table-row')
	document.getElementById(id_block).style.display='none';
else
	document.getElementById(id_block).style.display='table-row';
}

function CalendarTopic(uid, topic, element_id) {
if (document.getElementById(element_id).checked == 1)
	showCalendarTopic (uid, topic);
else
	hideCalendarTopic (uid, topic);
}

function hideCalendarTopic(uid, topic) {
var topic_prefix = "cal" + topic + "_";
var tr=document.getElementsByTagName("tr");
for (var i=0;i<tr.length;i++) { 
	var tr2 = tr[ i].id; 
	if (tr2.substring(0, topic_prefix.length) == topic_prefix)
			tr[ i].style.display='none';
}
if (topic == 1)
	saveElementChange(uid, "calendar", topic, 'no');
else
	saveElementChange(uid, "calendar", topic, 'yes');	
}

function showCalendarTopic(uid, topic) {
var topic_prefix = "cal" + topic + "_";
var tr=document.getElementsByTagName("tr");
for (var i=0;i<tr.length;i++) { 
	var tr2 = tr[ i].id; 
	if (tr2.substring(0, topic_prefix.length) == topic_prefix)
			tr[ i].style.display='inline';
}
if (topic == 1)
	saveElementChange(uid, "calendar", topic, 'yes');
else
	saveElementChange(uid, "calendar", topic, 'no');
}

// Record changes to show/hide items
// Initialize xmlHttp object
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

// Save visible / invisible changes
function saveElementChange(uid, section, section_id, item_visible)
{
if (section == 'grade')
	return;
var xmlHttp=GetXmlHttpObject();
var url="includes/ajax_element_change.php";
if (section == 'calendar')
	url="../includes/ajax_element_change.php";
url=url+"?uid="+uid;
url=url+"&section="+section;
url=url+"&section_id="+section_id;
url=url+"&item_visible="+item_visible;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}