

function FormatNumber(num, decimalNum, bolLeadingZero)
/* IN - num:            the number to be formatted
       decimalNum:     the number of decimals after the digit
       bolLeadingZero: true / false to use leading zero
  RETVAL - formatted number
*/
{
   var tmpNum = num;

   // Return the right number of decimal places
   tmpNum *= Math.pow(10,decimalNum);
   tmpNum = Math.floor(tmpNum);
   tmpNum /= Math.pow(10,decimalNum);

   var tmpStr = new String(tmpNum);

   // See if we need to hack off a leading zero or not
   if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
       if (num > 0)
           tmpStr = tmpStr.substring(1,tmpStr.length);
       else
           // Take out the minus sign out (start at 2)
           tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        

   return tmpStr;
}


function ltrim ( s )
{
        return s.replace( /^\s*/, "" );
}


function rtrim ( s )
{
        return s.replace( /\s*$/, "" );
}

function trim ( s )
{
        return rtrim(ltrim(s));
}


//NOME: formato
//ENTRADA: cadea a formatear
//SAÍDA: cadea formateada, onde os acentos, eñes, etc. se convertiron ao correspondente código html
function formatea (str){
    var malos = new Array('Á','É','Í','Ó','Ú','á','é','í','ó','ú','ñ','Ñ','?')
    var bos = new Array('&Aacute;','&Eacute;','&Iacute;','&Oacute;','&Uacute;','&aacute;','&eacute;','&iacute;',
                '&oacute;','&uacute;','&ntilde;','&Ntilde;','&quot;');
    var res = str;
    for (var i = 0; i < malos.length; i++)
       res = res.replace(malos[i],bos[i]);
    return res;    
}


function toggle(id) {
        obj = document.getElementById(id);
        if (obj.style.display == "none") {
                obj.style.display = "block";
        } else {
                obj.style.display = "none";
        }
}

//FUNCIÓN: getStyleObject
//DESCRICIÓN: función para obter o estilo dun obxecto dado o seu id
function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

//FUNCIÓN: changeObjectVisibility
//DESCRICIÓN: cambia a visibilidade dun obxecto con id objectId ao estado newVisibility
function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

// ---------------------------------------------------------------
// Funcion para amosar imaxes nunha ventana nova
// Nome: amosaImaxe
// Data: 29 de xuño de 2006
// Autor: Cas
// ENTRADA: 
// @PARAM: imaxe: ruta á imaxe que hai que cargar
// @PARAM: ancho: anchura da imaxe
// @PARAM: alto: altura da imaxe
// SAIDA: ventana coa imaxe cargada
//----------------------------------------------------------------
// Ultima modificacion:
// Motivo:
// ----------------------------------------------------------------

function amosaImaxe(imaxe, ancho, alto){  
    var ventana; 
    var paxina =  
      '<html>'+
      '<head>'+
      '<title>Imaxe da Conseller&iacute;a de Medio Ambiente e Desenvolvemento Sostible</title>'+
      '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">'+
      '</head>'+
      '<body bgcolor="#FFFFFF">'+
      '<div valign="center" align="center">'+
      '<img src="'+imaxe+'" width="'+ancho+'" height="'+alto+'">'+ 
      '</div>'+
      '<p style="text-align:center;font-family: Verdana, Arial, Times, sans-serif; font-size:10pt;"><a href="#" onClick="self.close()">Pechar a ventana</a>'+
      '</body>'+
      '</html>';

    ventana = window.open('','Imaxe','copyhistory=0,directories=0,location=0,menubar=0,resizable=0,status=0,toolbar=0, width='+ancho+',height='+alto);
    ventana.document.open();
    ventana.document.write(paxina);  
    ventana.document.close();
}



