/*****************************************************************************************
 * Library of functions shared by most Mantom web pages
 *
 *
 *****************************************************************************************/

//=============================================================================
// SPAM Protection against web crawlers and bots
//=============================================================================

// email addresses
var aContacts = new Array();
var i = 0;
aContacts[i++] = 'Trai' + 'ning@' + 'Mant' + 'om.net';
aContacts[i++] = 'Inf' + 'o@' + 'Mant' + 'om.net';
aContacts[i++] = 'Mat' + 't@' + 'Mant' + 'om.net';
aContacts[i++] = 'Jac' + 'k@' + 'Mant' + 'om.net';

// Web links
var aURLs = new Array();
var i = 0;
aURLs[i++] = 'ww' + 'w.Mant' + 'om.n' + 'et';

// Link types
var NONE  = 0;
PAGE  = 1;
var POPUP = 2;
var URL   = 3;
var MAIL  = 4;

// Mail addresses
var T = 0;
var I = 1;
var M = 2;
var J = 3;

// Button types
var CLEAR  = 0;
var RESET  = 1;
var SUBMIT = 2;

//=============================================================================
// LogoLoad() - Load the Mantom logo page
//=============================================================================
function LogoLoad( LogoPath )
{
	if ( !LogoPath   ) { var LogoPath   = "."; }

//	document.write( '<P><IMG SRC="' + LogoPath + '/mantom_logo.jpg" width=356 height=160 border=0 title="Mantom"></P>' );
	document.write( '<P><IMG SRC="' + LogoPath + '/mantom_logo.jpg" border=0 title="Mantom"></P>' );
}


//=============================================================================
// LogoLoadSmall() - Load the Mantom logo page
//=============================================================================
function LogoLoadSmall( LogoPath )
{
	if ( !LogoPath ) { var LogoPath = "."; }

	document.write( '<P><IMG SRC="' + LogoPath + '/mantom_logo_sm.jpg" border=0 title="Mantom"></P>' );
}



//=============================================================================
// HeaderLoad() - Load the Mantom logo
//=============================================================================
function HeaderLoad( TargetPath, LogoPath )
{
	if ( !TargetPath ) { var TargetPath = "."; }
	if ( !LogoPath   ) { var LogoPath   = "."; }

//	document.write( '<P><A HREF="' + TargetPath + '/main.html"><IMG SRC="' + LogoPath + '/mantom_logo.jpg" width=356 height=160 border=0 title="Mantom Home"></A></P>' );
	document.write( '<P><A HREF="' + TargetPath + '/main.html"><IMG SRC="' + LogoPath + '/mantom_logo.jpg" border=0 title="Mantom Home"></A></P>' );
}

//=============================================================================
// BackHeaderLoad() - Load the Mantom logo
//=============================================================================
function BackHeaderLoad( TargetPath, LogoPath )
{
	if ( !TargetPath ) { var TargetPath = "."; }
	if ( !LogoPath   ) { var LogoPath   = "."; }

//	document.write( '<P><IMG SRC="' + LogoPath + '/mantom_logo.jpg" width=356 height=160 border=0 onClick="history.go(-1);"></P>' );
	document.write( '<P><IMG SRC="' + LogoPath + '/mantom_logo.jpg" border=0 onClick="history.go(-1);"></P>' );

}

