function webmail(){
	var ad = document.form_webmail;
	var vv = document.getElementById("ec_l");
	var bb = document.getElementById("ec_s");

	
	if (ad.email.value == "") {
		ad.email.value = '';
        vv.innerHTML = "Obrigatório";
		vv.style.color = "#c00";
		vv.style.display = "inline";
		bb.style.display = "none";
		ad.email.focus();
	    return false;
    }
	
	
	if (ad.password.value == "") {
		bb.innerHTML = "Obrigatório";
		bb.style.color = "#c00";
		bb.style.display = "inline";
		vv.style.display = "none";
		ad.password.focus();
		return false;}
		return true;
	
}

function webmail_interno(){
	var ad = document.form_webmail_interno;
	var vv = document.getElementById("ec_l2");
	var bb = document.getElementById("ec_s2");

	
	if (ad.email.value == "") {
		ad.email.value = '';
        vv.innerHTML = "Obrigatório";
		vv.style.color = "#c00";
		vv.style.display = "inline";
		bb.style.display = "none";
		ad.email.focus();
	    return false;
    }
	
	
	if (ad.password.value == "") {
		bb.innerHTML = "Obrigatório";
		bb.style.color = "#c00";
		bb.style.display = "inline";
		vv.style.display = "none";
		ad.password.focus();
		return false;}
		return true;
	
}

function atendimento(id) {
	var url = 'http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee='+id+'@apps.messenger.live.com&mkt=pt-br';
	window.open(url,'','width=500,height=400,top=19,left=19,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
}

function contato(){
    var mensarem_erro = "", cont_erro = 0;
    var ad = document.getElementById('form_contato');
    var d = document.getElementById('erro').style;
    
    $('html,body').animate({
        scrollTop: $('.tit-h2').offset().top
    }, 800);
    
    
    if (ad.nome_cont.value == "") {
        mensarem_erro += "<b>Nome:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        cont_erro++;
        
    }
    
    
    if (ad.email_cont.value == "") {
        mensarem_erro += "<b>Email:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        
        cont_erro++;
    }
    
    if (ad.email_cont.value != "") {
        if (!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email_cont.value))) {
            mensarem_erro += "<b>E-mail:</b> Inválido<br />";
            d.display = 'block';
            cont_erro++;
        }
    }
	
	if (ad.tel_cont.value == "") {
        mensarem_erro += "<b>Telefone:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        
        cont_erro++;
    }
    
    if (ad.cidade_cont.value == "") {
        mensarem_erro += "<b>Cidade:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        cont_erro++;
    }
    
    if (ad.estado_cont.value == "") {
        mensarem_erro += "<b>Estado:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        cont_erro++;
    }
    
    if (ad.assunto_cont.value == "") {
        mensarem_erro += "<b>Assunto:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        cont_erro++;
    }
    
    if (ad.texto_cont.value == "") {
        mensarem_erro += "<b>Comentário:</b> é de preenchimento obrigatório<br />";
        d.display = 'block';
        cont_erro++;
    }
    
    if (cont_erro > 0) {
    
        document.getElementById("erro").style.display = "block";
        var mensagem_final = "<h4>Foram encontrados " + cont_erro + " erros no formulário.</h4><p class=\"er\">" + mensarem_erro + "</p>";
        document.getElementById("erro").innerHTML = mensagem_final;
        //location.href="#erro";	
        return false;
    }
    
    return true;
    
}




