$(document).ready(function() {
 
    var shown = false;
 
   // -- toggle display
   $('#content_header').click(function() {
		
		$('#text_block').slideToggle("slow");
		if($(this).attr('class') == 'report_news_header_on')
		{
		    $(this).removeClass('report_news_header_on');
		    $(this).addClass('report_news_header');
		} else
		{
			$(this).removeClass('report_news_header');
			$(this).addClass('report_news_header_on');
		} 
   });
 
 
    $('.report_news_header').click(function() {
		
		if(!shown && ($('.report_news_header_minus').css('display') == 'none'))
		{
		   
		    $('.report_news_header_cross').change();									
	
	    } else if(shown || ($('.report_news_header_cross').css('display') == 'none'))
	    { 
	 
		   $('.report_news_header_minus').change();	
		}
		
	});
 
 
	$('.report_news_header_cross').change(function() {
     
	    var id = this.id;
	    var active_block = (this.id + '_block');
		//alert(active_block);
		$("#" + active_block).slideDown("slow");
		$(this).parent().addClass("report_news_header_on");
		$(this).hide();
		$("#" + id + " .report_news_header_minus").show();
		 shown = true;
	});
	
	
	$('.report_news_header_minus').change(function() {
	    
		var id = this.id;
	    var active_block = (this.id + '_block');
		//alert(active_block);
		$("#" + active_block).slideUp("slow");
		$(this).parent().removeClass("report_news_header_on");
		$(this).hide();
		$("#" + id + " .report_news_header_cross").show();
		shown = false;
	});
	
	
});



/**
* tbc: need a way to retrieve content and region_state
*
* for auto-saving an article as a draft
* 
*/
function autoSave() 
{
    var aForm = document.create_report;
	
	// get the content
	var oEditor = FCKeditorAPI.GetInstance('content');
	oEditor.UpdateLinkedField();
	
	var region_state = '';
	var license_type = '';
	var category_2 = '';
	var authorID = '';
	var revisionNote = '';
	if(aForm.region_state) {
	   region_state = aForm.region_state.value;
	} 
	if(aForm.license) {
	   license_type = aForm.license.value;	
	} 
	if(aForm.category_2) {
	    category_2 = aForm.category_2.value;
    }
	if(aForm.authorID) {
		authorID = aForm.authorID.value;
	}
	if(aForm.revision_note) {
	   revisionNote = aForm.revision_note.value;
	}
	
    $.post(AJAX_DIR+'/account/autosave.php', 
	   { title: aForm.title.value, 
	     category_1: aForm.category_1.value, 
	     region:  aForm.region.value, 
	     content: aForm.content.value,
		 license_type: license_type,
		 region_state: region_state,
		 category_2: category_2,
		 tags: aForm.tags.value,
		 articleID: aForm.articleID.value,
		 groupID: aForm.groupID.value,
		 status: aForm.status.value,
		 revise: (aForm.action.value == 'revise_report'),
		 authorID: authorID,
		 revisionNote: revisionNote
	   }, function(result) { aForm.articleID.value = result; });
	
   window.setTimeout('autoSave()', 90*1000);
   return false;
}