// ***************************************************************
// FUNÇÕES AJAX
// ***************************************************************
var aguarde 	= "<img src='" + gblNivel + "img/wait.gif' width='16' height='16' alt='Aguarde...' />";
var ajax_span	= "";

function doComboCategorias(tipo,nome,pai){
	var objDiv	= document.getElementById(nome+'_span');
	if(pai!=0){
		var elMethod	= "get";
		var varArquivo	= gblNivel + "cf_ajax.asp?acao=COMBO_CATEGORIAS&nome=" + nome + "&id=" + tipo + "&id2=" + pai + "";
		objDiv.innerHTML = aguarde;
		var oAjax = new Ajax(objDiv, elMethod, varArquivo);
	}
	else{
		objDiv.innerHTML = "";
	}
}
function doComboCategoriasBusca(tipo,nome){
	var objDiv	= document.getElementById(nome+'_span');
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=COMBO_CATEGORIAS&nome=" + nome + "&id=" + tipo + "&id2=0";
	objDiv.innerHTML = aguarde;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);
}

function doPromocoesLoja(obj, wait){
	if(aux_loop==10){clearInterval(tempo);return false;}
	aux_loop++;
	var objDiv	= document.getElementById(obj);
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=PROMOCAO_LOJA";
	objDiv.innerHTML = wait;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);	
}
function doHit(codigo, tipo){
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=HIT&id=" + codigo + "&id2=" + tipo;
	var oAjax = new Ajax(null, elMethod, varArquivo);
}
function doVitrineLoja(obj, wait){
	if(aux_loop==10){clearInterval(tempo);return false;}
	aux_loop++;
	var objDiv	= document.getElementById(obj);
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=VITRINE_LOJA";
	objDiv.innerHTML = wait;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);	
}
function doVotaEnquete(i){
	var wait	= aguarde;
	var objDiv	= document.getElementById("aenquete");
	var rads	= document.getElementsByName("enquete_opcao");
	var o		= "";
	for (var x=0;x<rads.length;x++){
		if (rads[x].checked) o = rads[x].value;
	}

	if (o!=""){
		var elMethod	= "get";
		var varArquivo	= gblNivel + "cf_ajax.asp?acao=VOTAR_ENQUETE&id=" + i + "&id2=" + o + "";
		objDiv.innerHTML = wait;
		var oAjax = new Ajax(objDiv, elMethod, varArquivo);	
	}
	else{
		alert("Escolha uma opção e clique em 'Votar'.");
	}
}
function doProximaEnquete(){
	var wait	= aguarde;
	var objDiv	= document.getElementById("aenquete");
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=PROXIMA_ENQUETE";
	objDiv.innerHTML = wait;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);	
}

function doComboCategorias2(tipo,nome){
	var objDiv	= document.getElementById('categoria_codigo_pai_span');
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=COMBO_CATEGORIAS&nome=" + nome + "&id=" + tipo + "";
	objDiv.innerHTML = aguarde;
	var oAjax = new Ajax(objDiv, elMethod, varArquivo);
}
// ***************************************************************

function rsize(){
	var s=0;var l=document.getElementById("left");var r=document.getElementById("right");var c=document.getElementById("content");
	if(l.offsetHeight>s)s=l.offsetHeight;if(r.offsetHeight>s)s=r.offsetHeight;if(c.offsetHeight>s)s=c.offsetHeight;
	l.style.height=s+"px";r.style.height=s+"px";c.style.height=s+"px";
}
function changePagina(e,frm){if(document.all) var tecla=event.keyCode;else if(document.layers) var tecla=e.which;frm.submit();}
function setLocation(u){window.location.href=u;}
function Confirma(txt,u){if(confirm(txt)){setLocation(u);return true;}else{return false;}}
function moveListBoxItens(mnu_o, mnu_d){
    var arrmnu_o=new Array();
    var arrmnu_d=new Array();
    var arrLookup=new Array();
    var i;
    for (i=0;i<mnu_d.options.length;i++){arrLookup[mnu_d.options[i].text]=mnu_d.options[i].value;arrmnu_d[i]=mnu_d.options[i].text;}
    var fLength=0;
    var tLength=arrmnu_d.length;
    for(i=0;i< mnu_o.options.length;i++){
        arrLookup[mnu_o.options[i].text]=mnu_o.options[i].value;
        if (mnu_o.options[i].selected && mnu_o.options[i].value!=""){arrmnu_d[tLength]=mnu_o.options[i].text;tLength++;}
        else{arrmnu_o[fLength]=mnu_o.options[i].text;fLength++;}
    }
    arrmnu_o.sort();
    arrmnu_d.sort();
    mnu_o.length=0;
    mnu_d.length = 0;
    var c;
    for(c=0;c<arrmnu_o.length;c++){
        var no=new Option();
        no.value=arrLookup[arrmnu_o[c]];
        no.text=arrmnu_o[c];
        mnu_o[c]=no;
    }
    for(c=0;c<arrmnu_d.length;c++){
        var no=new Option();
        no.value=arrLookup[arrmnu_d[c]];
        no.text=arrmnu_d[c];
        mnu_d[c]=no;
   }
}
function selectItens(obj){for(var c=0;c<obj.options.length;c++){obj.options[c].selected=true;}}

