/*
	Assec 2008 ixPP  12.0  ( acesso )
 // 	
 // 
 //
 //       Coder  ppires@assec.pt
 //       file ixmenu.js( pagina principal)

*/



 


function  fviewn(){
    var now=new Date()

    v=(now.getSeconds())*10000 + (now.getMinutes())*1000 +
        (now.getDate())*100 + (now.getMonth())*100+(now.getHours()) ;
    v=v+1;
   return v;
}

function ixlpfuncao(value,lingua,expires,path,domain,secure) {


     ixpos(value,0,0,"",expires,path,domain,secure,"","",lingua);
    }



function ixfuncao(value,expires,path,domain,secure) {


     ixpos(value,0,0,"",expires,path,domain,secure,"")
    }

function ixpos(cix,pos,ppos,tix,expires,path,domain,secure,mix,email,lingua){

        zix = cix;

        valor = location.href.split('?');

        location.href=valor[0]+ '?cix='+escape(cix)
                +( (email) ? '&email='+escape(email) : '')
                +"&pos="+escape(pos)+ "&ppos="+escape(ppos)+ "&tix="
                +escape(tix)+ "&mix="+escape(mix)
                +"&mono_lang="+ escape(lingua)
                +"&v="+escape(fviewn());
      }


    
//window.captureEvents(event.RESIZE);   
window.onresize=ixredimensiona;
 function ixredimensiona(){
  //posicionaIMGTopo();
     
       }
    
      
//window.onscroll=ixscroll;
 function ixscroll(){
 // posicionaIMGTopo();
     
       }


// funcoes  do menu
function IxshowMenu(menu, x, y, child) {
       this.xi=0;
       
        if ( menu == null  ) return;
       var e = e || window.Event || window.event;
      // var posY =   window.pageY  || e.clientY;     
       
         if (document.all) {
                var pos =document.all.Layer2.offsetTop+1 ;

                }
          else {
                var pos = document.Layer2.offsetTop+1 ;
                }
                  
     
     // var  pos =  parseInt(posY)  +7  + document.body.scrollTop; 
       pos = pos+y;
 
     
       var xi =x+  (parseInt( document.body.clientWidth)-775)/2   ;
       if ( document.body.clientWidth < 775)
              xi =x;
       
               //      x =  x - parseInt((parseInt( document.body.clientWidth)-775)/2); 
        
           
     // MENUPOS.innerHTML = "  x-"+x+"    w-"+ document.body.clientWidth+"   xi- "+xi+"   valoer-"+ ((parseInt( document.body.clientWidth)-775)/2)+x; 
        showMenu(menu, xi, pos );
             
        
        }



function LeftShowMenu(leftmenu,posicao){
   this.leftmenu = leftmenu;
   this.posicao = posicao ;
   
  
   if (! posicao ) return;
    
   if (! leftmenu ) return;
//     alert('chegou2');
   var e = e || window.Event || window.event;
   var posY = e.pageY || e.clientY; 
 
   var lagura = 0;
   if  (posicao== 1)  lagura = 357;
   if  (posicao== 2)  lagura = 417;
   if  (posicao== 3)  lagura = 470;
   if  (posicao== 4)  lagura = 540;
   if  (posicao== 5)  lagura = 630;
   if  (posicao== 6)  lagura = 712;
   
  if ( this.leftmenu == null  ) return;
  
  var pos = (parseInt(document.body.clientWidth ) -780)/2+lagura  - parseInt(this.leftmenu.menuItemWidth)  ;
   
   if ( document.body.clientWidth < 780)
        pos = lagura - parseInt(this.leftmenu.menuItemWidth); 
  leftmenu.childMenuDirection = "left";
  

  
  

 // var posicaoY =document.all.Layer2.offsetTop+1; 
        if (document.all) {
                var posicaoY =document.all.SuperContentor.offsetTop+1 ;

                }
          else {
                var posicaoY = document.SuperContentor.offsetTop+1 ;
                };

  
   //if  (posicao== 1) 
   posicaoY = posicaoY+24;
 /*  if  (posicao== 2)  posicaoY = posicaoY+20;
   if  (posicao== 3)  posicaoY = posicaoY+39;
   if  (posicao== 4)  posicaoY = posicaoY+48;
   if  (posicao== 5)  posicaoY = posicaoY+37;  */
   
 showMenu(this.leftmenu, pos ,posicaoY);
  
  
    for (var i=0; i < this.leftmenu.childMenus.length; i++) {
      
            this.leftmenu.childMenus[i].childMenuDirection = "left";
        }
}

