var CLAP_STATE = [];
var CLAP_OPEN_TEXTS = [];
var CLAP_CLOSED_TEXTS = [];
var CLAPPEE_ELEMENTS = [];
var _CSS_OPEN_STYLE = 'url(#Application.EditorHome#/images/clap-minus.gif) no-repeat 0 50%';
var _CSS_CLOSED_STYLE = 'url(#Application.EditorHome#/images/clap-plus.gif) no-repeat 0 50%';
_CLOSED = 0;
_OPEN = 1;
clap = function(prefix) {
// get number of elements to open or close
clappees = CLAPPEE_ELEMENTS[prefix];
if (CLAP_STATE[prefix] == _OPEN) {
for (i = 0; i < clappees.length; i++) clappees[i].style.display = 'none';
CLAP_STATE[prefix] = _CLOSED;
if (CLAP_CLOSED_TEXTS[prefix])
document.getElementById(prefix + 'clapper').firstChild.nodeValue = CLAP_CLOSED_TEXTS[prefix];
document.getElementById(prefix + 'clapper').style.background = _CSS_CLOSED_STYLE;
} else {
for (i = 0; i < clappees.length; i++) {
// check if someone else wants this element to stay closed
openit = true;
classes = clappees[i].className.split(' ');
if (classes.length > 1) {
for (j = 0; j < classes.length; j++) {
if ((classes[j] != prefix + 'clappee') && (classes[j].indexOf('clappee') > -1)) {
prefix2 = classes[j].replace('clappee','');
if (CLAP_STATE[prefix2] == _CLOSED) openit = false;
}
}
}
if (!openit) continue;
if (clappees[i].nodeName == 'TR') {
try { clappees[i].style.display = 'table-row'; } // this fails with some browsers
catch (err) { clappees[i].style.display = 'block'; }
} else
clappees[i].style.display = 'block';
}
CLAP_STATE[prefix] = _OPEN;
if (CLAP_OPEN_TEXTS[prefix])
document.getElementById(prefix + 'clapper').firstChild.nodeValue = CLAP_OPEN_TEXTS[prefix];
document.getElementById(prefix + 'clapper').style.background = _CSS_OPEN_STYLE;
}
makeAjaxRequest('#Application.EditorHome#SaveClapperState.cfm?state=' + CLAP_STATE[prefix] + '&prefix=' + prefix);
}
initclapper = function() {
if(!document.getElementsByTagName){return;}
closedClappersDB = '#strClosed#';
// put all dom elements "*clappee" in arrays by prefix
var arrElements = (document.all)? document.all : document.getElementsByTagName('*');
for (x = 0; x < arrElements.length; x++) {
if (arrElements[x].className) {
// split multiple classes, i.e. "class='synclappee taxsectionclappee'"
classes = arrElements[x].className.split(' ');
for (y = 0; y < classes.length; y++) {
if (classes[y].indexOf('clappee') > -1) {
prefix = classes[y].replace('clappee','');
if (!CLAPPEE_ELEMENTS[prefix])
CLAPPEE_ELEMENTS[prefix] = new Array();
CLAPPEE_ELEMENTS[prefix].push(arrElements[x]);
}
}
}
}
arrElements = null;
for (x = 0; x < CLAP_PREFIXES.length; x++) {
prefix = CLAP_PREFIXES[x];
eval('document.getElementById(\'' + prefix + 'clapper\').onclick = function() { clap(\'' + prefix + '\'); return false; }');
CLAP_STATE[prefix] = _OPEN;
if (closedClappersDB.indexOf(' ' + CLAP_PREFIXES[x] + ' ') != -1)
clap(prefix);
else
document.getElementById(prefix + 'clapper').style.background = _CSS_OPEN_STYLE;
}
}
addevent(window, "load", initclapper);