// ---------------------------------------------------------------------------
// LIBRARY NAME: javalib.js
// VERSION:      2.0
// DESCRIPTION:  JavaScript Custom Functions Library.
// PROGRAMMER:   George Silberstern, ...by Graf!
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Functions included in this release:
//      * About()
//      * Center()
//      * GetPosition()
//      * GetDimension()
//      * HTMLFooter()
//      * HTMLHeader()
//      * SupportedFileType()
//
// Core modules:
//      * _errortrap()
// ---------------------------------------------------------------------------
var _libraryname = "JavaLib"
var _libversion  = "2.02"
var _libauthor   = "George Silberstern"
var _libcpyright = "2001-2003"
var _libownernam = "...by Graf!"
var _libownerurl = "http://www.grafs.net"
var _libownereml = "design@grafs.net"


// ===========================================================================
// About()
//      Description: Displays an "About" box identifying this library
//      Parameters:  None
//      Syntax:      About()
//      Requires:    GetPosition(), Center()
//      Returns:     Nothing
//
function About() {
	var WindowHandle = "About";
	var WindowAttrib = "toolbar=no,location=no,directories=no,status=no,menubar=no";
	var WindowScroll = "scrollbars=no";
	var WindowResize = "resizable=no";
	var BodyTag = 'bgcolor="#C0C0C0" link="#3300CC" vlink="#FF3399" alink="#99FF66" text="#000000" style="margin: 10px;"'
	var FontTag = '<font style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 9pt;">';
	var CloseLink = '<input type="button" value="    OK    " style="font-family: sans-serif; margin-top: 5px;" onClick="window.close()">'

	WindowWidth = 480;
	WindowHeight = 200;

	HPosition = GetPosition(screen.width, WindowWidth);
	VPosition = GetPosition(screen.height, WindowHeight);
	WindowAttrib = "width="+WindowWidth+",height="+WindowHeight+","+WindowAttrib+","+WindowScroll+","+WindowResize;

	About = window.open("", WindowHandle, WindowAttrib);
	Center(About);
	About.document.open();

	with (About.document) {
		write('<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">\n');
		write('<html>\n<head>\n')
		write('\t<meta name="generator" content="JavaScript">\n');
		write('\t<meta http-equiv="Content-Language" content="en-us">\n');
		write('\t<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">\n');
		write('\t<meta http-equiv="Resource-Type" content="document">\n');
		write('\t<title>About...</title>\n</head>\n\n');
		write('<body ' + BodyTag + '>\n\n');
		write('<form method="post">\n');
		write('<table border="0" cellpadding="0" cellspacing="0" width="450" align="center">\n');
		write('<tr>\n\t<td width="50%" align="left" valign="top">\n');
		write('\t' + FontTag + '\n');
		write('\t<b>Powered with ' + _libraryname + ' v' + _libversion + '</b>\n');
		write('\t</font>\n\t</td>\n\t<td width="50%" align="right" valign="top">\n');
		write('\t' + FontTag + '\n');
		write('\t<b>Copyright &copy;' + _libcpyright + ', <i>' + _libownernam + '</i></b>\n');
		write('\t</font>\n\t</td>\n</tr>\n');
		write('<tr>\n\t<td colspan="2" align="left" valign="top">\n');
		write('\t' + FontTag + '\n');
		write('\t<br>\n\n\t' + _libraryname + ' is a customized Web Application ');
		write('Enhancements Library developed by ' + _libauthor + ' \n\tfor ');
		write('<i>' + _libownernam + '</i>, an Internet and Systems Solutions ');
		write('Company.<br>\n\t<br>\n\n\tIf you have any questions, or would ');
		write('like more information, about our products and \n\tservices, please ');
		write('visit our Web Site at <a href="' + _libownerurl );
		write('" target="_blank"><b>' + _libownerurl + '</b></a>. \n\tOur email ');
		write('address is <a href="mailto:' + _libownereml + '"><b>');
		write(_libownereml + '</b></a>.<br>\n');
		write('\t</font>\n\t</td>\n</tr>\n');
		write('<tr>\n\t<td colspan="2" align="center" valign="bottom">\n');
		write('\t' + CloseLink + '\n\t</td>\n</tr>\n</table>\n</form>\n\n');
		write('</body>\n</html>\n');
		close();
	}
}

// ===========================================================================
// Center()
//      Description: Places a window in the center of the screen
//      Parameters:  Handle
//      Syntax:      Center(<expC>)
//      Requires:    _errortrap
//      Returns:     Nothing
//
function Center(Handle) {
	var Handle;

// ----[ Error Trap ]---------------------------------------------------------
	if (! Handle) {
		var topic = "Center";
		var param = "<expC>";
		var error = "Missing Object Handle";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		with (Handle) {
			if (window.resizeTo) {
				document.write();
				resizeTo(WindowWidth, WindowHeight);
			}
			moveTo(HPosition, VPosition);
			focus();
		}
	}
}
// ===========================================================================

// ===========================================================================
// GetDimension()
//      Description: Calculate the maximum dimension for a work area
//      Parameters:  WorkAreaSize, ObjectSize, [ObjectPadding]
//      Syntax:      GetDimension(<expN>,<expN>,[<expN>])
//      Requires:    _errortrap
//      Returns:     ObjectSize (<expN>)
//
function GetDimension(WorkAreaSize, ObjectSize, ObjectPadding) {
	var WorkAreaSize;
	var ObjectSize;
	var ObjectPadding;
	
// ----[ Error Trap ]---------------------------------------------------------
	if (! WorkAreaSize || ! ObjectSize) {
		var topic = "GetDimension";
		var param = "<expN>, <expN>[, <expN>]";
		var error = "Missing Parameter(s)";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		if (! ObjectPadding) { ObjectPadding = 0; }
	
		if (WorkAreaSize <= (ObjectSize + ObjectPadding)) {
			return(ObjectSize = (WorkAreaSize - (ObjectPadding / 2)));
		} else { 
			return(ObjectSize = (ObjectSize + ObjectPadding));
		}
	}
}
// ===========================================================================

