function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
	  retValue = retValue.substring(0, retValue.length - 1);
	  ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

function conta_caratteri(conta, mostra)	{
	mostra.value="["+conta.value.length+"]";
	}

function ControllaGB()
{
	frm = document.forms['MyForm'];
	sMsg2 = "";
	email_reg_exp=/^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if(trim(frm.Nomiagio.value)=="")
	{
		sMsg2 = sMsg2 + " * Nomiâgio\n";
	}
	smail=trim(frm.EMail.value);
	if(smail=="")
	{
		sMsg2 = sMsg2 + " * E-Mail\n";
	} else if (!email_reg_exp.test(smail)) {
		sMsg2 = sMsg2 + " * E-Mail (méttighe 'na Mail corètta!)\n";
	}

	if(trim(frm.Comento.value)=="")
	{
		sMsg2 = sMsg2 + " * Coménto\n";
	} else {
		var messaggio=trim(frm.Comento.value);
		if (messaggio.length > 1000)
			sMsg2 = sMsg2 + " * O teu Coménto o l'é ciù lóngo de 1000 caràteri!\n";
	}
	
	if(sMsg2!="")
	{
		sMsg2 = "Sti cànpi chi sótta són obligatöi ma no són stæti conpilæ bén:\n\n" + sMsg2 + "\n";
		alert(sMsg2);
	}
	else
	{
		frm.submit();
		return (true);
	}

}

