//escreve o flash na div desejada para que nao precise clicar nele antes de usa-lo
function montaFlash(destino, flavez, width, height, trans, scale){

	var myFlash =
	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'" id="'+flavez+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="swf/'+flavez+'.swf" />'
	;
	if (trans == "yes"){
		myFlash += '<param name="wmode" value="transparent" />';
	}
	if (scale == "yes"){
		myFlash += '<param name="scale" value="noscale" />';
	}
	myFlash +=
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="swf/'+flavez+'.swf" wmode="transparent" quality="high" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="empresas" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}


// SOLUÇÃO PARA O SCRIPT DO JQUERY QUE ENTRA EM CONFLITO COM O SCRIPT DO PROTOTYPE.
// FOI SUBSTTITUIDO O $ PARA %foo PARA SOLUCIONAR O PROBLEMA DO CONFLITO ENTRE OS SCRIPTS.
var $foo = jQuery.noConflict();

var inHome = true;


// 1 VARIÁVEL (VETOR) E 2 METODOS PARA CONTROLAR AS LISTAS DE CATEGORIAS NA GALERIA DE FOTOS DO SITE
var categorias = new Array();

function fechaCategorias(qtdCateg){
	//for(i=0; i<=qtdCateg; i++){
	for(i=0; i<=100000; i++){
		categorias[i]="fechado";
	}
}

//abre a categoria de fotos se ela estiver fechada
function abreFecha(id) {
	if(categorias[id] == "fechado"){
		//busca as categorias e as galerias que tem relacionamento com a categoria passada como parametro
		$foo('#cate_'+id).load("sistemas/geral/sis/galeria/new_view3/index.php?acao=filhoByCate&id="+id);
		$foo("#cate_"+id).slideDown("normal");
		categorias[id] = "aberto";
	}else{
		$foo("#cate_"+id).slideUp("normal");
		categorias[id] = "fechado";
	}
}


function verificaHome(){
	var urlAtual = window.location.href;
	var tamanho = urlAtual.split("#").length;
	if(tamanho==1)
	carregapagina("home");
}

//carrega a pagina solicitada
function carregapagina(pagina){
	//$foo("#internas").slideDown("normal");
	show_loading();
	setTimeout("pausa('"+pagina+"')",1000);
}

function pausa (pagina) {
	$foo("#internas").load("ctrlImplementa.php?acao="+pagina, function() {
		hide_loading();
	});

}

//mostra a mensagem de carregando
show_loading = function() {
	$foo("#ajax_loader").show();
	//$foo("#internas").slideUp("slow");
}

//oculta a mensagem de carregando
hide_loading = function() {
	$foo("#ajax_loader").hide();
	//$foo("#internas").slideDown("normal");
	setTimeout("document.title=':: EMBRASCOL ::';", 1000);
	//inicializa novamente o lightbox para paginas carregadas internamente via ajax
	setTimeout("Lightbox.prototype.initialize()", 10);
}

//verifica se o email informada eh valido
function validaEmail(email){
	ER = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{2,64}(\.[a-z0-9-]{2,64})*\.[a-z]{2,4}$");
	if (ER.test(email)){
		return true;
	}
	else{
		return false;
	}
}

//cadastra o email informado no newsletter
function cadNews(email){
	if(email==""){
		alert("Informe seu e-mail");
		return false;
	}else{
		if(!validaEmail(email)){
			alert("E-mail invalido!");
			return false;
		}else{
			$foo("#submitHidden").load("ctrlImplementa.php?acao=addNews&email="+email);
		}
	}
}