function indique(){
    var mensarem_erro = "", cont_erro = 0;
    var ad = document.form_indique;
    
    $('html,body').animate({
        scrollTop: $('.tit-h2').offset().top
    }, 800);
    
    if (ad.nome.value == "") {
        mensarem_erro += "<b>Seu Nome:</b> é de preenchimento obrigatório<br />";
        cont_erro++;
    }
    if (ad.email.value == "") {
        mensarem_erro += "<b>Seu e-mail:</b> é de preenchimento obrigatório<br />";
        cont_erro++;
    }
    if (!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email.value))) {
        mensarem_erro += "<b>Seu e-mail:</b> inválido<br />";
        cont_erro++;
    }
    if (ad.nome_a.value == "") {
        mensarem_erro += "<b>Nome amigo:</b> é de preenchimento obrigatório<br />";
        cont_erro++;
    }
    if (ad.email_a.value == "") {
        mensarem_erro += "<b>E-mail amigo:</b> é de preenchimento obrigatório<br />";
        cont_erro++;
    }
    if (!(/^\w+([\.-_-]?\w+)*@\w+([\.-_-]?\w+)*(\.\w{2,4})+$/.test(ad.email_a.value))) {
        mensarem_erro += "<b>E-mail amigo:</b> inválido<br />";
        cont_erro++;
    }
    if (ad.comentario.value == "") {
        mensarem_erro += "<b>Comentário:</b> é de preenchimento obrigatório<br />";
        cont_erro++;
    }
    if (cont_erro > 0) {
        document.getElementById("erro").style.display = "block";
        var mensagem_final = "<h4>Foram encontrados " + cont_erro + " erros no formulário.</h4><p class=\"er\">" + mensarem_erro + "</p>";
        document.getElementById("erro").innerHTML = mensagem_final;
        return false;
    }
}


/********telefone***********/
function mascara(o, f){
    v_obj = o
    v_fun = f
    setTimeout("execmascara()", 1)
}

function execmascara(){
    v_obj.value = v_fun(v_obj.value)
}

function telefone(v){
    v = v.replace(/\D/g, "")
    v = v.replace(/^(\d\d)(\d)/g, "($1) $2")
    v = v.replace(/(\d{4})(\d)/, "$1-$2")
    return v
}





var shortPass = '<p class="senha_cur" id="barra">Muito curta</p>'
var badPass = '<p class="senha_rui" id="barra">Ruim</p>'
var goodPass = '<p class="senha_roz" id="barra">Boa</p>'
var strongPass = '<p class="senha_rel" id="barra">Relevante</p>'

function passwordConf(password, username){
    score = 0
    
    if (password.length < 4) {
        return document.getElementById('result_forca_pass').innerHTML = shortPass;
    }
    
    
    
    if (password.toLowerCase() == username.toLowerCase()) 
        return document.getElementById('result_forca_pass').innerHTML = badPass;
    
    score += password.length * 4
    score += (checkRepetition(1, password).length - password.length) * 1
    score += (checkRepetition(2, password).length - password.length) * 1
    score += (checkRepetition(3, password).length - password.length) * 1
    score += (checkRepetition(4, password).length - password.length) * 1
    
    if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) 
        score += 5
    if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) 
        score += 5
    if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) 
        score += 10
    if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) 
        score += 15
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) 
        score += 15
    if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) 
        score += 15
    if (password.match(/^w+$/) || password.match(/^d+$/)) 
        score -= 10
    
    if (score < 0) 
        score = 0
    if (score > 100) 
        score = 100
    
    if (score < 34) 
        return document.getElementById('result_forca_pass').innerHTML = badPass;
    if (score < 68) 
        return document.getElementById('result_forca_pass').innerHTML = goodPass;
    return document.getElementById('result_forca_pass').innerHTML = strongPass;
}

function checkRepetition(pLen, str){
    res = ""
    for (i = 0; i < str.length; i++) {
        repeated = true
        for (j = 0; j < pLen && (j + i + pLen) < str.length; j++) 
            repeated = repeated && (str.charAt(j + i) == str.charAt(j + i + pLen))
        if (j < pLen) 
            repeated = false
        if (repeated) {
            i += pLen - 1
            repeated = false
        }
        else {
            res += str.charAt(i)
        }
    }
    return res
}



function aboft(){
    var xmlhttp = false;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (E) {
            xmlhttp = false;
        }
    }
    
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}





function limp(obj){
    document.getElementById(obj).style.display = "none";
}