function replaceAll(str,from,to){
    var idx=str.indexOf(from);
    while (idx>-1){
		str=str.replace(from,to); 
        idx=str.indexOf(from);
    }
    return str;
}
function AbreJanela(Url, Nome, Opcoes){
	var Janela = window.open(Url,Nome,Opcoes);
	return Janela;
}
function showFormComentario(tipo,id){
	AbreJanela(siteUrl + 'comentario.asp?tipo=' + tipo + '&id=' + id + '', 'popComent', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=500,height=290")
}
function showVideoAula(){
	AbreJanela('about:blank', 'popVideo', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=800,height=600")
}

function closeFormComentario(){self.close();}
function getPosicaoElemento(elemID){
    var offsetTrail = elemID;
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}
var ieBlink = (document.all)?true:false;
function doBlink(){
	if(ieBlink){
		obj = document.getElementsByTagName('BLINK');
		for(i=0;i<obj.length;i++){
			tag=obj[i];
			tag.style.visibility=(tag.style.visibility=='hidden')?'visible':'hidden';
		}
	}
}

function closeAdPub(){window.setTimeout('doClose()',200);}
function doClose(){document.getElementById('adpub').innerHTML = "";document.getElementById('adpub').style.display='none';document.cookie='CF_FeAds=1';}
function addFav(){
    var url      = "http://www.codigofonte.com.br";
    var title    = "Código Fonte - O Melhor Conteúdo para Programadores";
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if(window.opera && window.print){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if(document.all){window.external.AddFavorite(url, title);}
}
function installSearchProvider() {
 if (window.external && ("AddSearchProvider" in window.external)) {
 
   var elMethod	= "get";
   var varArquivo = gblNivel + "cf_ajax.asp?acao=SEARCH_PROVIDER_CLICK";
   var oAjax = new Ajax(null, elMethod, varArquivo);
 
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.codigofonte.com.br/codigofonte_opensearch.xml");
 } else {
   alert("Seu navegador não possui\nsuporte a nenhum 'Search Engine'.\n\nPara instalar esse recurso você\nprecisa do IE 7.x ou Firefox 2.x");
 }
}

function doNadaAlexa(r){return}
function alexaToolbar(){
	var elMethod	= "get";
	var varArquivo	= gblNivel + "cf_ajax.asp?acao=ALEXA";
	var oAjax = new Ajax(null, elMethod, varArquivo);
	document.location.href = "http://info.alexa.com/site/download";
}

/*********************************************************************
 FUNÇÕES CÓDIGOFONTE
*********************************************************************/
function modoEdicao(){
	document.getElementById("codigoFonte").style.display = "none";
	document.getElementById("oCodigo").style.display = "block";
	objCodigo = document.getElementById("oCodigo");
}
function codeCopy(){
	cop = document.getElementById("oCodigo").createTextRange();
	cop.execCommand("RemoveFormat");
	cop.execCommand("Copy");
	alert("Código copiado para a área de transferência.");
}
function fontMais(){
	var obj = document.getElementById("codigoFonte");
	if (obj.style.fontSize==""){obj.style.fontSize="12px"};
	if (obj.style.fontSize=="10px"){obj.style.fontSize = "12px";}
	else if (obj.style.fontSize=="12px"){obj.style.fontSize = "15px";}
	else if (obj.style.fontSize=="15px"){obj.style.fontSize = "17px";}
	else if (obj.style.fontSize=="17px"){obj.style.fontSize = "19px";}
	else if (obj.style.fontSize=="19px"){obj.style.fontSize = "21px";}
}
function fontMenos(){
	var obj = document.getElementById("codigoFonte");
	if (obj.style.fontSize==""){obj.style.fontSize="12px"};
	if (obj.style.fontSize=="21px"){obj.style.fontSize = "19px";}
	else if (obj.style.fontSize=="19px"){obj.style.fontSize = "17px";}
	else if (obj.style.fontSize=="17px"){obj.style.fontSize = "15px";}
	else if (obj.style.fontSize=="15px"){obj.style.fontSize = "12px";}
	else if (obj.style.fontSize=="12px"){obj.style.fontSize = "10px";}
}
function heightMais(){
	var obj = document.getElementById("codigoFonte");
	if (obj.style.height==""){obj.style.height="450px";}
	else if (obj.style.height=="390px"){obj.style.height = "450px";}
	else if (obj.style.height=="450px"){obj.style.height = "500px";}
	else if (obj.style.height=="500px"){obj.style.height = "550px";}
	else if (obj.style.height=="550px"){obj.style.height = "600px";}
	else if (obj.style.height=="600px"){obj.style.height = "650px";}
	else if (obj.style.height=="650px"){obj.style.height = "700px";}
}
function heightMenos(){
	var obj = document.getElementById("codigoFonte");
	if (obj.style.height==""){obj.style.height="390px"}
	else if (obj.style.height=="700px"){obj.style.height = "650px";}
	else if (obj.style.height=="650px"){obj.style.height = "600px";}
	else if (obj.style.height=="600px"){obj.style.height = "550px";}
	else if (obj.style.height=="550px"){obj.style.height = "500px";}
	else if (obj.style.height=="500px"){obj.style.height = "450px";}
	else if (obj.style.height=="450px"){obj.style.height = "390px";}
}
function setLinha(){
	var o = document.getElementById("codigoFonte");
	var cf = o.innerHTML;
	cf = cf.replace("\n", "\n1");
	o.innerHTML = cf;
}