/* utils.js */


/********************************************************************
 sample use:
<script language="JavaScript" type="text/javascript">
<!--
	document.write("GKSSA Webmaster: ");
	writeMLink('addr', 1, "32767.w", "sympatico", "ca");
-->
</script>
********************************************************************/
function writeMLink()	
{
	//from noSpam() : from Chris Sansom at <http://macintouch.com/spam.html>
	
    var link = arguments[0]; // text for the link 
    		// ''      - just glues the pieces; does not form an A tag
    		// 'addr'  - email address in HREF used as displayed text for the A tag
    		// other   - first parameter used as displayed text
    var pre = arguments[1];  // number of segments before the @ 

    var myat = String.fromCharCode(64);   // @ 
    var mydot = String.fromCharCode(46);  // . 
    var addr = ''; 

    // starting from the third argument, 
    // read the segments and build the address: 
    var i; 
    for (i = 2; i < arguments.length; i++)
    { 
        if (addr)
        { 
            // check whether this element (any but the first) 
            // comes after the @ or a dot: 
            addr += (i == pre + 2) ? myat : mydot; 
        } 
        addr += arguments[i]; 
    } 

    var str = ''; 
    if (link)
    { 
        // you could break this down further so that 
        // the 'mailto' is less apparent: 
        str = '<a class="ml" href="mailto:' + addr + '">'; 

        // if the first argument was literally 'addr', the text for the link 
        // is the address itself, otherwise it's the text of the argument: 
        str += (link == 'addr') ? addr : link; 

        str += '<\/a>';  // close the tag 
    } 
    else
    { 
        // if the first argument is '' just print the address 
        // without making it a link at all: 
        str = addr; 
    } 

    document.write(str); 
}	// writeMLink()


function isOlderBrowser()
{
	//  inherits var browser

	bIsOlder = false;
	
	// ugh!  look in userAgent or appName?
	// let's try appName (more dependable?)
	
	// TODO? what about other browsers that don't claim to be even Mozilla/4.x?
	var strAppName = navigator.appName.toLowerCase();
	
	if (browser.nn || browser.ie)
	{
		if (browser.major < 5)
		{
			if (strAppName.indexOf('netscape') == 0)
			{
				bIsOlder = true;
			}
			else
			{
				if (strAppName.indexOf('microsoft') == 0)
				{
					// don't be fooled by userAgent like:
					// 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)'
					var ua = navigator.userAgent.toLowerCase();
					
					if (ua.indexOf('msie 4') != -1)
					{
						bIsOlderBrowser = true;
					}
				}
			}
		}
	}	
	return bIsOlder;
}


function toggleMatchesDisclosure(sDivId, sImgId)
{
	var elContainer = document.getElementById(sDivId);
	if (elContainer)
	{
		elContainer.style.display = (elContainer.style.display == 'none' ? 'block' : 'none');

		var elDisclosure = document.getElementById(sImgId);
		if (elDisclosure)
		{
			elDisclosure.src = (elContainer.style.display == 'none' ? 'images/disclosure_closed.gif' : 'images/disclosure_open.gif');
		}
		//else alert('eek!');
	}
	//else alert("oh, oh");
}