/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Element.addMethods({
	createElement: function(appendTo, elementType, elementOptions)
	{
		var element = document.createElement(elementType);
		var optionsArray = [Object.keys(elementOptions), Object.values(elementOptions)];

		for (var i = 0; i <= (optionsArray).size(); i++)
		{
			var name = optionsArray[0][i], value = optionsArray[1][i];

			if (String(name).indexOf('style_') != -1)
			{
				name = name.replace('style_', 'style.');
			}

			if (typeof value == 'function')
			{
				eval('element.' + name + ' = ' + value + ';');
			}
			else
			{
				eval('element.' + name + ' = "' + value + '";');
			}
		}

		if (typeof appendTo != 'object') { appendTo = $(appendTo); }
		if (typeof appendTo == 'object' && appendTo)
		{
			appendTo.appendChild(element);
		}
		else
		{
			return false;
		}
	}
});

Object.extend(jaySite.global, {
	getClientDimension: function()
	{
		var _width = self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
		var _height = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
		return { width: _width, height: _height };
	},

	getBodyWrapDiv: function(_id, _opacity)
	{
		if (_id == null || !$(_id)) { return false; }
		_opacity = _opacity || 5;

		$(_id).setStyle({display: 'block', position: 'fixed', zIndex: '99'});
		var bodySize = this.getClientDimension();

		$('bodywrap').setStyle({width: '' + bodySize.width + 'px', height: '' + bodySize.height + 'px', display: 'block', opacity: '' + (_opacity / 10) + ''});
		$(_id).setStyle({left: ((bodySize.width / 2) - ($(_id).offsetWidth / 2)) + 'px', top: ((bodySize.height / 2) - ($(_id).offsetHeight / 2)) + 'px'});
	},

	timeOut: function(time, id)
	{
		$(id).update(time);
		time--;
		if (time >= 0)
		{
			window.setTimeout(function() { jaySite.global.timeOut(time, id); }, 1000);
		}
	},

	lockFieldOnChars: function(numChars, w)
	{
		if (w.value.length > numChars)
		{
			alert('In questo campo <' + (w.name || w.id) + '> è consentito inserire massimo <' + numChars + '> caratteri.\nCaratteri inseriti: <' + w.value.length + '>');
			w.value = w.value.substr(0, numChars);
		}
	},

	expandDiv: function(percent, index)
	{
		var div_c = document.getElementById('expand_content_div');
		var div = document.getElementById('expand_div');
		index = index || 0;
	
		if (index == 0)
		{
			div.style.display = '';
		}
	
		index++;
		div.style.width = (Math.floor(div_c.style.width.replace('px', '') / 100 * index)) + 'px';
	
		if (index < percent)
		{
			window.setTimeout(function() { jaySite.global.expandDiv(percent, index); }, 20);
		}
	}
});
jaySite.global.checkGfxValue = Class.create();
jaySite.global.checkGfxValue.prototype = {
	initialize: function()
	{
		var me = this;
		var gfxCode = '';

		for (var i = 0; i < arguments.length; i++)
		{
			gfxCode += arguments[i];
		}

		$('submit').disabled = true;
		$('code').onkeyup = function()
		{
			me.check(gfxCode);
		}
	},

	check: function(gfxCode)
	{
		$('code').value = $F('code').toUpperCase();
		if ($F('code') == gfxCode)
		{
			$('submit').disabled = false;
		}
		else
		{
			$('submit').disabled = true;
		}
	}
};

jaySite.WindowOnLoad = Class.create();
jaySite.WindowOnLoad.prototype = {
	initialize: function()
	{
		this.bodyElement = document.getElementsByTagName('body')[0];

		//this.highlightIntBox();
		this.insertAjaxBottomElement();
	},

	highlightIntBox: function()
	{
		var rows = document.getElementsByTagName('div');

		$$('div.intbox_a', 'div.intbox_b').each(function(row)
		{
			row.onmouseover = function()
			{
				if (this.className != 'intbox_a_sel' || this.className != 'intbox_b_sel')
				{
					this.className += '_sel';
				}
			}
			row.onmouseout = function()
			{
				if (this.className != 'intbox_a_sel' || this.className != 'intbox_b_sel')
				{
					this.className = this.className.replace('_sel', '');
				}
			}
		});
	},

	insertAjaxBottomElement: function()
	{
		this.bodyElement = document.getElementsByTagName('body')[0];

		new Insertion.Bottom(this.bodyElement, '<div id="bodywrap" class="bodywrap"></div>');
		new Insertion.Bottom(this.bodyElement, '<div id="__ajaxLoadingDiv"></div>');
	}
};
function windowOnLoad()
{
	new jaySite.WindowOnLoad();
}