//=============================================================================
// LinkListLoad() - Load a page of links including headers
//=============================================================================
function LinkListLoad( aHeaders, aLabels, aUrls, TableWidth, LinkType, Offset )
{
	var i = 0;

	if ( !TableWidth ) { var TableWidth = 512; }
	if ( !LinkType   ) { var LinkType   = 0;   }
	if ( !Offset     ) {
		var Offset = "";
	} else {
		var Offset = "width=" + Offset;
	}

	document.write( '<TABLE width=' + TableWidth + '>' );

	var NbHeaders = aHeaders.length;

	for ( i = 0; i < NbHeaders; i++ ) {

		if ( aHeaders[i] ) {
			document.write( '<TR><TH ' + Offset + '><H4 class="header_red">' + aHeaders[i] + '</H4></TH></TR>' );
		}
		if ( aLabels[i] ) {
			       if ( LinkType == NONE  ) { document.write( '<TR><TD ' + Offset + '></TD><TD><H5 class="bodytext">' + aLabels[i] + '</H5></TD></TR>' );
			} else if ( LinkType == PAGE  ) { document.write( '<TR><TD ' + Offset + '></TD><TD><A HREF="' + aUrls[i] + '" class="mantom">' + aLabels[i] + '</A></TD></TR>' );
			} else if ( LinkType == POPUP ) { document.write( '<TR><TD ' + Offset + '></TD><TD><A HREF="#" onClick=\'OpenWindow( "' + aUrls[i] + '" );\' class="mantom">' + aLabels[i] + '</A></TD></TR>' );
			} else if ( LinkType == URL   ) { document.write( '<TR><TD ' + Offset + '></TD><TD><A HREF="#" onClick=\'OpenLink( "http://' + aUrls[i] + '" );\' class="mantom">' + aLabels[i] + '</A></TD></TR>' );
			} else if ( LinkType == MAIL  ) { document.write( '<TR><TD ' + Offset + '></TD><TD><A HREF="mailto:' + aUrls[i] + '" class="mantom">' + aUrls[0] + '</A></TD></TR>' );
			}
		} else {
			document.write( '<TR><TD></TD><TD><H4 class="bodytext">(Coming Soon)</H4></TD></TR>' );
		}
	}

	document.write( '</TABLE>' );

	return(0);
}

//=============================================================================
// TitleLoad() - Load the Page title
//=============================================================================
function TitleLoad( Title, SubTitle, FootTitle )
{
	if ( Title ) {
		document.write( '<H1 class="title">' + Title + '</H1>' );
	}
	if ( SubTitle ) {
		document.write( '<H2 class="subtitle">' + SubTitle + '</H2>' );
	}
	if ( FootTitle ) {
		document.write( '<H5 class="foottitle">' + FootTitle + '</H5>' );
	}

	return(0);
}

//=============================================================================
// CourseTitleLoad() - Load the Page title
//=============================================================================
function CourseTitleLoad( Title, SubTitle )
{
	document.write( '<H2 class="title">' + Title + '</H2>' );

	if ( SubTitle != undefined ) {
		document.write( '<H3 class="subtitle">' + SubTitle + '</H3>' );
	}
}

//=============================================================================
// HomeLinkLoad() - Load the homepage link
//=============================================================================
function HomeLinkLoad( TargetPath )
{
	if ( TargetPath == undefined ) {
		var TargetPath = '.';
	}

	document.write( '<BR><A HREF="' + TargetPath + '/home.html" class="mantom_home">HOME</A><BR>' );
}

//=============================================================================
// CopyRightLoad() - Load the Copyright fineprint
//=============================================================================
function CopyRightLoad()
{
	document.write( '<H6 class="fineprint">(c)2002 Mantom, All rights reserved</H6>' );
}

//=============================================================================
// OpenWindow() - Open a page in a popup window
//=============================================================================
function OpenWindow( FileName )
{
	window.open( FileName, "", "width=425,height=350,scrollbars" );
}

//=============================================================================
// OpenLink() - Open a page in a popup window
//=============================================================================
function OpenLink( Url )
{
	window.open( Url );
}



//=============================================================================
// CloseWindow() - Close the specified window
//=============================================================================
function CloseWindow( oWindow )
{
	if ( !oWindow ) {
		window.close();
		return(0);
	}
	oWindow.close();
}

//=============================================================================
// ContactLoad() - Open a fresh new email page for the user
//=============================================================================
function ContactLoad( Address, Subject )
{
	if ( arguments.length <= 1 ) {
		var Subject = "";
	} else {
		var Subject = "?subject=" + Subject;
	}
	document.write( '<TR><TD></TD><td align=left><A HREF="mailto:' + aContacts[Address] + Subject + '" class="mantom">' + aContacts[Address] + '</A></TD></TR>' );

	return(0);	
}

//=============================================================================
// TextInputLoad()
//=============================================================================
function TextInputLoad( Name, Size )
{
	if ( !Name ) { var Name = "Button"; }
	var Size = ( !Size ? "" : "SIZE=" + Size );

	document.write( '<INPUT TYPE=text NAME="' + Name + '" ' + Size + ' class="menu">' );

	return(0);
}

