<!--  Copyright (c) 1997 - 2008, SirsiDynix - JavaScript functions defined in every page. -->
// include localization testing in mockup
// document.write('<script type="text/javascript" src="javascript/localization.js"></script>');

var iframeHistory = 0;
var ieVersion;
var detectedBrowser = navigator.appName;
var columns;
var nested_columns;
var content_containers;
var margins;
var padding;
var columnWidthDifference;
var ieColumnWidth;
var ieNestedColumnWidth;
var columnImages;
var columnImagesWidth;
var windowWidth;
var sendCurrentTab;

document.observe('dom:loaded', function() {
  browserDetection();
  storeElements();
  renderColumns();
  iphoneDisplay();
  contentDecorations();
  eventHandlers();
  initializeWebApp();
  renderColumns();
});

window.onload = function() {
  pngFix();

}

function pngFix() {
  if (ieVersion == null) {
    browserDetection();
  }
  if (ieVersion == 6) {
    $$('img').each( function(img) {
      currentImage = img;
      imgName = currentImage.src.toUpperCase();
      if (imgName.endsWith("PNG")) {
         imgID = (currentImage.id) ? "id='" + currentImage.id + "' " : "";
         imgClass = (currentImage.className) ? "class='" + currentImage.className + "' " : "";
         imgTitle = (currentImage.title) ? "title='" + currentImage.title + "' " : "title='" + currentImage.alt + "' ";
         imgStyle = "display:inline-block;" + currentImage.style.cssText; 
         if (currentImage.align == "left") {
           imgStyle = "float:left;" + imgStyle;
         }
         if (currentImage.align == "right") {
           imgStyle = "float:right;" + imgStyle;
         }
         if (currentImage.parentElement.href) {
           imgStyle = "cursor:hand;" + imgStyle;
         }
         if (ieVersion == 6) {
           strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "margin:2px; width:" + currentImage.width + "px; height:" + currentImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + currentImage.src + "\', sizingMethod='scale');\"></span>";
           
         }
         else {
           strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + currentImage.width + "px; height:" + currentImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + currentImage.src + "\', sizingMethod='scale');\"></span>";
         }
         currentImage.outerHTML = strNewHTML;
      }
    });
  }
}


function storeElements() {
  // store the columns
  columns = $$('.column');
  nested_columns = $$('.nested_column');
  
  // read margins and padding from css, and remove px. margin / padding not supported in all browsers, so we have to have margin-left, padding-left
  margins = parseInt(($$('.content_container')[0]).getStyle('margin-left').substring(0, ($$('.content_container')[0]).getStyle('margin-left').length-2));
  padding = parseInt(($$('.content')[0]).getStyle('padding-left').substring(0, ($$('.content')[0]).getStyle('padding-left').length-2));
  columnWidthDifference = (margins+padding)+15*2;
  
  // store initial column width for ie. ie returns style, ff returns offsetWidth?
  ieColumnWidth = parseInt(columns[columns.length-1].getStyle('width'));
  ieNestedColumnWidth = parseInt(columns[columns.length-1].getStyle('width'));

  content_containers = $$('.content_container');
  
  if(content_containers.length < 1) {
    return;
  }
  
  // slideshow image resizing. we want to resize images to be the width of the column they are displayed in
  // check to see if slideshow images exist on page, then store
  if ( $$('.slideShowImage') || $$('.scaleImage') ) {
    // array of slideshow image objects
    columnImages = ($$('.slideShowImage, .scaleImage'));
    // original image size
    columnImagesWidth = ($$('.slideShowImage, .scaleImage'));
    
    for (i = 0; i < columnImages.length; i++) {
      if (columnImages[i].width == 0) {
        columnImages[i].style.display = "block";
        columnImagesWidth[i] = columnImages[i].width;
        columnImages[i].style.display = "none";
      }
      else {
        columnImagesWidth[i] = columnImages[i].width;
      }
    }
  }
  if ($$('.slideshow_titles')[0]) {
    titles =  $$('.slideshow_titles .slideshow_title');
    slides =  $$('.slideshow_images img');
    description =  $$('.slideshow_description .slideshow_text');
    
    slideshow_images_container = slides[0].getOffsetParent();
    slideshow_images_container.style.height = slides[0].offsetHeight+"px"; 
    slideshow_description_container = description[0].getOffsetParent();
    slideshow_description_container.style.top =  slideshow_images_container.offsetHeight+90+"px";
    slideshow_parent = ($$('.slideshow_footers')[0]).getOffsetParent();
    ($$('.slideshow_footers')[0]).style.top = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+95+"px";
    slideshow_parent.style.height = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+($$('.slideshow_footers')[0]).offsetHeight+95+"px";
  }
}

function eventHandlers() {
  // event handlers to check if window has been resized. IE is slow
  // to do this, so we do a manual check, and then set a timeout to
  // do the update. actual behavior with resizing close to other
  // browsers now.

  updateScreen = self.setInterval("renderColumns()", 1000);

  if ( $$('.tabs_container li') ){
    tabs = $$('.tabs_container li');
    tabClasses = $$('.tabs_container li');
    for (i=0; i < tabs.length; i++) {
      tabClasses[i] = tabClasses[i].classNames().toString();
    }
    if (tabs[0]) {
      tabs[0].addClassName('selected_tab');
    }
    if ((sendCurrentTab != undefined) && ($('currentTab') != undefined)) {
      // for elibrary to load last tab clicked from hidden input
      if ($('currentTab').value == "") {
        tabs[0].addClassName('selected_tab');
      }
      else {
        tabs[0].removeClassName('selected_tab');
        displayTabPanels($('currentTab').value, tabs, tabClasses);
      }
    }
    tabs.each( function(tab) {
        tab.observe('click', function() {
            panel = tab.classNames().toString();
            displayTabPanels(panel, tabs, tabClasses);
        });
    });
  }
}

function displayTabPanels(panel, tabs, tabClasses) {
  var bFoundTab = false;
  // only passing in the name of the panel to display; ie from a link in the panel itself; not a tab
  if (tabs == undefined) {
     tabs = $$('.tabs_container li');
     tabClasses = $$('.tabs_container li');
    for (i=0; i < tabs.length; i++) {
      tabClasses[i] = tabClasses[i].classNames().toString();
    }
    for (i = 0; i < tabClasses.length; i++) {
      $(panel).style.display = "block";
      if (tabClasses[i].match(/selected_tab/)) {
        // we don't know the current panel. remove the classname from the selected tab, then extract classname from that to find panel to hide
        tabs[i].removeClassName('selected_tab');
        $(tabs[i].classNames().toString()).style.display = "none";
      }
      if (tabClasses[i] == panel) {
        tabs[i].addClassName('selected_tab');
        if ((sendCurrentTab) && ($('currentTab') != undefined)) {
          // for elibrary to keep track of current tab through cgi
          sendCurrentTab(tabClasses[i]);
        }
      }
    }
  }
  else {
    // tab is clicked
    for (i = 0; i < tabClasses.length; i++) {
      if ((tabClasses[i] == panel) || (tabClasses[i]+" selected_tab" == panel)) {
        bFoundTab = true;
        if ($(panel) != null) {
          $(panel).style.display = "block";
        }
        tabs[i].addClassName('selected_tab');
        if($('currentTab') != undefined) {
          $('currentTab').value = tabClasses[i];
        }
        if ((sendCurrentTab != undefined) && ($('currentTab') != undefined)) {
          // for elibrary to keep track of current tab through cgi
          sendCurrentTab(tabClasses[i]);
        }
      }
      else {
        $(tabClasses[i]).style.display = "none";
        tabs[i].removeClassName('selected_tab');
      }
    }
    if (bFoundTab == false) {
      tabs[0].addClassName('selected_tab');
      $(tabClasses[0]).style.display = "block"; 
      if($('currentTab') != undefined) {
        $('currentTab').value = tabClasses[0];
      }
      if ((sendCurrentTab) && ($('currentTab') != undefined)) {
        // for elibrary to keep track of current tab through cgi
        sendCurrentTab(tabClasses[i])
      }
    }
  }
}

function browserDetection() {
  // check the browser version so we can run conditional code later.
  // needs to be expanded to return all browsers.
  if (detectedBrowser == 'Microsoft Internet Explorer') {
    var searchFor  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (searchFor.exec( navigator.userAgent) != null)
      ieVersion = parseFloat( RegExp.$1 );
  }
  else {
    ieVersion = -1;
  }
}

function contentDecorations() {
  // add in content decorations - only if greater than ie6
  if (ieVersion > 6 || ieVersion == -1) {
    content_containers.each( function(content_container) {
      content_container.insert('<div class="top_edge"></div><div class="right_edge"></div><div class="bottom_edge"></div><div class="left_edge"></div><div class="top_left"></div><div class="top_right"></div><div class="bottom_right"></div><div class="bottom_left"></div>');
    });
  }
}

function renderColumns() {
  // some outside scripts may try to call renderColumns before data is loaded
  if (columns == null) {
    storeElements();
  }
  
  if (ieVersion == null) {
    browserDetection();
  }
  
  // resize all images with class slideShowImage to size of parent column if the width of the image is less than the width of the column
  if (columnImages != null && columnImages[0]) {
    columns.each( function(column) {
      var testColumnWidth = 0;
      var testColumnWidth = (column.offsetWidth)-columnWidthDifference;
      for (j = 0; j < columnImages.length; j++) {
        if (columnImages[j].descendantOf(column)) {
          if (columnImagesWidth[j] > testColumnWidth) {
            columnImages[j].style.width = testColumnWidth-columnWidthDifference+"px";
          }
          else {
            columnImages[j].style.width = columnImagesWidth[j]+"px";
          }
        }
      }
    });
  }
  
  // make the columns all the same height
  // reset column heights
	if ($$('.footer_container')[0] != undefined) {
  if ( (($$('.footer_container')[0]).style.textAlign != "")) {
    columns.each( function(column) {
      column.style.height =  "";
    });
    
    column_container_height = columns[0].offsetHeight;
  
    // set to current column container height
    columns.each( function(column) {
      column.style.height =  "";
    });
    column_container_height = columns[0].offsetHeight;
    
    columns.each( function(column) {
      if (column.offsetHeight > column_container_height) {
        column_container_height = column.offsetHeight;
      }
    });
    
    if (ieVersion == 6) {
        column_container_height = column_container_height + margins;
    }
    
    columns.each( function(column) {
      if (!column.className.match(/pct100/)) {
        column.style.height = column_container_height + "px";
      }
    });
  
    if (nested_columns != '') {
      nested_columns.each( function(nested_column) {
        nested_column.style.height = "";
      });
      
      nested_column_container_height = nested_columns[0].offsetHeight;
      
      nested_columns.each( function(nested_column) {
        if (nested_column.offsetHeight > nested_column_container_height) {
          nested_column_container_height = nested_column.offsetHeight;
        }
      });
      
      if (ieVersion == 6) {
          nested_column_container_height = nested_column_container_height + margins;
      }
      
      nested_columns.each( function(nested_column) {
        if (!nested_column.className.match(/pct100/)) {
          nested_column.style.height = nested_column_container_height + "px";
        }
      });
    }
    }  
    // fix last column width to prevent ie from moving columns around
    if (ieVersion == 6 || ieVersion == 7) {
      if (columns[columns.length-1].hasClassName("middle")) {
        // right to left support. turn off column borders based on orientation
        if (columns[columns.length-1].getStyle("float") == "left") {
          columns[columns.length-1].style.borderRight = "none";
        }
        else {
          columns[columns.length-1].style.borderLeft = "none";
        }
      }
  
      columns[columns.length-1].style.width = ieColumnWidth-.1+"%";
      if (nested_columns[0]) {
        nested_columns[nested_columns.length-1].style.width = ieNestedColumnWidth-.1+"%";
      }
    }
  }
}

function iphoneDisplay() {
   iphone = navigator.userAgent.toLowerCase();
   if (iphone.indexOf('iphone')!=-1) {
     // iphone specific code goes here
     // convert menus to dropdowns
     $$('.header_menu_container ul')[0].style.display = "none";
     getSelectedIndex="this.options[this.selectedIndex].value";
     $$('.header_menu_container')[0].insert("<select id='header_menu_dropdown' onchange='window.location="+getSelectedIndex+"'></select>");
     $('header_menu_dropdown').insert("<option value=''>Please make a selection</option>");
     $$('.header_menu_container ul li a').each( function(link) {
       $('header_menu_dropdown').insert("<option value='"+link.readAttribute('href')+"'>"+link.text+"</option>");
     });
   }
}

