var lCont = 0;
var lIntervaloFadeIn;
var lIntervaloFadeOut;
function carregaLightBox(pAbreFecha, pLightBox, pEscondeFundo, pCont) {
	var lEscondeFundo = document.getElementById(pEscondeFundo);

	if (pAbreFecha == 'abre') {
		if (pCont == 90) {
			clearTimeout(lIntervaloFadeIn);
		}

		if (pCont < 90) {
			lEscondeFundo.style.display = 'inline-block';
			lEscondeFundo.style.filter = 'alpha(opacity=' + pCont + ')';
			lEscondeFundo.style.opacity = '0.' + ((pCont > 10)?pCont:'0' + pCont);
			lCont = pCont + 5;
			lIntervaloFadeIn = setTimeout(function () { carregaLightBox('abre', pLightBox, pEscondeFundo, lCont); },35);
		}
		carregaProduto('abre', pLightBox, -30);
	}
	
	if (pAbreFecha == 'fecha') {
		if (pCont == 0) {
			lEscondeFundo.style.display = 'none';
			clearTimeout(lIntervaloFadeOut);
		}
		
		if (pCont > 0) {
			lEscondeFundo.style.filter = 'alpha(opacity=' + pCont + ')';
			lEscondeFundo.style.opacity = '0.' + ((pCont > 10)?pCont:'0' + pCont);
			lCont = pCont - 5;
			lIntervaloFadeOut = setTimeout(function () { carregaLightBox('fecha', pLightBox, pEscondeFundo, lCont); },35);
		}
		carregaProduto('fecha', pLightBox, 50);
	}
}

var lContProduto = 0;
var lIntervaloRolaProdutoIn;
var lIntervaloRolaProdutOut;
function carregaProduto(pAbreFecha, pLightBox, pCont) {
	var lLightBox = document.getElementById(pLightBox);
	
	if (pAbreFecha == 'abre') {
		if (pCont == 50) {
			clearTimeout(lIntervaloRolaProdutoIn);
		}
		
		if (pCont < 50) {
			lContProduto = pCont + 5;
			lLightBox.style.top = pCont + '%';
			lIntervaloRolaProdutoIn = setTimeout(function () { carregaProduto('abre', pLightBox, lContProduto); },35);
		}
	}
	
	if (pAbreFecha == 'fecha') {
		if (pCont == -120) {
			clearTimeout(lIntervaloRolaProdutOut);
		}
		
		if (pCont > -120) {
			lContProduto = pCont - 5;
			lLightBox.style.top = pCont + '%';
			lIntervaloRolaProdutOut = setTimeout(function () { carregaProduto('fecha', pLightBox, lContProduto); },35);
		}
	}
}
/////////////////////////////////////////////////////////////////
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;
			}
		}
	}
	lDIVGeral = document.getElementById(pDIV);
	lDIVGeral.innerHTML = '<br /><br /><center> <img src="webroot/imagens/estrutura/ajax_loader.gif" height="16" width="16" /> </center>';
	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;
		}
	}
	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);
        }
    }
}

function carregaMapa(pEstado) {
	carregaPagina('paginas/ajax/index.php?gEstado=' + pEstado + '','GET','DIVRepresentantes');
}

function carregaMSN() {
	window.open('http://balke.com.br/pop_msn.php','','width=300, height=400');
}

function verificaOrcamento() {
	var lProduto = document.getElementById('produto');
	var lEmpresa = document.getElementById('empresa');
	var lCNPJ = document.getElementById('cnpj');
	var lComprador = document.getElementById('comprador');
	var lTelefone = document.getElementById('telefone');
	var lCidade = document.getElementById('cidade');
	var lEstado = document.getElementById('estado');
	var lEmail = document.getElementById('email');

	if (lProduto.value == '' || lProduto.value == 'Produto*') {
		alert('Selecione algum produto, no link "Produtos" no menu principal!');
		lProduto.value = '';
		lProduto.focus();
		return true;
	}
	
	if (lEmpresa.value == '' || lEmpresa.value == 'Empresa*') {
		alert('Informe o nome da empresa!');
		lEmpresa.value = '';
		lEmpresa.focus();
		return true;
	}
	
	if (lCNPJ.value == '' || lCNPJ.value == 'CNPJ*') {
		alert('Informe o CNPJ da empresa!');
		lCNPJ.value = '';
		lCNPJ.focus();
		return true;
	}
	
	if (lComprador.value == '' || lComprador.value == 'Comprador*') {
		alert('Informe o nome do comprador!');
		lComprador.value = '';
		lComprador.focus();
		return true;
	}
	
	if (lTelefone.value == '' || lTelefone.value == 'Telefone*') {
		alert('Informe o telefone!');
		lTelefone.value = '';
		lTelefone.focus();
		return true;
	}
	
	if (lCidade.value == '' || lCidade.value == 'Cidade*') {
		alert('Informe o nome da sua cidade!');
		lCidade.value = '';
		lCidade.focus();
		return true;
	}
	
	if (lEstado.value == '' || lEstado.value == 'Estado*') {
		alert('Informe o estado!');
		lEstado.value = '';
		lEstado.focus();
		return true;
	}
	
	if (lEmail.value == '' || lEmail.value == 'E-mail*') {
		alert('Informe o seu E-mail!');
		lEmail.value = '';
		lEmail.focus();
		return true;
	}
	
	document.forms['formorcamento'].submit();
}

function verificaContato() {
	var lNome = document.getElementById('nome');
	var lEmail = document.getElementById('email');
	var lCidade = document.getElementById('cidade');
	var lEstado = document.getElementById('estado');
	var lMensagem = document.getElementById('mensagem');
	
	if (lNome.value == '' || lNome.value == 'Nome*') {
		alert('Informe seu nome!');
		lNome.value = '';
		lNome.focus();
		return true;
	}
	
	if (lEmail.value == '' || lEmail.value == 'E-mail*') {
		alert('Informe seu E-mail!');
		lEmail.value = '';
		lEmail.focus();
		return true;
	}
	
	if (lCidade.value == '' || lCidade.value == 'Cidade*') {
		alert('Informe o nome da sua cidade!');
		lCidade.value = '';
		lCidade.focus();
		return true;
	}
	
	if (lEstado.value == '' || lEstado.value == 'Estado*') {
		alert('Informe o estado!');
		lEstado.value = '';
		lEstado.focus();
		return true;
	}
	
	if (lMensagem.value == '' || lMensagem.value == 'Mensagem*') {
		alert('Informe a sua mensagem!');
		lMensagem.value = '';
		lMensagem.focus();
		return true;
	}
	
	document.forms['formcontato'].submit();
}
