/*
common.js
12/15/2005

common javascript functions
*/


/* layer toggle function --------------------------------------------- */

function expandCollapse() {
for (var i=0; i<expandCollapse.arguments.length; i++) {
var element = document.getElementById(expandCollapse.arguments[i]);
element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}



// Tab Toggle Script
// =============================
// slightly modified from the original version
// to change the IDs class to 'active' which is
// what gives it the orange background colour

var toggle = {
show : function() {
           for ( i=0; i < arguments.length; i++ ) {
               $(arguments[i]).style.display = '';
			   var newName = 'menu_' + arguments[i];
               var newNameActive = newName + '_active';
               if ($(newName)) {
				 $(newName).className='active';
                 $(newName).id=newNameActive;
			   }

               // reset vars
               var newName = '';
               var newNameActive = '';
           }
       },
hide : function() {
           for ( i=0; i < arguments.length; i++ ) {
               $(arguments[i]).style.display = 'none';
			   var removeName = 'menu_' + arguments[i];
               var removeNameActive = removeName + '_active';
               if ($(removeNameActive)) {
				   $(removeNameActive).className='';
                   $(removeNameActive).id=removeName;
               }

               // reset vars
               removeName = '';
               removeNameActive = '';
           }
       }
};


// math matrix madness for the ROI from hell
var calculateTotal = {
sum : function () { // pass in as many ids as you want to add up - the last argument is the id where you want the total
          total = 0;
          sumArgs = arguments.length - 1;
          lastArg = arguments[sumArgs];

          for ( i=0; i < sumArgs; i++ ) {
              total = +total + (+$(arguments[i]).value);
          }
          
          // $(lastArg).value = total.toFixed(2);
          $(lastArg).value = total;
      },
multiply : function () {
               totalMult = 1;
               sumArgs = arguments.length - 1;
               lastArg = arguments[sumArgs];

               for ( i=0; i < sumArgs; i++ ) {
                   totalMult = +totalMult * (+$(arguments[i]).value);
               }
               $(lastArg).value = totalMult;
           },
subtract : function () {
               totalSub = 0;
               sumArgs = arguments.length - 1;
               lastArg = arguments[sumArgs];

               for ( i=0; i < sumArgs; i++ ) {
                   totalSub = (-totalSub) - ($(arguments[i]).value);
               }
               totalSubRev = -totalSub;
               $(lastArg).value = formatCurrency(totalSubRev);
           },
divide : function () {
               $('n17').value = ($('n16').value / 60).toFixed(2);
         }
}
// Format a value as currency.
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}