function load_comments(page,userID) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/comments.php?u=' + userID + '&p=' + page;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4)
			document.getElementById('comments_box').innerHTML = oXML.responseText;
	}
	oXML.send(null);
}
function adjust_review(box,total) {
	var len = box.value.length;
	if (len > total)
		box.value = box.value.substr(0,total);
	document.getElementById(box.name + '_count').innerHTML = (total - len) + ' characters left.  ' + total + ' total.  No HTML please.';
}
function post_comment(userID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><input type="hidden" name="userID" value="' + userID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);"></textarea><div id="comment_count">2000 characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_comment(document.getElementById(\'comment_form\'));return false;">Comment</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function edit_comment(commentID,userID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><input type="hidden" name="userID" value="' + userID + '"/><input type="hidden" name="commentID" value="' + commentID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);">' + document.getElementById('comment_' + commentID).innerHTML + '</textarea><div id="comment_count">' + (2000 - document.getElementById('comment_' + commentID).innerHTML.length) + ' characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_comment(document.getElementById(\'comment_form\'));return false;">Comment</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function delete_comment(commentID,userID) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/comments.php?u=' + userID + '&p=1&d=' + commentID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('comments_box').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}
function delete_reply(replyID,userID) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/comments.php?u=' + userID + '&p=1&dr=' + replyID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('comments_box').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}
function post_reply(reviewID,userID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="userID" value="' + userID + '"/><input type="hidden" name="reviewID" value="' + reviewID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);"></textarea><div id="comment_count">750 characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function edit_reply(replyID,userID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="userID" value="' + userID + '"/><input type="hidden" name="replyID" value="' + replyID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);">' + document.getElementById('reply_' + replyID).innerHTML + '</textarea><div id="comment_count">' + (750 - document.getElementById('reply_' + replyID).innerHTML.length) + ' characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function add_reply(frm) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/comments.php?u=' + frm.userID.value+ '&p=1&';
	if (frm.reviewID)
		url += 'r=' + frm.reviewID.value;
	if (frm.replyID)
		url += 'repl=' + frm.replyID.value;
	url +='&t=' + encodeURIComponent(frm.comment.value);
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('comments_box').innerHTML = oXML.responseText;
				hide_box('popup');
			}
		}
	}
	oXML.send(null);
}
function add_comment(frm) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/comments.php?u=' + frm.userID.value + '&p=1&t=' + encodeURIComponent(frm.comment.value);
	if (frm.commentID)
		url += '&i=' + frm.commentID.value;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('comments_box').innerHTML = oXML.responseText;
				hide_box('popup');
			}
		}
	}
	oXML.send(null);
}
function add_friend(userID, lnk) {
	oXML = new XMLHttpRequest();
	oXML.open('GET','/profiles/process/add_friend.php?i=' + userID,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			lnk.parentNode.innerHTML = 'Friend Request Sent';
		}
	}
	oXML.send(null);
}

function load_blog_comments(blogID,page) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/blog_comments.php?b=' + blogID + '&p=' + page;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4)
			document.getElementById('comment_box').innerHTML = oXML.responseText;
	}
	oXML.send(null);
}
function post_blog_comment(blogID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><input type="hidden" name="blogID" value="' + blogID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);"></textarea><div id="comment_count">2000 characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_blog_comment(document.getElementById(\'comment_form\'));return false;">Comment</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function post_blog_reply(reviewID,blogID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="reviewID" value="' + reviewID + '"/><input type="hidden" name="blogID" value="' + blogID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);"></textarea><div id="comment_count">750 characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_blog_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function edit_blog_comment(blogID, commentID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Comment</div><form id="comment_form"><input type="hidden" name="commentID" value="' + commentID + '"/><input type="hidden" name="blogID" value="' + blogID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,2000);">' + document.getElementById('comment_' + commentID).innerHTML + '</textarea><div id="comment_count">' + (2000 - document.getElementById('comment_' + commentID).innerHTML.length) + ' characters left. 2000 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_blog_comment(document.getElementById(\'comment_form\'));return false;">Comment</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function edit_blog_reply(replyID,blogID) {
	var sOut = '<div class="popup_contents"><div class="popup_close"><a href="#" onClick="hide_box(\'popup\');return false;">X</a></div><div class="popup_hdr">Post a Reply</div><form id="comment_form"><input type="hidden" name="replyID" value="' + replyID + '"/><input type="hidden" name="blogID" value="' + blogID + '"/><textarea name="comment" id="comment_field" onKeyUp="adjust_review(this,750);">' + document.getElementById('reply_' + replyID).innerHTML + '</textarea><div id="comment_count">' + (750 - document.getElementById('reply_' + replyID).innerHTML.length) + ' characters left. 750 total. No HTML please.</div><div class="generic_btn generic_btn_right"><a href="#" onClick="hide_box(\'popup\');return false;">Cancel</a></div><div class="generic_btn generic_btn_right"><a href="#" onClick="add_blog_reply(document.getElementById(\'comment_form\'));return false;">Reply</a></div><div class="clear"></div></form></div></div>';
	display_box(sOut,true);
	if (document.getElementById('comment_field'))
		document.getElementById('comment_field').focus();
}
function add_blog_reply(frm) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/blog_comments.php?b=' + frm.blogID.value + '&p=1';
	if (frm.reviewID)
		url += '&r=' + frm.reviewID.value;
	if (frm.replyID)
		url += '&repl=' + frm.replyID.value;
	url += '&t=' + encodeURIComponent(frm.comment.value);
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('comment_box').innerHTML = oXML.responseText;
				hide_box('popup');
			}
		}
	}
	oXML.send(null);
}
function add_blog_comment(frm) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/blog_comments.php?b=' + frm.blogID.value + '&p=1';
	if (frm.commentID)
		url += '&c=' + frm.commentID.value;
	url += '&t=' + encodeURIComponent(frm.comment.value);
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				hide_box('popup');
				signout();
			} else {
				document.getElementById('comment_box').innerHTML = oXML.responseText;
				hide_box('popup');
			}
		}
	}
	oXML.send(null);
}
function delete_blog_comment(commentID,userID) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/blog_comments.php?b=' + userID + '&p=1&d=' + commentID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('comment_box').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}
function delete_blog_reply(replyID,userID) {
	var oXML = new XMLHttpRequest();
	var url = '/profiles/modules/blog_comments.php?b=' + userID + '&p=1&dr=' + replyID;
	oXML.open('GET',url,true);
	oXML.onreadystatechange = function() {
		if (oXML.readyState == 4) {
			if (oXML.responseText == '<LOGOUT/>') {
				signout();
			} else {
				document.getElementById('comment_box').innerHTML = oXML.responseText;
			}
		}
	}
	oXML.send(null);
}

