// Documento JavaScript
// by Almir Rogerio


//*******************************************************************************************
var CronoID = null
var CronoEjecutandose = false
var decimas, segundos
function PararCrono (){
	if(CronoEjecutandose)
		clearTimeout(CronoID)
	CronoEjecutandose = false
}
function InicializarCrono () {
	decimas = 0
	segundos = 0
	document.form1.display.value = '00'
}
function MostrarCrono () {
	decimas++
	if ( decimas > 9 ) {
		decimas = 0
		segundos++
		if ( segundos == 601 ) {
			alert('Você está a mais de 10 minutos na mesma pergunta, é aconselhavel que você pare esse jogo e reinicie um novo jogo...')
		}
	}
	var ValorCrono = ""
	ValorCrono = (segundos < 10) ? "0" + segundos : segundos
	document.form1.display.value = ValorCrono
	CronoID = setTimeout("MostrarCrono()", 100)
	CronoEjecutandose = true
	return true
}
function IniciarCrono () {
	PararCrono()
	InicializarCrono()
	MostrarCrono()
}


var msg = 'Função Desativada!'; var asciiF5 = 116; var asciiALT = 18; var asciiLeftArrow = 37; var asciiRightArrow = 39; var asciirefresh = 168; var asciiback1 = 8;
if(document.all){ document.onkeydown = onKeyPress; } //ie has to block in the key down
else if (document.layers || document.getElementById){ document.onkeypress = onKeyPress; } //NS and mozilla have to block in the key press
function onKeyPress(evt) {
	window.status = '';
	var oEvent = (window.event) ? window.event : evt;
	var nKeyCode = oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0;
	var bIsFunctionKey = false;
	if(oEvent.charCode == null || oEvent.charCode == 0){ f5button = (nKeyCode == asciiF5) }
	if(oEvent.charCode == null || oEvent.charCode == 0){ refreshbutton = (nKeyCode == asciirefresh) }
	if(oEvent.charCode == null || oEvent.charCode == 0){ backbutton = (nKeyCode == asciiback1) }
	var sChar = String.fromCharCode(nKeyCode).toUpperCase();
	var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
	var sTag = oTarget.tagName.toLowerCase();
	var sTagType = oTarget.getAttribute("type");
	var bAltPressed = (oEvent.altKey) ? oEvent.altKey : oEvent.modifiers & 1 > 0;
	var bRet = true;
	if(sTagType != null){ sTagType = sTagType.toLowerCase(); }
	if(f5button){ bRet = false; }
	else if(refreshbutton){ bRet = false; }
	else if(backbutton){ bRet = false; }
	else if(bAltPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow)){ bRet = false; }

	if(!bRet){
		try{
			oEvent.returnValue = false; oEvent.cancelBubble = true;
			if(document.all){
				oEvent.keyCode = 0;
			}else{
				oEvent.preventDefault(); oEvent.stopPropagation();
			}
			alert(msg);
		}catch(ex){ alert(msg); }
	}
	return bRet;
}
function desabilitar(){
	return false
}
document.oncontextmenu=desabilitar


// convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);
	var navegador = so = versao = "";
	// Pega o tipo browser
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)){ 
		navegador = 'ie';
		
		if (agt.indexOf("msie 4")!=-1) versao = 4;
		else if (agt.indexOf("msie 5.0")!=-1) versao = 5;
		else if (agt.indexOf("msie 5.5")!=-1) versao = 5.5;
		else if (agt.indexOf("msie 6.")!=-1) versao = 6;
		else if (agt.indexOf("msie 7.")!=-1) versao = 7;
	}
	else if (agt.indexOf('gecko'))	navegador = 'gecko'; 
	else if ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1)) navegador = 'nav';
	else if (agt.indexOf("aol")) navegador ='aol';
	else if (agt.indexOf("opera") != -1) navegador = 'opera';
	else if (agt.indexOf("webtv") != -1) navegador = 'webtv';
	else if ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)) navegador = 'TNavigator';
	else if (agt.indexOf("hotjava") != -1) navegador = 'hotjava';
	
	if ((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1)) so = 'win';
		else if (agt.indexOf("mac")!=-1) so = 'mac';


//*******************************************************************************************

//Função que abre janelas pop'up
function Abre_Janela(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

//*******************************************************************************************

function submeter_entra() {
	form = document.form1;
	ni = 0;
	no = 0;
	for (var i = 0; i < form.elements.length; i++) {
		if (form.elements[i].name.substring(0, 5) == "nivel" && form.elements[i].checked)
		{
			ni = 1;
		}
	}
	if(form.nome.value == "") {
		no = 0;	
	}
	else {
		no = 1;
	}

	if(ni == 0) {
		alert("Por favor escolha um Nível de Jogo!");
		return false;
	}
	if(no == 0) {
		alert("É preciso entrar com o seu nome para dar início ao Jogo!");
		form.nome.focus();
		return false;
	}
	
	return true;
}

//*******************************************************************************************

function submeter_resposta() {
	form = document.form1;
//	for (var i = 0; i < form.elements.length; i++) {
//		if (form.elements[i].name.substring(0, 7) == "escolha" && form.elements[i].checked) {
			document.form1.tipo_acao.value = "responder";
			return true;
//		}
//	}
//	alert("É preciso selecionar uma das respostas acima para Prosseguir!");
//	return false;

}

//*******************************************************************************************

function Pular() {
	document.form1.tipo_acao.value = "pular";
	document.form1.submit();
}

//*******************************************************************************************

function Parar() {
//	if(confirm('O Jogo Show do Cristão ainda esta em andamento. Tem certeza que deseja para-lo assim mesmo ?')) { da chances de o jogador pensar pra responder a pergunta
		document.form1.tipo_acao.value = "parar";
		document.form1.submit();
//	}
}

//*******************************************************************************************

function validaFormRecado() {
	
	d = document.Mural;
	//validar o nome
	if (d.nome.value == ""){
		alert("O Campo Nome deve ser preenchido!");
		d.nome.focus();
		return false;
	}
	//validar o email
	if (d.email.value == ""){
		alert("O Campo Email deve ser preenchido!");
		d.email.focus();
		return false;
	}
	else {
		
		//validar email(verificao de endereco eletronico)
		parte1 = d.email.value.indexOf("@");
		parte2 = d.email.value.indexOf(".");
		parte3 = d.email.value.length;
		if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
			alert("O campo Email deve ser conter um endereco eletronico!");
			d.email.focus();
			return false;
		}
	}
	//validar mensagem
	if (d.mensage.value == ""){
		alert("O campo Mensagem deve ser preenchido!");
		d.mensage.focus();
		return false;
	}
	return true;
}

//*******************************************************************************************

function textCounter(campo, countcampo, maxlimit){//conta/mostra caracteres restantes e limita o tamanho do campo
    if (campo.value.length > maxlimit) //se passar do limite nao deixa entrar o caracter
        campo.value = campo.value.substring(0, maxlimit);
        //reduz o valor do campo de contadem
    else 
        countcampo.value = maxlimit - campo.value.length;
}

//*******************************************************************************************

function inseresmile(string){
	document.Mural.mensage.value = document.Mural.mensage.value +" "+string +" ";
	document.Mural.mensage.focus();
}

//*******************************************************************************************