/*--- MODAL DIALOG BOX ---*/

function createModalDialogBox(content, contentTitle,  isIframe, hasIframeControls, isDraggable, isClosable, canMaximize, width, height) {
  // content -> url to load through ajax or iframe
  // contentTitle -> Title to display in modal window
  // isIframe -> load content into an iframe (true/false)
  // hasIframeControls -> display controls for Iframe navigation. forward, back, and open initial url in new window (true/false)
  // isDraggable -> modal window can be moved by the user
  // isClosable -> modal window has a close button
  // canMaximize -> modal window has a button that will maximize the window
  // width -> width of modal window in pixels or percentage (100px, 50%)
  // height -> height of modal window in pixels or percentage (100px, 50%)  
  
  var modalBackground = document.createElement('div');
  modalBackground.setAttribute('id', 'modalBackground');
  Element.extend(modalBackground);
  document.body.appendChild(modalBackground);
  
  if (modalBackground) {
    // get total height of document
    var documentHeight = 0;
    documentHeight += $$('.header_container')[0].offsetHeight;
    for (i = 0; i < $$('.header_menu_container').length; i++) {
      documentHeight += $$('.header_menu_container')[i].offsetHeight;
    }
    for (i = 0; i < $$('.columns_container').length; i++) {
      documentHeight += $$('.columns_container')[i].offsetHeight;
    }    
    documentHeight += $$('.footer_container')[0].offsetHeight;
    $('modalBackground').style.height = documentHeight+"px";
    // insert modal window into the main container which is modalBackground
    $('modalBackground').insert('<div id="modalWindow" style="display:none;"><div id="modalTitleBar"><div id="modalTitle"></div>');
    $('modalWindow').style.top = document.viewport.getScrollOffsets()[1]+'px';
    
    if (isClosable == true) {
      $('modalTitleBar').insert('<input id="modalClose" type="button" onclick="modalClose(\''+alert_closeMessage+'\');"/>');
    }
    if (width != '') {
      $('modalWindow').style.width = width;
    }
    if (height != '') {
      if (height.endsWith('%')) {
        height = height.substring(0, height.length-1);
        if (height.length < 3) {
          height = "0."+height;
          if (ieVersion == 6) {
             height = height * document.body.clientHeight;
          }
          else {
            height = Math.round(height * document.viewport.getHeight());
          }
        }
        else {
          if (ieVersion == 6) {
            height = document.body.clientHeight - 40;
          }
          else {
            height = document.viewport.getHeight() - 60;
          }
        }
        $('modalWindow').style.height = height+"px";
      }
      else if (height.endsWith('px')) {
        $('modalWindow').style.height = height;
      }
      else {
        $('modalWindow').style.height = height+"px";
      }
    }
    if (canMaximize == true) {
      $('modalTitleBar').insert('<input id="modalMaximize" type="button" onclick="modalMaximize(\''+width+'\',\''+height+'\');"/>');
    }
    $('modalWindow').insert('</div><div id="modalContentContainer"></div><div class="top_edge"></div><div class="right_edge"></div><div class="bottom_edge"></div><div class="left_edge"></div><div class="top_left"></div><div class="top_right"></div><div class="bottom_right"></div><div class="bottom_left"></div></div>');
    $('modalTitle').update(contentTitle);
    if (isDraggable == true) {
      new Draggable('modalWindow', {handle: 'modalTitleBar', starteffect: null, endeffect:null} );
    }
  }
  
  if (isIframe == false) {
    Effect.Appear('modalWindow', { duration: 1.0, queue: 'end' });
    $('modalContentContainer').style.overflow = 'auto';
    new Ajax.Request(content,
    {
      // prevent caching
      method: 'post',
      onSuccess: function(transport) {
        var response =  transport.responseText;
        $('modalContentContainer').insert(response);
      },
      onFailure: function() {
        $('modalContentContainer').insert(msg_failedAjax);
      },
      onComplete: function() {
        initializeLoadedAjax();
      }
    });
  }
  else {
    // fade doesn't play well with iframes.
    $('modalWindow').style.display = "block";
    var initialHistoryLength = history.length;
    iframeHistory = history.length;
    iframeHeight =  $('modalWindow').offsetHeight - $('modalTitleBar').offsetHeight - 26;
    sizeModification = 0;
    $('modalContentContainer').insert('<iframe style="height:'+iframeHeight+'px;" name="modalIframe" id="modalIframe" src="'+content+'" frameborder="0" style="display:block"></iframe>');
    if (hasIframeControls == true) {
      $('modalContentContainer').insert('<div id="modalIframeControls"><input class="admin_button" type="button" id="modalIframeGoBack" onclick="modalIframeGoBack('+initialHistoryLength+');" value="'+button_modalIframeGoBack+'"/><input class="admin_button" type="button" id="modalIframeRemoveFrame" onclick="modalIframeRemoveFrame(\''+content+'\');" value="'+button_removeIframe+'"/><input class="admin_button" type="button" id="modalIframeGoForward" onclick="modalIframeGoForward();" value="'+button_modalIframeGoForward+'"/><div/>');
      if (ieVersion == 6) {
        sizeModification = 54;
        $('modalIframe').style.height = $('modalContentContainer').offsetHeight - $('modalIframeControls').offsetHeight - sizeModification + "px";
      }
      else {
        $('modalIframe').style.height = $('modalContentContainer').offsetHeight - $('modalIframeControls').offsetHeight + "px";
      }
    }
  }
}

function modalIframeGoBack(initialHistoryLength) {
  if (iframeHistory < history.length) {
    iframeHistory++;
    frames['modalIframe'].history.go(-1);
  }
}

function modalIframeGoForward(initialHistoryLength) {
    frames['modalIframe'].history.go(1);
}

function modalIframeRemoveFrame(initialURL) {
  window.open(initialURL, "sdPopup");
}

function modalMaximize(width, height) {
  if (width != $('modalWindow').style.width) {
    $('modalWindow').style.width = width;
    $('modalWindow').style.height = height+"px";
  }
  else {
    if (ieVersion == 6) {
      $('modalWindow').style.width = document.body.clientWidth-40+"px";
      $('modalWindow').style.height = document.body.clientHeight-40+"px";
    }
    else {
      $('modalWindow').style.width = document.viewport.getWidth()-60+"px";
      $('modalWindow').style.height = document.viewport.getHeight()-60+"px";
    }
  }
  if ($('modalIframe')) {
    if ($('modalIframeControls')) {
      if (ieVersion == 6) {
        sizeModification = 50;
        $('modalIframe').style.height = $('modalWindow').offsetHeight - $('modalIframeControls').offsetHeight - sizeModification + "px";
      }
      else {
        $('modalIframe').style.height = $('modalContentContainer').offsetHeight - $('modalIframeControls').offsetHeight + "px";
      }
    }
    else {
         $('modalIframe').style.height = $('modalWindow').offsetHeight - $('modalTitleBar').offsetHeight - 26 + "px";
    }
  }
}

function modalClose(closeMessage) {
  if (closeMessage) {
    // if calling closeMessage from outside createModalDialogBox, there will be no message
    // makes automatic closing possible
    var confirmClose = confirm(closeMessage);
    if (confirmClose) {
      Effect.Fade('modalBackground', { duration: 1.0, queue: 'end', afterFinish: function() {$('modalBackground').remove();} } );
    }
    else {
    }
  }
  else {
    Effect.Fade('modalBackground', { duration: 1.0, queue: 'end', afterFinish: function() {$('modalBackground').remove();} } );
  }
  
}

function submitForm(formName, submitAndMaximize, submitAndClose) {
  // formName -> id of form to submit
  // submitAndMaximize -> submit the form using id and maximize the window
  // submitAndClose -> submit the form using id and close modal window

  if ($('modalContentContainer')) {
    $(formName).request(
    {
      method: 'post',
      onSuccess: function(transport) {
        var response =  transport.responseText;
        $('modalContentContainer').innerHTML = response;
      },
      onFailure: function() {
        $('modalContentContainer').innerHTML = msg_failedAjax;
      },
      onComplete: function() {
        initializeLoadedAjax();
        if (submitAndMaximize) {
          modalMaximize();
        }
        if (submitAndClose) {
          modalClose();
        }
      }
    });
  }
  else {
    // not in a modal dialog box. submit form normally
    $(formName).request();
  }
}

function initializeLoadedAjax() {
  // this is for running code on the dom we just loaded through ajax
  // if a wizard panel is available on page load, show the first one, and the navigation
  if ($$('.wizard_panel')[0]) {
   ($$('.wizard_panel')[0]).style.display = "block";
   ($$('.wizard_navigation')[0]).style.display = "block";
   if ($$('.wizard_previous')[0]) {
     ($$('.wizard_previous')[0]).style.display = "none";
   }
  }
}

/*--- WIZARD ---*/

function wizard_validate(wizardContainer, currentPanel) {
  var wizard_panels = ($$('.'+wizardContainer+' .wizard_panel'));
  // modify this to false if needed.
  valid = true;
  
  if (wizard_panels[currentPanel]) {
    // passed in panel exists. do some validation here.
    // we can do custom validation based on the wizardContainer name
    // passed in.
    // if validation is not successful, return valid = false,
    // and mark invalid fields.
    $('previous_panel').value = currentPanel;
  }
  return valid;
}

function wizard_next(wizardContainer) {
  // pass in wizard container class. this allows for generic functions
  var wizard_panels = ($$('.'+wizardContainer+' .wizard_panel'));
  for (i = 0; i < wizard_panels.length; i++) {
    //find currently displayed panel
    if (wizard_panels[i].style.display == "block") {
      wizard_validate(wizardContainer, i);
      if (wizard_validate() == true) {
        // validation successful
        if (wizard_panels[i].getElementsBySelector('[class="select_a_panel"]')) {
          // branching inputs available on current panel. 
          // check to see which panel to jump to
          var selectedInputForBranching = wizard_panels[i].getElementsBySelector('[class="select_a_panel"]');
          for (j = 0; j < selectedInputForBranching.length; j++) {
            if (selectedInputForBranching[j].checked) {
              wizard_panels[i].style.display = "none";
              wizard_panels[selectedInputForBranching[j].value].style.display = "block";
              ($$('.'+wizardContainer)[0]).style.height = "90%";
              // displayed selected panel. stop looping.
              j = 999;
            }
            else {
              if (i < wizard_panels.length-1) {
                // validation was successful. hide this panel and show next
                wizard_panels[i].style.display = "none";
                i++;
                wizard_panels[i].style.display = "block";
                ($$('.'+wizardContainer)[0]).style.height = "90%";
              }
            }
          }
        }
        else {
          // just go to the next panel
          if (i < wizard_panels.length-1) {
            wizard_panels[i].style.display = "none";
            i++;
            wizard_panels[i].style.display = "block";
            ($$('.'+wizardContainer)[0]).style.height = "90%";
          }
        }
        if (i == wizard_panels.length-1) {
          ($$('.wizard_finish')[0]).style.display = "inline";
          ($$('.wizard_next')[0]).style.display = "none";
        }
        if (i == 0) {
          ($$('.wizard_previous')[0]).style.display = "none";
        } 
        else {
          ($$('.wizard_previous')[0]).style.display = "inline";
        }
      }
    }
  }
}

function wizard_previous(wizardContainer) {
  // pass in wizard container class. this allows for generic functions
  var wizard_panels = ($$('.'+wizardContainer+' .wizard_panel'));
  for (i = 0; i < wizard_panels.length; i++) {
    //find currently displayed panel
    if (wizard_panels[i].style.display == "block") {
      // don't validate current panel if trying to go to previous panel
      // user may be trying to view previous information to make the
      // current form valid, so we don't want them to get stuck.
       if (i > 0) {
        wizard_panels[i].style.display = "none";
        i--;
        wizard_panels[i].style.display = "block";
      }
      if (i < wizard_panels.length-1) {
        ($$('.wizard_next')[0]).style.display = "inline";
        ($$('.wizard_finish')[0]).style.display = "none";
      }
      if (i == 0) {
        ($$('.wizard_previous')[0]).style.display = "none";
      } 
      else {
        ($$('.wizard_previous')[0]).style.display = "inline";
      }
    }
  }
}

