$(document).ready(function(){
	$('$[defaultvalue]').each(function() {
		myval=$(this).val();
		if(myval == '')
		{
			defaultvalue=$(this).attr('defaultvalue');
			$(this).val(defaultvalue);
		}
	});
	
	$('$[defaultvalue]').focus(function() {
		myval=$(this).val();
		defaultval=$(this).attr('defaultvalue');
		if(myval == defaultval) $(this).val('');
	});
	
	$('[required]').click(function() {
		$(this).removeClass('error');
	});
	
	$('$[defaultvalue]').blur(function() {
		myval=$(this).val();
		defaultval=$(this).attr('defaultvalue');
		if(myval == '') $(this).val(defaultval);
	});
	
	$('FORM').submit(function(){
		/*
		$(this).find('[defaultvalue]').each(function(){
			myval=$(this).val();
			defaultval=$(this).attr('defaultvalue');
			if(myval == defaultval) $(this).val('');
		});
		console.info('tried to go away');
		*/
		//validate form
		
		ok = true;
		//console.info('looking for mandatory');
		$(this).find('INPUT[required]').each(function() {
			defaultvalue=$(this).attr('defaultvalue');
			myval=$(this).val();
			if((defaultvalue == myval) || (myval == ''))
			{
				ok = false;
				$(this).addClass('error');
			}
//			console.info($(this).attr('name'));
		});
		//do the required checkbox red
		$(this).find('INPUT[type="checkbox"][required]').each(function() {
			ischecked=($(this).is(':checked') ? true : false);
			
//			console.info('VAlidating checkbox');
		});
		
		if(ok)
		{
			$(this).find('*').each(function() {
//				console.info('checking for ' + $(this).attr('name'));
				if($(this).val() == $(this).attr('defaultvalue'))
				{
//					console.info('removing value for ' + $(this).attr('name'));
					$(this).val('');
				}
			});
		}
//		console.info('done');
//		return false;
		return ok;
	});
});
