function removeColumnsByHeader(searchString, tableHeaders, tableColumns) {
  /* pass in a string to search for in the table header.
     when a match is found, remove the header, along with the
     cells underneath it
  */
  for (i=0; i < tableHeaders.length; i++) {
    findString = tableHeaders[i].innerHTML.indexOf(searchString);
    if (findString != -1) {
      tableHeaders[i].style.display = "none";
      tableColumns[i].style.display = "none";
    }
  }
}

function replaceColumnData(searchString, key, replacementString, tableHeaders, tableColumns) {
  /* pass in a string to search for in the table cells . when the string
     is found, replace it with replacementString.
  */
  if (key == "") {
    for (i=0; i<tableColumns.length; i++) {
      findString = tableColumns[i].innerHTML.indexOf(searchString);
      if (findString != -1) {
        tableColumns[i].innerHTML = replacementString; 
      }
    }
  }
  
  /* search table cells for key. 
     when found key is found, search cells of row for searchString
     then replace with replacementString   
  */
  if (key != "") {
    for (i=0; i<tableColumns.length; i++) {
      findString = tableColumns[i].innerHTML.indexOf(key);
      if (findString != -1) {
        currentRow = tableColumns[i];
        currentRowSiblings = currentRow.siblings();
        for (j=0; j< currentRowSiblings.length; j++) {
          findSearchString = currentRowSiblings[j].innerHTML.indexOf(searchString);
          if (findSearchString != -1) {
            currentRowSiblings[j].innerHTML = replacementString; 
          }
        }
      }
    }
  }
}

function customJavaScript() {
  // add title 'Easy view' to disability icon
  if (document.getElementById("adaModeDiv")) {
	var adaMode = document.getElementById("adaModeDiv");
    img = adaMode.firstChild.firstChild;
	img.title = "Easy view";
	img.src = "http://ucca.ent.sirsidynix.net.uk/custom/web/eye.png";
	function restoreImage () {
		img.style.display = "block";
	}
	setTimeout(restoreImage,1000);
	
	

  }
  // hit list
  if ($$('.range')[0] != undefined) {
    elementLabels = $$('.displayElementLabel');
    for (i=0; i< elementLabels.length; i++) {
      findString = elementLabels[i].innerHTML.indexOf("Available online");
      if (findString != -1) {
        elementLabels[i].style.display = "none";
        tempContainer = elementLabels[i].adjacent('div')
        tempAnchor = elementLabels[i].adjacent('a');
        tempAnchor[0].style.display = "none";
        tempContainer[0].innerHTML = "<a href='"+tempAnchor[0].href+"'><img src='/custom/web/uca/javascript/URL2.gif' alt='Access Online Resource'/></a>";
        
      }
    }
  }
  
  // details page
  if ( ($$('.range')[0] == undefined)  && ($$('.isbnValue')[0] != undefined) ) {
    tableHeaders = $$('#detailItemTable thead tr th');
    tableColumns = $$('#detailItemTable tbody tr td');
    
    // check to see if the detail page is for ebooks, then remove columns
    find = "VIRTUAL";
    for (x=0; x<tableColumns.length; x++) {
      found = tableColumns[x].innerHTML.indexOf(find);
      if (found != -1) {
        // remove the bar code column for Ebooks
        removeColumnsByHeader("Item Barcode", tableHeaders, tableColumns);
        //remove the holds column for Ebooks
        removeColumnsByHeader("Holds", tableHeaders, tableColumns);
      }
    }

    // search string, string to key off of, replace ment string, pass in headers, pass in column data
    
    // replace the XX call number for ebooks with "Ebook" for libraries with the name VIRTUAL    
    replaceColumnData("XX", "VIRTUAL", "Ebook", tableHeaders, tableColumns);
    
    // remove the hold text. may not be needed if you are removing the entire holds column
    replaceColumnData("Request Item", "VIRTUAL", "", tableHeaders, tableColumns);
  }


}


