$.fn.formVal=function(newVal){var self=this.get(0);var optVal=function(opt){if(opt.value)return opt.value;if(!opt.outerHTML)return'';return /\svalue=""(?:\s|>)/.test(opt.outerHTML)?'':opt.text;};if(newVal==null){if(this.size()<1)return'';if(self.type=='text')return self.value;if(self.tagName=='TEXTAREA')return this.text();if(self.type=='checkbox'||self.type=='radio')
return this.filter('input:checked').val()||'';if(self.tagName=='OPTION')return this.parent().formVal();if(self.tagName=='SELECT'&&self.selectedIndex>=0)
return optVal(self.options[self.selectedIndex]);return'';}
if(self.type=='text')this.val(newVal);else if(self.tagName=='TEXTAREA')this.text(newVal);else if(self.type=='checkbox'||self.type=='radio'){this.filter(':checked').removeAttr('checked');this.filter('[@value='+newVal+']').attr('checked','checked');}
else if(self.tagName=='OPTION')this.parent().formVal(newVal);else if(self.tagName=='SELECT'){for(var i=0,l=self.options.length;i<l;++i){if(newVal==optVal(self.options[i])){self.selectedIndex=i;break;}}}
return this;};;var MrClay=window.MrClay||{};
/*
 * Simplified access to/manipulation of document.location.hash
 * 
 * Based on: http://adamv.com/dev/javascript/files/querystring.js
 * Design pattern: http://www.litotes.demon.co.uk/js_info/private_static.html#wConst
 */
