function confirm(message, callback) {
	$('#confirm').modal({
		close:false,
		position: ["20%",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			dialog.data.find('.message').append(message);

			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}


if(!Array.indexOf){
	    Array.prototype.indexOf = function(obj){
	        for(var i=0; i<this.length; i++){
	            if(this[i]==obj){
	                return i;
	            }
	        }
	        return -1;
	    };
	}

$.fn.ajaxLoading = function() {
    $(this).html("<div style='width:100%; text-align:center'>Loading...</div>");
    return this;
};

$.fn.ajaxUpdate = function(action, method, data, cache) {
    var self = this;
    $(self).ajaxLoading();
    if (!method) method = "get";
    if (!data) data = {};
    
    $.ajax({
        url: action,
        type: method,
        dataType: "html",
        data: data,
        cache: cache,
        success: function(result) {
            $(self).html(result);
            $('a[title]',$(self)).qtip({ style: { name: 'dark', tip: true } });
        }
    });
    
    return this;
};


$(document).ready(function(){
	$(".answer_item").live("click", function(){
		var $this = $(this);
		$this.parent().removeClass("error");
	});
	$(".parent").live("click", function(){
		var $this = $(this);
		$this.parent().removeClass("error");
		var val = $this.attr("value");
		var id = $this.attr("name");
		if (val==1)
		  $this.siblings(".childs").ajaxUpdate("/questionnaire/childs/"+id);
		else
		  $this.siblings(".childs").empty();	
	});
	$('a[title]').qtip({ style: { name: 'dark', tip: true } });
});

