window.addEvent('domready',function(){ $$('.deleteitem').addEvent('click',function(){ return confirm('Are you sure you want to delete this item?'); }); $$('a.external').addEvent('click',function(){ window.open(this.href); return false; }); $$('.externallink').addEvent('click',function(){ window.open(this.href); return false; }); $$('.snippetcode').addEvent('focus',function(){ this.select(); }); $$('div.itemtile').addEvent('click',function(){ window.location = this.get('href'); return false; }); var th = new InputHinter($('searchbox'),'search'); // find rating star nodes var starwidgets = $$('.ratingstars'); starwidgets.each(function(starwidget){ if(starwidget.hasClass('active')){ // this is an active clickable widget var numerator = starwidget.getElement('.numerator'); var starlabel = starwidget.getElement('.starlabel'); starwidget.currentval = parseInt(starwidget.getElement('.numerator').get('html'))*10; starwidget.currenttext = ''; starwidget.getElements('.stars li a').each(function(st){ st.addEvent('click',function(){ var ratingval = st.getElement('.value').get('html'); if($('rating')){ $('rating').value = ratingval; } starwidget.currentval = ratingval; starwidget.currenttext = st.getElement('.rating-descriptor').get('html'); st.getParent('.stars').set('class','stars stars-'+ratingval); }) st.addEvent('mouseover',function(){ starlabel.set('html',st.getElement('.rating-descriptor').get('html')); starlabel.addClass('choosemode'); numerator.set('html', parseInt(st.getElement('.value').get('html'))/10 ); numerator.addClass('choosemode'); }); st.addEvent('mouseout',function(){ starlabel.set('html', starwidget.currenttext); starlabel.removeClass('choosemode'); numerator.set('html', starwidget.currentval/10); numerator.removeClass('choosemode'); }); }); } }); $$('.helpicon').each(function(i){ i.addEvent('click',function(){ var help = new Modalbox({ 'ismodal':true, 'title':'Help', 'draggable':true, 'width':'400px', 'blanketcolor':'#006BFA', 'internallinks':true, 'ajaxcontent':i.get('contenturl') }); return false; }); }); $$('input.dollar').each(function(el){ el.addEvent('blur',function(){ el.value = el.value.toFloat().numberFormat(); }); el.addEvent('focus',function(el){ this.select(); }); }); $$('.crunchiebox').each(function(box){ var panel = box.getElement('.panel'); var trigger = box.getElement('h4'); var mySlide = new Fx.Slide(panel) if(!box.hasClass('open')){ mySlide.hide(); trigger.addClass('triggerdown'); }else{ trigger.addClass('triggerup'); } trigger.addEvent('click',function(){ mySlide.toggle(); if(mySlide.open){ trigger.removeClass('triggerup'); trigger.addClass('triggerdown'); }else{ trigger.removeClass('triggerdown'); trigger.addClass('triggerup'); } }); }); $$('input.selectonfocus').each(function(elem){ elem.set('readonly','readonly'); elem.addEvent('focus',function(){ elem.select(); }); }) }); window.addEvent('load',function(){ if($$('.defaultfocus')){ if($$('.defaultfocus')[0]){ if($$('.defaultfocus')[0].focus){ $$('.defaultfocus')[0].focus(); } } } $$('.disappear').each(function(elem){ // do a fancy animation to make them hide var slider = new Fx.Slide(elem,{'duration':'long'}); var waiter = new Fx.Tween(elem,{'duration':1000,property:'opacity'}); var tweener = new Fx.Tween(elem,{'duration':'long',property:'opacity'}); waiter.start(1,1).chain( //Notice that "this" refers to the calling object (in this case, the myFx object). function(){ this.start(1,1);tweener.start(1,0); }, function(){ this.start(0,0);slider.slideOut(); } ); }); }); Number.implement({ /* Property: numberFormat Format a number with grouped thousands. Arguments: decimals, optional - integer, number of decimal percision; default, 2 dec_point, optional - string, decimal point notation; default, '.' thousands_sep, optional - string, grouped thousands notation; default, ',' Returns: a formatted version of number. Example: >(36432.556).numberFormat() // returns 36,432.56 >(36432.556).numberFormat(2, '.', ',') // returns 36,432.56 */ numberFormat : function(decimals, dec_point, thousands_sep) { decimals = Math.abs(decimals) + 1 ? decimals : 2; dec_point = dec_point || '.'; thousands_sep = thousands_sep || ','; var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + ''); // returns matches[1] as sign, matches[2] as numbers and matches[3] as decimals var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0; return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + (decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : ''); } });