/************* Desenvolvido por Geovani A. (geovanialvespereira@hotmail.com, geovani.bat@gmail.com) Cuiab� - MT ********************/
function modalWait(text){
    txt = '';//'<div class="a-center"><img src="images/ajax-loader1.gif" alt="Aguarde..." /></div>';
    if(text!='')
        txt += text;
    
    $.modal(txt,
    {
        overlayClose:false,
        escClose:false
    });
}
/**
 *  Fecha o modal 
 */
function modalWaitClose(){
    $.modal.close();
}
function loading() {
    var html = '<div class="a-center" style="padding: 20px 0;"><img src="images/loader_light_blue.gif" alt="Aguarde..." /></div>';
    return html;
}
function addEvent(obj, evType, fn){
    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, false);
    }
    if (obj.attachEvent){ 
        obj.attachEvent("on"+evType, fn);
    }
}

function validaEmail(email){
    //var email = document.getElementById(email);
    var filter = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    if(!filter.test(email)){
        return false;
    }
    return true;
}
// verifica login via ajax
function redirect(url){
    window.location.href = url;
}
function reload(url){
    window.location.href = window.location.href;
}
function preencher_campo(id, texto){
    var campo = document.getElementsByName(id);
    for(i=0;i<campo.length;i++){
        if(!campo[i].getAttribute("title") || campo[i].getAttribute("title") == ""){
            campo[i].setAttribute("title",texto);
        }
		
        var cValue = (texto == "")?campo[i].getAttribute("title"):texto;
        if(campo[i].value == ""){
            if(texto == ""){
                campo[i].value = cValue;
            }else{
                campo[i].value = cValue;
            }
        }
        campo[i].onblur = function(){
            if (this.value == ""){
                this.value = cValue;
            }
        }
        campo[i].onfocus = function(){
            if (this.value == this.getAttribute("title") || this.value == texto){
                this.value = "";
            //campo.style.textAlign = "left";
            }
        }
    }
}
function enviar_news(){
    var nome = document.getElementById("news_nome");
    var email = document.getElementById("news_email");
    if(nome.value == "" || nome.value.length < 4 || nome.value == nome.getAttribute("title")){
        alert("Por favor, informe-nos o seu Nome Corretamente.");
        nome.focus();
        nome.select();
        return false;
    }
    var filter = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    if(!filter.test(email.value)){
        alert("Por favor, informe-nos um e-mail v�lido.");
        email.focus();
        email.select();
        return false;
    }
    $.ajax({
        type: "post",
        url: "ajax_envia_news.php",
        data: "email="+email.value+"&nome="+nome.value,
        beforeSend:function(){
            //document.getElementById("tit_news").innerHTML = "Aguarde...";
            nome.disabled = 1;
            email.disabled = 1;
        },
        success:function(e){
            //document.getElementById("tit_news").innerHTML = e;
            nome.disabled = 0;
            email.disabled = 0;
            //alert("Obrigado por se Cadastrar!")
            alert('Obrigado por se Cadastrar!');
        }
    })
}
var G3 = {
	contaChar: function contaChar(e, maxChar, result){
	    ele = $(e);
	    //var campo = document.getElementById(id);
	    var result = (result == '' || result == null)?ele.next():$(result);
	    if(ele.val().length >= maxChar){
	        ele.val() = ele.val().substring(0, maxChar);
	    }
	    if(result != ""){
	        result.html(ele.val().size()+" de "+maxChar+" Caracteres.")
	    }
	} 
}
function contaChar(e, maxChar, result){
    var e = (!e)?window.event:e;
    var ele = e.target || e.srcElement;
    //var campo = document.getElementById(id);
    var result = (result == '' || result == null)?campo.nextSibling:document.getElementById(result);
    if(ele.value.length >= maxChar){
        ele.value = ele.value.substring(0, maxChar);
    }
    if(result != ""){
        result.innerHTML = ele.value.length+" de "+maxChar+" Caracteres.";
    }
}

function contaClickBanner(id, url_redirect){
    pg("conta_click_banner.php", "id_banner="+id, '');
    window.open(url_redirect,'new');
    return false
}
function popup($url, width, height){
    var width = (width=='')?760:width;
    var height = (height=='')?window.screen.height-100:height;
    window.open($url, 'new', 'width='+width+',height='+height+',resizable=1,top=10,Scrollbars=1')
}
/***********************************************************/
function mostraRelogio(){
    data = new Date()
    hora = data.getHours()
    minuto = data.getMinutes()
    segundo = data.getSeconds()

    hora_atual = (hora<10?'0'+hora:hora) + ":" + (minuto<10?'0'+minuto:minuto) + ":" + (segundo<10?'0'+segundo:segundo);

    document.getElementById('hora_hoje').innerHTML = hora_atual;

    setTimeout("mostraRelogio()",1000)
}
function ie(){
    return ((window.navigator.appName.indexOf('Microsoft Internet Explorer') != -1)?true:false);
}
start_loading_page = new Date()
function getTimePageLoading()  {
    stop_loading_page = new Date()
    tempo = stop_loading_page.getTime() - start_loading_page.getTime();
    if(document.getElementById("time_page_load"))
        document.getElementById("time_page_load").innerHTML = "Tempo gasto para carregar a p�gina: " + tempo + " mil�simos";

}
function log(msg){
    if(window.console){
        window.console.log(msg);
    }
}
