/*
Name: global.js
Author: Tim Siney/IHQ/SArmy
Description: global javascript functions
Date: 08/10/02
Copyright: 2002 The Salvation Army
*/
//redirectToDev();
function redirectToDev() {
// Redirect to development
var loc=document.location.href.toLowerCase();
window.status="Redirecting to Development Server.";
if (loc.indexOf('secure1')!=-1) {
document.location.href=loc.replace('https://secure1','http://saihqd');
}
}
function openWindow(page) {
OpenWin = window.open(page, "CtrlWindow", "width=600, height=500, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes");
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//Search functions
function returnFalse(s){
//guess the field if not supplied
s = (s == null) ? document.forms[0].Query : s;
//do the search
doSearch(s);
//this line should always be here!!
return false;
}
function openDbRelativeURL( url, target ){
//Check we have a target window;
target = (target == null ) ? window : target;
if (target == null || target==undefined) {
target=this;
}
//Work out the path of the database;
path = location.pathname.split('.nsf')[0] + '.nsf/';
target.location.href = path + url;
}
function doSearch ( s ) {
var regExp1 = /\bfield\b/;
var regExp2 = /[(,),<,>,\[,\]]/;
var str = s.value;
if ( str == "" ){
alert("Bitte geben Sie mindestens einen Suchbegriff ein.\n\nVeillez a ne pas lancer de recherche en laissant le champ de recherche vide.");
s.focus();
} else {
if ( typeof regExp1.source != 'undefined' ) //supports regular expression testing
if ( regExp1.test( str ) || regExp2.test( str ) ){
var alrt = "Bitte benutzen Sie keines der folgenden Zeichen:\nVous ne pouvez pas inclure :";
alrt += "\n\nDas Wort/le mot 'field'\n [, ], (, ), < or >";
s.focus();
return alert( alrt );
}
//First lets strip out all values in qoutes, to ensure they are left intact:
var regExp1 = /"[a-z0-9 ]+"/gi;
var str1 = str.match(regExp1);
//Strip out the quoted string
str = str.replace(str1, "");
//Strip out "and" from the string and replace with " ",
//ensuring we dont strip out "and" from within other words
str = str.replace(/\band\b/gi, " ")
//Strip out leading and trailing spaces
str = str.replace(/ $/gi, "")
str = str.replace(/^ /gi, "")
//return strings not in qoutes and replace " " with " AND "
var str2 = str.replace(/ +/gi, " AND ");
//lets find out what the user wants to search for
var path;
path = "vw_search_all";
//This is hidden when served up by domino
//if the Books category doesn't exist
//finally, lets build the search string
var searchString;
if(str1 == null){
searchString = str2;
}
if(str2 == ""){
searchString = str2;
}
if((str1 !== null) && (str2 !== "")){
searchString = str1 + " AND " + str2;
}
openDbRelativeURL(path + "?SearchView&Query=" + escape( searchString ) + "&start=1&count=10&SearchFuzzy=False");
}
}
function uppercase()
{
key = window.event.keyCode;
if ((key > 0x60) && (key < 0x7B))
window.event.keyCode = key-0x20;
}
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
// if the treatAsPhrase parameter is true, then we should search for
// the entire phrase that was entered; otherwise, we will split the
// search string so that each word is searched for and highlighted
// individually
if (treatAsPhrase) {
searchArray = [searchText];
} else {
searchArray = searchText.split(" ");
}
if (!document.body || typeof(document.body.innerHTML) == "undefined") {
if (warnOnFailure) {
alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
}
return false;
}
var bodyText = document.body.innerHTML;
for (var i = 0; i < searchArray.length; i++) {
bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
}
document.body.innerHTML = bodyText;
return true;
}
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag)
{
// the highlightStartTag and highlightEndTag parameters are optional
if ((!highlightStartTag) || (!highlightEndTag)) {
highlightStartTag = "";
highlightEndTag = "";
}
// find all occurences of the search term in the given text,
// and add some "highlight" tags to them (we're not using a
// regular expression search, because we want to filter out
// matches that occur within HTML tags and script blocks, so
// we have to do a little extra validation)
var newText = "";
var i = -1;
var lcSearchTerm = searchTerm.toLowerCase();
var lcBodyText = bodyText.toLowerCase();
while (bodyText.length > 0) {
i = lcBodyText.indexOf(lcSearchTerm, i+1);
if (i < 0) {
newText += bodyText;
bodyText = "";
} else {
// skip anything inside an HTML tag
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
// skip anything inside a