// Função Popup: <a href="arquivo.ext" onclick="popup(this.href,'360','535','1'); return false;"></a>
function popup(url,w,h,s) {
	var oW=window.open(url,'popup','width='+w+',height='+h+',directories=0,location=0,menubar=0,resizable=0,scrollbars='+s+',status=0,toolbar=0,marginleft=0,margintop=0,left='+(((screen.availWidth-w)/2)+-10)+',top='+(((screen.height-h)/2)+-10));
}

//Função para impressão
function imprimir(){
	popimpressao = window.open('', '_blank', 'width=751,height=450,left=0,top=0,scrollbars=yes,resizable=no,menubar=no,toolbar=no');

	with (popimpressao.document) {
		write('<html><head><title></title></head>');
		write('<link rel="stylesheet" href="../../css/default.css" type="text/css">');
		write('<link rel="stylesheet" href="../../css/print.css" type="text/css">');
		write('<body>');
		write(document.getElementById("impressao").innerHTML);
		write('</body></html>');
		close();
		}
        popimpressao.print();
}
var ant;
function escondeMostra(id){
    obj = document.getElementById(id);
    if(obj.style.display=='block'){
        obj.style.display='none';
    }else{
         obj.style.display='block';
   }
}

$(function() {
	$("#menucarnebau").hover(function(){ 
		$(this).find("ul").animate({ height: 'toggle', opacity: 'toggle' }, "fast");
	},function(){ 
		$(this).find("ul").animate({ height: 'toggle', opacity: 'toggle' }, "slow");
	});
});



function abrefecha(id) //Função que mostra/esconde as tabelas
{
   var tabela = document.getElementById("box" + id);
   var lnk = document.getElementById("lnk" + id);

   if(ant == id){
	   if (tabela.style.display == "block")
	   {
			lnk.className="lnkSetat";
			tabela.style.display = "none";
	   }
	   else
	   {
			lnk.className="lnkSetaon";
			tabela.style.display = "block";
	   }
   }
   else{
		if(ant != undefined){
			document.getElementById("box" + ant).style.display = "none";
			document.getElementById("lnk" + ant).className="lnkSeta";
		}
		lnk.className="lnkSetaon";
		tabela.style.display = "block";
		ant = id;
   }
}
var ant3;
function abrefecha3(id) //Função que mostra/esconde as tabelas
{
   var tabela = document.getElementById("box" + id);
   var lnk = document.getElementById("lnk" + id);

   if(ant3 == id){
	   if (tabela.style.display == "block")
	   {
			lnk.className="lnkSeta";
			tabela.style.display = "none";
	   }
	   else
	   {
			lnk.className="lnkSetaont";
			tabela.style.display = "block";
	   }
   }
   else{
		if(ant3 != undefined){
			document.getElementById("box" + ant3).style.display = "none";
			document.getElementById("lnk" + ant3).className="lnkSeta";
		}
		lnk.className="lnkSetaont";
		tabela.style.display = "block";
		ant3 = id;
   }
}

    var ant2;
    function abrefecha2(id) //Função que mostra/esconde as tabelas
    {
       var tabela = document.getElementById("boxS" + id);
       var lnk = document.getElementById("lnkS" + id);

       if(ant2 == id){
	       if (tabela.style.display == "block")
	       {
			    lnk.className="lnkSetaSem";
			    tabela.style.display = "none";
	       }
	       else
	       {
			    lnk.className="lnkSetaSemOn";
			    tabela.style.display = "block";
	       }
       }
       else{
		    if(ant2 != undefined){
			    document.getElementById("boxS" + ant2).style.display = "none";
			    document.getElementById("lnkS" + ant2).className="lnkSetaSem";
		    }
		    lnk.className="lnkSetaSemOn";
		    tabela.style.display = "block";
		    ant2 = id;
       }
    }



   // máscara de campos
    // uso: onkeydown="FormataCampo(this,event,'##/##/####')"
    function FormataCampo(Campo,teclapres,mascara, sai) {

        if (sai == "S" && consistente == "N") {
            if (obrigatorio == "N" && Campo.value.length > 0) {
                obrig_fixo = "S";
                Consist(Campo.maxLength, Campo);
                obrig_fixo = "N";
            }
            if (obrigatorio == "S" || Campo.value.length > 0) {
                if (sai == "S") {
                    if (Campo.value.length != mascara.length) {
                        alert('O campo precisa estar neste formato:\n\n       '+ mascara);
                        Campo.value = "";
                    }
                    erro = "S";
                    return false;
                }
            }
        }
        if (sai == "S" && obrigatorio == "N" && Campo.value.length > 0) {
            obrig_fixo = "S";
            Consist(Campo.maxLength, Campo);
            obrig_fixo = "N";
            if (consistente == "N") {
                alert('O campo precisa estar neste formato:\n\n       '+ mascara);
            }
        }

        strtext = Campo.value;
        tamtext = strtext.length;
        tammask = mascara.length;
        arrmask = new Array(tammask);
        for (var i = 0 ; i < tammask; i++) {
            arrmask[i] = mascara.slice(i,i+1)
        } 

		//alert(teclapres.keyCode );
        if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))) {
            if ((teclapres.keyCode >= 35 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)||(teclapres.keyCode == 16)){
                Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)		
            } else {
                Detona_Event(Campo,strtext)
            }
        } else {
            if ((arrmask[tamtext] == "A")) {
                charupper = event.valueOf()
                Detona_Event(Campo,strtext)
                masktext = strtext + charupper 
                Campo.value = masktext
            }
        }
    }

    function check_date(field){
        var checkstr = "0123456789";
        var DateField = field;
        var Datevalue = "";
        var DateTemp = "";
        var seperator = "/";
        var day;
        var month;
        var year;
        var leap = 0;
        var err = 0;
        var i;
		var strDataMsg = "";

        err = 0;
        DateValue = DateField.value;
       /* Delete all chars except 0..9 */
       for (i = 0; i < DateValue.length; i++) {
          if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
             DateTemp = DateTemp + DateValue.substr(i,1);
          }
       }
       DateValue = DateTemp;
       /* Always change date to 8 digits - string*/
       /* if year is entered as 2-digit / always assume 20xx */
       if (DateValue.length == 6) {
          DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
       if (DateValue.length != 8) {
          err = 19;
		  strDataMsg = "A data informada é inválida.";		  
		}

       /* year is wrong if year = 0000 */
       year = DateValue.substr(4,4);
       if (year == 0) {
          err = 20;
		  strDataMsg = "O ano informado é inválido.";
       }
       /* Validation of month*/
       month = DateValue.substr(2,2);
       if ((month < 1) || (month > 12)) {
          err = 21;
		  strDataMsg = "O mês informado é inválido.";
       }

       /* Validation of day*/
       day = DateValue.substr(0,2);
       if (day < 1) {
         err = 22;
		 strDataMsg = "o dia informado é inválido.";
       }

       /* Validation leap-year / february / day */
       if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
          leap = 1;
       }
       if ((month == 2) && (leap == 1) && (day > 29)) {
          err = 23;
		  strDataMsg = "O mês informado possui no máximo 29 dias.";
       }
       if ((month == 2) && (leap != 1) && (day > 28)) {
          err = 24;
		  strDataMsg = "O mês informado possui no máximo 28 dias.";
       }
       /* Validation of other months */
       if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
          err = 25;
		  strDataMsg = "O mês informado possui no máximo 31 dias.";
       }
       if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
          err = 26;
		  strDataMsg = "O mês informado possui no máximo 30 dias.";
       }
       /* if 00 ist entered, no error, deleting the entry */
       if ((day == 0) && (month == 0) && (year == 00)) {
          err = 0; day = ""; month = ""; year = ""; seperator = "";
       }
       /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
       if (err == 0) {
          //DateField.value = day + seperator + month + seperator + year;
          return true;
       }
       else {
          alert(strDataMsg);
          DateField.select();
          DateField.focus();
          return false;
       }
    }

	function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){
        if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){
            separador = arrpos
            masktext = strtext + separador
            Campo.value = masktext
        }
    }


