
// file: ixmain.js
// coder ppires@assec.pt

 
 // document.writeln(' <SCRIPT LANGUAGE="JavaScript1.2" SRC="./db/funcoes/js/ixmenu.js"></SCRIPT>');
 // document.writeln('<SCRIPT LANGUAGE="JavaScript1.2" SRC="./db/funcoes/js/ixlv.js"></SCRIPT>');
 
/////////////////////////////////////////////// ////////////////////////////// 
  var ixSpace = new Object(); ///////  defenido  o meu  TableSpace   ///
///////////////////////////////////////////// // /////////////////////////////
  
  
  var ultimoYposTab = 0;
  var camposFechados = new Array(' ');
 
	function pesrapclick() {
	    var p = document.formpesqa ;

	    p.sortpesquisa.value = '';

	    return true;
	    }



    function LayerWH(layer,w,h){
        if (!layer) return;
		
        if (document.all){
         layer.style.width= w;
         layer.style.height= h;
			}
        else {
         layer.style.width= w;
         layer.style.height= h;
			}
    }
	
	function  LayerTopLeftWidth(nome, valor, left,width){
			var p = document.getElementById(nome);
			if (!p) return;
			p.style.top=	valor +'px';
			if ( left ) 
				p.style.left=	left +'px';
			if ( width ) 
				p.style.width=	width +'px';
					
			}
			
	function  LayerWidth(nome, valor){
			var p = document.getElementById(nome);
			if (!p) return;
			p.style.width=	valor +'px';
			}		

    function LayerVis(layer,modo){
        if (!layer) return;

        if (document.all)
         layer.style.display= modo;
        else
          layer.display= modo;

    }
	
	function alteraVisibilidade(nome, modo){
		var p = document.getElementById(nome);
		if (!p) return;
		
		 if (document.all)
         p.style.visibility= modo;
        else
          p.visibility= modo;
		}
    
	var ultObj;
	function getObj(valor){
		var ultObj= document.getElementById( valor );
		return  ultObj;
		}
		
    function GetHeight(layer){

     if (!layer) return 0;
     if (document.all) {
       if (false && layer.style.pixelHeight)
              return (layer.style.pixelHeight);
            else
               return (layer.clientHeight);
        }
      else {
            if (false && layer.style.pixelHeight)
              return (layer.style.pixelHeight);
            else
               return (layer.clientHeight);
        }
     return (-1);

    }




    function PosicionaLayer(layer,pposx,pposy){
     this.pposx = pposx;
     this.pposy = pposy;

      if (!layer) return;


      if (document.all) {
        layer.style.left=pposx+"px";
        layer.style.top=pposy+"px";
        layer.style.visibility= "visible";

        }
      else {
          layer.left = this.pposx;
          layer.top  = this.pposy;

          layer.visibility= "visible";

        }
      }

    


    function dia_valido(dia,mes,ano) {
            var daysInMonth = DaysArray(12)
            return  ( ( mes == 2 && dia>daysInFebruary(ano)) || dia > daysInMonth[mes] );
          }


    function daysInFebruary (year){
            return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
          }

    function DaysArray(n) {
	       for (var i = 1; i <= n; i++) {
		      this[i] = 31
		      if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		      if (i==2) {this[i] = 29}
             }
            return this
          }

  function dataValida(valor){
        if ( dia_valido( parseInt(valor.substring(8)), parseInt(valor.substring(5,2)),parseInt(valor.substring(0,4)) ) ){
            alert(valor+' é uma data invalida.');
            return false;
          }
         return true;
        }

	function ePar(valor){
		//alert( ''+valor+':'+ (Math.floor( valor / 2)  ) ) ;
		if  ( Math.floor( valor / 2) - valor/2  == 0) return true;
		return false;
		}
	
  function _elementocor(layer,cor,bordacor){



    var lspd =  document.getElementById(layer);
    if (!lspd) return;

    lspd.style.borderColor= bordacor;
    lspd.style.borderStyle = 'solid' ;

    lspd.style.borderWidth = 1;

    
    lspd.style.background = cor;


  }

 /////// TAB's I
 var cAb= new Array();
 var cAb_n = 0;
 
    function ver_data( valor, msg ){
        var tempof = /^([0-9]{4})(-[0-9]{2})(-[0-9]{2})?$/;

        if  ( !(valor.match(tempof)) ){ alert(msg + ' deverá ser no formato\n YYYY-MM-DD .'); return false; }

        return dataValida(valor);
      }

    function artigomode(valor,campo,lst){
		this.campo =  (campo) ?   campo : 'artigo';
		this.aLst = (lst) ? lst: cAb
		
		var l =false;
		if (valor == ''  ) return;  
		for (i=0; i < this.aLst.length ; i++ ){ //cAb_n 
			var u = document.getElementById(this.campo+'_'+this.aLst[i]);
			if ( !u )  continue;
			if ( this.aLst[i] == valor ) { var l = u; continue;}
	        setIZStyle(u, 'visibility:hidden; z-index:9;');  
			eval(' if ( '+this.campo+'modeFos'+this.aLst[i]+'!= undefined  ) if ( '+this.campo+'modeFos'+this.aLst[i]+' != \'\' )  eval('+this.campo+'modeFos'+this.aLst[i]+');   v = '+this.campo+'modeFos'+this.aLst[i]+'; ');
			
			}
             
	    if ( l ) setIZStyle(l,'position:absolute; top:16; visibility:visible; z-index:99; '); // l.style.visibility= 'visible';
		eval(' if ( '+this.campo+'modePos'+valor+'!= undefined  ) if ( '+this.campo+'modePos'+valor+' != \'\' )  eval('+this.campo+'modePos'+valor+');   v = '+this.campo+'modePos'+valor+'; ');
       
    } 


    function removecategoria(valor,txt){
        if ( ! confirm(txt) ) return;
         //   else alert(' ok');
      document.myform.d_thesaurus.value = valor;
      document.myform.submit();
    }

    function add_cat(limite){
        var pxp = document.myform;

        resultado = '';
        for(i=0; i < limite; i++ ){
            eval(' box = document.myform.cat_'+i+' ; ');
            if ( box.selectedIndex == 0 ) continue;
            resultado +=  box.options[box.selectedIndex].name;
            if ( resultado != '') resultado += ';';
            }
        pxp.h_thesaurus.value = resultado;

        pxp.submit();
        }


    function remove_list(cod,variavel){
     if ( cod == '' || variavel == '' ) return;
     if ( ! confirm('Deseja remover linha?') ) return;
     eval( "document.myform.del"+variavel+".value = "+cod+ " ;");

      document.myform.submit();
    }

    function modifica_list(cod, variavel, texto, pos){
     if ( cod == '' || variavel == '' ) return;
     if ( ! (temp = prompt('Deseja modificar ?',texto) ) ) return;

     eval( "document.myform.mod"+variavel+"_id.value = '"+cod+ "' ;");
     eval( "document.myform.mod"+variavel+"_valor.value = '"+temp+ "' ;");
     eval( "document.myform.mod"+variavel+"_p.value = '"+pos+ "' ;");

     document.myform.submit();
     }
 /////// TAB's  F
 
 //////////////////////////////////////////////////////////////////////////
   var last_pos = -1;
    function ix_autocomplet(campo, possiveis, nforcar, depois, e ) {
	   var  antigo  = campo.value;
	   var suguestao = '';
	   var encontrou =false;
	   
		for (var i = 0; i < possiveis.length; i++) 
			if (possiveis[i].toUpperCase().indexOf(campo.value.toUpperCase()) == 0 ){
				suguestao = possiveis[i];
				last_pos  = i;
				encontrou = true;
				break;
			}
		
		if( window.event)  keynum = event.keyCode;
		else if ( e.which)  keynum = e.which;	
			 
			
		var cursorKeys =";38;40;";
		if (cursorKeys.indexOf(";"+keynum+";") != -1) {
			if (keynum == 38) campo.value  = possiveis[ i< 1? 0: i-1];
			if (keynum == 40) campo.value  = possiveis[ i <  possiveis.length-1 ?i +1:0];
			if (campo.createTextRange){
				var rNew = campo.createTextRange();
				rNew.moveStart('character',0) ;
				rNew.select();
				} else  campo.setSelectionRange(0, campo.value.length);
				
			return;
			}
		 
		cursorKeys =";8;46;37;38;39;40;33;34;35;36;45;";
		if (cursorKeys.indexOf(";"+keynum+";") == -1) 
		   if (  suguestao != antigo ){
			 if ( nforcar ) {
				campo.value  =  suguestao;
				if ( suguestao.length < 1)
					mostraHint(campo, null,'Possíveis valores:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +  possiveis.join('<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'));
				}
				else  if ( encontrou ) campo.value  =  suguestao;
			
			if (campo.createTextRange){
				var rNew = campo.createTextRange();
				rNew.moveStart('character',antigo.length) ;
				rNew.select();
				}
			else  campo.setSelectionRange(antigo.length, campo.value.length);

			}
	
	if ( depois  )
			eval(depois+'();');
	}

 	
	function campo_autocompleto(campo, possibilidae, fechado, depois ){
		var l = document.getElementById(campo) ;
		if (!l) return ;
			
		if (fechado) {
			camposFechados.push(campo);
			if (!campo_autocompletoSimpres)
				var novoselector =CriaSelector(l,possibilidae);
				else 
				l.onfocus = function (event){
					mostraHint(this,null,'Possíveis valores:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+possibilidae.join('<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'));
				}
			l.onblur = function (event){ escondeHint(); }
			}
			
		l.onkeyup = function (event){ // 
			ix_autocomplet(this, possibilidae,fechado,depois, event );
			}
        }
	
	function  ciarTextArea(no,nome,valor,AStyleAttrib,aStyleValue){
		var novoNo =document.createElement('TEXTAREA');
		
	 	if (valor == '') valor= '';  
		//var textonmeditor = document.createTextNode( valor ); 
		novoNo.value = valor;
			
		if ( AStyleAttrib != null  )
				setIZStyle(novoNo,AStyleAttrib,aStyleValue);
		
		if ( nome != null) novoNo.setAttribute('name', nome);
			 else novoNo.setAttribute('name', 'xub'+ no.name);
		
		if ( nome != null) novoNo.setAttribute('id', nome);
			 else novoNo.setAttribute('id', 'xub'+ no.name);
		
		//novoNo.appendChild(textonmeditor);
		no.appendChild(novoNo);	 
		return novoNo;
	}
	
	function criaInput(no,nome,tipo,valor,AStyleAttrib,aStyleValue){
		
		var novoNo = document.createElement('input');
		
		if (tipo !=  '')  novoNo.setAttribute('type',tipo);
					
		if (valor!= '') novoNo.setAttribute('value', valor);
		 
			
		if ( AStyleAttrib != null && aStyleValue != null )
				setIZStyle(novoNo,AStyleAttrib,aStyleValue);
		
		if ( nome != null) novoNo.setAttribute('name', nome);
			 else novoNo.setAttribute('name', 'xub'+ no.name);
		
		if ( nome != null) novoNo.setAttribute('id', nome);
			 else novoNo.setAttribute('id', 'xub'+ no.name);
			 
		no.appendChild(novoNo);
			 
		return novoNo;
		}
	
	function CriaDivBefore(no,topo,nome,AStyleAttrib,aStyleValue){
		return  CriaDiv(no,nome,AStyleAttrib,aStyleValue,'1',topo)
		}
	function CriaDiv(no,nome,AStyleAttrib,aStyleValue,modo,topo){
		var novoNo = CriaObjBase('DIV',no,nome,AStyleAttrib,aStyleValue,modo,topo)
		return novoNo;
		}
	function CriaSpan(no,nome,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('SPAN',no,nome,AStyleAttrib,aStyleValue)
		return novoNo;
		}
	function CriaSpam(no,nome,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('SPAN',no,nome,AStyleAttrib,aStyleValue)
		return novoNo;
		}
	function CriaP(no,nome,AStyleAttrib,aStyleValue){
		return CriaPtxt(no,nome,'',AStyleAttrib,aStyleValue);
		}
	function CriaPtxt(no,nome,v,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('P',no,nome,AStyleAttrib,aStyleValue)
		CrialTextNode(novoNo,v);
		return novoNo;
		}	
		
	function CriaBtxt(no,nome,v,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('B',no,nome,AStyleAttrib,aStyleValue)
		CrialTextNode(novoNo,v);
		return novoNo;
		}	
	
    function CriaTextarea(no,nome,valor,AStyleAttrib,aStyleValue) { return ciarTextArea(no,nome,valor,AStyleAttrib,aStyleValue);}
	
	function CriaObjBase(tipo,no,nome,AStyleAttrib,aStyleValue,modo,topo){
		if (!tipo) return;
		var novoNo = document.createElement(tipo);
		
		if ( nome != null) novoNo.id = nome;
		 else novoNo.id = 'xub'+ no.name;
		
	 
		
        if ( no != null)
			switch(modo){
			case '1':
				no.insertBefore(novoNo, topo);
				break;
			default:
				no.appendChild(novoNo);	
				}
		
		if ( AStyleAttrib != null  )
			setIZStyle(novoNo,AStyleAttrib,aStyleValue);
		  
		return novoNo;
		}
		
	
	function CriaSelector(no,campos,valores){
		if (document.getElementById('select'+no.id))  return;
		
		var novoselect = document.createElement('SELECT');
		no.parentNode.appendChild(novoselect);
 		novoselect.id =  'select'+no.id ;
		copyIZStyle(no,novoselect, Array('position','top','left','width','z-index'), Array('relative','0px','4px','160','99') );
		setIZClass(novoselect,'select') 
		setIZStyle(novoselect,'width:'+getIZStyle(no,'width')+';');
		
		if (!isArray(campos) ) return;
		for (j=0;j < campos.length;j++){
			var opt = document.createElement('OPTION');
			if (  valores == null ) opt.value = campos[j];
				else opt.value = valores[j];
			opt.text = campos[j];
 			novoselect.options.add(opt, j);
			}
		 
		novoselect.selectedIndex= campos.valueOf(no.value);
		novoselect.onchange = function(){
			no.value = this.value;
			}
		return novoselect;
		}
	
	function CriaImagem(no,nome, vSrc,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('img',no,nome,AStyleAttrib,aStyleValue)
		
		novoNo.setAttribute('border','0px');	 
		if ( vSrc != null)
			novoNo.setAttribute('src',	vSrc);	
	 
		return novoNo;
		} 
		
	function CriaLink(no,nome, vLink,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('A',no,nome,AStyleAttrib,aStyleValue)
		
		if ( vLink != null)
			novoNo.setAttribute('href',	vLink);	
	 
		return novoNo;
		}
		
	function CriaLinkTxt(no, vLink,txt,nome,AStyleAttrib,aStyleValue){
		var novoNo = CriaLink(no,nome, vLink,AStyleAttrib,aStyleValue);
		CrialTextNode(novoNo,txt);
		return novoNo;
		}
	
	function CriaIframeBefore(no,nome, vLink,outros,AStyleAttrib,aStyleValue){
		return CriaIframe(no,nome, vLink,outros,AStyleAttrib,aStyleValue,'1')
		}
	function CriaIframe(no,nome, vLink,outros,AStyleAttrib,aStyleValue,modo){
		var novoNo = CriaObjBase('iframe',no,nome,AStyleAttrib,aStyleValue,modo)
		 
		novoNo.setAttribute('FRAMEBORDER',0);
		novoNo.setAttribute('border','0');
		if (outros != null){  
			var loutros = outros.split(';')
			for (i=0;loutros.length ; i++){
			    if ( ! loutros[i] ) break;
				var tmp = loutros[i].split(':');
				 
				if ( tmp.length < 2  ) continue;
				 
				novoNo.setAttribute(leftTrim(tmp[0]), leftTrim(tmp[1]) );
				 
				}
			}
			
		if ( vLink != null)
			novoNo.setAttribute('src',	vLink);		
	
		return novoNo;
		}
	
	
	function CrialTextNode(sNo,valor){
	/*	var novoNo = document.createTextNode( valor  );
		no.appendChild(novoNo);*/
		
		var txt =valor;
		var aTxt = txt.split('\n');
		
		if (aTxt.length < 0){ 
			var linhaN= document.createTextNode(  sTxt );	
			sNo.appendChild( linhaN );
			return;
		}
	 
		for(m= 0 ; m < aTxt.length; m++){
			var linhan = document.createTextNode(  aTxt[m] );	
			var ebr = document.createElement('BR');
			sNo.appendChild( linhan );	
			sNo.appendChild( ebr );  
			}
		
		}
   
    function CriaForm(no,nome,valor,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('form',no,nome,AStyleAttrib,aStyleValue);
		
		return novoNo;
		}
	
	function CriaBotaoSubmit(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'submit',AStyleAttrib,aStyleValue);
		}	
	function CriaBotao(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'button',AStyleAttrib,aStyleValue);
		}
	function CriaInputText(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'text',AStyleAttrib,aStyleValue);
		}
	function CriaInputHidden(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'hidden',AStyleAttrib,aStyleValue);
		}
	function CriaInputFile(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'file',AStyleAttrib,aStyleValue);
		}
	function CriaInputCheckBox(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'checkbox',AStyleAttrib,aStyleValue);
		}
	function CriaInputRadio(no,nome,valor,AStyleAttrib,aStyleValue){
		return CriaInput(no,nome,valor,'radio',AStyleAttrib,aStyleValue);
		}	
		
	function CriaInput(no,nome,valor,tipo,AStyleAttrib,aStyleValue){
		if (!tipo) tipo ='text';
		var novoNo = document.createElement('input');
		
		if ( nome != null) novoNo.id = nome;
		 else novoNo.id = 'xub'+ no.name;
 
		novoNo.setAttribute('type',tipo);
		novoNo.setAttribute('value',valor);
		novoNo.setAttribute('name', novoNo.id);

		
		if ( AStyleAttrib != null  ) setIZStyle(novoNo,AStyleAttrib,aStyleValue);
 
		no.appendChild(novoNo);	
		return novoNo;
		}
	
	/* criando tabelas */
	function CriaTabela(no,nome,AStyleAttrib,aStyleValue){
		var novoNo = CriaObjBase('table',no,nome,AStyleAttrib,aStyleValue);
		novoNo.setAttribute('cellspacing','0');
		novoNo.setAttribute('cellpadding','0');
		var novoNo = CriaObjBase('tbody',novoNo,nome,AStyleAttrib,aStyleValue);
		return novoNo;
		} 
		
	function CriaTabelaLC(no,nome,lc,AStyleAttrib,aStyleValue){
	    /* devolve array com os objecto td*/
		if (lc == '' || lc == null) return CriaTabela(no,nome,AStyleAttrib,aStyleValue);
		var aLC = lc.split(',');
		if (aLC.lengtht < 2 ){
			var l = aLC[0];
			var c = aLC[0];
			} else {
			    var l = aLC[0];
				var c = aLC[1];
				}
		var t = CriaTabela(no,nome,AStyleAttrib,aStyleValue);
		var rst = new Array();  
		for(i=0; i< l; i++){
			var itr =  CriaObjBase('tr',t)
			var trst = new Array;
			for(j=0; j< c; j++){
				var itd =  CriaObjBase('td',itr,nome +i+'c'+j);
				trst.push(itd);
				}
			rst.push(trst);
			}
		return rst;
		}
	 
