// Esta função "chama" todas as funções usadas em um documento.
function init() {
	odd('ul'); odd('ol');
	altRowColor();
	getLast('ul');
	createExternalLinks();
}
addEvent(window, "load", init);
// --------------------



// Função responsável pela mensagem de dica nos campos dos formulários
function showHelp(objDica, strMsg){	objDica.innerText = strMsg; }



// Função Adicionar aos Favoritos para o IE
function AdicionarFavoritos(){
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		window.external.AddFavorite(document.location,"ADS Imóveis");
	}
}

// Função Adicionar aos favoritos para os browsers
function CreateBookmarkLink() {
	title = "ADS Imóveis"; 
	url = "http://www.adsimoveis.com.br";

	if (window.sidebar) { window.sidebar.addPanel(title, url,""); } // Firefox

	else if(window.opera && window.print) { return true; } // Opera
}
// --------------------



// Função para carregar e limitar o tamanho do text área, e passar o tamanho do mesmo para um input text, caso haja.
// No input adicione o comando: onkeyup='LimTextArea(this, valor maximo(ex.: 100), objeto que receberá o lenght do textarea)'
function LimTextArea(obj, Len, objLen){
	if(obj.value.length > Len){
		obj.value = obj.value.substring(0, Len);
	}
	if(objLen!=undefined){ 
	objLen.value = obj.value.length;
	}
}
// --------------------



// Adiciona a função (fn) ao evento (evType) do objeto (obj)
function addEvent(obj, evType, fn){
   if (obj.addEventListener){
	  obj.addEventListener(evType, fn, true)}
   if (obj.attachEvent){
	  obj.attachEvent("on"+evType, fn)}
}
// --------------------



// Extensão do getElementById(id), permitindo o uso de classes
// Autor: Náiron - www.elmicox.com
function DOMgetElementsByClassName($node,$className){
    var $node, $atual, $className, $retorno = new Array(), $novos = new Array();
    $retorno = new Array();
    for (var $i=0;$i<$node.childNodes.length;$i++){
       $atual = $node.childNodes[$i];
       if($atual.nodeType==1){// 1 = XML_ELEMENT_NODE
          $classeAtual = $atual.className;
          if(new RegExp("\\b"+$className+"\\b").test($classeAtual)){
             $retorno[$retorno.length] = $atual;
          }
          if($atual.childNodes.length>0){
             $novos = DOMgetElementsByClassName($atual,$className);
             if($novos.length>0){
                $retorno = $retorno.concat($novos);
             }
          }
       }
    }
    return $retorno;
}
// --------------------



// Função pra alternar a cor dos itens de listas, adicionando a classe 'odd' aos itens pares
function odd(list_type) {
	var list = document.getElementsByTagName(list_type);
	
	for(i=0; i<list.length; i++){
		var li = list[i].getElementsByTagName('li');
	
		for (var j=0; j<li.length; j++){
			if (j % 2 == 0) { li[j].className += ' odd'; }
		}
	}
}
// --------------------



// Adiciona a classe "ultimo" ao ultimo elemento das listas
function getLast(list_type) {
	var list = document.getElementsByTagName(list_type);
	
	for(i=0; i<list.length; i++){
		var li = list[i].getElementsByTagName('li');
	
		var j = li.length - 1;
		li[j].className += ' ultimo';
	}
}
// --------------------



// Alternar as cores de TRs
// Author: Cadu de Castro Alves - http://www.cadudecastroalves.com 
function altRowColor() {
  var objTables = document.getElementsByTagName('tbody');
  var tableQty = objTables.length;
  for(i = 0; i < tableQty; i++) {
    var rowQty = objTables[i].rows.length;
    for(j = 0; j < rowQty; j++) {
      if(j % 2 == 0) {
        objTables[i].rows[j].className += ' odd';
      }
    }
  }
}
// --------------------



// Procura por links com rel="external" e faz com que eles abram em uma nova janela
// Autor: Henrique C. Pereira - http://www.revolucao.etc.br
function createExternalLinks() {
    if(document.getElementsByTagName) {
        var anchors = document.getElementsByTagName('a');
        for(var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if(anchor.getAttribute("href") && anchor.getAttribute('rel')=='external') {
                anchor.target = '_blank';
                var title = anchor.title + ' (Este link abre uma nova janela)';
                anchor.title = title;
            }
        }
    }
}
// --------------------

$(function(){
	$("#anuncios button").click(function(){
		$("#anuncios").hide();
		$("#wrapper").css({'width':'772px', 'margin':'0 auto'})
	})
})
