// JavaScript Document

// SAIR DO GERENCIADFOR
function sairGerenciador(){
	if(confirm("Deseja sair do gerenciador?")){
		window.location='sair.php'	
	}
}

// TROCA IMGEME
function trocaImgSair1(){
	document.all.sair.src='imagens/sair1.jpg'
}

// SAIR NORMAL
function trocaImgSair2(){
	document.all.sair.src='imagens/sair.jpg'
}

// TROCA IMGEME
function trocaImgHome1(){
	document.all.inicial.src='imagens/home1.jpg'
}

// SAIR NORMAL
function trocaImgHome2(){
	document.all.inicial.src='imagens/home.jpg'
}

// LINHA SELECIONA
function M_over(src,clrOver) {
 if (!src.contains(event.fromElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrOver;
 }
}
function M_out(src,clrIn) {
 if (!src.contains(event.toElement)) {
  src.style.cursor = 'default';
  src.bgColor = clrIn;
 }
}

// NOVA JANELA
function NovaJanela(mypage, myname, w, h, scroll, status) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+''
win = window.open(mypage, myname, winprops)
if (parseInt(navigator.appVersion) >= 4) { win.window.focus();
}
}

// janela menu
function JanelaMenu(mypage, myname, w, h, scroll, status, menu) {
var winl = (screen.width - w) / 2;
var wint = (screen.height - h) / 2;
winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+', status='+status+', menubar='+menu+''
win = window.open(mypage, myname, winprops)
	if(parseInt(navigator.appVersion) >= 4){
		win.window.focus();
	}
}

// FAVORITOS
function bookmarksite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}

// de 30 a 0 //
var segundos = 60;
var minutos = 14;

function startCountdown(){
	if((minutos > 0) || (segundos > 0)){
		
		segundos = segundos - 1;
		segMostra = segundos;
		minMostra = minutos;
	   
			if(segundos == 0){
				minutos = minutos - 1;
				segundos = 60;
			}
			
			if(segundos < 10){ segMostra = '0'+segundos; }
			if(segundos == 60){	segMostra = '00'; }
			if(minutos < 10){
				minMostra = '0'+minMostra;
			}
			
	   // mostra
	   mostra = minMostra+':'+segMostra;
	   document.getElementById("mostraClock").innerText = mostra;
	   
			// para a index
			if(mostra == "00:00"){
				window.location='index.php?erro=Sua sessão expirou!';
			}
	   
	   setTimeout('startCountdown()',1000);
	   
	}
}


// RELOGIO
function atualizarelogio(){
var hoje=new Date()
var hora=hoje.getHours()
var minuto=hoje.getMinutes()
var seconds=hoje.getSeconds()

  if(hora<10){hora="0" + hora}
  if(minuto<10){minuto="0" + minuto}
  if(seconds<10){seconds="0" + seconds}

relog.innerText = hora + ":" + minuto // + ":" + seconds

setTimeout("atualizarelogio()",1000)
}

// RELOGIO
function atualizarelogio1(){
var hoje=new Date()
var hora=hoje.getHours()
var minuto=hoje.getMinutes()
var seconds=hoje.getSeconds()

  if(hora<10){hora="0" + hora}
  if(minuto<10){minuto="0" + minuto}
  if(seconds<10){seconds="0" + seconds}

relog.innerText = hora + ":" + minuto

setTimeout("atualizarelogio1()",1000)
}

// FRASE DO RODAPE
var hellotext=""
var thetext=""
var started=false
var step=0
var times=1
 function welcometext()
    {
      times--
      if (times==0)
      {
        if (started==false)
        {
          started = true;
          window.status = hellotext;
          setTimeout("anim()",1);
        }
        thetext = hellotext;
      }
    }
 function showstatustext(txt)
    {
      thetext = txt;
      setTimeout("welcometext()",4000)
      times++
    }
 function anim()
    {
     step++
      if (step==7) {step=1}
      if (step==1) {window.status='>==='+thetext+'===<'}
      if (step==2) {window.status='=>=='+thetext+'==<='}
      if (step==3) {window.status='>=>='+thetext+'=<=<'}
      if (step==4) {window.status='=>=>'+thetext+'<=<='}
      if (step==5) {window.status='==>='+thetext+'=<=='}
      if (step==6) {window.status='===>'+thetext+'<==='}
      setTimeout("anim()",200);
    }
//welcometext();

// MASCARA MOEDA
function MascaraMoeda(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // PRECO para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}

// tira o controle do flash
function flash(arqflash,largura,altura) {
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="' + arqflash + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<embed src="' + arqflash + '" width="' + largura + '" height="' + altura + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
	document.write('</object>');
}

// MOSTRA LAYER DO GERENCIADOR
var top = ((screen.height-95)/3)-20;
var left = (screen.width-228)/2;
function show(){ 
	Layer1.style.visibility="visible";
	Layer1.style.top=top;
	Layer1.style.left=left;
}

function hide(){ 
	Layer1.style.visibility="hidden"; 
}

// EMAIL
function mail(email){
	var email = decode64(email);
	document.location.href='mailto:'+email;
}

// 
function decode64(input) {

   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

// TROCA ENTRE
function trocaEnter(campo, evt) {
    var e = evt || event;
    k = e.keyCode;
    
    if(k == 13) {
		buscar();
        return false;
    }
}


// POSIÇÃO LAYER INICIAL
function pos(){
	document.getElementById("logo").style.left = ((screen.width - 520) / 2);
	document.getElementById("logo").style.top = 60;

	document.getElementById("logoPortal").style.left = 10;
	document.getElementById("logoPortal").style.bottom = 10;
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){ 
                    return true; 
                }
    }else{
        return false;
        }
}

