document.observe('dom:loaded', function() {


	$$('#subnav li.submenu').each(function(elm) {
		elm.observe('mouseover', function() {
			$(elm.down()).addClassName('hit');
			$(elm.down().next()).show();
			});
			elm.observe('mouseout', function() {
				$(elm.down()).removeClassName('hit');
				$(elm.down().next()).hide();
				});
		});
	$$('#step2 li.step').each(function(elms) {
		elms.observe('mouseover', function() {
			$(elms.down()).addClassName('hit');
			$(elms.down().next()).show();
			});
			elms.observe('mouseout', function() {
				$(elms.down()).removeClassName('hit');
				$(elms.down().next()).hide();
				});
		});
	
	});

function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, prec = decimals;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep;
    var dec = (typeof dec_point == "undefined") ? '.' : dec_point;
 
    var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = Math.abs(n).toFixed(prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
 
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    return s;
}
function format(id)
{
	document.getElementById(id).value = number_format(document.getElementById(id).value, 2, ',', '.');	
}
function formatAmount(e,id)
{
	var strCheck = '0123456789';
	var inp = document.getElementById(id);
	var whichCode = (window.Event) ? e.keyCode : e.keyCode;

	if (whichCode == 13)
	{	
		return false;  // Enter
	}	
	
	//tab it's ok
	if(whichCode == 9)
		return true;
	
	// backspace should revert to previously entered data
	if (whichCode == 8 || whichCode == 46)
	{	
		if(amount[id].length > 0){
			amount[id] = amount[id].substring(0,amount[id].length-1);
			inp.value = '';
			inp.value = format(amount[id]);
		}
		return false;
	}
	
	
	if(inp.value.length > 20){
		inp.value = '';
		inp.value = format(amount[id]);
		return false;
	};
		
	
	if(whichCode >= 96 && whichCode <= 105)
		whichCode = whichCode - 48;
	key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1)
	{
	 	return false;  // Not a valid key
	}
	if((amount[id].length == 0) && (key =='0'));
	else amount[id] = amount[id] + key;
	inp.value = '';
	inp.value = format(amount[id]);
	return false;

}

function format(amount){
	if(amount.length == 0)
		return '0,00';
	if(amount.length == 1)
		return '0,0' + amount;
	if(amount.length == 2)
		return '0,' + amount;
	
	var i,j,aux2,ret;
	if (amount.length > 2) {
		aux2 = '';
		for (j = 0, i = amount.length - 3; i >= 0; i--) {
			if (j == 3) {
				aux2 += '.';
				j = 0;
			}
			aux2 += amount.charAt(i);
			j++;
		}
		ret = '';
		len2 = aux2.length;
		for (i = len2 - 1; i >= 0; i--)
		{
			ret += aux2.charAt(i);
		}
		ret += ',' + amount.substr(amount.length - 2, amount.length);
	}
	
	return ret;
	
}
function form_x()
{
	j = 10;
	is = false;
	for(k=0; k < j; k++)
	{
		var lm = 'fila_';
		if(document.getElementById(lm+k).checked == true) is = true;
	}
	var chk = document.getElementById('all');
	if(chk.checked == true)
	{
		is = true;
	}
	if(is == true) {document.mprint.submit();}
}
function checkalls()
{
	var chk = document.getElementById('all');
	if(chk.checked == true)
	{
		chk.checked = false;
	}
	else chk.checked = true;
	checkall();
}
function checkall()
{
	j = 10;
	var state = document.getElementById('all');
	if(state.checked == true)
	{
		for(k=0; k < j; k++)
		{
			var lm = 'fila_';
			if(document.getElementById(lm+k) != 'undefined')
			document.getElementById(lm+k).checked = true;	
		}
	}
	else {
		for(k=0; k < j; k++)
		{
			var lm = 'fila_';
			if(document.getElementById(lm+k) != 'undefined')
			document.getElementById(lm+k).checked = false;	
		}	
	}
}