/* $Id: search.js,v 1.3 2010/03/12 18:22:31 tako Exp $ */
var advancedOpen=false,slideInUse=[]; window.onload=function(){if(document.getElementById("fromDate"))document.getElementById("fromDate").value=getTodaysDate();if(parent.location.search.substring(1)){doAutoQuery();parent.results.focus()}else document.getElementById("q").focus();document.getElementById("searchForm").onsubmit=function(){if(document.getElementById("q").value.trim()!=""||mode==searchEvents){if(mode==searchEvents){document.getElementById("keyword").value=document.getElementById("q").value;var a=document.getElementById("eventSearch"); a=a.elements;var d=a.length,b=[];otherParams="";for(var c=0;c<d;c++)if(a[c].type=="select-one"){b[a[c].id]=a[c].options[a[c].selectedIndex].value;b[a[c].id+"Index"]=a[c].selectedIndex}else b[a[c].id]=a[c].value;for(var e in b)otherParams+="&"+e+"="+b[e]}else if(mode==searchWeb){document.getElementById("qString").value=document.getElementById("q").value;if(getCheckedValue(document.forms.searchForm.as_sitesearch)&&document.getElementById("qString").value.indexOf("site:")!=-1)otherParams+="&site="+getCheckedValue(document.forms.searchForm.as_sitesearch)}else if(mode== searchOrganizations){document.getElementById("unitName").value=document.getElementById("q").value;a=document.getElementById("orgSearch");a=a.elements;d=a.length;b=[];otherParams="";for(c=0;c<d;c++)if(a[c].type=="select-one"){b[a[c].id]=a[c].options[a[c].selectedIndex].value;b[a[c].id+"Index"]=a[c].selectedIndex}else b[a[c].id]=a[c].value;for(e in b)otherParams+="&"+e+"="+b[e]}if(advancedOpen==true)otherParams+="&advancedOpen=true";parent.location.href=parent.location.protocol+"//"+parent.location.host+ parent.location.pathname+"?q="+encodeURIComponent(document.getElementById("q").value.trim())+otherParams}else return false;return false};document.getElementById("modes").onclick=function(a){a=a||window.event;a=a.target||a.srcElement;if(document.getElementById("q").value.trim()==="")return true;else a.href=a.href+"?q="+encodeURIComponent(document.getElementById("q").value.replace(/(^| )site:[\w*|.|-]*( |$)/gi,"").trim());return true}};function stopErrors(){return true} function doAutoQuery(){setInputValue(getURLParam());typeof mode=="function"?mode():alert('JavaScript function "'+mode+'" could not be found. No attempt was made to call the function.')} function setInputValue(a){for(var d=a.split("&"),b=0;b<d.length;b++){var c=d[b].split("="),e=decodeURIComponent(c[0]);c=decodeURIComponent(c[1].replace(/\+/," "));if(e.indexOf("Index")!=-1){var g=e.indexOf("Index");e=e.substring(0,g);document.getElementById(e).selectedIndex=c}else if(e=="advancedOpen"){if(c=="true"){if(mode==searchEvents)toggleAdvancedSearch("frameset1",{duration:1,height:165},{duration:1});else if(mode==searchOrganizations||mode==searchWeb)toggleAdvancedSearch("frameset1",{duration:1, height:120},{duration:1});document.getElementById("advanced-link").innerHTML="Hide Options"}}else if(e=="site"&&a.indexOf("site:")!=-1)setCheckedValue(document.getElementById("searchForm").elements.as_sitesearch,c);else if(document.getElementById(e)!=undefined)document.getElementById(e).value=c}return false}function getURLParam(){var a=parent.location.search.substring(1);if(a)return a;return""} function searchWeb(){document.getElementById("cse-search-box").q.value=document.getElementById("searchForm").q.value;document.getElementById("cse-search-box").submit()} function searchPeople(){var a=document.getElementById("q").value.trim();a=a.replace(/\*/gi,"%");var d=a.split(","),b;if(d.length==2){a=d[0].trim();b=d[1].trim()}else{d=a.split(/\s+/g);if(d.length==2){b=d[0].trim();a=d[1].trim()}else if(d.length>2){b=d[0].trim();a=a.substring(d[0].length+1)}else{b="";a=a}}document.getElementById("lastName").value=a;document.getElementById("firstName").value=b;document.getElementById("searchPeople").submit();return false} function searchBuildings(){document.getElementById("qString").value=document.getElementById("searchForm").q.value;document.getElementById("buildingSearch").submit();return false}function searchEvents(){document.getElementById("keyword").value=document.getElementById("q").value.trim();document.getElementById("eventSearch").submit();return false} function searchOrganizations(){document.getElementById("orgSearch").unitName.value=document.getElementById("searchForm").q.value;document.getElementById("orgSearch").submit();return false}function getTodaysDate(){var a=new Date,d=a.getMonth()+1,b=(a.getDate()<10?"0":"")+a.getDate();a=a.getFullYear();return d+"/"+b+"/"+a}String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}; function getCheckedValue(a){if(!a)return"";var d=a.length;if(d==undefined)return a.checked?a.value:"";for(var b=0;b<d;b++)if(a[b].checked)return a[b].value;return""}function setCheckedValue(a,d){if(a){var b=a.length;if(b==undefined)a.checked=a.value==d.toString();else for(var c=0;c<b;c++){a[c].checked=false;if(a[c].value==d.toString())a[c].checked=true}}} function toggleAdvancedSearch(a,d,b){if(advancedOpen==false){advancedOpen=true;Slide(a,d).expand()}else{advancedOpen=false;Slide(a,b).collapse()}} function Slide(a,d){slideInUse[a]=false;this.obj=parent.document.getElementById(a);this.duration=1;this.height=parseInt(this.obj.rows.split(",")[0]);this.options=typeof d!="undefined"?d:{};if(this.options.duration)this.duration=this.options.duration;if(this.options.height)this.height=this.options.height;this.collapse=function(){this.curHeight=this.height;this.newHeight="75";slideInUse[a]!=true&&this.slide()};this.expand=function(){this.curHeight=parent.document.getElementById(a).rows.split(",")[0]; this.newHeight=this.height;slideInUse[a]!=true&&this.slide()};this.slide=function(){slideInUse[a]=true;var b=30*duration,c=duration*1E3/b;c=Math.round(c);for(var e=(this.curHeight-this.newHeight)/b,g=[],f=0;f<b;f++)g[f]=f<b/2?e*(f/b)*4:e*(1-f/b)*4;for(f=0;f<b;f++){this.curHeight-=g[f];window.setTimeout("parent.document.getElementById('"+a+"').rows='"+Math.round(this.curHeight)+",*';",c*f)}window.setTimeout("delete(slideInUse['"+a+"']);",c*f);this.options.onComplete&&window.setTimeout(this.options.onComplete, c*(f-2));return c*f};this.finishup=function(b){this.obj.rows=b+",*"};return this}; 
