function ReturnData(strData){
	var newDateObj = new Date("12/12/2001")
	var ArrData
	var strSplit
	var lngDay 
	var lngMonth
	var lngYear 

	if (strData.search("/")>= 0) {
			strSplit = "/"
		}
	else {
			strSplit = "-"
		}
				
	ArrData= strData.split(strSplit)

	lngDay = new Number(ArrData[0]);
	lngMonth = new Number(ArrData[1]);
	lngYear = new Number(ArrData[2]);
	lngMonth--
	
	newDateObj.setMonth(lngMonth)
	newDateObj.setYear(lngYear)
	newDateObj.setDate(lngDay)
	
	return newDateObj
}

function checkBoxControl(objSpan,objForm,intIndexCheck){
var i = 0
var strLang = ""
var strTag = ""
var strCheckId = ''
var objNode
var colCheck = objSpan.rows
var strForm = ''

//alert(colCheck.item(1).cells.item(1).childNodes.item(1).lang)


for (i = 1;i < colCheck.length;i++)
	{
		objNode = colCheck.item(i).cells.item(intIndexCheck).childNodes
		
		strTag = objNode.item(intIndexCheck).tagName
		strLang = objNode.item(intIndexCheck).lang
		strLang = strLang.toUpperCase()
		strCheckId = objNode.item(intIndexCheck).id
		//alert(strCheckId + strLang)
		if (strLang == 'CHECKOBBL')
			{
				
				strForm = objForm.id
				//alert(eval('document.' + strForm + '.' + strCheckId + '.checked'))
				if(eval('document.' + strForm + '.' + strCheckId + '.checked') == true){
					return true
				}
			}	
	}	
	i = colCheck.length //ESCE DAL CICLO
	alert('Occorre selezionare almeno una voce.')
	return false
}

function checkInput(objForm){
	var i
	var obj
	var strLang = ""
	var colForm = objForm.elements
	var strTag = ""
		
		
	for (i = 0;i < colForm.length;i++)
		{
		strTag = colForm.item(i).tagName
		strLang = colForm.item(i).lang
		strLang = strLang.toUpperCase()
		
		if (strTag != 'LABEL')
			{
			
			if (strLang.indexOf("OBBL",0) >= 0 && checkOBL(colForm.item(i)) == false)
				{
				alert('Non è stato inserito un campo obbligatorio.')
				colForm.item(i).focus()
				return false
				}
			if (strLang.indexOf("DATA",0) >= 0)
				{
				if (checkData(colForm.item(i).value) == false)
					{
					alert("Inserire la data nel formato gg/mm/aaaa.")
					colForm.item(i).focus()
					return false	
					}
				}
				
			if (strLang.indexOf("INTERO",0) >= 0)
				{
				if (checkIntero(Trim(colForm.item(i).value)) == false)
					{
					alert('Non è stato inserito un numero intero corretto.')
					colForm.item(i).focus()
					return false	
					}
				}
			}
			
			if (strLang.indexOf("DECIMALE",0) >= 0)
				{
				if (checkDecimale(Trim(colForm.item(i).value)) == false)
					{
					alert('Non è stato inserito un numero decimale corretto.')
					colForm.item(i).focus()
					return false	
					}
				}

		}	

	return true		
}		
	
function Trim(strStringa){
var strOut = ''

for (i = 0;i <= strStringa.length;i++)
{
	if (strStringa.substr(i,1) != ' ')
		{
		strOut = strStringa.substr(i,strStringa.length)
		i = strStringa.length
		}
}

for (i = strOut.length - 1;i >= 0;i--)
{
	if (strOut.substr(i,1) != ' '){
		strOut = strOut.substr(0,i + 1)
		i = 0
		}
}

return strOut

}


function checkOBL(objElem){

var strType = ''

strType = objElem.type
strType = strType.toUpperCase()

if (strType == "TEXTAREA"){
	if(Trim(objElem.innerText) == "")
		{
		return false
		}
	}
else{
	if(Trim(objElem.value) == ''){
		return false
		}
	}	
return true			
}

function checkIntero(strValore){
		if (strValore == "")
			{
			return true
			}
		else 
			{
			return (parseInt(strValore) == String(strValore))
			}
}

function checkDecimale(strValore){
	return ! isNaN(strValore) || (strValore == "")
}

function Salva(){
	if(checkInput(document.frmDettServizi)){
		alert('Tutto Apposito');
		
	}
	
}

function checkData(strValore) {
	var dtData;
	var BlnEsatta 
	var strData
	var i
	var lngYear
	var lngMonth
	var lngDay
	var lngMaxDay
	var strMonth
	var ArrData 
	var strSplit 	
	
	strValore = Trim(strValore)

	if (strValore == ''){
		return false;
	}
	
	if (strValore.search("/")>= 0) {
		strSplit = "/"
	}else{
		strSplit = "-"
	}
	
	ArrData = strValore.split(strSplit)
	BlnEsatta = true;
	strData = new String (strValore);
	dtData = new Date (strValore);
	
	// Se non è una data
	if (isNaN(dtData)){
		return false;
	}
		
	lngDay = new Number(ArrData[0]);
	lngMonth = new Number(ArrData[1]);
	lngYear = new Number(ArrData[2]);
	
	// Se non sono riuscito a reperire i giusti elementi della data
	if(isNaN(lngDay)||isNaN(lngMonth)||isNaN(lngYear)){
		return false ;
	}
	
	// Se il mese è maggiore di 12 
	if (lngMonth>12) {
		return false ;
	}
	
	// Ottengo il massimo numero di giorni del Mese
	switch(Number(lngMonth)) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			lngMaxDay = 31;
			break
		case 2:
			// Questo codice dovrebbe calcolare il giusto numero di giorni di Febbraio
			if (Number(parseInt(lngYear/4))==Number(lngYear/4)){
				lngMaxDay = 29;
			}else{
				lngMaxDay = 28;
			}
			break
		case 4:
		case 6:
		case 9:
		case 11:
			lngMaxDay = 30;
			break
	}
	
	// Controllo se il giorno è maggiore del massimo per il mese
	if (lngDay>lngMaxDay) {
		return false;
	}
	
	// Controllo se l'anno sta tra il 1900 ed il 2100
	if ((lngYear>2100)||(lngYear<1900)) {
		return false;
	}
	
	return true;
}