function ltrim(s)	{ return s.replace( /^\s*/, "" ); }	function rtrim(s)	{ return s.replace( /\s*$/, "" ); }	function trim(s){ 	alert(s);	return rtrim(ltrim(s)); }	var tErrString='';var tFieldsArray=[];function inspect(elm){	var str = "";	for (var i in elm){		str += i + ": " + elm.getAttribute(i) + "\n";		}	alert(str);	}		function dumpObj(obj, name, indent, depth) {	if (depth > 10) {	return indent + name + ": <Maximum Depth Reached>\n";	}	if (typeof obj == "object") {	var child = null;	var output = indent + name + "\n";	indent += "\t";	for (var item in obj)	{	try {	child = obj[item];	} catch (e) {	child = "<Unable to Evaluate>";	}	if (typeof child == "object") {	//output += dumpObj(child, item, indent, depth + 1);	output += indent + (typeof child) + ": " + child.name + "\n";	} else {	output += indent + item + ": " + child + "\n";	}	}	return output;	} else {	return obj;	}	}	function getNodeListValue(theObj){	var tValue='';	for (var i=0; i<theObj.length; i++){		try{			switch(theObj[i].type){				case "radio":				case "checkbox":					if (theObj[i].checked)						{tValue=theObj[i].value;}					break;				default:					if (theObj[i].value != "")						{tValue=theObj[i].value;}					break;				}			}		catch(tErr){			}		if (tValue!="")			break;		}	return tValue;	}	function checkField(theObj, theErrString, theBadValue){	var tOk=true;	//alert(theObj.type);	switch (theObj.type){		case "select-one":			tOk = (theObj.selectedIndex!=0);			break;		case "checkbox":		case "radio":			tOk=theObj.checked;			break;			var myForm=theObj.form;			var myName=theObj.name;			for (var i=0; i<myForm[myName].length; i++){				tOk = tOk || myForm[myName][i].checked;				}			break;		case "hidden":		case "password":		case "text":			tOk = (theObj.value!=theBadValue && theObj.value!='');			break;		default:			try{				var tValue= getNodeListValue(theObj);				//alert(tValue);				tOk = (tValue!='' || tValue==theBadValue);				}			catch(tryErr){				tOk = false;				}			//alert(dumpObj(theObj, "Object", "", 9));			break;		}	if (!tOk){		if (theErrString==''){			tErrString+="valore mancante: " + theObj.name + " - Missing value: " + theObj.name + "\n";			}		else{			tErrString+=theErrString + "\n";			}		//alert(tErrString);		}	return tErrString;	}	function checkForm(theForm){ 	checkField(theForm.name, "Manca il nome", "Nome");	checkField(theForm.surname, "Manca il cognome", "Cognome");	checkField(theForm.email, "Manca l'email");	checkField(theForm.email2, "Manca la conferma email");	checkField(theForm.newpass, "Manca la password");	checkField(theForm.newpass2, "Manca la conferma password");	checkField(theForm.annonascita, "Manca l'anno di nascita");	checkField(theForm.sex, "Indicare il sesso");	checkField(theForm.address, "Manca l'indirizzo", "Indirizzo");	checkField(theForm.streetnum, "Manca il n. civico", "n. civ.");	checkField(theForm.cap, "Manca il cap", "CAP");	checkField(theForm.town, "Manca il comune", "Comune");	checkField(theForm.provincia, "Manca la provincia", "Prov.");	tErrString=checkField(theForm.work, "Seleziona l'area professionale");	//alert('aaa');	//alert(tErrString);	if (!theForm.email.value.match(/^\S+\@[\w-]+\.[\w\.-]+$/)) {		tErrString+= "Indirizzo email non valido.\n";		}	if (theForm.email.value != theForm.email2.value) {		tErrString+= "Gli indirizzi email non corrispondono.\n";		}			if (theForm.newpass.value != theForm.newpass2.value) {		tErrString+= "Le password non corrispondono.\n";		}			// checkField(theForm.accettazione_condizioni, "E' necessario acconsentire alle condizioni di utilizzo.");	checkField(theForm.accettazione_informativa, "E' necessario acconsentire al trattamento dei dati.");		if (tErrString!=""){		alert(tErrString);		tErrString="";		return false;		}	return true;	}	function checkNewsletterForm(theForm){ 	tErrString='';	checkField(theForm.name, "Manca il nome", "Nome");	checkField(theForm.surname, "Manca il cognome", "Cognome");	checkField(theForm.sex, "Manca il sesso");	//alert(tErrString);	if (theForm.email.value.length == 0 || !theForm.email.value.match(/^\S+\@[\w-]+\.[\w\.-]+$/)) {		tErrString+= "Indirizzo email non  valido.\n";		}	if (theForm.email.value != theForm.email2.value) {		tErrString+= "Gli indirizzi email non corrispondono.\n";		}			checkField(theForm.accettazione_informativa, "E' necessario acconsentire al trattamento dei dati.");	if (tErrString!=""){		alert(tErrString);		return false;		}	return true;	}	function checkRegistrationForm(theForm){ 	tErrString='';		checkField(theForm.name, "Manca il nome", "Nome");	checkField(theForm.surname, "Manca il cognome", "Cognome");	checkField(theForm.address, "Manca l'indirizzo", "Indirizzo");	checkField(theForm.streetnum, "Manca il n. civico", "n. civ.");	checkField(theForm.cap, "Manca il cap", "CAP");	checkField(theForm.town, "Manca il comune", "Comune");	checkField(theForm.provincia, "Manca la provincia", "Prov.");	checkField(theForm.nation, "Manca la nazione");	checkField(theForm.sex, "Manca il sesso");	checkField(theForm.phone, "Manca il telefono", "+39");	//alert(tErrString);	if (theForm.email.value.length == 0 || !theForm.email.value.match(/^\S+\@[\w-]+\.[\w\.-]+$/)) {		tErrString+= "Indirizzo email non  valido.\n";		}	if (theForm.email.value != theForm.email2.value) {		tErrString+= "Gli indirizzi email non corrispondono.\n";		}			checkField(theForm.accettazione_informativa, "E' necessario acconsentire al trattamento dei dati.");	if (tErrString!=""){		alert(tErrString);		return false;		}	return true;	}	function checkPrenotazioneForm(theForm){ 	tErrString='';		checkField(theForm.name, "Manca il nome", "Nome");	checkField(theForm.surname, "Manca il cognome", "Cognome");	checkField(theForm.address, "Manca l'indirizzo", "Indirizzo");	checkField(theForm.streetnum, "Manca il n. civico", "n. civ.");	checkField(theForm.cap, "Manca il cap", "CAP");	checkField(theForm.town, "Manca il comune", "Comune");	checkField(theForm.provincia, "Manca la provincia", "Prov.");	checkField(theForm.nation, "Manca la nazione");	checkField(theForm.sex, "Manca il sesso");	checkField(theForm.phone, "Manca il telefono", "+39");	//alert(tErrString);	if (theForm.email.value.length == 0 || !theForm.email.value.match(/^\S+\@[\w-]+\.[\w\.-]+$/)) {		tErrString+= "Indirizzo email non  valido.\n";		}	if (theForm.email.value != theForm.email2.value) {		tErrString+= "Gli indirizzi email non corrispondono.\n";		}			if (tErrString!=""){		alert(tErrString);		return false;		}	return true;	}	function checkCreditCardForm(theForm){ 	tErrString='';		checkField(theForm.card_name, "Manca il nome", "Nome");	checkField(theForm.card_surname, "Manca il cognome", "Cognome");	checkField(theForm.card_kind, "Manca il tipo di carta di credito", "----");	checkField(theForm.card_number, "Manca il numero", "numero carta di credito");	checkField(theForm.card_month, "Manca mese di scadenza", "");	checkField(theForm.card_year, "manca l'anno di scadenza", "");	//alert(tErrString);	if (tErrString!=""){		alert(tErrString);		return false;		}	return true;	}	function checkStep2(theForm){ 	tErrString='';	var tOk=false;	for (var i=0; i<theForm.proposta.length; i++)		tOk = tOk || theForm.proposta[i].checked;	//alert(tOk);	if (!tOk){		alert("Selezionare una soluzione per favore.");		return false;		}	return true;	}	function checkPassword(theForm){ 	tErrString='';	var tPasswords=true;	checkField(theForm.password, "Manca la password", "password");	tPasswords=tPasswords && checkField(theForm.newpassword, "Manca la nuova password", "nuova password");	if (tPasswords)		tPasswords=tPasswords && checkField(theForm.reppassword, "Manca la password di controllo", "ripeti password");	if (tPasswords && (theForm.newpassword.value!=theForm.reppassword.value)) {		tErrString+= "Le nuove password inserite non corrispondono.\n";		}	if (tErrString!=""){		alert(tErrString);		return false;		}	return true;	}	
