/******************************************
FUNCOES GERAIS
******************************************/

function ImprimirRodape(){
year = new Date(); 
atualyear= year.getYear(); 
document.write("<table border='0' cellspacing='0' cellpadding='0' width='94%' align='center'>" + 
					"<tbody>" +
						"<tr>" + 
							"<td align='left' width='60%' class='branco'>" + 
								"<span>SAFDI&Eacute; GEST&Atilde;O DE PATRIM&Ocirc;NIO</span> "+
							"</td>" +
							"<td align='right' width='40%' class='branco'>" +
								"&copy" + atualyear + " todos os direitos reservados &nbsp;" +
							"</td>" +
						"</tr>" +
					"</tbody>" +
					"</table>");
				
}
//Para os botoes que mostram e escondem as tabelas nos Titulos
function abreFechaTabela(imagem,tabela){
	if(imagem.className == 'fechaTabelaAzul')
		imagem.className = 'abreTabelaAzul';
	else
		imagem.className = 'fechaTabelaAzul';
	
	if(tabela.style.display == 'none')
		tabela.style.display = 'block';
	else
		tabela.style.display = 'none';
}

//Para os botoes que mostram e escondem as tabelas dentro das proprias tabelas	
function abreFechaTabelaDentro(imagem,tabela){
	if(imagem.className == 'fechaTabelaPreto')
		imagem.className = 'abreTabelaPreto';
	else
		imagem.className = 'fechaTabelaPreto';
    if(tabela.rows){
	    for (i = 2; i < tabela.rows.length; i++) {
		    if (tabela.rows(i).style.display == 'none') 
			    tabela.rows(i).style.display = 'block';
		    else 
			    tabela.rows(i).style.display = 'none';
	    }
	}else{
	if (tabela.style.display == 'none') 
			    tabela.style.display = 'block';
		    else 
			    tabela.style.display = 'none';
	}
}

function ImprimirObs()
{
document.write("<br />"+
    "<table border='0' cellspacing='0' cellpadding='0' width='100%'>" + 
        "<tr>"+
            "<td colspan='3' height='10' Class='cinza_claro_md' style='text-align: justify;font-size:9;!'>"+
            " OBS.: No caso de haver aplica&ccedil&otilde;es que n&atilde;o ocorreram por conta " +
            "e ordem do cliente por nosso interm&eacute;dio ou em fundos por n&oacute;s administrados, organizamos " +
            "as informa&ccedil&otilde;es com base em dados disponibilizados pelo cliente ('espelhamento')." + 
            " Nestes casos, n&atilde;o assumimos a responsabilidade sobre a veracidade ou exatid&atilde;o dos"+
            " dados sob espelhamento, inclusive em virtude de eventuais movimenta&ccedil&otilde;es realizadas pelo cliente"+
            " sem nos ter informado."+
            "</td>"+
        "</tr>"+
    "</table>");
}

//Barras automaticas para os campos de data
function colocaBarras(objeto){
        if (objeto.value.length == 2 || objeto.value.length == 5 ){
        objeto.value = objeto.value+"/";
        }
    }

/****************
CALENDARIO
****************/
function abreCalendario(calendario){
            calendario.style.display = 'block';
            calendario.style.position = 'absolute';
            calendario.children(0).contentWindow.form1.foco.focus();
    }
function fechaCalendario(idCalendario, dataSelecionada){
    idCalendario = idCalendario.replace('_popupCalendario', '');
    //o nome do campo que recebera a data eh setado sempre como o (NOME_DO_CALENDARIO)+_nome
    //exemplo id="calendario_campo"
    document.getElementById(idCalendario + '_campo').value = dataSelecionada;
    document.getElementById(idCalendario + '_popupCalendario').style.display = 'none';
}

/********************
MENU
*********************/

function selecionaMenu(botao){
    botao.href = 'javascript:void(0)';
    botao.style.cursor = 'arrow';

    botao = botao.parentElement;	
    botaoProximo = botao.nextSibling;
	botaoAnterior = botao.previousSibling;
	
	if(botao.className == 'botaoMenu'){
		botao.className = 'botaoMenuOver';
		botao.enabled = false;
		
		if(botaoProximo.className == 'ultimo')
			botaoProximo.className = 'ultimoOver';
		else
			botaoProximo.className = 'mioloOverDir';
		
		if(botaoAnterior.className == 'primeiro')
			botaoAnterior.className = 'primeiroOver';
		else
			botaoAnterior.className = 'mioloOverEsq';
	}	
	else {
	
		
	}
}


/********************
IMPRESSÃO
*********************/

function VerificaImpressao()
{

    
    var url = window.location.href;
    url += '';
    
    var tamanhoUrl = url.length;
    
    var parametro = url.substr(tamanhoUrl - 3, tamanhoUrl);
    
    if (parametro == "imp")
    {
        //document.getElementById('masterDiv').style.display = 'none';
        
        return true;
    }
    else
    {
        return false;
    }
        
}



function RecuperaParametros()
{

    document.getElementById('ctl00_Tipo_Atual').value = parent.opener.document.forms[0].ctl00_Tipo_Atual.value;
    document.getElementById('ctl00_Data_Atual').value = parent.opener.document.forms[0].ctl00_Data_Atual.value;

}

