function centraliza(largura,altura){
	window.moveTo((window.screen.width-largura)/2,(window.screen.height-altura)/2);
}

function abreJanela(arquivo,nome,barra,largura,altura) {
	window.open(arquivo,nome,"resizable=no,toolbar=no,status=no,menubar=no,scrollbars="+barra+",width="+largura+",height="+altura);
}

function redimenciona(){
	var i=0;
	function resize() {
		if (navigator.appName == 'Netscape') i=40;
		if (document.images[0]) window.resizeTo(document.images[0].width +50, document.images[0].height+80-i);
		if (window.moveTo((window.screen.width-document.images[0].width)/2,(window.screen.height-document.images[0].height)/2));
	}
}

function StringBuffer() { this.buffer = []; }
StringBuffer.prototype.append = function(string) {
    this.buffer.push(string);
    return this;
}

StringBuffer.prototype.toString = function() {
    return this.buffer.join("");
}

function montaSWF(arquivo,largura,altura,action){
	var now = new Date();	
	var dia = now.getDay();
	var mes = now.getMonth();
	var ano = now.getFullYear();
	var hora = now.getHours();
	var mintuto = now.getMinutes();
	var segundo = now.getSeconds();
	var data = ano+""+mes+""+dia+""+hora;

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + largura + '" height="' + altura + '">');
	document.write('<param name="movie" value="'+ arquivo +'.swf?ieSux='+ data +'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="FlashVars" value="'+ action +'&clearCache='+ data +'" />');
	document.write('<embed FlashVars="'+ action +'&clearCache='+ data +'" wmode="transparent" menu="false" src="'+ arquivo +'.swf?ieSux='+ data +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + largura + '" height="' + altura + '"></embed>');
	document.write('</object>');
}

function montaSWF2(arquivo,action){
	var now = new Date();	
	var dia = now.getDay();
	var mes = now.getMonth();
	var ano = now.getFullYear();
	var hora = now.getHours();
	var mintuto = now.getMinutes();
	var segundo = now.getSeconds();
	var data = ano+""+mes+""+dia+""+hora;

	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="707" height="100%">');
	document.write('<param name="movie" value="'+ arquivo +'.swf?ieSux='+ data +'" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="menu" value="false" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<param name="salign" value="t" />');
	document.write('<param name="align" value="top" />');
	document.write('<param name="FlashVars" value="'+ action +'&clearCache='+ data +'" />');
	document.write('<embed align="top" salign="t" scale="noscale" FlashVars="'+ action +'&clearCache='+ data +'" wmode="transparent" menu="false" src="'+ arquivo +'.swf?ieSux='+ data +'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="707" height="100%"></embed>');
	document.write('</object>');
}
function estica(param){
	var dv = document.getElementById("esticaGaleria");
	dv.style.height = param+"px";
}

Resize = function(i,largura,altura)
{
	var	w = largura;
	var h = altura;
    var img = i;
	img.style.display = '';
	var	iw = img.width;
	var	ih = img.height;
	
	if(iw > w || ih > h) {
		var nim = iw / w;
		if (ih / nim > h) {
		    nim = ih / h;
		}
		w = Math.round(iw / nim);
		h = Math.round(ih / nim);
		
		img.setAttribute('width',w);
		img.setAttribute('height',h);
	}
}

function tamanho () {
	var dinamico = document.getElementById('video_comentarios');
	
	var menu = document.getElementById('menu-interna');
	var cent = document.getElementById('colCentral-interna');
	var dire = document.getElementById('publicidade-interna');
	
	var Vdim = dinamico.offsetHeight;
	var Vmenu = menu.offsetHeight;
	var Vcent = cent.offsetHeight;
	var Vdire = dire.offsetHeight;
	
	//alert(Vdim);
	//document.getElementById('video_comentarios').style.height=Vdim +"px";
	
	if (Vmenu > Vcent || Vmenu > Vdire) {
		alert("esquerda é maior")
	}
	else if (Vcent > Vmenu || Vcent > Vdire) {
		
		document.getElementById('menu-interna').style.height=Vcent +"px";
		document.getElementById('publicidade-interna').style.height=Vcent +"px";
		
		alert(menu.offsetHeight + " - " + cent.offsetHeight + " - " + dire.offsetHeight);
		
		menu.style.height=Vcent +"px";
		dire.style.height=Vcent +"px";
		
	}
	else if (Vdire > Vmenu || Vdire > Vcent) {
		alert("direita é maior")
	}
}

