// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults



function ChangeColor(tableRow, highLight){
		if (highLight)
		{
			tableRow.style.backgroundColor = '#dcfac9';
			tableRow.style.cursor = 'pointer';
		}else{
			tableRow.style.backgroundColor = 'white';
			tableRow.style.cursor = '';
		}
	}

function DoNav(theUrl)
    {
	document.location.href = theUrl;
    }

function Total(sub_total_field,shipping_field,total_field)
{
var sub_total = parseFloat($(sub_total_field).firstChild.innerHTML.replace('$','').replace(',','').strip()); 
var shipping_cost = parseFloat($(shipping_field)[$(shipping_field).selectedIndex].text.split('-')[0].replace('$','').strip());

var total_price = sub_total + shipping_cost;
$(total_field).firstChild.innerHTML = formatCurrency(total_price);
}

function formatCurrency(num) {
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);
}

// var RuledTable = Class.create();
// RuledTable.prototype = {
//   
//   initialize: function(class_name) {
//     var tables = $$(class_name);
//     
//     for (var c = 0; c < tables.length; c++){
//     
// 	var rows = tables[c].getElementsByTagName('tr');
// 	for (var i = 0; i < rows.length; i++) {
// 	  this.setupRow(rows[i]);
// 	}
//     }
//   },
//   
//   onMouseOverRow: function(event) {
//     // Element.addClassName(this, 'highlight');
//     this.className = this.className.replace(/\s*\bhighlight\b|$/, ' highlight'); // faster than the above
//   },
//   
//   onMouseOutRow: function(event) {
//     // Element.removeClassName(this, 'highlight');
//     this.className = this.className.replace(/\s*\bhighlight\b\s*/, ' '); // faster than the above
//   },
//   
//   setupRow: function(row) {
//     Event.observe(row, 'mouseover', this.onMouseOverRow.bindAsEventListener(row));
//     Event.observe(row, 'mouseout', this.onMouseOutRow.bindAsEventListener(row));
//   }
//   
// };