/* Anti Spam (c) Djamil Legato 2007
   ---
   This should block most of the spambots 
   whose grab the emails looking at the source.
*/

var Site = {
	mailto: {
		'pattern': '-secure_mail-',
		'user': 'info',
		'domain': 'diffusionescientificacreativa.it'
	},
	start: function() {
		var mail_fake = Site.rewrite('fake');
		var mail_orig = Site.rewrite('orig');
		var oldStyle = '';

		$$('.delete').each(function(obj) {
			obj.addEvent('click', function(e) {
				var confirm = window.confirm("L'operazione e' irreversibile.\nContinuare?");
				if (confirm) window.location = this.href;
				e.stop();
			});
		}),

		$$('.windowed').each(function(obj) {
			obj.addEvent('click', function(e) {
				e.stop();
				newwin = window.open(this.href, 'windowed', 'height=475,width=830');
				x = (screen.availWidth - newwin.getWidth()) / 2;
				y = (screen.availHeight - newwin.getHeight()) / 2;
				newwin.moveTo(x,y);
				if (window.focus) newwin.focus();
			});
		}),

		$$('.email').each(function(email) {
			email.set('html', mail_orig);
			email.addEvents({
				'mouseover': function() {
					email.setProperty('href', 'mailto:' + mail_orig);
				},
				'mouseout': function() {
					email.setProperty('href', '#');
				}
			});
		}),

		$$('.admin_table').getElements('tr').each(function(tr) {
			tr.addEvent({
				'mouseover': function() {
					oldStyle = tr.getStyle('background-color');
					tr.setStyle('background-color', '#f00');
				},
				'mouseout': function() {
					tr.setStyle('background-color', oldStyle);
					oldStyle = '';
				}
			});
		}),

		$$('#cancel').each(function(obj) {
			obj.addEvent('click', function(e) { 
				if (document.location.href.search(/eventi_edit/) != -1) window.location = "/admin/home";
				else window.location = document.location.href.replace(/\?.*$/,'');
				e.stop();
			});
		})

	},
	rewrite: function(mail) {
		switch (mail) {
			case 'fake':
				return Site.mailto['user'] + Site.mailto['pattern'] + Site.mailto['domain'];
				break;
			case 'orig': default:
				return Site.mailto['user'] + '@' + Site.mailto['domain'];
		}
		return false;
	}
}
window.addEvent('domready', Site.start);