/*--- Slideshow ---*/
function nextSlideShow(id) {
  var currentSlide;
  var nextSlide;
  titles =  $$('.'+id+' .slideshow_titles .slideshow_title');
  slides =  $$('.'+id+' .slideshow_images img');
  description =  $$('.'+id+' .slideshow_description .slideshow_text');
  for (i=0; i < slides.length; i++) {
    if (slides[i].style.display != "none") {
      currentSlide = i;
      nextSlide = i;
      nextSlide++;
      if (nextSlide >= slides.length) {
        nextSlide = 0;
      }
    }
  }
  titles[currentSlide].style.display = "none";
  slides[currentSlide].style.display = "none";
  description[currentSlide].style.display = "none";
  new Effect.Appear(titles[nextSlide], { duration:0.5 });
  new Effect.Appear(slides[nextSlide], { 
    duration:0.5, 
    afterFinish: function() {
      slideshow_images_container = slides[nextSlide].getOffsetParent();
      slideshow_images_container.style.height = slides[nextSlide].offsetHeight+"px"; 
      new Effect.Appear(description[nextSlide], { 
        duration:0.5, 
        afterFinish: function() {
          slideshow_description_container = description[nextSlide].getOffsetParent();
          slideshow_description_container.style.top =  slideshow_images_container.offsetHeight+90+"px";
          ($$('.'+id+' .slideshow_footers')[0]).style.top = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+95+"px";
          ($$('.'+id)[0]).style.height = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+($$('.'+id+' .slideshow_footers')[0]).offsetHeight+95+"px";
        }
      });
    } 
  });
}

function previousSlideShow(id) {
  var currentSlide;
  var nextSlide;
  titles =  $$('.'+id+' .slideshow_titles .slideshow_title');
  slides =  $$('.'+id+' .slideshow_images img');
  description =  $$('.'+id+' .slideshow_description .slideshow_text');
  for (i=0; i < slides.length; i++) {
    if (slides[i].style.display != "none") {
      currentSlide = i;
      nextSlide = i;
      nextSlide--;
      if (nextSlide <= -1 ) {
        nextSlide = slides.length-1;
      }
    }
  }
  titles[currentSlide].style.display = "none";
  slides[currentSlide].style.display = "none";
  description[currentSlide].style.display = "none";
  new Effect.Appear(titles[nextSlide], { duration:0.5 });
  new Effect.Appear(slides[nextSlide], { 
    duration:0.5, 
    afterFinish: function() {
      slideshow_images_container = slides[nextSlide].getOffsetParent();
      slideshow_images_container.style.height = slides[nextSlide].offsetHeight+"px"; 
      new Effect.Appear(description[nextSlide], { 
        duration:0.5, 
        afterFinish: function() {
          slideshow_description_container = description[nextSlide].getOffsetParent();
          slideshow_description_container.style.top =  slideshow_images_container.offsetHeight+90+"px";
          ($$('.'+id+' .slideshow_footers')[0]).style.top = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+95+"px";
          ($$('.'+id)[0]).style.height = slideshow_images_container.offsetHeight+slideshow_description_container.offsetHeight+($$('.'+id+' .slideshow_footers')[0]).offsetHeight+95+"px";
        }
      });
    } 
  });  
}

function playSlideShow(id) {
  play = self.setInterval("nextSlideShow(\'"+id+"\')", 2000);
}

function stopSlideShow(id) {
  window.clearInterval(play);
}

/*--- WEB APP SPECIFIC JS ----------------------------------------------------*/

/* web app specific initialization code goes here */
function initializeWebApp() {
   required();
   $$('.content_container').each( function(data) {
       if (data.firstDescendant().empty()) {
         data.style.display = "none";
       }
       if (data.firstDescendant().offsetHeight < 32) {
         data.style.display = "none";
       }
   });
   
   if ($('keep_all_button')) {
     $('keep_all_button').style.display = "inline";
   }
   
   if ($('perm_keep_all_button')) {
     $('perm_keep_all_button').style.display = "inline";
   }
}

// used by environment and labels
var LocalizedValues = new Array();

// month name for display purposes
// used to convert localized month back to numeric
var DisplayMonthName = new Array();
var CheckDisplayMonth = new String();

// used by dynamic table sorting
var currentCol = 0;

function show_permalink_from_url()
{
	var reURL;
	var strBegin;
	var strEnd;
	var strWork;
	var intLocation;
	var strURL;

	reURL = new RegExp("http(.|\n)+?/cgisirsi/");

	strBegin = reURL.exec(window.location.href);

	strWork = new String(strBegin);

	strWork = strWork.split(",");

	strBegin = strWork[0];

	strEnd = window.location.href;

	intLocation = strEnd.indexOf("/28/");

	strEnd = strEnd.substring(intLocation);

	strURL = strBegin + "x/0/0" + strEnd;

	show_permalink(strURL);
}

