// -*- Mode: Java; -*-
// ----------------------------------------------------------------------
// FILENAME:	
//	portal.js	- client-attribute / preferences detection.
//
// DESCRIPTION:
//	Determine the .CSS filename (sans path) that should be used
//	to effect the appropriate font selections.
//
// ----------------------------------------------------------------------
// $Header: d:/cvs/webdocs/js/portal.js,v 1.3 2004/02/17 19:43:00 frotz Exp $
//

var xm = screen.width;			// Define xm (x-max)
var ym = screen.height;			// Define ym (y-max)
var cm = screen.colorDepth;		// Define cm (color-max)

// --[COOKIES]-----------------------------------------------------------
function get_cookie( name )
{
    var start = document.cookie.indexOf( name + "=" );
    var len = start+name.length+1;
    if ((!start) && (name != document.cookie.substring(0,name.length)))		{ return null; }
    if (start == -1)								{ return null; }
    var end = document.cookie.indexOf(";",len);
    if (end == -1)								{ end = document.cookie.length; }
    return( unescape( document.cookie.substring( len, end ) ) );
}

function set_cookie( name, value, expires )	{ document.cookie = name + "=" +escape( value ) + ";path=/;domain=" + location.hostname; }
function delete_cookie( name )			{ if (get_cookie( name )) { document.cookie = name + "=;path=/;domain=" + location.hostname + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } }

// --[IDENTITY]----------------------------------------------------------
function display_identity()
{
    var credentials = get_cookie( "Bugzilla_login" );
    if  (credentials != null)
    {
//	document.write( "<a href='/cgi-bin/login.pl?LOGOUT=1'>Logout</a>\n" );
//	document.write( " | \n" );
//	document.write( "<a href='/cgi-bin/login.pl?LOGIN=1'>Edit Profile</a>\n" );
//	document.write( "<br/>\n" );
    }
    else if (0)
    {
	document.write( "<form action='/cgi-bin/login.pl?AUTHENTICATE=1' method='POST'>\n" +
			"<input type='hidden' NAME='AUTHENTICATE' value='1'>\n" +
			"User: <input class='identityField' type='text' name='DOMAIN_LOGIN' size='6'> \n" +
			"Pass: <input class='identityField' type='password' name='PASSWORD' size='6'>\n" +
			"<input class='identityField' type='submit' value='Login'>\n" +
			"</form>\n" );
    }
    document.write( new Date() + " - " );
    document.write( xm + "x" + ym + "x" + cm + "\n" );
}
// --[THEMES]------------------------------------------------------------
function get_theme()
{
    var css = get_cookie( "theme" );
    css = (css == null) ? css = "wood.css" : css;
    return( css );
}
var theme_set = 0;
function set_theme( theme )
{
    if  (theme_set == 0)
    {
	set_cookie( "theme", theme );
    }
    theme_set = 1;
}
var last_theme = 0;
function theme( theme, display )
{
    var style = "";
    var cur_theme = get_theme();
    last_theme++;
    if  (last_theme > 1)	{ document.write( " | " ); }
    url = location.pathname;
    if  (cur_theme == theme)
    {
	style = "class=\"active\"";
    }
    document.write( "<a" + style + " href=\"" + url + "?theme=" + theme + "\" onclick=\"javascript:set_theme( '" + theme + "' ); return true;\">" + display + "</a>\n" );
}
function theme_list()
{
    document.write( "Themes: " );

    theme( "fire.css", "fire" );
    theme( "earth.css", "earth" );
    theme( "metal.css", "metal" );
    theme( "water.css", "water" );
    theme( "wood.css", "wood" );
}
// --[SIZES]-------------------------------------------------------------
function get_size()
{
    var size = get_cookie( "size" );
    size = (size == null) ? "medium.css" : size;
    return( size );
}
var last_size = 0;
function size( size, display )
{
    var style = "";
    var cur_size = get_size();
    last_size++;
    if  (last_size > 1)		{ document.write( " | " ); }
    url = location.pathname;
    if  (cur_size == size)
    {
	style = "class=\"active\"";
    }
    document.write( "<a" + style + " href=\"" + url + "?size=" + size + "\" onclick=\"javascript:set_size( '" + size + "' ); return true;\">" + display + "</a>\n" );
}
function set_size( size ) 	{ set_cookie( "size", size ); }
function size_list() 
{
    document.write( "Sizes: " );
    size( "small.css", "tiny" );
    size( "medium.css", "med" );
    size( "large.css", "big" );
}