//valida o formulario de contato e submita ele
function validaFrmContato(form){
	document.getElementById("resposta").style.display = "block";
	if(form.txtNome.value==""){
		form.txtNome.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo NOME!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	if(form.txtEmail.value==""){
		form.txtEmail.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo EMAIL!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}else{
		if(!validaEmail(form.txtEmail.value)){
			form.txtEmail.focus();
			document.getElementById("resposta").innerHTML = "Por favor, informe um EMAIL V&Aacute;LIDO!";
			setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
			return false;
		}
	}
	if(form.txtDDD.value==""){
		form.txtDDD.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo DDD!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	if(form.txtFone.value==""){
		form.txtFone.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo FONE!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	/*if(form.txtDDDF.value==""){
	form.txtDDDF.focus();
	document.getElementById("resposta").innerHTML = "Por favor, preencha o campo DDD do FAX!";
	setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
	return false;
	}
	if(form.txtFax.value==""){
	form.txtFax.focus();
	document.getElementById("resposta").innerHTML = "Por favor, preencha o campo FAX!";
	setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
	return false;
	}
	if(form.txtCidade.value==""){
	form.txtCidade.focus();
	document.getElementById("resposta").innerHTML = "Por favor, preencha o campo CIDADE!";
	setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
	return false;
	}
	if(form.txtEstado.value==""){
	form.txtEstado.focus();
	document.getElementById("resposta").innerHTML = "Por favor, preencha o campo ESTADO!";
	setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
	return false;
	}*/
	if(form.txtSite.value==""){
		form.txtSite.focus();
		document.getElementById("resposta").innerHTML = "Por favor, n&oacute;s diga o que voc&ecirc; achou do site!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	if(form.txtChegou.value==""){
		form.txtChegou.focus();
		document.getElementById("resposta").innerHTML = "Por favor, n&oacute;s diga como voc&ecirc; chegou ao site!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	if(form.txtAssunto.value==""){
		form.txtAssunto.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo ASSUNTO!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	if(form.txtMensagem.value==""){
		form.txtMensagem.focus();
		document.getElementById("resposta").innerHTML = "Por favor, preencha o campo MENSAGEM!";
		setTimeout("document.getElementById(\"resposta\").style.display = \"none\"",3000);
		return false;
	}
	//$foo("#resposta").load('ctrlImplementa.php?'+$foo("#frmContato").formSerialize());
}


function mudaLamDest(){
	var qtdeLamDest  = document.getElementById("qtdeLamDest");
	var lamDestAtual = document.getElementById("lamDestAtual");
	var newLam;

	//avancando as laminas
	newLam = parseInt(lamDestAtual.value)+1;

	lamDestAtual.value = newLam;

	//mudando a lâmina a ser mostrada
	for(i=0;i<qtdeLamDest.value;i++){
		//mostra a lâmina atual
		if(i==newLam){
			//document.getElementById("lamDest"+i).style.display = "block";
			$foo("#lamDest"+i).fadeIn("slow");
		}
		//oculta as outras lâminas
		else{
			//document.getElementById("lamDest"+i).style.display = "none";
			$foo("#lamDest"+i).hide();
		}
	}

	//se for a ultima
	if(newLam==(qtdeLamDest.value-1)){
		lamDestAtual.value = -1;
	}
}
var intervalo;
function dispara(){
	intervalo = setInterval("mudaLamDest()", 7000);
}


/**********************************************
Validação do formulário associe institucional
Criado por fernando
**********************************************/

function ValidarFormulario(Formulario){
	if(validarFormularios(Formulario)){
		//$foo("#resposta").load('ctrlImplementa.php?'+$foo("#frmAssociar").formSerialize());
		//Formulario.reset();
		$foo.ajax({
			type: "POST",
			url:"ctrlImplementa.php",
			data:$foo("#frmAssociar").formSerialize(),
			success: function(msg){
				//$("#internas").html(msg);
				//$("#internas").show("slow");
				$foo("#resposta").html(msg);
				//alert('enviado com sucesso');
				Formulario.reset();
				//hide_loading();

			},
			error:function(msg){
				alert('deu erro ');
			}
		});
			return false;
	}else{
		Formulario[posicao].focus();
		document.getElementById("resposta").style.display="block";
		document.getElementById("resposta").innerHTML=texto;
		return false;
	}
	return false;

}
var posicao=null;
var texto ="";
var parametros="";
function validarFormularios(Formulario){

	var Quantidade = Formulario.elements.length;
	posicao=null;
	texto="";
	var erros="";
	var i=0;
	parametros="";
	for(i;i< Quantidade;i++){
		parametros+=Formulario[i].name+"="+Formulario[i].value+"&";
		if(Formulario[i].title=="obr"){
			//alert(Formulario[i].name);
			if(Formulario[i].value==""){
				document.getElementById("label_"+Formulario[i].name).style.color="#f00";
				if(posicao==null){
					posicao= i;
					var nome = Formulario[i].alt;
					nome = nome.replace("txt","");
					texto=" Preencha o Campo "+nome+" \r\n";
				}
			}else{
				var nome_ = Formulario[i].name;
				if(nome_.indexOf("email")!=-1){

					if(!validaEmail(Formulario[i].value)){
						document.getElementById("label_"+Formulario[i].name).style.color="#f00";
						if(posicao==null){
							posicao= i;
							texto=" "+Formulario[i].alt+" Informado Incorretamente";
						}
					}else{
						document.getElementById("label_"+Formulario[i].name).style.color="#000";
					}

				}else{
					document.getElementById("label_"+Formulario[i].name).style.color="#000";
				}


			}

		}
	}
	if(posicao!=null){

		return false;
	}else{
		return true;
	}
}


function CarregarPagina(pagina,destino){
	$foo("#"+destino).load("ctrlImplementa.php?acao="+pagina);
}