/*  objecto avançados  ( inicio )  */
function CriaCaixa(nome, AStyleAttrib, aStyleValue){
	var  obj = document.getElementById('ixmain');
	if (!obj) return;
	setIZStyle(obj,'visibility:visible;');
	return CriaPainelFundo(obj,nome, AStyleAttrib, aStyleValue);
	}

 function CriaCaixaSimples(nome, AStyleAttrib, aStyleValue){

	var obj =  CriaCaixa(nome, AStyleAttrib, aStyleValue);
	var p = document.getElementById(nome+'fclose');
	if (p) setIZStyle(p,'visibility:hidden;');
	return obj;
	}
	
 function  fechaCaixa(){ fechapainel() }
 

 function CriaPainelFundo(obj,nome, AStyleAttrib, aStyleValue){
    
   inativaSelectores();
	var ql = CriaDiv( obj,nome,'z-index:199;'  );
	setIZClass(ql ,'layerbackground');
 
	var qb = CriaDiv( ql,nome+'fbg','width:760; height:520; background-color #CED5DB; filter:alpha(opacity=70); opacity: .7 ; ');
	setIZClass(qb,'layerbackgroundfundo');
	 
	var caixa = CriaDiv( ql,nome+'cx',AStyleAttrib, aStyleValue  );
	maximiza(qb); 	 
	
	window.onresize = function (){
	    var qb=  document.getElementById(nome+'fbg'); 
		if (!qb) return ;
		maximiza(qb);
		}
	 
	var qnl = CriaLink(ql,nome+'fclose','javascript://')
	setIZClass( qnl,'layerbackgroundbotao');
	CriaImagem(qnl,'','imagens/agenda/bfecha.gif')
	qnl.onclick= function (){
		//obj.innerHTML = '';
		fechapainel();
		activaSelectores(); 
		}
	return caixa;
	}
	
	function CriaPainelFundoBTclose(nome, AStyleAttrib, aStyleValue){
		var p = document.getElementById(nome+'fclose'); if (!p) return '';
		setIZStyle(p , AStyleAttrib, aStyleValue);
	}
	
	function inativaSelectores(){
		var  lstse = document.getElementsByTagName("SELECT");
	  
		for( i=0; i< lstse.length; i++ )
				setIZStyle(lstse[i],'display:none;')	
		}

    function activaSelectores(){
		var  lstse = document.getElementsByTagName("SELECT");
		 
		for( i=0; i< lstse.length; i++ )
				setIZStyle(lstse[i],'display:block; position:relative; top:-20px; left:4px; z-index:99; width:160;')	
	 		} 	
    	
	
	function fechapainel(){
			var p=  document.getElementById('ixmain'); if (!p) return ;
			p.innerHTML = '';
			activaSelectores();
			setIZStyle(p,'visibility:hidden');
			}
	
