	window.onload = function() {		
		$('searcher').observe('submit', dosearch);
		
		if ($('dosave') != null)		$('dosave').observe('click', dosave);
		if ($('doedit') != null)		$('doedit').observe('click', doedit);
		if ($('doeditalt') != null)		$('doeditalt').observe('click', doedit);
		if ($('dopreview') != null)		$('dopreview').observe('click', dopreview);
		
		if ($('dosend') != null)  		$('dosend').observe('click', docontact);
		if ($('doreset') != null)  		$('doreset').observe('click', doreset);
		
		if ($('toswarning') != null)	$('toswarning').observe('click', readtos);
		
		// hints
		if ($('title')) {
			$('title').observe('focus', function () { $('title_hint').show(); });
			$('title').observe('blur', function () { $('title_hint').hide(); });
		}
		
		if ($('admin') && $('admin_hint')) {
			$('admin').observe('focus', function () { $('admin_hint').show(); });
			$('admin').observe('blur', function () { $('admin_hint').hide(); });
		}
		
		if ($('view') && $('view_hint')) {
			$('view').observe('focus', function () { $('view_hint').show(); });
			$('view').observe('blur', function () { $('view_hint').hide(); });
		}
		
		if ($('captcha')) {
			$('captcha').observe('focus', function () { $('captcha_hint').show(); });
			$('captcha').observe('blur', function () { $('captcha_hint').hide(); });
		}

                if ($('sources')) {
                        $('sources').observe('focus', function () { $('sources_hint').show(); });
                        $('sources').observe('blur', function () { $('sources_hint').hide(); });
                }
	}
	
	function dosearch() {
		return false;
	}
  
	function doedit() {
		$('poster').writeAttribute({ action: "/" });
		$('poster').submit();
	}
  
	function dopreview() {
		$('poster').writeAttribute({ action: "/preview" });
		$('poster').submit();
	}
  
	function dosave() {
		$('poster').writeAttribute({ action: "/save" });
		$('poster').submit();
	}
  
	function readtos() {
		if ($('toswarning').checked)	$('dosave').enable();
		else 				$('dosave').disable();
	}
  
	function docontact() {
		if ($F('name').blank()) {
			$('error').show();
			$('error').update('Your name is missing.');
			return false;
		}
		
		if ($F('email').blank()) {
			$('error').show();
			$('error').update('Your email is missing.');
			return false;
		}
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (!reg.test($F('email'))) {
			$('error').show();
			$('error').update('Your email address is invalid.');
			return false;
		}
		
		if ($F('comment').blank()) {
			$('error').show();
			$('error').update('Your message is blank.');
			return false;
		}
		
		$('poster').submit();
	}  
	
	function doreset() { 
		$('error').hide(); 
	}
	
