function dump(obj, is_print, ident) {	
	if(!ident) ident = '';
	if(!is_print) is_print = 1;
	var output = '';
	var tmp = '';
    for (var item in obj) {
		if (typeof item == "object") {
			dump(item, is_print, '    ');
		}
		tmp = ident + item + ' = ' + obj[item] + '\n';
		if (is_print) {
			alert(tmp);
		}
		output += tmp;
    }
	
    return output;
}

function comboOptionInsertJson(url, params, element, msg_ok, msg_not) {
	comboOptionRemoveAll(element);
	comboOptionInsert(element, '', 'carregando...');
	$.getJSON(url, params, function(data){
		comboOptionRemoveAll(element);
		comboOptionInsertData(element, data, msg_ok, msg_not);
	});
}

function comboOptionInsertData(element, data, msg_ok, msg_not) {
	comboOptionRemoveAll(element);
	if (data.length > 0) {
		if (msg_ok != '') {
			comboOptionInsert(element, '', msg_ok);
		}
		for (var i=0; i<data.length; i++) {
			comboOptionInsert(element, data[i].key, data[i].val);
		}
	}
	else {
		comboOptionInsert(element, '', msg_not);
	}
}

function comboOptionInsert(element, value, text) {
	var elOptNew = document.createElement('option');
	elOptNew.text = text;
	elOptNew.value = value;
	
	try {
		element.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
	catch(ex) {
		element.add(elOptNew); // IE only
	}
}

function comboOptionRemoveAll(element) {
	for (var i = element.length - 1; i>=0; i--) {
		element.remove(i);
	}
}
