
//REESCREVE CAMPO DO FORM

function recupera(este, valor){
	if (este.value == ""){
		este.value = valor;
	}
}  	

// LIMPA CAMPO DO FORM

function limpa(este, padrao){
	if (este.value == padrao){
		este.value = "";
	}  	
}

// COLORE CAMPOS
function selectOver(este,status){
	if (!este.foco){
		este.style.backgroundColor = (status)?"#EFEFEF":"#FFFFFF";
	}
}

function selectField (este,foco){
	este.foco = foco;
	este.style.backgroundColor = (este.foco)?"#DFDFDF":"#FFFFFF";
}

// ENVIA UM FORM
function submitForm(id){
	document.getElementById(id).submit();
}

// VALIDA EMAIL
function validaEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return (filter.test(str));
}

// VALIDA CAMPO (IMPEDE VAZIO OU SÓ ESPAÇOS)
function isEmpty(str){
	var filter=/^[\s]+$/; // pega espaços
	return (filter.test(str) || (str == ""));
}

// VALIDA COR
function validaHexa(str){
	var filter=/(#([0-9A-Fa-f]{3,6})\b)/;
	return (filter.test(str));
}

// APROVA E SALVA DADOS DO FORM
function salvaPre(){
	var nome  = document.getElementById('nome');
	var email = document.getElementById('email');
	if (isEmpty(nome.value)){
		window.alert('Insira o seu nome no campo indicado');
		nome.focus();
	}
	else if (!validaEmail(email.value)){
		window.alert('Insira um endereço de e-mail válido');
		email.focus();
	}
	else {
		document.getElementById('preForm').submit();
	}
}