﻿/* fechar DHTML */
function fechar() {
    try {
        var obj = document.getElementById('div_dhtml_home');
        if (obj.style.visibility == 'hidden') {
            obj.style.visibility = 'visible';
            obj.style.width = 'auto';
            obj.style.height = 'auto';
        }
        else {
            obj.style.visibility = 'hidden';
            obj.style.overflow = 'hidden';
            obj.style.width = '1px';
            obj.style.height = '1px';
            obj.style.bottom = '1px';
            obj.style.right = '1px';
			obj.style.display = 'none'

        }

    } catch (e) {
        status = e.message
    }
}


/* Busca */
function validaBusca(campoBusca) {
    if (document.getElementById(campoBusca).value == '') {
        alert('Atenção!!!\nInforme o conteúdo que deseja buscar.');
        document.getElementById(campoBusca).focus();
        return false;
    }
    else if (document.getElementById(campoBusca).value.length < 3) {
        alert('Atenção!!!\nInforme no minímo 3 letras.');
        document.getElementById(campoBusca).focus();
        return false;
    }
    return true
}

////////////////////////////////////////////////////////////////////////////////////
// Verifica qual campo está sendo digitado e dá o focus no botão correspondente
////////////////////////////////////////////////////////////////////////////////////
function setFocus(e, botaoId) {
    var tecla = window.event ? e.keyCode : e.which;

    if (tecla == 13) {
        document.getElementById('ctl00_' + botaoId).focus();
        document.getElementById('ctl00_' + botaoId).click();
    }
}

/* comentarios */
function LimitarCaracter(idCampo, idContador, TamMax) {
    Caracteres = TamMax - document.getElementById(idCampo).value.length;
    document.getElementById(idContador).innerHTML = Caracteres;
    if (document.getElementById(idCampo).value.length >= TamMax) {
        document.getElementById(idCampo).value = document.getElementById(idCampo).value.substring(0, TamMax);
        document.getElementById(idContador).innerHTML = "0";
    }
}  

/* fotos home_cidades */
var cidade_id;
var total_childs;
var Pos = 0;
var arrFotos = new Array(); ;

function proximo() {
    if (Pos == total_childs) {
        Pos = 0;
    } else {
        Pos = Pos + 1;
    }

    //fadeOut("lnk_foto", .3)
    //setTimeout(loadFoto, 700);

    loadFoto();
}

function anterior() {
    if (Pos == 0) {
        Pos = total_childs;
    } else {
        Pos = Pos - 1;
    }

    //fadeOut("lnk_foto", .3)
    //setTimeout(loadFoto,700);

    loadFoto();
}

function loadFoto() {
    var foto = document.getElementById("foto");
    var link = document.getElementById("lnk_foto");

    foto.src = "/Upload/cidade/cidade/" + cidade_id + "/Album/" + arrFotos[Pos][0];
    link.setAttribute('href', "cidade_foto.aspx?cidade_id=" + cidade_id + "&foto_id=" + arrFotos[Pos][1]);

    //fadeIn("lnk_foto", .5);
}

/* paginação */

function next_page() {
    if (pagina_atual < numPaginas) {
        pagina_atual++
        show_page(pagina_atual);
    }
}

function previous_page() {
    if (pagina_atual > 0) {
        pagina_atual--
        show_page(pagina_atual);
    }
}

function show_page(page) {
    var paginas = document.getElementById("ul_paginas").getElementsByTagName("li")

    for (var i = 0; i < paginas.length; i++) {
        if (i == page) {
            paginas[i].style.display = "block";
        }else{
            paginas[i].style.display = "none";
        }
    } 
    
}



/* menu */
var persistmenu = true;
var persisttype = true;

function abrir_menu(obj) {
    if (document.getElementById) {
        var el = document.getElementById('submenu' + obj);
        var ar = document.getElementById("ctl00_menu").getElementsByTagName("span");
        var tit = document.getElementById("ctl00_menu").getElementsByTagName("h1");
        
        if (el.style.display != "block") {
            for (var i = 0; i < ar.length; i++) {
                if (ar[i].className == "submenu") {
                    ar[i].style.display = "none";
                    tit[i].style.backgroundPosition = "0px -22px";
                }
            }

            document.getElementById("tit_" + obj).style.backgroundPosition = "0px 0px";
            el.style.display = "block";
        }
        else {
            el.style.display = "none";
        }
    }
}

