/**
	Utilizado pelos filtros para alterara a imagem
*/
function filtrosAlteraImagem( id ) {
	document.getElementById(id).src = (document.getElementById(id).src.indexOf('btn_arrow_down.gif') != -1)? "images/btn/btn_arrow_up.gif" : "images/btn/btn_arrow_down.gif";
}

/**
	Converte um array para uma lista
*/
function arrayToList(array, separator) {
	// concatena os itens do array em uma string
	var lista = "";
	for(i = 0 ; i < array.length ; i ++)
		lista += array[i] + separator;
	// remove ultima virgula
	if(lista.charAt(lista.length - 1) == separator)
		lista = lista.substring(0, lista.length - 1);
	return lista;
}

/**
	Altera um objeto entre visivel e invisivel
*/
function toggleVisible(id) {
	var element = document.getElementById(id);
	if(element == null) alert("Element " + id + " not found in document!");
 	element.style.display = (element.style.display == "none")? "" : "none";
}

/**
	Set um objeto como visivel/invisivel
*/
function setVisible(idOrElement, visible) {
	if(isString(idOrElement)) {
		var element = document.getElementById(idOrElement);
	} else {
		var element = idOrElement;
	}
	if(element == null) alert("Element " + idOrElement + " not found in document!");
	element.style.display = visible ? '' : 'none';
}

function dumpBuffer(object, nivel) {
	if(!isObject(object)) {
		alert(object);
		return;
	}
	
	var buffer = "";
	for(var field in object) {
		if(isObject(field)) {
			buffer += dumpBuffer(field, nivel + "-");
		} else {
			buffer += nivel + field + ':' + object[field] + "\n";
		}
	}
	return buffer;
}

function dump(object) {
	alert(dumpBuffer(object, ""));
}

/**
	Retorna o value selecionado de um select pelo id ou retorna null
*/
function getSelectValue(id) {
	var select = getElementByIdOrName(id);
	if(select.selectedIndex == -1) return null;
	return select.options[select.selectedIndex].value;
}

function parserXML(xmlString) {
	 var myDocument; 
	if(document.implementation.createDocument){ 
	   // Mozilla, create a new DOMParser 
	   var parser = new DOMParser(); 
	   myDocument = parser.parseFromString(xmlString, "text/xml"); 
	 } else if (window.ActiveXObject){ 
	   // Internet Explorer, create a new XML document using ActiveX 
	   // and use loadXML as a DOM parser. 
	   myDocument = new ActiveXObject("Microsoft.XMLDOM") 
	   myDocument.async="false"; 
	   myDocument.loadXML(xmlString);   
	 } 
	 
	 return myDocument;
}

function getElementByIdOrName(idOrName) {
	var objeto = document.getElementById(idOrName);
	if(objeto == null) 
		objeto = document.getElementsByName(idOrName)[0];
		
	if(objeto == null)
		alert("Não foi possível encontrar o objeto " + idOrName + "!");
	
	return objeto;
}

/**
	Retorna um select de forma protegida contra bixeira do IE que se confude no getElementById com o name
*/
function getElement(id) {
	var objeto = document.getElementById(id);
	if(objeto.id != id) {
		// ie pegou outro campo, busca pelo nome e tenta encontrar o select
		var objetos = document.getElementsByName(id);
		for(var i = 0 ; i < objetos.length ; i ++ ) {
			if(objetos[i].id == id) {
				objeto = objetos[i];
				break;
			}
		}
	} 
	
	if(objeto == null) {
		alert("Não foi possível encontrar o objeto com id " + id + "!");
	}
	
	return objeto;
}

function Trim(str) {
	return str.replace(/^\s+|\s+$/, '');
}


function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) {
    return isObject(a) && a.constructor == Array;
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return a === null;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
} 

function over(e){
	e.className='item_over';
}
function out(e){
	e.className='';
}