var Cookie = {
	set: function(name, value, expires, path, domain, secure)
	{
		var today = new Date();
		today.setTime(today.getTime());
		
		if (expires)
		{
			expires = expires * 1000 * 60 * 60 * 24;
		}
		
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = name + '=' + escape(value) +
		((expires) ? ';expires=' + expires_date.toGMTString() : '') + 
		((path) ? ';path=' + path : '') +
		((domain) ? ';domain=' + domain : '') +
		((secure) ? ';secure' : '');
	},

	get: function(name)
	{
		var start = document.cookie.indexOf(name + '=');
		var len = start + name.length + 1;
	
		if ((!start) && (name != document.cookie.substring(0, name.length)))
		{
			return null;
		}
	
		if (start == -1) return null;
		var end = document.cookie.indexOf(';', len);
		if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
	},

	Delete: function(name, path, domain)
	{
		if(this.get(name))
		{
			document.cookie = name + '=' +
			((path) ? ';path=' + path : '') +
			((domain) ? ';domain=' + domain : '') +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
		}
	}
};

var QueryString = {
	getFromJs: function(jsFile, selVar)
	{
		var _scriptsSrcList = document.getElementsByTagName('script');

		for (var i = 0; i < _scriptsSrcList.length; i++)
		{
			if (_scriptsSrcList[i].src.match(_jsFile))
			{
				var _theQueryString = _scriptsSrcList[i].src.match(/\?(.*)/);
				var _theQueryStringSplit = _theQueryString[1].split('&');
			}
		}

		var _QS = _theQueryStringSplit;
		var _queryStringArray = new Array();
	
		for (var x = 0; x < _QS.length; x++)
		{
			var _qsVal = _QS[x].split('=');
			_queryStringArray[_qsVal[0]] = decodeURIComponent(_qsVal[1]);
		}

		return (selVar ? _queryStringArray[selVar] : _queryStringArray);
	},

	getFromPage: function(selVar)
	{
		var _locationSearch = location.search;
		if (_locationSearch.length > 1)
		{
			_locationSearch = _locationSearch.substr(1);
		}

		var _theQueryStringSplit = _locationSearch.split('&');

		var _QS = _theQueryStringSplit;
		var _queryStringArray = new Array();
	
		for (var x = 0; x < _QS.length; x++)
		{
			var _qsVal = _QS[x].split('=');
			_queryStringArray[_qsVal[0]] = decodeURIComponent(_qsVal[1]);
		}

		return (selVar ? _queryStringArray[selVar] : _queryStringArray);
	}
};

function $Q()
{
	var jsFile = arguments[1] || false;

	if (jsFile == false)
	{
		return QueryString.getFromPage(arguments[0]);
	}
	else
	{
		return QueryString.getFromJs(jsFile, arguments[0]);
	}
}

function array_assoc(keys, values)
{
    if (keys.length != values.length) {
        return false;
    }
    
    var array = new Array();
    for (var i = 0; i <= keys.length; i++) {
        array[keys[i]] = values[i];
    }
    
    return array;
}
Array.prototype.assoc = function(values)
{
    return array_assoc(this, values);
}

/* FUNZIONI TEMPORANEE - INIZIO */
function toggleSegnalaForm(_selPage)
{
	_selPage = _selPage || '';

	if ($('bodywrap').getStyle('display') == 'none')
	{
		$('__ajaxLoadingDiv').setStyle({backgroundColor: '#FFFFFF', border: 'solid 1px #000000', width: '515px', height: '180px', padding: '5px', fontSize: '12px', textAlign: 'left'});

		jaySite.global.getBodyWrapDiv('__ajaxLoadingDiv', 6);

		$('__ajaxLoadingDiv').update('<div style="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;">' +
									 'Segnala questa pagina ad un amico<br /><a href="" style="font-size: 10px;" onclick="toggleSegnalaForm(); return false;">(Chiudi)</a></div>' +
									 '<iframe style="width: 515px; height: 130px; margin-top: 10px; margin-bottom: 10px; border: 0px;" src="http://www.jacoz.net/segnala/sito.html?frame=true&amp;p=' + _selPage + '" scrolling="no" frameborder="0"></iframe>');
	}
	else
	{
		new Effect.Shrink('__ajaxLoadingDiv');
		$('bodywrap').hide();
	}
}

function colorStars(num, imageid, img)
{
	for(var i = 1; i <= num; i++)
	{
		$('star_' + imageid + '_' + i).src = img;
	}
}

function set_FullStars(num, imageid)
{
	colorStars(num, imageid, 'http://static.jacoz.net/images/rate_staron.gif');
}

function set_EmptyStars(num, imageid)
{
	colorStars(num, imageid, 'http://static.jacoz.net/images/rate_staroff.gif');
}
/* FUNZIONI TEMPORANEE - FINE */


Event.observe(window, 'load', windowOnLoad, false);
