function acBgAlert() {
	if (Browser.Engine.name == 'trident' && Browser.Engine.version < 5) ie6 = true;
	else ie6 = false;
	
	var formtags = $$('select','textarea');
	if ($('acalert')) {
		$(document.body).getElements('*[id^=acalert]').dispose();
		if (ie6 && formtags) formtags.setStyle('visibility', 'visible');
	}
	else {
		if (formtags.length > 0 && ie6) formtags.setStyle('visibility', 'hidden');
		var acBox = new Element('div', {"id":"acalert"})
			.setStyles({
				opacity: 0.7,
				background: '#000',
				position: 'absolute',
				top: 0,
				left: 0,
				width: window.getScrollSize().x,
				height: window.getScrollSize().y
			})
			.injectInside(document.body);
	}
	$(document.body).scrollTo(0,0);
}
function acAviso(msg) {
	acBgAlert();
	var acBoxMsg = new Element('div', {'id':'acalertbox'})
		.set("html",msg+"<br/><img src='img/load.gif' />")
		.setStyles({
			height: 60,
			width: 400,
			align: 'center',
			position: 'absolute',
			'z-index': '1000',
			opacity: 1,
			color: '#000',
			top: (window.getCoordinates().bottom/2)-35,
			left: (window.getCoordinates().right/2)-205
		})
		.injectInside(document.body);
}

function acMsg(msg) {
	acBgAlert();
	var acBoxMsg = new Element('div', {'id':'acalertbox'})
		.set("html",msg+"<br/><input type='button' id='acalertsim' value='Ok'/>")
		.setStyles({
			width: 400,
			align: 'center',
			position: 'absolute',
			'z-index': '1000',
			opacity: 0,
			color: '#000',
			left: (window.getCoordinates().right/2)-205
		})
		.injectInside(document.body);
		$('acalertbox').setStyle('top',(window.getCoordinates().bottom/2)-($('acalertbox').getSize().y/2)-5)
		var myFx = new Fx.Tween('acalertbox');
		myFx.start('opacity', '0', '1');
		if (!$('acalert')) acBgAlert();
		$('acalertsim').addEvent('click',function(){acBgAlert();});
		$('acalert').addEvent('click',function(){acBgAlert()});
}
function acError(msg,camp) {
	acBgAlert();
	var txt;
	if (msg.contains('erro0')) {
		txt = "Você não está logado ou sua sessão expirou.";
	}
	if (msg.contains('acErro1')) {
		campo = camp.substring(camp.indexOf("="));
		txt = "Este "+camp+" já está sendo utilizado, favor tentar um diferente."
	}
	if (msg.contains('acErro3')) {
		campo = camp.substring(camp.indexOf("="));
		txt = "O campo "+camp+" deve ser preenchido."
	}
	if (msg.contains('acErro4')) {
		txt = "Dado não encontrado no sistema."
	}
	if (msg.contains('acErro5')) {
		txt = "Favor preencher com algum texto para a busca."
	}
	if (msg.contains('acErro6')) {
		txt = "A senha atual digitada está incorreta."
	}
	if (msg.contains('acErro7')) {
		txt = "Selecione uma opção para votar"
	}
	if (msg.contains('acErro8')) {
		txt = "Você já votou nessa enquete"
	}
	if (msg.contains('acErro100')) {
		txt = "Erro de sistema, favor contactar a administração."
	}
	if (!txt) {
		txt = msg;
	}
	acMsg(txt);
}
function acEnviaEmail(e) {
	var event = new Event(e);
	var frm = new acForm("frm_contato");
	if (frm.error) {
		event.stop();
		event.preventDefault();
		event.stopPropagation(); 
	}
}
var acForm = new Class({
	initialize: function(form){
		if ($('erroForm')) $('erroForm').destroy();
		if ($('okForm')) $('okForm').destroy();
		if ($('erroForm2')) $('erroForm2').destroy();
		if ($('erroForm3')) $('erroForm3').destroy();
		var error = false;
		var status;
		$(form).getElements('*[class*=acObg]').each(function(el){
			status = true;
			if (el.getProperty('type') == 'checkbox' && !el.getProperty('checked')) status = false;
			else if (!el.get('value')) status = false;
			else if(el.get('acTipo') == 'email' && !el.get('value').match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9._-]+)/gi)){
				var acBoxMsg = new Element('div', {'id':'erroForm2'})
				.set("html","E-mail inválido. Favor tentar mais uma vez.")
				.inject($(form),'before');
				status = false;
				this.error = true;
			}
			if (!status) {
				error = true;
				if (el.getPrevious()) el.getPrevious().setStyle('color','red');
				else if (el.getNext()) el.getNext().setStyle('color','red');
			} else {
				if (el.getPrevious()) el.getPrevious().setStyle('color','#000');
				else if (el.getNext()) el.getNext().setStyle('color','#000');
				el.set('value',el.get('value').clean());
			}
		});
		if (error) {
			var acBoxMsg = new Element('div', {'id':'erroForm'})
			.set("html","Por favor, complete os dados que faltam.")
			.inject($(form),'before');
			this.error = true;
		} 
		else this.error = false;
	}
});