function get_cookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    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;
            returnvalue = unescape(document.cookie.substring(offset, end))
        } else {
            returnvalue = 1;
        }
        
    }
    return returnvalue;
}

function onloadfunction() {
    if (persistmenu) {
        var cookiename = (persisttype) ? "abrir_menu" : window.location.pathname
        var cookievalue = get_cookie(cookiename)

        if (cookievalue != "") {
            try {
                document.getElementById("tit_" + cookievalue).style.backgroundPosition = "0px 0px";
                document.getElementById("submenu" + cookievalue).style.display = "block";
            } catch (e) { 
            
            }
            
        }
    }
}

function savemenustate() {
    var inc = 1, blockid = ""

    while (document.getElementById("submenu" + inc)) {
        if (document.getElementById("submenu" + inc).style.display == "block") {
            blockid = inc;
            break;
        }
        inc++
    }
    var cookiename = (persisttype) ? "abrir_menu" : window.location.pathname
    var cookievalue = (persisttype) ? blockid + ";path=/" : blockid

    document.cookie = cookiename + "=" + cookievalue
}


if (window.addEventListener) {
    window.addEventListener("load", onloadfunction, false)
}
else if (window.attachEvent) {
    window.attachEvent("onload", onloadfunction)
}
else if (document.getElementById) {
    window.onload = onloadfunction
}


if (persistmenu) {    
    window.onunload = savemenustate
}

/* efeito alfha */
function fadeOut(id, time) {
    target = document.getElementById(id);
    alpha = 100;
    timer = (time * 1000) / 50;
    var i = setInterval(
	function() {
	    if (alpha <= 0)
	        clearInterval(i);

	    setAlpha(target, alpha);
	    alpha -= 2;
	}, timer);
}

function fadeIn(id, time) {
    target = document.getElementById(id);
    alpha = 0;
    timer = (time * 1000) / 50;
    var i = setInterval(
	function() {
	    if (alpha >= 100)
	        clearInterval(i);

	    setAlpha(target, alpha);
	    alpha += 2;
	}, timer);
}

function setAlpha(target, alpha) {
    target.style.filter = "alpha(opacity=" + alpha + ")";
    target.style.opacity = alpha / 100;
}

/* Mídias */
function InsereFlash(Arquivo, Largura, Altura, FlashVars) {
    document.write('<object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0"');
    document.write('height="' + Altura + '" width="' + Largura + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" VIEWASTEXT>');
    document.write('<param name="_cx" value="15425">');
    document.write('<param name="_cy" value="741">');
    document.write('<param name="FlashVars" value="' + FlashVars + '">');
    document.write('<param name="Movie" value="' + Arquivo + '">');
    document.write('<param name="Src" value="' + Arquivo + '">');
    document.write('<param name="WMode" value="Transparent">');
    document.write('<param name="Play" value="-1">');
    document.write('<param name="Loop" value="-1">');
    document.write('<param name="Quality" value="High">');
    document.write('<param name="SAlign" value="">');
    document.write('<param name="Menu" value="-1">');
    document.write('<param name="Base" value="">');
    document.write('<param name="AllowScriptAccess" value="">');
    document.write('<param name="Scale" value="noscale">');
    document.write('<param name="DeviceFont" value="0">');
    document.write('<param name="EmbedMovie" value="0">');
    document.write('<param name="BGColor" value="">');
    document.write('<param name="SWRemote" value="">');
    document.write('<param name="MovieData" value="">');
    document.write('<param name="SeamlessTabbing" value="1">');
    document.write('<param name="Profile" value="0">');
    document.write('<param name="ProfileAddress" value="">');
    document.write('<param name="ProfilePort" value="0">');
    document.write('<embed src="' + Arquivo + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ');
    document.write('type="application/x-shockwave-flash" width="' + Largura + '" height="' + Altura + '" FlashVars="' + FlashVars + '" ');
    document.write('_cx="15425" _cy="741" WMode="Transparent" Menu="-1" Scale="noscale" DeviceFont="0" EmbedMovie="0" SeamlessTabbing="1" Profile="0" ProfilePort="0"></embed>');
    document.write('</object>');
}