function setStatusBar(msgStr) { self.status = msgStr; }
setStatusBar("MOVINGBOX | Sound * Productions *");

//funzione per inserire solo numeri in una casella di testo
function CheckNumericPress() {
if ((event.keyCode>=48 && event.keyCode<=57) || event.keyCode==46 || (event.keyCode >= 43 && event.keyCode <= 45) || event.keyCode==27) {
	return true;
}
else {
	event.returnValue = false;
	return false;
	}
}

//funzione per inserire solo numeri in una casella di testo
function DigitaSoloNumeri() {
if ((event.keyCode>=48 && event.keyCode<=57)) {
	return true;
}
else {
	event.returnValue = false;
	return false;
	}
}

//funzione per sostituire un valore stringa vuoto con uno 0 in caso di input text numerico
function CheckZero() {
	if (event.srcElement.value == "" ) {
		event.srcElement.value = 0 ;
	}
}

function checkSubmit(Msg) {
	if (Msg != "")
		window.alert (Msg) ;
	else {
		doSubmit() ;
	}
}

function doSubmit() {
	doSubmitForm("DataForm") ;
}

function checkSubmitForm(Msg, Form) {
	if (Msg != "")
		window.alert (Msg) ;
	else {
		doSubmitForm(Form) ;
	}
}

function doSubmitForm(FormName) {
	var Form = window.document.getElementById(FormName) ;
	if (Form) {
		var Submitted = Form.Submitted ;
		if (Submitted != null) {
			Submitted.value = "1" ;
		}
		Form.submit();
	}
}

function checkLen (stringa, iMaxLength) {
/*
 restituisce:
 - true se la lunghezza della stringa passata è maggiore indicato dal parametro iMaxLength
 - false se è minore o uguale
*/
//debugger
	if (stringa.length + 0 > iMaxLength) {
		return true ;
	}
	else {
		return false ;
	}

}

function controlObjValueLen (obj, iMaxLength) {
// controlla che il valore del campo passato non superi il nimero di caratteri indicato dal parametro iMaxLength
// da chiamare sulla onkeypress e sulla on paste dell' oggetto
//debugger
	if (obj) {
		if (checkLen (obj.value, iMaxLength)) {
			alert ("Attenzione!\nIl valore del campo indicato non può superare " + iMaxLength + " caratteri!") ;
			obj.focus() ;
			//togliere ultimo carattere inserito
		}
	}
}

function checkRequiredFields (strField, strErr) {
// controllo che il campo inserito non abbia valore null
	//debugger;
	if (strErr == "") {
		var InputToCheck = document.getElementById(strField) ;
		//alert (InputToCheck.name + InputToCheck.value) ;
		if (InputToCheck.value == "" || InputToCheck == "undefined") {
				if ((InputToCheck.disabled==false) && (InputToCheck.readOnly==false) && (InputToCheck.type != "hidden")) {
					InputToCheck.focus() ;
				}
				return "Attenzione, il campo " + strField + " e' obbligatorio!";
			}
		else
			return strErr ;
		}
	else {
		return strErr ;
	}
}


function ReturnFieldValue (strField) {
// ritorno il valore del campo strField
	//debugger;
	var InputToCheck = document.getElementById(strField) ;
	if (InputToCheck) {
		//alert (InputToCheck.name + InputToCheck.value) ;
		if (InputToCheck.value == "" || InputToCheck == "undefined") {
				return "" ;
			}
		else
			return InputToCheck.value ;
		}
	else {
		return "" ;
	}
}

function AreBothEmptyOrBothNot (Stringa1, Stringa2) {
// ritorno true se entrambe le stringhe passate sono vuote o piene
	//debugger;

	if (AreBothEmpty (Stringa1, Stringa2)) {
		return true ;
	}
	else {
		if (Stringa1 != "" && Stringa2 != "") {
			return true ;
		}
		else {
			return false ;
		}
	}

}

function AreBothEmpty (Stringa1, Stringa2) {
// ritorno true se entrambe le stringhe passate sono vuote o piene
	//debugger;

	if (Stringa1 == "" && Stringa2 == "") {
		return true ;
	}
	else {
		return false ;
	}

}

function checkRequiredObj (objToCheck, strErr) {
// controllo che il campo inserito non abbia valore null
// objToCheck --> oggetto
	//debugger;
	if (strErr == "") {
		//alert (InputToCheck.name + InputToCheck.value) ;
		if (objToCheck) {
			if (objToCheck.value == "" || objToCheck == "undefined") {
				if ((objToCheck.disabled==false) && (objToCheck.readOnly==false) && (objToCheck.type != "hidden")) {
					objToCheck.focus() ;
				}
				return "Attenzione, il campo " + objToCheck.name + " e' obbligatorio!";
			}
			else {
				return strErr ;
			}
		}
		else {
			return strErr ;
		}
	}
	else {
		return strErr ;
	}
}

function ChangeValue() {
	if (window.event.srcElement.value == "0") 	{
		window.event.srcElement.value = "1" ;
	}
	else {
		window.event.srcElement.value ="0" ;
	}
	//alert (window.event.srcElement.value) ;
}

