var _actu_type='News';
var _actu_position=0;
var _actu_articles_list_position=0;
var _actu_selected_tag=-1;

function _actu_load(selectedid){
	if(selectedid==null) {
		loadXML('actu.xml.php', 'actu.xsl', $('_actu_news'), 'Type='+_actu_type+'&Position='+_actu_position+'&SelectedTag='+_actu_selected_tag, false, function(xml){
			_actu_position = parseInt(xml.getElementsByTagName('position')[0].firstChild.nodeValue,10);
			if(_actu_position<0) _actu_position=0;
		});	
	} else {		
		loadXML('actu.xml.php', 'actu.xsl', $('_actu_news'), 'Type='+_actu_type+'&SelectedId='+selectedid+'&SelectedTag='+_actu_selected_tag, false, function(xml){
			_actu_position = parseInt(xml.getElementsByTagName('position')[0].firstChild.nodeValue,10);
			if(_actu_position<0) _actu_position=0;
		});	
	}
}
function _actu_articles_list_load(){
	if($('_articles_list')) loadXML('actions_list.xml.php', 'actions_list.xsl', $('_articles_list'), 'Position='+_actu_articles_list_position, false);
}
function _actu_tags_list_load(){
	if($('_actu_tags_list')) loadXML('actu_tags.xml.php', 'actu_tags.xsl', $('_actu_tags_list'), 'Type='+_actu_type, false);
}
function _actu_articles_list_next_position(){
	++_actu_articles_list_position;
	_actu_articles_list_load();
}
function _actu_articles_list_previous_position(){
	if(_actu_articles_list_position>0) --_actu_articles_list_position;
	_actu_articles_list_load();
}
function _actu_next_position(){
	++_actu_position;
	_actu_load();
}
function _actu_previous_position(){
	if(_actu_position>0){
		--_actu_position;
		_actu_load();
	}
}
function _actu_goTo(position, type){
	if(type==null || type==_actu_type){
		_actu_position=position;
		_actu_load();
	} else {
		if(type=='Article')
			document.location.href='actions.php?Id='+position;
		else if(type=='News')
			document.location.href='blog.php?Page='+position;
	}
}
function _actu_show_actions(){
	Element.show('_actu_actions');
	Element.hide('_actu_news');
}
function _actu_hide_actions(){
	Element.hide('_actu_actions');
	Element.show('_actu_news');
}
function _actu_get_tag(id){
	_actu_selected_tag=id;
	_actu_load();
	_actu_articles_list_load();
}
function _actu_comment_show(id){
	_actu_show_actions();
	loadXML('actu_comments.xml.php', 'actu_comments.xsl', $('_actu_actions'), 'NewsID='+id, false, null);
}
function _actu_comment_add(id){
	var xml = null
	if (document.implementation && document.implementation.createDocument)
		xml = document.implementation.createDocument("", "", null);
	else if (window.ActiveXObject)
		xml = new ActiveXObject("Microsoft.XMLDOM");
	
	var root = xml.createElement("dataset");
	xml.appendChild(root);
	
	var comment = xml.createElement("comment");
	root.appendChild(comment);
	
	var newsid = xml.createElement("newsid");
	newsid.appendChild(xml.createTextNode(id));
	comment.appendChild(newsid);
	
	loadXML(xml, 'actu_comments_insert.xsl', $('_actu_actions'), '', false);
	_actu_show_actions();
}
function _actu_comment_do(action, id, form){
	if(action=='Insert'){
		form.Texte.value = form.Texte.value.replace(/\n/g,"<br />");
		loadXML('actu_comments.xml.php', 'actu_comments_insert.xsl', $('_actu_actions'), getActionFromForm(form), false, null);
	} else if(action=='Delete'){
		loadXML('actu_comments.xml.php', 'actu_comments.xsl', $('_actu_actions'), 'Action=Delete&Id='+id, false, null);
		_actu_load();
	} else if(action=='Approve'){
		loadXML('actu_comments.xml.php', 'actu_comments.xsl', $('_actu_actions'), 'Action=Approve&Id='+id, false, null);
		_actu_load();
	}	
}
function _actu_comment_cancel(action, id, form){
	if(action=='Insert') _actu_hide_actions();
}