/* --------------------------------------------------------------------------

	(c) 2006 U.S. Robotics Corporation

	-------------------------------------------------------------------------- */

/* --------------------------------------------------------------------------

	RTL SUPPORT

	To enable right-to-left CSS conversion, call this function in the page's
	onload event.

	If there is an Arabic character set in a META tag, enable the RTL stylesheet.

	It returns true if the page is right-to-left.

	Example:
		<link href="usr_rtl.css"	type="text/css" rel="stylesheet" disabled />
		<script src="usr_rtl.js" 	type="text/javascript"></script>

		<body onload="manageRTL(); initMenu();">

	N.B.	Safari does not add disabled stylesheets to the stylesheets
			collection, so we cannot disable the sheet by defaut in the HTML.
*/
function manageRTL()
{
	/*
		FFBUG: Firefox 2.0 ignores the "disabled" property,
		so we have to set it manually.
	*/

	/*
		Find the RTL stylesheet and set disabled manually,
		based on whether an Arabic character set is specified.
	*/
	var bIsRTL = isPageRTL();
	var sheets = document.styleSheets;
	for (var ix = 0; ix < sheets.length; ++ix)
	{
		if ((sheets[ix].href != undefined) && (sheets[ix].href.indexOf("usr_rtl.css") != -1))
		{
			sheets[ix].disabled = !bIsRTL;
			break;
		}
	}


	/*
		Safari hack. See comments in usr_rtl.css.
	*/
	if (bIsRTL)
	{
		// if this is Safari, add the class for Safari
		if ((window.navigator.userAgent.indexOf("AppleWebKit") >= 0) ||
			(window.navigator.userAgent.indexOf("Safari") >= 0))
		{
			// no sense passing this in because it's hardcoded in the CSS
			var strMenuID = "idMenu";

			// avoid error if there's no menu
			var eltMenu = document.getElementById(strMenuID);
			if (eltMenu != null)
				eltMenu.className += "clsMenuSafari";
		}
	}
}

function isPageRTL()
{
	/*
		Test all META tags to see if one specifies an Arabic character set
	*/
	var metas = document.getElementsByTagName("META");
	for (var i = 0; i < metas.length; ++i)
	{
		/*
			Safari is more strict about how we can access the DOM.
			IE and Firefox allow metas[i].attributes.content.nodeValue,
			but Safari does not.
		*/
		try
		{
			var nodeList = metas[i];
			var nodeAttr = nodeList.getAttributeNode("content");
			var nodeValue = nodeAttr.nodeValue;

			if (nodeValue.indexOf("windows-1256") != -1)
				return true;
		}
		catch (e)
		{
		}
	}
	return false;
}




/* --------------------------------------------------------------------------

	PAGE HEADER AND FOOTER FUNCTIONS

*/

/*
	Set document's title.

	If the <title> element is empty or doesn't exist, it uses the passed
	string. Then it appends the product name to the title. If nothing
	(or null) is passed, it uses the product name as the title.
*/
function setPageTitle(strTitle)
{
	
		document.title = getString("idProdNum") + " " + getString("idProdName") + ": " + getString("idDocType");
	
}

/*
	Write the page header

	The calling page should set the <title> element to the desired header
	text and page title. This function calls another that prepends the
	product name to the document title.
*/
function writeHeader(strTitle)
{
	// This lets the calling page override the <title> element.
	if (strTitle == null)
		strTitle = document.title;
	setPageTitle(strTitle);

	_writeHeader(strTitle);
}


/*
	This writes out a page's header, including the optional menu bar.
	The title parameter is optional. If passed, it's written out
	as the header text. If you're not including a picture of the device,
	remove the line containing "device.gif" and the three "<br>" lines 
	that follow it.
*/
function _writeHeader(strTitle)
{
	
	document.write("<div id=\"idHeader\">");
	document.write("<img id=\"idCopyright\" src=\"device.gif\" height=\"80\">");
	document.write("<br>");
	document.write("<br>");
	document.write("<br>");
	document.write("&nbsp; <img id=\"idImgHeader\" src=\"usr_logo_rgb.gif\">");
	

	if (strTitle == null)
		document.write("&nbsp;");	// to make sure header is tall enough
	else
		document.write(getString("idProdName") + ": " + getString("idDocType"));

	document.write("<\/div>");

	/*
		If this page doesn't include the menu script, don't create a menu
	*/
	if (typeof(createMenu) != "undefined")
		createMenu().write();

	document.write("<div id=\"idContent\">");
}


function writeFooter()
{
	document.write("<\/div>");
	document.write("<img id=\"idCopyright\" src=\"bg_color_cubes.gif\" width=\"16\" height=\"83\" \/>");
	document.write("<p class=\"clsCopyright\">&copy; 2005-2007 <a href=\"http://www.usr.com\">U.S. Robotics Corporation<\/a><\/p>");
}

