// JavaScript Document
function goCountry(strUrl){
	if(strUrl!=''){
		window.open('http://'+strUrl,'_blank');
	}
}

function enviarbusca(){
	strBusca = document.getElementById('buscadotopo').value;
	
	if(strBusca!=''){
		window.open('../noticia/?bid='+strBusca,'_self');
	}
}

function autenticar(){
	
	strLogin = document.getElementById('email').value;
	strSenha = document.getElementById('senha').value;
	
	if(strLogin!='login' && strSenha!='senha'){
		document.getElementById('form_autenticacao').submit();
	}else{
		alert('Preencha os campos Login e Senha corretamente.');
	}
	
}

function mostrar(strNomedoItem,posicao){

	intTamanhoJanela = document.body.clientWidth
	intTamanhoJanela = intTamanhoJanela-780
	intTamanhoJanela = ((intTamanhoJanela/2)-0.5)
	
/*	FECHA TODAS AS ABAS */
	ocultar();

	document.getElementById('box-'+strNomedoItem).style.visibility = 'visible';
	document.getElementById('box-'+strNomedoItem).style.left = (posicao+intTamanhoJanela)+'px';
	document.getElementById('box-'+strNomedoItem).style.top = '284px';
}

function ocultar(){
	document.getElementById('box-oqueewcg').style.visibility = 'hidden';
	document.getElementById('box-modalidades').style.visibility = 'hidden';
	document.getElementById('box-etapas').style.visibility = 'hidden';
	document.getElementById('box-tabelas').style.visibility = 'hidden';
	document.getElementById('box-multimidias').style.visibility = 'hidden';
}

function enviaDuvida(){
	
	str_Nome = document.getElementById('duv_nome').value;
	str_Email = document.getElementById('duv_email').value;
	str_Mensagem = document.getElementById('duv_mensagem').value;
	
	if(str_Nome.length<=3){
		document.getElementById('duv_nome').className = 'err';
		bol_erro1 = true;
	}else{
		document.getElementById('duv_nome').className = '';
		bol_erro1 = false;
	}
	
	if(str_Email.indexOf("@") > 0  && str_Email.indexOf(".") > -1 && str_Email.indexOf("@.") == -1){
		document.getElementById('duv_email').className = '';
		bol_erro2 = false;
	}else{
		document.getElementById('duv_email').className = 'err';
		bol_erro2 = true;
	}
	
	if(str_Mensagem.length<=10){
		document.getElementById('duv_mensagem').className = 'err';
		bol_erro3 = true;
	}else{
		document.getElementById('duv_mensagem').className = '';
		bol_erro3 = false;
	}
	
	if(bol_erro1 == true || bol_erro2 == true || bol_erro3 == true){
		document.getElementById('duv_mensagem_erro').innerHTML = 'Os campos marcados acima apresentam erro de preenchimento!';
	}else{
		document.getElementById('enviarduvidas').submit();
	}
	
}

