	function fAtribuiEvento(obj, evType, fn){
		if (obj.addEventListener) obj.addEventListener(evType, fn, true)
		if (obj.attachEvent) obj.attachEvent("on"+evType, fn)
	}
	
	function fValidaComentario () {
		var erro = false
		var msg = ''
		if(document.getElementById('nome').value.length < 2) {
			erro = true
			msg += "\n- O campo 'nome' deve ser preenchido."
		}
		if(document.getElementById('email').value.length < 2) {
			erro = true
			msg += "\n- O campo 'email' deve ser preenchido."
		}
		if(document.getElementById('comentario').value.length < 2) {
			erro = true
			msg += "\n- O campo 'comentario' deve ser preenchido."
		}
		if (erro) {
			alert(msg) ;
			return false ;
		 }else{
		 	return true ;
		 }
	}
		
	function fMostrarFormComentar () {
		if(obj = document.getElementById('comente')){
			obj.style.visibility = "visible"	
			Effect.SlideDown('comente')
			Effect.Fade('bt_adicionar_um_comentario')
		}
	}
		
	function fFechaConvite () {
		if (navigator.userAgent.indexOf('MSIE') != -1) {
			c = document.getElementsByTagName('div')
			for (i=0 ; i < c.length ; i++) {
				if (c[i].id == 'convite') c[i].style.display = 'none'
			}
		} else {
			convite = document.getElementById('convite')
			tagBody = document.getElementsByTagName('body')
			tagBody[0].removeChild(convite)
		}
	}
	
	function fIni () {
		// presentinhos para os IEs (css)
		if (navigator.userAgent.indexOf('MSIE') != -1) {
			tagLinks = document.getElementsByTagName('link') ;
			for (var i = 0 ; i < tagLinks.length ; i++) {
				if(tagLinks[i].type=="text/css"){
					cssPath = tagLinks[i].href
					cssPath = cssPath.substring(0,cssPath.lastIndexOf('/')+1)
					i = 9999
				}
			}
			d = document.createElement("link")
			d.setAttribute('rel', 'stylesheet')
			d.setAttribute('type', 'text/css')
			if (navigator.userAgent.indexOf('MSIE 7') != -1) {
				d.setAttribute('href', cssPath+'ie7.css')
			}else{
				d.setAttribute('href', cssPath+'ie6.css')
			}
			d.setAttribute('media', 'screen')
			d.setAttribute('charset', 'utf-8')
			h = document.getElementsByTagName("head")
			h[0].appendChild(d)
		}
		// comentarios
		if(obj = document.getElementById('comente')) Effect.SlideUp('comente', { duration: 0 })
		if (obj = document.getElementById('bt_adicionar_um_comentario')) fAtribuiEvento(obj,"click",fMostrarFormComentar)
		// convite
		if (obj = document.getElementById("fecharConvite")) fAtribuiEvento(obj,"click",fFechaConvite)
		// auto completar
		ThisUrl = document.location+" "
		if (ThisUrl.substr(ThisUrl.length-2,1)=='/') ThisUrl = ThisUrl.substr(0,ThisUrl.length-2)
		IndexPhpPos = ThisUrl.lastIndexOf('index.php')
		if (IndexPhpPos > 0) {
			bars = ((ThisUrl.substring(IndexPhpPos+9).split('/')).length)-1
			AutoCompleteUrl = "catalogo/autocomplete"
			if (bars==3) bars = 2
			if (bars==0) {
				AutoCompleteUrl = "index.php/"+AutoCompleteUrl
			} else {
				for (var i = 0 ; i < bars ; i++) AutoCompleteUrl = "../"+AutoCompleteUrl 
			}
		} else {
			AutoCompleteUrl = "/index.php/catalogo/autocomplete"
		}
		new Ajax.Autocompleter("pesquise", "autocomplete_choices", AutoCompleteUrl, {});

	}
	
	fAtribuiEvento(window,"load", fIni)