// Função para aceitar apenas números em campos texto
function soNumeros(e){
     var key;
     var keychar;

     if (window.event) {
        key = window.event.keyCode;
     } else if (e) {
        key = e.which;
     } else {
        return true;
     }

     keychar = String.fromCharCode(key);

     // teclas de controle
     if ((key==null) || (key==0) || (key==8) ||
          (key==9) || (key==13) || (key==27) ) {
        return true;
     } else if ((("0123456789").indexOf(keychar) > -1)) {
        return true;     
     } else {
        return false;
     }
}
// *********************** troca ganhadores home *************************
				var idganhador = 0;				
				var strganhador=[];	
				var strganhou=[];	
				var imgganhador=[];
/*
				strganhador[0] = "<strong>Adriano dos Anjos Silveira da Silva</strong><br />Santa Vitoria do Palmar Litoraneo - RS<br />";
				strganhou[0] = "<strong>00 Casa</strong> no valor de R$ 000.000,00";
				imgganhador[0] = "img/img_rc.jpg";
				

				strganhador[1] = "<strong>Renato rosa Anjos Silveira da Silva</strong><br />Santa Vitoria do Palmar Litoraneo - RS<br />";
				strganhou[1] = "<strong>01 Casa</strong> no valor de R$ 000.000,00";
				imgganhador[1] = "img/img_rs.jpg";
				

				strganhador[2] = "<strong>Renato abraao dos Anjos Silveira da Silva</strong><br />Santa Vitopria do Palmar Litoraneo - RS<br />";
				strganhou[2] = "<strong>02 Casa</strong> no valor de R$ 000.000,00";
				imgganhador[2] = "img/img_ra.jpg";
*/


// *********************** função troca ganhadores home *************************
				function Moveganha(op){
					if(op == 'p'){
						if(idganhador<strganhou.length-1){
							idganhador++;
							//document.getElementById("lnkganhadores").innerHTML = strganhador[idganhador];
							document.getElementById("lnkganhou").innerHTML = strganhou[idganhador];
							//document.getElementById("imgganha").src = imgganhador[idganhador];
						}
					}
					else{
						if(idganhador>0){
							idganhador--;
							//document.getElementById("lnkganhadores").innerHTML = strganhador[idganhador];
							document.getElementById("lnkganhou").innerHTML = strganhou[idganhador];
							//document.getElementById("imgganha").src = imgganhador[idganhador];
						}
					}
				}