// JavaScript Document

/*
function expandArticle(article_id, synopsis_id, controller){
	
	controller.innerHTML='collapse';
	var region = YAHOO.util.Dom.getRegion(synopsis_id);
	var synopsis_height = region.bottom - region.top;
	controller.onclick=function(){shrinkArticle(article_id, synopsis_id, synopsis_height, controller);};
	 //YAHOO.util.Dom.setStyle(article_id, 'display', 'block'); 
	 
	 for(var i =0; i<article_heights.length; i++){
			if (article_heights[i].id == article_id){
				var height = parseInt(article_heights[i].height);
				break;
			}
	 }
	 
	 
	
	
	
	
	
    var anim = new YAHOO.util.Anim(article_id, {height: { from: 0, to: height }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	var anim_synopsis = new YAHOO.util.Anim(synopsis_id, {height: { to: 0 }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	anim.animate(); 
	anim_synopsis.animate();
	
}

function shrinkArticle(article_id, synopsis_id, synopsis_height, controller){
	
	controller.innerHTML='expand';
	controller.onclick=function(){expandArticle(article_id,synopsis_id, controller);};
	
	var anim = new YAHOO.util.Anim(article_id, {height: { to:0 }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	var anim_synopsis = new YAHOO.util.Anim(synopsis_id, {height: { to: synopsis_height }}, 1.0, YAHOO.util.Easing.easeBothStrong);
	anim.animate(); 
	anim_synopsis.animate();
	
}

var article_heights = new Array()
function init() { 
		var ec= new Array();
		ec = YAHOO.util.Dom.getElementsByClassName('article_content');
		
			for (var i=0; i<ec.length; i++){
				var id = ec[i].id;
				var region = YAHOO.util.Dom.getRegion(ec[i]);
				article_heights.push( {id:ec[i].id, height: (region.bottom-region.top)}); 
				
			}
				
	   YAHOO.util.Dom.setStyle(ec, "height", "0"); 
	   
	   openArticle();
	   
	  
	} 
	YAHOO.util.Event.onDOMReady(init);
	
*/
function selectAll(obj){
	if (obj.checked) {
		var mark = true;
	}
	else {
		var mark = false;	
	}
	var category_tags=document.getElementsByName("category_value[]");
	for (var i=0; i<category_tags.length; i++){
		category_tags[i].checked=mark;
	}
	updateArticles();
}

function updateSelectAll() {
	var category_tags=document.getElementsByName("category_value[]");
	
	for (var i=0; i<category_tags.length; i++){
		
		if(!category_tags[i].checked){
			document.getElementById("select_all").checked = false;
			updateArticles();
			return;
		}
	}
	document.getElementById("select_all").checked = true;
	updateArticles();
}

function updateArticles() {

	var content = '';

	var callback = 
	{
		success: function(o) {
			var feature_article = '<div class="featured_event_title" style="margin:30px 0px 0px 15px;overflow:visible"><h1 style="font-size:1.7em">There are no upcoming articles at this time.</h1></div>';
			var article_list = "";

			try{
				content = YAHOO.lang.JSON.parse(o.responseText);
			}
			catch (x){
				//alert("JSON Parse failed!");
				//return;
			}
			
			if(o.responseText !== undefined && content['content'] !== undefined){
				feature_article = content['content']['feature_article'];
				article_list = content['content']['article_list'];
			}
		 
			document.getElementById("featured_article").innerHTML = feature_article;  
			document.getElementById("article_list").innerHTML = article_list;  
			resetContentBackground();
		}, 
		failure: function(o) {document.getElementById("featured_article").innerHTML = '<h3 style="margin:20px;">Error retrieving data.</h3>';}, 
		timeout: 50000
	} 
	
	var formObject = document.getElementById('category_filter');
	YAHOO.util.Connect.setForm(formObject);
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/common/scripts/article_control.php', callback);
	document.getElementById("featured_article").innerHTML = '<h3 style="margin:20px;">Loading...</h3>';
}

function populateNewsArchive(year_only) {
	var callback = 
	{ 
	  success: function(o) {
		  var archive_month="", article_select='';
		  if(o.responseText != ""){
			 	//alert(o.responseText);
				eval(o.responseText);  
		  }
		 	if(archive_month != ""){
				//alert(archive_month);
				document.getElementById("archive_month").innerHTML = archive_month;  
				setupSplit({button:"archive_month_button", selectbox:"archive_month_select", onclick:setMonthValue});
			}
		 	if (article_select != ""){
		
			  	document.getElementById("archive_articles").innerHTML = article_select; 
				setupSplit({button:"archive_article_button", selectbox:"archive_article_select", onclick:launchEvent});
			}
		  
		  
		  }, 
	  failure: function(o) {/*failure handler code*/}, 
	  timeout: 50000
	} 
	document.getElementById("year_only").value = year_only;
	var formObject = document.getElementById('article_archive');
	
	YAHOO.util.Connect.setForm(formObject);
	var cObj = YAHOO.util.Connect.asyncRequest('POST', '/common/scripts/article_control.php', callback);
}


function launchEvent() {
		if (this.menu.activeItem.value != "")
		window.location='?id='+this.menu.activeItem.value;
}

function setYearValue() {
	
	var item_value = this.menu.activeItem.value;
	var item_label  = stripHTML(this.menu.activeItem.element.innerHTML);
	this.button.set("label", item_label)
	
	var my_form = document.getElementById("article_archive");
	my_form.year.value = item_value;
	populateNewsArchive(1);
	return false;
}

function setMonthValue() {
	
	var item_value = this.menu.activeItem.value;
	var item_label  = stripHTML(this.menu.activeItem.element.innerHTML);
	
	this.button.set("label", item_label, true)
	
	var my_form = document.getElementById("article_archive");
	
	my_form.month.value = item_value;
	populateNewsArchive(0);
	return false;
}


YAHOO.util.Event.onAvailable("archive_year_select",setupSplit, {button:"archive_year_button", selectbox:"archive_year_select", onclick:setYearValue}, true);
YAHOO.util.Event.onAvailable("archive_month_select",setupSplit, {button:"archive_month_button", selectbox:"archive_month_select", onclick:setMonthValue}, true);
YAHOO.util.Event.onAvailable("archive_article_select",setupSplit, {button:"archive_article_button", selectbox:"archive_article_select", onclick:launchEvent}, true);
YAHOO.util.Event.onContentReady("date_filter", function(){document.getElementById("date_filter").style.display="block";});

