function carregaimagem(W_Objeto, W_Foto){
  //alert(W_Objeto);
  //alert(W_Foto);
  document.getElementById(W_Objeto).src = "../imagens/usuarios/" + W_Foto;
}

function PopUp(W_Pag, W_Larg, W_Alt){
  //alert('to ak');
	window.open(W_Pag,'nenWin','resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes, personalbar=no,width='+W_Larg+',height='+W_Alt+',top=250, left=300')
	//window.open(W_Pag,'nenWin','width='+W_Larg+',height='+W_Alt+',top=200, left=300');
}

function ForcaPost(){
 document.forms[0].submit();
}
//FUNCAO PARA A JANELA MODAL
function ShowModal(W_Pag, W_Larg, W_Alt){
  //var popup = window.open(W_Pagina,'Centermig','height=445, top=95, left=0, width=790, scrollbars=no');
  //if(!popup){
  //  alert('Seu Browser nao aceita Pop-Up, ou deve estar usando um Bloqueador');
  //}

  W_Larg = 350;
  W_Alt  = 300;
  //alert(W_Pag);
  var retorno = showModalDialog(W_Pag,'Altera Senha','help:no;status:no;scroll:yes;edge:raised;dialogWidth:'+W_Larg+'px;edge:raised;dialogHeight:'+W_Alt+'px');
  //if(!retorno){
  //  alert('Seu Browser nao aceita Pop-Up, ou deve estar usando um Bloqueador');
  //}
  //window.location.assign(retorno);
  //alert(retorno);
}

function FechaPagina(){
  window.returnValue = '';
  window.close();
}

function ContaCampos(){
  var W_Campos = "";
  for (W_I=0; W_I < document.forms[0].elements.length;W_I++){
    alert('ID: ' + document.forms[0].elements[W_I].id);
    alert('Valor hidden: ' + document.getElementById('HiddenParam').value);
    alert('Nome: ' + document.forms[0].elements[W_I].name);
  }
}

//funcoes de posicionamento
function PegaLeft(W_Obj) {  //alert('F_PegaLeft');
 return parseInt(W_Obj.x) ? W_Obj.x : F_PegaPosAbs(W_Obj,"Left");
}/* retorna o left absoluto */

function PegaTop(W_Obj) {
  //alert('F_PegaTop');
 return parseInt(W_Obj.y) ? W_Obj.y : F_PegaPosAbs(W_Obj,"Top");
}/* retorna o top absoluto */

function PegaPosAbs(W_Obj,W_Posicao) {
  //alert('F_PegaPosAbs');
 W_Pos = 0;
 while (W_Obj != null) {
  W_Pos += W_Obj["offset" + W_Posicao];
  W_Obj = W_Obj.offsetParent;
 }
 return W_Pos;
}/* funcao chamada para adquirir top ou left absoluto */

function redirect(LC_Url){
  if (navigator.appName == "Microsoft Internet Explorer"){//Netscape
    window.location.href(LC_Url);
  }else{
    window.location.href = LC_Url;
  }
  //location.reload(LC_Pagina);
}


function CriaArray (n) {
  this.length = n
  for (var i = 1 ; i <= n ; i++)
  { this[i] = "" }
}


////
// ROTINA PARA COLOCAR O FOOTER EM BAIXO NO BROWSER INDEPENDENTE
// DA RESOLUCAO TableMiolo
//ScreenPagina();
function ScreenPagina(){
  //alert(screen.height);
  parent.document.getElementById("TableMiolo").style.height = screen.height - 300;
}

function ShowModalDiv(W_Pagina){
  //var W_Atalho = "";
  //W_Atalho = W_Pagina;
  //alert(W_Pagina);
  CriaModalDiv(W_Pagina);
  document.getElementById("PaginaModal").style.visibility = "";
  document.getElementById("Mensagem").style.visibility    = "";
  if (document.getElementById("DivGrid").style.visibility == "" ){
    document.getElementById("DivGrid").style.visibility = "hidden";
  }
  //document.getElementById("FrameModal").style.visibility = "";
  ConfgDivModal(true);
}

function ConfgDivModal(state){
  var DivRef = document.getElementById("PaginaModal");
  var IfrRef = document.getElementById("Frame");
  if(state)  {
    DivRef.style.display  = "block";
    IfrRef.style.left     = 0;
    IfrRef.style.top      = 0;
    IfrRef.style.width    = DivRef.offsetWidth;
    IfrRef.style.height   = DivRef.offsetHeight + 200;
    IfrRef.style.display  = "block";
  }else{
    DivRef.style.display  = "none";
    IfrRef.style.display  = "none";
  }
}

