function swapImage (name, src) {
	document[name].src = src;
}

function goRegister () {
	window.location = '/myaccount/register';
	return false;
}

function goMyAccount () {
	window.location = '/myaccount';
	return false;
}

function showHide(showId, hideId) {
	var showDiv = document.getElementById(showId);
	var hideDiv = document.getElementById(hideId);
	
	showDiv.style.display = 'inline';
	hideDiv.style.display = 'none';
	return true;
}


//shows the edit comments tedxtarea
function editPostingComment ( theId ) {
	//show the editable area
	var commentDiv     = 'pc_id_' + theId;
	var editCommentDiv = 'pc_id_edit_' + theId;
	showHide(editCommentDiv,commentDiv);
	
	//hide the edit 
	var editButtonDiv   = 'pce_' + theId;
	var cancelButtonDiv = 'pcc_' + theId;
	showHide(cancelButtonDiv,editButtonDiv);
}
//hides the editPostingComment
function hideEditPostingComment ( theId ) {
	//show the editable area
	var commentDiv     = 'pc_id_' + theId;
	var editCommentDiv = 'pc_id_edit_' + theId;
	showHide(commentDiv,editCommentDiv);
	
	//hide the edit 
	var editButtonDiv   = 'pce_' + theId;
	var cancelButtonDiv = 'pcc_' + theId;
	showHide(editButtonDiv,cancelButtonDiv);
}

function showHide_junk( mode, articleId) {
	//set and get all the divs
	var divName1 = 'article_teaser' + articleId;
	var divName2 = 'article_complete' + articleId;
	var divName3 = 'article_more' + articleId;
	var divName4 = 'article_less' + articleId;

	var teaserDiv   = document.getElementById(divName1);
	var completeDiv = document.getElementById(divName2);
	var moreDiv     = document.getElementById(divName3);
	var lessDiv     = document.getElementById(divName4);

	if ( mode === 'more' ) {
		completeDiv.style.display = 'inline';
		teaserDiv.style.display   = 'none';
		moreDiv.style.display     = 'none';
		lessDiv.style.display     = 'inline';
	}
	else {
		completeDiv.style.display = 'none';
		teaserDiv.style.display   = 'inline';
		teaserDiv.style.height    = '30px';
		teaserDiv.style.overflow  = 'hidden';
		moreDiv.style.display     = 'inline';
		lessDiv.style.display     = 'none';
	}
}

function showComments ( section, id, force ) {
	var client = getXMLRequestObj();
	var commentDiv = document.getElementById('comments_sec'+id);
	var postDiv    = document.getElementById('postcomment_sec'+id);

	if ( commentDiv.style.display == 'none' || force) {
		client.onreadystatechange = function () {
			//in case of network failures
			if ( client.readyState == 4 ) {
				if ( client.status == 200 ) {
					window.location.reload();
				}
			}
		}
	}
	else {
		commentDiv.style.display = 'none';
		postDiv.style.display = 'none';
	}

	client.open("GET", '/articles/'+section+'/'+id, true);
	client.send(null);

	return false;
}

function postComment_old (theForm) {
	var id      = theForm.articleid.value;
	var section = theForm.section.value;
	var comment = theForm.comment.value;
	var loginid = theForm.posterid.value;

	if ( comment.length ) {
		var client  = getXMLRequestObj();

		client.onreadystatechange = function () {
			if ( client.readyState == 4) {
				if ( client.status == 200 ) {
					if ( client.responseText == 'SAVED' ) {
						//update the number of comments
						var numPostsDiv       = document.getElementById('numposts'+id);
						var numPosts          = parseInt(numPostsDiv.innerHTML) + 1;
						numPostsDiv.innerHTML = numPosts;

						//call the showComments functions
						showComments(section, id, 1);

						//clear out the comment field
						var commentForm = document.getElementById ('comment_area' + id);
						commentForm.value = '';
					}
				}
			}
		}

		//send the posting...
		var url = '/articles/postcomment/'+id+'?login_id='+loginid+'&comment='+comment;
		client.open("GET", url, true);
		client.send(null);
	}

	return false;
}
function postComment (theForm) {
	var id      = theForm.articleid.value;
	var section = theForm.section.value;
	var comment = theForm.comment.value;
	var loginid = theForm.posterid.value;
	
	if ( ! comment.length ) {
		alert ('Pleae enter a commnet.');
		return false;
	}

	var url = '/articles/postcomment/'+id+'?login_id='+loginid+'&comment='+comment+'&section='+section;
	window.location = url;
	return false;
}

