﻿


var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
    if ((navigator.userAgent.indexOf("Gecko") == -1) ||
		   (ugly_selectorText_workaround_flag)) {
        return; // we've already been here or shouldn't be here
    }
    var styleElements = document.getElementsByTagName("style");

    for (var i = 0; i < styleElements.length; i++) {
        var styleText = styleElements[i].firstChild.data;
        // this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
        // error in IE5, so we include the open brace and then strip it
        allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
    }

    for (var i = 0; i < allStyleRules.length; i++) {
        // probably insufficient for people who like random gobs of 
        // whitespace in their styles
        allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
    }
    ugly_selectorText_workaround_flag = true;
}



// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t, c, p, v) {
    var elements;
    if (t == '*') {
        // '*' not supported by IE/Win 5.5 and below
        elements = (ie) ? document.all : document.getElementsByTagName('*');
    } else {
        elements = document.getElementsByTagName(t);
    }
    for (var i = 0; i < elements.length; i++) {
        var node = elements.item(i);
        for (var j = 0; j < node.attributes.length; j++) {
            if (node.attributes.item(j).nodeName == 'class') {
                if (node.attributes.item(j).nodeValue == c) {
                    eval("node.style." + p + " = '" + v + "'");
                }
            }
        }
    }
}

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 var 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;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}