//=============================================================================
// SelectionListLoad()
//=============================================================================
function SelectionListLoad( Name, aLabels, aValues )
{
	var i;

	if ( !Name ) { return(1); }

	document.write( '<SELECT NAME="' + Name + '" class="menu">' );

	var NbItems = aLabels.length;

	for ( i = 0; i < NbItems; i++ ) {
		// Add item
		document.write( '<OPTION VALUE="' + aValues[i] + '">' + aLabels[i] );
	}
	document.write( '</SELECT>' );

	return(0);
}

//=============================================================================
// ButtonLoad()
//=============================================================================
function ButtonLoad( Title, Type, Enumeration )
{
	if ( !Title ) {
		var Title = "Button";
	}

	switch( Type ) {
		case "submit":
		case "reset":
		case "clear":
			break;
		default:
			var Type = "reset";
			break;
	}

	if ( !Enumeration ) { var Enumeration = Type + "button"; }

	document.write( '<INPUT TYPE=' + Type + ' NAME="' + Enumeration + '" VALUE="' + Title + '" onClick="ActivateCel(event);" class="button">' );

	return(0);
}

/*
//=============================================================================
		var oBrowser = window.navigator.appName;
		function ActivateCel(e)
		{
			if ( oBrowser == "Netscape" ) {
				e.target.style.borderColor      = "#dc0f0f";
				e.target.style.borderColorLight = "#dc0f0f";
				e.target.style.borderColorDark  = "#dc0f0f";
				e.target.style.bgColor          = "#dc0f0f";
			} else {
				e.srcElement.style.borderColor      = "#dc0f0f";
				e.srcElement.style.borderColorLight = "#dc0f0f";
				e.srcElement.style.borderColorDark  = "#dc0f0f";
				e.srcElement.style.bgColor          = "#dc0f0f";
			}
		}
		function ShowObjects(e)
		{
			var i;
			var aElements = new Array();
			var oEvent = ( oBrowser == "Netscape" ? e.target : e.srcElement );

			for ( element in oEvent ) {
				aElements.push( element );
			}

			var aSortedElements = aElements.sort();

			document.write( "<TABLE>" );

			for ( i = 0; i < aSortedElements.length; i++ ) {
				var Element = aSortedElements[i];

				document.write( "<TR>" );
				document.write( "<TD>" + Element + "</TD>" );
				document.write( "<TD>" + oEvent[Element] + "</TD>" );
				document.write( "<TD>" + typeof( Element ) + "</TD>" );
				document.write( "</TR>" );
			}
			document.write( "</TABLE>" );
		}
*/











/**********************************
 * Help Page Functions
 **********************************/

//=============================================================================
// HelpHeaderLoad() - Load the Mantom logo onto a help page
//=============================================================================
function HelpHeaderLoad( LogoPath, Page, Title, Caption, Width, Offset )
{

	if ( !LogoPath ) { var LogoPath = "."; }
	if ( !Width    ) { var Width    = 475; }
	if ( !Offset   ) { var Offset   = 185; }

	document.write( '<P><A HREF="' + LogoPath + '/' + Page + '"><IMG SRC="' + LogoPath + '/mantom_logo_sm.jpg" border=0></A></P>' );
	TitleLoad( "", Title, Caption );
}




//=============================================================================
// HelpSectionHeaderWrite() - Write a header for a section of a help page (ie: description, usage, etc...)
//=============================================================================
function HelpSectionHeaderWrite( Label, Width, RuleHeight )
{
	if ( !Width      ) { Width      = 450; }
	if ( !RuleHeight ) { RuleHeight = 2;   }

	// auto compute title width
	var i;
	var NbChar = 0;
	var NbSpaces = 2.5;
	var aCharacters = Label.split("");
	for ( i = 0; i < aCharacters.length; i++ ) {
		var ch = aCharacters[i];
		switch( ch ) {
			case "i":
			case "I":
			case ",":
			case ":":
			case ";":
			case "|":
			case "1":
			case "!":
			case "(":
			case ")":
			case "{":
			case "}":
			case "[":
			case "]":
			case "'":
				NbChar += 0.5;
				break;
			case " ":
				NbSpaces++;
				break;
			default:
				NbChar++;
				break;
		}
	}
	var TitleWidth = Math.round( (NbChar + NbSpaces) * 8 );

	var RuleWidth = Math.floor( ( Width - TitleWidth ) * 0.5 );

	document.write( '<TABLE width=' + Width + ' align=center border=0>' );
	document.write( '<TD><HR align=right color=FF0000 size=' + RuleHeight + ' width=' + RuleWidth + '></TD>' );
	document.write( '<TD class="highlight_white" width=' + TitleWidth + '>' + Label + '</TD>' );
	document.write( '<TD><HR align=left  color=FF0000 size=' + RuleHeight + ' width=' + RuleWidth + '></TD>' );
	document.write( '</TABLE>' );
}

