var emailValidacao_RegEx = /^[a-z0-9][\w\.-]*[a-z0-9]@[a-z0-9][\w\.-]*[a-z0-9]\.[a-z0-9][a-z\.]*[a-z]$/;
var emailValidacao_MsgErro = 'O e-mail digitado não é válido.';


function FormFaleConoscoValida(FormField) {
    if (faleconosco.txtEmail.value == '') {
        alert('O seu e-mail não foi preenchido.');
        return false;
    }
    else if (faleconosco.txtTitulo.value == '') {
        alert('O título não foi preenchido.');
        return false;
    }
    else if (faleconosco.txtMensagem.value == '') {
        alert('A mensagem não foi preenchida.');
        return false;
    }
    else return ValidaRegEx(faleconosco.txtEmail, emailValidacao_RegEx, emailValidacao_MsgErro);
}


function ValidaRegEx(campoOrigem, regularEx, mensagemErro) {
    var valor = campoOrigem.value;

    if (regularEx.test(valor.toLowerCase()) == false) {
        alert('O e-mail digitado não é válido.');
        campoOrigem.focus()
        return false;
    }
    return true;
}


function Trim(strIn) {
    return strIn.replace(/^\s+|\s+$/g, "");
}


function Ajax(url, method, returntag, parameters) {

    try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (ex) {
            try {
                xmlhttp = new XMLHttpRequest();
            }
            catch (exc) {
                //alert("Esse browser não tem recursos para uso do Ajax");
                xmlhttp = null;
            }
        }
    }

    url = url + '?' + Math.random();

    if (method == "GET") {
        xmlhttp.open("GET", url, true);
    } else {
        xmlhttp.open("POST", url, true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
        xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
        xmlhttp.setRequestHeader("Pragma", "no-cache");
    }

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 1) {
            //document.getElementById(returntag).innerHTML='<img src="load.gif">'
        }
        if (xmlhttp.readyState == 4 && returntag != '') {
            //alert(xmlhttp.responseText);
            document.getElementById(returntag).innerHTML = xmlhttp.responseText;
        }
    }

    if (method == "GET") {
        xmlhttp.send(null);
    } else {
        xmlhttp.send(parameters);
    }

}

function PopUpNaoSeiCep() {
    window.open('http://servicos.glamour.com.br/cepprocurar.asp', 'cep', 'resizable=0,scrollbars=1,width=600,height=500,top=20,left=20');
    return false;
} 


function PopUp(href, width, height, name, scroll) {
    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;
    window.open(href, name, 'scrollbars=' + scroll + ',status=0,menubar=0,resize=0,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left)
}


function swapImage(imgD, imgS) {
    if (document.images) document.images[imgD].src = document.images[imgS].src;
}

function CheckOut(flag) {
    form_cesta.checkout.value = flag;
    form_cesta.submit();
}

//validador de e-mail, bastando passar o componente e a mensagem de erro
//ex: ValidaEmail(document.getElementById('email'),'Email incorreto')
function ValidaEmail(email,mensagem) {
    var obj = eval(email);
    var txt = obj.value;
    if ((txt.length != 0) && ((txt.indexOf("@") < 1) || (txt.indexOf('.') < 7))) {
        alert(mensagem);
        obj.focus();
        return false;
    }
    else {
        return true;
    }
}