//Funções de integração com o popStats
function ContaPopStats(idPage)
{
    window.setTimeout("click_flash("+idPage+");", 1500);
    //alert(idPage);
}
function abrePopUpCampanha(idPage, url)
{
    window.setTimeout("click_flash("+idPage+");", 1500);
    window.open(url,'CampanhateleSena','width=455,height=541');
    //alert(idPage + " - " + url);
}
function DownLoadCampanha(idPage, url)
{
    window.setTimeout("click_flash("+idPage+");", 1500);
    window.location.href=url;
    //alert(idPage + " - " + url);
}


// 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();
}


// Função Mostra Resultado Sorteio Anteriores

function mostraResultado(sorteio){

	if (document.getElementById("resultadoBolas"+sorteio).style.display == "block") {
		//document.getElementById("resultadoBolas"+sorteio).style.display = "none";
		//document.getElementById("resultadoBarra"+sorteio).className = "bgResultadosSorteio"
	} else {
		document.getElementById("resultadoBolas"+sorteio).style.display = "block";
		if (sorteio == 1)	{
			document.getElementById("resultadoBarra"+sorteio).className = "bgResultadosSorteio7bolas"
		} else {
			if (sorteio == 2 || sorteio == 3 || sorteio == 4) {
				document.getElementById("resultadoBarra"+sorteio).className = "bgResultadosSorteio6bolas"
			} 
		}
	}
	//alert(sorteio);
}

function mostraResultadoInterna(sorteio){
	if (document.getElementById("resultadoBolas"+sorteio).style.display == "block") {
		document.getElementById("resultadoBolas"+sorteio).style.display = "none";
		document.getElementById("resultadoBarra"+sorteio).className = "bgResultadosOculto"
	} else {
		document.getElementById("resultadoBolas"+sorteio).style.display = "block";
		if (sorteio == 1)	{
			document.getElementById("resultadoBarra"+sorteio).className = "bgResultados7"
		} else {
			if (sorteio == 2 || sorteio == 3 || sorteio == 4) {
				document.getElementById("resultadoBarra"+sorteio).className = "bgResultados6"
			} 
		}
	}
}

// Função Mostra Respostas Dúvidas

imgBltOn = new Image();
imgBltOn.src = "../atendimento/img/blt_duvidas_on.gif";
imgBltOff = new Image();
imgBltOff.src = "../atendimento/img/blt_duvidas_off.gif";

function duvidas(idPopStats, duvida) {
    if(duvida != null && duvida != "")
    {
	    if (document.getElementById("resposta_"+duvida).style.display == "block") 
	    {
		    document.getElementById("resposta_"+duvida).style.display = "none";
		    document.getElementById("pergunta_"+duvida).style.textDecoration = "underline";
		    if(document.images) 
		    {               
			    document.images["blt_"+duvida].src = eval("imgBltOff.src");
		    }
	    } 
	    else 
	    {
		    document.getElementById("resposta_"+duvida).style.display = "block";
		    document.getElementById("pergunta_"+duvida).style.textDecoration = "none";
		    if(document.images) 
		    {               
			    document.images["blt_"+duvida].src = eval("imgBltOn.src");
		    }
		    if(idPopStats != null && idPopStats != "")
		        click_flash(idPopStats);
	    }
    }
}


   // 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
        }
    }


function Detona_Event(Campo,strtext){
	event.returnValue = false
	if (strtext != "") {
		Campo.value = strtext
	}
}

function limitatext(campo,maxtamanho){
	if (campo.value.length>=maxtamanho && event.keyCode !=8 && event.keyCode !=46) { 
		event.keyCode = 0;
	}

	if (campo.value.length >= maxtamanho) {
		campo.value = campo.value.substring(0,maxtamanho);
	}

}

// 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;
     }
}