/*   common.js   -   12/15/2005   -   common javascript functions   */
	 
function toggleLayer( whichLayer )
{
  var elem, vis, link;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function hideLayer( whichLayer ) {
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer ).style.display='none';
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
}


/* old layer toggle function - circa 2005 ---------------------- */

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 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 = '';
           }
       }
};

var laplinktabtoggle = {
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);
}