  
function select(element) {
    var row = element.parentNode;
    for (var i=0;i<row.childNodes.length;i++) {	    
        var e = row.childNodes[i];
        if (e.tagName == "TD" || e.tagName == "TH")
            e.style.borderBottomColor = 'red';
    }
    var table = row.parentNode;
    var rowbef;
    for (var i=0;i<table.childNodes.length;i++) {	
        var e = table.childNodes[i];		
        if (e == row) {
            rowbef = table.childNodes[i-1];
            if (rowbef.tagName != "TR")
                rowbef = table.childNodes[i-2];
        }
    }
    for (var i=0;i<rowbef.childNodes.length;i++) {	
        var e = rowbef.childNodes[i];
        if (e.tagName == "TD" || e.tagName == "TH")
            e.style.borderBottomColor = 'red';
    }
}

function selectDraggable(element) {
    select(element);
    element.style.cursor = "hand";
    element.style.backgroundColor = "#FAF4C0";
}

function unselect(element) {
    var row = element.parentNode;
    for (var i=0;i<row.childNodes.length;i++) {	
        var e = row.childNodes[i];		
        if (e.tagName == "TD" || e.tagName == "TH")
            e.style.borderBottomColor = '#CCCCCC';
            //e.style.borderBottomColor = '#C6C99E';
    }        
    var table = row.parentNode;
    var rowbef;
    for (var i=0;i<table.childNodes.length;i++) {	
        var e = table.childNodes[i];		
        if (e == row) {
            rowbef = table.childNodes[i-1];
            if (rowbef.tagName != "TR")
                rowbef = table.childNodes[i-2];
        }
    }
    for (var i=0;i<rowbef.childNodes.length;i++) {	
        var e = rowbef.childNodes[i];		        
        if (e.tagName == "TD" || e.tagName == "TH")
            e.style.borderBottomColor = '#CCCCCC';
            //e.style.borderBottomColor = '#C6C99E';
    }
}

function unselectDraggable(element) {
    unselect(element);
    element.style.cursor = "auto";
    element.style.backgroundColor = "transparent";
}

function CA(frm, src, targetName) {
    for (var i=0;i<frm.elements.length;i++) {	
        var e = frm.elements[i];		
        if ((e != src) && (e.name==targetName)) {	
            e.checked = src.checked;
        }
    }
    CCA(frm, targetName);
}

function CA2(frm, src, targetName, targetName2) {
    for (var i=0;i<frm.elements.length;i++) {	
        var e = frm.elements[i];		
        if ((e != src) && (e.name==targetName) && (!e.disabled)) {	
            e.checked = src.checked;
        }
    }
    CCA2(frm, targetName, targetName2);
}

function CCA(frm, targetName) {
    for (var i=0;i<frm.elements.length;i++) {	
        var e = frm.elements[i];		
        if ((e.name == targetName) && (e.checked == true)) {	
            e.parentNode.parentNode.style.backgroundColor = '#FAF4C0';
        } else if ((e.name == targetName) && (e.checked == false)) {
            e.parentNode.parentNode.style.backgroundColor = '#FFFFFF';
        }
    }
}

function CCA2(frm, targetName, targetName2) {
    for (var i=0;i<frm.elements.length;i++) {	
        var e = frm.elements[i];		
        if ((e.name == targetName) && (e.checked == true)) {	
            e.parentNode.parentNode.style.backgroundColor = '#FAF4C0';
        } else if ((e.name == targetName) && (e.checked == false)) {
            e.parentNode.parentNode.style.backgroundColor = '#FFFFFF';
        }
    }
    for (var i=0;i<frm.elements.length;i++) {	
        var e = frm.elements[i];		
        if ((e.name == targetName2) && (e.checked == true)) {	
            e.parentNode.parentNode.style.backgroundColor = '#FAF4C0';
        }
    }        
}

function selectgroup(element) {
    var row = element.parentNode;
    var rows = document.getElementsByName(row.id);
    rowtop = rows[0];
    row = rows[rows.length-1];

    // get the last row
    for (var i=0;i<row.childNodes.length;i++) {	
        var e = row.childNodes[i];		
        e.style.borderBottomColor = 'red';
        //e.style.borderBottomWidth = '2px';
    }
    var table = rowtop.parentNode;
    var rowbef;
    for (var i=0;i<table.childNodes.length;i++) {	
        var e = table.childNodes[i];		
        if (e == rowtop) {
            rowbef = table.childNodes[i-1];
        }
    }
    for (var i=0;i<rowbef.childNodes.length;i++) {	
        var e = rowbef.childNodes[i];		
        e.style.borderBottomColor = 'red';
        //e.style.borderBottomWidth = '2px';
    }
}

function unselectgroup(element) {
    var row = element.parentNode;
    var rows = document.getElementsByName(row.id);
    rowtop = rows[0];
    row = rows[rows.length-1];

    // get the last row
    for (var i=0;i<row.childNodes.length;i++) {	
        var e = row.childNodes[i];		
        //e.style.borderBottomColor = '#C6C99E';
        e.style.borderBottomColor = '#CCCCCC';
    }
    var table = rowtop.parentNode;
    var rowbef;
    for (var i=0;i<table.childNodes.length;i++) {	
        var e = table.childNodes[i];		
        if (e == rowtop) {
            rowbef = table.childNodes[i-1];
        }
    }
    for (var i=0;i<rowbef.childNodes.length;i++) {	
        var e = rowbef.childNodes[i];		
        //e.style.borderBottomColor = '#C6C99E';
        e.style.borderBottomColor = '#CCCCCC';
    }
}

function syncSelect(element) {
    var others = document.getElementsByName(element.name);

    for (var i=0; i<others.length; i++) {
        others[i].value = element.value;
    }
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {    
    if (name == "user.firstName")
        value = Base64.encode(value);
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    if (name == "user.firstName")
        return Base64.decode(unescape(dc.substring(begin + prefix.length, end)));
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }
}

   // CONSTANTS
  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format, print) {  // use: formatNumber(number, "format")
    if (print) document.write("formatNumber(" + number + ", \"" + format + "\")<br>");

    //if (number - 0 != number) return null;  // if number is NaN return null
    if (number - 0 != number) number = 0;  // if number is NaN make number = 0
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

 // patch provided by Patti Marcoux 1999/08/06
      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }




