
function envia_contato(form) {
    if (form.nome.value == ""){
	    alert('Os campos destacados são obrigatórios.');
	    form.nome.focus();
	    return false;
    }else if (form.fone.value == ""){
	    alert('Os campos destacados são obrigatórios.');
	    form.fone.focus();
	    return false;
    }else if (form.email.value == ""){
	    alert('Os campos destacados são obrigatórios.');
	    form.email.focus();
	    return false;
    }else if (!ChecaMail(form.email.value)){
	    alert('Você deve inserir um E-mail valido.');
	    form.email.focus();
	    return false;
    }else if (form.assunto.value == ""){
        alert('Os campos destacados são obrigatórios.');
	    form.assunto.focus();
	    return false;
	}else{
		form.submit();
	}
}

function envia_sugestao(form) {
    if (form.sugestao.value == ""){
	    alert('Os campos destacados são obrigatórios.');
	    form.email.focus();
	    return false;
    }else{
		form.submit();
	}
}

function ChecaMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
            return true;
        }
    }else{
        return false;
    }
}

function MascaraFormata(src, mascara) {
	var campo   = src.value.length;
	var saida   = mascara.substring(0,1);
	var texto   = mascara.substring(campo);
	if(texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

function FormataFone(fone,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.getElementById(fone).value;
	vr = vr.replace( " ", "" );
	vr = vr.replace( "(", "" );
	vr = vr.replace( ")", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length + 1;
	if (tecla != 9 && tecla != 8){
		if ( tam <= 10){
			if ( tam == 1)
				document.getElementById(fone).value = '(' + vr.substr( 0, 2 );
			if ( tam == 3)
				document.getElementById(fone).value = '(' + vr.substr( 0, 2 ) + ') ';
			if ( tam == 7)
				document.getElementById(fone).value = '(' + vr.substr( 0, 2 ) + ') ' + vr.substr( 2, 4 ) + '-';
			if ( tam == 10)
				document.getElementById(fone).value = '(' + vr.substr( 0, 2 ) + ') ' + vr.substr( 2, 4 ) + '-' + vr.substr( 6, 4 );
		}else{
			return false;
		}
	}
}

function sonum(e) {
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode;
	} else if(e.which) {
		// netscape
		key = e.which;
	} else {
		// no event, so pass through
		return true;
	}
	if ((key > 47 && key < 58) || (key == 8 || key == 9 || key == 127)){
	}else{
		return false;
	}
}
