﻿// JavaScript Document

	// Função de ajuste de exibição de imagens do tipo PNG em navegadores antigos
	//
	function pngFix() {
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])
		
		if ((version >= 5.5 && version < 7) && (document.body.filters)) {
			for(var i=0; i<document.images.length; i++) {
				var img = document.images[i];
				var imgName = img.src.toUpperCase();
				if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
					var imgID = (img.id) ? "id='" + img.id + "' " : "";
					var imgClass = (img.className) ? "class='" + img.className + "' " : "";
					var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
					var imgStyle = "display:inline-block;" + img.style.cssText;
					if (img.align == "left") {
						imgStyle = "float:left;" + imgStyle;
					}
					if (img.align == "right") {
						imgStyle = "float:right;" + imgStyle;
					}
					if (img.parentElement.href) {
						imgStyle = "cursor:hand;" + imgStyle;
					}
					var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
					img.outerHTML = strNewHTML
					i = i-1
				}
			}
		}
	}
	
	//
	// Função que captura largura e altura da tela do usuário
	//
	function getLargAlt(qual){
		if (qual != 'tel') {
			var retorno, winWidth, winHeight, d=document;
			if (typeof window.innerWidth!='undefined') {
				winWidth = window.innerWidth;
				winHeight = window.innerHeight;
			} else {
				if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0) {
					winWidth = d.documentElement.clientWidth
					winHeight = d.documentElement.clientHeight
				} else {
					if (d.body && typeof d.body.clientWidth!='undefined') {
						winWidth = d.body.clientWidth
						winHeight = d.body.clientHeight
					}
				}
			}
			
			if (qual == 'lar') {
				retorno = winWidth;
			} else {
				retorno = winHeight;
			}
		} else {
			telaLar = screen.width;
			telaAlt = screen.height;
			
			retorno = telaLar+'x'+telaAlt;
		}
		
		return retorno;
	}
	
	//
	// Função que simula a função TRIM
	//
	function Trim(str) {
		txt = "";
		for (r=0;r<str.length;r++) {
			if (str.charCodeAt(r) != 65279) {
				txt = txt + str.substr(r,1);
			}
		}
				
		return txt.replace(/^\s+|\s+$/g,"");
	}
/*-- FIM - FUNÇOES FERRAMENTAIS --*/
/*-------------------------------------------------------*/

window.onload = runInit;

	
function popup(pagina){
window.open(pagina,'Imagens','width=270,height=500,scrollbars=no');
}







// JavaScript Document
/*-------------------------------------------------------*/
/* INI - VARIÁVEIS GLOBAIS */

	//
	// Bloco de variáveis globais para o controle de imagens do Banner Home Top
	//
		callInterval3 = "";
		retContentAux = "";
	////////////////////////////////////////////////////////////////////////////
/* FIM - VARIÁVEIS GLOBAIS */
/*-------------------------------------------------------*/
/* INI - FUNÇÃO DE CHAMADA INICIAL */
	function runInit() {
		pngFix();
	}
/* FIM - FUNÇÃO DE CHAMADA INICIAL */
/*-------------------------------------------------------*/
/* INI - FUNÇÕES GERAIS */
	function validaContato() {
		nomeContato = document.getElementById("nome").value;
		emailContato = document.getElementById("email2").value;
		cidadeEstadoContato = document.getElementById("cidade_estado").value;
		mensagemContato = document.getElementById("mensagem").value;
		
		envia = "S";
		
		if (nomeContato == "" && emailContato == "" && mensagemContato == "") {
			alert("Por favor, informe todos os dados corretamente e tente novamente!\n\nObrigado!");
		} else if (nomeContato == "") {
			alert("Por favor, informe seu NOME e tente novamente!\n\nObrigado!");
		} else if (emailContato == "") {
			alert("Por favor, informe seu E-MAIL e tente novamente!\n\nObrigado!");
		} else if (!validaEmail(Trim(emailContato))) {
			 alert("Por favor, informe corretamente o seu E-MAIL e tente novamente!\n\nObrigado!");
		} else if (mensagemContato == "") {
			alert("Por favor, digite sua MENSAGEM e tente novamente!\n\nObrigado!");
		} else {
			window.location = "#";
			paramsToSet = [nomeContato, emailContato, cidadeEstadoContato, mensagemContato];
			setContato(paramsToSet);
		}
	}
	
	function setContato(dataToSend) {
		objDivCont = document.getElementById("conteudo-direita-3");
		
		retContentAux = objDivCont.innerHTML;
		retContentAux = retContentAux.replace(new RegExp( "\\n", "g" ),"");
		
		txtHTMLCad = "<h1>ENTRE EM CONTATO</h1><p>Por favor, aguarde...</p>";
		
		objDivCont.innerHTML = txtHTMLCad;
		objDivCont.style.background = "url(imagens/loading.gif) center no-repeat #99CC33";
		
		var thisUrl = "http://www.afamg.com.br/php/contato.php";
		var thisParams = "inputnome="+dataToSend[0]+"&inputemail="+dataToSend[1]+"&inputcidade_estado="+dataToSend[2]+"&inputmsg="+dataToSend[3];
		var thisFuncao = "getContato";
		
		sendDataPost(thisUrl, thisParams, thisFuncao);
	}
	
	function getContato(retorno) {
		objDivCont = document.getElementById("conteudo-direita-3");
		
		txtHTMLCad = "<h1>ENTRE EM CONTATO</h1><p>"+retorno+"</p>";
		
		objDivCont.innerHTML = txtHTMLCad;
		objDivCont.style.background = "#99CC33";
		
		callInterval3 = setInterval("voltaTela('conteudo-direita-3','"+retContentAux+"')",5000);
	}
	
	function validaCadastro() {
		emailCadastro = document.getElementById("email").value;
		if (emailCadastro == "") {
			alert("Por favor, informe o E-MAIL a ser cadastrado e tente novamente!\n\nObrigado!");
		} else if (!validaEmail(Trim(emailCadastro))) {
			alert("Por favor, verifique o E-MAIL informado e tente novamente!\n\nObrigado!");
		} else {
			setCadastro(emailCadastro);
		}
	}
	
	function setCadastro(dataToSend) {
		objDivCad = document.getElementById("divCadastro");

		retContentAux = objDivCad.innerHTML;
		retContentAux = retContentAux.replace(new RegExp( "\\n", "g" ),"");
		
		txtHTMLCad = "<img src='imagens/loading.gif' width='20' height='20' align='left' border='0' /> Por favor, aguarde...";
		
		objDivCad.innerHTML = txtHTMLCad;
		
		var thisUrl = "http://www.afamg.com.br/php/cadastro.php";
		var thisParams = "inputemail="+dataToSend;
		var thisFuncao = "getCadastro";
		
		sendDataPost(thisUrl, thisParams, thisFuncao);
	}
	
	function getCadastro(retorno) {
		objDivCad = document.getElementById("divCadastro");
		
		txtHTMLCad = retorno;
		
		objDivCad.innerHTML = txtHTMLCad;
		
		callInterval3 = setInterval("voltaTela('divCadastro','"+retContentAux+"')",5000);
	}
	
	function voltaTela(alvo, conteudo) {
		clearInterval(callInterval3);
		objAlvo = document.getElementById(alvo);
		objAlvo.innerHTML = conteudo;
	}
/* FIM - FUNÇÕES GERAIS */

	// Função de validação de e-mail
	//
	function validaEmail(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;
		}
	}

	//
	
	
