function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("most-tabs") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("most") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
if (window.addEventListener) window.addEventListener("load", initTabs, false);
else if (window.attachEvent) window.attachEvent("onload", initTabs);

function textLimit(field)
{
	var maxlen = 1000;
	if (field.value.length > maxlen)
		field.value = field.value.substring(0, maxlen);
}
function updateScore(id, score, u)
{
	var url = 'http://www.lmtribune.com/includes/comments/update_score.php';
	var pars = 'id='+id+'&score='+score+'&userid='+u;

	var myAjax = new Ajax.Updater(
		'score'+id,
		url,
		{
			method: 'get',
			parameters: pars
		}
	);
}

function digg(id, user)
{
	//gave a thumbs up to the comment
	//add one to the counter
	//disable all images and change their src's

	if(document.getElementById('digg'+id).src=='http://www.lmtribune.com/templates/default/images/c-digg.png')
	{
		//disable both thumbs up and down
		//document.getElementById('bury'+id).disabled = true;
		//document.getElementById('digg'+id).disabled = true;

		//update comment score
		updateScore(id, 1, user);

		//change image src's to indicate they are inactive
		document.getElementById('bury'+id).src = 'http://www.lmtribune.com/templates/default/images/c-bury-off.png';
		document.getElementById('digg'+id).src = 'http://www.lmtribune.com/templates/default/images/c-digg-off.png';
	}
	else
	{
		//do nothing
		//alert('digg disabled');
	}
}

function bury(id, user)
{
	//thumbs down
	//subtract one from the counter
	//disable images and change their src's

	if(document.getElementById('bury'+id).src=='http://www.lmtribune.com/templates/default/images/c-bury.png')
	{
		//slide the comment up to hide it
		Effect.BlindUp("comment"+id);

		//update comment score
		updateScore(id, -1, user);

		//change image src's to indicate they are inactive
		document.getElementById("bury"+id).src = "http://www.lmtribune.com/templates/default/images/c-bury-off.png";
		document.getElementById("digg"+id).src = "http://www.lmtribune.com/templates/default/images/c-digg-off.png";

		document.getElementById("reply"+id).innerHTML = '';
	}
	else
	{
		//do nothing
		//alert('bury disabled');
	}
}

function toggleShow(link, comment)
{
	if(document.getElementById(link).innerHTML == '(show comment)')
	{
		Effect.BlindDown(comment);
		document.getElementById(link).innerHTML = '(hide comment)';
	}
	else
	{
		Effect.BlindUp(comment);
		document.getElementById(link).innerHTML = '(show comment)';
	}

}

function replyForm(id, one, two, md, user, storyid)
{
	var form = '';
	form += '<form action="http://www.lmtribune.com/insert_comment.php" method="post">';
	if(user != '')
	{
		form += '<input type="hidden" name="username" value="'+user+'" />';
	}else{
		form += 'Display Name: <input type="text" name="username" value="" />';
	}
	form += '<input type="hidden" name="storyid" value="'+storyid+'" />';
	form += '<input type="hidden" name="reply_to" value="'+id+'" />';
	form += '<textarea name="comment" onkeyup="textLimit(this)" wrap="hard" rows="10" cols="80"></textarea><br />';
	form += '<input type="hidden" name="sec_answer" value="'+md+'" />';
	form += 'Security Question: '+one+' + '+two+' = <input type="text" name="num_security" value="" size="3" /><br />';
	form += '<input type="submit" name="comment_submit" value="Submit" /></form>';

	//set the paragraph to something new
	document.getElementById('reply'+id).innerHTML = form;
}

function replyFormPoll(id, one, two, md, user, pollid)
{
	var form = '';
	form += '<form action="http://www.lmtribune.com/insert_poll_comment.php" method="post">';
	if(user != '')
	{
		form += '<input type="hidden" name="username" value="'+user+'" />';
	}else{
		form += 'Display Name: <input type="text" name="username" value="" />';
	}
	form += '<input type="hidden" name="pollid" value="'+pollid+'" />';
	form += '<input type="hidden" name="reply_to" value="'+id+'" />';
	form += '<textarea name="comment" onkeyup="textLimit(this)" rows="10" cols="80"></textarea><br />';
	form += '<input type="hidden" name="sec_answer" value="'+md+'" />';
	form += 'Security Question: '+one+' + '+two+' = <input type="text" name="num_security" value="" size="3" /><br />';
	form += '<input type="submit" name="comment_submit" value="Submit" /></form>';

	//set the paragraph to something new
	document.getElementById('reply'+id).innerHTML = form;
}

function checkUsername(name){

	var url = 'http://www.lmtribune.com/includes/checkname.php';
	var pars = 'name='+name;

	var myAjax = new Ajax.Updater(
		'name_available',
		url,
		{
			method: 'get',
			parameters: pars,
			success: 'name_available'
		}
	);
}







function printerFriendly(id){
	var temp = "http://www.lmtribune.com/print.php?id=" + id;
	window.open(temp,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=400, height=400");
}

function emailArticle(id){
	var temp = "http://www.lmtribune.com/email.php?id=" + id;
	window.open(temp,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=500, height=500");
}

function emailArchive(id){
	var temp = "http://www.lmtribune.com/email-archive.php?id=" + id;
	window.open(temp,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=500, height=500");
}
function printerFriendlyArchive(id){
	var temp = "http://www.lmtribune.com/print-archive.php?id=" + id;
	window.open(temp,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width=400, height=400");
}
