// // put all custom javascript functions and global definitions here // function el(id) { return document.getElementById(id); } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } // ------------------------------------------------------------------------------------ // function domoreless() { var link =el("moreless_link"); var theel = el("moreless_text") //1--TOGGLE var linkname = link.innerHTML; if (linkname == "More...") { js_showhide(theel,1); linkname = "Less..."; } else { js_showhide(theel,0); linkname = "More..."; } link.innerHTML = linkname; return void(0); } function js_showhide(el,show) { if (!el) return; if (show) { el.style.display = 'block'; } else { el.style.display = 'none'; } } // --------------------------------------------------------------------------------------- // function add_to_menu(selectname,thetext,thevalue,select) { var elOptNew = document.createElement('option'); elOptNew.text = thetext; elOptNew.value = thevalue; if (select) { elOptNew.selected = true; } var elSel = document.getElementById(selectname); if (elSel.options[0]) if (elSel.options[0].value == 0) { elSel.options[0].selected = false; //unselect the NONE option } try { elSel.add(elOptNew, null); // standards compliant; doesn't work in IE } catch(ex) { elSel.add(elOptNew); // IE only } } function add_to_menu_and_select(selectname,thetext,thevalue) { var selectname_in = selectname; var filter = window["filter_" + selectname_in]; // see filterlist.js -- global defined? if (filter) { // get all the menu options back in the list before we do the add_to_menu filter.set(' '); // trick to show all! el("regexp_"+selectname_in).value=''; } var multiname = "multi_" + selectname_in; if (el("id_" + selectname_in)) { selectname = "id_" + selectname_in; //if we have a id of id_primary_investigator use that instead of primary_investigator } add_to_menu(selectname,thetext,thevalue,1); var multi = el(multiname); if (multi) { add_to_menu(multiname,thetext,thevalue,1); } if (filter) { //step 1--make sure we add the new value into the filter's copy, then init the list just as when we first arrive at the page filter.init(); //step 2--now filter for that name you just added! filter.set(thetext); el("regexp_"+selectname_in).value=thetext; } } function add_to_menus(selectnames,thetext,thevalue) { //loop -- are there cases where we need to add to multiple lists? not yet //add_to_menu_and_select(selectname,thetext,thevalue) } function showhideit(showid,show) { var showspan = document.getElementById(showid); if (show) { showspan.style.display = 'block'; } else { showspan.style.display = 'none'; } } function toggleit(that,section_num) { var show; if (that.innerHTML == "(Skip This Section)") { that.innerHTML = "(Show This Section)"; show = 0; } else { that.innerHTML = "(Skip This Section)"; show = 1; } showhideit("section_"+section_num,show); return false; } function fnAdd(name,menu) { var selected = menu.options[menu.selectedIndex].text; var selected_value = menu.options[menu.selectedIndex].value; //alert(menu.id); ///if (usesingle[menu.id]) ///{ /// selecteda = selected.split(divider[menu.id]); /// selected = selecteda[1]; //the second value (e.g. country in "continent - country") ///} if (!selected) return; var three = document.getElementById(name); var len = three.options.length; //make sure not already in list! for(var i in three.options) { var val = three.options[i]; if (val && (selected_value == val.value)) { alert(selected +" already in list"); return; } } //do it! //alert(len+selected); var opt = new Option(); opt.text = selected; opt.value = selected_value; three.options[len] = opt; //three.selectedIndex = len; // select the final one? fnClear(name); } function fnClear(name) { var three = document.getElementById(name); if (!three) three = document.getElementById("id_"+name); three.selectedIndex = -1; } function fnDelete(name) { var three = document.getElementById(name); var selectedi = three.selectedIndex; if (selectedi < 0) return; var selected = three.options[selectedi].text; if (!selected) return; //alert("deleting #"+selectedi +" "+selected); //removed! three.options[selectedi] = null; } function fnSelectAll(names) { names = names.split(","); for(var n in names) { name = names[n]; var three = document.getElementById(name); // alert(name); three.multiple = true; for(var i in three.options) { if (!three.options[i]) continue; if (three.options[i] == null) continue; if (!three.options[i].text) continue; three.options[i].selected = true; //alert(three.options[i].text); } } return true; } // // from header.html // function newwindow(reference){ //opens reference in new window without tool bar, but with scroll newwind=window.open(reference,'refwin','width=300,height=400,scrollbar=yes'); newwind.focus(); } function showDate() { // Display current date in date field var currDate = new Date() var currDay = currDate.getDate(); var currMonth = currDate.getMonth()+1; var currYear = currDate.getYear(); if (currYear < 2000) currYear += 1900; //fixes for netscape normalizing to 1900 var currDateStr = currMonth + "/" + currDay + "/" + currYear; document.visitorForm.today.value=currDateStr; } function validEmail(emailinfo) { //From JavaScript for the World Wide Web 3rd Edition var emailadd=emailinfo.value; invalidChars = " /:,;"; if (emailadd.length == 0) { // cannot be empty return false; } for (i=0; i -1) { return false; } } atPos = emailadd.indexOf("@",1); // there must be one "@" symbol if (atPos == -1) { return false; } if (emailadd.indexOf("@",atPos+1) != -1) { // and only one "@" symbol return false; } periodPos = emailadd.indexOf(".",atPos); if (periodPos == -1) { // and at least one "." after the "@" return false; } if (periodPos+3 > emailadd.length) { // must be at least 2 characters after the "." return false; } return true } function isBlank(testStr){ // check for blank line or all spaces if (testStr.length == 0){ // Blank line with nothing entered? return true; } for (var i = 0; i <= testStr.length-1; i++){ // all spaces? if (testStr.charAt(i) != " "){ return false; } } return true; } function validateEmail(email){ //validate e-mail address if (!validEmail(email)){ alert('You must enter a valid e-mail address!'); // document.visitorForm.email.focus() return false; } return true; } function validateTextBox(str,fieldName){ //validate the field is neither empty nor all spaces if (isBlank(str.value)){ //If the field is blank select it again so user can fill in field alert('You must enter information into the ' + fieldName + ' field!'); return false; } return true; } function validateForm(thisForm) // validate Survey data { //Add person's fullname to the subject heading on form - reset to just visitor // research form so if the person goes back for a second look it doesn't add there // name multiple times to the subject heading document.visitorForm.subject.value="Visitor Research Form"; document.visitorForm.subject.value=document.visitorForm.subject.value + ": " + document.visitorForm.fullname.value; if (!validateTextBox(thisForm.fullname,"Full Name")){ // full name valid? document.visitorForm.fullname.focus(); return false; } if (!validateTextBox(thisForm.address,'Address')){ // Address entered? document.visitorForm.address.focus(); return false; } if (!validateEmail(thisForm.email)){ // email valid? document.visitorForm.email.focus(); return false; } if (!validateTextBox(thisForm.phone,'Telephone')){ // Telephone number entered? document.visitorForm.phone.focus(); return false; } if (!validateTextBox(thisForm.restitle,'Research Title')){ // Research title entered? document.visitorForm.restitle.focus(); return false; } return true; }