<!-- -*-java-*- -->

var pageMode = getPageMode();
var currWindow = null;
var browserWidth = 0;
var browserHeight = 0;
var currBox = null;

function isMac() {return (navigator.appVersion.indexOf("Mac") != -1);}
function isIEMac() {return (document.all) && isMac();}
function isIE5() {return (navigator.userAgent.indexOf("MSIE 5") > -1);}
function isIE6() {return (navigator.userAgent.indexOf("MSIE 6") > -1);}
function isOpera() {return (navigator.userAgent.indexOf("Opera") > -1);}
function isNavSafari() {return (navigator.userAgent.indexOf("Safari") > -1);}
function isSafari() {return isNavSafari() && (navigator.userAgent.indexOf("Mac") > -1);}

if (isIEMac())
{
    document.location.href = "/cgi/station";
}

// Error if this is IE on the Mac
function checkBrowser()
{
    if (isIEMac())
    {
	alert("Internet Explorer Mac");
    }
}

// Adjust pop-up menu position for IE.
function adjustForIE() {return((isIE5() || isIE6()) ? 2 : 0);}

// Alias for document.getElementById().
function getElemId(id) {return document.getElementById(id);}

// Change the focus to an object by id
function focusOn(id) 
{
    var obj = getElemId(id);
    if (obj != null) 
	obj.focus();
}

function focusField(id)
{
    document.getElementById(id).focus();
}

// Page mode -- 0: quirks, 1: strict
function getPageMode() 
{
    if (document.compatMode)
    {
	switch (document.compatMode)
	{
	case "BackCompat":
	    return 0;
	case "CSS1Compat":
	    return 1;
	case "QuirksMode":
	    return 0;
	}
    }
    else
    {
	if (isIE5())
	    return 0;
	if (isSafari())
	    return 1;
    }
    
    return 0;
}

// Get the clientHeight property.
function getClientSize()
{
    if (typeof(window.innerWidth) == 'number') 
    {
	// Non-IE
	browserWidth = window.innerWidth;
	browserHeight = window.innerHeight;
    } 
    else if (document.documentElement &&
	     (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
    {
	// IE 6+ in 'standards compliant mode'
	browserWidth = document.documentElement.clientWidth;
	browserHeight = document.documentElement.clientHeight;
    } 
    else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
    {
	// IE 4 compatible
	browserWidth = document.body.clientWidth;
	browserHeight = document.body.clientHeight;
    }
    
    //window.alert('Width = ' + browserWidth);
    //window.alert('Height = ' + browserHeight);
}

// Get the clientHeight property.
function getClientHeight()
{
    switch (pageMode)
    {
    case 0:
	return document.body.clientHeight;
    case 1:
	if ((!isOpera()) && document.documentElement && (document.documentElement.clientHeight > 0))
	    return document.documentElement.clientHeight;
	else
	    return document.body.clientHeight;
    }
}

// Get the clientWidth property.
function getClientWidth()
{
    switch (pageMode)
    {
    case 0:
	return document.body.clientWidth;
    case 1:
	if ((!isOpera()) && document.documentElement && (document.documentElement.clientWidth > 0))
	    return document.documentElement.clientWidth;
	else
	    return document.body.clientWidth;
    }
}

// Display a popup window
function popup(url, name, w, h)
{
    var left = (window.screen.width / 2) - (w / 2);
    
    w = window.open(url, name,
		    "resizable=1,status=0,scrollbars=yes,toolbar=0,width=" + w + 
		    ",height=" + h + ",top=50," + "left=" + left);
    
    if (!w.opener)
	w.opener = self;
    
    if (window.focus) 
	w.focus()
    
    return false;
}

function showBox(id)
{
    if (currBox != null)
	hideBox(currBox);
    
    var winObj = getElemId(id);
    if (winObj != null)
	winObj.style.visibility = "visible";

    currBox = id;
}

function hideBox(id)
{
    var winObj = getElemId(id);
    if (winObj != null)
	winObj.style.visibility = "hidden";

    currBox = null;
}

function toggleBox(id)
{
    if (currBox == null)
	showBox(id);
    else if (currBox == id)
	hideBox(id);
}

function createCookie(name, value, days) 
{
    if (days) 
    {
	var date = new Date();	
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
    }
    else 
	expires = "";
    
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) 
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) 
    {
    	var c = ca[i];
    	while (c.charAt(0) == ' ') 
	    c = c.substring(1,c.length);
    	if (c.indexOf(nameEQ) == 0) 
	    return c.substring(nameEQ.length, c.length);
    }
    
    return null;
}



