window.onload = function() {
	loadLibrary("/js/framework.js",ajaxReady);
}

function ajaxReady() {
	getId();
}

function getId() {
	urlParts = parseUrl();

	var url = "/comments.cfm?action=getId&path=" + escape(urlParts[1]) + "&page=" + escape(urlParts[2]) + "&queryString=" + escape(urlParts[3]);



	ajaxRequest(url,addHtml);
}

function addHtml(contentId) {
	addControls(contentId);
	getComments(contentId);
}

function addControls(contentId) {
	commentsControls = "<div id=\"feedback\"><span class=\"title\">FEEDBACK</span><br /><br />Have thoughts on this article? Share them by submitting feedback.<br /><br />You can view other people's comments by jumping to the bottom of the page.<br /><br /><div><a href=\"/comments.cfm?id=" + contentId + "\" class=\"buttonlink\">SUBMIT FEEDBACK</a> <a href=\"#comments\" class=\"buttonlink\">READ COMMENTS</a></div></div>";
	
	var rightDiv = document.getElementById("right");

	mainContent = rightDiv.innerHTML;
	
	rightDiv.innerHTML = commentsControls + mainContent;
}

function getComments(contentId) {
	var urlParts = parseUrl();
	
	var url = "/comments.cfm?action=getComments&id=" + contentId;


	ajaxRequest(url,addComments);	
}

function addComments(commentsHtml) {
	var commentsDiv = document.createElement("div");
	commentsDiv.innerHTML = commentsHtml;

	var rightDiv = document.getElementById("right");

	rightDiv.appendChild(commentsDiv);
}

function loadLibrary(lib,callback) { scriptTag = document.createElement("script"); scriptTag.src = "http://" + window.location.host + lib;  scriptTag.type = "text/javascript"; head = document.getElementsByTagName("head").item(0); head.appendChild(scriptTag); scriptTag.onload = function() { callback(); }; scriptTag.onreadystatechange = function() { callback(); }; scriptTag.onreadystatechange = function() { if(scriptTag.readyState == "loaded") { callback(); } }; }
