function validaForm(f) {
	avisos = "";
	for(i=0;i<f.length;i++) {
		id = f.elements[i].id;
		id = id.substr(0,4);
		if(id == "vTxt") fTexto(f.elements[i]);
		if(id == "vEm0") fEmail(f.elements[i],false);
		if(id == "vEm1") fEmail(f.elements[i],true);
		/*
		if(id == "vfSelect") fSelect(f.elements[i]);
		if(id == "vfEmail") fEmail(f.elements[i]);
		if(id == "vfNumero") fNumero(f.elements[i]);
		if(id == "vfMoeda") fMoeda(f.elements[i]);
		if(id == "vfData") fData(f.elements[i],1);
		if(id == "vfDataN") fData(f.elements[i],0);
		if(id == "vfCnpjCpf") fCnpjCpf(f.elements[i]);
		if(id == "vfUnico") fUnico(f.elements[i],i);
		if(id == "vfUnicoEmail") fUnicoEmail(f.elements[i],i);
		*/
	}
	if(avisos!="") {
		alert("Verifique o preenchimento do formulário\n\n"+avisos);
		return false;
	}
	return true;
}
// Trata campos texto obrigatórios ----/
function fTexto(campo) {
	if(campo.type=="select-one") {
		if(campo.selectedIndex==0) {
			cp = campo.title;
			avisos = avisos + " - O campo "+cp+" é obrigatório!\n";
		}
	} else {
		if(campo.value.length < 2) {
			if(campo.alt)
				cp = campo.alt;
			else
				cp = campo.title;
			avisos = avisos + " - O campo "+cp+" é obrigatório!\n";
		}
	}
}
// Trata o e-mail válido ----/
function fEmail(campo,obrigatorio) {
	if(obrigatorio || campo.value!="") {
		rexp = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
		if(!rexp.test(campo.value)) {
			avisos = avisos + " - Preencha o campo "+campo.alt+" com um e-mail válido!\n";
		}
	}
}
function tvHome(obj,id,legenda,url,target,pos) {
	for (var i = 0; i < document.getElementsByClassName("link_img_02").length; i++) {
		document.getElementsByClassName("link_img_02")[i].className = "link_img_01";
	}
	pos = pos + 1;
	obj.className = "link_img_02";
	window.document.getElementById("tvHomeImagem").src = "media/home/img_"+id+".jpg";
	window.document.getElementById("tvHomeLegenda").innerHTML = legenda;
	window.document.getElementById("tvHomeUrl").href = url;
	window.document.getElementById("tvHomeUrl").target = target;
	window.clearTimeout(temp);
	temp = window.setTimeout("show("+pos+")",10000);
}
document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}
function soNumeros(e) {
	if(window.event) { // IE
		tecla = e.keyCode
	} else if(e.which) { // Netscape/Firefox/Opera
		tecla = e.which
	}
	if((tecla < 48 && tecla != 8)||(tecla > 57)) {
		 	return false;
	}	
}
function mskData(e,f) {
	if(window.event) { // IE
		tecla = e.keyCode
	} else if(e.which) { // Netscape/Firefox/Opera
		tecla = e.which
	}
	if(tecla!=8) {
		if(f.value.length==2) f.value = f.value + "/";	
		if(f.value.length==5) f.value = f.value + "/";
	}
	if((tecla < 48 && tecla != 8)||(tecla > 57)) {
		 	return false;
	}	
}
function mskTEL(e,f) {
	if(window.event) { // IE
		tecla = e.keyCode
	} else if(e.which) { // Netscape/Firefox/Opera
		tecla = e.which
	}
	if(f.value.length==0) f.value = f.value + "(";
	if(f.value.length==3) f.value = f.value + ") ";
	if(f.value.length==9) f.value = f.value + "-";
	if((tecla < 48 && tecla != 8)||(tecla > 57)) {
		 	return false;
	}	
}
var hGal = function(t) { window.document.getElementById("gal_grande").innerHTML = t.responseText;}
var eGal = function(t) {return false;}
function imgGaleria(id) {
	window.document.getElementById("imgGaleria").src = "_images/galeria_carregando.gif";
	var url			= "ajax/galeria.php";
	new Ajax.Request(url, {method:'get', parameters:'id='+id, onSuccess:hGal, onFailure:eGal});
}