//=============================================================================
// HelpToolInfoWrite() - Write a header for a section of a help page (ie: description, usage, etc...)
//=============================================================================
function HelpToolInfoWrite( aData, Width, Offset )
{
	if ( !Width  ) { Width  = 500; }
	if ( !Offset ) { Offset = 100; }

	var aLabels = new Array( "Category", "Platforms", "Type", "Compatibility", "Language", "Scriptable", "Version", "XSI Batch"  );
//	var aData   = new Array( "General", "Windows, Linux", "Command", "4.0", "JScript", "Yes", "1.0", "No"  );

	document.write( '<TABLE width=' + Width + ' align=center border=1 bordercolor=FFFFFF cellpadding=0 cellspacing=0>' );

	var i;
	for ( i = 0; i < aLabels.length; ) {
		document.write( '<TR>' );
		document.write( '<TD width=' + Offset + ' class="label_grey">' + aLabels[i] + ': </TD><TD>' + aData[i++] + '</TD>' );
		document.write( '<TD width=' + Offset + ' class="label_grey">' + aLabels[i] + ': </TD><TD>' + aData[i++] + '</TD>' );
		document.write( '</TR>' );
	}

	document.write( '</TABLE>' );
}

//=============================================================================
// HelpUsageWrite() - Write an ordered list of descriptions.
//=============================================================================
function HelpUsageWrite( aDescriptions, Width )
{
	if ( !Width ) { Width = 475; }

	document.write( '<TABLE width=' + Width + ' align=center>' );
	document.write( '<TR>' );
	document.write( '<TD><OL>' );

	var i;
	for ( i = 0; i < aDescriptions.length; i++ ) {
		document.write( '<LI>' + aDescriptions[i] + '</LI>' );
	}

	document.write( '</OL></TD>' );
	document.write( '</TR>' );
	document.write( '</TABLE>' );
}

//=============================================================================
// HelpParameterWrite() - Write a parameter and it's description
//=============================================================================
function HelpParameterWrite( Label, Description, Width, Offset )
{
	if ( !Width  ) { Width  = 500; }
	if ( !Offset ) { Offset = 100; }

	document.write( '<TABLE width=' + Width + ' align=center border=0>' );
	document.write( '<TR>' );
	document.write( '<TD width=' + Offset + ' class="label_tool">' + Label + ':</TD>' );
	document.write( '<TD align=left>' + Description + '</TD>' );
	document.write( '</TR>' );
	document.write( '</TABLE>' );
}

//=============================================================================
// HelpSubParameterWrite() - Write a subparameter (parameter option) and it's description
//=============================================================================
function HelpSubParameterWrite( aLabels, aDescriptions, Width, Offset )
{
	if ( !Width  ) { Width  = 500; }
	if ( !Offset ) { Offset = 125; }

	document.write( '<TABLE width=' + Width + ' align=center border=0>' );

	var i;
	for ( i = 0; i < aLabels.length; i++ ) {
		document.write( '<TR><TD class="label_grey" width=' + Offset + '>' + aLabels[i] + ':</TD><TD align=left>' + aDescriptions[i] + '</TD></TR>' );
	}
	document.write( '</TABLE>' );
}

//=============================================================================
// HelpLinkWrite() - Write a subparameter (parameter option) and it's description
//=============================================================================
function HelpLinkWrite( Label, URL, Offset )
{
	if ( !Offset ) { Offset = 0; }

	document.write( '<A HREF="' + URL + '" class="mantom">' + Label + '</A><BR>' );
}