function showMenuButton(buttonmenu,x){
       this.buttonmenu = buttonmenu;
       this.x= x;

      var e = e || window.Event || window.event;
    //  var posY = e.clientY || e.pageY;
        var posY =document.all.imageButton.offsetTop+15;
     
        
       x = x+ (parseInt(document.body.clientWidth ) -775)/2;
       if ( document.body.clientWidth < 775)
                x= x-(parseInt(document.body.clientWidth ) -775)/2;
                
       
        if ( this.buttonmenu == null  ) return;
        
    //   var posicao =  parseInt(posY)  -15 -  parseInt(this.buttonmenu.items.length)*20 + document.body.scrollTop;
          var posicao =  parseInt(posY)  -15 -  parseInt(this.buttonmenu.items.length)*20 ;
       
      showMenu(buttonmenu,x,posicao);
      
  }

 function PosicionaLayer(layer,pposx,pposy){
     this.pposx = pposx;
     this.pposy = pposy;
    
      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 posicionaIMGTopo(){
     var  l= new Object ;
     var posx= 0;
     var posy= 0;
     
     if (document.all){ l =  document.all;  }
       else {
         l =  document;
          };
     
     if (document.all) {
       // posiciona  left
           if ( document.body.clientWidth > 785)
              posx= (parseInt(document.body.clientWidth ) -785)/2;
  
           }
      else {
                // posiciona  left
           if ( document.body.offsetWidth > 785)
              posx= (parseInt(document.body.offsetWidth ) -785)/2;
       
            }
              
     
   
      // posicionar top
      var posy= 0;
      if (document.all)  {
        
             posy= (parseInt( document.body.offsetHeight) - parseInt( l.SuperContentor.clientHeight  )    )/2 -2  ;
      }
         else
                  posy= (parseInt(document.height) - parseInt( l.SuperContentor.clip.height)    )/2 -2  ;
       
      
       // if (posy < 0  ) 
       posy = 0;
      
      //  if (document.all){ }
      //        else  posy = 0;

        window.posx = posx;
        window.posy = posy;
        
      // posiciona top de  botton
   
          
      PosicionaLayer( l.LayerCorpo,posx,posy);
     // PosicionaLayer( l.LayerTopo,0+0,0+0);
      PosicionaLayer( l.SuperContentor,posx,posy);
    
   //  if ( window.ActiveMenu )  hideActiveMenus(window.ActiveMenu);
};
      
      
      */
      
function mostraP(mix){
   ixpos(0,0,0,0,0,0,0,0,mix)
    };
    

function ixposPesquisa(cix,pos,ppos,tix,pesquisado,path,domain,secure,expires){
 
     
     document.cookie = "cix=" + escape ('busca')+ "; expires=" +  "";
    
     document.cookie = "pesquisa=" +escape(pesquisado)+ "; expires=" +  "";
     
     document.cookie = "ppos=" +escape(ppos)+ "; expires=" +  "";
       

    var v=fviewn();
    
    
    if ( document.cookie == ''){      
     
            location= "main.php?cix=busca&pesquisa="+pesquisado;
            }
       else location="main.php?v="+v; 
        
  };
  

    
function    busca(pesquisado){
 
  var v=fviewn();
    
  location= "main.php?cix=busca&pesquisa="+pesquisado+"&v="+v;

}


       
       
 var lastmenu = '0';
     
 function AlteraMenu(pmenu){
     if (pmenu =='') return;
     var  l= new Object ;
     
     l = eval( 'document.all.'+pmenu);
    
   
    
     if   (!(l.style.display  == 'none')  )
                l.style.display = 'none'; 
              else {
                    l.style.display = 'block'; 
                     lastmenu = pmenu;
                     }
                     
     posicionaIMGTopo();
   
     pcontentorresized();
   
     }
     
     
  function ixmp(value,pos,value2,expires,path,domain,secure){
      
        ixpos(value,pos,value2,"",expires,path,domain,secure,"");  
        }
  
  
  
  
  
 function escreve_cookie(nome,valor,expires,path,domain,secure) {
 
   document.cookie =
     nome + "=" + escape (valor) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + "assec.pt" : "") +
    ((secure) ? "; secure" : "");

  }

 function ixIMGMax(imgname,top){
        fixIMGMax(imgname, top )
   }
   
 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 findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
         
 function fixIMGMax(imgname,top,obj){
    var l = document.getElementById('lixgMax');
	if (!l) return;
	
    //if (!l.visibility )
	l.style.visibility= "hidden";
	//	else l.visibility = "hidden";
	if (!top) top = 100;
	   
	 top = (top +8); 
	 
	 var left = findPosX(document.getElementById('asseccentro')) + 100;
	 
	document.getElementById('ixImg').src = 'db/imagens/0.gif';   
   
	if ( imgname.indexOf('0.gif.lp') > 0 ) return;
	 
    document.getElementById('ixImg').src = imgname;
	 
	setIZStyle(getObj('lixgMax'),'position:absolute; left:'+left+'px; top:'+top+'px; visibility:visible; z-index:15;');
 
   
    }

 function ixIMGOff(){
       document.getElementById('lixgMax').style.visibility= "hidden";
       document.getElementById('ixImg').src = 'db/imagens/0.gif';
       }
       
 function u_checkver() {
    return true;
  }

	function getObj(valor){
		var ultObj= document.getElementById( valor );
		return  ultObj;
		}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}
 function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
    function zprint(){
	 zmain.zix = zix;
     zmain.zprint();
    }


 function mostraCaminho(caminho){
  var l = document.getElementById('llocalizacao');
  if ( !l ) return;
  
  l.innerHTML = caminho;  
  l.style.display = 'block';
 }