function LimpaCampos(form){
    var input = document.getElementById(form).getElementsByTagName('input')
    var select = document.getElementById(form).getElementsByTagName('select')
    var textarea = document.getElementById(form).getElementsByTagName('textarea')
    
    for (var i = 0; i < select.length; i++) 
        select[i].selectedIndex = 0;
    
    for (var i = 0; i < textarea.length; i++) 
        textarea[i].value = '';
    
    for (var i = 0; i < input.length; i++) 
        switch (input[i].type) {
            case 'text':
                input[i].value = '';
                break;
            case 'radio':
                input[i].checked = '';
                break;
            case 'checkbox':
                input[i].checked = '';
                break;
        }
    
}


function fecharBox(obj){
    $("#" + obj).slideUp(600);
}


var Convert = {
    initialize: function(){
        var spans = document.getElementsByTagName("span");
        for (var i = 0; i < spans.length; i++) {
            if (spans[i].getAttribute("class") == "maskemail") {
                string = spans[i].childNodes[0].nodeValue;
                email = string.split("_")[0] + "@" + string.split("_")[1] + "." + string.split("_")[2] + "." + string.split("_")[3];
                spans[i].innerHTML = '<a class="email" href="mailto:' + email + '">' + email + '<\/a>';
            }
        }
    }
}
window.onload = Convert.initialize;



function OpenAjax(obj, url, ajax){
    var obj;
    obj = document.getElementById(obj);
    
    ajax = aboft();
    
    ajax.open("GET", 'ajax/' + url + '.php', true);
    
    obj.style.display = 'block';
    
    ajax.onreadystatechange = function(){
        if (ajax.readyState == 1) {
            obj.innerHTML = '<img src="images/loading.gif" align="absmiddle" style="margin-right:3px;" /> Carregando...';
        }
        else 
            if (ajax.readyState == 4) {
            
                if (ajax.status == 200) {
                
                    obj.innerHTML = ajax.responseText;
                    
                }
                else 
                    if (ajax.status == 404) {
                        obj.innerHTML = "Pgina no encontrada";
                    }
                    else {
                        obj.innerHTML = "Error:".ajax.status;
                    }
            }
    }
    ajax.send(null);
}


function setField_enquete(){
    var f = document.getElementById('form_enquete');
    var op = document.form_enquete.opcao.value;
    
    //var cp = document.getElementById('opcao').value;
    
    var resposta;
    var tamanho = f.opcao;
    marcado = 0;
    for (i = 1; i <= eval(tamanho.length + 2); i++) {
        if (f[i].checked != '') {
            marcado = i;
            resposta = f[i].value;
            
        }
    }
    
    if (marcado == 0) {
        alert("Selecione uma opção de voto.");
        f.opcao[0].focus();
        return false;
    }
    else {
        return VotaEnquete(resposta, '' + encodeURI(document.getElementById('acao_enquete').value) + '');
    }
}

function VotaEnquete(opcao, acao){
    var obj, preloaderEnquete;
    obj = document.getElementById('resultEnquete');
    preloaderEnquete = document.getElementById('preloader-enquete');
    
    
    ajax = aboft();
    
    ajax.open("GET", 'ajax/enquete.php?opcao=' + opcao + '&acao=' + acao, true);
    
    ajax.onreadystatechange = function(){
        if (ajax.readyState == 1) {
            preloaderEnquete.innerHTML = '<img src="images/loading.gif" align="absmiddle" style="margin-right:3px;" /> Votando...';
        }
        else 
            if (ajax.readyState == 4) {
                if (ajax.status == 200) {
                
                    obj.innerHTML = ajax.responseText;
					$(".box-enquete").hide();
					$(".box-enquete").fadeIn("slow");
					
     
                    
                }
                else 
                    if (ajax.status == 404) {
                        obj.innerHTML = "Pgina no encontrada";
                    }
                    else {
                        obj.innerHTML = "Error:".ajax.status;
                    }
            }
    }
    ajax.send(null);
}



