/*PP-LOGIC-START*/ var PPB64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; function ppB64v(s){ var a=PPB64.indexOf(s.charAt(0)); var b=PPB64.indexOf(s.charAt(1)); if(a<0){a=0;} if(b<0){b=0;} return a*64+b; } var PPCUM=[0,31,59,90,120,151,181,212,243,273,304,334]; var PPMON=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; function ppNum(v){ if(v===null){return null;} if(v===undefined){return null;} var n=Number(v); if(isNaN(n)){return null;} return n; } function ppDoy(m,d){ m=ppNum(m); d=ppNum(d); if(m===null){return null;} if(d===null){return null;} if(m<1){return null;} if(m>12){return null;} if(d<1){return null;} if(d>31){return null;} return PPCUM[m-1]+d; } function ppFmtDoy(d){ var tag=""; while(d>365){d=d-365;tag=" (next year)";} while(d<1){d=d+365;tag=" (earlier in the year)";} var m=0; while(m<11){if(d>PPCUM[m+1]){m=m+1;}else{break;}} return PPMON[m]+" "+(d-PPCUM[m])+tag; } function ppValidZip(z){ if(typeof z!=="string"){return false;} if(z.length!==5){return false;} return /^[0-9]{5}$/.test(z); } function ppZipMap(){ if(typeof FROSTZIP==="undefined"){return null;} var s=FROSTZIP; var map={}; var n=s.length-(s.length%9); var i,z; for(i=0;i=FROSTCITIES.length){return null;} return FROSTCITIES[i]; } function ppFrostInfo(zip,map,cityIdx){ var e=null; var c=null; if(cityIdx===null){cityIdx=undefined;} if(cityIdx===undefined){ if(map===null){return {missing:true};} e=map[zip]; if(!e){return {missing:true};} c=ppCity(e.city); }else{ c=ppCity(cityIdx); } if(c===null){return {missing:true};} var last=ppDoy(c[2],c[3]); var first=ppDoy(c[4],c[5]); var ff=false; if(last===null){if(first===null){ff=true;}} var dist=null; if(e!==null){dist=e.dist;} return {missing:false,name:String(c[1]),zone:String(c[6]),dist:dist,lastDoy:last,firstDoy:first,frostFree:ff}; } function ppCrop(r){ return {key:String(r[0]),name:String(r[1]),type:String(r[2]),season:String(r[3]), dtmMin:ppNum(r[6]),dtmMax:ppNum(r[7]),sun:String(r[8]),difficulty:String(r[9]), startInWks:ppNum(r[12]),fallOk:!!r[13],frostTol:String(r[14])}; } function ppCrops(){ if(typeof CROPS==="undefined"){return null;} var out=[]; var i; for(i=0;i=need+14){return {kind:"plenty",need:need,left:left};} if(left>=need){return {kind:"tight",need:need,left:left};} return {kind:"late",need:need,left:left}; } function ppSuggestFall(crops,left,excludeKey){ var out=[]; var i,c,need; for(i=0;i=3){break;}names.push(out[j].crop.name);} return names; } function ppSeason(lastDoy,firstDoy){ if(lastDoy===null){if(firstDoy===null){return {frostFree:true};}} if(lastDoy===null){return {unknown:true};} if(firstDoy===null){return {unknown:true};} var days=firstDoy-lastDoy; if(days<0){return {unknown:true};} return {frostFree:false,days:days}; } function ppBand(days){ if(days<120){return "short";} if(days<=180){return "mid";} return "long"; } function ppTodayDoy(){ var n=new Date(); return PPCUM[n.getMonth()]+n.getDate(); } function ppEsc(s){ s=String(s); s=s.replace(/&/g,"&"); s=s.replace(//g,">"); s=s.replace(/"/g,"""); return s; } if(typeof module!=="undefined"){if(module.exports){ module.exports={b64v:ppB64v,doy:ppDoy,fmtDoy:ppFmtDoy,validZip:ppValidZip,zipMap:ppZipMap, city:ppCity,frostInfo:ppFrostInfo,crop:ppCrop,crops:ppCrops,transplantCrops:ppTransplantCrops, transplantWindow:ppTransplantWindow,need:ppNeed,lastChance:ppLastChance,suggestFall:ppSuggestFall, season:ppSeason,band:ppBand,todayDoy:ppTodayDoy,esc:ppEsc}; }} /*PP-LOGIC-END*/