<!-- ************************************************************************* -->
<!-- ************************ calculator scripts ***************************** -->

//Pre Set Vars
var sCurrentTab = "tab1";
//Page Load
function init(){
   inittabs();
}

//Calculations

var eventDays = 3;
var eventAttending = 200;
var percentageDriving = 80;
var percentageFlying = 20;

function GetInfraTotal(frm)
{
var sqrft = frm.event_sqr_ft.value;
var days = eventDays; // verify frm.event_days.value;
var attending = eventAttending; // verify frm.event_attending.value;
var total =(((sqrft*0.0261)*days)*1.882)/2205+(((sqrft*0.0010)*days)*12.0593)/2205;

frm.event_emissions.value = Math.round(total*100)/100;
// frm.inf_total.value = Math.round(total*100)/100;
GetGrandTotal(frm);
}

function GetAutoTotals(frm)
{
var days = eventDays; // frm.event_days.value;
var attending = eventAttending; // frm.event_attending.value;
var PerDriving = percentageDriving; // frm.event_percent_driving.value;
var DriveDistance = frm.event_driving_distance.value;
var DriveDistanceAt = frm.event_driving_distance_at.value;
// --------------------------- ORIGINAL CALCULATION BELOW -------- 04-27-07 ------------------------- //
// -------------------------------------------------------------------------------------------------- //
// var total = ((((PerDriving/100)*attending*DriveDistance/21)*19.36)/2205)+(((DriveDistanceAt/21)*19.36)/2205)*days; //
var total = ((((PerDriving/100)*DriveDistance/21)*19.36)/2205)+(((DriveDistanceAt/21)*19.36)/2205)*days;

frm.auto_emissions.value = Math.round(total*100)/100;
GetTransportationTotal(frm);
}

function GetAirTotals(frm)
{
var days = eventDays; // frm.event_days.value;
var attending = eventAttending; // frm.event_attending.value;
var flyingHours = frm.event_attend_flying_hours.value;
var perFlying = percentageFlying; // frm.event_attend_flying.value;
var flyMiles = frm.event_total_flying_miles.value;
var total =((flyingHours*414.65*.968)/2205)+(flyMiles*.968)/2205;
//var total = ((D19*Figures!C35*Figures!C36)/2205)+((D23*Figures!C36)/2205)

frm.air_emissions.value = Math.round(total*100)/100;
GetTransportationTotal(frm);
}

function GetTransportationTotal(frm)
{
var air = parseFloat(frm.air_emissions.value);
var auto = parseFloat(frm.auto_emissions.value);
var total = air + auto;

frm.total_travel_emissions.value = Math.round(total*100)/100;
frm.trans_total.value = Math.round(total*100)/100;
GetGrandTotal(frm);
}

function GetMealTotals(frm)
{
var meals = parseFloat(frm.event_meals.value);
var total =(meals*0.1682)/2205+(meals*3.13)/2205;

frm.total_meals_emissions.value = Math.round(total*100)/100;
frm.meal_total.value = Math.round(total*100)/100;
}
function GetLodgingTotals(frm)
{
var rooms = frm.guest_rooms.value;
var room_nights = frm.guest_nights.value;
var suites = frm.suite_rooms.value;
var suite_nights = frm.suite_nights.value;
var total =((((rooms*room_nights)*325)*0.0261)*1.882)/2205+((((suites*600)*suite_nights)*0.0261)*1.882)/2205+((((rooms*room_nights)*325)*0.0010)*12.0593)/2205+((((suites*suite_nights)*600)*0.0010)*12.0593)/2205;

frm.total_lodging_emissions.value = Math.round(total*100)/100;
frm.lodge_total.value = Math.round(total*100)/100;
GetGrandTotal(frm);
}

function GetGrandTotal(frm)
{
var total = parseFloat(frm.lodge_total.value) + parseFloat(frm.meal_total.value) + parseFloat(frm.trans_total.value);
frm.event_total.value = Math.round(total);
GetOffset(frm);
}
function GetOffset(frm)
{
frm.offset.value = frm.event_total.value;
var totaloffset = parseFloat(frm.offsetPrice.value) * parseFloat(frm.offset.value);
frm.offsetPriceTotal.value = totaloffset; 
}

//Validation for numbers
function goodKey(ctl){
var fValue = ctl.value;
if (!IsNumeric(fValue)){ 
      	alert('Please enter only numbers or decimal points') 
      	ctl.value = '';
      	ctl.focus(); 
      	return false; 
      } 

	return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}

function clearTabs(){
   var tabs = document.getElementById("tabBar").cells
   for (var i = 0; i < tabs.length; i++)
   {
         tabs[i].className = "inactiveTab"
   }
   var contentDivs = document.getElementById('contentArea').getElementsByTagName("DIV");
   for (var i = 0; i < contentDivs.length; i++)
   {
      if (contentDivs[i].style.display = "none") {
      }
      contentDivs[i].style.display = "none"
   }
}

function showPanel(selectedTab){
   clearTabs();
   var tabEl = document.getElementById(selectedTab);
   tabEl.className = "activeTab";
   var con = tabEl.getAttribute('CONNECT');
   var panel = document.getElementById(con);
   panel.style.visibility = "visible";
   panel.style.display = "block";
   document.getElementById('hiddenTabId').value = selectedTab;
   // hide message/error display
   //hideErrMsg();
}

function callPanel(selectedTab){
   clearTabs();
   var tabEl = document.getElementById(selectedTab);
   tabEl.className = "activeTab";
   var con = tabEl.getAttribute('CONNECT');
   var panel = document.getElementById(con);
   panel.style.visibility = "visible";
   panel.style.display = "block";
   document.getElementById('hiddenTabId').value = selectedTab;
}

function inittabs(){
   if (sCurrentTab.length > 0) {
      showPanel(sCurrentTab);
   }
   // fix for the mac's slow paint of the layers.. hiding them until paint is done
   if (document.getElementById('HideForMac1')) {
      //alert(document.getElementById('HideForMac1').style.visibility);
      document.getElementById('HideForMac1').style.visibility = "visible";
      //alert(document.getElementById('HideForMac1').style.visibility);
   }
   if (document.getElementById('HideForMac2')) {
      //alert(document.getElementById('HideForMac1').style.visibility);
      document.getElementById('HideForMac2').style.visibility = "visible";
      //alert(document.getElementById('HideForMac1').style.visibility);
   }
   if (document.getElementById('HideForMac3')) {
      //alert(document.getElementById('HideForMac1').style.visibility);
      document.getElementById('HideForMac3').style.visibility = "visible";
      //alert(document.getElementById('HideForMac1').style.visibility);
   }
}