function opacity(id, opacStart, opacEnd){
    var speed = Math.round(1500 / 150);
    var timer = 0;
    
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
    else 
        if (opacStart < opacEnd) {
            for (i = opacStart; i <= opacEnd; i++) {
                setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
                timer++;
            }
        }
}

function changeOpac(opacity, id){
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}


function createCookie(name, value, days){
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
        var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name){
    var cookieValue = "";
    var search = name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) 
                end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}


function zoomText(tipo){

    if (tipo == 0) {
        tam = 13;
    }
    else {
        tam = 16;
    }
    
    createCookie('TextSize', tam, 86400);
    document.getElementById('all').style.fontSize = tam + 'px';
    document.getElementById('footer').style.fontSize = tam + 'px';
    
}


function getZoomText(){

    var setTamCookie = readCookie('TextSize');
    
    document.getElementById('all').style.fontSize = setTamCookie + 'px';
    document.getElementById('footer').style.fontSize = setTamCookie + 'px';
    
    
}


function preLoadPicture(pic) {
	heavyImage = new Image(); 
	heavyImage.src = CurUrl + pic + ".jpg";
};

var OriPicNum = "1";
var CurDocument = 0;
var CurPicNum = "1";
var CurUrl = "";

function getNextThumbNum(CurNum) {
	thumbs = new Array('1','2','3');
	for (i = 0; i < thumbs.length; i++) {
		if (thumbs[i] > CurNum) {
			return thumbs[i];
		}
	}
	return thumbs[0];
};

function nextThumbnail(idDoc) {
	if ( idDoc == CurDocument) {
		document.getElementById("pic_" + CurDocument).src = CurUrl + "/" + CurPicNum + ".jpg";
		//alert(CurUrl + "/" + CurPicNum + ".jpg");
		nextthumb = getNextThumbNum(CurPicNum);
		preLoadPicture(nextthumb);
		CurPicNum = nextthumb;
		setTimeout("nextThumbnail("+ CurDocument +")", 1000);
	}
};

function stopThumbSlide(OriPicNum) {
	TmpDoc = CurDocument;
	CurDocument = 0;
	document.getElementById("pic_" + TmpDoc).src = CurUrl + "/1.jpg";	
};

function startThumbSlide(IdDoc, CurNum, Url) {
	if (CurDocument == 0) {
		OriPicNum = CurNum;
		CurDocument = IdDoc;
		CurUrl = Url;
		nextthumb = getNextThumbNum(CurNum);
		preLoadPicture(nextthumb);
		CurPicNum = nextthumb;
		setTimeout("nextThumbnail("+ CurDocument +")", 20);
	}
};

function trocaVideoHome(idv, line){
	
	$(".embed_player").html('<object width="250" height="219"><param name="movie" value="http://www.youtube.com/v/' + idv + '?autoplay=1&fs=1&amp;hl=pt_BR&amp;rel=0&amp;color1=0xffffff&amp;color2=0xffffff"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + idv + '?autoplay=1&fs=1&amp;hl=pt_BR&amp;rel=0&amp;color1=0xffffff&amp;color2=0xffffff" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="250" height="219"></embed></object>');
	
	$(".mais_videos li > a").removeClass('focu');
	$(".mais_videos #lineVideo_"+line+" a").addClass('focu');
	
};

function functionsJquery(){

    $("#nav a").hover(function(){
        $(this).animate({
            lineHeight: "30px"
        }, 300);
        
    }, function(){
        $(this).animate({
            lineHeight: "26px"
        }, 300);
    });
	
	// Linght box
	$("a[rel='openFotosLightbox']").colorbox({
         slideshow:false, 
		 slideshowAuto: false,
		 transition:'fade', 
		 opacity:0.75, 
		 slideshowSpeed:3000, 
		 slideshowStart : 'Play slideshow',
		 slideshowStop : 'Stop slideshow',
		 returnFocus : true
   });
	
	$("a[rel='openVideo']").colorbox({
		iframe:true, innerWidth:600, innerHeight:440,
		returnFocus : true
	});

       
}
