function updateCoords(c) {
	$('#x').val(c.x);
	$('#y').val(c.y);
	$('#w').val(c.w);
	$('#h').val(c.h);
};

function checkCoords() 
{ 
  if ($('#x').val() != '') return true; 
  alert('Maak eerst een selectie.'); 
  return false; 
}; 

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

function createTableSortable(table, action) {
	$(table).sortable({ 
		items: 'tr', 
		placeholder: 'ui-state-highlight', 
		axis: 'y', 
		handle: '.handle',
		items: 'tr:not(.head)',
		helper: function(e, tr) {
			var $originals = tr.children();
			var $helper = tr.clone();
			$helper.children().each(function(index) {
				$(this).width($originals.eq(index).width())
			});
			return $helper;
		},
		update: function(e, ui){
            $.ajax({
                type: "POST",
                url: webroot+action,
                data: "itemId=&newOrder="+$(table).sortable('toArray'),
                error: function(msg){
                    $("#JQresult").html(msg);
                },
                success: function(msg){
                    $("#JQresult").html(msg);
                }
            });
		}
	});
}

function createSortable(id, itemsClass, handler, action, direction){
	$(id).sortable({ 
        items: itemsClass,
        delay: 10,
        distance: 0,
        axis: direction,
        opacity: 0.5,
        placeholder: 'ui-placeholder',
        helper: function(e, tr) {
			var $originals = tr.children();
			var $helper = tr.clone();
			$helper.children().each(function(index) {
				$(this).width($originals.eq(index).width())
			});
			return $helper;
		},
        handle: handler,
		update: function(e, ui){
            $.ajax({
                type: "POST",
                url: webroot+action,
                data: "itemId=&newOrder="+$(id).sortable('toArray'),
                error: function(msg){
                    $("#JQresult").html(msg);
                },
                success: function(msg){
                    $("#JQresult").html(msg);
                }
            });
		}
    });
}


function loadFrontEditor(id) {
	$(id).htmlarea({
        // Override/Specify the Toolbar buttons to show
        toolbar: [
            ["html", "bold", "italic", "underline", "orderedlist", "unorderedlist", "h3"]
        ],
 		width:900,
 		height:100,
        css: webroot+"css/jHtmlArea.Editor.css"
    });
}