/* CADASTRO */
function valida(cmp,tipo){

	if(tipo=='texto'){

		xstring = document.getElementById(cmp).value;
		if(!(xstring.length>=3)){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
			return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
			return true;
		}
	
	}
	
	if(tipo=='email'){

		xstring = document.getElementById(cmp).value;
		parte1 = xstring.indexOf("@");
		parte2 = xstring.indexOf(".");
		parte3 = xstring.length;
		parte4 = xstring.indexOf(" ");
		if (!(parte1 >= 3 && parte2 >= 1 && parte3 >= 9 && parte2 <= (parte3-3) && parte1 <= (parte3-6) && parte4 <= 0)) {
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
			return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
			return true;
		}
	
	}
	
	if(tipo=='textolongo'){

		xstring = document.getElementById(cmp).value;
		if(!(xstring.length>=20 && xstring.indexOf(" ")>=2)){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
			return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
			document.getElementById(cmp).focus();
			return true;
		}
	
	}
	
	if(tipo=='fone'){
		
		xstring = document.getElementById(cmp).value;

		exp = /\(\d{2}\)\d{4}\-\d{4}/
		
	    if(!exp.test(xstring)){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
			return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
			return true;
		}
	
	}
	

	if(tipo=='cpf'){
                 cpf = document.getElementById(cmp).value;
                 erro = new String;
                 if (cpf.length < 11) erro += "São necessarios 11 digitos para verificação do CPF! \n\n";
                 var nonNumbers = /\D/;
                 if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";
                 if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
                         erro += "Número de CPF invalido!"
               }
               var a = [];
               var b = new Number;
               var c = 11;
               for (i=0; i<11; i++){
                       a[i] = cpf.charAt(i);
                       if (i < 9) b += (a[i] * --c);
               }
               if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
               b = 0;
               c = 11;
               for (y=0; y<10; y++) b += (a[y] * c--);
               if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
               if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
                       erro +="Digito verificador com problema!";
               }
               if (erro.length > 0){
					document.getElementById(cmp).className = 'inp_cadastro_erro';
					document.getElementById(cmp).focus();
					err_form+=', '+cmp;
					return false;
               } else {
					document.getElementById(cmp).className = 'inp_cadastro';
					return true;
			   }
	}
	
	if(tipo=='cep'){
		
		xstring = document.getElementById(cmp).value;

		exp = /\d{5}\-\d{3}/
		
	    if(!exp.test(xstring)){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
            return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
            return true;
	    }
		
	}
	
	if(tipo=='data'){
		
		xstring = document.getElementById(cmp).value;

		exp = /\d{2}\/\d{2}\/\d{4}/
		
	    if(!exp.test(xstring)){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
            return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
            return true;
	    }
		
	}
	
	if(tipo=='numero'){
		
		xstring = document.getElementById(cmp).value;

		if(!(isNaN(xstring)==false && xstring!="")){
			document.getElementById(cmp).className = 'inp_cadastro_erro';
			document.getElementById(cmp).focus();
			err_form+=', '+cmp;
            return false;
		} else {
			document.getElementById(cmp).className = 'inp_cadastro';
            return true;
	    }
		
	}

}

function contrato(){
	if(document.getElementById('contrato').checked==true){
		window.open('?contrato=aceito','_self');
	} else {
		alert('É necessário aceitar o contrato para continuar.');
	}
}

function checamudasenha(){
	
	okok = true;
	
	if(valida('senhaold','texto')==false){ okok = false; };
	if(valida('senhanova','texto')==false){ okok = false; };

	if(document.getElementById('cosenhanova').value!=document.getElementById('senhanova').value){
		document.getElementById('cosenhanova').className = 'inp_cadastro_erro';
		document.getElementById('cosenhanova').focus();
		err_form+=', '+cmp;
		okok=false;
	} else {
		document.getElementById('cosenhanova').className = 'inp_cadastro';
	}

	if(okok==true){
		document.getElementById('formmudasenha').submit();
	}

}

