var tmpid="";
  
function replaceAll(str,f,r) {
  var intIndexOfMatch = str.indexOf(f);
  
  while (intIndexOfMatch != -1){
    // Relace out the current instance.
    str=str.replace(f, r);

    // Get the index of any next matching substring.
    intIndexOfMatch = str.indexOf(f);
  }
  
  return str;
}

function toFloat(str) {
  str=str.toString();
  str=replaceAll(str,"€","");
  str=replaceAll(str,"&euro;","");
  str=replaceAll(str,"EUR","");
  str=replaceAll(str,"eur","");
  if(str.indexOf(",")!=-1) str=replaceAll(str,".","");
  str=replaceAll(str,",",".");
  str=str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  
  return parseFloat(str);
}

function roundNumber(num, dec) {
  if(isNaN(num)) num=parseFloat(0.00);
  var result = parseFloat(Math.round(num*Math.pow(10,dec))/Math.pow(10,dec));
  var str=result.toFixed(2);
  str=str.toString();
  str=str.replace(".",",");
  
  var conta=false;
  var c=0;
  var output = '';
  for(var i=str.length-1;i>-1;i--) {
   if(conta==true) c++;
   if(c==4) {
    output+=".";
    c=1;
   } 
   if(str.charAt(i)==",") conta=true;
   output+=str.charAt(i);
  }
  
  var newString = "";  
  var counter = output.length; 

  for (counter  ;counter > 0 ;counter -- ) { 
     newString += output.substring(counter-1, counter); 
  }
  
  return newString;
}

function mostra(id) {
  var height=document.getElementById(id).style.height;
  document.getElementById(id).style.overflow='hidden';
  
  if(height=="") {
    document.getElementById(id).style.height='1px';
    document.getElementById(id).style.visibility='hidden';
  } else {
    document.getElementById(id).style.height='';
    document.getElementById(id).style.visibility='visible';
    window.scrollTo(0,0);
  }
}

function mostra2(id) {
  var height=document.getElementById(id).style.height;
  document.getElementById(id).style.overflow='hidden';
  
  if(height=="") {
    document.getElementById(id).style.height='1px';
    document.getElementById(id).style.visibility='hidden';
  } else {
    document.getElementById(id).style.height='';
    document.getElementById(id).style.visibility='visible';
  }
}

function mostraNoScroll(id) {
  if(tmpid!="") mostra2(tmpid);
  
  var height=document.getElementById(id).style.height;
  document.getElementById(id).style.overflow='hidden';
  
  if(height=="") {
    document.getElementById(id).style.height='1px';
    document.getElementById(id).style.visibility='hidden';
    tmpid="";
  } else {
    document.getElementById(id).style.height='';
    document.getElementById(id).style.visibility='visible';
    tmpid=id;
  }
}