function isString(a) {
    return typeof a == 'string';
}

  

function setIZStyle(obj,nomes,valores) {
   
	if ( !obj ) return;
	// ppires@assec.pt   
	 
	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]);
			
	}
	 	 
  function checkEmail(v){
    var re = /^[\w][\w\.\-]*\@([\w][\w\.\-]*\.)+[\w]{2,}$/;
   
    if (!( v.match(re))  ) {
		alert('O  email é inválido!');
		return false;
		}  
	return true;
  
	}
  
 function uncheck(obj){
	var l =  document.getElementById(obj);
	if (!l )  return true; else  l.checked = false; 
	return false;	
	}
	
function apenas1(id, pos ){
	for(i=0; i<20; i++) if (pos != i) if  (uncheck('qtd_'+id+'_'+i+'_0') )   break;
	temN =1;
    return false;
  }

function zprint(){
  window.open('db?funcao=imprimirconteudo&cod='+zix);
  return ;
 }

 function ekix(e){
 

	if( window.event)  keynum = event.keyCode;
		else if ( e.which)  keynum = e.which;
     
	if (keynum == 13   ) 
	   document.forms[0].submit()
  
 	return true;	 
	}	
	
function painelMsg(sMSG){
  var ixlayer = document.getElementById('ixlayer');
  if ( !ixlayer ) return;
  ixlayer.innerHTML = '<div  style=" position:absolute;  left:274px; top: '+ (141 + _ix_pos_y ) +'px;   ;" class="ix_msg"> '+sMSG+'<div>';
   
  msg_on();
  setTimeout('msg_off()',3000);
}

function msg_off(){
  var ixlayer = document.getElementById('ixlayer');
  ixlayer.style.visibility= "hidden";
  }
function msg_on(){
  var ixlayer = document.getElementById('ixlayer');
  setTimeout('msg_off();',10000);
  ixlayer.style.visibility= "visible";
  }	

  