function busca(input, evento, url) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if (tecla == 8 || tecla == 46 || tecla == 39 || tecla == 37 || tecla == 36 || tecla == 35 || tecla == 9) {
        return true;
    }
    if (tecla == 13) {
        evento.returnValue = false;
        window.location.href = url + '/buscar.aspx?q=' + input.value;
        return false;
    }
}

var ie =(((navigator.userAgent.indexOf("MSIE")>-1)||(navigator.userAgent.indexOf("Mozilla/5.0")>-1))&&navigator.userAgent.indexOf("Opera")==-1?true:false);
var ns =(navigator.userAgent.indexOf("Netscape")>-1&&navigator.userAgent.indexOf("Opera")==-1?true:false);
function ajustar_cep(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 5) {
            input.value += "-";
        }
    }
    return true;
}

function ajustar_data(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 2 || input.value.length == 5) {
            input.value += "/";
        }
    }
    return true;
}

function ajustar_cpf(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 3 || input.value.length == 7) {
            input.value += ".";
        }
        if (input.value.length == 11) {
            input.value += "-";
        }
    }
    return true;
}

function autotab(original, destination) {
    if (original.getAttribute && original.value.length == original.getAttribute("maxlength"))
        destination.focus();
}

function enviar_ass(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla == 13) {
        ass_envia();
        return false;
    }
    return true;
}

function enviar_ass_cep(input, evento) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla == 13) {
        ass_envia();
        return false;
    }
    if (tecla < 48 || tecla > 57) {
        evento.returnValue = false;
        return false;
    }
    else {
        if (input.value.length == 5) {
            input.value += "-";
        }
    }
    return true;
}

function ass_envia() {
    f = document.forms[0];
    if (!f.assNome.value) {
        alert('Nome não foi preenchido corretamente.');
        f.assNome.focus();
        return false;
    }
    else if (!f.assEmail.value) {
        alert('E-mail não foi preenchido corretamente.');
        f.assEmail.focus();
        return false;
    }
    else if (!f.assCep.value) {
        alert('CEP não foi preenchido corretamente.');
        f.assCep.focus();
        return false;
    }
    else {
        window.location.href = 'cep.asp?origem=rodape' + ajaxDoFormPost("ass_rodape");
        return false;
    }
}

function validar_assinatura() {
    f = document.forms[0];
    if (!f.txtNome.value) {
        alert(unescape('O campo Nome n%E3o foi preenchido corretamente.'));
        f.txtNome.focus();
        return false;
    }
    if (!f.txtEmail.value) {
        alert(unescape('O campo E-mail n%E3o foi preenchido corretamente.'));
        f.txtEmail.focus();
        return false;
    }
    if (!f.txtCpf.value) {
        alert(unescape('O campo CPF n%E3o foi preenchido corretamente.'));
        f.txtCpf.focus();
        return false;
    }
    if (!f.txtCep.value) {
        alert(unescape('O campo CEP n%E3o foi preenchido corretamente.'));
        f.txtCep.focus();
        return false;
    }
    if (!f.txtEndereco.value) {
        alert(unescape('O campo Endere%E7o n%E3o foi preenchido corretamente.'));
        f.txtEndereco.focus();
        return false;
    }
    if (!f.txtNumero.value) {
        alert(unescape('O campo N%FAmero n%E3o foi preenchido corretamente.'));
        f.txtNumero.focus();
        return false;
    }
    if (!f.txtBairro.value) {
        alert(unescape('O campo Bairro n%E3o foi preenchido corretamente.'));
        f.txtBairro.focus();
        return false;
    }
    if (!f.txtCidade.value) {
        alert(unescape('O campo Cidade n%E3o foi preenchido corretamente.'));
        f.txtCidade.focus();
        return false;
    }
    if (!f.ddlEstado.value) {
        alert(unescape('O campo Estado n%E3o foi preenchido corretamente.'));
        f.ddlEstado.focus();
        return false;
    }
    if (!f.txtResidencial.value) {
        alert(unescape('O campo Tel Res. n%E3o foi preenchido corretamente.'));
        f.txtResidencial.focus();
        return false;
    }
    if (!vradio(f.radPlano)) {
        alert('Selecione o Plano Desejado.');
        return false;
    }
    if (!vradio(f.radPagamento)) {
        alert('Selecione a Forma de Pagamento.');
        return false;
    }
}

