﻿function contato(){
	$("#contat").dialog({
		modal: true,
		width: 400,
		buttons: {
			Enviar: function(){
				var email = $("#emCont").val();
				var nome = $("#nmCont").val();
				var txt = $("#txtCont").val();
				if(nome == "" || email == "" || txt == ""){
					alerta("Erro", "<p>* Todos os campos devem ser preenchidos.</p>");
					return;
				}

				var exp = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
				if(!exp.test(email)){
					alerta("Erro", "<p>* Email inválido.</p>");
					return;
				}
				$.blockUI();
				$.ajax({
					url: "/ws/ajax.aspx",
					data: {func:"addcontat", nome:nome, email:email, txt:txt},
					success: function(msg){
						$.unblockUI();
						if(msg == "true")
							alerta("Aviso", "<p>* Formulário de contato enviado com sucesso!</p>");
						else
							alerta("Erro", "<p>* Erro ao enviar formulário de contato!</p>", true);
					}
				});
				$(this).dialog("close");
			},
			Cancelar: function() {
				$(this).dialog("close");
			}
		}
	});
}

function alerta(title, text, relod, wdth, hgth){
	if(typeof relod == "undefined"){relod = false;}
	var obj = {
		title: title,
		modal: true,
		buttons: {
			OK: function(){
				$(this).dialog("close");
			}
		},
		close: function(){
			if(relod){window.location = ".";};
		}
	}
	if(typeof hgth != "undefined")
		obj.height = hgth;
	if(typeof wdth != "undefined")
		obj.width = wdth;

	$("#alerta").html(text).dialog("destroy").dialog(obj);
}

function modal(){
	var res = window.showModalDialog("/global/politica.html", "", "dialogHeight:500px; dialogWidth:820px; center:yes; resizable:no; scroll:yes; toolbar:no; help:no; minimize:yes; maximize:no; status:no;");
}

function fancy(url){
	$.fancybox(
		[url],
		{transitionIn:'elastic', transitionOut:'elastic', type:'image'}
	);
}

$(function(){
	$("#slider").nivoSlider({
		effect: "random",
		animSpeed: 1000,
		pauseTime: 6000,
		controlNav: false
	});
	//$(document).ajaxStop($.unblockUI);
	//$(document).ajaxStart($.blockUI);
	//$.ajaxSetup({ cache:false, type:"GET" });
	$(document).ajaxError(function(e,x,a,t){$.blockUI(); if(t != "abort"){ alerta("Erro","<p>Erro grave de requisição.</p>", true);} });
});

