// CHOICE FIELDS
// getSelect(s)
// used in all drop-down ACTION lists such as ACTIONS, etc. 
//Drop-down choices: this acts on the choice a user has made in the drop-down choice lists
function getSelect(s) {
// Get the select list value  
 url = s.options[s.selectedIndex].value;
// trap the delete 
if (url.indexOf('?DeleteDocument') != -1) { 
        if (!(confirm('Are you sure want to delete this item?'))) 
                return false; 
} else if (url == '') {
               return false;
} else if (url.indexOf('Back') != -1) {
	return 'javascript:parent.history.back()';
}
  return s.options[s.selectedIndex].value
}
// getSelected(s)
// returns value of seleted item in a list 
function getSelected(s) {
// Get the select list value  
s.options[s.selectedIndex].value;
return s.options[s.selectedIndex].value
}
//BUTTONS -- RADIO
function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function
//Radio button, return value selected
//example getSelectedRadioValue(document.forms[0].RadioButtonFieldName) 
function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function
//CHECK BOXES
function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function
//2nd part of function
function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function
//To use one of the above radio or checkbox functions, just make a call and pass the radio button or check box object. 
//For example, if you want to find out if at least one check box is selected and the check box field name is MyCheckBox
//then write the following statements:
//var checkBoxArr = getSelectedCheckbox(document.forms[0].MyCheckBox);
//if (checkBoxArr.length == 0) { alert("No check boxes selected"); }
//COPY
//March 2007. Works for IE, Firefox and Opera 8.5
function copy(text2copy) {
        if (window.clipboardData) {
          window.clipboardData.setData("Text",text2copy);
        } else {
          var flashcopier = 'flashcopier';
          if(!document.getElementById(flashcopier)) {
            var divholder = document.createElement('div');
            divholder.id = flashcopier;
            document.body.appendChild(divholder);
          }
          document.getElementById(flashcopier).innerHTML = '';
          var divinfo = '<embed src="' + WebGlobalSetup + '/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
          document.getElementById(flashcopier).innerHTML = divinfo;
        }
alert('Copied. Now paste where you wish.');
      }
    
