// Adjust the backgorund of an object
function background_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.backgroundColor = val;}
    else if (document.getElementById) {el.backgroundColor = val;}
    else {el.bgColor = val;}
}

function border_color_set (item, val)
{
    var el  = getStyleObj(item); 
    if (document.all) {el.borderColor = val;}
    else if (document.getElementById) {el.borderColor = val;}
    else {el.borderColor = val;}
}



// Get a reference to an object
function getObj(id) 
{
    //alert (id);
    if (document.getElementById) {return document.getElementById(id);}
    else if (document.all)          {return document.all[id];}
    else          {return false;}
}


// Get a reference to the style definition of an object
function getStyleObj(id) 
{
   // alert (id);
    if (document.getElementById) {return getObj(id).style;} 
    else {return getObj(id);}
}

// Set visibility
function vis_set (item, val) 
{
    //alert ("setting visibility of " + item + " to " + val);
    var el  = getStyleObj(item); 
    el.visibility = val;
}

// Adjust the alpha of an object
function alpha_set (item, val)
{
    //alert ("setting alpha of " + item + " to " + val);
    var el  = getStyleObj(item);
    if (document.all) {el.filter = "alpha(opacity=" + val +");";}
    else if (document.getElementById) {el.opacity = parseFloat (val/100);}
}











// This allows the user to show/hide bio information
function toggle(link, divId, imageChange, itemChange) 
{
    var lText = link.innerHTML; 
    var d = getObj(divId);
    
    if (lText == 'Read Bio') 
    { 
        link.innerHTML = 'Hide Bio'; 
        d.style.display = 'block'; 
        background_set (itemChange, "#dcecf9");
        objCurrentImage = document.getElementById(imageChange);
        //objCurrentImage.src = "/extension/ezwebin/design/ezwebin/images/bio_read_less.gif";
    }
    else 
    { 
        link.innerHTML = 'Read Bio'; 
        d.style.display = 'none';
        background_set (itemChange, "#ffffff");
        objCurrentImage = document.getElementById(imageChange);
        //objCurrentImage.src = "/extension/ezwebin/design/ezwebin/images/bio_read_more.gif";
    }
}





// Calculators
// This function is likely deprecated
function commuteCalcu(form) 
{
    miles = eval(form.miles.value);
    
    // Number of miles times 20 (avg. work days a month) times 54.1 cents (est. cost of operation per mile)
    sov = parseInt(((miles*22)*.541));  

    carpool = parseInt(((miles*22)*.3907));  
    
    vanpool =  parseInt(((miles*22)*.10364)); 

    form.sov.value = sov;
    form.carpool.value = carpool;
    form.vanpool.value = vanpool;
}




function teleWork(form) 
{
    hours = eval(form.hours.value);
    days = eval(form.days.value);
    saved = (((hours*days)*52)/8);
    form.telework.value = saved;
}



function selectthis(item)
{
    var el=item.name
    document.commuteCalculator[el].select();    
}