/* objecto avançados   ( fim ) */

   
	
	function campo_valor(nome){
		var p=  document.getElementById(nome); 
		if (!p) return  '';
		return p.value;
		}
	 
	 
    function campo_inicioF(campo, valor ){
		return campo_inicio(campo, valor, true )
		}
	 
	function campo_inicio(campo, valor, forca ){
		var l = document.getElementById(campo) ;
		if ( !l ) return;
		if ( forca ) {
			l.value =  valor;
			}
		else 
			if (l.value =='') l.value =  valor;
			
		if ( camposFechados.join(', ').indexOf(campo) != -1 ) {	 
			var p= document.getElementById('select'+campo) ;
			if (!p) return;
			  
			for( i=0; i < p.options.length; i++ ) 
				if ( p.options[i].value == valor) {
					p.selectedIndex = i;
					break;
					} 
				 
			}
		}
 
	function campo_disable(campo){
		var l = document.getElementById(campo);
		if (!l) return ; 
		l.disabled= true;
		l.style.backgroundColor = '#E9ECEF';
		 
		if ( camposFechados.join(', ').indexOf(campo) != -1 )  
			alteraVisibilidade('select'+campo,'hidden');
		}
	
 function valorDe(dE){
	var p = document.getElementById('entidadeP_'+dE); if (!p) return '';
	return escape(p.value);
	}
			