function validar_comentario() {
    f = document.forms[0];
    if (!f.txtNome.value) {
        alert('Favor preencha o campo Nome.');
        f.txtNome.focus();
        return false;
    }
    if (!f.txtEmail.value) {
        alert('Favor preencha o campo E-mail.');
        f.txtEmail.focus();
        return false;
    }
    if (!f.txtEmail.value.match(/^([a-zA-Z0-9_-][a-zA-Z0-9_.-]+@([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,4})$/)) {
        alert(unescape('Endere%E7o de E-mail inv%E1lido.'));
        f.txtEmail.focus();
        return false;
    }
    if (!f.txtMensagem.value) {
        alert(unescape('Favor preencha o campo Coment%E1rio.'));
        f.txtMensagem.focus();
        return false;
    }
}

function vradio(obj) {
    key = false;
    for(i = 0; i < obj.length; i++) {
        if (obj[i].checked) {
            key = true;
            break;
        }
    }
    return key;
}

function MM_Show(obj) {
    if (document.getElementById(obj).style.display == '')
        document.getElementById(obj).style.display = 'none';
    else
        document.getElementById(obj).style.display = '';
}

function enviaenter(input, evento, destino, titulo) {
    var tecla = (evento.keyCode ? evento.keyCode: evento.which ? evento.which : evento.charCode);
    if ((tecla == 8)||(tecla == 46)||(tecla == 39)||(tecla == 37)||(tecla == 36)||(tecla == 35)||(tecla == 9)) {
        return true;
    }
    if (tecla == 13) {
        switch(destino) {
            case "amigo":
                enviar_amigo(titulo);
                break;
            case "erro":
                enviar_erro(titulo);
                break;
        }
        return false;
    }
    return true;
}

// ENVIAR AMIGO
function enviar_amigo(titulo) {
    f = ajaxDoFormPost("enviar_amigo");
    nome = document.getElementById("amigo_nome");
    email = document.getElementById("amigo_email");
    
    if (!nome.value) {
        alert('O campo Nome deve ser preenchido.');
        nome.focus();
    }
    else if (!email.value) {
        alert('O campo E-mail deve ser preenchido.');
        email.focus();
    }
    else {
        doRequest("/server.aspx?act=amigo&titulo=" + titulo + "&url=" + encodeURIComponent(window.location) + f,resposta_amigo);
    }
}

function resposta_amigo(f) {
    document.getElementById("amigo_nome").value = "";
    document.getElementById("amigo_email").value = "";
    alert(f);
}

// COMUNICAR ERRO
function enviar_erro(titulo) {
    f = ajaxDoFormPost("enviar_erro");
    nome = document.getElementById("erro_nome");
    email = document.getElementById("erro_email");
    descricao = document.getElementById("erro_descricao");
    
    if (!nome.value) {
        alert('O campo Nome deve ser preenchido.');
        nome.focus();
    }
    else if (!email.value) {
        alert('O campo E-mail deve ser preenchido.');
        email.focus();
    }
    else if (!descricao.value) {
        alert('O campo Descrição deve ser preenchido.');
        descricao.focus();
    }
    else {
        doRequest("/server.aspx?act=erro&titulo=" + titulo + "&url=" + encodeURIComponent(window.location) + f,resposta_erro);
    }
}

function resposta_erro(f) {
    document.getElementById("erro_nome").value = "";
    document.getElementById("erro_email").value = "";
    document.getElementById("erro_descricao").value = "";
    alert(f);
}

function limita(input,n) {
    if (input.value.length > n)
        input.value = input.value.substr(0,n);
}