/**
 * <p>Title: working.js</p>
 * <p>Description: Javascript to drive in-window "working" message.</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Kreber Graphics, Inc.</p>
 * @author Charlie Reading
 */

// Includes
var working_js = 1;
var includes = ((typeof browser_js == 'undefined') ? " browser.js\n" : "");
if (includes != "")
{
	alert("working.js: you must first include:\n" + includes);
}

//
// Constants
//
kWorkingTag_MessageBox = "workingMessageBox";		// Message box
kWorkingTag_Message = "workingMessage";		        // Message text
kWorkingTag_Image = "workingImage";


//
// Geometry
//
var gWorking_Width = 320;
var gWorking_Height = 75;
var gWorking_Image = "/kreberweb/working.gif";
var gWorking_Style = "background:lightgrey; color:black;";
var gWorking_StyleClass = null;

// Frame working appears in
var gWorking_Frame = null;

// "pop" timer (default: 2 seconds)
var gWorking_PopTimerMsecs = (1000 * 2);
var gWorking_PopTimer = null;


//
// Generate the tag structure for the message-box.
//
function workingTagMessageBox(width, height, image, style, styleClass)
{
	if ((typeof width != 'undefined') && (width != null))
	{
		gWorking_Width = width;
	}
	if ((typeof height != 'undefined') && (height != null))
	{
		gWorking_Height = height;
	}
	if ((typeof image != 'undefined') && (image != null))
	{
		gWorking_Image = image;
	}
	if ((typeof style != 'undefined') && (style != null))
	{
		gWorking_Style = style;
	}
	if ((typeof styleClass != 'undefined') && (styleClass != null))
	{
		gWorking_StyleClass = styleClass;
	}

	var sStyleClass = ((gWorking_StyleClass != null) ? 'class="'+gWorking_StyleClass+'"' : '');
	var html = "";

	html += '<div id="' + kWorkingTag_MessageBox + '" ' + sStyleClass + ' align="center" valign="middle" style="position:absolute; top:0px; left:0px; width:' + gWorking_Width + 'px; height:' + gWorking_Height + 'px; visibility:hidden; z-index:9999; ' + gWorking_Style + '"> \n';
	html += '  <div ' + sStyleClass + ' align="center" valign="middle" style="position:absolute; top:0px; left:0px; width:' + (gWorking_Width) + 'px; height:' + (gWorking_Height) + 'px; border:thick double black; ' + gWorking_Style + '"> \n';
	html += '    <div ' + sStyleClass + ' align="center" valign="middle"> \n';
	html += '      <table border="0" cellpadding="0" cellspacing="0" width="100%"> \n';
	html += '			   <tr> \n';
	html += '				   <td align="center"><img src="/kreberweb/trans.gif" height="10" width="1"></td> \n';
	html += '			   </tr> \n';
	html += '			   <tr> \n';
	html += '				   <td align="center"><img id="' + kWorkingTag_Image + '" src="' + gWorking_Image + '" align="middle"></td> \n';
	html += '			   </tr> \n';
	html += '			   <tr> \n';
	html += '				   <td align="center"><img src="/kreberweb/trans.gif" height="10" width="1"></td> \n';
	html += '			   </tr> \n';
	html += '			   <tr> \n';
	html += '				   <td align="center"><div id="' + kWorkingTag_Message + '"></div></td> \n';
	html += '			   </tr> \n';
	html += '		   </table> \n';
	html += '	   </div> \n';
	html += '	 </div> \n';
	html += '</div> \n';

	return html;
}

//
// Show working message box
//
function workingShowMessageBox(messageHTML, image, popTimer)
{
	if (typeof popTimer == 'undefined')
	{
		popTimer = false;
	}

	var tagBox = idToTagInFrame(kWorkingTag_MessageBox,gWorking_Frame);
	var tagText = idToTagInFrame(kWorkingTag_Message,gWorking_Frame);
	var tagImage = idToTagInFrame(kWorkingTag_Image,gWorking_Frame);

	// Set the text
	tagText.innerHTML = messageHTML;

	// Align it in the parent
	workingAlignMessageBox();

	// Set the image
	if ((typeof image != 'undefined')
			&& (image != null))
	{
		tagImage.src = image;
	}
	else
	{
		tagImage.src = tagImage.src;
	}

	// Show it (or delay it)
	if (popTimer)
	{
		gWorking_PopTimer = setTimeout("workingShow()", gWorking_PopTimerMsecs);
	}
	else
	{
		workingShow();
	}
}

//
// Do the actual show
//
function workingShow()
{
	// NULL our pop-timer (just in case, since we might be here 'cause it fired)
	gWorking_PopTimer = null;

	var tagBox = idToTagInFrame(kWorkingTag_MessageBox,gWorking_Frame);
	tagBox.style.visibility = 'visible';
}

//
// Align working message box
//
function workingAlignMessageBox()
{
	var tagBox = idToTagInFrame(kWorkingTag_MessageBox,gWorking_Frame);

	// Align it in the parent (horizontal: center, vertical: 1/3)
	var left = document.body.scrollLeft + ((window.document.body.clientWidth - gWorking_Width) / 2);
	var top = document.body.scrollTop + ((window.document.body.clientHeight - gWorking_Height) / 3);
	tagBox.style.left = left + "px";
	tagBox.style.top = top + "px";
}

//
// Hide working message box
//
function workingHideMessageBox()
{
	// Cancel timer
	if (gWorking_PopTimer != null)
	{
		clearTimeout(gWorking_PopTimer);
		gWorking_PopTimer = null;
	}

	var tagBox = idToTagInFrame(kWorkingTag_MessageBox,gWorking_Frame);

	// Hide it
	tagBox.style.visibility = 'hidden';
}
