// Must be loaded BEFORE handle_events.js
// callerID=13&cid=Gig3O1217980476

	var hostdomain = "www.illinois-valley-news.com";
	var wwwcheck = window.location.href.split('/');
	var iswww = 0;
	for (i=0; i<wwwcheck.length; i++) {
		if (wwwcheck[i].substr(0,3) == 'www') {iswww = 1;}
	}
	if (iswww == 0) {hostdomain = "illinois-valley-news.com";}
	var req = false;
	var clinklist = new Array();
	var clinkstring = "";
	var nullcount = 1;
	
	function linkloader() {
		var andarray, eqarray;
		if (clinklist.length) {
			for (i=0; i<clinklist.length; i++) {
				andarray = clinklist[i].split('&');
				eqarray = andarray[0].split('=');
				clinkstring += (i + ' ' + eqarray[1] + ' ');
				eqarray = andarray[1].split('=');
				clinkstring += (eqarray[1] + '|');
			}
			getlinkdata();
		}
	};
	
	function getlinkdata() {
		nullcount++;
		url = ("http://" + hostdomain + "/scripts/comments/fplinks.pl?enum=" + nullcount);
		poststr = 'linkstr=' + clinkstring;
		req = false;
		if (window.XMLHttpRequest) { req = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				try {req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {}
			}
		}
		if (req) {
			req.onreadystatechange = function() {getdata();}
			req.open("POST", url, 1);
			req.send(poststr);
		} else {alert("Unfortunately, your browser does not support the Javascript functions used in the comments system.");}
	}

	function getdata() {
		if (req.readyState == 4) {
			if (req.status == 200) {
				if (req.responseText != " ") {
					var linklist = req.responseText.split('|');
					if (linklist.length) {
						var trio, spanid, linktext, newlink, newtext, thespan;
						for (var x=0; x<linklist.length; x++) {
							// three elements: 0=sequence, 1=comment count, 2=link URL
							trio = linklist[x].split(' ');
							spanid = "hcmt" + trio[0];
							linktext = '(Comments: ' + trio[1] + ')';
							newlink = document.createElement("a");
							newlink.href = trio[2];
							newlink.target = "_blank";
							newtext = document.createTextNode(linktext);
							newlink.appendChild(newtext);
							thespan = document.getElementById(spanid);
							thespan.appendChild(newlink);
						}
					}
				}
			}
		}
	}

/* This goes in the HTML body where each link is to appear
<script type="text/javascript">document.write("<span class='fpcommentlink' id='hcmt" + clinklist.length + "'></span>");clinklist.push("callerID=13&cid=Gig3O1217980476");</script>
*/