function checkEmail (Email) {
// Controllo la validità dell' indirizzo e-mail inserito
	var msg = "" ;

	// Espressione regolare per un indirizzo email
	var Controlla = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if (Email != "" && Email != "undefined") {
		if (!Controlla.test(Email)) {
			msg = "L' indirizzo email inserito non e' valido!"
		}
	}
	//if (Email == "" || Email == "undefined") {
	//	msg = "E' necessario inserire un indirizzo email!"
	//}

	if (msg != "") {
		alert (msg) ;
		return false ;
	}
	else {
		return true ;
	}
}

function CheckPartitaIva(PartitaIVA) {
	J= 0;
	for (I=0;I<10;I++) {
		if ((I%2) == 0)
			J += parseInt(PartitaIVA.charAt(I))
		else {
			T = 2 * parseInt(PartitaIVA.charAt(I));
			J += (T%10) + ((T-(T%10))/10) ;      //cifre delle unità e delle decine
		}
	}
	if (J%10 == 0)
		return (0 == parseInt(PartitaIVA.charAt(10)))
	else
		return ((10 - (J%10)) == parseInt(PartitaIVA.charAt(10)));
}

/*Mostra calendario*/
function ShowDate(inputText) {
	var wrkStr ;
	var wrkObj = document.getElementsByName(inputText);
	var CalendarPath = "../Date/Calendar.asp" ;
	//alert ("Percorso=" + CalendarPath) ;
	if (!wrkObj[0].disabled) {
		wrkStr = window.showModalDialog(CalendarPath,"","dialogWidth:312px;dialogHeight:400px") ;
		//window.open(CalendarPath,null,"height=400,width=400,status=yes,toolbar=no,menubar=no,location=no");


		if (wrkStr)
		{
			wrkObj[0].value = wrkStr ;
		}
		wrkObj[0].focus() ;
	}
}

/***************************************************************
Funzioni di controllo della validità della data
***************************************************************/

function checkValidDate() {
//Controlla validità data
	//debugger
	var DateToCheck = event.srcElement ;
	var sDay
	var sMonth
	var sYear
	var sDate
	var arDate
	
	sDate = DateToCheck.value.toString() ;
	if (sDate != "") {

		sDate = FormatDate (sDate) ;

		if (sDate != "") {
			arDate = sDate.split("/") ;
			if (arDate.length == 3) {
				sDay = arDate[0] ;
				sMonth = arDate[1] ;
				sYear = arDate[2] ;
				if (!(isValidDayOfMonth(sDay, sMonth, sYear))) {
					NotValidDate(DateToCheck) ;
				}
			}
		}
		else {
			NotValidDate(DateToCheck) ;
		}
	}
}

function NotValidDate(objNotValid) {
	var Msg = "Attenzione!\nData non valida!"
	alert (Msg) ;
	objNotValid.value = "" ;
	objNotValid.focus () ;
}

function FormatDate(timeStr) {
/* Funzione di formattazione della data*/

	var date;
	var dd,mm,yyyy;
	var timePat = /^(\d{1,2})\D?(\d{1,2})\D?(\d{4})$/;
	
	var matchArray = timeStr.match(timePat);
	if (matchArray == null) {
		return "";
	}
	
	dd		= matchArray[1];
	mm		= matchArray[2];
	yyyy	= matchArray[3];

	if (dd.length < 2){ dd = "0" + dd; }
	if (mm.length < 2){ mm = "0" + mm; }
	date = dd + "/" + mm + "/" + yyyy;
	if (date == "") date="";
	return date;
}

function isLeapYear(year) {
	// is it leap year ? returns a boolean
	return ( (0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))); 
	// ie, if the year divides by 4, but not by 100 except when it divides by
	// 400, it is leap year
}

function isValidDayOfMonth(day, month, year) { 
	// determines whether a day is valid 
	// (ie, prevents Feb 30 from being processed) 
	// ( not used but left here for other pages that use 
	// this calendar, like the time-off request form ) 
	// 
	var leapdays = new Array(31,29,31, 30,31,30, 31,31,30, 31,30,31); 
	var yeardays = new Array(31,28,31, 30,31,30, 31,31,30, 31,30,31); 

	if (day <= 0) { return false; }
	if (isLeapYear(year)) { return (day <= leapdays[month-1])}
	return ( day <= yeardays[month-1]); 
}

/***************************************************************
Fine Funzioni di controllo della validità della data
***************************************************************/

// eliminazione fisica dati dal DB
function DeleteItem (Table, KeyField, KeyValue, KeyType, PageName) {
// Param contiene gli uteriori parametri da aggiungere alla Querystring di PageToOpen
	var PageToOpen ;
	var RetValue ;
	var Param ;
	
	Param = "?Table=" + Table + "&KeyField=" + KeyField + "&KeyValue=" + KeyValue + "&KeyType=" + KeyType ;

	PageToOpen = "../Utils/Delete.asp" ;

	RetValue = window.showModalDialog(PageToOpen + Param,"","dialogWidth:250px;dialogHeight:150px;status:no") ;

	//alert ("RetValue=" + RetValue ) ;
	if (RetValue) {
		PageToOpen = "../Utils/Delete.asp" ;
		Param = Param + "&conferma=si&Page=" + PageName ;
		window.navigate(PageToOpen + Param) ;
	}
}

function CheckTextAreaLength (oObj, MaxLength) {
	if (oObj) {
		if (oObj.innerHTML.length > MaxLength) {
			alert("Il testo inserito è troppo lungo!\nIl campo può contenere al massimo " + MaxLength.toString() + " caratteri!") ;
			oObj.focus() ;
		}
	}
}
