function redirecciona(query_string){
	window.location = "pagina.php?" + query_string;
}

function getDivAltura(nomeDiv){
	var div = document.getElementById(nomeDiv);
	var altura=0;
	if (div)
		altura = div.offsetHeight;
	return altura;
}

function ajustaAlturaErrosMsgs(){
	var alturaErros = getDivAltura("erros");
	var alturaMsgs = getDivAltura("msgs");
	var alturaConteudo = getDivAltura("conteudo");
	var divConteudo = document.getElementById("conteudo");
	var divErros = document.getElementById("erros");
	var conteudoMarginTop = document.getElementById("conteudo").style.marginTop;
	//conteudoMarginTop = 42;
	var alturaTotal = alturaErros + alturaMsgs + conteudoMarginTop;
	alert("alturaTotal: " + alturaTotal + " alturaErros: " + alturaErros + " alturaMsgs: " + alturaMsgs + " conteudoMarginTop: " + conteudoMarginTop);
	divErros.setAttribute("style", "margin-top:-" + alturaConteudo + "px");
	divConteudo.setAttribute("style", "margin-top:" + alturaTotal + "px");
	alert("conteudoMT: " + conteudoMarginTop);
}

function mostraErros(erros){
	var divErros = document.getElementById("erros");
	divErros.style.display = "block";
	divErros.innerHTML = erros;
}

function mostraMsgs(msgs){
	var divMsgs = document.getElementById("msgs");
	divMsgs.style.display = "block";
	divMsgs.innerHTML = msgs;
}

function getElementsByStyleClass (className) {
	var all = document.all ? document.all :	document.getElementsByTagName('*');
	var elements = new Array();
	for (var e = 0; e < all.length; e++)
		if (all[e].className == className)
			elements[elements.length] = all[e];
	return elements;
}

function getScrollXY() {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return [x, y];
}

function setScrollXY(x, y) {
    window.scrollTo(x, y);
}

function getFilenameExtension(name){
	var ext = name.substr(name.lastIndexOf('.'));
	var filename = name.substr(0, name.lastIndexOf('.'));
	
	return new Array(filename, ext);
}

function mudaSlides(obj, idx, idImages, evento){
	
	if (evento=='click')
		bannersAutomaticos = 0; //se mudaSlides foi chamada por click, poe a flag de transiçao automatica a 0
	
	if(idx == slidesActivos[idImages])
		return false;
	
	//id do <ul> que contem os botoezinhos que mudam o banner
	var idUL = $("botoesBannerCentro").id;
	
	//alert(idUL);
	
	var elementos = $(idImages).getElements('li');
	for (var i=0; i<elementos.length; i++)
		elementos[i].setStyle('display', 'none');
	
	//$(idImages).style.filter = "alpha(opacity=0)";
	//$(idImages).style.opacity = 0;
	
	//Effect.Appear($(idImages).getElements('li')[idx].id, { duration:1, from:0.0, to:1.0 });
	$(idImages).getElements('li')[idx].setStyle('display', 'block');
	
	//fadeIn(idImages,1);
	
	var imgs;

	imgs = $$('#' + idUL + ' li a');
	
	for (i=0; i<imgs.length; i++)
		imgs[i].getElement('img').src = 'images/genericos/item_inactivo.png';	
	
	$$('#'+idUL+' li a')[idx].getElement('img').src = 'images/genericos/item_activo.png';
		
	slidesActivos[idImages] = idx;
	
	return false;
}

//OBRIGADO IE7
function corrigeCaixaE(){
	//o IE7 por vezes (a cada 2 refreshs de pagina prai) considerava q 100% no height do caixa_e correspondia
	//à height do viewport, apesar do seu pai (.fora) ter position relative. corrige-se por JS indo-se buscar
	//a height que o .fora ficou a ocupar e dando-se explicitamente essa height ao caixa_e
	var foras = $$('.fora');
	var h;
	for (i=0; i<foras.length; i++){
		var h = foras[i].measure(function(){return this.getSize();}).y;
		//h = foras[i].getSize().y;
		foras[i].getElement(".caixa_e").setStyle("height", h);
		//alert(h);
	}
}


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;
}

function suportaFlash(){//return false;
	return DetectFlashVer(8, 0, 0);
}

function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(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};
}