function CriaModalDiv(W_Pag){
  var tabela = "";                                                                                                                                      //position:absolute;
  tabela += '<div id="D" align="right" width="360" onmousedown="AbilitaMove()" css="CSS_FonteWhite" Style="cursor: move; background:#0098DF; border: black 1px solid;">';
  tabela += '<img id="ImgFechar" onClick="HiddeModalDiv();" Style="cursor: move;" alt="" width="18" height="18" src="../imagens/ico_fechar.gif">';
  tabela += '<table border="0" cellpadding="0" cellspacing="0" style="border: black 0px solid;" bordercolor="#111111" width="100%" id="AutoNumber1" height="80">';
  tabela += ' <tr>';
  tabela += '	<td colspan="2" width="100%" height="21" valign="middle" bgcolor="#CCCCCC" bordercolor="#CCCCCC"> ';
  tabela += '  <iframe id="FramePesquisa" src="'+W_Pag+'" width="345" height="300" scrolling="no" runat="server" frameBorder="0" Style="border: green 0px solid"></iframe>';
  tabela += ' </td>';
  tabela += ' </tr>';
  tabela += '</table>';
  tabela += '</div>';

  // cria uma div onde será aberta a página Modal
  var DivMsg = document.getElementById("Mensagem");
  if (!DivMsg) {
    DivMsg                        = document.createElement("div");
    DivMsg.id                     = "Mensagem";
    DivMsg.zindex                 = 999;
    DivMsg.style.position         = "absolute";
    DivMsg.style.left = (screen.height / 2) - 100;
    DivMsg.style.top              = 380;
    DivMsg.style.width            = 345;
    DivMsg.style.font             = "bold 13px Arial, Verdana, Tahoma";
    DivMsg.style.visibility       = "";
    DivMsg.innerHTML              = tabela;
    document.body.insertBefore(DivMsg, document.body.firstChild);
  }else{
    DivMsg.innerHTML              = "";
    DivMsg.innerHTML              = tabela;
  }

  // cria uma div do tamanho da pagina com o fundo translucido
  // para deixar as opçoes de tr´s sem ação
  var DivPrincipal = document.getElementById("PaginaModal");
  if (!DivPrincipal) {
    DivPrincipal                   = document.createElement("div");
    DivPrincipal.id                = "PaginaModal";
    DivPrincipal.zindex            = 98;
    DivPrincipal.style.position    = "absolute";
    DivPrincipal.style.align       = "center";
    DivPrincipal.style.left        = 0;
    DivPrincipal.style.top         = 0;
    DivPrincipal.style.width       = screen.width - 20;
    DivPrincipal.style.height      = screen.height - 155;
    DivPrincipal.style.font        = "bold 13px Arial, Verdana, Tahoma";
    DivPrincipal.style.backgroundColor  = "silver";
    DivPrincipal.style.filter      = "alpha(opacity=70)";
    DivPrincipal.style.visibility  = "";
    tabela = "<iframe id='Frame' src='iframe.htm' scrolling='no' frameBorder='0'></iframe>";
    DivPrincipal.innerHTML         = tabela;
    document.body.insertBefore(DivPrincipal, document.body.firstChild);
  }
  //W_PaginaModal = DivPrincipal;

}

function HiddeModalDiv(){
  parent.document.getElementById("Mensagem").style.visibility = "hidden";
  parent.document.getElementById("PaginaModal").style.visibility = "hidden";
  document.getElementById("DivGrid").style.visibility = "";
}

/// tentar fazer a Janela Modal mexer
N = (document.all)? 0 : 1;
var ob;
function MD(e) {

  if (N) {
    ob = document.layers[e.target.name];
    X  = e.x;
    Y  = e.y;
    return false;
  }
  else {
    ob = event.srcElement.parentElement.style;
    X  = event.offsetX;
    Y  = event.offsetY;
  }
}
function MM(e) {
  if (ob) {
    if (N) {
      ob.moveTo((e.pageX-X), (e.pageY-Y));
    }
    else {
      // o original é este, mas como estou com a janela por cima de um outro div
      // tive que pegar as cordenadas do div

      //ob.pixelLeft = event.clientX-X + document.scrollLeft;
      //ob.pixelTop = event.clientY-Y + document.scrollTop;
      ob.pixelLeft = event.clientX-X + document.getElementById("PaginaModal").scrollLeft;
      ob.pixelTop = event.clientY-Y + document.getElementById("PaginaModal").scrollTop;
      return false;
    }
  }
}
function MU() {
  ob = null;
}

