if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) {
	document.location = "apple/index.php";
}

function carregaPagina(pPagina, pMetodo, pDIV) {
	var lDIVGeral;
	var lConteudoPagina;
	var lConteudo;

	try{
		XMLHttp = new XMLHttpRequest();
	} catch(ee) {
		try{
			XMLHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try{
				XMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				XMLHttp = false;
			}
		}
	}
	/*document.getElementById('DIVFundo').style.display = 'block';
	document.getElementById('DIVVerde').style.display = 'none';
	document.getElementById('DIVPattern').style.display = 'none';*/
	
	lDIVGeral = document.getElementById(pDIV);
	lDIVGeral.innerHTML = '<div id="DIVFundoImagem"><center>carregando...</center></div>';
	XMLHttp.open(pMetodo, pPagina,true);
	XMLHttp.onreadystatechange = function() {
		if (XMLHttp.readyState == 4) {
			lConteudoPagina = XMLHttp.responseText;
			getScripts(lConteudoPagina);
			lConteudoPagina = lConteudoPagina.replace(/\+/g," ");
			lConteudoPagina = unescape(lConteudoPagina);
			lConteudo = document.getElementById(pDIV);
			lConteudo.innerHTML = lConteudoPagina;
			//document.getElementById('DIVVerde').style.display = 'block';
			//document.getElementById('DIVPattern').style.display = 'block';
			//setInterval(function () { document.getElementById('DIVFundo').style.display = 'none'; }, 1000)
		}
	}
	XMLHttp.send(null);
}

function getScripts(pConteudo) { 
    var lInicio = 0;
	var lFim;
	var lNovoTexto;
	
    while (lInicio != -1){
        lInicio = pConteudo.indexOf('<script', lInicio);
        if (lInicio >= 0){
            lInicio = pConteudo.indexOf('>', lInicio) + 1;
            lFim = pConteudo.indexOf("<\/script>", lInicio);
            codigo = pConteudo.substring(lInicio,lFim);
            lNovoTexto = document.createElement("script")
            lNovoTexto.text = codigo;
            document.body.appendChild(lNovoTexto);
        }
    }
}

var lIntervalo;
var lOpacity = 99;
function carregaInfo(pID) {
	var lIMG = document.getElementById(pID);
	var lIMGs = document.getElementById('DIVPortilofio').getElementsByTagName('img');
	var lDIVBloqueio = document.getElementById('DIVBloqueio');
	var lTempOpacity;
	
	for (var lContIMGs = 0; lContIMGs < lIMGs.length; lContIMGs++) {
		if (lIMGs[lContIMGs].id != pID) {
			lIMGs[lContIMGs].style.filter = 'alpha(opacity=99)';
			lIMGs[lContIMGs].style.opacity = '0.99';
		}
	}
	
	if (lOpacity > 1) {
		if (lOpacity < 10) {
			lTempOpacity = '0' + lOpacity;
		} else {
			lTempOpacity = 	lOpacity;
		}
		lIMG.style.filter = 'alpha(opacity=' + lTempOpacity + ')';
		lIMG.style.opacity = '0.' + lTempOpacity + '';
		lOpacity = lOpacity - 5;
		clearInterval(lIntervalo);
		lIntervalo = setInterval(function () { carregaInfo(pID); }, 15);
	}
}

function fechaInfo(pID) {
	var lIMG = document.getElementById(pID);
	var lIMGs = document.getElementById('DIVPortilofio').getElementsByTagName('img');
	var lDIVBloqueio = document.getElementById('DIVBloqueio');
	lDIVBloqueio.style.display = 'none';
	var lTempOpacity;
	
	for (var lContIMGs = 0; lContIMGs < lIMGs.length; lContIMGs++) {
		if (lIMGs[lContIMGs].id != pID) {
			lIMGs[lContIMGs].style.filter = 'alpha(opacity=99)';
			lIMGs[lContIMGs].style.opacity = '0.99';
		}
	}
	
	if (lOpacity != 99) {
		if (lOpacity < 99) {
			if (lOpacity < 10) {
				lTempOpacity = '0' + lOpacity;
			} else {
				lTempOpacity = lOpacity;
			}
	
			lIMG.style.filter = 'alpha(opacity=' + lTempOpacity + ')';
			lIMG.style.opacity = '0.' + lTempOpacity + '';
			lOpacity = lOpacity + 5;
			clearInterval(lIntervalo);
			lIntervalo = setInterval(function () { fechaInfo(pID); }, 15);
		}
	} else {
		lIMG.style.filter = 'alpha(opacity=1)';
		lIMG.style.opacity = '1';
	}
}

var lContMapa = 0;
var lTimeOut;
function carregaMapa() {
	var lDIVMapa = document.getElementById('DIVConteudoMapa');
	
	if (lContMapa == 0) {
		$('html,body').animate({scrollTop: $('#DIVConteudoMapa').offset().top}, 800);
	}
	
	if (lContMapa < 520) {
		lContMapa = lContMapa + 20;
		if (lContMapa <= 380) {
			lDIVMapa.style.height = lContMapa + 'px';
		}
		clearTimeout(lTimeOut);
		lTimeOut = setTimeout(function () {
			carregaMapa();
		},5);
	}
	
	if (lContMapa == 520) {
		$('html,body').animate({scrollTop: $('#DIVConteudoMapa').offset().top}, 800);
		iniciaBuscas();
	}
}

