// JavaScript Document
function flash(arq, x, y)	{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+x+'" height="'+y+'">');
	document.write('<param name="movie" value="'+arq+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+arq+'" width="'+x+'" height="'+y+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>');
	document.write('</object>');
}

////////////////////////////////////////////////////////
var id = "";
//menu
function extraiScript(texto){
    var ini, pos_src, fim, codigo;
    var objScript = null;
    ini = texto.indexOf('<script', 0)
    while (ini!=-1){
        var objScript = document.createElement("script");
        //Busca se tem algum src a partir do inicio do script
        pos_src = texto.indexOf(' src', ini)
        ini = texto.indexOf('>', ini) + 1;

        //Verifica se este e um bloco de script ou include para um arquivo de scripts
        if (pos_src < ini && pos_src >=0){//Se encontrou um "src" dentro da tag script, esta e um include de um arquivo script
            //Marca como sendo o inicio do nome do arquivo para depois do src
            ini = pos_src + 4;
            //Procura pelo ponto do nome da extencao do arquivo e marca para depois dele
            fim = texto.indexOf('.', ini)+4;
            //Pega o nome do arquivo
            codigo = texto.substring(ini,fim);
            //Elimina do nome do arquivo os caracteres que possam ter sido pegos por engano
            codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");
            // Adiciona o arquivo de script ao objeto que sera adicionado ao documento
            objScript.src = codigo;
        }else{//Se nao encontrou um "src" dentro da tag script, esta e um bloco de codigo script
            // Procura o final do script
            fim = texto.indexOf('</script>', ini);
            // Extrai apenas o script
            codigo = texto.substring(ini,fim);
            // Adiciona o bloco de script ao objeto que sera adicionado ao documento
            objScript.text = codigo;
        }

        //Adiciona o script ao documento
        document.body.appendChild(objScript);
        // Procura a proxima tag de <script
        ini = texto.indexOf('<script', fim);

        //Limpa o objeto de script
        objScript = null;
    }
}

///////////////////////////////////////////////////////////////////////////

function XMLHttpRequestChange() {
	if (HttpReq.readyState == 1) {
		var texto1 = document.getElementById(id);
		texto1.innerHTML = '<img src="img/loading.gif" border="0"  align="absmiddle">';
	}

	if (HttpReq.readyState == 4 && HttpReq.status == 200){
		// coloca o valor no objeto requisitado
		texto=unescape(HttpReq.responseText.replace(/\+/g," "));
		document.getElementById(id).innerHTML=texto;
		// executa scripts
		extraiScript(texto);
   }
}

////////////////////////////////////////////////////////////////////////////

function detalhes(url, campo){
	id = campo;
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

//////////////////////////////////////////////////////////////////

function enviar_email(url, campo, form){
	id = campo;
	
	var assunto = form.assunto.value;

	var para = form.para.value;
	if (para == "")	{
		alert('Selecione uma CONTATO para prosseguir. Tente novamente.');
		form.para.focus();
		return;
	}

	var nome = form.nome.value;
	if (nome == "")	{
		alert('O campo NOME deve ser preenchido. Tente novamente.');
		form.nome.focus();
		return;
	}

	var email = form.email.value;
	if (email == "")	{
		alert('O campo E-MAIL deve ser preenchido. Tente novamente.');
		form.email.focus();
		return;
	}else if (!checarEmail(email))	{
		alert('E-mail invalido. Tente novamente.');
		form.email.focus();
		return;
	}

	var texto = form.texto.value;
	if (texto == "")	{
		alert('O campo MENSAGEM deve ser preenchido. Tente novamente.');
		form.texto.focus();
		return;
	}
	
	url = url + "?email=" + email + "&nome=" + nome + "&para=" + para + "&assunto=" + assunto + "&texto=" + texto;
	
	form.para.selectedIndex = 0;
	form.nome.value = "";
	form.email.value = "";
	form.assunto.value = "";
	form.texto.value = "";
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

//////////////////////////////////////////////////////////////////

function indique_email(url, campo, form){
	id = campo;

	var nome = form.nome.value;
	if (nome == "" || nome == "digite seu nome")	{
		alert('Digite seu Nome para prosseguir. Tente novamente.');
		form.nome.focus();
		return;
	}

	var email = form.email.value;
	if (email == "")	{
		alert('Digite o E-mail para quem você indica para prosseguir. Tente novamente.');
		form.email.focus();
		return;
	}else if (!checarEmail(email))	{
		alert('E-mail invalido. Tente novamente.');
		form.email.focus();
		return;
	}

	url = url + "?nome=" + nome + "&email=" + email;
	
	if (document.getElementById) { //Verifica se o Browser suporta DHTML.
		if(window.XMLHttpRequest) {
			try {
				HttpReq = new XMLHttpRequest();
			} catch(e) {
				HttpReq = false;
			}
		} else if(window.ActiveXObject) {
			try {
				HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					HttpReq = false;
				}
			}
		}
		if(HttpReq) {
			HttpReq.onreadystatechange = XMLHttpRequestChange;
			HttpReq.open("GET", url, true);
			HttpReq.send(null);
		}		  
	}
}

function indique_ok ()	{
	document.indique.nome.value = "digite seu nome";
	document.indique.email.value = "digite o email";
	document.getElementById('emailOk').innerHTML = "";
}

//////////////////////////////////////////////////////////////////

// Mudar cod
function cor(doc, cor, font_color)	{
	document.getElementById(doc).style.backgroundColor = cor;
	document.getElementById(doc).style.color = font_color;
}
//////////////////////////////////////////////

// Validar Post
function valPost(form)	{
	var texto = form.texto.value;

	if (texto == " " || texto == "")	{
		alert('O campo Texto deve ser preenchido.');
		form.texto.focus();
		return;
	}
	
	form.submit();
}

// Validar Anexo
function valArq(form)	{
	var arq = form.arq.value;
	var titulo = form.titulo.value;

	if (titulo == " " || titulo == "")	{
		alert('O campo Titulo deve ser preenchido.');
		form.titulo.focus();
		return;
	}

	if (arq == " " || arq == "")	{
		alert('Selecione um arquivo para proseguir.');
		form.arq.focus();
		return;
	}
	
	form.submit();
}


//////////////////////////////////////////////////////////////////
function limpa(campo)	{
	campo.value = "";
}
//////////////////////////////////////////////////////////////////

//Valida EMAIL
function checarEmail(campo){
	x = 0;
	email=campo;
  	carac_invalido = " /:,;";
  	if (email == ""){
		return false;
  	}
  	for (i=0; i<carac_invalido.length; i++){
    	carac_errado = carac_invalido.charAt(i);
    	if (email.indexOf(carac_errado,0) > -1){
			return false;
    	}
  	}

  	atPos = email.indexOf("@",1);
  	if (atPos == -1){
		return false;
  	}

  	if (email.indexOf("@",atPos+1) != -1){
		return false;
  	}
  	periodPos = email.indexOf(".",atPos)

  	if (periodPos == -1){
		return false;
  	}

  	if (periodPos+3 > email.length){
		return false;
  	}
	return true;
}
/////////////////////////////////////////////////////

//JAVASCRIPT PARA FECHAR A JANELA DO BANNER:
function MM_showHideLayers() { //v9.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3)
	   with (document) 
			if (getElementById && ((obj=getElementById(args[i]))!=null)) { 
				v=args[i+2];
		   	if (obj.style) {
					obj=obj.style;
					v=(v=='show')?'visible':(v=='hide')?'hidden':v;
				}
				obj.visibility=v; 
			}
}