var n = 15;
var secao_atual = 'home';
var pos_centro = 0;
var pos_lateral = 1000;
var z = 0;

function validaForm(form) {
	var msg = "Os campos devem ser preenchidos corretamente: \n\n";
	var cpo = '';

	if(form.nome_contato.value == ' | Nome do contato') cpo += "- Nome do contato\n";
	if(form.nome_empresa.value == ' | Nome da empresa') cpo += "- Nome da empresa\n";
	if(form.telefone.value == ' | Telefone') cpo += "- Telefone\n";
	if(form.email.value == ' | E-mail') cpo += "- E-mail\n";
	if(form.descricao.value == ' | Descri��o do evento') cpo += "- Descri��o do evento\n";
	if(form.publico_alvo.value == ' | P�blico-alvo') cpo += "- P�blico-alvo\n";
	if(form.data.value == ' | Data') cpo += "- Data\n";

	if(cpo !== '') {
		alert(msg + cpo);
		return false;
	}

	return true;
}

function movimenta (direcao, pos_atual, pos_final, box) {
	var pos_atual = pos_atual;
	var pos_final = pos_final;
	var newx = pos_atual + (pos_final - pos_atual)/n;
	document.getElementById(box).style.left = newx+'px';
	//document.formnews.news_nome.value = newx; 
	var tm = setTimeout("movimenta ('" + direcao + "', " + newx + "," + pos_final + ", '" + box + "')",n);
	switch(direcao) {
		case 'fw' :
			if(newx > (pos_final - 100)) {
				clearTimeout(tm);
			}
			break;
		case 'rw' :
			if(newx < (pos_final + 100)) {
				clearTimeout(tm);
			}
			break;
	}
	return true;
}	

function mudaSecao(atual,proxima,direcao) {

	switch(direcao) {
		case 'fw' :
		if(movimenta ('fw',0, 1100, 'box'+parseFloat(z-1)))
		movimenta ('fw',-1000,100,'box'+z);
		break;
		case 'rw' :
		if(movimenta ('rw',0, -1100, 'box'+parseFloat(z-1)))
		movimenta ('rw',1000,-100,'box'+z);
		break;
	}
}
	
function carregaSecao(nome,direcao, params) {
	insereNodulo(direcao,nome);
	
	var asid = nome.split("/");
	
	var lv = new LoadVars();
	lv.sid = asid[1];
	
	var verifica_sessao = function(id){
		switch(id){
			case 'agsa_solucoes.php':
			if(params.is_orcamento == true){
				carregaSolucao('orcamento',0);
			}else{
				alert("chamo");
			}
			break;
		}
	}
	
	lv.onLoad = function () {
		document.getElementById('box'+z).innerHTML = unescape(lv.content.UNhtmlEntities()).split("+").join(" ");
		verifica_sessao(nome);
		
		mudaSecao(secao_atual,nome,direcao);
		secao_atual = nome;
	}
	tapaTudo('on');
	lv.send(nome,"POST");
}	

function insereNodulo(posicao,tBg) {
	z++;
	var oDiv = document.getElementById('box');
	var nDiv = document.createElement('div');
	nDiv.setAttribute('id','box' + z);
	nDiv.style.width = 1000;
	nDiv.style.height = 550;
	nDiv.style.position = 'absolute';
	nDiv.style.top = 0;
	nDiv.style.background = 'URL(lay/bg_' + tBg.substring(0,tBg.indexOf('.')) + '.gif) no-repeat';
	
	switch(posicao) {
		case 'fw' : 
			nDiv.style.left = -1000;
			break;
		case 'rw' :
			nDiv.style.left = 2000;
			break;
	}
	oDiv.appendChild(nDiv);
	
	if(document.getElementById('box'+parseFloat(z-1))) {
		setTimeout("removeElement('box','box"+parseFloat(z-1)+"')",2000);
	}
	
	
}

