/*---------------------------------------------------------------------------
   (c) 2002-2007 Stefan K.S. Tucker, 12noon
   (c) 1996-2002 Stefan K.S. Tucker, Perpetual Motion Software
---------------------------------------------------------------------------*/

//---------------------------------------------------------------------------
/*
   These functions output a certain string if the passed date is in the past.
   In other words, if the passed date is still in the future, it outputs
   the HTML code it's supposed to.

   For example, if we want the text "New" to be displayed until 8-31-2000,
   we would call itemNew("Aug 31 2000").

      <script type="text/javascript">itemNew("Aug 31 2000");</script>
*/
//---------------------------------------------------------------------------
// New flag
function itemNew(strStampDate)
{
	dtExpireDate = new Date(strStampDate)
	if (Date.parse(Date()) < Date.parse(dtExpireDate))
		document.write("<span class=\"clsNew\">&nbsp;New&nbsp;<\/span>");
}

// Update flag
function itemUpdated(strStampDate)
{
	dtExpireDate = new Date(strStampDate)
	if (Date.parse(Date()) < Date.parse(dtExpireDate))
		document.write("<span class=\"clsUpdated\">&nbsp;Updated&nbsp;<\/span>");
}



//---------------------------------------------------------------------------
/*
	We call this to determine if we need to use absolute references to pages;
	if not, we can use relative references.

	Example: check_version.pl?abc=xyz
*/
function needAbsoluteRef()
{
	var strFilename = getPageFilename();		  // get filename of current page

	/*
		Look for the first period.
		N.B.: We assume there are no periods in directory names or filenames.
	*/
	var ixDot = strFilename.indexOf(".");
	if (ixDot == -1)
		return true;

	// if it's not an HTML file, we need an absolute reference.
	return (strFilename.substr(ixDot, 4) != ".htm");
}

//---------------------------------------------------------------------------
/*
   This writes out the page header.

   <head>:
      <script type="text/javascript" src="12noon.js"></script>

   <body>
      <script type="text/javascript">writeHeader("Alarm++");</script>
*/
function writeHeader(strTitle)
{
	var strAbs = (needAbsoluteRef() ? "\/" : "");

   document.write("<div id=\"idHeader\">");
   document.write("	<a href=\"" + strAbs + "index.htm\"><img id=\"idHomeLogo\" src=\"" + strAbs + "graphics\/12noon-100home.png\" title=\"Home\" width=\"100\" height=\"100\"\/><\/a>");
   document.write("	<span id=\"idHeaderTitle\">" + strTitle + "<\/span>");
   document.write("<\/div>");

   document.write("<div id=\"idContent\">");
}


/*
	This function returns the filename of the current page.
	It looks for both slash and backward slash.
*/
function getPageFilename()
{
	var strFilename = document.URL;
	var ixSeparator = strFilename.lastIndexOf("/");
	var ixSeparator2 = strFilename.lastIndexOf("\\");
	if (ixSeparator2 > ixSeparator)
		ixSeparator = ixSeparator2;
	if (ixSeparator != -1)
		strFilename = strFilename.substr(ixSeparator + 1);
	return strFilename;
}


//---------------------------------------------------------------------------
/*
   This writes the footer for every page.
*/
function writeFooter()
{
   document.write("<\/div>");		// close <div id="idContent"> tag

   document.write("<p id=\"idCopyright\">&copy; 1995-" + (new Date).getFullYear() + " 12noon, Stefan Tucker<\/p>");
}



//---------------------------------------------------------------------------
/*
	COMMON FUNCTIONS
*/
//---------------------------------------------------------------------------

function setVisibilityByCheckbox(idCheck, idSame, idOpposite)
{
	var eltCheck = document.getElementById(idCheck);
	if ((eltCheck == null) || !eltCheck.style || (eltCheck.style.display == null))
		return;

	setVisibility(idSame, eltCheck.checked);

	if ((idOpposite != null) && (idOpposite != ""))
		setVisibility(idOpposite, !eltCheck.checked);
}

function toggleVisibility(id)
{
	var elt = document.getElementById(id);
	if ((elt == null) || !elt.style || (elt.style.display == null))
		return;

	if (elt.style.display == "none")
		elt.style.display = "";
	else
		elt.style.display = "none";
}

function setVisibility(id, state)
{
	var elt = document.getElementById(id);
	if ((elt == null) || !elt.style || (elt.style.display == null))
		return;

	if (state)
		elt.style.display = "";
	else
		elt.style.display = "none";
}

