// get all open elements of an article and store the ids of those elements
function saveArticleLayout(id) {
	// get the article we are talking about
	var el = YAHOO.util.Dom.get(id);
	// get an array with the ids of open divs in the article
	open = YAHOO.util.Dom.getElementsBy(hasBlock,'div',el);
	for(var i = 0; i < open.length; ++i) {
		open[i] = open[i].id; // we only want the ids
//		alert(open[i]); // for testing purposes
	}
// return open;
}

function insertSaveOpenArticles() {
	var body = document.getElementById('body');
	var div = document.createElement('div');
	div.setAttribute('class','save');
	div.setAttribute('style','position:absolute; right: 0px;');
	div.innerHTML = '<a href="javascript:saveOpenArticles()"><img src="style/save.gif" style="float: left;">&nbsp;open articles</a>';
	body.appendChild(div);
}

// get the ids of all open articles 
function saveOpenArticles(root) {
	alert('please wait until you get a confirmation that the open articles are saved');
	var level2 = YAHOO.util.Dom.getElementsByClassName('level2');
	var open = [];
	var levels = [];
	for(i=0; i<level2.length; ++i) {
		// if level 2's id != upcoming or archive then it's current
		if( (level2[i].id != "upcoming") && (level2[i].id != "archive" ) && (level2[i].id != "about" ) ) {
			if(hasBlock(level2[i])) open.push(level2[i].id);
		} else {
			// check open articles
			// if level2.id != current id then the articles are the divs on level3
			nodes = YAHOO.util.Dom.getElementsByClassName('level3','div',level2[i]);
			for(j=0;j<nodes.length;++j) {
				if(hasBlock(nodes[j])) open.push(nodes[j].id);
			}
			// check if upcoming and archive are open
			if(level2[i].id == "upcoming") {
				if(hasBlock(level2[i])) {
					levels.push('upcoming');
					alert('upcoming is open');
				}
			}
			if(level2[i].id == "archive"){
				if(hasBlock(level2[i])) {
					alert('archive is open');
					levels.push('archive');
				}
			}
		}
	}
	alert(open.length + ' article(s) are saved as open');
	document.articlesform.openlevels.value=levels;
	document.articlesform.openarticles.value=open;
	document.articlesform.submit();
}

// check if the element is open 
function hasBlock(el) {
	if(el.style.display == 'block') return true;
	else return false;
}
