/*
//-------------------------//
//-- FUNZIONI AUSILIARIE --//
//-------------------------//
*/

function nl2br( str ) {
	return str.replace(/([^>])\n/g, '$1<br />\n');
}

function purge(d) {
	var a = d.attributes, i, l, n;
	if (a) {
		l = a.length;
		for (i = 0; i < l; i += 1) {
			n = a[i].name;
			if (typeof d[n] === 'function') {
				d[n] = null;
			}
		}
	}
	a = d.childNodes;
	if (a) {
		l = a.length;
		for (i = 0; i < l; i += 1) {
			purge(d.childNodes[i]);
		}
	}
}



Function.prototype.setScope = function(scope) {
	var f = this;
	return function() {
		f.apply(scope);
	}
}

/*
//---------------------------//
//-- FUNZIONE PER I COOKIE --//
//---------------------------//
*/
function setCookie(name, value) {
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 365 * 24 * 3600 * 1000);
	document.cookie = name+'='+escape(value)+'; expires=' + largeExpDate.toGMTString();
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1){
				end = document.cookie.length;
				return unescape(document.cookie.substring(offset));
			}
			else
				{
				return unescape(document.cookie.substring(offset, end));
			}
		}
	}
}

/*
//--------------------//
//-- XMLHttpRequest --//
//--------------------//
*/
// funzioni
function assegnaXMLHttpRequest() {
	var XHR = null,
	browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object"){
		XHR = new XMLHttpRequest();
	}
	else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0){
		if(browserUtente.indexOf("MSIE 5") < 0){
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		}
		else {
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return XHR;
}