function editComment (theForm) {
	var id      = theForm.postingid.value;
	var comment = theForm.comment.value;

	if ( comment.length ) {
		var client  = getXMLRequestObj();

		client.onreadystatechange = function () {
			if ( client.readyState == 4) {
				if ( client.status == 200 ) {
					if ( client.responseText == 'SAVED' ) {
						window.location.reload();
					}
				}
			}
		}

		//send the posting...
		var url = '/articles/editcomment/'+id+'?comment='+comment;
		client.open("GET", url, true);
		client.send(null);
	}

	return false;
}
var btnWhichRateButton; // global button variable
function rateIt (theForm) {
	var id      = theForm.postingid.value;
	var loginid = theForm.posterid.value;
	var rating  = btnWhichRateButton.value;
	
	var client  = getXMLRequestObj();
	client.onreadystatechange = function () {
		if ( client.readyState == 4) {
			if ( client.status == 200 ) {
				if ( client.responseText == 'SAVED' ) {
//					alert ('Rating Saved');
//					window.location.reload();
				}
			}
		}
	}

	//send the rating...
	var url = '/articles/rateposting/'+id+'?login_id='+loginid+'&rating='+rating;
	client.open("GET", url, true);
	client.send(null);

	return false;
}

function showRating (theButton) {
	//set the images from 1 to theButton.value to the yellow image.
	for ( var i = 1; i <= theButton.value; i++) {
		var img = 'rating_' + i;
		var imgElement = document.getElementById(img);
		imgElement.src = "/images/ratings/yellow_" + i + ".jpg";
	}
	
	//set the rest to the white image
	var nextRating = parseInt(theButton.value) + 1;
	for ( var j = nextRating; j <= 7; j++ ) {
		var img = 'rating_' + j;
		var imgElement = document.getElementById(img);
		imgElement.src = "/images/ratings/white_" + j + ".jpg";
	}
	
	return false;
}

function toggle(id){
	ul = "ul_" + id;
	img = "img_" + id;
	ulElement = document.getElementById(ul);
	imgElement = document.getElementById(img);
	if (ulElement){
		if (ulElement.className == 'closed'){
			ulElement.className = "open";
			imgElement.src = "/images/nav/opened.gif";
		}else{
			ulElement.className = "closed";
			imgElement.src = "/images/nav/closed.gif";
		}
	}
}

function flagArticle (id) {
	if ( id.length ) {
		var client  = getXMLRequestObj();

		client.onreadystatechange = function () {
			if ( client.readyState == 4) {
				if ( client.status == 200 ) {
					if ( client.responseText == 'SAVED' ) {
						//update the number of comments
						alert ('This article has been flagged for review.')
					}
				}
			}
		}

		//send the posting...
		var url = '/articles/flagged/'+id;
		client.open("GET", url, true);
		client.send(null);
	}
	return false;
}

//preload images
image1 = new Image();
image1.src = '/images/buttons/submissions_roll.gif';

//navigation menu images
image2 = new Image();
image2.src = '/images/nav/menu/nav_ro_01.jpg';
image3 = new Image();
image3.src = '/images/nav/menu/nav_ro_03.jpg';
image4 = new Image();
image4.src = '/images/nav/menu/nav_ro_05.jpg';
image5 = new Image();
image5.src = '/images/nav/menu/nav_ro_07.jpg';
image6 = new Image();
image6.src = '/images/nav/menu/nav_ro_09.jpg';
image7 = new Image();
image7.src = '/images/nav/menu/nav_ro_11.jpg';
image8 = new Image();
image8.src = '/images/nav/menu/nav_ro_13.jpg';

//archive icons
image9 = new Image();
image9.src = '/images/nav/opened.gif';
image10 = new Image();
image10.src = '/images/nav/closed.gif';
