function CommentToggle(iParent, iId)
{
	if ((document.getElementById("ChildCommments_"+iParent).innerHTML == "") || (document.getElementById("ChildCommments_"+iParent).innerHTML == " ...reply comments")) {
		ShowComment(iParent, "./AjaxPages/Comments.php?comic="+iId+"&parent="+iParent);
	}
	else {
		HideComment(iParent);
	}
}

function ShowComment(iParent, url)
{
	loadCommentXMLDoc(iParent, url);
	document.getElementById("ChildCommments_"+iParent).style.display = "block";
	document.getElementById("CommentToggle_"+iParent).innerHTML = "-";
}

function HideComment(iParent)
{
	document.getElementById("ChildCommments_"+iParent).innerHTML = "";
	document.getElementById("CommentToggle_"+iParent).innerHTML = "+";
}

function LoadComments(sSource,iParent) {
	document.getElementById("ChildCommments_"+iParent+"").innerHTML = sSource;
}

function loadCommentXMLDoc(iParent, url) {
	var req;
	req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest) {
  	try {
			req = new XMLHttpRequest();
    }
		catch(e) {
			req = false;
    }
    	// branch for IE/Windows ActiveX version
  }
	else if(window.ActiveXObject) {
  	try {
   		req = new ActiveXObject("Msxml2.XMLHTTP");
  	}
		catch(e) {
    	try {
    		req = new ActiveXObject("Microsoft.XMLHTTP");
    	}
			catch(e) {
    		req = false;
    	}
		}
  }
	if(req) {
		//req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.onreadystatechange = function () {
		if (req.readyState == 4) {
			if(req.status == 200)
				LoadComments(req.responseText,iParent);
			else
				LoadComments("Error loading page<br>"+req.responseText,iParent);
			}
		};
		req.send(null);
	}
}

function LoadCommentAndClose(iParent, iId, hndPopup)
{
	//CommentShow(iParent, "http://www.chubbynickel.com/AjaxPages/Comments.php?comic="+iId+"&parent="+iParent);
	PopupManager.ClosePopup(hndPopup);
	document.location.href = document.location.href;
}

function ClosePopup(hndPopup)
{
	PopupManager.ClosePopup(hndPopup);
	document.location.href = document.location.href;
}

function NewComment(iComicId, iParentId)
{
    sTitle = "Add Comment";
    sUri = "./HtmlTemplates/CommentAddEdit.php?comic="+iComicId+"&parent="+iParentId;
	PopupManager.CreatePopup({title:sTitle, size:{x:450, y:280}, source:sUri, contentType: 'iframe', resizable: false, type:'rounded', footer:false });
}
