/* HighBeam Research utility functions copyright 2003, justin blecher / digital pulp, inc. */ // == global vars ============================================================== // tests for DHTML capability var capable = (document.getElementById) ? true : false; // variables for iframe setup var IFRAME_URL = "/prefs/saveprefs.asp"; var IFRAME_ID = "hbr_server_comm"; // classes and ids of page elements used in dhtml /* NOTE: certain functions below rely upon specific JS variables and CSS IDs and CLASSes if you modify any HTML or CSS, and you start getting JS errors, check here! */ var NAVTAVBS_ID = "tabs"; var DISPLAYSETTINGS_ID = "displaySettings"; var LISTINGCONTENT_ID = "listingContent"; var LOGO_CLASS = "logo"; var SUMMARY_CLASS = "summary"; var SEARCHING_CLASS = "searching"; var CONTENT = "content"; var DISPLAY_SETTINGS_FORM_NAME = "display_setttings_form"; var SHOWELIB = "showelib"; var NEWWINDOWWEB = "newwindowweb"; //DHTML textbox character counter (IE4+) script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/) function taLimit() { var taObj=event.srcElement; if (taObj.value.length==taObj.maxLength*1) return false; } function taCount(visCnt) { var taObj=event.srcElement; if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1); if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length; } // == display settings utility functions ======================================= function updateFontSelectMenu(form) { var form_to_use; if ( (!document.forms[DISPLAY_SETTINGS_FORM_NAME]) || (typeof(alt_css) == 'undefined')) return; document.forms[DISPLAY_SETTINGS_FORM_NAME].ds_font_style.options.selectedIndex = (alt_css.getValueForProperty('font') == 'serif') ? 1 : 0; } // END: updateFontSelectMenu() function updateFontSizeLinks() { var font_size_abbr; if (typeof(alt_css) == 'undefined') return; switch (alt_css.getValueForProperty('size')) { case 'small': font_size_abbr = "S"; break; case 'medium': font_size_abbr = "M"; break; case 'large': font_size_abbr = "L"; break; case 'xlarge': font_size_abbr = "XL"; break; default: font_size_abbr = "M"; } showSizeFeedback('size' + font_size_abbr); } // END: updateFontSizeLinks() function fixTabs() { var tab_wrapper = document.getElementById(NAVTAVBS_ID); var tabs = tab_wrapper.getElementsByTagName('li'); for (var i=0; i < tabs.length; i++) { if (tabs[i].className != 'active'){ tabs[i].onclick = function(e) { location.href = this.firstChild.firstChild.href; }; // end function } } } // END: fixTabs() function showSizeFeedback(id) { var el, container, all_links; if (!(el = document.getElementById(id))) return; container = document.getElementById(DISPLAYSETTINGS_ID); all_links = container.getElementsByTagName('a'); for (var i=0; i < all_links.length; i++) { if (all_links[i].id.indexOf('size') != -1) all_links[i].style.color = "#C00"; } el.style.color = "#666"; } // END: sizeFeedback() // == display settings functions =============================================== function toggleLogos(el) { var results_list = document.getElementById(LISTINGCONTENT_ID); var all_images = results_list.getElementsByTagName('img'); for (var i=0; i < all_images.length; i++) { if (all_images[i].className == LOGO_CLASS) all_images[i].style.display = (all_images[i].style.display == 'none') ? 'inline' : 'none'; } saveDisplaySettingToProfile('show_logos', el.checked); } // END: toggleLogos() function toggleRefLogos(el) { var results_list = document.getElementById(LISTINGCONTENT_ID); var all_images = results_list.getElementsByTagName('img'); for (var i=0; i < all_images.length; i++) { if (all_images[i].className == LOGO_CLASS) all_images[i].style.display = (all_images[i].style.display == 'none') ? 'inline' : 'none'; } saveDisplaySettingToProfile('show_reflogos', el.checked); } // END: toggleRefLogos() // function toggleLinks(el) { // Looks for all resultlinks and changes the target // Input: checkbox var all_results = document.getElementsByName('resultlink'); var newtarget; if (el.checked){ newtarget = '_blank';}else{ newtarget = '_self';} for (var i=0; i < all_results.length; i++) { all_results[i].target = newtarget; } saveDisplaySettingToProfile('open_links', el.checked); } // END: toggleLinks() function toggleLinksWeb(el) { var results_list = document.getElementById(LISTINGCONTENT_ID); var all_links = results_list.getElementsByTagName('a'); for (var i=0; i < all_links.length; i++) { all_links[i].target = (all_links[i].target == '_blank') ? '_self' : '_blank'; } saveDisplaySettingToProfile('open_linksWeb', el.checked); }// END: toggleLinksWeb() function toggleLinksExec(el) { var results_list = document.getElementById(LISTINGCONTENT_ID); var all_links = results_list.getElementsByTagName('a'); for (var i=0; i < all_links.length; i++) { all_links[i].target = (all_links[i].target == '_blank') ? '_self' : '_blank'; } saveDisplaySettingToProfile('open_linksExec', el.checked); }// END: toggleLinksExec() function toggleSummaries(el) { var results_list = document.getElementById(LISTINGCONTENT_ID); var all_items = results_list.getElementsByTagName('div'); for (var i=0; i < all_items.length; i++) { if (all_items[i].className == SUMMARY_CLASS) all_items[i].style.display = (all_items[i].style.display == 'none') ? 'block' : 'none'; } saveDisplaySettingToProfile('show_summaries', el.checked); } // END: toggleSummaries() function toggleElib(el) { if (el.checked) { document.getElementById("SHOWELIB").style.display = 'block' document.getElementById("SHOWELIB1").style.display = 'block' document.getElementById("dsShowElib").checked = true; document.getElementById("dsShowElib1").checked = true; } else { document.getElementById("SHOWELIB").style.display = 'none' document.getElementById("SHOWELIB1").style.display = 'none' document.getElementById("dsShowElib").checked = false; document.getElementById("dsShowElib1").checked = false; } saveDisplaySettingToProfile('show_elib', el.checked); } //END: toggleElib() function toggleSearching(el) { var results_list = document.getElementById(CONTENT); var all_items = results_list.getElementsByTagName('div'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == LISTINGCONTENT_ID) all_items[i].style.display = 'none'; if (all_items[i].id == 'listingHeader') all_items[i].style.display = 'none'; if (all_items[i].id == 'listingFooter') all_items[i].style.display = 'none'; if (all_items[i].className == SEARCHING_CLASS) all_items[i].style.display = 'block' ; } } // END: toggleSearching() function toggleSearchingIndex(el) { var results_list = document.getElementById(CONTENT); var all_items = results_list.getElementsByTagName('div'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == 'groups') all_items[i].style.display = 'none'; if (all_items[i].className == SEARCHING_CLASS) all_items[i].style.display = 'block' ; } } // END: toggleSearching() //Used to replace all html and text between the specified span tag. //spanid = id of span tag //text1 = text or html first displayed on the page //text2 = text you want to toggle to function rewrite(spanid, text1, text2) { if (document.getElementById(spanid).innerHTML == text1){ document.getElementById(spanid).innerHTML = text2; } else{ document.getElementById(spanid).innerHTML = text1; } } // end rewrite function saveDisplaySettingToProfile(pref, value) { ts = new Date(); createCommChannel(); document.getElementById(IFRAME_ID).src = IFRAME_URL + "?" + pref + "=" + value + "&time=" + ts.getTime(); destroyCommChannel(); } // END: saveDisplaySettingToProfile() // == metasearch functions =========================================== // This function calls the function to toggle the searching text, // then submits the current form. function submit_metaform() { toggleSearching(this); document.searchForm.submit(); } function submit_metaform_index() { toggleSearchingIndex(this); document.searchForm.submit(); } // == iframe communication functions =========================================== /* NOTE: we need to create and destroy this each time the function is called so the browser history doesn't get clogged up with iframe 'navigation' */ function createCommChannel() { var iframe_parent, iframe; iframe = document.getElementById(IFRAME_ID); if (iframe == null) { iframe = document.createElement('iframe'); iframe.id = IFRAME_ID; iframe.style.visibility = "hidden"; iframe.style.width = 1 + "px"; iframe.style.height = 1 + "px"; iframe_parent = document.getElementsByTagName('body')[0]; iframe_parent.appendChild(iframe); } } // END: createCommChannel() function destroyCommChannel() { //alert ('beforedestroy'); //document.getElementsByTagName('body')[0].removeChild(document.getElementsByTagName('body')[0].lastChild); } // END: destroyCommChannel() // == radio/checkbox toggle functions ========================================== function adjustSearchType(obj) { var looking_for = (obj.type == "checkbox") ? "radio" : "checkbox"; for (var i=0; i < document.forms[obj.form.name].length; i++ ) { if (document.forms[obj.form.name].elements[i].type == looking_for) document.forms[obj.form.name].elements[i].checked = false; } } // END: adjustSearchType() // == window pop functions ===================================================== function saveArticle() { var width = 375; var height = 275; var url = "popup.save-article.html"; var window_name = 'saveArticleWin'; window.open(url, window_name, "width=" + width + ",height=" + height + ",toolbar=no,status=no,scrolling=no"); } function editResearchGroups() { var width = 460; var height = 430; var url = "popup.edit-research-group.html"; var window_name = 'editResearchWin'; window.open(url, window_name, "width=" + width + ",height=" + height + ",toolbar=no,status=no,scrolling=no"); } function toggleSearchingIndex(el) { var results_list = document.getElementById(CONTENT); var all_items = results_list.getElementsByTagName('div'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == 'groups') all_items[i].style.display = 'none'; if (all_items[i].className == SEARCHING_CLASS) all_items[i].style.display = 'block' ; } } // END: toggleSearching() ///////BEGIN: ADVANCED SEARCH SPECIFIC FUNCTIONS////////////////// //Used to update the forms on the search page function updateSrcs(srcName){ var all_items = document.getElementsByTagName('input'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == srcName.id){ if (all_items[i].type == "checkbox") { //get all the labels associated with the checkbox var label_items = document.getElementsByName(all_items[i].id+'_label'); if (srcName.checked){ all_items[i].checked = true; //change the labels to red and bold for (var x=0; x < label_items.length; x++) { //MTK 1/3/06 Removed bold red source types. //label_items[x].style.color = "#C00"; //red //label_items[x].style.fontWeight = "bold"; label_items[x].style.color = "#000"; //black label_items[x].style.fontWeight = "normal"; } }else{ all_items[i].checked = false; //change the labels to black and non-bold for (var x=0; x < label_items.length; x++) { label_items[x].style.color = "#000"; //black label_items[x].style.fontWeight = "normal"; } } }else{ if (srcName.checked){ all_items[i].value = "on"; //alert("on"); }else{ all_items[i].value = "off"; //alert("off"); } } } } }//end updateSrcs() /////////////////////////////////////////////////////////////////////////// function updateShowAdv(thisCheck){ var all_items = document.getElementsByTagName('input'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == thisCheck.id){ if (all_items[i].type == "checkbox") { if (thisCheck.checked){ all_items[i].checked = true; }else{ all_items[i].checked = false; } } } } }//end updateSrcs() /////////////////////////////////////////////////////////////////////////// function toggleSearchForm(onName) { var results_list = document.getElementById('searchHeader'); var all_items = results_list.getElementsByTagName('div'); var offName; if (onName == 'advancedform'){ offName = 'simpleform'; } else{ offName = 'advancedform'; } for (var i=0; i < all_items.length; i++) { if (all_items[i].id == offName){ all_items[i].style.display = 'none'; } if (all_items[i].id == onName){ all_items[i].style.display = 'block'; } } } // END: toggleSearchForm() /////////////////////////////////////////////////////////////////////////// function toggleAdvancedOptions() { var results_list = document.getElementById('advancedform'); var all_items = results_list.getElementsByTagName('div'); for (var i=0; i < all_items.length; i++) { if (all_items[i].id == 'advOpt'){ if (all_items[i].style.display == 'block'){ all_items[i].style.display = 'none'; } else{ all_items[i].style.display = 'block'; } } } } // END: toggleSearchForm() ////////////////BEGIN: USED ON SEARCH.ASP FOR ADVANCED SEARCH FEATURES////////////////// // This function returns the current search form (either the normal or the advanced one). function getSearchForm() { if (document.subToggle.whichform.value == "searchForm"){ return document.searchForm; }else{ return document.advancedSearchForm; } } function submitadvanced(freePremium){ var inputElem = document.createElement("input"); inputElem.setAttribute("type","hidden"); inputElem.setAttribute("name","FreePremium"); inputElem.setAttribute("value",freePremium); if (document.subToggle.whichform.value == "searchForm"){ document.searchForm.appendChild(inputElem) document.searchForm.submit(); }else{ updatePubsHidden(document.advancedSearchForm, document.advancedSearchForm.myList, document.advancedSearchForm.search_publication); document.advancedSearchForm.appendChild(inputElem) document.advancedSearchForm.submit(); } } function toggleSubToggle(){ var thisForm = document.subToggle.whichform; if (thisForm.value == "searchForm"){ thisForm.value = "advancedSearchForm"; }else{ thisForm.value = "searchForm"; } } //////////////////////////////////////////////////////// function clearEmptyOptions(thisForm){ for (n=0; n < thisForm.options.length; n++) { if (thisForm.options[n].value == ""){ thisForm.options[n] = null; } } } //////////////////////////////////////////////////////// function sourcesToPop(thisForm){ var theList; theList = ""; clearEmptyOptions(thisForm); for (n=0; n < thisForm.options.length; n++) { theList = theList + escape(thisForm.options[n].text) + "|||"; } return theList; } //////////////////////////////////////////////////////// function openViewSrcs(thisForm, cntrlInfo){ //convert list of sources into string for the popup var theList; theList = sourcesToPop(thisForm); //open window with the list attached in the querystring var SrcWin = window.open('/library/viewsrcs.asp?' + cntrlInfo + '&source=news&kp=' + theList,'ViewPublications','toolbar=no,resizable=yes,status=no,scrollbars=yes,width=700,height=500'); SrcWin.focus(); } //////////////////////////////////////////////////////// function updatePubsHidden(thisForm, thisList, thisHidden){ var savestr; savestr = ""; clearEmptyOptions(thisList); for (i=0; i= 0; i--) { thisBox.options[i] = null; } } //////////////////////////////////////////////////////////////////////////////// function wipeSingles(thisBox){ for (i=thisBox.options.length - 1; i>=0; i--) { if (thisBox.options[i].selected == true){ thisBox.options[i] = null; } } } ///////////////////////////////////////////////////////////////// function updateMylist(thisList, thistext, thisval){ var q; var thisText; var thisVal; q = thisList.length; thisText = new Option(thistext, thisval); try { thisList.options[q] = thisText; } catch(exception){ alert("Error is " + exception.message) alert("Error is |" + exception.description + "|"); } } ///////END: ADVANCED SEARCH SPECIFIC FUNCTIONS////////////////// ///////////////////////////////////////////////////////////////////////////////////// //trim functions function LTrim(str) { var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(0)) != -1) { var j=0, i = s.length; while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++; s = s.substring(j, i); } return s; } function RTrim(str) { var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { var i = s.length - 1; while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--; s = s.substring(0, i+1); } return s; } function Trim(str) { return RTrim(LTrim(str)); } ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// //used by advanced search for dates function greyout(whichBox){ whichBox.style.backgroundColor = "#EEEEEE"; whichBox.disabled = true; } function greyin(whichBox){ whichBox.style.backgroundColor = "#FFFFFF"; whichBox.disabled = false; } function greytxt(){ var thisel = document.getElementById("greyword"); thisel.style.color = "#CCCCCC"; } function blacktxt(){ var thisel = document.getElementById("greyword"); thisel.style.color = ""; } function alterdate(datetype, dateone, datetwo) { var CurrentDate = new Date(); var CurrentMonth = CurrentDate.getMonth() + 1; var CurrentYear = CurrentDate.getYear(); var CurrentDay = CurrentDate.getDate(); var MinusMonth; var MinusYear; var browser = navigator.appName; var isokay = 1; if (browser.indexOf("Netscape") != -1) { var version = navigator.appVersion; version=version.substring(0,2); if (version < 3.0) { isokay = 0; } } if (isokay == 1) { var WidgetValue = datetype.options[datetype.selectedIndex].value; if (WidgetValue == "all") { greyout(dateone); greyout(datetwo); greytxt(); } else if ((WidgetValue == "matches") || (WidgetValue == "before") || (WidgetValue == "after")){ greyin(dateone); greyout(datetwo); greytxt(); } else{ greyin(dateone); greyin(datetwo); blacktxt(); } } if (isokay == 1) { if ((WidgetValue == "matches") || (WidgetValue == "before") || (WidgetValue == "after")) { if (dateone.value == ""){ dateone.value = "MM/DD/YYYY"; } datetwo.value = ""; } else if (WidgetValue == "all") { datetwo.value = ""; dateone.value = ""; } else if (WidgetValue == "between") { if (dateone.value == ""){ dateone.value = "MM/DD/YYYY"; } if (datetwo.value == ""){ datetwo.value = "MM/DD/YYYY"; } } else { if (CurrentYear < 200) { CurrentYear += 1900; } datetwo.value = CurrentMonth + "/" + CurrentDay + "/" + CurrentYear; MinusMonth = WidgetValue % 12; MinusYear = (WidgetValue - MinusMonth) / 12; if (CurrentMonth <= MinusMonth) { MinusMonth -= 12; MinusYear += 1; } CurrentMonth -= MinusMonth; CurrentYear -= MinusYear; if (CurrentDay > 28) { if (CurrentMonth == 2) { if ((CurrentYear % 400) == 0) { CurrentDay = 29; } else if ((CurrentYear % 100) == 0) { CurrentDay = 28; } else if ((CurrentYear % 4) == 0) { CurrentDay = 29; } else { CurrentDay = 28; } } else if ((CurrentDay > 30) && ((CurrentMonth == 4) || (CurrentMonth == 6) || (CurrentMonth == 9) || (CurrentMonth == 11))) { CurrentDay = 30; } } dateone.value = CurrentMonth + "/" + CurrentDay + "/" + CurrentYear; } } } ///////////////////////////////////////////////////////////////////////////////////// //END: used by advanced search for dates