function show_permalink(inURL)
{
	var heading = getLocalizedValue("PERMALINK");
	var message = getLocalizedValue("TO_LINK");
	var height = 150;
	var width = 400;

	var left = screen.width  - width - 50;
	var top = 50;
	var myURL = inURL;
	myURL = myURL.replace(/'/g,"&#39;");

	var strParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + width;
	strParam = strParam + ",height=" + height;
	strParam = strParam + ",left=" + left;
	strParam = strParam + ",top=" + top;

	aWindow = window.open('','',strParam);

	aWindow.document.open("text/html");

	aWindow.document.write("<html><head><title>");
	aWindow.document.write(heading);
	aWindow.document.write("</title></head>");
	aWindow.document.write("<body>");

	aWindow.document.write(message);
	aWindow.document.write("<br><br>");

	aWindow.document.write("<strong>Permalink</strong> <input type='text' size = '45' value='");
	aWindow.document.write(myURL);
	aWindow.document.write("' readonly='readonly' onclick='this.select()'>");

	aWindow.document.write("</body></html>");

	aWindow.document.close();
}

function CreateBookmarkLinkfromURL(inTitle) 
{
	var reURL;
	var strBegin;
	var strEnd;
	var strWork;
	var intLocation;
	var strURL;

	reURL = new RegExp("http(.|\n)+?/cgisirsi/");

	strBegin = reURL.exec(window.location.href);

	strWork = new String(strBegin);

	strWork = strWork.split(",");

	strBegin = strWork[0];

	strEnd = window.location.href;

	intLocation = strEnd.indexOf("/28/");

	strEnd = strEnd.substring(intLocation);

	strURL = strBegin + "x/0/0" + strEnd;

	CreateBookmarkLink(inTitle,strURL);
}

function CreateBookmarkLink(inTitle,inURL) 
{
	var workTitle = new String(inTitle);

	if (workTitle.length == 0)
	  workTitle = document.title;

	if (window.sidebar) 
	  { // Mozilla Firefox Bookmark		
	  window.sidebar.addPanel(workTitle, inURL,"");	
	  } 
	else if( window.external ) 
	  { // IE Favorite	
	  window.external.AddFavorite( inURL, workTitle); 
	  }	
	else if(window.opera && window.print) 
	  { // Opera Hotlist
	  var mbm = document.createElement('a');
          mbm.setAttribute('rel','sidebar');
          mbm.setAttribute('href',inURL);
	  mbm.setAttribute('title',workTitle);
	  mbm.click(); 
	  }
}

function setLocalizedValue(inName,inValue)
{
	LocalizedValues[inName] = inValue;
}

function getLocalizedValue(inName)
{
	return LocalizedValues[inName];
}

function open_win(url) {
	new_win = window.open(url,"new_win",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	if (new_win)
	{
	  new_win.focus();
	}
}

function open_bare_win(url) {
	new_b_win = window.open(url,"new_b_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=620,height=450');
	if (new_b_win)
	{
	  new_b_win.focus();
	}
}

function open_hyperion_image_win(url) {
	hyperion_image_win = window.open(url,"hyperion_image_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=450,screenX=410,screenY=210');
}

function open_hyperion_info_win(url) {
	hyperion_info_win = window.open(url,"hyperion_info_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=400,height=450,screenX=0,screenY=210');
}

function open_win_timeout(url,timeout) {
	new_win = window.open(url,"new_win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	setTimeout("new_win.close()",timeout);
}

function open_help_win(url) {
       new_win = window.open(url,"help_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=640,height=480');
	if (new_win)
	{
	  new_win.focus();
	}
}

function open_bounce_win(url) {
  new_win = window.open(url,"bounce_win",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=620,height=450');
}

/* Obsolete Function for icon-type search form action */
function orig_form_action(searchEngineUrlPt1,searchEngineUrlPt2)
{
	if (!document.searchform.search_type[0].checked)
	  {
	  return true;
	  }
	else
	  {
          document.url_form.url.value = searchEngineUrlpt1 + document.searchform.searchdata1.value + searchEngineUrlPt2;
          open_win(document.url_form.url.value);
	  return false;
	  }
}

function combine_fields()
{
    document.getElementById("searchdata3").value="{LEXILE}>" + document.getElementById("lexilemin").value + "<" + document.getElementById("lexilemax").value;
    //alert (document.getElementById("searchdata3").value);
}

/* Function for icon-type search form action */
function search_form_action(searchEngineUrlPt1,searchEngineUrlPt2)
{
	var search_engine_checked = 0;
	var temp_str;

	for (var i = 0; i < document.searchform.search_type.length; i++)
	  {
	  if (document.searchform.search_type[i].value == "searchengine")
	    if (document.searchform.search_type[i].checked)
	      search_engine_checked = 1;
	  }

	if (!search_engine_checked)
	  {
	  return true;
	  }
	else
	  {
          temp_str = document.searchform.searchdata1.value;
	  temp_str = temp_str.replace(/\s+/g,"+");
          document.url_form.url.value = searchEngineUrlPt1 + temp_str + searchEngineUrlPt2; 
          open_win(document.url_form.url.value);
	  return false;
	  }
}

function put_admin_help_button(langDir, alttextHelp) {
  document.writeln('<a href="#" onclick="javascript:open_admin_help_win(\''+langDir+'\',\''+alttextHelp+'\')" alt="'+alttextHelp+'" title="'+alttextHelp+'">'+alttextHelp+'<\/a>');
}

function open_admin_help_win(langDir, alttextHelp) {
  if ($("currentTab")) {
    var selected_tab = $("currentTab").value;
    if (selected_tab) {
      selected_tab = selected_tab.replace(/ /g,"_");
      selected_tab = selected_tab.toLowerCase();
      open_help_win("/iBistro_helps/Admin/" + langDir + "/index.htm?context=elibrary_admin&topic=" + selected_tab);
    }
  }
}


function getNonJavaHelpFileUrl(langDir, file)
{
  if (file == "ibistro_overview") {
    return '/iBistro_helps/User/' + langDir + '/index.htm';
  }
  else {
    return '/iBistro_helps/User/' + langDir + '/index.htm?context=elibrary&topic=' + file;
  }
}

function put_help_button(langDir, alttextHelp, file)
{
  document.writeln('<a href="#" onclick="javascript:open_help_win(\''+getNonJavaHelpFileUrl(langDir,file)+'\')" alt="'+alttextHelp+'" title="'+alttextHelp+'">'+alttextHelp+'<\/a>');
}

/*
function put_keepremove_button(ckey,value,imgOther,alttextKeep,webcatUrl,session,alttextRemove)
{
  document.writeln('<img name="ickey-' + ckey + '"');
  document.writeln('src="'+imgOther+'/clear.gif"');
  document.writeln('alt="' + value + '" border="0">');

  document.writeln('<input type="button"');
  if (value == alttextKeep)
    {
    document.writeln('class="button keep_button"');
    }
  else
    {
    document.writeln('class="button remove_button"');
    }
  document.writeln('name="ckey-' + ckey + '"');
  document.writeln('id="ckey-' + ckey + '"');
  document.writeln('value="' + value + '" alt="' + value + '"');

  document.writeln('onClick="updatekeptlist(\''+alttextKeep+'\',\''+webcatUrl+'\',\''+session+'\',\''+imgOther+'\',\''+alttextRemove+'\',this,\''+ckey+'\');">');
}
*/

/* keep button as check box */

function put_keepremove_button(ckey,value,imgOther,alttextKeep,webcatUrl,session,alttextRemove)
{
  document.writeln('<img name="ickey-' + ckey + '"');
  document.writeln('src="'+imgOther+'/clear.gif"');
  document.writeln('alt="' + value + '" border="0">');
  
  document.writeln('<input type="checkbox" style="margin:0px 4px 0px 0px; padding:0px; float:left; display:inline; position:relative; width:12px;"');
  if (value == alttextKeep)
    {
    document.writeln('');
    }
  else
    {
    document.writeln('checked');
    }
  document.writeln('name="ckey-' + ckey + '"');
  document.writeln('id="ckey-' + ckey + '"');
  document.writeln('value="' + value + '" alt="' + value + '"');

  document.writeln('onClick="updatekeptlist(\''+alttextKeep+'\',\''+webcatUrl+'\',\''+session+'\',\''+imgOther+'\',\''+alttextRemove+'\',this,\''+ckey+'\');">');
  document.writeln('<label id="keep_label_ickey-' + ckey + '" style="margin:0px; padding:0px;  float:left; display:inline; position:relative; " for="ckey-' + ckey + '"">' + value + '</label>');
}


function updatekeptlist(alttextKeep,webcatUrl,session,imgOther,alttextRemove,myButton,ckey)
{
  key = "i" + myButton.name;
  if (myButton.value == alttextKeep)
    {
    myImage = new Image();
    myImage.src = webcatUrl + '/' + session + '/125/ADD?kept-' + ckey + '=on';
    document.images[key].src=myImage.src;
    myImage = new Image();
    myImage.src = imgOther + '/clear.gif';
    myImage.alt = myButton.value;
    document.images[key].src=myImage.src;
    document.images[key].alt=alttextRemove;
    myButton.value = alttextRemove;
    $('keep_label_ickey-'+ckey).innerHTML = alttextRemove;
    myButton.className = 'keep_button';
    }
  else
    {
    myImage = new Image();
    myImage.src = webcatUrl + '/' + session + '/125/REMOVE?kept-' + ckey + '=on';
    document.images[key].src=myImage.src;
    myImage = new Image();
    myImage.src = imgOther + '/clear.gif';
    myImage.alt = myButton.value;
    document.images[key].src=myImage.src;
    document.images[key].alt=alttextKeep;
    myButton.value = alttextKeep;
    $('keep_label_ickey-'+ckey).innerHTML = alttextKeep;
    myButton.className = 'remove_button';
  }
}

function put_keepremove_perm_button(list_id,ckey,value,imgOther,alttextKeep,webcatUrl,session,alttextRemove)
{
  document.writeln('<img name="ppckey-' + ckey + '"');
  document.writeln('src="'+imgOther+'/clear.gif"');
  document.writeln('alt="' + value + '" border="0">');

  document.writeln('<input type="checkbox" style="margin:0px 4px 0px 0px; padding:0px; float:left; display:inline; position:relative; width:12px;"');
  if (value == alttextKeep)
    {
    document.writeln('');
    }
  else
    {
    document.writeln('checked');
    }
  document.writeln('name="pckey-' + ckey + '"');
  document.writeln('id="pckey-' + ckey + '"');
  document.writeln('value="' + value + '" alt="' + value + '"');

  document.writeln('onClick="updatepermkeptlist(\''+alttextKeep+'\',\''+webcatUrl+'\',\''+session+'\',\''+imgOther+'\',\''+alttextRemove+'\',this,\''+ckey+'\',\''+list_id+'\');">');
  document.writeln('<label id="keep_label_ppckey-' + ckey + '" style="margin:0px; padding:0px;  float:left; display:inline; position:relative; " for="pckey-' + ckey + '">' + value + '</label>');
}

function updatepermkeptlist(alttextKeep,webcatUrl,session,imgOther,alttextRemove,myButton,ckey,listid)
{
  var mylist = new String(listid);

  if (mylist.length == 0)
    {
    $('pckey-'+ckey).checked = false; // reset checkbox
    alert(getLocalizedValue("CREATE_A_LIST"));
    }
  else
    {
    key = "p" + myButton.name;
    if (myButton.value == alttextKeep)
      {
      myImage = new Image();
      myImage.src = webcatUrl + '/' + session + '/154?list_id=' + listid + '&ckeys=' + ckey;
      document.images[key].src=myImage.src;
      myImage = new Image();
      myImage.src = imgOther + '/clear.gif';
      myImage.alt = myButton.value;
      document.images[key].src=myImage.src;
      document.images[key].alt=alttextRemove;
      myButton.value = alttextRemove;
      $('keep_label_ppckey-'+ckey).innerHTML = alttextRemove;
      myButton.className = 'keep_button';
      }
    else
      {
      myImage = new Image();
      myImage.src = webcatUrl + '/' + session + '/155?list_id=' + listid + '&ckeys=' + ckey;
      document.images[key].src=myImage.src;
      myImage = new Image();
      myImage.src = imgOther + '/clear.gif';
      myImage.alt = myButton.value;
      document.images[key].src=myImage.src;
      document.images[key].alt=alttextKeep;
      myButton.value = alttextKeep;
      $('keep_label_ppckey-'+ckey).innerHTML = alttextKeep;
      myButton.className = 'remove_button';
      }
    }
}

function put_keepremove_all_button(imgOther,webcatUrl,session,alttextRemove)
{
    document.writeln('<img name="ckey-ALL"');
    document.writeln('src="'+imgOther+'/clear.gif"');
    document.writeln('alt="' + getLocalizedValue("alttext_keep_all") + '" border="0">');
  
    document.writeln('<input type="button" id="keep_all_button" class="button" style="display:none;"');
    document.writeln('value="' + getLocalizedValue("alttext_keep_all") + '"');
  
    document.writeln('onClick="updatekeptlist_all(\''+webcatUrl+'\',\''+session+'\',\''+imgOther+'\',\''+alttextRemove+'\',this,keep_ckeys_array);">');
}

function put_keepremove_all_perm_button(list_id,imgOther,webcatUrl,session,alttextRemove)
{
  document.writeln('<img name="ckey-ALL"');
  document.writeln('src="'+imgOther+'/clear.gif"');
  document.writeln('alt="' + getLocalizedValue("alttext_keep_all_perm") + '" border="0">');

  document.writeln('<input type="button" class="button" id="perm_keep_all_button"');
  document.writeln('value="' + getLocalizedValue("alttext_keep_all_perm") + '"');

  document.writeln('onClick="updatekeptlist_all_perm(\''+webcatUrl+'\',\''+session+'\',\''+imgOther+'\',\''+alttextRemove+'\',this,keep_ckeys_array,\''+list_id+'\');">');
}

function updatekeptlist_all(webcatUrl,session,imgOther,alttextRemove,myButton,ckeys_array)
{
  var ckey_str = new String("");

  for (i=0; i<ckeys_array.length; i++)
  {
    ckey_str = ckey_str + "kept-" + ckeys_array[i] + "=on&";
  }
  key = "ckey-ALL";
  myImage = new Image();
  myImage.src = webcatUrl + '/' + session + '/125/ADD?' + ckey_str;
  document.images[key].src=myImage.src;

  // Change all individual Keep buttons to "marked"
  for (i=0; i<ckeys_array.length; i++) {
    ckey = ckeys_array[i];
    element_id = "ckey-" + ckey;
    if ( document.images[key] != null ) {
      document.images["i" + element_id].alt = alttextRemove;
    }
    document.getElementById(element_id).value = alttextRemove;
    document.getElementById(element_id).className = 'remove_button';
    document.getElementById(element_id).checked = true;
    $('keep_label_ickey-'+ckey).innerHTML = alttextRemove;
  }

  myImage = new Image();
  myImage.src = imgOther + '/clear.gif';
  myImage.alt = myButton.value;
  if ( document.images[key] != null ) {
    document.images[key].src=myImage.src;
  }
}

function updatekeptlist_all_perm(webcatUrl,session,imgOther,alttextRemove,myButton,ckeys_array,list_id)
{
  var ckey_str = new String("");

  if (list_id.length == 0)
    {
    alert(getLocalizedValue("CREATE_A_LIST"));
    }
  else
    {
    for (i=0; i<ckeys_array.length; i++)
      {
      if (ckey_str.length == 0)
        ckey_str = ckeys_array[i];
      else
        ckey_str = ckey_str + ":" + ckeys_array[i];
      }
    key = "ckey-ALL";
    myImage = new Image();
    myImage.src = webcatUrl + '/' + session + '/154?list_id=' + list_id + '&ckeys=' + ckey_str;
    document.images[key].src=myImage.src;

    // Change all individual Keep buttons to "marked"
    for (i=0; i<ckeys_array.length; i++)
      {
      ckey = ckeys_array[i];
      element_id = "pckey-" + ckey;
      if ( document.images["p" + element_id] != null ) {
        document.images["p" + element_id].alt = alttextRemove;
      }
      document.getElementById(element_id).value = alttextRemove;
      document.getElementById(element_id).className = 'remove_button';
      document.getElementById(element_id).checked = true;
      $('keep_label_ppckey-'+ckey).innerHTML = alttextRemove;
      }
  
    myImage = new Image();
    myImage.src = imgOther + '/clear.gif';
    if ( document.images[key] != null ) {
      document.images[key].src=myImage.src;
    }
    }
}

function do_history(form)
  {
  // Based on the value of the srch_history <select> list, set the search input fields.
  var opt_idx;
  var i = 0;
  
  opt_idx = form.srch_history.selectedIndex;
  
  // The history "value" is formatted:  "term^label^library"
  valueArray = form.srch_history.options[opt_idx].value.split("^");
  
  // Set the search term
  form.searchdata1.value = valueArray[0];
  
  // Set the search type - if it is present
  if (form.srchfield1 != null)
    {
    for (i<0; i<form.srchfield1.length; i++)
      {
      if (form.srchfield1.options[i].text == valueArray[1])
        {
        form.srchfield1.options[i].selected = true;
        break;
        }
      }
    }
  
  // Set the library
  form.library.value = valueArray[2];
  }

function sendOpenURL(inISBN,inTITLE,inISSN,inGENRE,openUrl)
{
	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }

        nFORM=aWindow.document.createElement('form');
	nFORM.action=openUrl;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="OpenURL";

	if (inISBN.length != 0)
	  {
	  nISBN=aWindow.document.createElement('input');
	  nISBN.name='isbn';
	  nISBN.value=inISBN;
	  nISBN.type='hidden';

	  nFORM.appendChild(nISBN);
	  }

	if (inTITLE.length != 0)
	  {
	  nTITLE=aWindow.document.createElement('input');
	  nTITLE.name='title';
	  nTITLE.value=inTITLE;
	  nTITLE.type='hidden';

	  nFORM.appendChild(nTITLE);
	  } 

	if (inISSN.length != 0)
	  {
	  nISSN=aWindow.document.createElement('input');
	  nISSN.name='issn';
	  nISSN.value=inISSN;
	  nISSN.type='hidden';

	  nFORM.appendChild(nISSN);
	  }

	if (inGENRE.length != 0)
	  {
	  nGENRE=aWindow.document.createElement('input');
	  nGENRE.name='genre';
	  nGENRE.value=inGENRE;
	  nGENRE.type='hidden';

	  nFORM.appendChild(nGENRE);
	  }

	aWindow.document.body.appendChild(nFORM);

	nFORM.submit();

	aWindow.document.body.removeChild(nFORM);

}

function sendEnvisionWare(inUser,inPassword,accessType,accountPin,envisionwareUrl)
{
	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }

	if (accessType == 1)
	  strPassword = accountPin;
	else
          strPassword = inPassword;

        nFORM=aWindow.document.createElement('form');
	nFORM.action=envisionwareUrl;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="EnvisionWare";
	
	nuid=aWindow.document.createElement('input');
	nuid.id='user_id';
	nuid.name='user_id';
	nuid.value=inUser;
	nuid.type='hidden';

	nFORM.appendChild(nuid);

	npassword=aWindow.document.createElement('input');
	npassword.id='password';
	npassword.name='password';
	npassword.value=strPassword;
	npassword.type='hidden';

	nFORM.appendChild(npassword);

	aWindow.document.body.appendChild(nFORM);

	nFORM.submit();

	aWindow.document.body.removeChild(nFORM);
}

function sendAxis(inUser,inLibrary,inBill,inTotal,inAmount,cfgCurrency,axisReturnUrl,axisBackUrl,axisUrl,axisFundCode,axisFundName,axisReferenceNumber,axisReferenceNumberTwo)
{

	currencyStr = cfgCurrency;

	if (currencyStr == "$")
	  {
	  currencyStr = "\\" + currencyStr;  
	  }

	re = new RegExp(currencyStr,"g");

	inTotal = inTotal.replace(re,"");

	inAmount = inAmount.replace(re,"");

	strTotal = inTotal;
	strAmount = inAmount;

	strTotal = strTotal.replace(".","");
	strAmount = strAmount.replace(".","");

	strRef = inUser + '|' + inLibrary + '|';
	strRef = strRef + inBill + '|' + strTotal + '|';
	strRef = strRef + strAmount;

	// convert the strings to numbers and 
        // test for minimum before opening window
	
	if (inAmount.indexOf(",") == -1)
	  {
	  floatAmount = parseFloat(inAmount);
	  }
	else
	  {
	    floatAmount = 0.0;
	    workstr = inAmount;
	    while (workstr.indexOf(",") != -1)
	      {
		partialstr = workstr.substr(0,workstr.indexOf(","));
		floatAmount = floatAmount + parseFloat(partialstr);
		workstr = workstr.substr(workstr.indexOf(",") + 1);
	      }
	    floatAmount = floatAmount + parseFloat(workstr);
	  }

	floatAmount = Math.round(floatAmount*100)/100;

	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }

        nFORM=aWindow.document.createElement('form');
	nFORM.action=axisUrl;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="AXIS";

	nRequid=aWindow.document.createElement('input');
	nRequid.name='requid';
	nRequid.value=strRef;
	nRequid.type='hidden';

	nFORM.appendChild(nRequid);
	
	nAmount=aWindow.document.createElement('input');
	nAmount.name='amt';
	nAmount.value=floatAmount;
	nAmount.type='hidden';

	if (nAmount.value.indexOf(".") == -1)
	  {
	  nAmount.value = nAmount.value + ".";
	  }

	while((nAmount.value.length - nAmount.value.indexOf(".")) < 3)
	  {
          nAmount.value = nAmount.value + "0";
	  }

	nFORM.appendChild(nAmount);
	
	nReturnURL=aWindow.document.createElement('input');
	nReturnURL.name='rurl';
	nReturnURL.value=axisReturnUrl;
	nReturnURL.type='hidden';

	nFORM.appendChild(nReturnURL);
	
	nBackURL=aWindow.document.createElement('input');
	nBackURL.name='back.url';
	nBackURL.value=axisBackUrl;
	nBackURL.type='hidden';

	nFORM.appendChild(nBackURL);

	nSource=aWindow.document.createElement('input');
	nSource.name='source';
	nSource.value='I';
	nSource.type='hidden';

	nFORM.appendChild(nSource);
	
	nFundCode=aWindow.document.createElement('input');
	nFundCode.name='fund.code';
	nFundCode.value=axisFundCode;
	nFundCode.type='hidden';

	nFORM.appendChild(nFundCode);
	
	nFundName=aWindow.document.createElement('input');
	nFundName.name='fund.name';
	nFundName.value=axisFundName;
	nFundName.type='hidden';

	nFORM.appendChild(nFundName);
	
	nRefNumber=aWindow.document.createElement('input');
	nRefNumber.name='ref';
	nRefNumber.value=axisReferenceNumber;
	nRefNumber.type='hidden';

	nFORM.appendChild(nRefNumber);
	
	nRefNumberTwo=aWindow.document.createElement('input');
	nRefNumberTwo.name='ref2';
	nRefNumberTwo.value=axisReferenceNumberTwo;
	nRefNumberTwo.type='hidden';

	nFORM.appendChild(nRefNumberTwo);
	
	aWindow.document.body.appendChild(nFORM);

	nFORM.submit();

	aWindow.document.body.removeChild(nFORM);
}

function sendPayPal(inUser,inLibrary,inBill,inTotal,inAmount,inBillUser,cfgCurrency,paypalMinimum,paypalMinimumMessage,paypalUrl,paypalBusiness,paypalNotifyUrl,paypalCurrency)
{

	currencyStr = cfgCurrency;

	if (currencyStr == "$")
	  {
	  currencyStr = "\\" + currencyStr;  
	  }

	re = new RegExp(currencyStr,"g");

	inTotal = inTotal.replace(re,"");

	inAmount = inAmount.replace(re,"");

	// convert the strings to numbers and 
        // test for minimum before opening window
	
	if (inAmount.indexOf(",") == -1)
	  {
	  floatAmount = parseFloat(inAmount);
	  }
	else
	  {
	    floatAmount = 0.0;
	    workstr = inAmount;
	    while (workstr.indexOf(",") != -1)
	      {
		partialstr = workstr.substr(0,workstr.indexOf(","));
		floatAmount = floatAmount + parseFloat(partialstr);
		workstr = workstr.substr(workstr.indexOf(",") + 1);
	      }
	    floatAmount = floatAmount + parseFloat(workstr);
	  }

	floatAmount = Math.round(floatAmount*100)/100;

	floatMinimum = parseFloat(paypalMinimum);

	if (floatAmount < floatMinimum)
	  {
	    alert (paypalMinimumMessage);
	    return;
	  }	  
	
	aWindow = window.open('','','toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=750,height=250');
	
	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }


        nFORM=aWindow.document.createElement('form');
	nFORM.action=paypalUrl;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="PayPal";

	nCustom=aWindow.document.createElement('input');
	nCustom.name='custom';
	nCustom.value='user=' + inUser + '&';
	nCustom.value=nCustom.value + 'library=' + inLibrary + '&';
	nCustom.value=nCustom.value + 'bill_number=' + inBill + '&';
	nCustom.value=nCustom.value + 'total_owed=' + inTotal + '&';
	nCustom.value=nCustom.value + 'amount_paid=' + inAmount + '&';
	nCustom.value=nCustom.value + 'bill_user_id=' + inBillUser;
	nCustom.type='hidden';

	nFORM.appendChild(nCustom);

	nAmount=aWindow.document.createElement('input');
	nAmount.name='amount';
	nAmount.value=floatAmount;
	nAmount.type='hidden';

	nFORM.appendChild(nAmount);
	
	nCmd=aWindow.document.createElement('input');
	nCmd.name='cmd';
	nCmd.value='_xclick';
	nCmd.type='hidden';

	nFORM.appendChild(nCmd);
	
	nBusiness=aWindow.document.createElement('input');
	nBusiness.name='business';
	nBusiness.value=paypalBusiness;
	nBusiness.type='hidden';

	nFORM.appendChild(nBusiness);
	
	nItemName=aWindow.document.createElement('input');
	nItemName.name='item_name';
	nItemName.value='bill payment';
	nItemName.type='hidden';

	nFORM.appendChild(nItemName);
	
	nNotifyURL=aWindow.document.createElement('input');
	nNotifyURL.name='notify_url';
	nNotifyURL.value=paypalNotifyUrl;
	nNotifyURL.type='hidden';

	nFORM.appendChild(nNotifyURL);
	
	nCurrencyCode=aWindow.document.createElement('input');
	nCurrencyCode.name='currency_code';
	nCurrencyCode.value=paypalCurrency;
	nCurrencyCode.type='hidden';

	nFORM.appendChild(nCurrencyCode);

	aWindow.document.body.appendChild(nFORM);

	nFORM.submit();

	aWindow.document.body.removeChild(nFORM);
}

function clearCreditCardFields()
{
	ouracct_number=document.getElementById("acct_number");
	ouracct_name=document.getElementById("acct_name");
	ourexp_date=document.getElementById("exp_date");
	ouracct_number.value="";
	ouracct_name.value="";
	ourexp_date.value="";
}

function submitVeriSign(inUser,inData,webcatUrl,session)
{
	nFORM=document.createElement('form');
	document.body.appendChild(nFORM);
	nFORM.action=webcatUrl + '/' + session + '/144';
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="Payment";
	
	nUser=document.createElement('input');
	nUser.name='user_id';
	nUser.value=inUser;
	nUser.type='hidden';

	nFORM.appendChild(nUser);

	nData=document.createElement('input');
	nData.name='data';
	nData.value=inData;
	nData.type='hidden';

	nFORM.appendChild(nData);

	nFORM.submit();
}

function OpenGateway(inURL,inGateway,needToReplace,userID,password)
{
	if (need_to_replace)
	  {
	  inURL = inURL.replace(":///","://"+location.host+"/");
	  }

	aWindow = window.open('','','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=600,height=600');

	inUserId = userID;
	inPassword = password;

	if (aWindow.document.body == null)
	  {
	  aBody = aWindow.document.createElement('body');
	  aWindow.document.appendChild(aBody);
	  }

        nFORM=aWindow.document.createElement('form');
	nFORM.action=inURL;
	nFORM.target="_self";
	nFORM.method="post";
	nFORM.name="Gateway";

	if (inGateway.length != 0)
	  {
	  nGateway=aWindow.document.createElement('input');
	  nGateway.name='new_gateway_db';
	  nGateway.value=inGateway;
	  nGateway.type='hidden';

	  nFORM.appendChild(nGateway);
	  }

	if (inUserId.length != 0)
	  {
	  nUser=aWindow.document.createElement('input');
	  nUser.name='user_id';
	  nUser.value=inUserId;
	  nUser.type='hidden';

	  nFORM.appendChild(nUser);
	  } 

	if (inPassword.length != 0)
	  {
	  nPIN=aWindow.document.createElement('input');
	  nPIN.name='password';
	  nPIN.value=inPassword;
	  nPIN.type='hidden';

	  nFORM.appendChild(nPIN);
	  }

	aWindow.document.body.appendChild(nFORM);

	nFORM.submit();

	aWindow.document.body.removeChild(nFORM);

}

function OnlineUserRegistrationCheck(formobj,ourMissingFields,ourPinDoesNotMatch){
	// Enter name of mandatory fields
	var fieldRequired = Array("firstname", "lastname", "street", "city", "state", "zip", "pin", "validatepin");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("First Name", "Last Name", "Street", "City", "State", "Zip", "PIN", "Re-Type PIN");
	// dialog message
	var alertMsg = ourMissingFields + ":\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg)
	  {
	  if(formobj.pin.value != formobj.validatepin.value)
	    {
            alert (ourPinDoesNotMatch);
	    return false;
	    }
	  return true;
	  }
	else
	  {
	  alert(alertMsg);
	  return false;
	  }
}

function OnlineUserActivationCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("user_id", "pin", "new_user_id");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Temporary ID", "PIN", "New User ID");
	// dialog message
	var alertMsg = "Please complete the following required fields:\n";

	var l_Msg = alertMsg.length;

	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

function selectAll(inForm,inBox) 
{
	var checkboxes = document.getElementById(inForm).length;
	var stronclick;
	var bprocess;

	if (document.getElementById(inBox).checked == true)
          {
	  for (i=0; i < checkboxes; i++) 
	    {
            if (document.getElementById(inForm)[i].onclick == null)
              {
              bprocess = true;
              }
            else
              {
	      stronclick = new String(document.getElementById(inForm)[i].onclick);
	      if (stronclick.indexOf("selectAll") != -1)
	        {
	        bprocess = true;
	        }
	      else
	        {
	        bprocess = false;
	        }
              }
	    if (bprocess &&
		document.getElementById(inForm)[i].type == "checkbox")
	      document.getElementById(inForm)[i].checked = true;
	    }
	  }
        else 
	  {
	  for (i=0; i < checkboxes; i++)
	    {
            if (document.getElementById(inForm)[i].onclick == null)
              {
              bprocess = true;
              }
            else
              {
	      stronclick = new String(document.getElementById(inForm)[i].onclick);
	      if (stronclick.indexOf("selectAll") != -1)
	        {
	        bprocess = true;
	        }
	      else
	        {
	        bprocess = false;
	        }
              }
	    if (bprocess && 
		document.getElementById(inForm)[i].type == "checkbox")
	      document.getElementById(inForm)[i].checked = false;
	    }
	  }
}

function NewCalHold(pCtrl,pFormat,pShowTime,pTimeMode,inCheckbox,inLocalizedNever)
{
	var myCheckbox;

	myCheckbox = document.getElementById(inCheckbox);
	
	if (myCheckbox.checked != true)
	  NewCal(pCtrl,pFormat,pShowTime,pTimeMode,inLocalizedNever);
}

function cancelSelected()
{
	var myCheckbox;
	var mySubmit;
        var mySubmitTop;

	myCheckbox = document.getElementById("cancelselected");
	mySubmit = document.getElementById("submitholdsbutton");
	mySubmitTop = document.getElementById("submitholdsbuttontop");
	mySelect = document.getElementById("pickup_library");
	myExpiration = document.getElementById("hold_expiration_date");

	if (myCheckbox != null && (myCheckbox.checked == true || myCheckbox.type == "hidden"))
	  {
	  if (mySubmit != null)
	    mySubmit.value = getLocalizedValue("CANCEL_HOLDS_BUTTON");
	  if (mySubmitTop != null)
	    mySubmitTop.value = getLocalizedValue("CANCEL_HOLDS_BUTTON");
	  if (mySelect != null)
	    mySelect.disabled = true;
	  if (myExpiration != null)
	    myExpiration.disabled = true;
	  }
	else
	  {
	  if (mySubmit != null)
	    mySubmit.value = getLocalizedValue("EDIT_SELECTED_HOLD_TEXT");
	  if (mySubmitTop != null)
	    mySubmitTop.value = getLocalizedValue("EDIT_SELECTED_HOLD_TEXT");
	  if (mySelect != null)
	    mySelect.disabled = false;
	  if (myExpiration != null)
	    myExpiration.disabled = false;
	  }
}

function processholdform(inToday,inNever)
{
	var myCheckbox;
	var myForm;
	var checkboxes;
	var conirmeditall;
	var count;
	var editall;
	var strWork;
	var strID;
	var pieces;
	var sometoedit;
	var nFORM;
	var nField;
	var myHoldExpiration;
	var myPickupLibrary;

	myCheckbox = document.getElementById("cancelselected");

	if (myCheckbox.checked == true || myCheckbox.type == "hidden")
	  {
	  myForm = document.getElementById("holds_list");
	  if (myForm != null)
	    {
	    if (someChecked("holds_list"))
	      {
	      editall = allChecked("holds_list");
	      if (editall)
	        confirmeditall = confirm(getLocalizedValue("21501"));

	      if (!editall || (editall && confirmeditall))
	        {
	        myForm.submit();
		}
	      }
	    else
	      {
	      window.alert(getLocalizedValue("13094"));
	      }
	    }
	  }
	else
	  {
	  // The edit portion 
	  myForm = document.getElementById("holds_list");
	  if (myForm != null)
	    {
	    sometoedit = someChecked("holds_list");
	    if (sometoedit)
	      {
	      editall = allChecked("holds_list");
	      if (editall)
	        confirmeditall = confirm(getLocalizedValue("21501"));

	      if (!editall || (editall && confirmeditall))
	        {
	        if (document.getElementById("hold_expiration_date") != null)
	          myHoldExpiration = new String(document.getElementById("hold_expiration_date").value);
                else
	          myHoldExpiration = new String("");
	        if (myHoldExpiration == getLocalizedValue(inToday))
	          myHoldExpiration = 'TODAY';
	        if (myHoldExpiration == getLocalizedValue(inNever))
	          myHoldExpiration = 'NEVER';
	        if (document.getElementById("pickup_library") != null)
	          myPickupLibrary = new String(document.getElementById("pickup_library").value);
                else
                  myPickupLibrary = new String("");
                nFORM=document.createElement('form');
     	        nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/136";
	        nFORM.target="_self";
	        nFORM.method="post";
  	        nFORM.name="EditHolds";
	        checkboxes = myForm.length;
	        for (count = 0; count < checkboxes; count++)
	          {
	          if (myForm[count].id.indexOf("HLD") != -1)
	            {
		    if (myForm[count].checked == true)
		      {
		      strWork = myForm[count].id;
		      pieces = strWork.split("^");
		      strID = pieces[0] + "^" + pieces[5];
		      strID = strID + "^" + pieces[3] + "^" + pieces[2];
	
		      nField=document.createElement('input');
	              nField.name=strID;
	              nField.id=strID;
	              nField.value='on';
	              nField.type='hidden';

	              nFORM.appendChild(nField);
		      }
                    }
		  }
	        if (myHoldExpiration.length > 0)
	          {
	          nField=document.createElement('input');
	          nField.name='hold_expiration_date';
	          nField.id='hold_expiration_date';
	          nField.value=myHoldExpiration;
	          nField.type='hidden';
	          nFORM.appendChild(nField);
	          }
	        if (myPickupLibrary.length > 0)
	          {
	          nField=document.createElement('input');
	          nField.name='pickup_library';
	          nField.id='pickup_library';
	          nField.value=myPickupLibrary;
	          nField.type='hidden';
	          nFORM.appendChild(nField);
	          }
	        document.body.appendChild(nFORM);
	        nFORM.submit();
		}
	      }
	    else
	      {
	      window.alert(getLocalizedValue("SELECTHOLDSTOEDIT"));
	      }
	    }
	  }
}

function processSuspend(inStart,inEnd)
{
	var myCheckbox;
	var myStartDate;
	var myEndDate;
	var myButton;

	myCheckbox = document.getElementById("activate");
	myStartDate = document.getElementById("suspend_start_date");
	myEndDate = document.getElementById("suspend_end_date");
	myButton = document.getElementById("submitactivatebutton");

	if (myCheckbox != null && myCheckbox.checked)
	  {
	  if (myStartDate != null)
	    {
	    myStartDate.disabled = true; 
	    myStartDate.value = getLocalizedValue(inStart);
	    }
	  if (myEndDate != null)
	    {
	    myEndDate.disabled = true; 
	    myEndDate.value = getLocalizedValue(inEnd);
	    } 
	  if (myButton != null)
	    myButton.value = getLocalizedValue("ACTIVATESELECTEDTEXT");
	  }
	else
	  {
	  if (myStartDate != null)
	    {
	    myStartDate.disabled = false; 
	    myStartDate.value = getLocalizedValue(inStart);
	    }
	  if (myEndDate != null)
	    {
	    myEndDate.disabled = false; 
	    myEndDate.value = getLocalizedValue(inEnd);
	    } 
	  if (myButton != null)
	    myButton.value = getLocalizedValue("SUSPENDSELECTEDTEXT");
	  }
}

function processactivateform(inToday,inNever)
{
  
	var myCheckbox;
	var myForm;
	var checkboxes;
	var count;
	var confirmeditall;
	var editall;
	var strWork;
	var strID;
	var pieces;
	var sometoedit;
	var nFORM;
	var nField;
	var myStartDate;
	var myEndDate;

	// The edit portion 
	myForm = document.getElementById("holds_list");
	if (myForm != null)
	  {
	  sometoedit = someChecked("holds_list");
	  if (sometoedit)
	    {
	    editall = allChecked("holds_list");
	    if (editall)
	      confirmeditall = confirm(getLocalizedValue("21501"));

	     if (!editall || (editall && confirmeditall))
	     { 

	      myStartDate = document.getElementById("suspend_start_date").value;
	      if (myStartDate == getLocalizedValue(inToday))
	        myStartDate = 'TODAY';
	      if (myStartDate == getLocalizedValue(inNever))
	        myStartDate = 'NEVER';
	      myEndDate = document.getElementById("suspend_end_date").value;
	      if (myEndDate == getLocalizedValue(inToday))
	        myEndDate = 'TODAY';
	      if (myEndDate == getLocalizedValue(inNever))
	        myEndDate = 'NEVER';
              nFORM=document.createElement('form');
     	      nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/136";
	      nFORM.target="_self";
	      nFORM.method="post";
  	      nFORM.name="SuspendHolds";
	      checkboxes = myForm.length;
	      for (count = 0; count < checkboxes; count++)
	        {
	        if (myForm[count].id.indexOf("HLD") != -1)
	          {
	          if (myForm[count].checked == true)
		    {
		    strWork = myForm[count].id;
		    pieces = strWork.split("^");
		    strID = pieces[0] + "^" + pieces[5];
		    strID = strID + "^" + pieces[3] + "^" + pieces[2];

		    nField=document.createElement('input');
	            nField.name=strID;
	            nField.id=strID;
	            nField.value='on';
	            nField.type='hidden';

	            nFORM.appendChild(nField);
		    }
                  }
	        }
	      nField=document.createElement('input');
	      nField.name='suspend_start_date';
	      nField.id='suspend_end_date';
	      nField.value=myStartDate;
	      nField.type='hidden';
	      nFORM.appendChild(nField);
	      nField=document.createElement('input');
	      nField.name='suspend_end_date';
	      nField.id='suspend_end_date';
	      nField.value=myEndDate;
	      nField.type='hidden';
	      nFORM.appendChild(nField);
	      document.body.appendChild(nFORM);
	      nFORM.submit();
	      }
	    }
	  else
	    {
	    window.alert(getLocalizedValue("SELECTHOLDSTOACTIVATE"));
	    }
	  }
}

function sendCurrentTab(inTab)
{
	var myImage;
	var aImage;

	aImage = document.getElementById("settab");

	myImage = new Image();
	myImage.src = getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/148/" + inTab;
	aImage.src=myImage.src;
	myImage = new Image();
	myImage.src = getLocalizedValue("IMG_OTHER") + "/clear.gif";
	aImage.src=myImage.src;
}

function verifyAndSubmit(inForm)
{
	if (!someChecked(inForm))
	  ask_to_select(inForm);
	else
	  {
	  if (allChecked(inForm))
	    {
	    if (ask_for_confirmation(inForm))
	      {
	      submitForm(inForm);
	      }
	    }
	    else
	      {
	      submitForm(inForm);
	      }
	  }
}

function allChecked(inForm)
{
	var allselected = false;

	var myForm;

	myForm = document.getElementById(inForm);
	if (myForm != null)
	  {
	  allselected = true;
	  checkboxes = myForm.length;
	  for (count = 0; count < checkboxes; count++)
	    if (myForm[count].type == 'checkbox')
	      if (myForm[count].onclick == null)
	        if (myForm[count].checked == false)
		  allselected = false;
	  }

	return allselected;
}

function someChecked(inForm)
{
	var somechecked = false;
	var myForm;

	myForm = document.getElementById(inForm);
	if (myForm != null)
	  {
	  checkboxes = myForm.length;
	  for (count = 0; count < checkboxes; count++)
	    if (myForm[count].type == 'checkbox')
	      if (myForm[count].onclick == null)
	        if (myForm[count].checked == true)
		  somechecked = true;
	  }

	return somechecked;
}

function ask_to_select(inForm)
{
	var strMessage;

	strMessage = getLocalizedValue("21504");

	if (inForm == "renewitems")
	  strMessage = getLocalizedValue("13066");
	if (inForm == "rsvns_list")
	  strMessage = getLocalizedValue("13096");

	window.alert(strMessage);
}

function ask_for_confirmation(inForm)
{
	var strMessage;

	strMessage = getLocalizedValue("21503");

	if (inForm == "renewitems")
	  strMessage = getLocalizedValue("21502");
	if (inForm == "avail_list")
	  strMessage = getLocalizedValue("21500");

	return confirm(strMessage);
}

function submitForm(inForm)
{
	var myForm;

	myForm = document.getElementById(inForm);

	if (myForm != null)
	  myForm.submit();
}

function stripLeading(inString)
{
	while (inString.indexOf(" ") == 0 || inString.indexOf("\n") == 0 || inString.indexOf("\t") == 0)
	  {
	  inString = inString.substr(1);
	  }

	return inString;
}

function removeExtra(inString)
{
	 inString = inString.replace(/<(.|\n)+?>/g,"");
	 inString = inString.replace(/ /g,"");
	 inString = inString.replace(/\n/g,"");

	 return inString;
}

function pullAmount(inString)
{
	var reMoney;
	var result;
	var strWork;
	var portion;
	var strTemp;

	strTemp = "^\\" + getLocalizedValue("CURRENCY") + "\\d+(\\.\\d\\d)?$";

	reMoney = new RegExp(strTemp);
	result = reMoney.exec(inString);
	if (!reMoney.test(inString))
	  {
	  result = "$0.00,";
	  }
	strWork = new String(result);
	strTemp = getLocalizedValue("CURRENCY");
	strWork = strWork.replace(strTemp,"");
	portion = strWork.split(",");
	inString = portion[0];

	return inString;
}

function CompareAlpha(a, b)
{
	var strA = a[currentCol].toLowerCase();
	var strB = b[currentCol].toLowerCase();
	var pieces;
	var i;
	var reDontConsider;
	// remove html wrappers to sort the title
	strA = strA.replace(/<(.|\n)+?>/g,"");
	strB = strB.replace(/<(.|\n)+?>/g,"");
	// remove items we don't want the sort to consider
	var strDontConsider = getLocalizedValue("DONT_SORT_ON_THESE"); 
	pieces = strDontConsider.split(",");
	for (i = 0; i < pieces.length; i++)
	  {
	  reDontConsider = new RegExp(pieces[i],"g");
	  strA = strA.replace(reDontConsider,"");
	  strB = strB.replace(reDontConsider,""); 
	  }
	strA = stripLeading(strA);
	strB = stripLeading(strB);
	if (strA < strB) { return -1; }
	else
	  {
	  if (strA > strB) { return 1; }
	  else { return 0; }
	  }
}

function CompareDate(a, b)
{
	var pattern;
	var pieces;
	var result;
	var workdate;
	var portion;
	var datetype;
	var displaymonthasalpha;
	var dateone;
	var datetwo;
	var workstring;

	datetype = getLocalizedValue("DATE_TYPE"); 

	displaymonthasalpha = getLocalizedValue("DISPLAY_MONTH_AS_ALPHA");

	if (displaymonthasalpha == "1")
	  {
	  datetype = datetype + 10; 
	  }

	switch(datetype)
	  {
	  case 0:
	      // American style dates MM/DD/YYYY
	      pattern = new RegExp("([1-9]|0[1-9]|1[012])[/]([1-9]|0[1-9]|[12][0-9]|3[01])[/](19|20)\\d\\d");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
	        result = "01/01/2035";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      dateone = new Date(portion[0]);
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
	        result = "01/01/2035";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      datetwo = new Date(portion[0]);
	      break;
	  case 1:
	      // European style date DD/MM/YYYY
	      pattern = new RegExp("([1-9]|0[1-9]|[12][0-9]|3[01])[/]([1-9]|0[1-9]|1[012])[/](19|20)\\d\\d");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
	        result = "01/01/2035";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      dateone = new Date();
	      dateone.setDate(parseInt(pieces[0]));
	      dateone.setMonth(parseInt(pieces[1]) - 1);
	      dateone.setFullYear(parseInt(pieces[2]));
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
	        result = "01/01/2035";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      datetwo = new Date();
	      datetwo.setDate(parseInt(pieces[0]));
	      datetwo.setMonth(parseInt(pieces[1]) - 1);
	      datetwo.setFullYear(parseInt(pieces[2]));
	      break;
	  case 2:
	      // Asian style dates YYYY/MM/DD
	      pattern = new RegExp("(19|20)\\d\\d[/]([1-9]|0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01]|[1-9])");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
		result = "2035/01/01,";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      dateone = new Date();
	      dateone.setDate(parseInt(pieces[2]));
	      dateone.setMonth(parseInt(pieces[1]) - 1);
	      dateone.setFullYear(parseInt(pieces[0]));
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
		result = "2035/01/01,";
	      workdate = new String(result);
	      portion = workdate.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      datetwo = new Date();
	      datetwo.setDate(parseInt(pieces[2]));
	      datetwo.setMonth(parseInt(pieces[1]) - 1);
	      datetwo.setFullYear(parseInt(pieces[0]));
	      break;
	  case 10:
	      // American style dates MMM DD, YYYY
	      pattern = new RegExp("(" + CheckDisplayMonth + ") ([12][0-9]|3[01]|[1-9]|0[1-9]), (19|20)\\d\\d");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
	        {
	        result = "01/01/2035";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        workstring = workstring.replace(/,/,"");
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      dateone = new Date(portion[0]);
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
	        {
	        result = "01/01/2035";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        workstring = workstring.replace(/,/,"");
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      datetwo = new Date(portion[0]);
	      break;
	  case 11:
	      // European style date DD MMM YYYY
	      pattern = new RegExp("([12][0-9]|3[01]|[1-9]|0[1-9]) (" + CheckDisplayMonth + ") (19|20)\\d\\d");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
	        {
	        result = "01/01/2035";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      dateone = new Date();
	      dateone.setDate(parseInt(pieces[0]));
	      dateone.setMonth(parseInt(pieces[1]) - 1);
	      dateone.setFullYear(parseInt(pieces[2]));
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
	        {
	        result = "01/01/2035";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      datetwo = new Date();
	      datetwo.setDate(parseInt(pieces[0]));
	      datetwo.setMonth(parseInt(pieces[1]) - 1);
	      datetwo.setFullYear(parseInt(pieces[2]));
	      break;
	  case 12:
	      // Asian style dates YYYY MMM DD
	      pattern = new RegExp("(19|20)\\d\\d (" + CheckDisplayMonth + ") ([12][0-9]|3[01]|[1-9]|0[1-9])");
	      result = pattern.exec(a[currentCol]);
	      if (!pattern.test(a[currentCol]))
	        {
	        result = "2035/01/01";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      dateone = new Date();
	      dateone.setDate(parseInt(pieces[2]));
	      dateone.setMonth(parseInt(pieces[1]) - 1);
	      dateone.setFullYear(parseInt(pieces[0]));
	      result = pattern.exec(b[currentCol]);
	      if (!pattern.test(b[currentCol]))
	        {
	        result = "2035/01/01";
	        workstring = new String(result);
	        }
	      else
	        {
	        workstring = new String(result);
	        for (count = 1; count <= 12; count++)
	          if (workstring.indexOf(DisplayMonthName[count]) != -1)
	            {
	            workstring = workstring.replace(DisplayMonthName[count],count);
	            workstring = workstring.replace(/ /g,"/");
	            }
	        }
	      portion = workstring.split(",");
	      workstring = new String(portion);
	      pieces = workstring.split("/");
	      datetwo = new Date();
	      datetwo.setDate(parseInt(pieces[2]));
	      datetwo.setMonth(parseInt(pieces[1]) - 1);
	      datetwo.setFullYear(parseInt(pieces[0]));
	      break;
	  default:
	      dateone = new Date();
	      datetwo = new Date();
	      break;
	  }

	if (dateone < datetwo) { return -1; }
	else
	  {
	  if (dateone > datetwo) { return 1; }
	  else { return 0; }
	  }
}

function CompareNumeric(a, b)
{
	var numA = a[currentCol];
	var numB = b[currentCol];

	numA = stripLeading(numA);
	numA = removeExtra(numA);
	numA = parseInt(numA);
	if (isNaN(numA))
	  numA = 0;

	numB = stripLeading(numB);
	numB = removeExtra(numB);
	numB = parseInt(numB);
	if (isNaN(numB))
	  numB = 0;

        return numA - numB; 
}

function CompareMoney(a, b)
{
	var numA = a[currentCol];
	var numB = b[currentCol];

	numA = stripLeading(numA);
	numA = removeExtra(numA);
	numB = stripLeading(numB);
	numB = removeExtra(numB);
	numA = pullAmount(numA);
	numB = pullAmount(numB);

	numA = parseFloat(numA);
	numB = parseFloat(numB);

	numA = numA * 100;
	numB = numB * 100;

	numA = Math.round(numA);
	numB = Math.round(numB);

	if (isNaN(numA)) { return 0;}
	else
	  {
	  if (isNaN(numB)) { return 0; }
	  else { return numA - numB; }
	  }
}

function TableSort(myTable, myCallingObject, myType)
{
	// this function will determine the column number for
	// rectangular tables that have one column header
	// for each column.
	var aColumn = myCallingObject.cellIndex;
	TableSortByColumn(myTable, aColumn, myType, myCallingObject, 1);
}

function switchImage(myCallingObject)
{
	var aColumn = myCallingObject;
	var aPath= getLocalizedValue("IMG_OTHER");
	var reImage;
	var result;
	
	var strTemp;

	strTemp = myCallingObject.innerHTML;

	// check if arrow is up or down
	reImage = new RegExp("DOWN.gif\">");
	if (!reImage.test(strTemp))
	  result = 1;
	else
	  result = 0;

	// remove the current image string
	strTemp = strTemp.replace(/<img src(.|\n)+?>/gi,"");

	if (result == 0)
	  {
	  strTemp = "<img src=\"" + aPath + "/UP.gif\"> " + strTemp;
	  }
	else
	  {
	  strTemp = "<img src=\"" + aPath + "/DOWN.gif\"> " + strTemp;
	  }

	myCallingObject.innerHTML = strTemp;
}

function setImageDown(myCallingObject, myStepBack)
{
	var aColumn = myCallingObject;
	var aPath = getLocalizedValue("IMG_OTHER");
	var aRow;
	var aTableSection;
	var myCells;
	var myChildren;
	var myCount;
	var myCountToo;

	var strTemp;
	var strWork;
	
	strTemp = myCallingObject.innerHTML;

	if (myStepBack == 1)
	  {
	  // remove images from all columns
	  aRow = myCallingObject.parentNode;
	  myCells = aRow.childNodes;
	  for (myCount = 0; myCount < myCells.length; myCount++)
	    {
	    if (strTemp != myCells[myCount].innerHTML)
	      {
	      strWork = myCells[myCount].innerHTML;
	      if (strWork != null)
	        {
	        strWork = strWork.replace(/<img src(.|\n)+?>/gi,"");
	        myCells[myCount].innerHTML = strWork;
		}
	      }
	    }
	  }
	else
	  {
	  // have to get all rows in the multiple level column headers
	  aTableSection = myCallingObject.parentNode.parentNode;
	  myCells = aTableSection.childNodes;
	  for (myCount = 0; myCount < myCells.length; myCount++)
	    {
	    if (myCells[myCount] != null)
	      {
	      if (myCells[myCount].nodeType == 1)
	        {
		myChildren = myCells[myCount].childNodes;
		for (myCountToo = 0; myCountToo < myChildren.length; myCountToo++)
		  {
		  if (myChildren[myCountToo] != null && 
		      myChildren[myCountToo].nodeType == 1)
		    {
	            if (strTemp != myChildren[myCountToo].innerHTML)
	              {
	              strWork = myChildren[myCountToo].innerHTML;
	              if (strWork != null)
	                {
	                strWork = strWork.replace(/<img src(.|\n)+?>/gi,"");
	                myChildren[myCountToo].innerHTML = strWork;
		        }
	              }
		    }
	          }
	        }
	      }
	    }
	  }

	strTemp = myCallingObject.innerHTML;
	strTemp = strTemp.replace(/<img src(.|\n)+?>/gi,"");

	strTemp = "<img src=\"" + aPath + "/DOWN.gif\"> " + strTemp;

	myCallingObject.innerHTML = strTemp;

}

function check_for_sorted(myCallingObject)
{
	// If the column has an arrow then it is sorted
	var reImage;
	var result;
	var strTemp;

	strTemp = myCallingObject.innerHTML;

	// check if arrow is up or down
	reImage = new RegExp("<img src(.|\n)+?>","i");
	if (reImage.test(strTemp))
	  result = true;
	else
	  result = false;

	return result;
}

function TableSortByColumn(myTable, myColumn, myType, myCallingObject, myStepBack)
{
	var mySource = document.getElementById(myTable);
	var myRows = mySource.rows.length;
	var myCols = mySource.rows[0].cells.length;
	var i;
	var j;
	currentCol = myColumn;
	var myArray = new Array(myRows);
	for (i=0; i < myRows; i++)
	  {
	   myArray[i] = new Array(myCols);
	   for (j=0; j < myCols; j++)
	     {
	     if (mySource.rows[i].cells[j] != null)
	       myArray[i][j] = mySource.rows[i].cells[j].innerHTML;
	     else
	       myArray[i][j] = "";
	     }
	  }

	if (check_for_sorted(myCallingObject))
	  {
	  switchImage(myCallingObject);
	  myArray.reverse();
	  }
	else
	  {
	  setImageDown(myCallingObject,myStepBack);
	  switch (myType)
	    {
	    case "a":
	        myArray.sort(CompareAlpha);
	        break;
	    case "d":
	        myArray.sort(CompareDate);
	        break;
	    case "n":
	        myArray.sort(CompareNumeric);
	        break;
	    case "m":
	        myArray.sort(CompareMoney);
	        break;
	    default:
		myArray.sort(CompareAlpha);
		break;
	    }
	  }

	for (i=0; i < myRows; i++)
	  {
	  for (j=0; j < myCols; j++)
	    {
            if (mySource.rows[i].cells[j] != null)
	      mySource.rows[i].cells[j].innerHTML = myArray[i][j];
	    }
	  }
}

function verifyDateAndSubmit(inForm,inField,inLocalizedNever)
{
	var fields = inField.split(",");
	var localizedNever = inLocalizedNever.split(",");
	var theDate;

	for (count = 0; count < fields.length; count++)
	  {
	  theDate = document.getElementById(fields[count]);

	  if (theDate != null && theDate.value == getLocalizedValue(localizedNever[count]))
	    theDate.value = "NEVER";
	  }

	submitForm(inForm);
}

function setDisplayMonthName(inMonth,inLocalizedName)
{
	DisplayMonthName[inMonth] = inLocalizedName;

	if (CheckDisplayMonth.length == 0)
	  CheckDisplayMonth = inLocalizedName;
	else
	  CheckDisplayMonth = CheckDisplayMonth + "|" + inLocalizedName;
}

function createList()
{
	var nForm;
	var nValue;

	nValue = document.getElementById("list_description").value;

	nValue = new String(nValue);

	if (nValue.length == 0)
	  alert(getLocalizedValue("CREATE_LIST"));
	else
	  {
	  nFORM=document.createElement('form');
	  nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/150";
	  nFORM.target="_self";
	  nFORM.method="post";
	  nFORM.name="createlistform";

	  nField=document.createElement('input');
	  nField.name='description';
	  nField.id='description';
	  nField.value=document.getElementById("list_description").value;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  document.body.appendChild(nFORM);
	  nFORM.submit();
	  }
}

function removeList()
{
	var nForm;
	var portion;
	var nValue;

	nValue = document.getElementById("current_list").value;

	nValue = new String(nValue);
	portion = nValue.split("^");
	nValue = portion[0];

	if (confirm(getLocalizedValue("DELETE_LIST") +  " " + portion[1]))
	  {
	  nFORM=document.createElement('form');
	  nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/151";
	  nFORM.target="_self";
	  nFORM.method="post";
	  nFORM.name="removelistform";

	  nField=document.createElement('input');
	  nField.name='list_id';
	  nField.id='list_id';
	  nField.value=nValue;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  document.body.appendChild(nFORM);
	  nFORM.submit();
	  }
}

function renameList()
{
	var nForm;
	var portion;
	var nValue;
	var nNewDescription;

	nValue = document.getElementById("current_list").value;

	nValue = new String(nValue);
	portion = nValue.split("^");
	nValue = portion[0];

	nNewDescription = prompt(getLocalizedValue("LD_RENAME") + "  " + portion[1],"");

	if (nNewDescription != null &&
	    nNewDescription != "")
	  {
	  if (nNewDescription.length > 80)
	    {
	    var alertMsg = getLocalizedValue("LD_RENAME");
	    alertMsg += getLocalizedValue("21493");
	    alert(alertMsg);
	    }
	  else
	    {
	    nFORM=document.createElement('form');
     	    nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/153";
	    nFORM.target="_self";
	    nFORM.method="post";
  	    nFORM.name="renamelistform";

	    nField=document.createElement('input');
	    nField.name='list_id';
	    nField.id='list_id';
	    nField.value=nValue;
	    nField.type='hidden';
	    nFORM.appendChild(nField);

	    nField=document.createElement('input');
	    nField.name='description';
	    nField.id='description';
	    nField.value=nNewDescription;
	    nField.type='hidden';
	    nFORM.appendChild(nField);

	    document.body.appendChild(nFORM);
	    nFORM.submit();
	    }
	  }
}

function makeListActive()
{
	var nForm;

	nValue = document.getElementById("current_list").value;

	nValue = new String(nValue);
	portion = nValue.split("^");
	nValue = portion[0];

	nFORM=document.createElement('form');
   	nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/156/" + nValue;
	nFORM.target="_self";
	nFORM.method="post";
  	nFORM.name="setcurrentform";

	document.body.appendChild(nFORM);
	nFORM.submit();
}

function removeCheckedTitles(inList)
{
	var nForm;
	var myForm;
	var workString;
	var ckeys = new String();

	myForm = document.getElementById("captureform");
	if (myForm != null)
	  {
	  checkboxes = myForm.length;
	  for (count = 0; count < checkboxes; count++)
	    if (myForm[count].type == 'checkbox')
	        if (myForm[count].checked == true)
                  {
	          workString = new String(myForm[count].name);
	          if (workString.indexOf("kept-") != -1)
	            {
	            workString = workString.substring(5);
	            if (ckeys.length == 0)
	              ckeys = workString;
	            else
	              ckeys = ckeys + ":" + workString;
	            } 
                  }
	  }

	if (ckeys.length != 0)
	  {
	  nFORM=document.createElement('form');
	  nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/155";
	  nFORM.target="_self";
	  nFORM.method="post";
	  nFORM.name="removelistform";

	  nField=document.createElement('input');
	  nField.name='list_id';
	  nField.id='list_id';
	  nField.value=inList;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  nField=document.createElement('input');
	  nField.name='ckeys';
	  nField.id='ckeys';
	  nField.value=ckeys;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  document.body.appendChild(nFORM);
	  nFORM.submit();
	  }
}

function removeAllTitles(inList)
{
	var nForm;
	var myForm;
	var workString;
	var ckeys = new String();

	myForm = document.getElementById("captureform");
	if (myForm != null)
	  {
	  checkboxes = myForm.length;
	  for (count = 0; count < checkboxes; count++)
	    if (myForm[count].type == 'checkbox')
	      {
	      workString = new String(myForm[count].name);
	      if (workString.indexOf("kept-") != -1)
	        {
	        workString = workString.substring(5);
	        if (ckeys.length == 0)
	          ckeys = workString;
	        else
	          ckeys = ckeys + ":" + workString;
	        }
	      } 
	  }

	if (ckeys.length != 0 && confirm(getLocalizedValue("REMOVE_ALL_TITLES")))
	  {
	  nFORM=document.createElement('form');
	  nFORM.action=getLocalizedValue("WEBCAT_URL") + "/" + getLocalizedValue("SESSION") + "/155";
	  nFORM.target="_self";
	  nFORM.method="post";
	  nFORM.name="removelistform";

	  nField=document.createElement('input');
	  nField.name='list_id';
	  nField.id='list_id';
	  nField.value=inList;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  nField=document.createElement('input');
	  nField.name='ckeys';
	  nField.id='ckeys';
	  nField.value=ckeys;
	  nField.type='hidden';
	  nFORM.appendChild(nField);

	  document.body.appendChild(nFORM);
	  nFORM.submit();
	  }
}

function setEnterpriseReturn(inLogoutURL, inReturnURL)
{
	window.location = inLogoutURL;
	window.location = inReturnURL;
}

function required() {
  date = new Date;
	if ($('required') != undefined) {
		$('required').insert('Copyright &#169; 2000 - '+date.getFullYear()+', SirsiDynix');
	}
}

function setDisabled(inElement, inElementCB)
{
	myElement = document.getElementById(inElement);
	myElementCB = document.getElementById(inElementCB);

	if (myElementCB.checked)
	  myElement.disabled = true;
	else
	  myElement.disabled = false;
}


function saveFirst(e) 
{
	if (getChangedAdmin()) 
	  {
	  if(!e) e = window.event;
	  e.cancelBubble = true;
	  e.returnValue = getLocalizedValue("ADMIN_CHANGE"); 

	  if (e.stopPropagation) 
	    {
	    e.stopPropagation();
	    e.preventDefault();
	    }
	  return getLocalizedValue("ADMIN_CHANGE");
	  }
}

function setChangedAdminOff()
{
	adminchanged = 0;
}

function setChangedAdmin()
{
	adminchanged = 1;
}

function getChangedAdmin()
{
	return adminchanged;
}

function saveAdmin()
{
	setChangedAdminOff();
	myform = document.getElementById("update_form");
	myform.submit();
}

function checkEnvnChange(inForm,inSelect)
{
	var myform = document.getElementById(inForm);
	var rc;
	if (getChangedAdmin())
	  {
	  rc = confirm(getLocalizedValue("ADMIN_CHANGE"));
	  if (rc == true) 
	    {
	    setChangedAdminOff();
	    myform.submit();
	    }
	  else
	    {
	    var myselect = document.getElementById(inSelect);
	    restoreSelect(myselect,getLocalizedValue("ADMIN_ENVN"));
	    }
	  }
	else myform.submit();
}

function restoreSelect(inSelect,inValue)
{
	var pos = -1;
	for (count = 0; count < inSelect.length && pos == -1; count++)
	  {
	  if (inValue == inSelect.options[count].value)
	    pos = count;
	  }
	inSelect.selectedIndex = pos;
}

function keep_alive(webcatUrl,session,imgOther)
{
    	var xRequest = null;
    	if (window.XMLHttpRequest)
    	  {
	  xRequest= new XMLHttpRequest();
    	  }
    	else if (typeof ActiveXObject != "undefined")
    	  {
	  xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	
	if (xRequest != null)
	  {
	  xRequest.open("GET",webcatUrl + "/" + session + "/302",true);
	  xRequest.send(null);
	  }
}

function loadEnterpriseSearch(event, enterprise_search_url) {
  var search_term = $('search_term').value;
  // var search_term = document.getElementById('search_term').value;
  
  // there is a quicker way to do this, but this is easier for modification

  search_term = search_term.replace(/\$/gi,  '$002524');
  
  search_term = search_term.replace(/ /gi,  '$002b');
  search_term = search_term.replace(/"/gi,  '$002522');
  search_term = search_term.replace(/'/gi,  '$002527');
  search_term = search_term.replace(/\//gi, '$00252F');
  search_term = search_term.replace(/\\/gi, '$00255C');
  
  search_term = search_term.replace(/\`/gi, '$002560');
  search_term = search_term.replace(/\~/gi, '$00257E');
  search_term = search_term.replace(/!/gi,  '$002521');
  search_term = search_term.replace(/@/gi,  '$002540');
  search_term = search_term.replace(/#/gi,  '$002523');
  search_term = search_term.replace(/%/gi,  '$002525');
  search_term = search_term.replace(/\^/gi, '$00255E');
  search_term = search_term.replace(/&/gi,  '$002526');
  search_term = search_term.replace(/\*/gi, '$002a');
  search_term = search_term.replace(/\(/gi, '$002528');
  search_term = search_term.replace(/\)/gi, '$002529');
  search_term = search_term.replace(/\+/gi, '$00252B');
  search_term = search_term.replace(/\=/gi, '$00253D');
  search_term = search_term.replace(/\[/gi, '$00255B');
  search_term = search_term.replace(/\]/gi, '$00255D');
  search_term = search_term.replace(/\{/gi, '$00257B');
  search_term = search_term.replace(/\}/gi, '$00257D');
  search_term = search_term.replace(/\|/gi, '$00257C');
  search_term = search_term.replace(/\:/gi, '$00253A');
  search_term = search_term.replace(/\;/gi, '$00253B');
  search_term = search_term.replace(/\</gi, '$00253C');
  search_term = search_term.replace(/\>/gi, '$00253E');
  search_term = search_term.replace(/\,/gi, '$00252C');
  search_term = search_term.replace(/\?/gi, '$00253F');
  
  var search_url = enterprise_search_url; 
  if (event) {
    // check to see if enter was pressed
    if(event.keyCode=='13'){
      window.location = search_url+search_term;
    }
  }
  else {
    // no key press. button was clicked.
    window.location = search_url+search_term;
  }
}