function checacadastro(qual){
	
	okok = true;
	err_form = '';
	
	if(valida('cad_apelido','texto')==false){ okok = false; };
	if(valida('cad_senha','texto')==false){ okok = false; };
	
	if(document.getElementById('cad_cosenha').value!=document.getElementById('cad_senha').value){
		document.getElementById('cad_cosenha').className = 'inp_cadastro_erro';
		document.getElementById('cad_cosenha').focus();
		err_form+=', '+cmp;
		okok=false;
	} else {
		document.getElementById('cad_cosenha').className = 'inp_cadastro';
	}
	
	if(valida('cad_email','email')==false){ okok = false; };
	if(valida('cad_cemail','email')==false){ okok = false; };

	if(document.getElementById('cad_cemail').value!=document.getElementById('cad_email').value){
		document.getElementById('cad_cemail').className = 'inp_cadastro_erro';
		document.getElementById('cad_cemail').focus();
		err_form+=', '+cmp;
		okok=false;
	} else {
		document.getElementById('cad_cemail').className = 'inp_cadastro';
	}

	if(valida('cad_nome','texto')==false){ okok = false; };
	if(valida('cad_sobrenome','texto')==false){ okok = false; };
	if(valida('cad_nascimento','data')==false){ okok = false; };

	if(valida('cad_rg','numero')==false){ okok = false; };
	if(valida('cad_cpf','cpf')==false){ okok = false; };

if(qual=='jogador'){
	if(valida('cad_cep','cep')==false){ okok = false; };
	if(valida('cad_endereco','texto')==false){ okok = false; };

	if(valida('cad_bairro','texto')==false){ okok = false; };
	if(valida('cad_cidade','texto')==false){ okok = false; };
	if(valida('cad_fone','fone')==false){ okok = false; };
}
	if(valida('cad_celnumero','fone')==false){ okok = false; };
	
if(qual=='imprensa'){
	if(valida('cad_empresa','texto')==false){ okok = false; };
}

	if(okok==true){
		document.getElementById('formcadastro').submit();
	}
	return false;
alert(err_form+' - '+okok);
}

function AplicaMascara(Mascara, elemento){

    // Seta o elemento
    var elemento = (elemento) ? elemento : document.getElementById(elemento);
    if(!elemento) return false;
   
    // Método que busca um determinado caractere ou string dentro de uma Array
    function in_array( oque, onde ){
            for(var i = 0 ; i <onde.length; i++){
            if(oque == onde[i]){
                return true;
            }
        }
        return false;
    }
    // Informa o array com todos os caracteres que podem ser considerados caracteres de mascara
    var SpecialChars = [':', '-', '.', '(',')', '/', ',', '_'];
    var oValue = elemento.value;
    var novo_valor = '';
    for( i = 0 ; i <oValue.length; i++){
        //Recebe o caractere de mascara atual
        var nowMask = Mascara.charAt(i);
        //Recebe o caractere do campo atual
        var nowLetter = oValue.charAt(i);
        //Aplica a masca
        if(in_array(nowMask, SpecialChars) == true && nowLetter != nowMask){
            novo_valor +=  nowMask + '' + nowLetter;
        } else {
            novo_valor += nowLetter;
        }
        // Remove regras duplicadas
        var DuplicatedMasks = nowMask+''+nowMask;
        while (novo_valor.indexOf(DuplicatedMasks)>= 0) {
         novo_valor = novo_valor.replace(DuplicatedMasks, nowMask);
        }
    }

// Retorna o valor do elemento com seu novo valor
    elemento.value = novo_valor;
   
}

function bloqueia()
{
	var ctrl=window.event.ctrlKey;
	var tecla=window.event.keyCode;
	if (ctrl && tecla==67) {
//		alert("CTRL+C");
		event.keyCode=0;
		event.returnValue=false;
	}
	if (ctrl && tecla==86) {
//		alert("CTRL+V");
		event.keyCode=0;
		event.returnValue=false;
	}
}

function autotab(current,to){
    if (current.getAttribute && 
      current.value.length==current.getAttribute("maxlength")) {
        document.getElementById(to).focus()
        }
}

/* AJAX */

var http_request = false;
var divid = 'url';

var http_request = false;
var divid = 'url';

    function abrir(url,id) {
		
		divid = id
		
        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // Prepara o conteudo pra receber arquivos com XMLHttpRequest
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Desculpe-nos mais seu navegador n?o suporta AJAX.');
            return false;
        }
        http_request.onreadystatechange = alertContents;
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function alertContents() {

		var x = document.getElementById(divid);

        if (http_request.readyState == 2) {
			x.innerHTML = 'Localizando...';
        }

        if (http_request.readyState == 3) {
			x.innerHTML = 'Carregando...';
        }

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				x.innerHTML = http_request.responseText;
            } else {
                x.innerHTML = http_request.responseText;
            }
        }

    }
