/*
This file is part of slidePresenter: real-time slideshow presentations via web browser
Copyright (C) 2006 Allen Shaw
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
$Id$
*/
// Functions useful for improving control functionality
var common_controls_sets = new Array();
function addSetItem(set, id, val) {
common_controls_sets[set][id] = val;
return 1;
}
function setInfoBox(box,set,id) {
value = common_controls_sets[set][id]
value = value.replace(/</g, '<');
value = value.replace(/>/g, '>');
value = value.replace(/"/g, '"');
value = value.replace(/&/g, '&');
setControlValue(box,value);
return 1;
}
function disableControl(controlId, val, reverse){
element = document.getElementById(controlId);
if (reverse) {
if (val) {
element.disabled = false;
} else {
element.disabled = true;
}
} else {
element.disabled = val;
}
return 1;
}
function hideControl(controlId, val, reverse){
element = document.getElementById(controlId);
if (reverse) {
show = "hidden";
hide = "visible";
} else {
show = "visible";
hide = "hidden";
}
if (val) {
element.style.visibility = hide;
} else {
element.style.visilibity = show;
}
return 1;
}
function collapseControl(controlId, val, reverse){
element = document.getElementById(controlId);
if (reverse) {
show = "none";
hide = "block";
} else {
show = "block";
hide = "none";
}
if (val) {
element.style.display = hide;
} else {
element.style.display = show;
}
return 1;
}
function setControlValue(controlId,val) {
element = document.getElementById(controlId);
if (element.type == "checkbox") {
element.checked = val
} else {
element.value = val
}
return 1;
}
function appendControlValue(controlId,val) {
var element;
var space = '';
element = document.getElementById(controlId);
if (element.value) {
space = ' ';
}
element.value = element.value + space + val;
return 1;
}
function moveSelectOption(controlId,rel,setFocus) {
var element;
element = document.getElementById(controlId);
var index = element.selectedIndex;
var total = element.options.length-1;
if (setFocus) {
element.focus();
}
if (index == -1) return false;
if (rel == +1 && index == total) return false;
if (rel == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = element.options[i].text;
values[i] = element.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
element.options[i + rel] = new Option(items[i],values[i], 0, 1);
element.options[i] = new Option(items[i + rel], values[i + rel]);
i--;
}
else {
element.options[i] = new Option(items[i], values[i]);
}
}
return 1;
}
function deleteSelectOption(controlId,setFocus) {
var element = document.getElementById(controlId);
var index = element.selectedIndex;
element.options[index] = null;
if (setFocus) {
element.focus();
if (element.options[index]) {
element.selectedIndex = index;
} else {
element.selectedIndex = element.options.length - 1;;
}
}
return 1;
}
function appendSelectOption(controlId,text,value,setFocus) {
var element = document.getElementById(controlId);
var total = element.options.length;
element.options[total] = new Option(text,value);
element.selectedIndex = total;
if (setFocus) {
element.focus();
if (element.options[index]) {
element.selectedIndex = index;
} else {
element.selectedIndex = 0;
}
}
return 1;
}
function setAction(id, formId){
document.getElementById('action'+formId).value = id;
}