function cancelarContato(){
	if(confirm("Deseja realmente cancelar seu contato?")){
		window.top.location = "index.php";
	}
}

// funcionar javascript no ajax
function extraiScript(texto){   
//desenvolvido por Skywalker.to, Micox e Pita.   
//http://forum.imasters.uol.com.br/index.php?showtopic=165277   
    var ini, pos_src, fim, codigo;   
    var objScript = null;   
    ini = texto.indexOf('<script', 0)   
    while (ini!=-1){   
        var objScript = document.createElement("script");   
        //Busca se tem algum src a partir do inicio do script   
        pos_src = texto.indexOf(' src', ini)   
        ini = texto.indexOf('>', ini) + 1;   
  
        //Verifica se este e um bloco de script ou include para um arquivo de scripts   
        if (pos_src < ini && pos_src >=0){//Se encontrou um "src" dentro da tag script, esta e um include de um arquivo script   
            //Marca como sendo o inicio do nome do arquivo para depois do src   
            ini = pos_src + 4;   
            //Procura pelo ponto do nome da extencao do arquivo e marca para depois dele   
            fim = texto.indexOf('.', ini)+4;   
            //Pega o nome do arquivo   
            codigo = texto.substring(ini,fim);   
            //Elimina do nome do arquivo os caracteres que possam ter sido pegos por engano   
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");   
            // Adiciona o arquivo de script ao objeto que sera adicionado ao documento   
            objScript.src = codigo;   
        }else{//Se nao encontrou um "src" dentro da tag script, esta e um bloco de codigo script   
            // Procura o final do script   
            fim = texto.indexOf('</script', ini);   
            // Extrai apenas o script   
            codigo = texto.substring(ini,fim);   
            // Adiciona o bloco de script ao objeto que sera adicionado ao documento   
            objScript.text = codigo;   
        }   
  
        //Adiciona o script ao documento   
        document.body.appendChild(objScript);   
        // Procura a proxima tag de <script   
        ini = texto.indexOf('<script', fim);   
  
        //Limpa o objeto de script   
        objScript = null;   
    }   
} 

function verificaCaptcha(){
	captcha = document.frmContato.CAPTCHA.value;
}

function confirmarContato(){
	
	// VARIAVEIS
	nome = document.frmContato.NOME.value;
	empresa = document.frmContato.EMPRESA.value;
	cidade = document.frmContato.CIDADE.value;
	estado = document.frmContato.ESTADO.value;
	assunto = document.frmContato.ASSUNTO.value;
	mensagem = document.frmContato.MENSAGEM.value;
	retorno = document.frmContato.RETORNO.value;
	telefone = document.frmContato.TELEFONE.value;
	enderecoe = document.frmContato.ENDERECOE.value;
	motivo = document.frmContato.MOTIVO.value;
	
	captcha = document.frmContato.CAPTCHA.value;
	
	if(nome == ""){
		alert("Preencha o campo nome");
		document.frmContato.NOME.focus();
		return false
	}

	if(cidade == ""){
		alert("Preencha o campo cidade");
		document.frmContato.CIDADE.focus();
		return false
	}

	if(assunto == ""){
		alert("Preencha o campo assunto");
		document.frmContato.ASSUNTO.focus();
		return false
	}

	if(mensagem == ""){
		alert("Preencha o campo mensagem");
		document.frmContato.MENSAGEM.focus();
		return false
	}

	if(telefone == ""){
		alert("Preencha o campo telefone");
		document.frmContato.TELEFONE.focus();
		return false
	}

	if(enderecoe == ""){
		alert("Preencha o campo email");
		document.frmContato.ENDERECOE.focus();
		return false
	}
	
	if(!checkMail(enderecoe)){
		alert("O email informado é inválido!");
		document.frmContato.ENDERECOE.focus();
		return false
	}
	
	if(captcha == ""){
		alert("Preencha o código de segurança!");
		document.frmContato.CAPTCHA.focus();
		return false
	}

	// PASSA
	var head 	= document.getElementsByTagName('head').item(0);
	var eScript = document.createElement("script");
	eScript.setAttribute('src','acoes.php?acao=captcha&captcha='+captcha);
	head.appendChild(eScript);
	return false

}


function confirmarEnvio(){
	document.form_cartao.action = "faleConoscoEnvia.php";
	document.form_cartao.target = "contato";
	window.open('about:blank','contato');
	document.form_cartao.submit();
}

function escondeLayers(){
	document.getElementById("mostraPaginas").style.display = "none";
}

function mostraLayers(i){
	for(x = 1; x <= 999999999999; x++){
		if(x == 20000){
			document.getElementById("mostraPaginas").style.display = "block";
			break;
		}
	}

	var pagina = new Array();
	pagina[1] = "sobreaCliniSport.php";
	pagina[2] = "conhecaMais.php";
	pagina[3] = "galeriadeFotos.php";
	pagina[4] = "estrutura.php";
	pagina[5] = "muraldeRecados.php";
	pagina[6] = "mapadeLocalizacao.php";
	pagina[7] = "faleConosco.php";
	
	carregaDados('mostraPaginas', pagina[i]);
	
}

