CPS JavaScript functions
$Id: functions.js.dtml 32288 2006-01-26 17:36:06Z tziade $
var msie5 = (navigator.userAgent.indexOf('MSIE 5') != -1);
//************************************************************
// Folder content
var isSelected = false;
function toggleSelect(toggleSelectButton, selectAllText, deselectAllText) {
formElements = toggleSelectButton.form.elements;
if (isSelected) {
for (i = 0; i < formElements.length; i++) {
formElements[i].checked = false;
}
isSelected = false;
toggleSelectButton.value = selectAllText;
} else {
for (i = 0; i < formElements.length; i++) {
formElements[i].checked = true;
}
isSelected = true;
toggleSelectButton.value = deselectAllText;
}
}
//************************************************************
/**
* Toggles an element's visibility.
* Function to show tooltips.
* If your element is a span, you must use inline display instead of block
* XXX recognize div and span then automaticly choose the best display rule
*/
function toggleElementVisibility(id) {
element = document.getElementById(id);
if (element) {
//window.alert(element.tagName)
if (element.style.visibility == 'hidden') {
element.style.visibility = 'visible';
if (element.tagName == 'DIV') {
element.style.display = 'block';
} else if (element.tagName == 'SPAN') {
element.style.display = 'inline';
} else {
element.style.display = 'block';
}
} else {
element.style.visibility = 'hidden';
element.style.display = 'none';
}
}
}
function showElement(show, id) {
element = document.getElementById(id);
if (element) {
//window.alert(element.tagName)
if (show) {
element.style.visibility = 'visible';
if (element.tagName in ['DIV', 'P']) {
element.style.display = 'block';
} else {
element.style.display = 'inline';
}
} else {
element.style.visibility = 'hidden';
element.style.display = 'none';
}
}
}
//************************************************************
function trim(s) {
if (s) {
return s.replace(/^\s*|\s*$/g, "");
}
return "";
}
//************************************************************
function checkEmptySearch(formElem) {
var query = trim(formElem.SearchableText.value);
if (query != '') {
formElem.SearchableText.value = query;
return true;
}
formElem.SearchableText.value = query;
formElem.SearchableText.focus();
return false;
}
//************************************************************
/**
* Sets focus on elements that have a class attribute
* containing the class 'focus'.
* Examples:
*
*
*
* This function does not work on crappy MSIE5.0 and MSIE5.5.
*/
function setFocus() {
if (msie5) {
return false;
}
var elements = document.getElementsByTagName('input');
for (var i = 0; i < elements.length; i++) {
var nodeClass = elements[i].getAttributeNode('class');
//alert("nodeClass = " + nodeClass);
if (nodeClass) {
var classes = nodeClass.value.split(' ');
for (var j = 0; j < classes.length; j++) {
if (classes[j] == 'focus') {
elements[i].focus();
return true;
}
}
}
}
}
/**
* Validates that the input fields designated by the given ids are not empty.
* It returns true if all the input fields are not empty, it returns false
* otherwise.
* Example:
*