﻿/* por Rodolfo Paoni
* E-mail: rpaoni@ctallen.com.br
* Allen Informática - 2010
*/
window.onload = mudaBusca;
var caixaBusca = "ctl00_cbxBusca_";
var cadastrarNewsLetter = "ctl00_CadastrarNewsLetter_";
var master = "ctl00_Main_";
String.prototype.trim = function() {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
String.prototype.isValidEmail = function() {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    return this.match(re);
};
function mudaBusca() {
    var inp = document.getElementById(caixaBusca + "txtBusca");
    if (!inp) {
        return;
    }
    var txt = "Buscar";
    var clr = "#000";
    inp.value = txt;
    inp.style.color = clr;
    inp.onfocus = function mudaBusca() {
        this.value = "";
        this.style.color = "#000";

    }
    inp.onblur = function mudaBusca2() {
        if (this.value.trim() == "") {
            this.style.color = clr;
            this.value = txt;
        }
    }
    startList = function() {
        if (document.all && document.getElementById) {
            navRoot = document.getElementById("nav");
            for (i = 0; i < navRoot.childNodes.length; i++) {
                node = navRoot.childNodes[i];
                if (node.nodeName == "LI") {
                    node.onmouseover = function() {
                        this.className += " over";
                    }
                    node.onmouseout = function() {
                        this.className = this.className.replace
	(" over", "");
                    }
                }
            }
        }
    }
    window.onload = startList;
}
function showMenu(menu) {
    obj = document.getElementById(menu);
    if (obj.style.display == "block") {
        obj.style.display = "none";
    }
    else {
        obj.style.display = "block";
    }
}
// CadastrarNewsLetter.ascx
function validarNewsLetter() {
    var txtNome = document.getElementById(cadastrarNewsLetter + "txtNome");
    var txtEmail = document.getElementById(cadastrarNewsLetter + "txtEmail");
    if (txtNome.value.trim() == "" || txtEmail.value.trim() == "") {
        window.alert("Os campos nome e e-mail são de preenchimento obrigatório.");
        return false;
    }
    if (!txtEmail.value.isValidEmail()) {
        window.alert("E-mail em formato inválido.");
        txtEmail.focus();
        return false;
    }
    return true;
}
// CaixaBusca.ascx
function validarBuscar() {
    var txtBusca = document.getElementById(caixaBusca + "txtBusca");
    if (txtBusca.value.trim() == "" || txtBusca.value.trim() == "Buscar" || txtBusca.value.trim() == "buscar") {
        window.alert("Informe algum critério de busca.");
        txtBusca.focus();
        return false;
    }
    if (txtBusca.value.trim().length < 3) {
        window.alert("O critério de busca deve conter ao menos 3 caracteres.");
        txtBusca.focus();
        return false;
    }
    return true;
}
// FaleConosco.aspx
function validarFaleConosco() {
    var txtNome = document.getElementById(master + "txtNome");
    var txtEmail = document.getElementById(master + "txtEmail");
    var txtAssunto = document.getElementById(master + "txtAssunto");
    var txtMensagem = document.getElementById(master + "txtMensagem");
    var txtTelefone = document.getElementById(master + "txtTelefone");
    var ddlUnidade = document.getElementById(master + "ddlUnidade");
    if (txtNome.value.trim() == "" || txtEmail.value.trim() == "" || txtAssunto.value.trim() == ""
        || txtTelefone.value.trim() == "" || txtMensagem.value.trim() == "" || ddlUnidade.value.trim() == "0") {
        window.alert("Os campos nome, e-mail, assunto, telefone, unidade e mensagem\nsão de preenchimento obrigatório.");
        return false;
    }
    if (!txtEmail.value.isValidEmail()) {
        window.alert("E-mail em formato inválido.");
        txtEmail.focus();
        return false;
    }
    return true;
}
function retirarAcentos(campo) {
    var texto = campo.value;
    var acento = '.áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';
    var semacento = '.aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
    var nova = '';

    for (i = 0; i < texto.length; i++) {
        if (acento.search(texto.substr(i, 1)) >= 0) {
            nova += semacento.substr(acento.search(texto.substr(i, 1)), 1);
        }
        else {
            nova += texto.substr(i, 1);
        }
    }
    campo.value = nova;
}