// ===========================================================================
// GetPosition()
//      Description: Calculate a Screen Coordinate for Object placement
//      Parameters:  WorkAreaSize, ObjectSize
//      Syntax:      GetPosition(<expN>,<expN>)
//      Requires:    _errortrap
//      Returns:     Coordinate (<expN>)
//
function GetPosition(WorkAreaSize, ObjectSize) {
	var ObjectSize;
	var WorkAreaSize;

// ----[ Error Trap ]---------------------------------------------------------
	if (! WorkAreaSize || ! ObjectSize) {
		var topic = "GetPosition";
		var param = "<expN>, <expN>";
		var error = "Missing Parameter(s)";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		return(Coordinate = (WorkAreaSize / 2) - (ObjectSize / 2));
	}
}
// ===========================================================================

// ===========================================================================
// HTMLFooter()
//      Description: Write HTML code for Document Footer
//      Parameters:  Handle
//      Syntax:      HTMLFooter(<expC>)
//      Requires:    _errortrap
//      Returns:     Nothing
//
function HTMLFooter(Handle) {
	var Handle;

// ----[ Error Trap ]---------------------------------------------------------
	if (! Handle) {
		var topic = "HTMLFooter";
		var param = "<expC>";
		var error = "Missing Object Handle";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		with (Handle.document) {
			write('</body>\n</html>\n');
		}
	}
}
// ===========================================================================

// ===========================================================================
// HTMLHeader()
//      Description: Write HTML code for Document Header
//      Parameters:  Handle, [Attrib]
//      Syntax:      HTMLHeader(<expC>[,<expC>[,<expC>]])
//      Requires:    _errortrap
//      Returns:     Nothing
//
function HTMLHeader(Handle, Title, Attrib) {
	var Handle;
	var Attrib;
	var Title;
	
// ----[ Error Trap ]---------------------------------------------------------
	if (! Handle) {
		var topic = "HTMLHeader";
		var param = "<expC>[, <expC>[, <expC>]]";
		var error="Missing Object Handle";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		if (! Title) { Title = "Dynamic Window"; }
		if (! Attrib) { Attrib = 'body bgcolor="#FFFFFF" link="#000080" vlink="#800000" alink="#008000" text="#000000"' }

		with (Handle.document) {
			write('<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">\n');
			write('<html>\n<head>\n')
			write('\t<meta name="generator" content="JavaScript">\n');
			write('\t<meta http-equiv="Content-Language" content="en-us">\n');
			write('\t<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">\n');
			write('\t<meta http-equiv="Resource-Type" content="document">\n');
			write('\t<title>' + Title + '</title>\n</head>\n');

			write('\n<!--//\n');
			write('------------------------------------------------------------------------------\n');
			write('Dynamically created with ' + _libraryname + ' v' + _libversion + ', ');
			write('a customized JavaScript application\nby '+_libauthor+'.\n');
			write('Copyright (c)' + _libcpyright + ' by ' + _libauthor + ', ' + _libownernam + '\n');
			write('Please visit our Web Site at ' + _libownerurl + ', or write to: ' + _libownereml + '\n');
			write('------------------------------------------------------------------------------\n');
			write('//-->\n\n');

			write('<body ' + Attrib + '>\n');
		}
	}
}
// ===========================================================================


// ===========================================================================
// SupportedFileType()
//      Description: Test for filetype support in a Web Browser and report 
//                   the results.
//      Parameters:  FileType
//      Syntax:      SupportedFileType(<expC>)
//      Requires:    _errortrap
//      Returns:     Nothing
//
function SupportedFileType(FileType) {
	var FileType;
	var SupportState = "File Type not supported.";

// ----[ Error Trap ]---------------------------------------------------------
	if (! FileType) {
		var topic = "SupportedFileType";
		var param = "<expC>";
		var error="Missing File Type";
		_errortrap(topic, param, error);
	} else {

// ----[ Procedures ]---------------------------------------------------------
		for (var i = 0; i < navigator.mimeTypes.length; i++) {
			var ExtensionsTable = navigator.mimeTypes[i].suffixes;
			if (ExtensionsTable.indexOf(FileType.toLowerCase()) != -1 && navigator.mimeTypes[i].enabledPlugin) {
				SupportState = "File Type suppored by: " + navigator.mimeTypes[i].enabledPlugin.name;
			}
		}
		alert('.' + FileType.toUpperCase() + ' - ' + SupportState);
	}
}
// ===========================================================================

// ===========================================================================
// _errortrap
//      Description: Display an alert message for runtime errors
//      Parameters:  _source, _params, [_error]
//      Syntax:      _errortrap(<expC>,<expC>[,<expC>])
//      Requires:    Nothing
//      Returns:     Nothing
//
function _errortrap(_source, _params, _error) {
	var _source, _params, _error;

	if (! _source || ! _params) {
		_source = "_errortrap";
		_params = "<expC>, <expC>[, <expC>]"
		if (! _source) { _error = "Missing Function Name" }
		if (! _params) { _error = "Missing Parameter(s) List"}
	}

	if (_error) { 
		_lineA = "ERROR: " + _source + "() - " + _error + "\n"; 
	} else { 
		_lineA = "ERROR: " + _source + "() - Unspecified Error\n"; 
	}

	_lineB = "    USAGE: " + _source + "(" + _params + ")\n";

	alert(_lineA + _lineB);
}
// ===========================================================================