function calc()
{
 if (document.commuteCalculator.mpg.value == 0.0)
 {   
   with (document.commuteCalculator)
   {  
	return;
   }
 } 
 else
 {  
   with (document.commuteCalculator)
   {  
     res = ((dist.value * workdays.value * deprec1.value) + (dist.value * workdays.value * (price.value / mpg.value)) + (dist.value * workdays.value * maint1.value) + (dist.value * workdays.value * tax1.value) + (Insur.value * 1) + (Fin.value * 1) + (parking.value * 1));
     carpool_factor = .75;
     carpool2_result = ((dist.value * workdays.value * deprec1.value * carpool_factor) + (dist.value * workdays.value * (price.value / mpg.value) * carpool_factor ) + (dist.value * workdays.value * maint1.value * carpool_factor) + (dist.value * workdays.value * tax1.value) + (Insur.value * 1) + (Fin.value * 1) + (parking.value * 1));
     vanpool_result_monthly = ( 1200 / 12 ) +  (dist.value * workdays.value * tax1.value) + (Insur.value * 1) + (Fin.value * 1);
     carpool_savings_monthly = res - carpool2_result; 
     vanpool_savings_monthly = res - vanpool_result_monthly;
    }
 }


 if (res - parseInt(res) == 0)
 {
   // res2 is yearly cost
   res2 = res*12;
   // carpool2_result12 is yearly cost
   carpool2_result12 = carpool2_result*12;
   vanpool_result_yearly = vanpool_result_monthly*12;

   // Format the costs
   res  = res  + ".00";
   res2 = res2 + ".00";
   // carpool2_result is monthly cost?
   carpool2_result = carpool2_result + ".00";
   vanpool_result_monthly = vanpool_result_monthly + ".00";
   // Format the yearly costs
   carpool2_result12 = carpool2_result12 + ".00";
   vanpool_result_yearly = vanpool_result_yearly + ".00";

 }
 else
 {
   // Round the monthly results
   res += 0.005;                        // round to penny
   temp = (res - parseInt(res)) + 1;    // temp = 1.xxx...
   temp = temp + " ";                   // temp = string
   temp = temp.substring(1,4);          // temp = .xx
   res = parseInt(res) + temp;          // res = integer + .xx

   carpool2_result += 0.005;
   temp = (carpool2_result - parseInt(carpool2_result)) + 1;
   temp = temp + " ";
   temp = temp.substring(1,4);
   carpool2_result = parseInt(carpool2_result) + temp;

   vanpool_result_monthly += 0.005;
   temp = (vanpool_result_monthly - parseInt(vanpool_result_monthly)) + 1;
   temp = temp + " ";
   temp = temp.substring(1,4);
   vanpool_result_monthly = parseInt(vanpool_result_monthly) + temp;


   // Round the yearly results
   res2 = res*12;
   res2 += 0.005;                       // round to penny
   temp = (res2 - parseInt(res2)) + 1;  // temp = 1.xxx...
   temp = temp + " ";                   // temp = string
   temp = temp.substring(1,4);          // temp = .xx
   res2 = parseInt(res2) + temp;        // res2 = integer + .xx
    
   carpool2_result12 =  carpool2_result*12;
   carpool2_result12 += 0.005;
   temp = (carpool2_result12 - parseInt(carpool2_result12)) + 1;
   temp = temp + " ";
   temp = temp.substring(1,4);
   carpool2_result12 =  parseInt(carpool2_result12) + temp;

   vanpool_result_yearly = vanpool_result_monthly*12;
   vanpool_result_yearly += 0.005;
   temp = ( vanpool_result_yearly - parseInt( vanpool_result_yearly ) ) + 1;
   temp = temp + " ";
   temp = temp.substring( 1, 4 );
   vanpool_result_yearly = parseInt( vanpool_result_yearly ) + temp;

 }

// Graph
// Find maximum number for bars.

var res2 = Number(res2);
var carpool2_result12 = Number(carpool2_result12);
var vanpool_result_yearly = Number( vanpool_result_yearly );

max1 = Math.max( res2, carpool2_result12, vanpool_result_yearly );

// Display first two bars.

 document.getElementById('bar_res2').style.width = (res2/max1*100) + "%";
 document.getElementById('bar_res2').innerHTML = "&nbsp;$" + res2;

 document.getElementById('bar_carpool2_result12').style.width = (carpool2_result12/max1*100) + "%";
 document.getElementById('bar_carpool2_result12').innerHTML = "&nbsp;$" + carpool2_result12;

 document.getElementById('bar_result_vanpool').style.width = (vanpool_result_yearly/max1*100) + "%";
 document.getElementById('bar_result_vanpool').innerHTML = "&nbsp;$" + vanpool_result_yearly;


 saved_carpool12 = res2 - carpool2_result12;
 saved_vanpool_yearly = res2 - vanpool_result_yearly;

// Display last bar.

 document.getElementById('bar_saved_carpool12').style.width = Math.max( ( saved_carpool12/max1*100 ), 0 ) + "%";
 document.getElementById('savings_saved_carpool12').innerHTML = "&nbsp;$" + saved_carpool12.toFixed(2);
 document.getElementById('bar_saved_vanpool').style.width = Math.max( ( saved_vanpool_yearly/max1*100 ), 0 ) + "%";
 document.getElementById('savings_saved_vanpool').innerHTML = "&nbsp;$" + saved_vanpool_yearly.toFixed(2);

// End of graph.

}
