function toggleDiv(divobj) {
	if ($(divobj).style.display == "none" || $(divobj).style.display == "") {
		$(divobj).style.display = "inline";
	} else {
		$(divobj).style.display = "none";
	}
}

function createSortable () {
	sections = ['col_1','col_2','col_3','col_4'];

	Sortable.create("col_1", {tag:'div', handle: 'move', overlap: 'vertical', constraint: false, only: 'box', dropOnEmpty: true, containment: sections, onUpdate:function(){
	var options = {method: 'post', parameters: Sortable.serialize('col_1')};
	new Ajax.Request('/save/', options);
}});

	Sortable.create("col_2", {tag:'div', handle: 'move', overlap: 'vertical', constraint: false, only: 'box', dropOnEmpty: true, containment: sections, onUpdate:function(){
	var options = {method: 'post', parameters: Sortable.serialize('col_2')};
	new Ajax.Request('/save/', options);
}});

	Sortable.create("col_3", {tag:'div', handle: 'move', overlap: 'vertical', constraint: false, only: 'box', dropOnEmpty: true, containment: sections, onUpdate:function(){
	var options = {method: 'post', parameters: Sortable.serialize('col_3')};
	new Ajax.Request('/save/', options);
}});

	Sortable.create("col_4", {tag:'div', handle: 'move', overlap: 'vertical', constraint: false, only: 'box', dropOnEmpty: true, containment: sections, onUpdate:function(){
	var options = {method: 'post', parameters: Sortable.serialize('col_4')};
	new Ajax.Request('/save/', options);
}});

}

function addFeed() {
	var url = escape($F('url'));
	var note_id = $F('note_id');
	var tags = $F('tags');
	var verify = $F('verify');

	Lightbox.showBoxImage('/img/blank.gif');

	var options = {method: 'post', postBody: 'action=addfeed&url=' + url + '&note_id=' + note_id + '&tags=' + tags + '&verify=' + verify + '', asynchronous: false, onComplete:function(){new Ajax.Updater('feeds', '/content/feeds/', {onComplete:function(){createSortable(); Lightbox.hideBox();}});}};

	var myAjax = new Ajax.Request('/save/', options);

	var status = myAjax.transport.responseText;

	if (status == -1)
		alert("Verification failed!");

	$('addfeed').style.display='none';

}

function quickaddFeed(feed_id) {
	if (confirm('Are you sure you want to add this feed?')) {
		var options = {method: 'post', postBody: 'action=quickaddfeed&feed_id=' + feed_id + ''};
	
		var myAjax = new Ajax.Request('/save/', options);
		alert("Feed added!");
	}
}

function saveFeed() {
	var feed_id = $F('feed_id');
	var note_id = $F('note_id');

	var options = {method: 'post', postBody: 'action=savefeed&feed_id=' + feed_id + '&note_id=' + note_id + '', asynchronous: true, onComplete:function(){$('box_' + feed_id + '').style.background='url(/img/note' + note_id + '.png) repeat-y left bottom';}};

	new Ajax.Updater('boxcontent_' + feed_id + '', '/content/printbox/' + feed_id + '/');

	var myAjax = new Ajax.Request('/save/', options);
}

function delBox(feed_id) {
	if (confirm('Are you sure you want to delete this feed?')) {
		var box = "box_" + feed_id;
		var options = {method: 'post', postBody: 'action=delbox&feed_id=' + feed_id + '', asynchronous: true};
		var myAjax = new Ajax.Request('/save/', options);

		Effect.Fade(box);
	}
}

function checkit(form) {
	var name = escape($F('regusername'));

	var options = {method: 'post', postBody: 'action=checkname&name=' + name +'', asynchronous: false};
	var myAjax = new Ajax.Request('/save/', options);

	var status = myAjax.transport.responseText;

	if (status>0) {
		$('checkreturn').innerHTML = '<span class="deny">Sorry that Username is already taken.</span><br>';
	} else {
		$('checkreturn').innerHTML = '<span class="accept">Congratulations! You can use that Username.</span><br>';
	}
	return false;  
}

function enableButton(button, target) {
	var string = target.value; 
	if (string.length > 2) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}
