var vetFiltros = new Array (); // Matriz de filtros
var vMeit = new Array();
var vGrDados = '';
var vCelulas = '';
var _rsz=0;

function cadproj ( tipo ) {

 w = screen.width;
 h = screen.height;
 var sURL = 'cadproj.php?tipo=' + tipo;
 if ( sURL != '' )  openModalWindow (sURL, '', w, h )

} //cadproj

function fundo ( cd_fundo ) {

  if ( cd_fundo == 0 ) {
     bg = "<img width='30%' src='sistemas/sipat/topo.jpg' border=1></img>";
  }

 document.getElementById('mapas').innerHTML = bg;

} // fundo


function locat (cd, nm) {

  alert (9);
//  location.href = '_20400.php?cdus='+cd+'&nome='+nm;

} // locat

function listagens ( clist ) {

  parent.document.getElementById('ifdados').src  = 'listproj.php?clist=' + clist;

} //listagens


function gerUser (cduser, acao) {

if ( acao == 2 ) {
    x = confirm ('Confirma a exclusao deste usuário?');
}
// document.getElementById('hidpar').value = cduser;
 //document.submit();

} // gerUser

function confPopUP (msg) {
  
  alert (msg);
  window.opener.location.reload();
  self.close(); 
  
  
} //confPopUP  

function novo ( cod_ent) {

  var w = 600;
  var h = 400;
  if ( cod_ent == 0 || cod_ent==7 ) {
      w = screen.width;
      h=screen.height;
  }
  
  if ( cod_ent == 8 ) { h=500; w=400; }

// 1=cadgrupodados.php 4=cadunge.php

  var sURL = new Array ('cadproj.php','mail.php','wralerta.php','cadcampo.php','chnpss.php'
                       ,'caduser.php','griduser.php','gerarelat.php','salasitua/chat.php'
                       ,'statusproj.php', 'cadunge.php');

  if ( sURL != '' )  openModalWindow (sURL[cod_ent], '', w, h )

} //novo


function notlog () {
  
  alert ('Usuario ou senha invalidos!.\nProcure o Administrador da Unidade Gestora\n ou o CMO local.');
  location.href='index.php';
  
} // notlog


function clicacombo (sName) {
 
  var Index = document.getElementById(sName).selectedIndex;
  var sCod = document.getElementById(sName).options[Index].value;
  var sDesc = document.getElementById(sName).options[Index].text;

} //clicacombo 

function validaForm () {

  var x = document.forms[0].elements.length;
  var sName;
  var sValue;
  var corpo;
  var sair=0;

  for (i=0; i < x;  i++ ) {

    sId = document.forms[0].elements.item(i).id;
    sName = document.forms[0].elements.item(i).name;
    sValue = document.forms[0].elements.item(i).value;
	
    if ( sId.search('obr') != -1  && sValue == '' )
    {
      alert ('o campo ' + sName + ' nao pode ser vazio');
      document.getElementById(sId).focus();
      sair=1; i=x;

    } //if
	  
    else {
	  
        //corpo += '<BR>' + sName + ': ' + sValue;
	  
    } //else
     
  } //for


  if ( !sair )  {
         //alert ('Dados enviados com sucesso!');
    document.forms[0].submit();
  } //if


} //validaForm

function novoInDiv ( cod_ent) {

  if ( cod_ent == 1) titulo_campo = 'Informe o nome da nova Tabela';
  if ( cod_ent == 2) titulo_campo = 'Informe o nome do novo Grupo de Dados';
  if ( cod_ent == 3) titulo_campo = 'Informe o nome da nova Celula';
  if ( cod_ent == 4) titulo_campo = 'Informe o nome da nova unidade gestora';
  
  ret = prompt(titulo_campo);
  if ( ret )  secao (ret, cod_ent);


} //novoInDiv

function secao ( ret, cod_ent ) {

  if ( cod_ent == 2 ) vGrDados += ret + ';';
  if ( cod_ent == 3 ) vCelulas += ret + ';';

  var div = new Array ('', 'tabela', 'gdados', 'celula', 'ggest');
  document.getElementById( div[cod_ent] ).innerHTML +=  ret + '<br>';


} //secao



function load () {

  if ( screen.width == 800 ) {
      return 'img/gov_bahia_800.600.jpg';
   }
   
   else {
   
     return 'img/gov_bahia_1024.768.jpg';
   
   }
   
} // Load

function status (tipo, filtro, user) {

  document.getElementById('stloca').innerHTML = tipo;
  document.getElementById('stfiltro').innerHTML = filtro;
  document.getElementById('stuser').innerHTML = user;


} // status

function aviso () {

   alert ('Aguarde... Rotina em desenvolvimento.');
  
} //aviso

function list ( cod_rel ) {

    parent.document.getElementById('ifdados').src  = 'pac_filtros.php?rela=' + cod_rel;


} //list



