// JavaScript Document
var Redirect = {
	beforeSubmit: function(form){
		var e = '', inputObbligatori = {
			user: function(input){
				return ($F(input) == input.defaultValue);			
			},
			
			password: function(input){
				return ($F(input) == input.defaultValue);
			}
		};
		
		$A(form).each(function(input){
			if((input.type == 'text' || input.type == 'password') && Object.isFunction(inputObbligatori[input.id]) && inputObbligatori[input.id](input))
				e += (input.defaultValue || 'Password')  + ": campo non compilato correttamente\n";
		});
		
		if (e) {
			alert(e);
			return false;
		}
		
		return true;
	},
	
	defaultValue: function(input, classBlur, classFocus){
		Event.observe(input, 'focus', (function(){
			if (this.value == this.defaultValue) {
				this.value = '';
				if (classFocus) $(this).changeClassNames(classFocus, classBlur);
				if ($(this).hasClassName('password')) {
					this.style.display = 'none';
					if (Prototype.Browser.IE)
						$('password').size = '42';					
					$('password').style.display = '';
					$('password').focus();
					$('password').select();
				}
			}
		}).bindAsEventListener(input));
	
		Event.observe(input, 'blur', (function(){
			if (this.value.blank()) {
				this.value = this.defaultValue;
				if (classBlur) $(this).changeClassNames(classBlur, classFocus);
			}
		}).bindAsEventListener(input));
	},
	
	home: function(){
		window.location.href = 'http://www.ilruoloterapeutico.it/';
	},
	
	reset: function(){
		$A($$('input.outside[type="text"]', 'input.inside[type="text"]')).each(function(input){
			input = $(input);
			input.value = input.defaultValue;
			if (input.hasClassName('outside')) 
			 input.changeClassNames('inside','outside');
		});
	}
}

document.observe("dom:loaded", function(){
	$A($$('input.inside:not(.search):not(#password)')).each(function(input){
		Redirect.defaultValue(input, 'inside', 'outside');
	});
});

