<!-- 
// alert("Hello World!");
/* Don't change anything below this unless you know what you're doing */
// START ALTERNATE TABLE ROWS
addEvent(window, "load", alternate_init);

// TABLE MUST HAVE CLASS='alternate_rows'

function alternate_init() {
	// Find all tables with class sortable and make them sortable
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("alternate_rows") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,	NS6 and Mozilla
// By Scott Andrew
{
	if (elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	} else if (elm.attachEvent){
		var r = elm.attachEvent("on"+evType, fn);
		return r;
	} else {
		// alert("Handler could not be removed");
	}
} 

function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}
// END ALTERNATE TABLE ROWS

// Begin Rounding Functions
function round(number,X) {
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
} // EOF

function roundDecimal(n, d)
{ d = (d>10?10:d);
 d = (d<0?0:d);
 var r = "" + Math.round(n * Math.pow(10,d));
 return (d==0?r:r.substring(0,r.length-d)+"."
 +r.substring(r.length-d,r.length));
} // EOF

function roundPrice(number) {
Number = Math.round(number*Math.pow(10,2))/Math.pow(10,2);
return roundDecimal(Number,2)
} // EOF
// End Rounding Functions

// Begin Pricing Function
function prescPrice (qty, pkg_cost, pkg_size, sch_min_price, sch_min_fee, sch_mu_pct, int_fee, int_fee_pct) {
// set price_sch defaults
if (!sch_min_fee) {sch_min_fee = 4.95;}
if (!sch_min_price) {sch_min_price = 6.95;}
if (!int_fee) {int_fee = 0.00;}
if (!int_fee_pct) {int_fee_pct = 0.00;}
if (!sch_mu_pct) {sch_mu_pct = 1;}
// turn sch_mu_pct into a pct
sch_mu_pct = ((100+sch_mu_pct)/100);
// determine unit_price
unit_price = pkg_cost/pkg_size*sch_mu_pct;
// determine int_mu 
int_mu = (round (((qty*unit_price)+int_fee)/100*int_fee_pct)+int_fee);
// determine item_mu (check against mins)
if (sch_min_fee >= int_mu) {
item_mu = sch_min_fee;} else {item_mu = int_mu;}
// get initial price
price = (unit_price*qty)+item_mu;
// check against min_price
if (price < sch_min_price) {price = sch_min_price;} 
price = roundPrice(price);
// if(typeof(price)) != "undefined"){ price = "TBD"; }
return price;
} // EOF 
// End Pricing Function
// -->