function meso ( cod_meso ) {

    parent.document.getElementById('ifdados').src  = 'pac_filtros.php?meso=' + cod_meso;



} //meso

function micro ( cod_micro ) {

    parent.document.getElementById('ifdados').src  = 'pac_filtros.php?micr=' + cod_micro;

} //micro


function teid ( cod_teid ) {

    parent.document.getElementById('ifdados').src  = 'pac_filtros.php?teid=' + cod_teid;

} //teid


function municipio ( cod_muni ) {

    parent.document.getElementById('ifdados').src  = 'pac_filtros.php?muni=' + cod_muni;

} //municipio


function filtro ( cod_filtro ) {

   document.getElementById('ifdados').src  = 'pac_filtros.php?cod_proj=' + cod_filtro;
   vetStatus = new Array ('MESORREGIAO', 'TERRITORIOS DE IDENTIDADE', 'MICRORREGIAO', 'SEDES MUNICIPAIS');
   status ('Tipo Localidade: ' + vetStatus[cod_mapa],'','');

} // filtro

function geoframe (cod) {

  iframe  = "<iframe id='geoframe' src='_60200.php' scrolling='no' ";
  iframe += " frameborder=0 width='550px' height='460px'></iframe>";
  document.getElementById('mapas').innerHTML = iframe;
  

} //geoframe

function mapas (cod_mapa) {

if (screen.width == 800 )
  vetMapas = new Array ('meso2.jpg', 'ident2.jpg', 'micr2.jpg', 'muni2.jpg');
else
  vetMapas = new Array ('meso.jpg', 'ident.jpg', 'micr.jpg', 'muni.jpg');
  
  mapa = "<img width='100%' src='cart/" + vetMapas[cod_mapa] + "' usemap='#mapa1' border=0></img><br>";
   mapa += "<map name='mapa1'>";
    mapa += "<area shape='rect' coords='1,1,600,690' href='javascript:aviso();'>";
   mapa += "</map>";
  
  document.getElementById('mapas').innerHTML = mapa;
  //dados_mapa (cod_mapa );

} //mapas

function dados_mapa (cod_mapa) {
//
//   document.getElementById('ifdados').src  = 'pac_mapas.php?cod_mapa=' + cod_mapa;
//   vetStatus = new Array ('MESORREGIAO', 'TERRITORIOS DE IDENTIDADE', 'MICRORREGIAO', 'SEDES MUNICIPAIS');
//   status ('Tipo Localidade: ' + vetStatus[cod_mapa],'','');

} // dados_mapa

function user ( cod_user ) {

   document.getElementById('ifdados').src = 'users.php?cod_user=' + cod_user;

} // user


function jsmail (cod_user ) {

  sURL = 'mail.php?user=' + cod_user;
  sTitle = 'PAC - BA Ferramenta de Comunicao Interna';
  sParameters = 'width=600,height=400, scrollbars=no';

   try {
     janela=window.open(sURL, sTitle, sParameters);
   }
   catch (errorinfo) {
     janela=window.open(sURL);
   }
   finally  {}
 //interceptacao de erro na abertura da janela

      text = "Desative o Bloqueio de pop-up";

          if( janela == null ) { alert(text); return; }

 //fim

      janela.moveTo(350,150);

} // jsmail

function jsalert (cod_user ) {

	if (screen.width >= 1024){
		largura = 600;
		altura = 400;
	}else{
		largura = 600;
		altura = 400;
	}


  sURL = 'alert.php?user=' + cod_user;
  sTitle = 'PAC - BA Ferramenta de Comunicao Interna';
  sParameters = 'width=600,height=400, scrollbars=no';

   try {
     janela=window.open(sURL, sTitle, sParameters);
   }
   catch (errorinfo) {
     	janela = window.open (sURL);
   }
   finally  {}


 //interceptacao de erro na abertura da janela

      text = "Desative o Bloqueio de pop-up";

          if( janela == null ) { alert(text); return; }

 //fim

      janela.moveTo(350,150);

} // jsalert

function vsasi ( cdsasi ) {

  sURL = '_50400.php?ss=' + cdsasi;
  _rsz = 1;
  main ( sURL );

} //vproj


function vfilt ( cdfilt ) {

  sURL = '_30300.php?cf=' + cdfilt;
  main ( sURL );

} //vproj


function vproj ( cod_proj ) {

  sURL = '_80700.php?cod_proj=' + cod_proj;
  main ( sURL );

} //vproj

function euser ( cdus ) {

  sURL = '_20300.php?cdus=' + cdus;
  main ( sURL );

} //euser


function tools ( cod_tool ) {

 if ( cod_tool == 1) {
 
      sURL = 'statusproj.php';

 }
  else {
      sURL = 'gerarelat.php?cod_proj=' + cod_tool;

 }

      janela = window.open (sURL);
} //tools


function le_alerts ( usu ) {

   
   openModalWindow ('_80200.php', '', 500,300 )

   
} // le_alerts


