Event.observe(window, 'load', page_loaded); function page_loaded() { calc_preloadImages(); var tooltipNodes = document.getElementsByClassName('calc_links'); tooltipNodes.each(function(node) { new Tooltip(node,'tooltip', {delta_x: -130, delta_y: -20}); }); new Tooltip($('tons_of_co2_link'),'tooltip', {delta_x: -130, delta_y: -20}); display_lang(); init_myCalcObj(); current_section = 'get_started'; response_text_flags = { 'vehicles': false, 'air_travel': false }; section_viewed_flags = { 'get_started': true, 'home_energy': false, 'driving_flying': false, 'food_diet': false, 'buying_waste': false, 'results': false }; select_form(current_section); highlight_nav(current_section); $('loading').hide(); $('baseline_people').show(); EventSelectors.start(Rules); } var Rules = { '#tabs img:mouseover': function(el) { highlight_nav(el.name); }, '#tabs img:mouseout': function(el) { reset_nav(el.name); }, '#tabs img:click': function(el) { select_form(el.name); }, '.question .calc_links:mouseover': function(el) { Element.update($('tooltip'), el.up('.question').down('.tooltip').innerHTML); }, '.question .calc_links:click, #tons_of_co2_link:click': function(el, ev) { //window.open(el.href, 'more_info', 'width=605,height=400,scrollbars=yes'); Event.stop(ev); }, '#tons_of_co2_link:mouseover': function(el) { Element.update($('tooltip'), $(el.id + '_tooltip').innerHTML); }, 'img.continue:click': function(el, ev) { var target = $(current_section + '_form').next(); var section = target.id.substring(0, target.id.length-5); select_form(section); Event.stop(ev); }, '.how_calculated_link:click': function(el, ev) { Event.stop(ev); window.open(el.attributes.href.value, 'math', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=600,height=450,left=50,top=50'); }, '#offset_button:click': postResults, '#get_started_form .calc_for:click': function(el, ev) { Event.stop(ev); var calc_for_val = el.className.match(/individual/) == null ? 'my_entire_household' : 'me_only'; // are we switching calc_for after having answered it once? if ($F('calc_for') != '' && (section_viewed_flags.home_energy || section_viewed_flags.driving_flying || section_viewed_flags.food_diet || section_viewed_flags.buying_waste) ) { var calc_reset = false; if (display_confirm('calc_buttons')) { var orig_people = $F('people'); $('calc_form').reset(); $('people').selectedIndex = orig_people; init_myCalcObj(); display_results.reset(); } } $('calc_for').value = calc_for_val; // show proper language depending on individual or household calcs display_lang(); select_form('home_energy'); }, '#home_energy_form .calculate:click': function(el, ev) { // validate that dropdowns have been selected if (el.type == 'radio') { if ($F('state') == '' || $F('home') == '' || $F('bedrooms') == '') { display_validation('baseline_home'); return null; } } calculate.all(el); display_results.home_energy(); }, '#driving_flying_form .calculate:click': function(el, ev) { calculate.all(el); display_results.driving_flying(); }, '#driving_flying_form .calculate:change': function(el, ev) { if (el.name == 'vehicle1_size') { if (el.options[el.selectedIndex].text == 'No vehicle') { $('vehicles2', 'vehicles3', 'vehicles1_xtra_text', 'vehicle_air_filter', 'tire_pressure').invoke('hide'); } else { $('vehicles1_xtra_text', 'vehicle_air_filter', 'tire_pressure').invoke('show'); } } }, '#food_diet_form .calculate:click': function(el) { calculate.all(el); display_results.food_diet(); }, '#buying_waste_form .calculate:click': function(el) { calculate.all(el); display_results.buying_waste(); }, '#home_energy_form .calculate_text:keyup': function(el) { calculate.all(el); display_results.home_energy(); }, '#driving_flying_form .calculate_text:keyup': function(el) { // text box validation if (!el.value.match(/(^\d*$)/)) { el.value = el.value.substring(0, el.value.length-1); //alert('Please enter a number'); return false; } if (el.name == 'vehicle1_miles' || el.name == 'vehicle2_miles' || el.name == 'vehicle3_miles') response_text_flags.vehicles = true; if (el.name == 'long_flights1' || el.name == 'short_flights1') response_text_flags.air_travel = true; calculate.all(el); display_results.driving_flying(); }, '#food_diet_form .calculate_text:keyup': function(el) { calculate.all(el); display_results.food_diet(); }, '#buying_waste_form .calculate_text:keyup': function(el) { // text box validation if (!el.value.match(/(^(\d+\.)?\d*$)/)) { el.value = el.value.substring(0, el.value.length-1); return false; } calculate.all(el); display_results.buying_waste(); }, '#vehicles1 a.add_vehicle:click': function(el, ev) { Event.stop(ev); $('vehicles2').show(); el.hide(); }, '#vehicles2 a.add_vehicle:click': function(el, ev) { Event.stop(ev); $('vehicles3').show(); el.hide(); } } function display_validation(container_id) { var text = $$('#'+container_id+' .validation')[0].innerHTML; alert(text); } function display_confirm(container_id) { var text = $$('#'+container_id+' .validation')[0].innerHTML; return confirm(text); } function display_lang() { if ($F('calc_for') == 'me_only') { $$('.lang_ind').invoke('show'); $$('.lang_household').invoke('hide'); } else { $$('.lang_household').invoke('show'); $$('.lang_ind').invoke('hide'); } } function select_form(section) { // force get_started form if # of people question not answered if (section != 'get_started' && $F('people') == 0) { display_validation('baseline_people'); return null; } if (section != 'get_started' && $F('calc_for') == '') { display_validation('tabs'); if (current_section == 'get_started') return null; } // if 'results' set flags, calc total if (section == 'results') { if (!section_viewed_flags.home_energy || !section_viewed_flags.driving_flying || !section_viewed_flags.food_diet || !section_viewed_flags.buying_waste) { display_validation('results_form'); } section_viewed_flags.home_energy = true; section_viewed_flags.driving_flying = true; section_viewed_flags.food_diet = true; section_viewed_flags.buying_waste = true; section_viewed_flags.results = true; } else { section_viewed_flags[section] = true; } calculate.all(); current_section = section; reset_forms(); if (section != 'get_started') eval('display_results.' + section + '()'); $(section + '_form').show(); highlight_nav(section); } function reset_forms() { // brute force! $('get_started_form', 'home_energy_form', 'driving_flying_form', 'food_diet_form', 'buying_waste_form', 'results_form').invoke('hide'); change_images('get_started', ''); change_images('home_energy', ''); change_images('driving_flying', ''); change_images('food_diet', ''); change_images('buying_waste', ''); change_images('results', ''); } function highlight_nav(section) { change_images(section, 'over'); } function reset_nav(section) { if (section != current_section) change_images(section, ''); } function change_images(section, modifier) { if (section == '') return; changeImages(section, 'images/'+section+modifier+'.gif'); } function newImage(arg) { if (document.images) { rslt = new Image(); rslt.src = arg; return rslt; } } function changeImages() { if (document.images && (calc_preloadFlag == true)) { for (var i=0; i