var CommentForm = new Class({
    Implements:Options,
    options: 
    {
    },		
    initialize: function(options)
    {	    
		this.setOptions(options);
        this.commentform = document.forms['commentform'];
		if(!this.commentform)
		{
			this.commentform = document.commentform;	
		}   
		if(this.commentform)
		{	    
			if(this.commentform.author)
			{				
				this.author = this.commentform.author;		    				
				this.email = this.commentform.email;
				this.url = this.commentform.url;
				this.comment = this.commentform.comment;
				this.remember = this.commentform.remember;		
			}
			this.readCookies();
			this.validator = new Validator({validators:'.commentform_validator'})	    
		}
    },
    validate:function()
    {
	if(this.validator.isValid(this.commentform))
	{
	    this.writeCookies();           
	    return true; 
	}
	return false;  
    },
    writeCookies:function()
    {
		if(this.commentform.author)
		{
			if(this.remember.checked)
			{
				Cookie.write('Spotlife.CommentForm.Remember','1',{duration:100000,path:'/'}); 
				Cookie.write('Spotlife.CommentForm.Author',this.author.value,{duration:100000,path:'/'});  
				Cookie.write('Spotlife.CommentForm.Email',this.email.value,{duration:100000,path:'/'});
				Cookie.write('Spotlife.CommentForm.Url',this.url.value,{duration:100000,path:'/'});        
			}
			else
			{
				Cookie.dispose('Spotlife.CommentForm.Remember');
				Cookie.dispose('Spotlife.CommentForm.Author');
				Cookie.dispose('Spotlife.CommentForm.Email');
				Cookie.dispose('Spotlife.CommentForm.Url');
			}
		}
    },
    readCookies:function()
    {
		if(this.commentform.author)
		{
			var remember = Cookie.read('Spotlife.CommentForm.Remember'); 
			var author = Cookie.read('Spotlife.CommentForm.Author');  
			var email = Cookie.read('Spotlife.CommentForm.Email');
			var url = Cookie.read('Spotlife.CommentForm.Url');
			this.remember.checked = (remember) ? true : false;
			this.author.value = (author) ? author : '';
			this.email.value = (email) ? email : '';
			this.url.value = (url) ? url : '';
		}
    }
});