//Permite somente numeros em um campo
//chamar assim: onkeypress="return somenteNumero(event);"
 function somenteNumero(evento){
    if (document.all)
	    var tecla = event.keyCode;
    else if(document.layers)
	    var tecla = evento.which;
	    if (tecla > 47 && tecla < 58)
		    return true;
	    else
		    {
			    if (tecla != 8){
				    event.keyCode = 0;
			    }else
				    return true;
		    }
}

function verificarData(){

var data_inicial = document.getElementById("ctl00_ContentPlaceHolder1_calendario1_campo");   
var data_final   = document.getElementById("ctl00_ContentPlaceHolder1_calendario2_campo");   
dia_inicial      = data_inicial.value.substr(0,2);   
dia_final        = data_final.value.substr(0,2);   
mes_inicial      = data_inicial.value.substr(3,2);   
mes_final        = data_final.value.substr(3,2);   
ano_inicial      = data_inicial.value.substr(6,4);   
ano_final        = data_final.value.substr(6,4);   

    if (ano_final < ano_inicial){   
        exibirPopupMensagem("A data inicial deve ser anterior a data final.", true);   
        return false   
    }
    else {
        if ((mes_final < mes_inicial) && (ano_final <= ano_inicial)){
        exibirPopupMensagem("A data inicial deve ser anterior a data final.", true);   
        return false   
        }
        else{
            if ((dia_final < dia_inicial) && (mes_final < mes_inicial) && (ano_final <= ano_inicial)){
            exibirPopupMensagem("A data inicial deve ser anterior a data final.", true);   
            return false   
            }
            else{
                if((mes_final <= mes_inicial) && (dia_final < dia_inicial)  && (ano_final <= ano_inicial)){
                exibirPopupMensagem("A data inicial deve ser anterior a data final.", true);   
                return false   
                }
                else{
                return true
                }
            }
        }
    }
}
/****************************************
Formatacao de data
*****************************************/
function formataData(obj,event){
    if(somenteNumero(event)) {
        setTimeout("mascData(document.all." + obj.name + ");",60);
    } else {
        return false;
    }
}

function mascData(obj){
    tamanho = obj.value.length;
    strString = obj.value;
    strString = strString.replace("/","");
    strString = strString.replace("/","");
    if(tamanho>=2)  {
        strDia = strString.substring(0,2);
        strMes = strString.substring(2,4);
        strAno = strString.substring(4,8);
        strAno = strAno.replace("/","");
        //alert("dia=" + strDia +" mes=" + strMes + " ano=" + strAno)
        strString = strDia + "/";
        if (trim(strMes)!="")  {
	        strString = strString + strMes;
	        if(strMes.length==2)  {
		        strString = strString + "/" + strAno;
	        }
        }
        else  {
	        strString = strString;
        }
    }
    obj.value = strString;
}
function somenteNumero(event){
    var cont = 0;
    if(navigator.appName.indexOf("Netscape")!= -1) { 
        tecla= event.which; 
    } else { 
        tecla= event.keyCode;
    }

    if(tecla > 47 && tecla < 58) { // numeros de 0 a 9
        return true;
    } else {
        if (tecla != 8) {// backspace
	        return false;
        } else {
	        return true;
        }
    }
}
function trim(string){
    tamanho=string.length;
    posicao=string.indexOf(" ");
    while(posicao==0){
        string=string.substring(1,tamanho);
        tamanho=string.length;
        posicao=string.indexOf(" ");
    }
	
    tamanho=string.length;
    tamanho=tamanho-1;
    posicao=string.lastIndexOf(" ");
    while(posicao==tamanho){
        string=string.substring(0,tamanho);
        tamanho=tamanho-1;
        posicao=string.lastIndexOf(" ");
    }
    return string;
}
function verifica_Data(strdata){
	if( strdata != ""){
 		//Verifica a quantidade de digitos informada esta correta.
 		if (strdata.length != 10){
 			return false;
 		}
 		//Verifica máscara da data
 		if ("/" != strdata.substr(2,1) || "/" != strdata.substr(5,1)){
 			return false;
 		}
 		dia = strdata.substr(0,2)
 		mes = strdata.substr(3,2);
 		ano = strdata.substr(6,4);
 		//Verifica o dia
 		if (isNaN(dia) || dia > 31 || dia < 1){
 			return false;
 		}
 		if (mes == 4 || mes == 6 || mes == 9 || mes == 11){
 			if (dia == "31"){
 				return false;
 			}
 		}
 		if (mes == "02"){
 			bissexto = ano % 4;
 			if (bissexto == 0){
 				if (dia > 29){
 					return false;
 				}
 			}else{
 				if (dia > 28){
 					return false;
 				}
 			}
 		}
 	//Verifica o mês
 		if (isNaN(mes) || mes > 12 || mes < 1){
 			return false;
 		}
 		//Verifica o ano
 		if (isNaN(ano) || ano < 1900 ){
 			return false;
 		}
 	}
	return true;
 }       
        
