﻿var color;

function MostraNoticia(id){
    var element = document.getElementById(id);
    var estatus = element.style.display;
    if (estatus == "none" || estatus == ""){
        element.style.display = "block";
    }else{
        element.style.display = "none";
    }
}

function selectRow(element){
    color = element.style.backgroundColor;
    element.style.backgroundColor = "ffff00";
    element.style.cursor = "hand";
}

function exitSelectRow(element){
    element.style.backgroundColor = color;
}

function refresh(){
    document.location.reload(true);
}

function fieldCheckTelefone(src, args){
    if (args.Value != '(  )     -    '){
        if (/\(\d{2}\)\ \d{4}-\d{4}/.test(args.Value))
            args.IsValid = true;
        else
            args.IsValid = false;
    }
    return args.IsValid;
}

function fieldCheckCep(src, args){
    if (args.Value != '     -   '){
        if (/\d{5}-\d{3}/.test(args.Value))
            args.IsValid = true;
        else
            args.IsValid = false;
    }
    return args.IsValid;
}

function loadFlash(path, width, height) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,24" width="'+width+'" height="'+height+'">');
    document.write('<param name="movie" value="'+path+'">');
    document.write('<param name="quality" value="high">');
    document.write('<param name="wmode" value="transparent">');
    document.write('<param name="menu" value="false">');
    document.write('<embed src="'+path+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
    document.write('</object>');
}

function SetFont(){
    var font = document.getElementById('content');
    switch (font.style.fontSize){
        case '':
        case '11px':
            font.style.fontSize = '12px';
            font.style.lineHeight = '15px';
            break;
        case '12px':
            font.style.fontSize = '14px';
            font.style.lineHeight = '16px';
            break;
        case '14px':
            font.style.fontSize = '11px';
            font.style.lineHeight = '15px';
            break;
    }
}

function clickEdit(pagina, largura, altura){
    var esquerda = (screen.width - largura)/2;
    var topo = (screen.height - altura)/2 -20 ;
    var win = window.open(pagina, "", "height=" + altura + ", width=" + largura + ", top=" + topo + ", left=" + esquerda);
    if (win == null)
        alert("Desative o bloqueador de popup");
}

function clickData(codigo, sessao, url){
    location.href = url + "?codigo=" + codigo + "&sessao=" + sessao;
}

function clickDataPopup(codigo){
    var win = window.open("Popup.aspx?codigo=" + codigo, "", "scrollbars=1,menubar=0,resizable,dependent,status,width=480,height=620,left=10,top=10");
    if (win == null)
        alert("Desative o bloqueador de popup");
}

function clickRow(ID){
    var win = window.open("Popup.aspx?" + ID, "", "scrollbars=1,menubar=0,resizable,dependent,status,width=480,height=620,left=10,top=10");
    if (win == null)
        alert("Desative o bloqueador de popup");
}

function Pesquisa(){
    var element = document.getElementById('pesq').style;
    if (element.display == "none"){
        element.display = "block";
        document.getElementById('ipesq').focus();
    }
    else
        element.display = "none";
}

function clickPopup(Link){
    var win = window.open(Link, "", "scrollbars=1,menubar=0,resizable,dependent,status,width=600,height=800,left=10,top=10");
    if (win == null)
        alert("Desative o bloqueador de popup");
}

c = 0;
du = "";
function escondediv(dv, n) {
    for(i = 1; i <= n; i++){
        if(i == dv){
            if(du != dv){
                document.getElementById('mdiv'+i).style.display = "inline";
                du = dv;
        } else {
            du = "";
            document.getElementById('mdiv'+i).style.display = "none";
        }
        } else {
            document.getElementById('mdiv'+i).style.display = "none";
        }
    }		
}

function reveza(qq){
   document.getElementById(qq).className = "itens_menu_r";
}

