/**
 * AutoSave {}
*/
var dtHours, dtMins, dtSecs;
AutoSave = {
	interval		: 10000,
	cookieName		: "PBlogsAutoSave",
	
	save 		: function( elements, form ) {
		// Already got it
		if(!this.fx) {
			this.fx				= new Fx.Style($('autosave-notice'), 'opacity', {
				 duration: 3000,
				'onComplete' : function() {
					if(this.now === 1 ) {
						this.toggle.delay(3000, this);	
					}
					this.element.setHTML(Locale["Προσωρινή αποθήκευση"]+": " + dtHours + ":"+dtMins+":"+dtSecs);
				}
			}).set(0);
		
		}
		
		if( blogASave)
			return;
	
		var data 	= "";
		form 		= $(form);
		
		if (typeof form != "undefined" && form != null)
		{
			elements.forEachBind( function() {
				eval( "var el = form."+this);
				var value = el.value;

				if(value === Locale["Τίτλος εγγραφής"]) {
					value = '';
				}	

				
				if( el.rte) {
					value = el.rte.getContent();
				}
				data += encodeURIComponent(value) + ",";
				}
			);
			// null data?
			if (data.replace( /,/g,'').trim() == '') {
				return; 
			}

			data = data.replace( /,$/g,'');
		
			// Bigger than max cookie size - word pasted prolly
			if( document.cookie.length + data.length  > 3900 ) 
				return false;		
			Node.show($("autosave-notice").parentNode.parentNode);
		
			var dt = new Date();
			
			// lame:(
			dtHours = dt.getHours();
			if (dtHours.toString().length < 2 ) dtHours = "0"+dtHours;
			
			dtMins = dt.getMinutes();
			if( dtMins.toString().length < 2 ) dtMins = "0"+dtMins;
			
			dtSecs = dt.getSeconds();
			if( dtSecs.toString().length < 2 ) dtSecs = "0" + dtSecs;
			
			$("autosave-notice").innerHTML = "Προσωρινή αποθήκευση: " + dtHours + ":"+dtMins+":"+dtSecs;
			this.fx.start(0, 1);
			Cookie.set( AutoSave.cookieName, data );

		}
	},

	restore: function( elements, form ) {
		form 		= $(form);
		
		var data 	= Cookie.get( AutoSave.cookieName);
		var values= data.split( /,/);
		if( !values.length )
			return;
			
		var cnt = 0;
		elements.forEachBind( function() {
			eval( "var el = form."+this);
			var value = decodeURIComponent(values[cnt]);
			if( el.rte)  {
				el.rte.setContent(value);
			}
			el.value = value;
			cnt++;
			}
		);						
		
		// Remove italic
		Cookie.set( AutoSave.cookieName,"", -1);
	},
	
	remove : function() {
		// Remove italic
		Cookie.set( AutoSave.cookieName,"", -1);		
			
	},

	removeNotice: function() {
		var node;
		node = $("autosave-options");
		new Fx.Slide(node).slideOut();

	}
}
