function $(id){
	var xxxy = document.getElementById(id);
	if(!xxxy){
		alert("Falha! Elemento '"+id+"' não encontrado. A página pode não ser exibida corretamente.");
		return false;
	}
	return xxxy;
}
function toggleDiv(id, forceShow, inline){
	var xxxy = document.getElementById(id);
	if(!forceShow) forceShow = 0;
	if(!inline)    inline    = 0;
	if(forceShow == 1)      // Força exibir
		xxxy.style.display = (inline?'inline':'block');
	else if(forceShow == 2) // Força esconder
		xxxy.style.display = 'none';
	else                    // Alterna
		xxxy.style.display = (xxxy.style.display == 'none')?(inline?'inline':'block'):'none';
}

function toggleOptBox(){
	var lastOpt;
}
toggleOptBox.toggle = function(id, forceShow){
	if(toggleOptBox.lastOpt != id){
		if(toggleOptBox.lastOpt)
			toggleDiv(toggleOptBox.lastOpt, 2);
		toggleOptBox.lastOpt = id;
		
	}
	if(!forceShow)
		forceShow = 0;
	toggleDiv(id, forceShow);
}


function selectObj(){}
selectObj.clearAll = function(obj, defaultValue){
	obj.options.length = 0;
	if(defaultValue)
		selectObj.insert(obj, '', defaultValue);
}
selectObj.insert   = function(obj, value, text){
	var elOptNew = document.createElement('option');
	elOptNew.value = value;
	elOptNew.text  = text;
 	try{
		obj.add(elOptNew, null);
	}
	catch(e){
		obj.add(elOptNew);
	}
}
selectObj.insertList = function(obj, list){
	for(var i = 0; i < list.length; i++){
		(typeof list[i] == "string")?
			selectObj.insert(obj, list[i], list[i]):
			selectObj.insert(obj, list[i][0], list[i][1]);
	}
}
selectObj.select = function(obj, value){
	for(var i = 0; i < obj.options.length; i++){
		if(obj.options[i].value == value){
			obj.selectedIndex = i;
			continue;
		}
	}
}

autoRefreshIfrList = [];
function autoRefreshIfr(ifr){
	autoRefreshIfrList[autoRefreshIfrList.length] = ifr;
	autoRefreshIfrHit();
}
function autoRefreshIfrHit(){
	if(!autoRefreshIfrList.length)
		return;
	
	for(var i in autoRefreshIfrList)
		refreshIfrSize(autoRefreshIfrList[i]);
	
	setTimeout(autoRefreshIfrHit, 500);
}
function refreshIfrSize(ifr){
	ifr = $(ifr);
	
	ifr.height = 50;
	var the_height = ifr.contentWindow.document.body.scrollHeight;
	
	if(the_height < 50){
		the_height = 50;
	}
	ifr.height = the_height;
}