function openModalWindow (strURL, strArgument, intWidth, intHeight) {
 var intTop = ((screen.height - intHeight) / 2);
 var intLeft = ((screen.width - intWidth) / 2);
 var strEnderec=strURL;
 var strAjustesIE='status=0; help=0; center:yes; dialogWidth:'+intWidth+'px; dialogHeight:'+intHeight+'px';
 var strAjustesNS='width='+intWidth+', height='+intHeight+', status=0, scrollbars=1, menubar=0, dependent=1, left='+intLeft+', top='+intTop;

 with (window.navigator){
  switch (appName){

    case 'Microsoft Internet Explorer':
      var x = window.showModalDialog(strEnderec, strArgument ,strAjustesIE);
    break;

    case 'Netscape':
     var x = window.open(strEnderec, 'Default', strAjustesNS);
    break;
 }
}
} // openModalWindow


/*********************************************************************************************************************************
  ********************************************************************************************************************************/
            
function abrir() {

  if ( !j ) {
    alert ('Preencha corretamente o pedido!');
    exit;
  }

  var x = document.forms[0].elements.length, i=0;
  for (; i < x-1; i++) {
    if  ( document.forms[0].elements.item(i).type == 'text'  ) {
      document.forms[0].elements.item(i).disabled='true';
    } //Fecha if
  } //Fecha for


  sURL = 'solmat.htm?numero=' + solNumero;
  sTitle = 'Solicitacao de Material N.' + solNumero;
  sParameters = 'width=500,height=500, scrollbars=no';

  janela=window.open(sURL, sTitle, sParameters);

 //interceptacao de erro na abertura da janela

      text = "Desative o Bloqueio de pop-up";

          if(janela == null) { alert(text); return; }

 //fim

      janela.moveTo(350,150);

}

function selec (sName) {
  document.getElementById(sName).style.backgroundColor = 'yellow';
  sCampo = sName;
}

function deselec (sName) {
  document.getElementById(sName).style.backgroundColor = 'white';
  //sCampo = '';
}

function atribuir (sName) {

//   if (sName == 'mat' ) {
    var Index = document.getElementById(sName).selectedIndex;
    var sCod = document.getElementById(sName).options[Index].value;
    var sDesc = document.getElementById(sName).options[Index].text;
//    document.getElementById('cod' + j).value = sCod;
//    document.getElementById('desc' + j).value = sDesc;
//    document.getElementById('solic' + j ).value = document.getElementById('quant').value;
//   }

  document.getElementById('div' + sName).innerHTML = sDesc;

}

function MarcaTodos () {

  var x = document.forms[0].elements.length;
  var i, s;

  s = document.getElementById("_chk").checked;

  for (i=0; i < x-1; i++) {

    if  ( document.forms[0].elements.item(i).type == 'checkbox'  ) {
        document.forms[0].elements.item(i).checked =  s;
    } //Fecha if

  } //Fecha for


} //MarcaTodos


function _swap (cev) {

 ajaxgrid('ifdados', '_70100.php?cev=' + cev  );

} // _swap

function swap (cev) {

 ajaxhiden( '_70100.php?cev=' + cev  );

} // swap


function nova (sTema) {

  // if ( confirm('Deseja cancelar o formulario atual?') )    location.reload();

  sValue = prompt ('Informe o novo valor para ' + sTema);
  if ( sValue != '' )
     document.getElementById('div' + sTema).innerHTML = sValue;


} // nova

function _resize () {

 width =  screen.width;
 height =  screen.height;

 PosFimX = width - 20;
 PosFimY = height - 70;

 if(screen.width == 1024 && screen.height == 768 ){}
 if(screen.width == 800 && screen.height == 600 ) { }
 PosIniX=((screen.availWidth/2)-(PosFimX/2));
 PosIniY=((screen.availHeight/2)-(PosFimY/2));

 w = 'resizable=0,top='+PosIniX+',left='+PosIniX+',width='+PosFimX + ',height='+PosFimY;
 return w;
 
} //_resize

function resize_ (t,l,w,h) {

 PosFimX = w;
 PosFimY = h;
 PosIniX= l;
 PosIniY= t;;

 w = 'resizable=0,top='+PosIniX+',left='+PosIniX+',width='+PosFimX + ',height='+PosFimY;
 return w;

} // resize_

function main ( URL ) {

var Name = 'teste';

  var sPar = '';
  sPar += 'titlebar=0,toolbar=0,location=0,directories=0,menubar=0,scrollbars=1,status=0,';
  sPar +=  ( _rsz )?resize_(5,5,400,500):_resize();

  if ( URL )  window.open(URL, '', sPar);
  if ( URL == 'main.php' ) self.close();

} // main

function atualiza ( g ) {

  //document.forms[0].submit();
  runajax ('campo_dado', '_70100.php' );

} // atualiza