MrClay.LocationHash=function(){var parse=function(str){var assignments=str.split('&'),obj={},propValue;for(var i=0,l=assignments.length;i<l;++i){propValue=assignments[i].split('=');if(propValue.length>2||-1!=propValue[0].indexOf('+')||propValue[0]==''){continue;}
if(propValue.length==1){propValue[1]=propValue[0];}
obj[unescape(propValue[0])]=unescape(propValue[1].replace(/\+/g,' '));}
return obj;};function construct_(spec){spec=spec||window;if(typeof spec=='object'){this.window=spec;spec=spec.location.hash.substr(1);}else{this.window=window;}
this.vars=parse(spec);}
construct_.reload=function(vars,window_){window_=window_||window;vars=vars||(new MrClay.LocationHash(window_)).vars;var l=window_.location,currUrl=l.href,s=MrClay.LocationHash.toString(vars),newUrl=l.protocol+'//'+l.hostname+l.pathname
+l.search+(s?'#'+s:'');if(currUrl==newUrl){l.reload();}else{l.assign(newUrl);}};construct_.get=function(key,default_,window_){window_=window_||window;return(new MrClay.LocationHash(window_)).get(key,default_);};construct_.set=function(key,value,window_){window_=window_||window;(new MrClay.LocationHash(window_)).set(key,value).reload();};construct_.toString=function(vars){var pieces=[];for(var prop in vars){pieces.push(escape(prop)+'='+escape(vars[prop]));}
return pieces.join('&');};construct_.prototype.reload=function(){MrClay.LocationHash.reload(this.vars,this.window);return this;};construct_.prototype.get=function(key,default_){if(typeof default_=='undefined'){default_=null;}
if(typeof key=='undefined'){return this.vars;}
return(this.vars[key]==null)?default_:this.vars[key];};construct_.prototype.set=function(key,value){var obj={};if(typeof key=='string'){obj[key]=value;}else{obj=key;}
for(var prop in obj){if(obj[prop]==null){delete this.vars[prop];}else{this.vars[prop]=obj[prop];}}
return this;};construct_.prototype.toString=function(){return MrClay.LocationHash.toString(this.vars);};return construct_;}();;jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+options.path:'';var domain=options.domain?'; domain='+options.domain:'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{if(document.cookie){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){return decodeURIComponent(cookie.substring(name.length+1));}}}
return null;}};;var $RG_presetRadios,RG_dateRadio,RG_today=new Date(),RG_radioGroupReportType,RG_radioGroupDateRange,RG_specDatesFaded=false,RG_doFades=!$.browser.safari;function RG_reportTypeChange(){var rt=RG_radioGroupReportType.getValue();if(rt=='monthly'){$('#fromDate_d, #toDate_d').formVal('1').hide();RG_dateRadio.checked=true;$RG_presetRadios.attr('disabled',true);RG_dateRadioChange();var range=RG_getDateRange();var lastMonth=RG_firstOfMonth(new Date(RG_firstOfMonth(RG_today)-7200000));if(range.to>lastMonth){RG_setDate('toDate',lastMonth);RG_fixDates(true);}}else{$('#fromDate_d, #toDate_d').show();$RG_presetRadios.attr('disabled',false);}
if(rt=='all'||rt=='hourly'){$('#vars__ET')[0].disabled=true;}else{$('#vars__ET')[0].disabled=false;}}
function RG_dateRadioChange(){if(RG_dateRadio.checked){if(RG_specDatesFaded){RG_doFades&&$('#set_specDates').fadeTo(100,1);RG_specDatesFaded=false;}
$('#set_specDates select').unbind('change',RG_chooseSpecifiedDates);}else{if(!RG_specDatesFaded){RG_doFades&&$('#set_specDates').fadeTo(100,0.5);RG_specDatesFaded=true;}
RG_setPresetRanges(RG_radioGroupDateRange.getValue());$('#set_specDates select').bind('change',RG_chooseSpecifiedDates);}}
function RG_chooseSpecifiedDates(){RG_radioGroupDateRange.setValue('dates');RG_doFades&&$('#set_specDates').fadeTo(100,1);RG_specDatesFaded=false;}
function RG_getDateRange(){var v={};$('#set_specDates select').each(function(){v[this.name]=$(this).formVal();});return{from:new Date(v.fromDate_y,v.fromDate_m-1,v.fromDate_d),to:new Date(v.toDate_y,v.toDate_m-1,v.toDate_d)};}
function RG_setDate(selectNamePrefix,dateObj){$('#'+selectNamePrefix+'_y').formVal(dateObj.getFullYear());$('#'+selectNamePrefix+'_m').formVal(dateObj.getMonth()+1);$('#'+selectNamePrefix+'_d').formVal(dateObj.getDate());}
function RG_firstOfMonth(dateObj){return new Date(dateObj.getFullYear(),dateObj.getMonth(),1);}
function RG_setPresetRanges(days){RG_setDate('fromDate',new Date(RG_today-(86400000*days)));RG_setDate('toDate',new Date(RG_today-86400000));}
function RG_fixDates(supressAlert){var range=RG_getDateRange();if(range.from>range.to){RG_setDate('fromDate',range.to);if(!supressAlert){alert('The From: date was later than the To: date\nFrom: was altered'
+' to match the To: date.\nPlease verify the dates are as you'
+' desire before submitting.');return false;}}
return true;}
function RG_wetBulbRequirementChange(){var wb=$('#vars__WetBulb')[0];if(!this.checked&&wb.checked){wb.checked=false;alert('WetBulb Temp cannot be calculated without Temp (2m) and Dewpoint (2m).');}
wb=null;}
function RG_init(){RG_dateRadio=$('#set_presetRanges input[@value=dates]')[0];$RG_presetRadios=$('#set_presetRanges input[@name=presetRange]').not(RG_dateRadio);RG_radioGroupReportType=Fawn.extendRadioGroup($('#reportGeneratorForm')[0].reportType,RG_reportTypeChange);RG_radioGroupDateRange=Fawn.extendRadioGroup($('#reportGeneratorForm')[0].presetRange,RG_dateRadioChange);$('#reportGeneratorForm').submit(function(){if($.browser.safari){this.action+=(new Date()).getTime();}
$('em.error').hide();$.cookie('rgSettings',RG_formToString(),{path:'/data/reports/',expires:365});return RG_fixDates();});Fawn.checkboxOnchange($('#vars__WetBulb')[0],function(){if(this.checked){$('#vars__AirTemp9, #vars__DewPoint').attr('checked',true);}});Fawn.checkboxOnchange($('#vars__AirTemp9')[0],RG_wetBulbRequirementChange);Fawn.checkboxOnchange($('#vars__DewPoint')[0],RG_wetBulbRequirementChange);RG_reportTypeChange();RG_dateRadioChange();$('input[type=radio]').each(function(){if(!this.id){this.id=this.name+'__'+this.value;}});var el,i=0,els=$('#set_Measurements input').get();while(el=els[i++]){if(el.checked){return;}}
if(document.location.hash.indexOf('vars=')!=-1){RG_stringToForm(document.location.hash.substring(1));}else{var c=$.cookie('rgSettings');if(c){RG_stringToForm(c);}}}
function RG_formToString(){var locs=[],vars=[];$('#set_Locations input').each(function(){this.checked&&locs.push(this.id.split('__')[1]);});$('#set_Measurements input').each(function(){this.checked&&vars.push(this.id.split('__')[1]);});var type=RG_radioGroupReportType.getValue(),date=RG_radioGroupDateRange.getValue(),range=RG_getDateRange();var h='locs='+locs.join(',')
+'&vars='+vars.join(',')
+'&date='+date;if(type!=='daily'){h+='&type='+type;}
if(date==='dates'){h+='&from='+(new String(range.from.getTime())).replace(/000$/,'')
+'&to='+(new String(range.to.getTime())).replace(/000$/,'');}
return h;}
function RG_createLink(){var h='#'+RG_formToString();$('#selfLink div').html('<p>Link: <a href="'+h.replace(/&/,'&amp;')
+'">My Custom FAWN Report</a> (right-click to add to your favorites/bookmarks)</p><p>URL: '
+'<input type="text" value="" style="width:50%" readonly="readonly" />'
+' (e.g. for copying into e-mail)</p>');$('#selfLink input').val($('#selfLink a')[0].href).focus(function(){this.select();}).click(function(){this.select();});}
function RG_stringToForm(str){var checkIds=[];var h=(new MrClay.LocationHash(str)).get();h.vars&&$.each(h.vars.split(','),function(){checkIds.push('vars__'+this);});h.locs&&$.each(h.locs.split(','),function(){checkIds.push('locs__'+this);});h.type&&(checkIds.push('reportType__'+h.type));h.date&&(checkIds.push('presetRange__'+h.date));$.each(checkIds,function(){$('#'+this).attr({checked:true});});RG_reportTypeChange();RG_dateRadioChange();h.from&&RG_setDate('fromDate',new Date(parseInt(h.from+'000')));h.to&&RG_setDate('toDate',new Date(parseInt(h.to+'000')));}
$(function(){if(/*@cc_on!@*/false){setTimeout(RG_init,1);}else{RG_init();}});