function removeElement(parentDiv, childDiv){
     if (childDiv == parentDiv) {
          //alert("The parent div cannot be removed.");
     }
     else if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
     else {
          //alert("Child div has already been removed or does not exist.");
          return false;
     }
     tapaTudo('off')
}	

function controlaFocus(texto,campo) {
	if(campo.value == texto) { 
		campo.value = '';
	} else if(campo.value == '') {
		campo.value = texto;
	}
}

function tapaTudo(status) {
	switch(status) {
		case 'on' : document.getElementById('divTapaTudo').innerHTML = '<div style="position: absolute; top:0; left:0;"><table width="100%" height="100%" border-"0" cellpadding="0" cellspacing="0"><tr><td><img src="lay/inv.gif" width="1000" height="550" border="0" /></td></tr></table></div>'; break;
		case 'off' : document.getElementById('divTapaTudo').innerHTML = ''; break;
	}
}

function carregaSolucao (sid,mid,pagina) {
	var lv = new LoadVars();
	lv.sid = sid;
	lv.mid = mid;
	lv.pagina = pagina;
	lv.onLoad = function () {
		document.getElementById("br-solucoes-home").innerHTML = lv.content.UNhtmlEntities();
	}
	carregaLoader("br-solucoes-home","on", '100%', 394);
	lv.send("ajax.solucao.php","POST");
}

function carregaNoticia(nid) {
	var lv = new LoadVars();
	lv.nid = nid;
	lv.onLoad = function () {
		document.getElementById("bl-noticias").innerHTML = lv.content.UNhtmlEntities();
		php_unescape();
	}
	carregaLoader("bl-noticias","on", '100%', 394);
	lv.send("ajax.noticia.php","POST");
}

function carregaLoader(div,status,w,h) {
	switch(status) {
	case "on" :
		if(document.getElementById(div)) {
			document.getElementById(div).innerHTML = '<table width="'+w+'" height="'+h+'" border="0" cellpadding="0" cellspacing="0"><tr><td align="center"><embed src="swf/loader_paginas.swf" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent" allowfullscreen="true" width="100" height="100"></embed></td></tr></table>';
		}
		break;
	case "off":
		if(document.getElementById(div)) {
			document.getElementById(div).innerHTML = '';
		}
		break;
	}
}

function abreLegenda(topo,esquerda,texto) {
	
	var div = document.getElementById("alt-colaboradores"); 
	
	div.style.display = 'block';
	div.style.position = 'absolute';
	div.style.top = topo+'px';
	div.style.left = esquerda+'px';
	div.style.background = '#FFF';
	div.style.border = '1px solid #CCC';
	div.style.padding = '5px';
	div.style.width = '190px';
	div.style.height = '30px';
	
	var txt = texto.split(";");
	var legenda = '';
	legenda += '<strong>'+txt[0]+'</strong><br /><em>'+txt[1]+'</em>';
	div.innerHTML = legenda;
	
}

function fechaLegenda() {
	var div = document.getElementById("alt-colaboradores");
	div.style.display = 'none';
	
}

function abreComentario(cid) {
	if(document.getElementById('comentario-'+cid)) {
		if(document.getElementById('comentario-'+cid).style.display == 'none') {
			document.getElementById('comentario-'+cid).style.display = 'block';
		} else {
			document.getElementById('comentario-'+cid).style.display = 'none';
		}
	}
	
}

function exibe (valor,opcao) {
	if(document.getElementById(opcao+'-'+valor)) {
		if(document.getElementById(opcao+'-'+valor).style.display == 'none') {
			document.getElementById(opcao+'-'+valor).style.display = 'block';
			document.getElementById('img-'+opcao+'-'+valor).src = 'lay/seta_arquivos_baixo.gif';
		} else {
			document.getElementById(opcao+'-'+valor).style.display = 'none';
			document.getElementById('img-'+opcao+'-'+valor).src = 'lay/seta_arquivos_frente.gif';
		}
	}
}

function php_unescape() {
	document.body.innerHTML = document.body.innerHTML.replace( /(%u([0-9A-F]{4}))/gi, "&#x$2;");
}