/* $Id: calendar.js,v 1.8 2005/10/15 00:03:20 charlie Exp $
 * These functions are used with the Event Calendar to show and hide the
 * different events. Make sure pleasanton.js is included before this file.
 */
// Check if browser supports the DHTML functions we need.
var DHTML2 = (document.getElementsByTagName && (document.getElementById || document.all || document.layers));
// getObj. Browser dependent object.
function getObj(name) {
  if (document.getElementById) {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
  } else if (document.all) {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  } else if (document.layers) {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}
// inArray.
function inArray(ary, value) {
    for (var i=0; i < ary.length; i++) {
        if (ary[i] == value)
            { return true; }
    }
    return false;
};
// fWeightAll. Change the weight of the object.
// state. css font-weight string. on, off
// cnames. array of class names that should be changed.
function fWeightAll(state, cnames) {
    if (!DHTML2) return;
    for (var i=0; i<cnames.length; i++) {
        setCatState(state, cnames[i]);
    }
}
// displayAll. Set the visibility on the divs with the passed classnames.
// state. css visibility string. on, off.
// cnames. array of div class names to change.
function displayAll(state, cnames) {
    if (!DHTML2) return;
    var x = document.getElementsByTagName('div');
    for (var i=0; i<x.length; i++) {
        if (inArray(cnames, x[i].className))
        {
            if (state == 'off')  { x[i].style.display = 'none'; }
            else { x[i].style.display = 'inline'; }
        }
    }
}
// toggleVisibility. cname. The div class name to toggle.
function toggleVisibility(cname) {
    if (!DHTML2) return;
    // Turn all off.
    var x = document.getElementsByTagName('div');
    for (var i=0;i<x.length;i++) {
        if (x[i].className == cname) {
            if (x[i].style.display == 'inline' || x[i].style.display == '') {
                x[i].style.display = 'none';
            } else {
                x[i].style.display = 'inline';
            }
        }
    }
}
// toggleFWeight. name. the id name of the element to toggle.
function toggleFWeight(name) {
    if (!DHTML2) return;
    v = new getObj(name);
    if (v.style.fontWeight == 'bold' || v.style.fontWeight == '') {
        setCatState('off', name);
    } else {
        setCatState('on', name);
    }
}
// fWeightAllDivs. Set the font on the divs with the passed classnames.
// weight. css font-weight string. bold, normal.
// cnames. array of div class names to change.
function fWeightAllDivs(weight, cnames) {
    if (!DHTML2) return;
    var x = document.getElementsByTagName('div');
    for (var i=0; i<x.length; i++) {
        if (inArray(cnames, x[i].className))
            { x[i].style.fontWeight = weight; }
    }
}
// state. visi. css visibility string. on, off.
// cname. The div class name to toggle.
function visibility(state, cname) {
    if (!DHTML2) return;
    var x = document.getElementsByTagName('div');
    for (var i=0;i<x.length;i++) {
        if (x[i].className == cname) {
            if (state == 'off')  { x[i].style.display = 'none'; }
            else { x[i].style.display = 'inline'; }
        }
    }
}
// state. visi. css visibility string. on, off.
// cname. The div class name to toggle.
function setCatState(state, cname) {
    if (!DHTML2) return;
    y = new getObj(cname);
    z = new getObj(cname+"Li");

    if (state == 'on') {
        y.style.fontWeight = 'bold';
        z.obj.src = '/resources/images/greenlight.gif';
    } else {
        y.style.fontWeight = 'normal';
        z.obj.src = '/resources/images/redlight.gif';
    }
}
// setCalCookies. idnames. array of id names that should be checked.
function setCalCookies(idnames) {
    if (!DHTML2) return;
    if (!COOKIES) return;
    setPlsCookie( 'hascookies', '1', '365', '/', '', '' );
    for (var i=0; i<idnames.length; i++) {
        w = new getObj(idnames[i]);
        if (w.style.fontWeight == 'bold' || w.style.fontWeight == '')
            { setPlsCookie( idnames[i], '1', '365', '/', '', '' ); }
        else
            { setPlsCookie( idnames[i], '0', '365', '/', '', '' ); }
    }
}
// idnames. array of id names that should be checked.
function getCalCookies(idnames) {
    if (!DHTML2) return;
    if (!COOKIES) return;
    var c;
    for (var i=0; i<idnames.length; i++) {
        //c = '1'; // Default to on.
        c = getPlsCookie(idnames[i]);
        if (c == '0') {
            visibility('off', idnames[i]);
            setCatState('off', idnames[i]);
        } else if (c == '1') {
            visibility('on', idnames[i]);
            setCatState('on', idnames[i]);
        }
    }
}
// cn. category name.
// cnames. array of class names that should be changed.
function onlyThisCat(cn, cnames) {
    displayAll('off', cnames);
    fWeightAll('off', cnames);
    toggleVisibility(cn);
    toggleFWeight(cn);
    setCalCookies(cnames);
}

