function loadChild(myId,childId,routine,dataToSend,callback,carregando,extraFirstOptionDiv){
	var me = gebi(myId);
	
	if(!carregando){
		carregando = 'Carregando...';
	}
	if(!extraFirstOptionDiv){
		extraFirstOptionDiv = '<span class="sbaixo"></span>';
	}
	
	//if(me.value != ''){
		var firstOption = gebi(childId).options[0];
		var firstOptionDiv = gebi(childId+'_div');
		var firstTxt = '';
		if(firstOption){
			firstTxt = firstOption.text;
			firstOption.text = carregando;
			if(firstOptionDiv)
				firstOptionDiv.innerHTML = carregando;
		}
		$.ajax({
			url: routine,
			dataType: 'json',
			data: dataToSend,
			success: function(data){
				var ops = '';
				if(firstOption){
					ops += '<option value="">'+firstTxt+'</opiton>';
					if(firstOptionDiv)
						firstOptionDiv.innerHTML = firstTxt+extraFirstOptionDiv;
				}
				for(var x=0;x<data.length;x++){
					var aux = '';
					if(data.length == 1){
						aux = 'selected="selected"';
					}
					ops += '<option title="'+data[x].text+'" alt="'+data[x].text+'" '+aux+' value="'+data[x].value+'">'+data[x].text+'</opiton>';
				}
				$('#'+childId).html(ops);
				if(callback){
					callback();
				}
			}
		});
	//}
}
$(document).ready(function(){
	$('input,textarea').each(function(e){
		var input = this;//input em questão
		$(this).focus(function(){
			if(this.value === this.defaultValue){
				this.value = '';
			}
		});
		$(this).blur(function(){
			if(this.value == ''){
				this.value = this.defaultValue;
			}
		});
	});
	$('#encontresuperficie_CMB0').change(function(){
		var that = this;
		if(that.value == ''){
			loadChild('encontretipo_CMB0','encontresuperficie_CMB0','routines.php?action=loadLinhas',{id_tipo:''});
		}
		loadChild('encontresuperficie_CMB0','encontretipo_CMB0','routines.php?action=loadTipos',{id_linha:this.value});
		loadChild('encontretipo_CMB0','Produtos_CMB0','routines.php?action=loadProdutos',{id_tipo:this.value,id_linha:gebi('encontresuperficie_CMB0').value});
	});
	$('#encontretipo_CMB0').change(function(){
		var that = this;
		//if(that.value != ''){
		if($('#encontresuperficie_CMB0').val() == ''){	
			loadChild('encontretipo_CMB0','encontresuperficie_CMB0','routines.php?action=loadLinhas',{id_tipo:this.value});
		}
			loadChild('encontretipo_CMB0','Produtos_CMB0','routines.php?action=loadProdutos',{id_tipo:this.value,id_linha:$('#encontresuperficie_CMB0').val()});
		//}
	});
	$('#Produtos_CMB0').change(function(){
		f.send('frmproduto');
	});
});
