<!--

//-------------------------------------
// @VERSAO 3.0 2011-03-11
// @DESC   Funções JS gerais. 
//-------------------------------------

   var str_aguarde = "Aguarde por favor";
   if (lingua!="PT") {str_aguarde = "Please wait";}
   document.write('<div id="loading"><br>' + str_aguarde + '...</div>');

   window.onload = function() {
	document.getElementById("loading").style.display="none";
   }


//----------------
function getAllSheets() {
  //if you want ICEbrowser's limited support, do it this way
  if (!window.ScriptEngine && navigator.__ice_version ) {
  	//IE errors if it sees navigator.__ice_version when a window is closing
  	//window.ScriptEngine hides it from that
    return document.styleSheets; 
  }
  if (document.getElementsByTagName ) {
    //DOM browsers - get link and style tags
    var Lt = document.getElementsByTagName('link');
    var St = document.getElementsByTagName('style');
  } else if (document.styleSheets && document.all ) {
    //not all browsers that supply document.all supply document.all.tags
    //but those that do and can switch stylesheets will also provide
    //document.styleSheets (checking for document.all.tags produces errors
    //in IE [WHY?!], even though it does actually support it)
    var Lt = document.all.tags('LINK'), St = document.all.tags('STYLE');
  } else { return []; 
  } //lesser browser - return a blank array
  //for all link tags ...
  for (var x = 0, os = []; Lt[x]; x++ ) {
    //check for the rel attribute to see if it contains 'style'
    if (Lt[x].rel ) { var rel = Lt[x].rel;
    } else if( Lt[x].getAttribute ) { var rel = Lt[x].getAttribute('rel');
    } else { var rel = ''; 
    }
    if (typeof( rel ) == 'string' && rel.toLowerCase().indexOf('style') + 1 ) {
      //fill os with linked stylesheets
      os[os.length] = Lt[x];
    }
  }
  //include all style tags too and return the array
  for( var x = 0; St[x]; x++ ) { 
    os[os.length] = St[x]; 
alert(St[x]);
  } 
  return os;
}
function changeStyle() {
  for( var x = 0, ss = getAllSheets(); ss[x]; x++ ) {
    //for each stylesheet ...
    if( ss[x].title ) {
      //disable the stylesheet if it is switchable
      ss[x].disabled = true;
    }
    for( var y = 0; y < arguments.length; y++ ) {
      //check each title ...
      if( ss[x].title == arguments[y] ) {
        //and re-enable the stylesheet if it has a chosen title
        ss[x].disabled = false;
      }
    }
  }
  if( !ss.length ) { alert( 'Your browser cannot change stylesheets' ); }
}
//----------------


function trim(obj)
//-------------------------------------
{
  var a = null;
  var b = null;
  
	obj = obj + " ";
	obL = obj.length - 1;
	
	for (i=0; i<obL; i++) {
		if ((i!=obj.indexOf(" ",i)) && (a==null)) {
			a = i;
		}
		if ((i<obj.indexOf(" ",i)) && (a!=null)) {
			b = i + 1;
		}
	}
	return obj.slice(a, b);
}


function abre_fecha_teste(e, ed, n, max)
//-------------------------------------
{
//alert(e);
  var codTecla = [e.keyCode || e.which];
//alert(codTecla);
 if (codTecla == 9) {// tab
   
   return false;
 }

  if (codTecla == 13 || codTecla == 1 || codTecla == '') {// enter
    if (document.getElementById(ed+n).style.display=='none') {
      if (max>0) fecha_todos(ed,max);
      document.getElementById(ed+n).style.display='';
    }else{
      document.getElementById(ed+n).style.display='none';
    }
  }
}

function abre_fecha(ed, n, max)
//-------------------------------------
{
  if (document.getElementById(ed+n).style.display=='none') {
    if (max>0) fecha_todos(ed,max);
    document.getElementById(ed+n).style.display='';
  }else{
    document.getElementById(ed+n).style.display='none';
  }
}


function fecha_todos(ed, max)
//-------------------------------------
{
  for (n=1; n<=max; n++) {
    if (document.getElementById(ed+n)!=null) { 
      document.getElementById(ed+n).style.display='none';
    }
  }
}


function checkNum()
//---------------------------------------
// Só aceita teclas 0-9 e BackSpace
//---------------------------------------
{
  var codTecla = window.event.keyCode;
  
  if (codTecla == 8) // BS
    return true;
  if (codTecla < 48 || codTecla > 57) // <> 0-9 
    return false;

  return true; // Mostra
}


