window.addEvent('siteready', function() {
	s.startAccount( $(document) );
	s.accountBlock( $(document) );
	
	document.addEvent('updateblock', function(obj) {
		s.startAccount( obj );
		s.accountBlock( obj );
	} );
} );


siteEngine.prototype.startAccount = function( obj )
{
	var thisObj = this;
	
	if ($('accept'))
	{
		var accept = $('accept');
		thisObj.controlAccept( accept );
		accept.addEvent('click', function(obj) {
			thisObj.controlAccept( obj );
		}.pass(accept, thisObj) );
	}
}

siteEngine.prototype.accountBlock = function( obj )
{
	var errors = obj.getElements('.error');
	for (var i=0; i<errors.length; i++)
	{
		this.putError( errors[i] );
 	}
}

siteEngine.prototype.controlAccept = function( obj )
{
	if (obj.checked)
	{
		$('save-profile').disabled = false;
		$('save-profile').removeClass('disabled');
	}
	else
	{
		$('save-profile').disabled = true;
		$('save-profile').addClass('disabled');
	}
}

siteEngine.prototype.putError = function( obj )
{
	var thisObj = this;
	
	if (!obj.errorPopup)
	{
		obj.errorPopup = new Element('div').addClass('error-msg').inject( document.body );
		obj.errorPopup.setStyles( {'position': 'absolute', 'z-index': 999999} );
		obj.errorPopup.fx = new Fx.Tween(obj.errorPopup, { 'property': 'opacity', 'link': 'cancel'} ).set(0);	
	}
	
	obj.addEvent('focus', function(event) {
		new Event(event).stop();
		var pos = obj.getCoordinates();
		this.errorPopup.setStyles( {'left':pos.left+pos.width+10, 'top':pos.top} );
		this.errorPopup.set('html', '<span>'+this.title+'</span>');
		this.errorPopup.fx.start(0, .9);
	});
	obj.addEvent('blur', function(event) {
		new Event(event).stop();
		this.errorPopup.fx.start(.9, 0);
	});
}