function verificaContato() {
	var lNome = document.getElementById('nome');
	var lEmail = document.getElementById('email');
	var lMensagem = document.getElementById('mensagem');
	
	if (lNome.value == '' || lNome.value == 'Digite seu nome') {
		alert('Informe seu nome!');
		lNome.value = '';
		lNome.focus();
		return true;
	}
	
	if (lEmail.value == '' || lEmail.value.indexOf('@') == -1 || lEmail.value == 'Digite seu email') {
		alert('Informe seu email!');
		lEmail.value = '';
		lEmail.focus();
		return true;
	}
	
	if (lMensagem.value == '' || lMensagem.value == 'Digite sua mensagem') {
		alert('Digite sua mensagem!');
		lMensagem.value = '';
		lMensagem.focus();
		return true;
	}
	
	document.forms['formcontato'].submit();
}

function verificaTrabalhe() {
	var lNome = document.getElementById('nome_trabalhe');
	var lEmail = document.getElementById('email_trabalhe');
	var lCargo = document.getElementById('cargo_trabalhe');
	var lExperiencia = document.getElementById('experiencia_trabalhe');
	
	if (lNome.value == 'Seu nome' || lNome.value == '') {
		alert('Informe seu nome');
		lNome.value = '';
		lNome.focus();
		return false;
	}
	
	if (lEmail.value == 'Seu email' || lEmail.value == '') {
		alert('Informe seu email');
		lEmail.value = '';
		lEmail.focus();
		return false;
	}
	
	if (lCargo.value == 'Cargo Desejado' || lCargo.value == '') {
		alert('Selecione o cargo desejado');
		return false;
	}
	
	if (lExperiencia.value == 'Fale um pouco sobre sua experiência' || lExperiencia.value == '') {
		alert('Fale um pouco sobre sua experiência');
		lExperiencia.value = '';
		lExperiencia.focus();
		return false;
	}
	
	document.forms['form_trabalhe'].submit();
}

function contarCaracteres(box,valor,campospan){
	var conta = valor - box.length;
	document.getElementById(campospan).innerHTML = "Você ainda pode digitar " + conta + " caracteres";
	if(box.length >= valor){
		document.getElementById(campospan).innerHTML = "Opss.. você não pode mais digitar..";
		document.getElementById("experiencia_trabalhe").value = document.getElementById("experiencia_trabalhe").value.substr(0,valor);
	}	
}

function abreSelect() {
	var lSelect = document.getElementById('DIVCargo');
	var lInput = document.getElementById('cargo_trabalhe');

	if (lSelect.style.display == 'none') {
		lSelect.style.display = 'inline-block';
		lInput.style.borderLeft = '1px solid #999';
		lInput.style.borderRight = '1px solid #999';
		lInput.style.borderTop = '1px solid #999';
		return false;
	} else {
		lInput.style.borderLeft = '1px solid #4C4C4C';
		lInput.style.borderRight = '1px solid #4C4C4C';
		lInput.style.borderTop = '1px solid #4C4C4C';
		lSelect.style.display = 'none';
		return false;
	}
}

function carregaImagem(pFoto, pDIV, pBotao, pTabela, pContImagens) {
	var lTabela = document.getElementById(pTabela).getElementsByTagName('div');
	
	lContImagens = pContImagens;
	
	for (var lCont = 0; lCont < lTabela.length; lCont++) {
		if (lTabela[lCont].id == pBotao.id) {
			pBotao.style.backgroundPosition = '0 0';
		} else {
			lTabela[lCont].style.backgroundPosition = '0 -14px';
		}
	}
	
	carregaPagina('paginas/ajax/foto.php?gDIV=' + pDIV + '&gFoto=' + pFoto,'GET',pDIV);
	clearInterval(lIntervalo);
	lIntervalo = setInterval(function () {
											if (lContImagens == lImagens.length) {
												lContImagens = 0;
											}
											
											for (var lCont = 0; lCont < lNavegacao.length; lCont++) {
												if (lNavegacao[lCont].id == 'Port1' + parseInt(lContImagens+1)) {
													lNavegacao[lCont].style.backgroundPosition = '0 0';
												} else {
													lNavegacao[lCont].style.backgroundPosition = '0 -14px';
												}
											}
											
											//carregaPagina('paginas/ajax/banners.php?gFoto=' + lImagens[lContImagens] + '','GET','DIVBanner');
											carregaPagina('paginas/ajax/foto.php?gDIV=' + pDIV + '&gFoto=' + lImagens[lContImagens],'GET',pDIV);
											//$('html,body').animate({scrollTop: $('#TabelaNavegacao').offset().top}, 1000);
											lContImagens++;
										}, 15000);
}
