//ESTESIONI FUNZIONI BASE JAVASCRIPT


function IsDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?

	if (matchArray == null) {
	return false;
	}
	month = matchArray[3]; // p@rse date into variables
	day = matchArray[1];
	year = matchArray[5];

	if (month < 1 || month > 12) { // check month range
	return false;
	}
	if (day < 1 || day > 31) {
	return false;
	}

	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	return false;
	}

	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {
	return false;
	}
	}
	return true; // date is valid
}
//FINE ESTESIONI FUNZIONI BASE JAVASCRIPT


//FUNZIONI UTILI A TUTTO IL SITO
function el(elemento)
{return document.getElementById(elemento)}

function cambiaClasse(elemento,classe)
{elemento.className=classe;return true;}


function assegnaStile(elemento,stile)
{
	elemento.className=stile;
}

//Funzione Generale pr il Suubmit di Form in AJAX
function c_SubmitForm(myForm,idSe,idSo)
{
new Ajax.Request(myForm.action,{method:"post", parameters:Form.serialize(myForm),
	onFailure: function(t) {alert('Error ' + t.status + ' -- ' + t.statusText +' ');},
	onComplete: function() {stampaIstanze(idSe,idSo);}});
}

function c_controlla_email(input){
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (Filtro.test(input))
		return true;
	else
		return false;
}

function startCallback(){
	// make something useful before submit (onStart)
	return true;
}

function completeCallback(response){
	// make something useful after (onComplete)
	document.getElementById('r').innerHTML = response;
}

AIM = {
	frame : function(c) {
		var n = 'f' + Math.floor(Math.random() * 99999);
		var d = document.createElement('DIV');
		d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
		document.body.appendChild(d);
		var i = document.getElementById(n);
		if (c && typeof(c.onComplete) == 'function') {
			i.onComplete = c.onComplete;
		}
		return n;
	},
	form : function(f, name) {
		f.setAttribute('target', name);
	},
	submit : function(f, c) {
		AIM.form(f, AIM.frame(c));
		if (c && typeof(c.onStart) == 'function') {
			return c.onStart();
		} else {
			return true;
		}
	},
	loaded : function(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} else {
			var d = window.frames[id].document;
		}
		if (d.location.href == "about:blank") {
			return;
		}
		if (typeof(i.onComplete) == 'function') {
			i.onComplete(d.body.innerHTML);
		}
	}
}

function trim(stringToTrim) {
 return stringToTrim.replace(/^\s+|\s+$/g,"");
}