//////////////////////////
 var ratoNoHit = 0;	
 var ratoNoOBJ = 0;	 
 function mostraHint(obj,e,sMSG){

	var pixpainel = document.getElementById('ixpainel');
    if ( !pixpainel ) return;
	
	if (e) {
		Xpos = e.pageX || (window.event.x + document.body.scrollLeft);
		Ypos = e.pageY || (window.event.y + document.body.scrollTop) ;  
		}
	 else { 
		Xpos = findPosX(obj) ; 
		Ypos = findPosY(obj) +13 ;  
		}
 	
	pixpainel.innerHTML= '<div id ="xixpainel" class="painelhint" style="position:absolute;   filter:alpha(opacity=79); top:0; left:15;">'+sMSG+'</div>';

	var largura =  parseInt(document.body.clientWidth) || parseInt(document.documentElement.clientWidth ); 
	var altura =  parseInt(document.body.scrollHeight); 
	var ppainelhint = document.getElementById('xixpainel');
	 
	
    if ( largura  <  Xpos  + 240) Xpos = Xpos - 184  ;
 	 
	pixpainel.style.left = Xpos +6 ;
	pixpainel.style.top = Ypos +6;
		
	var alturaAgora =  parseInt(document.body.scrollHeight)  ; 
		
	if  (alturaAgora > altura) 
			pixpainel.style.top = Ypos - (alturaAgora - altura)*2;

	pixpainel.style.visibility= "visible";
	
	ratoNoOBJ = 1;
	obj.onmouseout = function (){ ratoNoOBJ = 0;  }
	pixpainel.onmouseover = function (){ ratoNoHit = 1; }
	pixpainel.onmouseout  = function (){ ratoNoHit = 0; }
	
	setTimeout('escondeHint()',200);
	 
	return pixpainel;
	}			
 
 
 
 
 function escondeHint(){
	 if  (ratoNoHit == 0 && ratoNoOBJ == 0){
		//document.getElementById('ixpainel').innerHTML = '';
		return fadoutHint();
		}
	 setTimeout('escondeHint()',200);
	}
 
 
  
 function fadoutHint() {
    
	var l= document.getElementById('ixpainel').innerHTML = '';
	l.innerHTML ='';
	return;
	if ( document.all ){
	 	var opacidade = l.filter.alpha.opacity - 12;
	 	l.filter.alpha.opacity = opacidade;	
		}
	else {
		//l.style.MozOpacity = 0.85 ;
		l.innerHTML ='';
		}
	if (opacidade < 5 )
		l.innerHTML ='';
	 else setTimeout("fadoutHint()",50);
	
	}
 
  	
	
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}



 function Abusca(lista,buscar){
    var sLista = lista.toString();
	var sPos;
	 
	if ( ( sPos= sLista.indexOf(buscar) ) < 0  ) return -1;
	
	sLista =  sLista.substr(0,sPos);
	var tlista = sLista.split(','); 
	return tlista.length -1;
	}
 
 
 function  vesteTabName(pTabName,myOffset,topOffset){
	var pTab = document.getElementById(pTabName); 
	if (!pTab) return;  
	return;
    setIZStyle(pTab,"background-image: url('imagens/der/cte.gif'); background-position: 0 0; background-repeat: no-repeat;");
    
 
	var canto= document.getElementById( pTabName+'canto');
	if (!canto ) {
	    var canto = CriaImagem(pTab,pTabName+'canto','imagens/der/cte.gif');
		// ,'position:relative;  left:-3px; z-index:109;'
		//var canto = document.createElement('img');
		//canto.setAttribute('border','0');
		//canto.setAttribute('id', pTabName+'canto');
		}
	
	var esquerda = (pTab.offsetLeft -7); 
	if (myOffset) esquerda = (esquerda  +myOffset);
	if (topOffset) topo = topOffset;
		else topo= '2';
	
 	setIZStyle(canto, Array('position','top','left','z-index'), Array('absolute',topo+'px',esquerda,'99'));  
	
	//canto.setAttribute('src','imagens/der/cte.gif');
	//pTab.appendChild(canto);
	 
	}
 
 

