// create the prototype on the String object
String.prototype.trim = function() {
 // skip leading and trailing whitespace
 // and return everything in between
  return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

// Funzione per la validazione di una email
function checkMail(sMail){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	return filter.test(sMail)
}

var MINUTE = 60 * 1000
var HOUR = MINUTE * 60
var DAY = HOUR * 24
var WEEK = DAY * 7

function addDays(myDate,days) {
    days = parseInt(days);     
    var mDate = new Date(myDate);
    var dt = new Date(mDate.getTime() + days*DAY);     
//    var st = (dt.getMonth()+1) + "/" + dt.getDate() + "/"  +  dt.getFullYear();     
    return dt;     
}

function convertDate(aDate){
	var yy = aDate.slice(0,4);
	var mm = aDate.slice(5,7);
	var dd = aDate.slice(8,10);
	return new Date(yy,mm-1,dd);
}

function verifyDate(aDate,sMsg,iFlag){

	if ((aDate.value.trim() == "") && !iFlag){
		return false;
	}
	
	if (aDate.value.trim() == ""){
		alert(sMsg);
		aDate.focus()
		return true;
	} 

	// Verifico che la data sia valida.

//	var aTestDate = new Date(aDate.value);
	var aTestDate = convertDate(aDate.value);
	if (isNaN(aTestDate)){
		alert("Inserire la data in formato corretto")
		aDate.focus()
		return true;
	}
	
}