var hCad = function(t) {
	if(t.responseText=="ok")
	   	window.document.fDados.submit();
	else
		alert("Este e-mail já está cadastrado!");
}
var hCad2 = function(t) {
	if(t.responseText=="ok") {
	   	cad(t.responseText);
	} else {
		if(t.responseText==1)
			alert("O e-mail primário fornecido já esta cadastrado");
		if(t.responseText==2)
			alert("O e-mail secundário fornecido já esta cadastrado");
		if(t.responseText==3)
			alert("Os e-mails primário e secundário fornecidos já estão cadastrados");
	}
}
var eCad = function(t) {return false;}
function cad(email) {
	var url			= "ajax/cadastro.php";
	new Ajax.Request(url, {method:'get', parameters:'email='+email, onSuccess:hCad, onFailure:eCad});
}
function cad_contato(priemail,pridb,secemail,secdb) {
	var url			= "ajax/cadastro_alt.php";
	new Ajax.Request(url, {method:'get', parameters:'priemail='+priemail+'&pridb='+pridb+'&secemail='+secemail+'&secdb='+secdb, onSuccess:hCad2, onFailure:eCad});
}
var hImagem = function(t) {window.document.getElementById("imagemperf").innerHTML = t.responseText;}
var eImagem = function(t) {return false;}
function excluiImg(c) {
	var url	= "ajax/excluiImg.php";
	if(confirm("A imagem será excluída!\nVocê tem certeza?"))
		new Ajax.Request(url, {method:'get', parameters:'c='+c, onSuccess:hImagem, onFailure:eImagem});
}
function admmenu(id) {
	if(window.document.getElementById(id).className=="adm_menu_off") {
		window.document.getElementById(id).className="adm_menu_on";
		window.document.getElementById("img"+id).src="../../media/icons/minus.gif";
	} else {
		window.document.getElementById(id).className="adm_menu_off";
		window.document.getElementById("img"+id).src="../../media/icons/plus.gif";
	}
}
function enviaIndica() {
	window.open('incs/indicar.php','popIndica','width=460,height=200');
	void(0)
}
function rascunho() {
	window.document.fDados.in_ativo.value=0;
	if(window.document.fDados.tx_titulo.value=="")
		validaForm(window.document.fDados);
	else
		window.document.fDados.submit();
}
function publicar() {
	window.document.fDados.in_ativo.value=1;
	if(window.document.fDados.tx_titulo.value=="")
		validaForm(window.document.fDados);
	else
		window.document.fDados.submit();
}
function aprovar() {
	window.document.fDados.in_ativo.value=1;
	window.document.fDados.submit();
}
function reprovar() {
	window.document.fDados.in_ativo.value=3;
	window.document.fDados.submit();
}

function vfSinopse(campo,event,id) {
		maximo = campo.title;
		var texto = campo.value;
		var falta = maximo - texto.length;
		var aviso = falta;
		document.getElementById(id).innerHTML = aviso;
		if(falta<0) 
			campo.value = campo.value.substr(0,maximo);
		if(falta>0)
			return true;
		else
			if(event.keyCode==46 || event.keyCode == 8)
				return true;
			else
				return false;
}

function sinopse() {
	if(document.getElementById("vfCaixaContador01")) {
		document.getElementById("vfCaixaContador01").focus();
		document.getElementById("vfCaixaContador01").blur();
	}
	if(document.getElementById("vfCaixaContador02")) {
		document.getElementById("vfCaixaContador02").focus();
		document.getElementById("vfCaixaContador02").blur();
	}
	if(document.getElementById("vfCaixaContador03")) {
		document.getElementById("vfCaixaContador03").focus();
		document.getElementById("vfCaixaContador03").blur();
	}
	if(document.getElementById("vfCaixaContador04")) {
		document.getElementById("vfCaixaContador04").focus();
		document.getElementById("vfCaixaContador04").blur();
	}
}
window.onload = function() {
	fcksite("wysiwyg");
}
function fcksite(id) {
	if(window.document.getElementById(id)) {
		var oFCKeditor = new FCKeditor(id);
		oFCKeditor.ReplaceTextarea();
	}	
}