var doingAjax = false;
function selectChild(select){
    $(select).parent().submit();
}

function setLoading(el){
    $(el).html('<img class="ajaxLoader" src="'+base_url+'img/loader.gif" alt=""/>');
}

function clearLoading(el){
    $(el).html('');
}

function removeChildForm(el){
    if(childrenIterator>1){
	$("#"+el).remove();
	childrenIterator--;
    }else{
	alert('You have to create at least 1 child.');
    }
}

function addChildForm(childFormUrl){
    if(childrenIterator<10){
	if(doingAjax)
	    return;
	doingAjax = true;
	setLoading('#childLoading');
	$.ajax(
	    {
		//async:false,
		data: {
		    iterator: childrenIterator
		},
		type: 'post',
		url: childFormUrl,
		success: function(data){
		    clearLoading('#childLoading');
		    $('#childrenForm').append(data);
		    childrenIterator++;
		    doingAjax = false;
		}
	    }
	);
    }else{
	alert('You cannot add more than 10 children');
    }
}

jQuery.fn.removeScrollBar = function(){
	var totalHeight = 0;
	this.find('div').each(function(){
		totalHeight += $(this).height();
	});
	if(totalHeight < this.height()){
		this.css('overflow-y', 'hidden');
	}
};