// dreamweaver stuff
 function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

/* Functions that swaps images. */
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}			
  
function leftTrim(sString) 
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
return sString;
}


function maximiza( obj ){
 
 var largura = 0;
 var altura = 0;
 
if (self.innerWidth)
	{
		largura = self.innerWidth;
		altura = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		largura = document.documentElement.clientWidth;
		altura = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		largura = document.body.clientWidth;
		altura = document.body.clientHeight;
	}
	else return;
	 
 	if (document.body.scrollHeight > altura)
 		altura =  document.body.scrollHeight ;
	 
	setIZStyle(obj,Array('width','height'),Array(largura+'px' ,altura+'px') );

	}
  
   
function isin_array(a, valor){
  if ( !isArray(a) ) return -1;
  for(i=0; i< a.length;i++)
	if (a[i] ==  valor ) return i;
  return -1;
} 
 
 
function is_array(variavel) {
   return  isArray(variavel);  
}

function isFunction(a) {
    return typeof a == 'function';
}
function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
  function isArray(a) {
    return isObject(a) && a.constructor == Array;
}


  
   function setIZClass(obj,valor) { 
	  if ( !document.all) obj.setAttribute('class',valor);
				else obj.setAttribute('className', valor);
	}
  
  function setIZStyle(obj,nomes,valores) {
     
	if ( !obj ) return;
	 
	if ( isString(nomes) ){
		if ( !document.all ){
			obj.setAttribute('style',nomes);	
			return;
			}
		
	    tmp = nomes.split(';');
		 
		if ( isArray(tmp) )
		for (i=0; i < tmp.length; i++){
		    if ( tmp[i] == undefined  || tmp[i] == '' ) continue;
			var tmpa = tmp[i].split(':');
			if ( isArray(tmpa) )
				if ( tmpa[0] != undefined 
					&& tmpa[1] != undefined 
					&& tmpa[0] != '' 
					&& tmpa[1] != '' 
					)  obj.style.setAttribute(tmpa[0].replace(/ /,""),  tmpa[1].replace(/ /,"")); 
					   
			} 
		 
		return;
		} 

	if ( nomes == null || valores == null) return;
	if ( !document.all){ 
			var estilo= '';
			for(var i=0 ; i	< nomes.length; i++)
				estilo = estilo + nomes[i]+':'+valores[i]+'; ';
			obj.setAttribute('style',estilo);		
			}
		else
			for(var i=0 ; i	< nomes.length; i++)
				obj.style.setAttribute(nomes[i],valores[i]);
			
	}

  
  


