	var position;
	var next;
	var prev;
	
	function loadHomeRotator() {
		document.getElementById("rotatorImg").src = 'images/articles/' + images[0];
		document.getElementById("homeRotatorTitleText").innerHTML = '<a href="article.php?id=' + id[0] + '">' + titles[0] + '</a>';
		document.getElementById("homeRotatorSubBarText").innerHTML = subtitles[0];
		document.getElementById("homeRotatorSubBarWhat").innerHTML = '1 of ' + length;
		document.getElementById("homeRotatorSelector").innerHTML = '<a href="javascript:rotateHomeRotator(1);"><img src="images/rightarrow.jpg" /></a> <a href="article.php?id=' + id[0] + '">view</a> <a href="javascript:rotateHomeRotator(' + (length-1) + ');"><img src="images/leftarrow.jpg" /></a>';
	}
	
	function rotateHomeRotator(which) {
		document.getElementById("rotatorImg").src = 'images/articles/' + images[which];
		document.getElementById("homeRotatorTitleText").innerHTML = '<a href="article.php?id=' + id[which] + '">' + titles[which] + '</a>';
		document.getElementById("homeRotatorSubBarText").innerHTML = subtitles[which];
		if(which == apl) {
			prev = which - 1;
			next = 0;
		} else if (which == 0) {
			prev = apl;
			next = 1;
		} else {
			prev = which - 1;
			next = which + 1;
		}

		document.getElementById("homeRotatorSubBarWhat").innerHTML = (which + 1) + ' of ' + length;
		document.getElementById("homeRotatorSelector").innerHTML = '<a href="javascript:rotateHomeRotator(' + next + ');"><img src="images/rightarrow.jpg" /></a> <a href="article.php?id=' + id[which] + '">view</a> <a href="javascript:rotateHomeRotator(' + prev + ');"><img src="images/leftarrow.jpg" /></a>';
	}

function ajax() {
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ro = new XMLHttpRequest();
	}
	return ro;
}

function trim(s) {
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}


function addComment2(what) {			
	var recaptcha_response_field = document.getElementById("recaptcha_response_field").value;
	var recaptcha_challenge_field = document.getElementById("recaptcha_challenge_field").value;
	var name = document.commentsForm.name.value;
	var comments = document.commentsForm.comments.value;
	comments = comments.replace("/n","<br>");
	var articleID = document.commentsForm.articleID.value;
	
	name = trim(name);
	comments = trim(comments);
	
	if(name == '' || comments == '') {
		alert("You must enter a name and a comment.");	
	} else {
	
		var ajx = new ajax;
		var params = 'recaptcha_response_field=' + recaptcha_response_field + '&recaptcha_challenge_field=' + recaptcha_challenge_field + '&name=' + name + '&comments=' + comments + '&articleid=' + articleID + '&what=' + what;
		ajx.open('POST', 'script/ajax.php?action=postComment',true);
		ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajx.setRequestHeader("Content-length", params.length);
		ajx.setRequestHeader("Connection", "close");
		ajx.onreadystatechange = function() {
			if(ajx.readyState == 4){
				response = ajx.responseText;
				if(response == 'fail') {
					alert("Your reCaptcha is incorrect.\nPlease enter the distorted words you see into the box.");		
				}
				if(response == 'win') {
					alert("Your comment has been posted. Thank you!");
					document.commentsForm.name.value = '';
					document.commentsForm.comments.value = '';
					window.location.reload()
				}
			}
		}
		ajx.send(params);
	}
}

function addComment3(what) {			
	var recaptcha_response_field = document.getElementById("recaptcha_response_field").value;
	var recaptcha_challenge_field = document.getElementById("recaptcha_challenge_field").value;
	var name = document.getElementById("commentname").value;
	var comments = document.getElementById("commentcomments").value;
	comments = comments.replace("/n","<br>");
	var articleID = document.getElementById("articleID").value;
	
	name = trim(name);
	comments = trim(comments);
	
	if(name == '' || comments == '') {
		alert("You must enter a name and a comment.");	
	} else {
	
		var ajx = new ajax;
		var params = 'recaptcha_response_field=' + recaptcha_response_field + '&recaptcha_challenge_field=' + recaptcha_challenge_field + '&name=' + name + '&comments=' + comments + '&articleid=' + articleID + '&what=' + what;
		ajx.open('POST', 'script/ajax.php?action=postComment',true);
		ajx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajx.setRequestHeader("Content-length", params.length);
		ajx.setRequestHeader("Connection", "close");
		ajx.onreadystatechange = function() {
			if(ajx.readyState == 4){
				response = ajx.responseText;
				if(response == 'fail') {
					alert("Your reCaptcha is incorrect.\nPlease enter the distorted words you see into the box.");		
				}
				if(response == 'win') {
					alert("Your comment has been posted. Thank you!");
					document.getElementById("commentname").value = '';
					document.getElementById("commentcomments").value = '';
					window.location.reload()
				}
			}
		}
		ajx.send(params);
	}
}
