
function switchTab(i)
{
	var img=document.getElementById('articles-tabs');
	if(i == 1)
	{
		img.src="images/btn_latestnews.jpg";
	}
	else if(i == 2)
	{
		img.src="images/btn_mostpopular.jpg";
	}
	else if(i == 3)
	{
		img.src="images/btn_lastviewed.jpg";
	}
	
}

var story = 1;
function topStory(id)
{
	if (id == 0)
	{
		id = story + 1;
		if(id > 5)
		{
			id = 1;
		}
	}
	
	for(var i = 1; i <= 5; i++)
	{
		var btn = document.getElementById("story_btn" + i);
		if(id == i)
		{
			btn.src = "images/btn_" + i + "_o.gif";
			
			//storyTitle X, storyDate X, storyLink X ?
			
		}
		else
		{
			btn.src = "images/btn_" + i + ".gif";		
		}
	}
	story = id;	
}

function pollSubmit()
{
}
function addEmail()
{
}
function inviteEmail()
{
}

var responseSuccess = function(o){
	var entries = new Array();
	var newsOutput = ""; 
	var response = o.responseText;	
	entries = response.split( '<|!!|>' );

	var maxVal = 4;
	if(entries.length-1 < 4)
	{
		maxVal = entries.length-1;
	}
	//alert(maxVal);
	newsOutput += '<h1 style="margin-top:15px; color: #990000">'+entries[0]+'</h1>';
	//alert(entries[0]);
	for (var i = 0; i<= maxVal;i++)
	{		
		var entry = entries[i];
		if(entry  && entry != "")
		{
			
			var info = new Array();
			info = entry.split( '<|!|>' );
			
			if(info.length > 1)
			{	
			newsOutput += '<h1 style="margin-top:15px">' + info[0] + '</h1>';
			newsOutput += '<p>' + info[2].replace(/(<([^>]+)>)/ig,"") + '</p>';
			newsOutput += '<table cellpadding="0" cellspacing="0" class="newsResult"><tr><td align="left"><span class="date">' + info[3] +  '</span></td><td align="right"><a href="' + info[1] + '" onClick="trackClick('+info[4]+');clicks()" target="_blank">Read More &gt; </a></td></tr></table>';
			//alert(newsOutput);
			}
		}
	}
	document.getElementById('newsFeed').innerHTML = newsOutput;

};

var responseFailure = function(o){
}

var callback =
{
  success:responseSuccess,
  failure:responseFailure
};
/*
function getFeed(url, header) 
{
	switchTab(1);
	//YAHOO.util.Connect.asyncRequest('POST', 'feed_info.php', callback, "url=" + escape(url).replace(new RegExp( "\\+", "g" ),"%2B"));
	YAHOO.util.Connect.asyncRequest('POST', 'feed_info.php', callback, "header='"+header+"'&url=" + encodeURIComponent(url));

}
*/
function getFeed(id) 
{
	switchTab(1);
	//YAHOO.util.Connect.asyncRequest('POST', 'feed_info.php', callback, "url=" + escape(url).replace(new RegExp( "\\+", "g" ),"%2B"));
	YAHOO.util.Connect.asyncRequest('POST', 'feed_info.php', callback, "id=" + id);

}


function getMostPopular()
{
	YAHOO.util.Connect.asyncRequest('POST', 'get_most_popular.php', callback, "");
}

function getLastViewed()
{
	YAHOO.util.Connect.asyncRequest('POST', 'get_last_viewed.php', callback, "");
}

function displayPage(i, title)
{
	var cb_def = {
		success: function(o) {
			showThickbox(o.responseText, title);
		},
		failure: function() {
		}
	}		
	var request = YAHOO.util.Connect.asyncRequest('POST', 'special_page.php', cb_def, 'id=' + i); 
}	

function trackClick(article)
{
	YAHOO.util.Connect.asyncRequest('POST', 'track_click.php', "", "id=" + article);
}

function highlight(divID)
{
var div = document.getElementById(divID);
div.style.fontWeight = "bold";
div.style.color = "#990000";
}


function unhighlight(divID)
{
var div = document.getElementById(divID);
div.style.fontWeight = "normal";
div.style.color = "#333333";
}

function unhighlightLearn(){
	for (var i=1; i<=10; i++){
		unhighlight(i);
	}
}

function toggleLearn(showID)
{
	unhighlightLearn();
	highlight(showID); 

}

function unhighlightDiscover(){

		unhighlight(lastID);

}
var lastID = 1;
function toggleDiscover(showID)
{
	unhighlightDiscover();
	highlight(showID); 
	lastID = showID;

}