function confirmLink(theLink,lang)
{
    	if(lang=="it"){
		var is_confirmed = confirm('Vuoi cancellare questa informazione?\n');
	}else{
		var is_confirmed = confirm('Are you sure to delete this information?\n');
	}	
    	
    if (is_confirmed) {
        theLink.href += '';
    }

    return is_confirmed;
}

function Submitedge(edge)
{
      this.document.pages.edge.value = edge;
      this.document.pages.submit();
}

function checkDate(datefield,lang){
	// var pattern = new RegExp([0-3][0-9]-0|1[0-9]-19|20[0-9]{2});
	var pattern = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
	
	if (document.getElementById(datefield).value.search(pattern) == -1) {
	//if(document.getElementById(datefield).value.match(pattern))
	//{
		if(lang=="it"){
			alert("Inserisci la data in formato GG/MM/AAAA");
		}else{
			alert("You have to insert the date as DD/MM/YYYY");
		}
		return false;
	}
		var date_array = document.getElementById(datefield).value.split('/');
		if(date_array[2].length != 4 ){
			if(lang=="it"){
				alert("La data non e' corretta.");
			}else{
				alert('Date is not correct!');
			}
			document.getElementById(datefield).style.backgroundColor="#FF0000";
			return false;
		}
	     var year = date_array[2];
	     // Attention! Javascript consider months in the range 0 - 11
	     // var month = date_array[1] - 1;
	     var month = date_array[1];
	     var day = date_array[0];
	     
	     var d = new Date();
		var curr_date = d.getDate();
		var curr_month = d.getMonth() + 1;
		var curr_year = d.getFullYear();
		
		var leap = 0;
		var err = 0;
	     //alert('today is '+curr_year+'-'+curr_month+'-'+curr_date+'');
	     
	     if( (year == curr_year) && ( month > curr_month ) || (year == curr_year) && ( month == curr_month ) && ( day > curr_date) )
	     {
	        	if(lang=="it"){
				alert("La data e' nel futuro.");
			}else{
				alert('Date is on the future!');
			}
			document.getElementById(datefield).style.backgroundColor="#FF0000";
	     	return false;
	     }
	     
	     if(year < 1900 || year > curr_year)
	     {
	        	if(lang=="it"){
				alert("L'anno non e' valido.");
			}else{
				alert('Year is not valid!');
			}
			document.getElementById(datefield).style.backgroundColor="#FF0000";
	     	return false;
	     }
	     
	     if(day > 31 || day < 1)
	     {
	        	if(lang=="it"){
				alert("Il giorno non e' valido.");
			}else{
				alert('Day is not valid!');
			}
			document.getElementById(datefield).style.backgroundColor="#FF0000";
	     	return false;
	     }
	     
	     if(month > 12 || month < 1)
	     {
	        	if(lang=="it"){
				alert("Il mese non e' valido.");
			}else{
				alert('Month is not valid!');
			}
			document.getElementById(datefield).style.backgroundColor="#FF0000";
	     	return false;
	     }
	     
	      /* Validation leap-year / february / day */
		if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
			leap = 1;
		}
		if ((month == 2) && (leap == 1) && (day > 29)) {
		     err = 23;
		}
		if ((month == 2) && (leap != 1) && (day > 28)) {
		     err = 24;
		}
		/* Validation of other months */
		if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		     err = 25;
		}
		if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		     err = 26;
		}
		
	     // This instruction will create a date object
	     /*
	     source_date = new Date(year,month,day);
	
	     if(month != source_date.getMonth())
	     {
	        alert('Month is not valid!');
	        return false;
	     }
	
	     if(day != source_date.getDate())
	     {
	        alert('Day is not valid!');
	        return false;
	     }
	     
	     if(year != source_date.getFullYear())
	     {
	        alert('Year is not valid!');
	        return false;
	     }
	     */
	//}else{
	if(err > 0){
	     if(lang=="it"){
			alert("La data non e' valida.");
		}else{
			alert('Date format is not valid!');
		}
	     document.getElementById(datefield).style.backgroundColor="#FF0000";
		//datefield.focus();
	     return false;
	}else{	
		return true;
	}
}
