// seedcalc.js - last modified: November 20 2009 12:09:09.


(function($)
{$.fn.jqm=function(o)
{var _o={zIndex:3000,overlay:50,overlayClass:'jqmOverlay',closeClass:'jqmClose',trigger:'.jqModal',ajax:false,target:false,modal:false,toTop:false,onShow:false,onHide:false,onLoad:false};return this.each(function()
{if(this._jqm)return;s++;this._jqm=s;H[s]={c:$.extend(_o,o),a:false,w:$(this).addClass('jqmID'+s),s:s};if(_o.trigger)$(this).jqmAddTrigger(_o.trigger);});};$.fn.jqmAddClose=function(e){hs(this,e,'jqmHide');return this;};$.fn.jqmAddTrigger=function(e){hs(this,e,'jqmShow');return this;};$.fn.jqmShow=function(t){return this.each(function(){if(!H[this._jqm].a)$.jqm.open(this._jqm,t)});};$.fn.jqmHide=function(t){return this.each(function(){if(H[this._jqm].a)$.jqm.close(this._jqm,t)});};$.jqm={hash:{},open:function(s,t)
{var h=H[s],c=h.c,cc='.'+c.closeClass,z=(/^\d+$/.test(h.w.css('z-index')))?h.w.css('z-index'):c.zIndex,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});h.t=t;h.a=true;h.w.css('z-index',z);if(c.modal)
{if(!A[0])
F('bind');A.push(s);o.css('cursor','wait');}
else if(c.overlay>0)
h.w.jqmAddClose(o);else o=false;h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):false;if(ie6)
{$('html,body').css({height:'100%',width:'100%'});if(o)
{o=o.css({position:'absolute'})[0];for(var y in{Top:1,Left:1})
o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}
if(c.ajax)
{var r=c.target||h.w,u=c.ajax,r=(typeof r=='string')?$(r,h.w):$(r),u=(u.substr(0,1)=='@')?$(t).attr(u.substring(1)):u;r.load(u,function()
{if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
else if(cc)
h.w.jqmAddClose($(cc,h.w));if(c.toTop&&h.o)
h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);(c.onShow)?c.onShow(h):h.w.show();e(h);return false;},close:function(s)
{var h=H[s];h.a=false;if(A[0]){A.pop();if(!A[0])F('unbind');}
if(h.c.toTop&&h.o)
$('#jqmP'+h.w[0]._jqm).after(h.w).remove();if(h.c.onHide)
h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();}
return false;}};var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version=="6.0"),i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i);f(h);},f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(e){}},F=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return!r;},hs=function(w,e,y)
{var s=[];w.each(function(){s.push(this._jqm)});$(e).each(function()
{if(this[y])
$.extend(this[y],s);else
{this[y]=s;$(this).click(function()
{for(var i in{jqmShow:1,jqmHide:1})
for(var s in this[i])
if(H[this[i][s]])
H[this[i][s]].w[i](this);return false;});}});};})(jQuery);(function($)
{$.fn.jqDrag=function(h){return i(this,h,'d');};$.fn.jqResize=function(h){return i(this,h,'r');};$.jqDnR={dnr:{},e:0,drag:function(v)
{if(M.k=='d')
E.css({left:M.X+v.pageX-M.pX,top:M.Y+v.pageY-M.pY});else
E.css({width:Math.max(v.pageX-M.pX+M.W,0),height:Math.max(v.pageY-M.pY+M.H,0)});return false;},stop:function()
{E.css('opacity',M.o);$().unbind('mousemove',J.drag).unbind('mouseup',J.stop);}};var J=$.jqDnR,M=J.dnr,E=J.e,i=function(e,h,k)
{return e.each(function()
{h=(h)?$(h,e):e;h.bind('mousedown',{e:e,k:k},function(v)
{var d=v.data,p={};E=d.e;if(E.css('position')!='relative')
try{E.position(p);}catch(e){}
M={X:p.left||f('left')||0,Y:p.top||f('top')||0,W:f('width')||E[0].scrollWidth||0,H:f('height')||E[0].scrollHeight||0,pX:v.pageX,pY:v.pageY,k:d.k,o:E.css('opacity')};E.css({opacity:0.8});$().mousemove($.jqDnR.drag).mouseup($.jqDnR.stop);return false;});});},f=function(k){return parseInt(E.css(k))||false;};})(jQuery);(function($)
{var timers={};$.delayCallOnce=function(name,delay,func)
{if(timers[name])
clearTimeout(timers[name]);timers[name]=setTimeout(function(){delete timers[name];func();},delay)};var SeedCalc=function(options)
{this.seedtypes={bent_col:{name:'Bentgrass, Colonial',min:500,max:1000},bent_creep_penn:{name:'Bentgrass, Creeping',min:500,max:1000},blue_creep:{name:'Bluegrass, Creeping',min:350,max:500},blue_kent:{name:'Bluegrass, Kentucky',min:350,max:500},blue_rough:{name:'Bluegrass, Rough',min:350,max:500},enviro:{name:'Envirolawn',min:750},fescue_fine:{name:'Fescue, Fine',min:150,max:200},fescue_tall:{name:'Fescue, Turf Type Tall',min:100,max:125},mix_fescue_kent:{name:'Mixtures, Turf Type Fescue & Kentucky Bluegrass',min:175,max:200},mix_fescue_rye:{name:'Mixtures, Ryegrass & Fine Fescue',min:125,max:175},mix_fescue_blue:{name:'Mixtures, Ryegrass, Bluegrass, & Fine Fescue',min:175,max:250},mix_rough_sup:{name:'Mixtures, Rough Bluegrass & Supina Bluegrass',min:350,max:500},mix_rye_peren:{name:'Ryegrass, Perennial',min:100,max:140},poa_supina:{name:'Poa Supina',min:350,max:500},bahia:{name:'Bahia',min:175,max:200},bermuda:{name:'Bermuda',min:350,max:500},blue_grama:{name:'Blue Grama',min:350,max:500},buffalo:{name:'Buffalo',min:350,max:500},carpet:{name:'Carpet',min:200,max:250},centipede:{name:'Centipede - Coated',min:1000,max:2000},seashore:{name:'Seashore Paspalum',min:1000},zoysia:{name:'Zoysia',min:500,max:1000},combat_cold:{name:'Combat Extreme&trade; Cold Climate',min:100,max:125}};var cookie=$.cookie('SeedCalc'),container,self=this,init=false,active=false,seedtp=null,typedisp,coveragedisp,area,result,qc,ac,current_calc;var opts=$.extend({dialog:true},options);if(cookie)
self.archived=JSON.parse(cookie);self.display=function(typename,desc,elem)
{if(!init)return;seedtp=this.seedtypes[typename];if(desc)seedtp.name=desc;typedisp.html(seedtp.name);coveragedisp.text((seedtp['min']?seedtp.min+' - '+seedtp.max:seedtp.min)+' sq. ft.');if(opts.dialog)
{if(!active&&elem)
{var el=$(elem),pos=el.position();container.css({position:'absolute',left:pos.left+el.width()+6,top:pos.top-6});}
container.jqmShow();}
active=true;current_calc.update();};self.calc=function(sqft)
{if(!active)return;area.text((isNaN(sqft)?0:sqft.toFixed(0))+' sq. ft.');var res=sqft/seedtp.min;if(isNaN(res)||res==0)
return result.text('0 lbs.');if(!seedtp['max'])
return result.text(res.toFixed(2)+' lbs.');var res2=sqft/seedtp.max;result.text(res2.toFixed(2)+' - '+res.toFixed(2)+' lbs.');$.delayCallOnce('SeedCalc_save',3000,self.save);};self.save=function()
{var o={current:current_calc.name};qc.collect(o);ac.collect(o);$.cookie('SeedCalc',JSON.stringify(o));};var activateQuick=function()
{ac.hide();qc.show();$('#qc_tab').addClass('on').removeClass('off');$('#ac_tab').addClass('off').removeClass('on');qc.update();current_calc=qc;return false;};var activateAdv=function()
{qc.hide();ac.show();$('#ac_tab').addClass('on').removeClass('off');$('#qc_tab').addClass('off').removeClass('on');ac.update();current_calc=ac;return false;};self.init=function()
{if(init)return;container=$('#calc');typedisp=container.find('#qc_type');coveragedisp=container.find('#qc_perlbs');area=$('#sc_area');result=$('#sc_result');qc=new QuickSeedCalculator(self);ac=new AdvancedSeedCalculator(self);if(self.archived&&self.archived['current'])
{if(qc.name==self.archived['current'])
activateQuick();else activateAdv();}
else activateQuick();$('#qc_tab').click(activateQuick);$('#ac_tab').click(activateAdv);if(opts.dialog)
container.jqm({closeClass:'close',overlay:0,onHide:function(h){active=false;h.w.hide();}}).jqDrag('.dragbar');init=true;};$(document).ready(function(){self.init();});};var QuickSeedCalculator=function(parent)
{this.name='QuickSeedCalculator';container=$('#qc_container');var self=this,unitsel=container.find('#qc_units').change(function(){self.update();}),unitforms={lw:container.find('#qc_lw'),sf:container.find('#qc_sf'),ac:container.find('#qc_ac')},uinp={l:container.find('#qc_leni').keyup(function(){self.calc();}),w:container.find('#qc_widi').keyup(function(){self.calc();}),s:container.find('#qc_sfi').keyup(function(){self.calc();}),a:container.find('#qc_aci').keyup(function(){self.calc();})},acrecnv=43560,units;self.update=function()
{units=unitsel.val();for(i in unitforms)
unitforms[i].hide();unitforms[units].show();self.calc();};self.calc=function()
{var sqft=0;switch(units)
{case'lw':sqft=parseInt(uinp.l.val())*parseInt(uinp.w.val());break;case'sf':sqft=parseInt(uinp.s.val());break;case'ac':sqft=parseFloat(uinp.a.val())*acrecnv;break;}
parent.calc(sqft);};self.collect=function(obj)
{$.extend(obj,{QuickSeedCalculator:{l:uinp.l.val(),w:uinp.w.val(),s:uinp.s.val(),a:uinp.a.val()}});};self.restore=function()
{if(!parent.archived||!parent.archived[self.name])return;var o=parent.archived[self.name];uinp.l.val(o.l);uinp.w.val(o.w);uinp.s.val(o.s);uinp.a.val(o.a);}
self.show=function(){container.show();$('#qc_text').show();};self.hide=function(){container.hide();$('#qc_text').hide();};self.restore();self.update();};var AdvancedSeedCalculator=function(parent,container)
{this.name='AdvancedSeedCalculator';container=$('#ac_container');var self=this;var aidx=0,areas={},voids={},areas_ctr=$('#ac_areas'),voids_ctr=$('#ac_voids'),tpl=container.find('tr.area_row').remove();tpl.find('input[type!=button]').val('');areas_ctr.find('input[name=add_area]').click(function(){new self.Area(self,areas,areas_ctr);});voids_ctr.find('input[name=add_void]').click(function(){new self.Area(self,voids,voids_ctr);});self.Area=function(parent,collection,container)
{var self=this;var o=tpl.clone(),l=o.find('input[name=l]').keyup(function(){parent.update();}),w=o.find('input[name=w]').keyup(function(){parent.update();}),col=collection,ctr=container,idx=aidx++;ctr.append(o);ctr.find('tr.empty_area_row').hide();col[idx]=this;o.find('input[name=remove]').click(function(){self.remove();parent.update();});this.area=function(){var v=parseInt(l.val())*parseInt(w.val());return isNaN(v)?0:v;};this.save=function(){return{l:l.val(),w:w.val()};};this.restore=function(obj){l.val(obj.l);w.val(obj.w);};this.remove=function()
{o.remove();delete col[idx];var c=0;for(var i in col)c++;if(c==0)
ctr.find('tr.empty_area_row').show();};};self.update=function()
{var sqft=0;for(var i in areas)
sqft+=areas[i].area();for(var i in voids)
sqft-=voids[i].area();if(sqft<0)
sqft=0;parent.calc(sqft);};self.collect=function(obj)
{var o={areas:[],voids:[]};for(var i in areas)
o.areas.push(areas[i].save());for(var i in voids)
o.voids.push(voids[i].save());$.extend(obj,{AdvancedSeedCalculator:o});};self.restore=function()
{if(!parent.archived||!parent.archived[self.name])return false;var o=parent.archived[self.name];for(var i=0;i<o.areas.length;i++)
{var a=new self.Area(self,areas,areas_ctr);a.restore(o.areas[i]);}
for(var i=0;i<o.voids.length;i++)
{var v=new self.Area(self,voids,voids_ctr);v.restore(o.voids[i]);}
self.update();return true;};self.show=function(){container.show();$('#ac_text').show();};self.hide=function(){container.hide();$('#ac_text').hide();};if(!self.restore())
{new self.Area(self,areas,areas_ctr);new self.Area(self,voids,voids_ctr);}};$.ui=$.ui||{};$.ui.SeedCalc=SeedCalc;$.fn.seedCalcLink=function(options)
{try
{var seedcalc=new SeedCalc(options);this.each(function(i)
{var el=$(this),type;for(var i in seedcalc.seedtypes)
if(el.hasClass(i))
type=i;if(type)el.css({cursor:'pointer'}).click(function(){seedcalc.display(type,el.attr('title'),this);});});}
catch(e){console.error('seedCalcLink: '+e.message);}
return this;};})(jQuery);