function volta(qq){
    document.getElementById(qq).className = "itens_menu";
}

 function getData(){
    var data = new Date();
    var dia =  data.getDate();
    var mes = data.getMonth();
    var ano = data.getFullYear();
    var dias  = ((dia < 10) ? "0" : "") + dia;
    switch(mes){
        case 0: mes  = "janeiro"; break;
        case 1: mes  = "fevereiro"; break;
        case 2: mes  = "março"; break;
        case 3: mes  = "abril"; break;
        case 4: mes  = "maio"; break;
        case 5: mes  = "junho"; break;
        case 6: mes  = "julho"; break;
        case 7: mes  = "agosto"; break;
        case 8: mes  = "setembro"; break;
        case 9: mes  = "outubro"; break;
        case 10: mes = "novembro"; break;
        case 11: mes = "dezembro"; break;
    }
    document.getElementById("data").innerHTML = "Belo Horizonte, " + dias + " de " + mes + " de " + ano;
}

 function Clock(){
   data = new Date();
   hora = data.getHours();
   minuto = data.getMinutes();
   segundo = data.getSeconds();
   horas = ((hora < 10) ? "0" : "") + hora + ":";
   horas += ((minuto < 10) ? "0" : "") + minuto + ":";
   horas += ((segundo < 10) ? "0" : "") + segundo + " ";
   dia =  data.getDate();
   mes = data.getMonth();
   ano = data.getFullYear();
   dias  = ((dia < 10) ? "0" : "") + dia;
   switch(mes){
     case 0: mes =  "janeiro"; break;
     case 1: mes =  "fevereiro"; break;
     case 2: mes =  "março"; break;
     case 3: mes =  "abril"; break;
     case 4: mes =  "maio"; break;
     case 5: mes =  "junho"; break;
     case 6: mes =  "julho"; break;
     case 7: mes =  "agosto"; break;
     case 8: mes =  "setembro"; break;
     case 9: mes = "outubro"; break;
     case 10: mes = "novembro"; break;
     case 11: mes = "dezembro"; break;
    }
   
   document.getElementById("display").value = "Belo Horizonte, " + dias + " de " + mes + " de " + ano + "  -  " + horas + "hs";
   setTimeout("Clock()", 1000); 
  }
  
function Envia(Codigo)
 	{
		var vUrl = "/MostraNoticias.asp?codigo="+Codigo;
		Mostra = window.open(vUrl,"Mostra","left=0, top=0, width=500, height=500, tollbar=no, scrollbars=yes, status=no, titlebar=no");
//		Mostra.document.write(vUrl);
	}

function isNumberKey(Key)
      {
         var charCode = (Key.which) ? Key.which : event.keyCode
         if (charCode > 47 && charCode < 58 || charCode == 8)
            return true;
         return false;
      }
	
var xml;
function loadXML(cep, form)
	{
		if (cep.length == 8)	
			{	
				xml = null;
		
				if (window.XMLHttpRequest) 
					{
						xml = new XMLHttpRequest();
						if (form == 0)
							xml.onreadystatechange = Monta;
						else
							if (form == 1)
								xml.onreadystatechange = Monta1;
							else
								xml.onreadystatechange = Monta2;
						xml.open("GET", "function.asp?cep="+cep, true);
						xml.send(null);
					} 
				else 
					if (window.ActiveXObject) 
						{
							xml = new ActiveXObject("Microsoft.XMLHTTP");
							if (form == 0)
							xml.onreadystatechange = Monta;
						else
							if (form == 1)
								xml.onreadystatechange = Monta1;
							else
								xml.onreadystatechange = Monta2;
							xml.open("GET", "function.asp?cep="+cep, true);
							xml.send();
						}
			}
	}

function Monta()
	{	
		f = document.frmCurr;
		exibe = document.getElementById('procurando');
		
		if (xml.readyState == 1)
			{
				exibe.style.display = 'block';
				exibe.innerHTML = "<b><font color='red'>procurando cep. Aguarde...</font></b>";
			}
		if (xml.readyState == 4)
			{
				exibe.innerHTML = "";
				exibe.style.display = 'none';
				if (xml.status == 200)
					{
						response = xml.responseText;
						response = unescape(response);
						response = response.replace(/\+/g," ");
						result = response.split("|");
						
						f.logradouro.value = result[0];
						f.bairro.value = result[1];
						f.municipio.value = result[2];
						f.uf.value = result[3];
						f.numero.focus();
					}
				else
					{
						f.logradouro.value = "";
						f.bairro.value = "";
						f.municipio.value = "";
						f.uf.value = "";
						f.numero.value = "";
					}
					
			}
	}
