// Muda a cor do campo selecionado
function changeColor(oField, iAcao){
	if (iAcao == 0){
		oField.style.backgroundColor = '#F5F5F5';
	} else if (iAcao == 1){
		oField.style.backgroundColor = '#efefef';
	}
}

lib = new Object();

lib = {
	Import: function(File){
		document.write('<script src="../includes/js/'+File+'" type="text/javascript"></script>\n');
	}
}

lib2 = new Object();

lib2 = {
	
	Import2: function(File){
		document.write('<script src="'+ URLREESCRITA +'admin/includes/js/'+File+'" type="text/javascript"></script>\n');
	}
}


lib3 = new Object();

lib3 = {
	Import3: function(File){
		document.write('<script src="'+ URLREESCRITA +'admin/includes/js/'+File+'" type="text/javascript"></script>\n');
	}
}

function calcula_preco_real(preco)
{
		preco = preco.replace(".","");
		preco = preco.replace(",",".");
		
		preco = parseFloat(preco);
		preco = ((45 * preco)/100)+preco;
		
		return formata_valor_pt(preco);
}

function formata_valor_pt(num)
{
	x = 0;
	
	if(num<0) {
		num = Math.abs(num);
		x = 1;
	}
	
	if(isNaN(num)) num = "0";
		cents = Math.floor((num*100+0.5)%100);

	num = Math.floor((num*100+0.5)/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));
	 ret = num + ',' + cents;
	 
	 if (x == 1) ret = ' - ' + ret;return ret;
}

var msg = new Object();
msg = {
	
	showMessageBlock : function(text){		
		jQuery.blockUI({ message: text });
		
		setTimeout(function(){
				$('#msg').remove();
		},3000);
		
	},	
	show : function(text){
		
		$('#msg').remove();
			
			$('body').prepend("<div align='center' class='msg' id='msg'>"+text+"</div>");
							
			setTimeout(function(){
				$('#msg').remove();
			},3000);
	},
	remove : function(){
		$('#msg').remove();
		jQuery.unblockUI();
	}	
}


function hide(){
	document.getElementById('mensagem').style.display  = 'none';
}

function DesabilitaForm( ){
    var inputFocus = null;
	var inputs = document.getElementsByTagName( 'input' );
    $x=0;
	$x2=0;
    while( $x < inputs.length ){
	   inputs[$x].setAttribute('disabled', 'disable');
	   if($x2 == 0){
		   inputFocus =  inputs[$x];
		   $x2++;
	   }
       $x++;
    }
	
	var inputs = document.getElementsByTagName( 'select' );
    $x=0;
	$x2=0;
    while( $x < inputs.length ){
	   inputs[$x].setAttribute('disabled', 'disable');
	   if($x2 == 0){
		   inputFocus =  inputs[$x];
		   $x2++;
	   }
       $x++;
    }
}


function number_format( number, decimals, dec_point, thousands_sep ) {
    
    var n = number, prec = decimals;
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };
 
    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) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = toFixedFix(Math.abs(n), 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);
    }
 
    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}


