
/* - ag_common.js - */
// http://creamery.psu.edu/portal_javascripts/ag_common.js?original=1
function resizeColumns(){setTimeout("doresizeColumns()",300)}
function doresizeColumns(){var bodyClass=document.body.className;var contentWrapper=document.getElementById("portal-column-content");var centerColumn=document.getElementById("centercolumn");var personalTools=document.getElementById("portal-personaltools");if(!personalTools&&bodyClass.match(/template-document_homepage_view/)&&contentWrapper&&centerColumn&&(msieversion()>=8||msieversion()==0)){centerColumn.style.height="auto";iHeight=centerColumn.offsetHeight;failsafe=0;while(failsafe<500&&(centerColumn.offsetTop+centerColumn.offsetHeight)<(contentWrapper.offsetTop+contentWrapper.offsetHeight-3)){iHeight++;failsafe++;centerColumn.style.height=iHeight+"px"}}}
function msieversion(){var ua=window.navigator.userAgent
var msie=ua.indexOf("MSIE ")
if(msie>0)
return parseInt(ua.substring(msie+5,ua.indexOf(".",msie)))
else
return 0}
function getElement(theId,vPadding,IEvPadding){var theElement=document.getElementById(theId)?document.getElementById(theId):document.createElement("div");theElement.elementHeight=theElement.offsetHeight?theElement.offsetHeight:theElement.pixelHeight;theElement.style.height="auto";if(!vPadding){vPadding=0}
if(document.all&&IEvPadding){theElement.vPadding=IEvPadding}
else{theElement.vPadding=vPadding}
return theElement}
function setSearch(){var theSearchButton=document.getElementById("goSearch");var theSearchDropdown=document.getElementById("searchSource");var thePloneSearchForm=document.getElementById("plonesearchform");if(theSearchButton&&theSearchDropdown&&thePloneSearchForm){theSearchDropdown.style.display="inline";theSearchButton.onclick=function(){return searchOnSubmit()}
thePloneSearchForm.onsubmit=function(){return searchOnSubmit()}}}
function searchOnSubmit(){var theSearchDropdown=document.getElementById("searchSource");var theSearchForm=document.getElementById("GoogleSearch");var theSearchBox=document.getElementById("SearchableText");var theCustomSearchBox=document.getElementById("GoogleCustomSearch");var currentfolderCheckbox=document.getElementById("searchbox_currentfolder_only");if(theSearchDropdown&&theSearchForm&&theSearchBox&&theCustomSearchBox&&currentfolderCheckbox){var theSearchOption=theSearchDropdown.options[theSearchDropdown.selectedIndex].value;if(theSearchOption=="section"){currentfolderCheckbox.checked=true;return true}
else if(theSearchOption=="college"){theCustomSearchBox.q.value=theSearchBox.value;theCustomSearchBox.submit();return false}
else if(theSearchOption=="psu"){theSearchForm.q.value=theSearchBox.value;theSearchForm.submit();return false}
else{currentfolderCheckbox.checked=false;return true}}}
registerPloneFunction(setSearch);registerPloneFunction(resizeColumns);jq(document).ready( function(){var mobileRegex=/(iphone|ipod|android|blackberry|symbian|midp|windows ce|treo|webos|mobile safari)/;var userAgent=navigator.userAgent.toLowerCase();if(mobileRegex.test(userAgent)){jq("#visual-portal-wrapper").prepend(jq('<div id="mobile-version"><a href="m">Mobile Version</a></div>'))}});jq(document).ready( function(){if(jq("#archetypes-fieldname-id input").val()){jq("#archetypes-fieldname-id").show()}
else{jq("body.template-atct_edit #archetypes-fieldname-title label.formQuestion").dblclick(function(){if(confirm("Only set the short name if you absolutely have to.")){jq("body.template-atct_edit #archetypes-fieldname-id").show()}})}});jq(document).ready(
function(){jq('body.custom-semicolon-delimited #content .description, body.custom-semicolon-delimited #content .documentDescription #parent-fieldname-description, body.custom-semicolon-delimited #content #parent-fieldname-description .documentDescription').each(
function(){var lines=this.innerHTML.split(";");var new_html="<ul>";for(var i=0;i<lines.length;i++){var line_text=lines[i];if(line_text.match(":")){list=line_text.split(":");line_text="<strong>"+list[0]+":</strong>"+list[1]}
new_html=new_html+"<li>"+line_text+"</li>"}
new_html=new_html+"</ul>";this.innerHTML=new_html})})
jq(document).ready(
function(){isTwoColumn=jq('body.custom-two-column').length;if(isTwoColumn){summary_items=jq('body.custom-two-column #content>div>.tileItem');insert_after=jq('body.custom-two-column #content>div>.tileItem:last');if(summary_items.length==0){summary_items=jq('body.custom-two-column #content>div>.tileItem');insert_after=jq('body.custom-two-column #content>div>.tileItem:last')}
listing_items=jq('body.custom-two-column #content .tileTitle');if(summary_items.length>=1){first_column_items=Math.ceil(summary_items.length/2)
two_column_left=jq('<div id="two-column-left"></div>');two_column_right=jq('<div id="two-column-right"></div>');insert_after.after('<div class="visualClear">&nbsp;</div>');insert_after.after(two_column_right);insert_after.after(two_column_left);item_count=0;summary_items.each(
function(){item_count++;if(item_count<=first_column_items){two_column_left.append(this)}
else{two_column_right.append(this)}})}
else if(listing_items.length>=1){first_column_items=Math.ceil(listing_items.length/2)
two_column_left=jq('<dl id="two-column-left"></dl>');two_column_right=jq('<dl id="two-column-right"></dl>');theList=jq('body.custom-two-column #content dl:not(#history)');theList.before(two_column_left);theList.before(two_column_right);theList.before('<div class="visualClear">&nbsp;</div>');item_count=0;jq('body.custom-two-column #content .tileTitle').each(
function(){if(this.nodeName=='H3'){item_count++}
if(item_count<=first_column_items){two_column_left.append(this)}
else{two_column_right.append(this)}})}}})
function getEventDate(dateType){if(dateType=="startDate"){dateType+="_0"} else if(dateType=="endDate"){dateType+="_1"} else{dateType=""}
if(dateType!=""){year=jq("#edit_form_"+dateType+"_year").val();month=jq("#edit_form_"+dateType+"_month").val();day=jq("#edit_form_"+dateType+"_day").val();hour=jq("#edit_form_"+dateType+"_hour").val();minute=jq("#edit_form_"+dateType+"_minute").val();ampm=jq("#edit_form_"+dateType+"_ampm").val();if(hour==12&&ampm=="AM"){hour=0} else if(hour<12&&ampm=="PM"){hour=parseInt(hour)+12}
return new Date(year,month-1,day,hour,minute,0,0)} else{return ""}}
function setEventDate(dateType,dateObj){if(dateType=="startDate"){dateType+="_0"} else if(dateType=="endDate"){dateType+="_1"} else{dateType=""}
if(dateType!=""){jq("#edit_form_"+dateType+"_year").val(dateObj.getFullYear());jq("#edit_form_"+dateType+"_month").val(formatNumberForSelectBox(dateObj.getMonth()+1));jq("#edit_form_"+dateType+"_day").val(formatNumberForSelectBox(dateObj.getDate()));jq("#edit_form_"+dateType+"_minute").val(formatNumberForSelectBox(dateObj.getMinutes()));var hours=dateObj.getHours();if(hours==0){jq("#edit_form_"+dateType+"_hour").val("12");jq("#edit_form_"+dateType+"_ampm").val("AM")} else if(hours==12){jq("#edit_form_"+dateType+"_hour").val("12");jq("#edit_form_"+dateType+"_ampm").val("PM")} else if(hours>12){jq("#edit_form_"+dateType+"_hour").val(formatNumberForSelectBox(hours-12));jq("#edit_form_"+dateType+"_ampm").val("PM")} else{jq("#edit_form_"+dateType+"_hour").val(formatNumberForSelectBox(hours));jq("#edit_form_"+dateType+"_ampm").val("AM")}}}
function formatNumberForSelectBox(aNumber){if(aNumber<10){aNumber="0"+aNumber}
return aNumber}
function roundUpDateToNearestHour(dateObj){if(dateObj.getMinutes()!=0){dateObj.setMinutes(0);dateObj.setTime(dateObj.getTime()+(60*60*1000))}
return dateObj}
function onStartDateChange(){if(okToChangeEventEndDate){var currentEndDate=getEventDate("endDate");if(eventOriginalEndDate.getTime()==currentEndDate.getTime()){currentEndDate.setTime(getEventDate("startDate").getTime()+(60*60*1000));setEventDate("endDate",currentEndDate);eventOriginalEndDate=currentEndDate} else{okToChangeEventEndDate=false}}}
var okToChangeEventEndDate=false;var eventOriginalEndDate=new Date();jq(document).ready(
function(){if(jq("#archetypes-fieldname-id input").val()){return false}
var eventStartDate=getEventDate("startDate");if(eventStartDate.getTime()==getEventDate("endDate").getTime()){if(eventStartDate.getHours()==0&&eventStartDate.getMinutes()==0){return false}
okToChangeEventEndDate=true;eventStartDate=roundUpDateToNearestHour(eventStartDate);setEventDate("startDate",eventStartDate);eventOriginalEndDate.setTime(eventStartDate.getTime()+(60*60*1000));setEventDate("endDate",eventOriginalEndDate);jq("#edit_form_startDate_0_year").change( function(){onStartDateChange()});jq("#edit_form_startDate_0_month").change( function(){onStartDateChange()});jq("#edit_form_startDate_0_day").change( function(){onStartDateChange()});jq("#edit_form_startDate_0_hour").change( function(){onStartDateChange()});jq("#edit_form_startDate_0_minute").change( function(){onStartDateChange()});jq("#edit_form_startDate_0_ampm").change( function(){onStartDateChange()})}});jq(document).ready(
function(){isFactSheet=jq('body.template-factsheet_view').length;if(isFactSheet){var browser_mozilla=jq.browser.mozilla;var browser_version=jq.browser.version.split('.',1);if(browser_mozilla&&browser_version>=4){var two_column=jq('body.template-factsheet_view .addthis_toolbox .two_column_print');two_column.show();two_column.click(function(){alert("This is an experimental feature for printing factsheets in two columns that is only available in Firefox 4 and above. If it doesn't print well, just click on the printer icon to print in a single column.\n\nRecommended settings:\n\n  * Check 'Ignore Scaling and Shrink To Fit Page Width' in 'Print' Dialog.\n  * Go to about:config and set print.print_margin_* to 0.25.");jq('body').addClass('two_column_print');window.print();jq('body').removeClass('two_column_print')})}}});jq(document).ready(
function(){jq('body.portaltype-formsavedataadapter #content form input[name="clearSavedFormInput"]').parent().submit(
function(event){return confirm('Are you sure you want to clear the saved data?')})});