////////////////////////////////////////////////////////////////////// 
////////////////////////////////////////  ObjPainelSeletor  ////////////// 
	
    //
	ixSpace.ObjPainelSeletor = function(){ 
		this.valorSelect = new Object();
		this.lstNovos = new Array();
		this.updCampo = ''; 
		this.ixFe =false;
		}
	//
	ixSpace.ObjPainelSeletor.prototype = {
		getvalor: function (){
 			//return ixSpace.ObjPainelSeletor.valorSelect ;
			return  this.valorSelect;
			},
		setvalor: function (v){ 
			ixSpace.ObjPainelSeletor.valorSelect = v;
			this.valorSelect = v;
			return ;
			},
			
		getUpdCampo: function(){
			return this.updCampo;
			}, 
		setUpdCampo: function(v){
			this.updCampo = v;
			ixSpace.ObjPainelSeletor.updCampo = v;
			},	
			
		render:function (campo,v ){
			this.XMLselect = v;
			this.setUpdCampo(campo);
          
		    ixSpace.ObjPainelSeletor.lstNovos = new Array();
			 
			var painel =  this.fVisual(v);
	          	
			painel.bAdd.onclick = this.fAdd;
		 	painel.bok.onclick = this.onbtok;
			painel.bcancel.onclick= this.onbtcancel;
               	
			return painel ;
			},  
		  
		onbtok: function (){
			fechaCaixa(); 
			},
		onbtcancel: function (){
			fechaCaixa(); 
			}
		}
 
	ixSpace.ObjPainelSeletor.prototype.fVisual = function (XMLselect){
 
        var p = CriaDiv(CriaCaixaSimples(),'','position:absolute; top:120px; left:85px; width:511px; height:300px;');
		setIZClass( p,'menuprincipal');
		CriaPtxt( p,null,'Alunos','position:relative; left:22px; top:13px; ');
		CriaPtxt( p,null,'a adicionar','position:absolute; left:266px; top:13px; ');
		this.ixFe = CriaIframe( p,'',XMLselect,'width:220; height:200;','position:absolute; left:23px; ');
		
		this.bAdd = CriaBotao( p,null,'>','position:absolute; left:248px; top:63px; ');
		  
		var l = CriaDiv( p,'painel','position:absolute; left:266px; top:33px; width:220; height:200; ');
		setIZClass( l,'menuprincipal');
		 
		var bs = CriaDiv( p,null,'position:absolute; left:275px; top:266px;');
		this.bcancel = CriaBotao( bs,null,'Cancelar');
		this.bok = CriaBotao( bs,null,'Ok','position:relative; left:66px; width:68;');
 
		return this; 
		}	
	//
	ixSpace.ObjPainelSeletor.prototype.fAdd = function (){
		v = ixSpace.ObjPainelSeletor.valorSelect  ; 
       
		if (v =='') return;
		var partes = v.split('|');
		 
		ixSpace.ObjPainelSeletor.actualizaCampo(partes[0]);
		 
		var l =  document.getElementById('painel');
		var q =CriaLinkTxt(l,'#'+partes[0],partes[1]+',');
		q.onclick = function (){
		    var c = this.firstChild.nodeValue.length - 1;
		    var tmp = this.firstChild.nodeValue.substr(0,c);
		    if (!confirm("Deseja remover '"+tmp +"' da lista ?") ) return;
		    var parte = this.href.split('#')
			
			var a =  ixSpace.ObjPainelSeletor.lstNovos;
			//var b = parte[1];
			//var total= '';	
			
			for(i=0;i < a.length; i++)
			    if  (a[i] == parte[1] ) 
					ixSpace.ObjPainelSeletor.lstNovos.pop(i);
		 
			var p = document.getElementById(ixSpace.ObjPainelSeletor.updCampo);
			if (!p) return;
		
			p.value = ''; 
			for (i=0; i < a.length ; i++)
				p.value += ixSpace.ObjPainelSeletor.lstNovos[i]+';' 
				
			alert(p.value);	
				
			}	 
		}
	//
	ixSpace.ObjPainelSeletor.actualizaCampo = function (v){
		if ( v == '') return;
		var p = document.getElementById(ixSpace.ObjPainelSeletor.updCampo);
		if (!p) return;
		 
		ixSpace.ObjPainelSeletor.lstNovos.push(v);
		var limite = ixSpace.ObjPainelSeletor.lstNovos.length;
		 
		p.value = '';
		for (i=0; i < limite ; i++)
			p.value += ixSpace.ObjPainelSeletor.lstNovos[i]+';' 
		}	
 
	
	var ObjPainelSeletor =  ixSpace.ObjPainelSeletor;
