
	var TIPS = new Array("Do you forget to take out the trash?  <a href='/chores'>Choreminder won't!</a>","Can't seem to get it done?  Break it into smaller pieces!","Changed your AC filters lately?","Do you need an oil change?","What did I do <A href='/journal'>yesterday?</a>");

	function tip() {
		index = Math.floor(Math.random() * TIPS.length);
		document.getElementById('tip').innerHTML = TIPS[index];
	}

	function ruleTypeHandler() {
		var s = document.getElementById('scheduled');
		var e = document.getElementById('estimated');
		if (document.getElementById('type_s').checked) {
			s.style.display='block';
			e.style.display='none';
		} else {
			s.style.display='none';
			e.style.display='block';
		}
		return true;
	}

	function vote(poll,vote) {

		if (hasvoted == 0) {
		var command = apiurl + "/vote?poll=" + poll+ "&vote=" + vote;
		var ajax=new Ajax.Request(command,{method:'get',onSuccess: voted});
		hasvoted = 1;
		}
		return false;
	}



	function pushed(res) {

		if (res.responseText == "OK") {

		} else {

            $('message').innerHTML='TODO PUSHED FAILED';
			$('message').style.display='block';
		}

	}



	function newTodo() {
		var todo = Field.serialize('todo');
		if ($('todo').value == "What do you need to do?" || $('todo').value == "") {
			$('message').innerHTML = '<b>Huzzuh? You\'ve gotta type something before you add it to your list!</b>';
			$('message').style.display='block';
			return false;
		}
		$('message').style.display='none';
		var command = apiurl + "/add?" + todo + "&priority=" + priority;
		var ajax=new Ajax.Request(command,{method:'get',onSuccess: todoAdded});
		return false;
	}




	function complete(id,obj) {
		if (obj.checked) {
			$('todo'+id).className='completed';
				Effect.Fade('actions' + id);
			var command = apiurl + "/complete?id="+id;
			var ajax=new Ajax.Request(command,{method:'get',onSuccess: completed});
		} else {
			$('todo'+id).className='todo';
				Effect.Appear('actions' + id);

			var command = apiurl + "/uncomplete?id="+id;
			var ajax=new Ajax.Request(command,{method:'get',onSuccess: uncompleted});
		}


		return true;
	}

	function deletetodo(id) {
			var command = apiurl + "/delete?id="+id;
			var ajax=new Ajax.Request(command,{method:'get',onSuccess: deleted});
			Effect.Fade('todo'+id);
			return false;
	}	




	function push(id,postponed) {
		var nextpri = nextpriority;
		if (postponed != 0 && postponed % 5 == 0 && nextpri != 'today') {
			if (confirm('You have snoozed this item a lot!  Do you want to move it to your postponed bin, where it will no longer be part of the relentless march of progress?')) { 
				nextpri = 'later';
			}
		}
		var command = apiurl + "/push?id=" + id + "&priority="+nextpri;
		var ajax=new Ajax.Request(command,{method:'get',onSuccess: pushed});
		Effect.Fade('todo'+id);
		return false;
	}

	function todoAdded(res) {

		if (res.responseText !='FAIL') {
			var nid = res.responseText;
			var todo = $F('todo');
			$('todo').value='';
			var tdl = $('todo_list');
			var template = new Template('<div style="display: none;" class="todo" id="todo#{id}"><div class="actions"  id="actions#{id}"><a href="#" onClick="return deletetodo(#{id});"><img src="/img/delete.png" border="0" /></a>&nbsp; &nbsp;<a href="#" onClick="return push(#{id},0);"><img src="/img/snooze.png" border="0" /></a></div><span class="title"><input type="checkbox" id="check#{id}" onClick="return complete(#{id},this);">&nbsp;#{todo}</input></span></div>');
			var show = { id: nid, todo: todo };
			var newlist = template.evaluate(show) + tdl.innerHTML;
			tdl.update(newlist);
			Effect.Appear("todo" + nid);
			if ($('nothing_todo')) {
				$('nothing_todo').style.display='none';
			}
		} else {
			$('message').innerHTML = '<h3>Error!</h3>We could not add that todo to your list!';
			$('message').style.display='block';
		}
	}

	function deleted(res) {

	}
	function completed(res) {


	}

	function uncompleted(res) {

	}


	function voted(res) {
		$('popchart').update('<img src="/popchart.pl?' + res.responseText + '">');
	}
