/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * www.JacoZ.net - Tutti i diritti sono riservati. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Il codice contenuto in questa pagina non pu essere copiato od utilizzato da terzi. * * * * * * * * * * * * * *
 * Questo codice  stato scritto ed appartiene a www.JacoZ.net ad al suo legittimo proprietario. * * * * * * * * *
 * Sar possibile, previa richiesta ed approvazione dello staff, utilizzare parte del codice * * * * * * * * * * *
 * Per effettuare tale richiesta contattare l'amministrazione di www.JacoZ.net al seguente indirizzo * * * * * * *
 * di posta elettronica: info@staff.jacoz.net !! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Chiunque non rispetti le regole sopracitate sar perseguito a norma di legge. * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * www.JacoZ.net - Tutti i diritti sono riservati. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

var jaySite = {
	Author: 'Jacopo Andrea Nuzzi',
	Version: '3.0.1'
};

jaySite.global = {};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.RateItem = Class.create();
jaySite.RateItem.prototype = {
	initialize: function(_sec, _id)
	{
		this.options = {
			cookieName: 'jaySite.RateCookie',
			section: _sec,
			id: _id
		};

		var _myCookie = Cookie.get(this.options.cookieName);
		var me = this;

		if (_myCookie == null || _myCookie.indexOf('' + this.options.section + ':' + this.options.id + '') == -1)
		{
			$('__rateli_' + this.options.id).update();

			$('__rateli_' + this.options.id).createElement('img', {id: 'rateImageUp_1_' + this.options.id, src: 'http://static.jacoz.net/images/rate_upoff.gif', style_cssText: 'cursor: hand; cursor: pointer; margin-right: 7px;'});
			Event.observe('rateImageUp_1_' + this.options.id, 'mouseover', (function() { $('rateImageUp_1_' + this.options.id).src = 'http://static.jacoz.net/images/rate_upon.gif'; }).bindAsEventListener(this));
			Event.observe('rateImageUp_1_' + this.options.id, 'mouseout', (function() { $('rateImageUp_1_' + this.options.id).src = 'http://static.jacoz.net/images/rate_upoff.gif'; }).bindAsEventListener(this));
			Event.observe('rateImageUp_1_' + this.options.id, 'click', (function() { me.onClick('up'); }).bindAsEventListener(this));

			$('__rateli_' + this.options.id).createElement('img', {id: 'rateImageDown_1_' + this.options.id, src: 'http://static.jacoz.net/images/rate_downoff.gif', style_cssText: 'cursor: hand; cursor: pointer;'});
			Event.observe('rateImageDown_1_' + this.options.id, 'mouseover', (function() { $('rateImageDown_1_' + this.options.id).src = 'http://static.jacoz.net/images/rate_downon.gif'; }).bindAsEventListener(this));
			Event.observe('rateImageDown_1_' + this.options.id, 'mouseout', (function() { $('rateImageDown_1_' + this.options.id).src = 'http://static.jacoz.net/images/rate_downoff.gif'; }).bindAsEventListener(this));
			Event.observe('rateImageDown_1_' + this.options.id, 'click', (function() { me.onClick('down'); }).bindAsEventListener(this));
		}
		else
		{
			if (_myCookie.indexOf('' + this.options.section + ':' + this.options.id + '') != -1)
			{
				if (_myCookie.indexOf('' + this.options.section + ':' + this.options.id + ':up') != -1) {
					var _myCookieRate = 'up';
				} else if (_myCookie.indexOf('' + this.options.section + ':' + this.options.id + ':down') != -1) {
					var _myCookieRate = 'down';
				}

				$('__rateli_' + this.options.id).update();

				$('__rateli_' + this.options.id).createElement('img', {id: 'ratedImage_1_' + this.options.id, src: 'http://static.jacoz.net/images/rate_' + _myCookieRate + 'on.gif', style_cssText: 'cursor: hand; cursor: pointer;'});
				Event.observe('ratedImage_1_' + this.options.id, 'click', (function() { alert('Hai gi votato,  possibile votare una sola volta.'); }).bindAsEventListener(this));
			}
		}

		return false;
	},

	onClick: function(r)
	{
		var me = this;

		$('__ajaxLoadingDiv').setStyle({display: 'none', backgroundColor: '#FFFFFF', border: 'solid 1px #000000', padding: '20px', fontSize: '15px'});
		$('__ajaxLoadingDiv').update('<img src="http://static.jacoz.net/images/loading2.gif" alt="" /><br />Salvataggio in corso...<br />L\'operazione potrebbe richiedere alcuni minuti.');

		jaySite.global.getBodyWrapDiv('__ajaxLoadingDiv', 6);

		new Ajax.Request('/__ajax.php', {postBody: '__selPage=globalRate&section=' + this.options.section + '&id=' + this.options.id + '&rate=' + r + '', onSuccess: this.onSuccess.bind(this)});
	},

	onSuccess: function(t)
	{
		var rateResult = t.responseText.split('\n');

		if (Cookie.get(this.options.cookieName) != null)
		{
			Cookie.set(this.options.cookieName, Cookie.get(this.options.cookieName) + ';' + rateResult[0] + ':' + rateResult[1], 1);
		}
		else
		{
			Cookie.set(this.options.cookieName, rateResult[0] + ':' + rateResult[1], 1);
		}

		alert('Il tuo voto  stato registrato con successo!\nGrazie per la tua opinione.');
		$('__rateli_' + this.options.id).update();
		$('__rateli_' + this.options.id).createElement('img', {id: 'ratedImage_1_' + this.options.id, src: 'http://static.jacoz.net/images/rate_' + rateResult[1] + 'on.gif', style_cssText: 'cursor: hand; cursor: pointer;', onclick: function() { alert('Hai gi votato,  possibile votare una sola volta.'); }});
		Event.observe('ratedImage_1_' + this.options.id, 'click', (function() { alert('Hai gi; votato,  possibile votare una sola volta.'); }).bindAsEventListener(this));

		$('__ajaxLoadingDiv', 'bodywrap').invoke('hide');
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Account = {
	changeUserListPage: function(_pageNum)
	{
		new Ajax.Updater('account_usersList', '/__ajax.php', {postBody: '__selPage=ul&ajax=true&cmd=usersList&pageNum=' + _pageNum + ''});
	},

	checkUsernameAvailabilityEnableButton: function()
	{
		if ($F('username') == false)
		{
			$('checkusername').disabled = true;
			$('availabilityresponse').innerHTML = '';
		}
		else
		{
			$('checkusername').disabled = false;
		}
	},

	checkUsernameAvailability: function()
	{
		new Ajax.Updater('availabilityresponse', '/join.html', {postBody: 'cmd=checkUsername&username=' + $F('username') + '', loadingabs: true});
	},

	webdevSubmenu_isOpen: 0,

	toggleWebdevSubmenu: function()
	{
		var me = this;

		$('leftcontent').getElementsBySelector('li[title="account_webdev_submenu"]').each(function(element, i)
		{
			if (me.webdevSubmenu_isOpen == 0)
			{
				me.webdevSubmenu_isOpen = 1;
				(element).style.display = '';
			}
			else
			{
				me.webdevSubmenu_isOpen = 0;
				(element).style.display = 'none';
			}
		});
	}
};

jaySite.Account.Newsletter = {
	addNewUser: function()
	{
		new Ajax.Updater('newsletteraction', '/newsletter.html', {postBody: 'action=update', onComplete: function() { alert('L\'iscrizione alla newsletter  avvenuta con successo.'); }});
	},

	deleteUser: function()
	{
		var _answer = confirm("Sei sicuro di volerti cancellare dalla newsletter di JacoZ.net ?\nProcedendo con questa operazione non sarai pi aggiornato su tutti gli aggiornamenti e le modifiche effettuate sul sito.");
		if (_answer)
		{
			new Ajax.Updater('newsletteraction', '/newsletter.html', {postBody: 'action=update', onComplete: function() { alert('La cancellazione dalla newsletter  avvenuta con successo.'); }});
		}
		else
		{
			return false;
		}
	},

	getMailList_close: function()
	{
		new Effect.Fade($('__ajaxLoadingDiv'));
		$('bodywrap').hide();
	},

	getMailList: function()
	{
		new Ajax.Request('/newsletter.html', {postBody: 'action=list', onSuccess: this.getMailList_private.bind(this)});
	},

	getMailList_private: function(t)
	{
		$('__ajaxLoadingDiv').setStyle({display: 'none', backgroundColor: '#FFFFFF', border: 'solid 1px #000000', padding: '20px', fontSize: '15px'});
		$('__ajaxLoadingDiv').update('<img src="http://static.jacoz.net/images/loading2.gif" alt="" /><br />Salvataggio in corso...<br />L\'operazione potrebbe richiedere alcuni minuti.');

		jaySite.global.getBodyWrapDiv('__ajaxLoadingDiv', 6);

		$('__ajaxLoadingDiv').setStyle({width: '450px', padding: '5px', textAlign: 'left', fontSize: '12px'});
		$('__ajaxLoadingDiv').update(t.responseText);
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Directory = {
	rateLink: function(siteid)
	{
		var votechoose = $('votechoose_' + siteid);
		var votelink = $('votelink_' + siteid);
		var voteoutput = '';

		voteoutput += '<br />';
		for(i = 1; i <= 5; i++)
		{
			voteoutput += '<img style="cursor: hand; cursor: pointer;" ';
			voteoutput += 'id="star_' + siteid + '_' + i + '" ';
			voteoutput += 'src="http://static.jacoz.net/images/rate_staroff.gif" ';
			voteoutput += 'onclick="jaySite.Directory.registerNewVote(' + siteid + ', ' + i + '); return false;" ';
			voteoutput += 'onmouseover="set_FullStars(' + i + ', ' + siteid + '); jaySite.Directory.printRateMessage(' + i + ', ' + siteid + ');" ';
			voteoutput += 'onmouseout="set_EmptyStars(' + i + ', ' + siteid + '); jaySite.Directory.killRateMessage(' + siteid + ');" " ';
			voteoutput += 'alt="" />';
		}
		voteoutput += '<span id="votemsg_' + siteid + '"></span>';

		votechoose.update(voteoutput);
		votelink.update('Non votare');

		if (votechoose.style.display != 'inline')
		{
			votechoose.style.display = 'inline';
			votechoose.update(voteoutput);
			votelink.update('Non votare');
		}
		else
		{
			votechoose.hide();
			votechoose.update();
			votelink.update('Vota');
		}
	},

	printRateMessage: function(vote, siteid)
	{
		var _voteMsg = $('votemsg_' + siteid);
		var _rateMsg = ['Davvero brutto', 'Niente di speciale', 'Accettabile', 'Carino', 'Splendido'];

		_voteMsg.update(' <em style="font-size: 10px; color: #666666">' + _rateMsg[(vote - 1)] + '</em>');
	},

	killRateMessage: function(siteid)
	{
		$('votemsg_' + siteid).innerHTML = '';
	},

	registerNewVote: function(siteid, vote)
	{
		var _voteChoose = $('votechoose_' + siteid);
		var _voteLink = $('votelink_' + siteid);

		_voteChoose.hide();
		_voteLink.update('Vota');
		new Ajax.Updater('voteval_' + siteid + '', '/rate.php', {postBody: 's=true&r=' + siteid + '-' + vote + ''});
	},

	registerNewClick: function(siteid)
	{
		new Ajax.Request('/jump.php', {postBody: 'redirect=false&id=' + siteid + ''});
	},

	userShowOptions: function(siteid, w)
	{
		w = w || '';

		if (typeof siteid == 'string' && siteid == 'all')
		{
			setTimeout(function()
			{
				if (w.innerHTML == 'Mostra le opzioni di tutti gli elementi') {
					w.innerHTML = 'Nascondi le opzioni di tutti gli elementi';	
				} else {
					w.innerHTML = 'Mostra le opzioni di tutti gli elementi';			
				}
			}, 500);

			$('directorysiteslist').getElementsBySelector('[name="directorylinkoptions"]').each(function(element)
			{
				new Effect.toggle(element.id, 'blind', {duration: 0.5});
			});
		}
		else
		{
			new Effect.toggle('directorylinkoptions_' + siteid + '', 'blind', {duration: 0.5});
		}
	},

	userDoLinkOption: function(action, siteid)
	{
		if (action == 'modify')
		{
			var sitemodify = $('directorylinkmodify_' + siteid);

			sitemodify.show();
			new Ajax.Updater('directorysiteslist', '/__ajax.php', {postBody: '__selPage=ad&sec=edit&action=modify&id=' + siteid + ''});
		}
		else if (action == 'delete')
		{
			var siteLi = $('directorylink_' + siteid);
			var siteOptions = $('directorylinkoptions_' + siteid);
			var _deleteAnswer = confirm('Sei sicuro di voler eliminare questo link dalla directory?');

			if (_deleteAnswer)
			{
				new Effect.Fade('directorylink_' + siteid);
				new Ajax.Updater('', '/__ajax.php', {postBody: '__selPage=ad&sec=edit&action=delete&id=' + siteid + ''});
                
				return false;
			}
			else
			{
				new Effect.BlindUp('directorylinkoptions_' + siteid + '', {duration: 0.5});

				return false;
			}
		}
	},

	userUpdateLink: function(siteid)
	{
		var siteOptions = $('directorylinkoptions_' + siteid);
		var siteModify = $('directorylinkmodify_' + siteid);

		siteOptions.hide();
		siteModify.hide();
		new Ajax.Updater('directorylinkinfo_' + siteid + '', '/__ajax.php', {postBody: '__selPage=ad&sec=edit&action=info&id=' + siteid + ''});
	},

	userCheckExistingUrl_private: function(t)
	{
		eval(t.responseText);
		return directory_urlAlreadyExists;
	},

	userCheckExistingUrl: function(url)
	{
		new Ajax.Request('/__ajax.php', {postBody: '__selPage=ad&sec=edit&action=checkExistingUrl&url=' + encodeURIComponent(url) + '', onSuccess: this.userCheckExistingUrl_private.bind(this)});
	},

	submitForm: function(action)
	{
		action = action || 'add';
		var errors = [], _name = $F('name').strip(), _url = $F('url').strip(), _desc = $F('desc').strip(), _dir = $F('directory').strip();

		if (_name == '' || _name.length > 100) {
			errors.push(['name_error', 'Inserire il nome del sito (massimo 100 caratteri).']);
		} if (!_url.match('http://' || _url.length > 255)) {	
			errors.push(['url_error', 'Inserire un sito internet comprensivo di http:// (massimo 255 caratteri).']);
		} if (this.userCheckExistingUrl(_url) == 1) {
			errors.push(['url_error', 'Il sito internet inserito  gi esistente.']);
		} if (_desc > 255) {
			errors.push(['desc_error', 'Inserire una descrizione di massimo 255 caratteri.']);
		} if (_dir == '0') {
			errors.push(['dir_error', 'Il sito non pu&ograve; essere nella directory principale (Top).']);
		}

		$('accountconfig_form').getElementsBySelector('[name="erroroutput"]').each(function(element)
		{
			element.update();
		});
		if (errors.size() > 0)
		{
			errors.each(function(error)
			{
				$(error[0]).update('<span style="color: #FF0000; font-size: 12px; font-weight: bold;">' + error[1] + '</span>');
			});

			return false;
		}
		else
		{
		    _postBody = $('accountconfig_form').serialize();
			$('accountconfig_form').getElementsBySelector('[type="submit"]', '[type="button"]').invoke('disable');
			new Ajax.Updater('accountconfig_formresult', '/__ajax.php', {postBody: _postBody});
		}
	},
	
	updateDescCounter: function(field)
	{
	    $('descCharCounter').value = (255 - field.value.length);
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Favorites = {
	addNewItem: function(_section, _id)
	{
		new Ajax.Updater('fav_' + _id + '', '/__ajax.php', {postBody: '__selPage=fav&action=add&section=' + _section + '&id=' + _id + ''});
	},

	deleteItem: function(_section, _id)
	{
		var _answer = confirm('Sei sicuro di voler eliminare questo link dai tuoi preferiti?');

		if (_answer)
		{
			new Ajax.Updater('fav_' + _id + '', '/__ajax.php', {postBody: '__selPage=fav&action=del&section=' + _section + '&id=' + _id + ''});
		}
		else
		{
			return false;
		}
	},

	deleteItems: function()
	{
		var _Section = $F('favlistsection'), _IDs_1 = '', _IDs_2 = '';

		$('favlistform').getElementsBySelector('[name="favdel"]').each(function(element)
		{
			if (!element.checked)
			{
				_IDs_1 += element.value + ',';
			}
			else
			{
				_IDs_2 += element.value + ',';
			}
		});

		if (_IDs_2 == '')
		{
			alert('Selezionare almeno un elemento.');
			return false;
		}


		if (confirm('Sei sicuro di voler eliminare questi elementi dai preferiti?'))
		{
			new Ajax.Request('/__ajax.php', {postBody: '__selPage=fav&action=update&section=' + _Section + '&id_1=' + _IDs_1 + '&id_2=' + _IDs_2 + '', onSuccess: this.deleteItems_private.bind(this)});
		}
		else
		{
			return false;
		}
	},
	deleteItems_private: function(t)
	{
		$w(t.responseText).each(function(id)
		{
			if (id != '')
			{
				new Effect.DropOut('favitemid' + id + '');
				setTimeout(function()
				{
					$('favitemid' + id + '').remove();
				}, 1000);
			}
		});
		setTimeout(function()
		{
			if ($$('ul#favdatalist li').size() == 0)
			{
				new Insertion.Before('favdatalist', 'Nessun elemento presente in questa categoria.');
				$('favdatalist').remove();
				$('favlistform').getElementsBySelector('[type="button"]').invoke('remove');
			}
		}, 1000);
		
		$('favlistform').getElementsBySelector('[type="button"]')[1].disabled = true;
		$('favlistform').getElementsBySelector('[type="button"]')[1].value = 'Elimina';
	},

	openFolder: function(_folder)
	{
		tabMenu_changeCurrentTab(jaySite.Favorites.Show, '', _folder);
		tabMenu_changeCurrentSection(jaySite.Favorites.Show, _folder)

		return false;
	},
    
	reloadFolder: function(_folder)
	{
	    new Ajax.Updater('favdatalist', '/favorites.php', {postBody: 'action=reload&sec=' + _folder + ''});
	},
	
	getAllCheckedElements: function()
	{
		var checked = 0;
		$('favlistform').getElementsBySelector('[name="favdel"]').each(function(element)
		{
			if (element.checked)
			{
				checked++;
			}
		});

		return checked;
	},

	toggleElement: function(w)
	{
		var favItem = $('favitemid' + w.value + '');

		if (favItem.style.fontWeight == 'bold')
		{
			w.checked = false;

			favItem.setStyle({fontWeight: 'normal'});
		}
		else
		{
			w.checked = true;

			favItem.setStyle({fontWeight: 'bold'});
			if ($('favitemexclude' + w.value + '')) { $('favitemexclude' + w.value + '').setStyle({fontWeight: 'normal'}); }
			new Effect.Highlight('favitemid' + w.value + '');
		}

		if (this.getAllCheckedElements() == $('favlistform').getElementsBySelector('[name="favdel"]').size())
		{
			$('favlistform').getElementsBySelector('[type="button"]')[0].value = 'Deseleziona tutti';
		}
		else
		{
			$('favlistform').getElementsBySelector('[type="button"]')[0].value = 'Seleziona tutti';
		}
		if (this.getAllCheckedElements() > 0)
		{
			$('favlistform').getElementsBySelector('[type="button"]')[1].disabled = false;
			$('favlistform').getElementsBySelector('[type="button"]')[1].value = 'Elimina (' + this.getAllCheckedElements() + ')';
		}
		else
		{
			$('favlistform').getElementsBySelector('[type="button"]')[1].disabled = true;
			$('favlistform').getElementsBySelector('[type="button"]')[1].value = 'Elimina';
		}
	},

	toggleAllElements: function(w)
	{
		var me = this;

		$('favlistform').getElementsBySelector('[name="favdel"]').each(function(element, i)
		{
			setTimeout(function()
			{
				me.toggleElement(element);
			}, ((i - 1) * 100));
		});
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Forum = {
	toggleForumCat: function(_id)
	{
		new Effect.toggle('forumCat_' + _id + '', 'blind', {duration: 0.5});
	},

	highlightBox: function(_class)
	{
		$$(_class).each(function(div)
		{
			var originalBg = div.getElementsByTagName('div')[0].style.backgroundColor;
			var originalBorder = div.getElementsByTagName('div')[0].style.border;
			div.onmouseover = function()
			{
				this.getElementsByTagName('div')[0].style.border = 'solid 1px #000000';
				//this.getElementsByTagName('div')[0].style.backgroundColor = '#E2E2E2';
			}
			div.onmouseout = function()
			{
				this.getElementsByTagName('div')[0].style.border = originalBorder;
				//this.getElementsByTagName('div')[0].style.backgroundColor = originalBg;
			}
		});	
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.My = {
	createTopContent: function()
	{
		$('__MAINBOX').createElement('div', {style_cssText: 'text-align: center; clear: both; padding-bottom: 10px;', innerHTML: '[<a href=\'javascript:;\' onclick=\'new jaySite.My.Config.init(); return false;\'>Aggiungi dei contenuti</a> | <a href=\'javascript:;\' onclick=\'new jaySite.My.toggleAllElements(this); return false;\'>Riduci tutti</a> | <a href=\'javascript:;\' onclick=\'new jaySite.My.toggleAllOptions(this); return false;\'>Espandi le opzioni</a>]'});
	},

	createList: function()
	{
		var me = this;
		this.mainBox = $('__MAINBOX');
		this._colDiv = [];

		for(var i = 0; i < 2; i++)
		{
			if (i % 2 == 0) {
				var _colDivClassName = 'mainboxright';
			} else {
				var _colDivClassName = 'mainboxleft';
			}

			(this.mainBox).createElement('div', {id: '__colDiv_' + (i + 1) + '', className: _colDivClassName});
			$('__colDiv_' + (i + 1) + '').createElement('ul', {id: '__MAINUL_' + (i + 1) + '', style_cssText: 'list-style-type: none; margin: 0px; padding: 0px; min-width: 300px; min-height: 300px;'});
		}
	},

	toggleEditBox: function()
	{
		var me = this;
		var _editBoxID = me.id.replace(/[^0-9]/g, '');

		new Effect.toggle('__editDiv_' + _editBoxID + '', 'blind', {duration: 0.5});
	},

	toggleAllElements: function(w)
	{
		if (w.innerHTML == 'Riduci tutti') {
			w.update('Espandi tutti');
		} else {
			w.update('Riduci tutti');
		}

		for (var i = 0; i < jaySite.My.AllBoxes; i++)
		{
			new Effect.toggle('__contentDiv_' + i + '', 'blind', {duration: 0.5});
		};
	},

	toggleAllOptions: function(w)
	{
		if (w.innerHTML == 'Espandi le opzioni') {
			w.innerHTML = 'Riduci le opzioni';
		} else {
			w.innerHTML = 'Espandi le opzioni';
		}

		for (var i = 0; i < jaySite.My.AllBoxes; i++)
		{
			new Effect.toggle('__editDiv_' + i + '', 'blind', {duration: 0.5});
		};
	},

	getBoxContent: function(_boxContent, _ID)
	{
		new Ajax.Updater('__contentDiv_' + _ID + '', '/__ajax.php', {postBody: '__selPage=box&do=getBox&sid=' + _boxContent + ''});
	}
};

jaySite.My.createBox = Class.create();
jaySite.My.createBox.BoxID = 0;
jaySite.My.createBox.prototype = {
	initialize: function(_boxTitle, _boxName, _colID)
	{
		var me = this;

		this._boxID = jaySite.My.createBox.BoxID++;

		if (_colID == null)
		{
			if (this._boxID < Math.ceil(jaySite.My.AllBoxes / 2)) {
				var _colID = 2;
			} else {
				var _colID = 1;
			}
		}

		$('__MAINUL_' + _colID + '').createElement('li', {id: '__li_' + _boxName + '', style_cssText: 'float: left; width: 300px; float: left; padding-right: 5px;'});
		$('__li_' + _boxName + '').createElement('div', {id: '__boxDiv_' + me._boxID + '', className: 'medbox'});
		$('__boxDiv_' + this._boxID + '').createElement('div', {id: '__editDiv_' + me._boxID + '', style_cssText: 'display: none;'});
		$('__editDiv_' + this._boxID + '').createElement('div', {id: '__editDiv_' + me._boxID + '_content', name: '__editDiv_options', style_cssText: 'padding: 2px; padding-top: 4px; text-align: right; background-color: #FFCC00; border-left: solid 1px #CCCCCC; border-right: solid 1px #CCCCCC;'});
		$('__editDiv_' + me._boxID + '_content').createElement('img', {id: '__editDiv_' + me._boxID + '_content_img_reduce'});
		$('__editDiv_' + me._boxID + '_content').createElement('img', {id: '__editDiv_' + me._boxID + '_content_img_close'});
		$('__boxDiv_' + this._boxID + '').createElement('h3', {id: '__titleDiv_' + me._boxID + '', style_cssText: 'cursor: hand; cursor: pointer;', innerHTML: '<span class=handle>' + _boxTitle + '</span>'});
		$('__boxDiv_' + this._boxID + '').createElement('div', {id: '__contentDiv_' + me._boxID + '', className: 'medboxcontent', style_cssText: 'text-align: left;'});
		$('__boxDiv_' + this._boxID + '').createElement('img', {className: 'spacer', src: 'http://static.jacoz.net/images/spacer.gif', alt: ''});
		$('__boxDiv_' + this._boxID + '').createElement('div', {id: '__closeDiv_' + me._boxID + '', className: 'medboxbot'});

		new jaySite.My.imageButtons($('__editDiv_' + me._boxID + '_content_img_reduce'), 'riduci', this._boxID, _boxName);
		new jaySite.My.imageButtons($('__editDiv_' + me._boxID + '_content_img_close'), 'chiudi', this._boxID, _boxName);
		$('__titleDiv_' + this._boxID + '').onclick = jaySite.My.toggleEditBox;

		jaySite.My.getBoxContent(_boxName, this._boxID);
	}
};

jaySite.My.Config = {
	boxAdded: 0,

	init: function()
	{
		if ($('bodywrap').getStyle('display') == 'none')
		{
			$('__ajaxLoadingDiv').setStyle({backgroundColor: '#FFFFFF', border: 'solid 1px #000000', width: '530px', height: '300px', padding: '5px', fontSize: '12px', textAlign: 'left'});

			jaySite.global.getBodyWrapDiv('__ajaxLoadingDiv', 6);

			new Ajax.Request('/__ajax.php', {postBody: '__selPage=personalize&do=showList', onSuccess: jaySite.My.Config.getBoxesList.bind(this)});
		}
		else
		{
			if (this.boxAdded != 0)
			{
				var _confirm = confirm('Salvare le modifiche?');
				if (_confirm)
				{
					this.saveChanges();
				}
				else
				{
					new Effect.Shrink('__ajaxLoadingDiv');
					$('bodywrap').hide();
				}
			}
			else
			{
				new Effect.Shrink('__ajaxLoadingDiv');
				$('bodywrap').hide();
			}
		}
	},

	changeTitleStyle: function(_id, _name, _title)
	{
		_name = _name || '';
		_title = _title || '';
		var myItem = $('__boxTitle_' + _id + '');

		if (myItem.style.fontWeight == 'bold')
		{
			myItem.setStyle({fontWeight: 'normal'});
			this.boxAdded--;
			jaySite.My.AllBoxes--;
			$('__li_' + _name + '').remove();
		}
		else
		{
			myItem.setStyle({fontWeight: 'bold'});
			new Effect.Highlight('__boxTitle_' + _id + '');
			this.boxAdded++;
			jaySite.My.AllBoxes++;
			new jaySite.My.createBox(_title, _name, (jaySite.My.AllBoxes % 2 == 0 ? 1 : 2));
		}
	},

	getBoxesList: function(t)
	{
		var me = this;
		var _divName = $('__ajaxLoadingDiv');

		var _xmlDoc = t.responseXML.documentElement;
		var _itemsCounter = _xmlDoc.getElementsByTagName('item')
		var _output = '';
		var checkedItems = [];

		_output += '<div class="handle" style="cursor: move; border-bottom: solid 1px #000000; text-align: center; font-size: 15px; font-weight: bold; background-color: #EFEFEF; margin-top: -5px; margin-left: -5px; margin-right: -5px; margin-bottom: 5px; padding-top: 5px; padding-bottom: 5px;">';
		_output += 'Aggiungi dei contenuti<br /><a href="" style="font-size: 10px;" onclick="jaySite.My.Config.init(); return false;">(Chiudi)</a></div>';
		_output += '<div style="padding-bottom: 10px; margin-top: -5px; margin-right: -5px; height: ' + (Prototype.Browser.IE ? '258' : '252') + 'px; overflow: auto;"><form id="boxesConfigForm" action="/__ajax.php" method="post">';
		for (var i = 0; i < _itemsCounter.length; i++)
		{
			_title = _itemsCounter[i].getElementsByTagName('title');
			_boxTitle = _itemsCounter[i].getElementsByTagName('boxtitle');
			_name = _itemsCounter[i].getElementsByTagName('name');
			_checked = _itemsCounter[i].getElementsByTagName('checked');

			try
			{
				if(_checked[0].firstChild.data)
				{
					checkedItems[checkedItems.size()] = i;
				}
			}
			catch(e){}

			_output += '<fieldset style="margin: 0px; border: 0px; padding: 5px;"><label for="__boxSel_' + i + '">';
			_output += '<input type="checkbox" id="__boxSel_' + i + '" name="mybox" value="' + _name[0].firstChild.data + '" onclick="jaySite.My.Config.changeTitleStyle(' + i + ', \'' + _name[0].firstChild.data + '\', \'' + _boxTitle[0].firstChild.data + '\');" />';
			_output += ' <span id="__boxTitle_' + i + '">' + _title[0].firstChild.data + '</span>';
			_output += '</label></fieldset>';
		}
		_output += '<br /><input id="__boxSaveButton" type="button" value=" Salva le modifiche " onclick="jaySite.My.Config.saveChanges(); return false;" />';
		_output += '</form></div>';

		_divName.update(_output);

		(checkedItems).each(function(i)
		{
			$('__boxSel_' + i + '').checked = true;
			$('__boxTitle_' + i + '').setStyle({fontWeight: 'bold'});
			new Effect.Highlight('__boxTitle_' + i + '');
		});

		var draggableSnap = function(x, y, d)
		{
			function constrain(n, l, u)
			{
				if (n > u) return u;
				else if (n < l) return l;
				else return n;
			}
		
			element_dimensions = Element.getDimensions(d.element);
			parent_dimensions = Element.getDimensions(d.element.parentNode);
			return [constrain(x, 0, parent_dimensions.width - element_dimensions.width), constrain(y, 0, parent_dimensions.height - element_dimensions.height)];
		};
		new Draggable('__ajaxLoadingDiv', {handle: 'handle'});
	},

	saveChanges: function()
	{
		var boxesList = '';
		$('boxesConfigForm').getElementsBySelector('[name="mybox"]').each(function(element)
		{
			if (element.checked)
			{
				boxesList += element.value + ','
			}
		});

		if (this.boxAdded != 0)
		{
			var ajaxOnSuccess = function()
			{
				alert('Salvataggio avvenuto con successo!');
				new Effect.Shrink('__ajaxLoadingDiv');
				$('bodywrap').hide();
			}

			new Ajax.Request('/__ajax.php', {postBody: '__selPage=personalize&do=save&box=' + boxesList + '', onSuccess: ajaxOnSuccess});
		}
		else
		{
			new Effect.Shrink('__ajaxLoadingDiv');
			$('bodywrap').hide();
		}
	}
};

jaySite.My.imageButtons = Class.create();
jaySite.My.imageButtons.prototype = {
	initialize: function(_image, _action, _ID, _boxName)
	{
		this.getImage(_image, _action, _ID, _boxName);
	},

	getImage: function(_image, _action, _ID, _boxName)
	{
		var me = this;
	
		_image.src = 'http://static.jacoz.net/images/my/' + _action + '_1.gif';
		_image.onmouseover = function()
		{
			me.onMouseOver(_image, _action, false, false);
		}
		_image.onmouseout = function()
		{
			me.onMouseOut(_image, _action, false, false);
		}
		_image.onmousedown = function()
		{
			me.onMouseDown(_image, _action, false, false);
		}
		_image.onmouseup = function()
		{
			me.onMouseOut(_image, _action, false, false);
		}
		_image.onclick = function()
		{
			me.onClick(_image, _action, _ID, _boxName);
		}
		_image.style.cssText = 'margin-left: 4px;';
		_image.style.cursor = 'default';

		return _image;
	},
	
	onMouseOver: function(_img, _action)
	{
		_img.src = 'http://static.jacoz.net/images/my/' + _action + '_2.gif';
	},
	
	onMouseOut: function(_img, _action)
	{
		_img.src = 'http://static.jacoz.net/images/my/' + _action + '_1.gif';
	},
	
	onMouseDown: function(_img, _action)
	{
		_img.src = 'http://static.jacoz.net/images/my/' + _action + '_3.gif';
	},

	_unDoDelete: function(_ID)
	{
		$('__unDoDiv_' + _ID + '').update();
		$('__titleDiv_' + _ID + '', '__contentDiv_' + _ID + '', '__closeDiv_' + _ID + '').invoke('show');
	},
	
	onClick: function(_img, _action, _ID, _boxName)
	{
		var _boxDiv = $('__boxDiv_' + _ID + '');
		var _titleDiv = $('__titleDiv_' + _ID + '');
		var _contentDiv = $('__contentDiv_' + _ID + '');
		var _closeDiv = $('__closeDiv_' + _ID + '');

		if (_action == 'riduci')
		{
			var _subAction = 'ingrandisci';

			new Effect.BlindUp('__contentDiv_' + _ID + '', {duration: 0.5});
			this.getImage(_img, _subAction, _ID, _boxName);
		}
		if (_action == 'ingrandisci')
		{
			var _subAction = 'riduci';
	
			new Effect.BlindDown('__contentDiv_' + _ID + '', {duration: 0.5});
			this.getImage(_img, _subAction, _ID, _boxName);
		}
		if (_action == 'chiudi')
		{
			if (jaySite.My._userNotLogged == true)
			{
				alert('Funzione abilitata ai soli utenti registrati.');
			}
			else
			{
				var _confirmMessage = confirm('Sei sicuro di voler chiudere questo box?');
		
				if (_confirmMessage == true)
				{
					new Effect.DropOut('__boxDiv_' + _ID + '');
					new Ajax.Updater('', '/__ajax.php', {postBody: '__selPage=box&do=deleteBox&sid=' + _boxName + ''});
				}
			}
		}
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Lyrics = {
	changeTabSectionFromSideMenu: function(id)
	{
		if ($('tabmenu_mainhtml'))
		{
			tabMenu_changeCurrentTab(jaySite.Lyrics.TabMenu, currentSection, id);
			tabMenu_changeCurrentSection(jaySite.Lyrics.TabMenu, id);

			$('submenu_' + currentSection + '').className = '';
			currentSection = id;
			$('submenu_' + currentSection + '').className = 'currentsec';
			$$('#maincontent h1')[0].innerHTML = 'Lyrics - ' + $(currentSection).innerHTML + '';
		}
	},

	changeSearchSuggestSection: function(w, options)
	{
		options = options || {};
		this.searchSuggest(w.value);
	},

	searchSuggest: function(w, options)
	{
		options = options || {field: 'query', divName: 'lyrics_suggest'};
		new Ajax.Autocompleter(options.field, options.divName, '/search.php', {parameters: 'action=suggest&sec=' + (w ? w : 'text') + '&maxRes=10', frequency: 0.1});
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Programs = {
	searchSuggest: function()
	{
		new Ajax.Autocompleter('q', 'prg_suggest', '/search.php', {parameters: 'action=suggest', frequency: 0.1});
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Search = {
	registerNewSearch: function(_query)
	{
		new Ajax.Request('/__ajax.php', {postBody: '__selPage=rs&query=' + _query + '', onSuccess: Prototype.emptyFunction.bind(this)});
	},

	searchSuggest: function()
	{
		new Ajax.Autocompleter('q', 'search_suggest', '/__ajax.php', {parameters: '__selPage=ss&maxRes=10', frequency: 0.1});
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Services = {
	setStatus: function(_section)
	{
		new Ajax.Updater('buttons_' + _section + '', '/__ajax.php', {postBody: '__selPage=config&section=' + _section + '&action=setStatus'});
	},

	showSubSection: function(_section, _id, _functions)
	{
		_functions = _functions || {};
		jaySite.Services.Config.replaceAllClasses2(_id);

		($('tabmenu_menu').descendants()).each(function(element, i)
		{
			i += 1;
			if (i != _id)
			{
				$('services_' + _section + '_' + i).hide();
				if (_functions.onHide && typeof _functions.onHide == 'function')
				{
					_functions.onHide();
				}
			}
			else
			{
				$('services_' + _section + '_' + i).show();
				if (_functions.onShow && typeof _functions.onShow == 'function')
				{
					_functions.onShow();
				}
			}
		});
	}
};

jaySite.Services.Clickcounter = {
	jumpMenuOnShow: function(_id)
	{
		$('save_button' + _id + '').enable();
		$('services_config_form_' + _id + '').show();
		$('services_config_result_' + _id + '').update().hide();
	},

	Save: function(_id)
	{
		var errors = [],
			_srvName = $F('srvname'),
			_srvID = $F('srv_id' + _id + ''),
			_save = $('save_button' + _id + ''),
			_url = $F('url' + _id + '').strip(),
			_title = $F('title' + _id + '').strip(),
			_cookie = $F('usecookie' + _id + ''),
			_month = $F('month' + _id + '');

		if (_title == '' || _title.length > 255) {
			errors.push(['title_error', 'Inserire il nome del sito (massimo 255 caratteri).']);
		} if (!_url.match('http://' || _url.length > 255)) {	
			errors.push(['url_error', 'Inserire un sito internet comprensivo di http:// (massimo 255 caratteri).']);
		}

		$('accountconfig_form').getElementsBySelector('[name="erroroutput"]').each(function(element)
		{
			element.update();
		});
		if (errors.size() > 0)
		{
			errors.each(function(error)
			{
				$(error[0]).update('<span style="color: #FF0000; font-size: 12px; font-weight: bold;">' + error[1] + '</span>');
			});

			return false;
		}
		else
		{
			(_save).disable();
			new Ajax.Request('/__ajax.php', {postBody: '__selPage=config&service=' + _srvName + '&sec=config&cmd=configure&id=' + _srvID + '&url=' + _url + '&title=' + _title + '&usecookie=' + _cookie + '&month=' + _month + '', onSuccess: this.savePrivate.bind(this)});
		}
	},

	savePrivate: function(t)
	{
		var result = (t.responseText).split('\n');

		$('services_config_form_' + result[0] + '').hide();
		$('services_config_result_' + result[0] + '').update(result[1]).show();
	}
};

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

jaySite.Webdev = {
	CorrelatedArtsMenuStatus: -1,
	
	buildCorrelatedArtsHtml: function(_artId)
	{
	    $('correlated_div').update('<a id="correlated_link" href="javascript:;" ' +
	                               'onclick="jaySite.Webdev.getCorrelatedArts(\'' + _artId + '\')">' +
	                               'Articoli collerati</a><br /><br /><div id="correlated_article"></div>');
	},
	
	getCorrelatedArts: function(_artId)
	{
		var correlatedarticle = $('correlated_article');
		var correlatedlink = $('correlated_link');

		if(this.CorrelatedArtsMenuStatus == 1)
		{
			this.CorrelatedArtsMenuStatus = -1;
			new Effect.Fold('correlated_article');
			correlatedlink.update('Articoli correlati');
		}
		else
		{
			this.CorrelatedArtsMenuStatus = 1;
			correlatedarticle.setStyle({display: 'none', padding: '5px', border: 'solid 1px #0000FF', backgroundColor: '#EFEFEF', margin: 'auto', width: 'auto', marginLeft: '10px', marginBottom: '10px'});
			correlatedlink.update('Articoli correlati (Chiudi)');
			new Ajax.Request('/articoli/getcorr.html', {postBody: 'artid=' + _artId + '', onSuccess:
							 (function(t)
									   {
											$('correlated_article').update(t.responseText);
											$('correlated_article').setStyle({display: 'none'});
											new Effect.BlindDown('correlated_article');
									   }).bind(this)});
		}
	},

	searchSuggest: function()
	{
		new Ajax.Autocompleter('q', 'arts_suggest', '/search.php', {parameters: 'action=suggest&maxRes=10', minChars: 3, frequency: 0.1});
	},

	functionsSuggest: function(_sec)
	{
		new Ajax.Autocompleter('query', 'functions_suggest', '/search.php', {parameters: 'action=suggest&section=' + _sec + '', minChars: 1, frequency: 0.1});
	}
};