////////////////////////////////////////  ObjPainelSeletor  ////////////// 
////////////////////////////////////////////////////////////////////// 


////////////////////////////////////////  ObjPainelIfram  ////////////// 
////////////////////////////////////////////////////////////////////// 
  
  ixSpace.ObjPainelIframe = function (url,titulo,sStyle){
	this.url  = url;
	this.titulo = titulo;
	
	this.render = render;
	if (!sStyle) this.sStyle = 'width:620; height:465;','position:absolute; left:23px; '
		else this.sStyle = sStyle;
	
	this.cxStyle = 'position:absolute; top:13px; left:25px; width:660px; height:515px;';	
 	this.comOK = true;
	var pFrame;
    var bok;
	var _Obj = this;
	
	
    function render(){ 
		var p = CriaDiv(CriaCaixaSimples(),'',this.cxStyle );
		setIZClass( p,'menuprincipal'); 
		CriaPtxt( p,null,_Obj.titulo ,'position:relative; left:22px; top:13px; ');
		 
		var iFru = CriaIframe( p,'',this.url,this.sStyle);
		var bs = CriaDiv( p,null,'position:absolute; left:500px; top: 6px;');
	 
		if (_Obj.comOK ){
			this.bok = CriaBotao( bs,null,'Fechar','position:relative; left:70px; width:68;');
			this.bok.onclick = 	fechaCaixa;
			}
		this.pFrame = iFru;
		return p;
		}
	
  
  
  
	}
var ObjPainelIframe =  ixSpace.ObjPainelIframe;
////////////////////////////////////////  ObjPainelIfram  ////////////// 
////////////////////////////////////////////////////////////////////// 

////////////////////////////////////////  ObjAnimMenu  /////////////// 
////////////////////////////////////////////////////////////////////// 

ixSpace.ObjAnimMenu = function (layer,rootLayer,dh,maxH){

		this.layername= layer;
		
		this.objMenu = document.getElementById( layer ); 
		if (! this.objMenu ) return false;
		
		this.rootLayer = document.getElementById( rootLayer );
		if (! this.rootLayer ) return false;
					 
		this.dh =  (dh) ? dh : 13;
		
		this.maxH = (maxH) ? maxH : this.objMenu.clientHeight;   
		 
		this.minH = 22;
		this.curH = this.maxH;

		this.Minz = pMinz;
		this.Maxz = pMaxz;
		this.goMinz = pgoMinz; 
		this.ini = pIni;
		this.esperarEmCima =esperarEmCima;
		
		
		this.painelObj = false;
		this.painelInnerHTML = '';
		this.parouMin = false;
		this.parouGo = false;
		this.ratocima = false;
		this.ticTac = 50;
	
		var  pObj = this;
		
		function pgoMinz(){
			if ( pObj.parouGo ) return; 
			 
			pObj.objMenu.onmouseover = function () { 
				pObj.parouMin = true; 
				pObj.ratocima = true;
			//	inativaSelectores();
				if (pObj.parouGo) setTimeout( function () {  pObj.Maxz();} ,pObj.ticTac );   
				 else setTimeout( function () {    pObj.esperarEmCima();} , pObj.ticTac*8);   
			 
				this.onmouseout = function () { 
					pObj.ratocima = false;
				}
			} 
		
		 
 
			pObj.parouMin = false; 
			pObj.Minz();
			}
			
		function esperarEmCima(){
			if ( !pObj.ratocima ) return ; 
			inativaSelectores();
			pObj.Maxz();
			}
		
		
		function pMinz(){
			if (pObj.parouMin) return;  
			if ( pObj.ratocima ) return 
			
			this.parouGo = true;  
			
			
			this.curH = (this.curH - this.dh);
			if ( this.curH <  this.minH )  this.curH =  this.minH  ;
			
			setIZStyle(this.objMenu, 'height:'+ this.curH+'; overflow:hidden; ');  
				
			if ( this.curH ==  pObj.minH ||  this.parouMin   ) { 
				this.parouMin =false;
				pObj.parouGo = false;
				pCriaMostraCaminho();
				activaSelectores();
				return;
				}
			else
				setTimeout(function () {  pObj.Minz();} ,this.ticTac);	
			}
			
		function pMaxz (h){
			pObj.parouGo = true;

			pRemoveMostraCaminho();
			
			pObj.curH = pObj.curH +pObj.dh*2;
			if (pObj.curH > pObj.maxH ) pObj.curH = pObj.maxH
 
			setIZStyle(this.objMenu, 'height:'+pObj.curH+'; overflow:hidden; ');  
			
			if (pObj.curH == pObj.maxH) { 
				pObj.parouMin =false;
				pObj.parouGo = false;
				activaSelectores();
				return;
				}
			else
				setTimeout( function () { pObj.Maxz(); } ,pObj.ticTac);	
			}	
		
		function pCriaMostraCaminho(){  
			if ( pObj.painelObj ) return;
		    pObj.painelObj = CriaDivBefore(pObj.objMenu, pObj.objMenu.childNodes[0],'painelcaminho','position:relative; left:0; top:0;  background-color:#ffffff; height:26px;  z-index:199; '  );
			pObj.painelObj.innerHTML =    pObj.painelInnerHTML;	
			}
		
		function pRemoveMostraCaminho(){
		   
		   if ( pObj.painelObj ) pObj.objMenu.removeChild(pObj.painelObj);
		   pObj.painelObj = false;
		   }
		
			
		function  pIni(){
			pObj.rootLayer.onscroll = function (){
				setTimeout( function() { inativaSelectores(); pObj.goMinz(); } , 200);
				return false;
				}
				
			pObj.objMenu.onmouseover = function () { 
				pObj.ratocima = true;
				}
			
			}
	   
		
		}
			
	var ObjAnimMenu = ixSpace.ObjAnimMenu ;
