/*************************************************************************
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2003-5 by Sharon Paine 
  See Terms of Use at www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!
*************************************************************************/

function doTooltip(e, ar) {
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	//var tip = document.getElementById( Tooltip.tipID );
	Tooltip.show(e, ar);
}

function hideTip() {
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	Tooltip.hide();
}

// optional preloader 
var imageHandler = { 
	path:"images/", // path to images
	imgs:[], preload:function() { for(var i=0;arguments[i];i++) {
	var img=new Image(); img.src=this.path+arguments[i]; this.imgs[this.imgs.length]=img;}}
}


function collapseComments(id, num_comments)
{
	var element_id = 'journal_comments_links_'+id;
	
	html = '<div class="journal_num_comment"><a onclick="expandComments(' + id + ',' + num_comments + ')"><img class="journal_expand_image" src="images/expand.jpg">&nbsp;&nbsp;Comments (' + num_comments + ')</a></div><div class="journal_add_comment"><a href="add_comment.php?id=' + id + '">Add Comment</a></div>';
	document.getElementById(element_id).innerHTML=html;
	
	var element_id = 'journal_comments_'+id;
	document.getElementById(element_id).innerHTML='';
	
}
	
function expandComments(id, num_comments)
{
	var xdoc;
	var element_id = 'journal_comments_links_'+id;
	
	html = '<div class="journal_num_comment"><a onclick="collapseComments(' + id + ',' + num_comments + ')"><img class="journal_expand_image" src="images/collapse.jpg">&nbsp;&nbsp;Comments (' + num_comments + ')</a></div><div class="journal_add_comment"><a href="add_comment.php?id=' + id + '">Add Comment</a></div>';

	document.getElementById(element_id).innerHTML=html;
	xmlFile = "scripts/php/gen_comments_xml.php?id=" + id;
	if (document.implementation && document.implementation.createDocument)
	{
		xdoc = document.implementation.createDocument("", "", null);
		xdoc.load(xmlFile);

		xdoc.onload = function()
		{
			create_comments_html(xdoc,id);
		}

	  return true;
		
	}
	else if (window.ActiveXObject)
	{
		xdoc = new ActiveXObject("Microsoft.XMLDOM");
		xdoc.async = false;
		xdoc.load(xmlFile);
		
		create_comments_html(xdoc,id);

		return true;
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
}


function create_comments_html(xmlDoc, id) {
	var html = '';
	var comments = xmlDoc.getElementsByTagName('comment');
	for (i = 0; i<comments.length; i++) {
	
		
		
		var part_html = '<div class="title_bar_div" style="border-bottom-width: .1em;"><div class="alignleft left_title" style="font-size:16px;">' + comments[i].getAttribute("date") + '&nbsp;&nbsp;&nbsp;' + comments[i].getAttribute("time") + '</div><div style="clear: both;"></div></div>';
		part_html = part_html + '<div class="journal_comments_comment"><p>' + comments[i].getAttribute("comment") + '</p></div>';
		part_html = part_html + '<div class="journal_comments_name" style="text-align: right;"><p>--' + comments[i].getAttribute("name") + '</p></div>';
		html = html + part_html;
	}
	var element_id = 'journal_comments_'+id;
	document.getElementById(element_id).innerHTML=html;
}