function fullDataEd(dt)
//--------------------------------------- 
// Autor: 	A. Batista
// Data: 	2005-08-25
// Entrada: Date
// Saida: 	Data formatada do tipo YYYY-MM-DD HH:MM:SS
//---------------------------------------
{
  var sep1 = "-"; 
  var sep2 = ":";
  var ano = dt.getFullYear();
  var mes = dt.getMonth()+1;
  var dia = dt.getDate();
  var hor = dt.getHours();
  var min = dt.getMinutes();
  var sec = dt.getSeconds();
  if (mes < 10) {mes = '0' + mes;} 
  if (dia < 10) {dia = '0' + dia;} 
  if (hor < 10) {hor = '0' + hor;} 
  if (min < 10) {min = '0' + min;} 
  if (sec < 10) {sec = '0' + sec;} 

  return ano + sep1 + mes + sep1 + dia + " " + hor + sep2 + min + sep2 + sec;
}


function LV_dialog(sURL, vArguments, Cod_Obj, Des_Obj) 
//--------------------------------------- 
// Autor: 	A. Batista
// Data: 	2006-02-05
//---------------------------------------
{
  var sFeatures = 'status:no; resizable:no; scroll:no; center:yes; help:no; dialogWidth:500px; dialogHeight:400px;';
  var x1 = showModalDialog(sURL, vArguments, sFeatures);

  if (typeof x1 != "undefined") { //fechar a janela
    if (x1) { //cancelar - false
	var x2 = x1.split("|");
	Cod_Obj.value = x2[0];
	Des_Obj.innerHTML = ""
	if (x2[1] != "") {
	    Des_Obj.innerHTML = x2[1] + " <SMALL class=label>(" + x2[0] + ")</SMALL>";
	}
    }
  } 
}


function seal_popup(cert) 
//---------------------------------------
{
  var url = "https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=" + cert + "&lang=pt";

  return cga_popup(url, '560', '500');
}

function cga_popup(url, w, h) 
//---------------------------------------
{
// var url = "https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn="+cert+"&lang=pt";
//&issuerSerial=
  var tbar;

  tbar = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no"
  tbar = tbar + ", width="+w+", height="+h+"";

  sw = window.open(url, 'CGA_popup', tbar);

  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
    if(sw) {
      sw.focus();
    } 
  }
}


function Add_Favoritos() 
//--------------------------------------- 
{
  //if (document.all) window.external.AddFavorite(location.href, document.title);

  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(document.title, location.href,"");
  } else if (window.external) { // IE Favorite
    window.external.AddFavorite(location.href, document.title); }
  else if (window.opera && window.print) { // Opera Hotlist
    return true; }

}
	

function Set_HomePage()
//--------------------------------------- 
{
  if (navigator.userAgent.indexOf("MSIE") != -1) {
    document.body.style.behavior='url(#default#homepage)';
    document.body.setHomePage("www.cga.pt");
  }
}


function doOpenPDF( form, pdfType )
//--------------------------------------- 
{
  try {
    document.getElementById('h_iPdfType').value = pdfType;
    document.getElementById(form).submit();
  }
  catch (e) {    
  }
}

function abrir_novaJanela(formId, url)
{
        var x = document.getElementById(formId);
        x.target="_blank";
        var lastURL = x.action;
        x.action=url;
        x.submit();
        x.target="";
        x.action = lastURL;
}



// resize largura paginas
// --------------------------------------

function changeWidth() {
	var cookie = readCookie("estilo");
  	var largura = cookie ? cookie : 'fix';
	var hL = document.getElementById("hLarguraEcra")
	var fL = document.getElementById("fLarguraEcra")	

	if (document.getElementById("ecraPagina")!=null) { 
		if (largura == 'max') {
			document.getElementById("ecraPagina").className = "ecraFix";
			hL.src = hL.src.replace(/go_fixo.gif/i, "go_largo.gif");
			fL.src = fL.src.replace(/go_fixo.gif/i, "go_largo.gif");
			createCookie("estilo", 'fix', 365);
		}
		if (largura == 'fix') {
			document.getElementById("ecraPagina").className = "ecraMax";
			hL.src = hL.src.replace(/go_largo.gif/i, "go_fixo.gif");
			fL.src = fL.src.replace(/go_largo.gif/i, "go_fixo.gif");
			createCookie("estilo", 'max', 365);
		}
	}
}

function createCookie(nome, valor, dias) {
  if (dias) {
    var date = new Date();
    date.setTime(date.getTime()+(dias*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = nome+"="+valor+expires+"; path=/";
}

function readCookie(nome) {
  var nomeEQ = nome + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nomeEQ) == 0) return c.substring(nomeEQ.length,c.length);
  }
  return null;
}


// -->