////////////////////////////////////////  ObjAnimMenu  //////////////// 
////////////////////////////////////////////////////////////////////// 
  
  
  

	
//////////////////////////////////////////////////////////////////////   
/////////////////////////////////////   estilo arendondado    ////////////// 

 function aredonda(o,bk,color,size){  
	
	setIZStyle(o, 'backgroundcolor:'+bk+';'); 
	aredondaTopo(o,bk,color,size);
	aredondaBase(o,bk,color,size);

	}

 function aredondaTopo(el,bk,color,size){
	var i;
	var d=document.createElement("b");
	
	
	var cn="r";
	var lim=4;
	if(size && size=="small"){ cn="rs"; lim=2}
	//d.className="rtop";
	setIZClass( d,'rtop');
	//d.style.backgroundColor=bk;
	
	setIZStyle(d,'backgroundcolor:'+bk+';');
	 
	for(i=1;i<=lim;i++){
		var x=document.createElement("b");
		//x.className=cn + i;//x.style.backgroundColor=color;
		setIZClass( x,cn + i);
	 	setIZStyle(x,' background-color:'+color+'; ');
		//x.className=cn + i;//
		//x.style.backgroundColor=color;
		d.appendChild(x);
		}
	
	el.insertBefore(d,el.firstChild);
	}
 function aredondaBase(el,bk,color,size){
	var i;
	var d=document.createElement("b");
	var cn="r";
	var lim=4;
	if(size && size=="small"){ cn="rs"; lim=2}
	//d.className="rbottom";
	
	setIZClass(d,'rbottom' );
	setIZStyle(d,'background-color:'+bk+';');
	d.style.backgroundColor=bk;
	for(i=lim;i>0;i--){
	    var x=document.createElement("b");
		
//	    x.className=cn + i;
 	   
		setIZClass( x,cn + i);
	 	setIZStyle(x,'background-color: '+color+';');
		 x.style.backgroundColor=color;
		d.appendChild(x);
		
	    
	    }
	el.appendChild(d,el.firstChild); 
	}  
/////////////////////////////////////   estilo arendondado    ////////////// 
////////////////////////////////////////////////////////////////////// 
  
///////////////////////////////////////////////////  
////////////////////////  defenições globais  /////////
var campo_autocompletoSimpres  = false;


////////////////////////////////////////////////////
//  Interface com o FCKEditor
////////////////////////////////////////////////////

///////////////////////////////////////////////////
//  Interface com o FCKEditor
////////////////////////////////////////////////////

 function activaFck_____(campo, altura,template){
     
	if ( !campo  )  return;
	
	setTimeout( function (){
 
			var oFCKeditor = new FCKeditor( campo ) ;
 
			oFCKeditor.BasePath = "../templates/FCKeditor/" ;
 
			if (template){
				oFCKeditor.Config['EditorAreaCSS'] = '../../../../includes/'+template+'/FCK.css' ;
				oFCKeditor.Config['ToolbarComboPreviewCSS'] = '../../../../includes/'+template+'/FCK.css' ;
				}
				
			if (altura) oFCKeditor.Height = altura;
			
			oFCKeditor.ReplaceTextarea() ;
			}, 200 );
 
	}

  function trocaTab(valor,campo,lst,offsetY){
		this.campo =  (campo) ?   campo : 'artigo';
		this.aLst = (lst) ? lst: cAb
		if ( offsetY != null ) this.offsetY = parseInt(offsetY);
			else this.offsetY = 0;
		
		
		var l =false;
		if (valor == ''  ) return;  
		for (i=0; i < this.aLst.length ; i++ ){ //cAb_n 
		    
			var u = document.getElementById(this.campo+'_'+this.aLst[i]);
			if ( !u )  continue;
			if ( this.aLst[i] == valor ) { var l = u; continue;}
	        setIZStyle(u, 'visibility:hidden; z-index:2;');  
			eval(' if ( '+this.campo+'modeFos'+this.aLst[i]+'!= undefined  ) if ( '+this.campo+'modeFos'+this.aLst[i]+' != \'\' )  eval('+this.campo+'modeFos'+this.aLst[i]+');   v = '+this.campo+'modeFos'+this.aLst[i]+'; ');
			
			}
        paraImprimir = this.campo+'_'+valor;	
		if ( l ) {
			var w = document.getElementById('tabMenu'+campo);
			if (!w) psTop = 68;  else psTop =GetHeight(w) + this.offsetY ;
		 
			setIZStyle(l,'position:absolute; top:'+psTop+'; left:0; visibility:visible; z-index:99; '); // l.style.visibility= 'visible';
			}
		eval(' if ( '+this.campo+'modePos'+valor+'!= undefined  ) if ( '+this.campo+'modePos'+valor+' != \'\' )  eval('+this.campo+'modePos'+valor+');   v = '+this.campo+'modePos'+valor+'; ');
       
    } 

	
	