if (N) {
  document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
}
function AbilitaMove(){
  document.onmousedown = MD;
  document.onmousemove = MM;
  document.onmouseup = MU;
}

function Indicador(W_Nome) {
  alert('toin');
  document.getElementById(W_Nome).Click();
}

//function BannerLateral(){

//  if (screen.availWidth < 900){
//    alert('maior');
//    document.getElementById("DivBannerLateral").style.visibility = "";
//  }else{
//    alert('menor');
//    document.getElementById("DivBannerLateral").style.visibility = "hidden";
//  }

//}

function Visivel(W_Obj,W_Valor){
  //alert('W_Valor: ' + W_Valor);
  //alert('Objeto: ' + W_Obj);
  if (W_Valor == "hidden"){
  //if (document.getElementById(W_Obj).style.visibility == ""){
    //alert('invisible');
    W_Obj.style.visibility = W_Valor;
    //document.getElementById(W_Obj).style.visibility = W_Valor;
  }else{
    //alert('visible');
    W_Obj.style.visibility = "";
    //document.getElementById(W_Obj).style.visibility = "";
  }
}

function AddForm(W_Form, W_Campo, W_Valor){
//  window.opener.document.formemail['TxtPara'].value = window.opener.document.formemail['TxtPara'].value + ';' + 'Teste'
	if (W_Form[W_Campo].value == ''){
	  W_Form[W_Campo].value = W_Valor;
  }else{
	  //W_Form[W_Campo].value = W_Form[W_Campo].value + ';\nl' + W_Valor;
	  W_Form[W_Campo].value = W_Form[W_Campo].value + ';' + W_Valor;
	}
}

function marcadesmarca(W_Objeto){
  var W_Y = 0;
  //alert(W_Objeto);
  if (document.getElementById(W_Objeto).checked == true){
    for (W_I = 0; W_I < document.forms[0].elements.length; W_I++){
			//alert(document.forms[0].elements[W_I].id.substring(0,6));
			if (document.forms[0].elements[W_I].type == "checkbox"){
				if (document.forms[0].elements[W_I].id.substring(0,6) == 'CkBox_'){
					document.forms[0].elements[W_I].checked = true;
				}
			}
    }
  }
  else{
    for (W_I=0; W_I < document.forms[0].elements.length;W_I++){
			if (document.forms[0].elements[W_I].type == "checkbox"){
				if (document.forms[0].elements[W_I].id.substring(0,6) == 'CkBox_'){
					document.forms[0].elements[W_I].checked = false;
				}
			}
    }
  }
}

function RecuperaSelecao(){
  W_Opcao = "";
	try
	{
    for (W_I=0; W_I < document.forms[0].elements.length;W_I++){
      if (document.forms[0].elements[W_I].type == "checkbox"){

        if (document.forms[0].elements[W_I].id.substring(0,8) != "CheckBox"){

          if (document.forms[0].elements[W_I].checked == true ){
            if (W_Opcao == ""){
              if (document.forms[0].elements[W_I].name != "Todos"){
                W_Opcao = document.forms[0].elements[W_I].id;
              }
            }
            else{
              if (document.forms[0].elements[W_I].name != "Todos"){
                W_Opcao += ";" + document.forms[0].elements[W_I].id;
              }
            }

          }

        }

      }
    }
    W_Opcao += ";";
    W_Opcao += "80;90;";
    document.getElementById("HiddenSelecao").value = W_Opcao;
	}
	catch(ex){
    document.getElementById("HiddenSelecao").value = "";
  }
}

function pop_agenda(arquivo)
{
	window.open(arquivo,'nenWin','resizable=no,toolbar=no,status=no,menubar=no,scrollbars=yes, personalbar=no,width=300,height=300, top=50, left=50')
}


function Boletim(W_Object){

   if (W_Object){
			if (W_Object.checked){
				document.getElementById('cabecalhoNews').style.visibility = '';
				document.getElementById('cabecalhoNews').style.display = '';
				document.getElementById('rodapeNews').style.visibility = '';
				document.getElementById('rodapeNews').style.display = '';
			}else{
				document.getElementById('cabecalhoNews').style.visibility = 'hidden';
				document.getElementById('cabecalhoNews').style.display = 'none';
				document.getElementById('rodapeNews').style.visibility = 'hidden';
				document.getElementById('rodapeNews').style.display = 'none';
			}
	 
	 }
	 
}