function entraEdit(obj,texto) {
	if (obj.value == texto) {
		obj.value = "";
	}
}
function saiEdit(obj,texto) {
	if (obj.value == "") {
		obj.value = texto;
	}
}

function validaInformativos() {
	var nome = $('#informativo_nome');
	var email = $('#informativo_email');
	if ((nome.val() == "") || (nome.val() == "Nome")) {
		alert("É preciso preencher o campo Nome.");
		nome.focus();
		return false;
	}
	if ((email.val() == "") || (email.val() == "E-Mail")) {
		alert("É preciso preencher o campo E-Mail.");
		email.focus();
		return false;
	}
	var data = {
		nome: nome.val(),
		email: email.val()
	}
	$.post("processaInformativos.php", data,
		function(ret){
			switch(ret){
				case "1":
					alert('Dados cadastrados com sucesso!');
					break;
				case "2":
					alert('Dados inválidos!');
					break;
				case "3":
					alert('O E-Mail informado já está cadastrado!');
					break;
			}
		}
	);
}

function validateEmail(txt) {
	var RegExPattern = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{ 1,3}){3}\])$/;
	if ((txt.match(RegExPattern)) && (trim(txt!='')))
		return true;
	else
		return false;
}
function trim(str){
	if (typeof(str) == "string") {
		return str.replace(/^\s+|\s+$/g,"");
	} else {
		return str;
	}
} 

function validaContato(){

	var nome = $('#nome');
	var email = $('#email');
	var assunto = $('#assunto');
	var telefone = $('#telefone');
	var texto = $('#texto');

	if($.trim(nome.val()) == ''){
		alert('Preencha o campo Nome.');
		nome.focus();
		return false;
	}
		
	if($.trim(email.val()) == ''){
		alert('Preencha o campo E-Mail.');
		email.focus();
		return false;		
	}
	if(!validateEmail(email.val())){
		alert('O campo E-Mail é inválido.');
		email.focus();
		return false;
	}
			
	if($.trim(assunto.val()) == ''){
		alert('Preencha o campo Assunto.');
		assunto.focus();
		return false;
	}
				
	if($.trim(texto.val()) == ''){
		alert('Preencha a mensagem.');
		texto.focus();
		return false;
	}
	
	var data = {
		nome: nome.val(),
		email: email.val(),
		assunto: assunto.val(),
		telefone: telefone.val(),
		texto: texto.val()
	}
	
	$.post("processaContato.php", data,
		function(ret){
			switch(ret){
				case "1":
					alert('Sua mensagem foi enviada com sucesso!');
					$('#frmContato').each (function(){
						this.reset();
					});
					break;
				case "2":
					alert('Erro ao enviar sua mensagem!');
					break;
				case "3":
					alert('Dados inválidos!');
					break;
			}
		}
	);
}

/*target - inicio*/
function init() {
	createExternalLinks();
}
function createExternalLinks() {
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='external') {
                anchor.target = '_blank';
                var title = anchor.title + ' (Este link abre uma nova janela)';
                anchor.title = title;
            }
        }
    }
}
function addEvent(obj, evType, fn){
    if(obj.addEventListener){
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent('on'+evType, fn);
        return r;
    } else {
        return false;
    }
}
addEvent(window, "load", init);
/*target - fim*/