// COOKIE
// deleteCookie(name, path, domain)
// 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)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
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";
  }
}
// COOKIE
// getCookie(name)
// name - name of the desired cookie
// * return 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;
  return unescape(dc.substring(begin + prefix.length, end));
}
// COOKIE
// setCookie(name, value, expires, path, domain, secure)
// This set of functions handles information to and from cookies
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
// DATE
// fixDate(date)
//No idea where this is used, if at all. Verify and if not used, delete. Jan 2003
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
// DELETING
// reopenView()
// used by VIEWDELETEDOC function 
function reopenView() {
var webdbview=webdbname + "/" + ViewName + "/";
location.href=webdbview;
}
// DELETING
// ViewDeleteDoc(UNID,returnURL)
//Calls on REOPENVIEW to work together to delete items from views (only in Contact Manager as of Nov 2002) and re-open view for user
//if no special returnURL is required, just supply a blank in the form of '' .  
//this is picked up by the $$ReturnDocumentDeleted form.  If returnURL is supplied blank, it will just reopen to the previous view
//sample in Notes function language:
//TempReturn := "/nin/teams.nsf/pages/" + @ReplaceSubstring(Team;" ";"");
//"<a href=\"javascript:ViewDeleteDoc('" + @Text(@DocumentUniqueID) +"','" + TempReturn + "'" + ")\">Delete</a>";
function ViewDeleteDoc(UNID,returnURL) {
var webdbview=webdbname + "/" + ViewName + "/";
var returntemp = ((returnURL) ? "&returnurl=" + returnURL : "");
if(confirm('Are you sure you want to delete this document?')){
window.location.href=webdbview+ UNID +"?DeleteDocument" +returntemp;
setTimeout("reopenView()",2000)}
}
// EMAIL ADDRESSES
// EmailScramble(TempName,TempDomain)
// e.g. EmailScramble('mbrown','acme.com')
//email address is contained in pages in a way that spammers can't harvest them
//but ordinary users can, because this writes it onto the page
function EmailScramble(TempName,TempDomain){
 var a,b,c,d,e
 a='<a title=\"' + TempName + '\" class=\"emaillink\" href=\"mai'
 b=TempName
 c='\">'
 a+='lto:'
 b+='@'
 e='</a>'
 b+=TempDomain
 document.write(a+b+c+b+e)
}
// LANGUAGE
// LanguageSwitch(TargetLang)
// Used on bilingual sites
//performs language switch. uses variables created in html head field
//usage example: LanguageSwitch("French")
function LanguageSwitch(TargetLang)
{
if (SwitchLanguageURL == 'NoTranslation')
{
alert(NotFoundMessage);
} else {
var exp = new Date();
var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000);
exp.setTime(oneYearFromNow);
setCookie('language',TargetLang.toLowerCase());
window.location=SwitchLanguageURL
}
}
//LEFT
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
// NAVIGATION
// checkSearch(s)
//performs jump-down in view rolodex function
function checkSearch(s)
{
var TempEntry;
var f = document.Views;
TempEntry = s.options[s.selectedIndex].value;
  //ViewName and webdbname are variables defined in HTML head;     
location.replace(webdbname + '/' + ViewName + '!OpenView&Startkey='+ TempEntry);
}
//MenuOpen(menuitem)
//Used for collapsible/tree style menu
//page also needs these global page variables which can't be inside function
//var ns6=document.getElementById&&!document.all?1:0
//var head="display:''"
//var folder=''
function MenuOpen(menuitem){
menucategory=ns6?menuitem.nextSibling.nextSibling.style:document.all[menuitem.sourceIndex+1].style
if (menucategory.display=="none")
menucategory.display=""
else
menucategory.display="none"
}
// REPLACE
// replacesubstring(fullS,oldS,newS)
// used by ViewSearch()
//imitates replacesubstring function in Notes
function replacesubstring(fullS,oldS,newS) {
for (var i=0; i<fullS.length; i++) { 
if (fullS.substring(i,i+oldS.length) == oldS) { 
fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length) 
} 
} 
return fullS 
}
//RIGHT
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// SEARCHING
//returnFalse(s)
function returnFalse(s){
//guess the field if not supplied
//s = (s == null) ? document.forms[0].Query : s;
//if you want to do the search, use this line
ViewSearch();
//if you want to alert the user, use this line
//alert('Please use the \'Arrow!!\' button to do a search');
//this line should always be here!!
return false;}
// ViewSearch()
//handles in-place search field on the web
function ViewSearch()
{
var msgEmpty;
var msgNotFound;
var msgFlag;
var URLToPass;
var Qry;
// For search and replace operation for Words variable;
var Words01;
var Words02;
var Words03;
var Words04;
var Words05;
var Words06;
var Words07;
var Words08;
var Words09;
var Words10;
var Words;
var f= document.forms[0];
var TargetField = f.SearchInput;
Qry = f.SearchInput.value;
Words01 = replacesubstring(Qry,' AND ','^');
Words02 = replacesubstring(Words01,' OR ','^');
Words03 = replacesubstring(Words02,' NOT ','^');
Words04 = replacesubstring(Words03,' FIELD ','^');
Words05 = replacesubstring(Words04,' CONTAINS ','^');
Words06 = replacesubstring(Words05,' and ','^');
Words07 = replacesubstring(Words06,' or ','^');
Words08 = replacesubstring(Words07,' not ','^');
Words09 = replacesubstring(Words08,' field ','^');
Words10 = replacesubstring(Words09,' contains ','^');
Words = replacesubstring(Words10,' ','^');
Qry1 =Qry;
Qry2 = replacesubstring(Qry1," and "," ~~~ ");
QrySend = replacesubstring(Qry," ","+");
//Now we have pure seach words separated by a ^ ready to pass to agent;
msgFlag = "false";
if (LanguagePref == "French") {
msgEmpty = "Veuillez entrer quelque chose";
}
 else
{
msgEmpty = "Please enter something to search on";
}
if (Qry == "") {
            alert(msgEmpty);
            TargetField.focus();	
            return false;
          } 
else {
  //ActiveSearchDb is a variable defined in HTML head;
  //websiteurl is a variable defined in HTML head;
URLToPass = 'http://' + websiteurl + '/' + ActiveSearchDb + '/Search?openagent&Query='+ QrySend + '&SearchOrder=1&SearchMax=0&SearchWV=No&SeeAlso=No&Words=' + Words + '&DB=All' + '&language=' + LanguagePref;
//must use window.open specifying _top or you get into window location & history issues;
//window.open = (URLToPass,'_top')
location.href = URLToPass
}
}
/***********************************************************
trim is a simple function to remove leading/trailing spaces
************************************************************/
function trim(aStr) {
	return aStr.replace(/^\s{1,}/, "").replace(/\s{1,}$/, "")
}
/***********************************************************
Propercase is the equaivalent of @propercase
************************************************************/
function Propercase(STRING){
var strReturn_Value = "";
var iTemp = STRING.length;
if(iTemp==0){
return"";
}
var UcaseNext = false;
strReturn_Value += STRING.charAt(0).toUpperCase();
for(var iCounter=1;iCounter < iTemp;iCounter++){
if(UcaseNext == true){
strReturn_Value += STRING.charAt(iCounter).toUpperCase();
}
else{
strReturn_Value += STRING.charAt(iCounter).toLowerCase();
}
var iChar = STRING.charCodeAt(iCounter);
if(iChar == 32 || iChar == 45 || iChar == 46){
UcaseNext = true;
}
else{
UcaseNext = false
}
if(iChar == 99 || iChar == 67){
if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
UcaseNext = true;
}
}
} //End For
return strReturn_Value;
} //End Function
// VALIDATION
// isBlank(fieldName,fieldMsg)
function isBlank(fieldName,fieldMsg) {
var f = document.forms[0];
// Check field
if (fieldName.value == "" || fieldName.value == "null") {
msg = "Please fill in " + fieldMsg;
// Prompt user to enter the value if missing
fieldName.value = prompt (msg, "");
// If they hit cancel (returns "null") or still leave it blank, alert and return false
if (fieldName.value == "" || fieldName.value == "null") {
fieldName.value = ""
alert (msg);
fieldName.focus();
return false;
}
}
}
// WINDOWS - Full Size New Window
// NewWindow(ThisURL)
//Opens a full sized window and brings it to the foreground
//Does not attempt to manipulate anything about the user's browser, makes a regular new window
function newWindow(ThisURL) {
  TempWindow = window.open (ThisURL,'NewWindow');
TempWindow.focus()
}
// WINDOWS -- Popup
// HelpWindow(ThisURL)
//Used by "teacher" help to display the help in a popup-window
function HelpWindow(ThisURL) {
  TempWindow = window.open (ThisURL,'sub','height=400,width=400,scrollbars=yes');
TempWindow.focus()
}
// WINDOWS - Popup
// Popup(ThisURL)
//Opens a sized window and brings it to the foreground
//Used by online help
function Popup(ThisURL) {
  TempWindow = window.open (ThisURL,'sub','height=400,width=400,scrollbars=yes');
TempWindow.focus()
}
function toggleT(_w,_h) {
var ns4 = (document.layers); 
var ie4 = (document.all &&!document.getElementById); 
var ie5 = (document.all && document.getElementById); 
var ns6 = (!document.all && document.getElementById); 
// netscape 4 
if(ns4){ 
if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
} 
// Explorer 4 
else if(ie4){ 
if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
} 
// W3C - Explorer 5+ and netscape 6+ 
else if(ie5 || ns6){ 
if (_h=='s') eval("document.getElementById('" +_w+"').style.visibility='visible';");
if (_h=='h') eval("document.getElementById('" +_w+"').style.visibility='hidden';");
} 
}
function swapImg(name, newImg) 
{
document.images[name].src = newImg;
}
//converts rel="external" into target="_blank"
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
} 
