
// --------------------------------------------------- 	
// Funzione di servizio x visualizzare l'errore   	
// --------------------------------------------------- 	

	function Display_error( Form_name, input_element, div_error_id,  message ) {	
		
		//var closebut_html = '<!--  <div style="position: absolute; right: 4px; top: 2px;"><a href="#">x</a></div> -->';
		var closebut_html = ' <u>Chiudi</u>';
		
		$( "div#" + div_error_id ).fadeIn( 100, 
			function(){
				$( "div#" + div_error_id ).empty().append( message + closebut_html ).fadeIn( 100, 
					function(){
						$( "div#" + div_error_id + "" ).hover( 
							function() {
								$( this ).css( "cursor", "pointer" );
							},
							function() {
								$( this ).css( "cursor", "default" );
							});
						
						$( "div#" + div_error_id + "" ).click(
							function(){
								$( "div#" + div_error_id ).empty().fadeOut( 100 );
								Form_name.elements[ input_element ].focus();
								return ( false );
							});
						// End {"click close"}
					});
				// End {"fadeIn MSG"}
			});
		// End {"fadeIn Slert box"}({
	}
	
// --------------------------------------------------- 	



// --------------------------------------------------- 	
// CheckEmail( e-mail )
// - return: {1 = ok}, {0 = non valida}
// - Non ammette e-mail vuota 
// - ex reg.expr: ^\w+((\+\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.([A-Za-z0-9])([A-Za-z0-9]?)([A-Za-z0-9]?)$
// --------------------------------------------------- 	
	function CheckEmail( my_email ) {	
		if ( my_email.search( /^[a-z0-9._-]+\@[a-z0-9._-]+\.[a-z]{2,4}$/ ) < 0 ) {
			return 0;
		} else {
			return 1;
		}		
	}
// --------------------------------------------------- 







// --------------------------------------------------- 	
// CHECK CONTACTS FORM  	
// (utilizza 'Display_error')
// --------------------------------------------------- 	
	
	function Form_Validator( theForm ) {	

		var error_div = 'formContactsCheck';
		
		// Nome
		if ( theForm.elements[ 'item_field[firstname]' ].value == "" ) {
			Display_error( theForm, 'item_field[firstname]', error_div, "<b>Attenzione!</b> Nome non valido o mancante." );
			return ( false );
		}
		// Nome //
		
		// Cognome
		if ( theForm.elements[ 'item_field[lastname]' ].value == "" ) {
			Display_error( theForm, 'item_field[lastname]', error_div, "<b>Attenzione!</b> Cognome non valido o mancante." );
			return ( false );
		}
		// Cognome //
		
		// E-mail
		if ( ( CheckEmail( theForm.elements[ 'item_field[email]' ].value ) == 0 )/* || ( theForm.elements[ 'item_field[email]' ].value == "" ) */) {  
			Display_error( theForm, 'item_field[email]', error_div, "<b>Attenzione!</b> E-mail non valida o mancante." );
			return ( false );
		}
		// E-mail //		
		
		// Città
		if ( theForm.elements[ 'item_field[city]' ].value == "" ) {
			Display_error( theForm, 'item_field[city]', error_div, "<b>Attenzione!</b> Città non valida o mancante." );
			return ( false );
		}
		// Città //
		
		// Telefono
		if ( theForm.elements[ 'item_field[telephone]' ].value == "" ) {
			Display_error( theForm, 'item_field[telephone]', error_div, "<b>Attenzione!</b> Telefono non valido o mancante." );
			return ( false );
		}
		// Telefono //
		
		
		// Marca e modello
		if ( ( theForm.elements[ 'marcaid' ].value == "0" ) || ( theForm.elements[ 'modelloid' ].value == "0" ) ) {
			Display_error( theForm, 'marcaid', error_div, "<b>Attenzione!</b> Selezionare la marca e il modello." );
			return ( false );
		}
		// Marca e modello //
		
		
		if ( ( theForm.elements[ 'get_itemid' ].value == "0" ) ) {
			// Controllo attivo solo se non è già selezionato un articolo in particolare //
			// Codice
			if ( ( theForm.elements[ 'ricambio' ].value == "ALTRO" ) && ( theForm.elements[ 'altro' ].value == "" ) ) {
				Display_error( theForm, 'altro', error_div, "<b>Attenzione!</b> Specificare il tipo di ricambio non in elenco." );
				return ( false );
			}
			// Codice //
		}
		
		
		// Messaggio
		if ( theForm.elements[ 'messaggio' ].value == "" ) {
			Display_error( theForm, 'messaggio', error_div, "<b>Attenzione!</b> Messaggio mancante." );
			return ( false );
		}
		// Messaggio //	
		
		$( 'div#overlayer' ).fadeIn( 200, 
			function() {	
				//$( 'div#pagePopUp-close' ).remove();
				var newMarginTop = $( 'body' ).scrollTop() + 50;
				var p = { marginTop: newMarginTop + "px" };
				
				$( 'div#pagePopUp-inner' ).empty().animate( p, 10, 
					function() {
						//$( 'div#pagePopUp-close' ).remove();
						$( 'div#pagePopUp-inner' ).append( '<div style="width: 100%; height: 80px; background-color: #fff;"><div id="loadingPage"> ...<b>Invio in corso</b>... </div></div>' );
						$( 'div#pagePopUp' ).fadeIn( 100, 
							function() {
								//
							});
						// End {"fadeIn pagePopUp"} 
					});
				// End {"animate"} 	
			});
		// End {"fadeIn overlayer"} 	
		
		$( '#ContactsForm input:hidden[name=okForm]' ).attr( 'value', '1' );
		
		//theForm.okForm.value = true;
		//alert(theForm.okForm.value);
		return ( true );
		
	}
// --------------------------------------------------- 	
// --------------------------------------------------- 




// --------------------------------------------------- 	
// SEARCH FORM  	
// --------------------------------------------------- 	
	
	var keyword_min_code = 2;	
	//var keyword_min_keyword = 3;	
	
	function Search_Validator( theForm ) {	

		var closebut_html = ' <div style="position: absolute; left: -12px; top: -2px;"><a href="#">x</a></div>';
		
		// Search String
		//var radio_word_checked = ( $('#src_mode-word').attr( 'checked' ) != undefined ) ? $('#src_mode-word').attr( 'checked' ) : false;
		//var radio_code_checked = ( $('#src_mode-code').attr( 'checked' ) != undefined ) ? $('#src_mode-code').attr( 'checked' ) : false;
		
		//if ( !radio_word_checked && radio_code_checked ) {
			// Caso di ricerca per codice prodotto //
			var keyword_min = keyword_min_code;
		//} else {
			// Caso di ricerca per parola chiave //
		//	var keyword_min = keyword_min_keyword;	
		//}
		
		//alert( keyword_min );return ( false );
		if ( theForm.elements[ 'src_code' ].value.length < keyword_min ) {
			
			$( "div#formSearchCheck" ).fadeIn( 100, 
				function(){
					$( "div#formSearchCheck" ).empty().append( '<b>Attenzione!</b> La chiave di ricerca è troppo corta.' + closebut_html ).fadeIn( 100, 
						function(){
							theForm.elements[ 'src_code' ].focus();
							$( "div#formSearchCheck a" ).click(
								function(){
									$( "div#formSearchCheck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}
			
			return ( false );
		}			
		// Search String //
		
		theForm.okForm.value = true;
		ClickLoading();
		return (true);
	}

	
	function SearchSpecial_Validator( theForm, errorDiv ) {	

		var keyword_min = keyword_min_code;
		//var error_div = 'formSearchSpecialCheck';
		var error_div = errorDiv;
		
		// Codice // 
		if ( theForm.elements[ 'src_code' ].value.length < keyword_min ) {
			theForm.elements[ 'src_code' ].value = 'Attenzione! La chiave di ricerca è troppo corta.';
			theForm.elements[ 'src_code' ].focus();
			
			//Display_error( theForm, 'src_string', error_div, "<b>Attenzione!</b> il codice inserito è troppo corto." );
			return ( false );
		}
		// Codice //
		
		theForm.okForm.value = true;
		ClickLoadingHard();
		return (true);
	}
	
	
	
	// Search HP 
	function SearchHP_Validator( theForm, modo ) {	

		if ( modo == 'auto' ) {
			
			var error_div = 'formSearchAutoCheck';
			
			// Marca //
			//alert( keyword_min );return ( false );
			if ( theForm.elements[ 'marcaid' ].value == 0 ) {
				
				Display_error( theForm, 'marcaid', error_div, "<b>Attenzione!</b> si prega di scegliere la marca." );
				return ( false );
			}			
			// Marca //
		
			// Modello //
			if ( theForm.elements[ 'modelloid' ].value == 0 ) {
				Display_error( theForm, 'modelloid', error_div, "<b>Attenzione!</b> si prega di scegliere il modello." );
				return ( false );
			}
			// Modello //
			
			// Reset Src_String //
			if ( theForm.elements[ 'src_string' ].value == formHPdefaultTxt ) {
				theForm.elements[ 'src_string' ].value = '';
			}
			// Reset Src_String //
		
		
		}
		
		if ( modo == 'targa' ) {
		
			var error_div = 'formSearchTargaCheck';
			
			// targa //
			if ( ( theForm.elements[ 'src_targa' ].value.length < 7 ) || ( theForm.elements[ 'src_targa' ].value.length > 12 ) ) {
				Display_error( theForm, 'src_targa', error_div, "<b>Attenzione!</b> la lunghezza della targa immessa potrebbe non essere corretta." );
				return ( false );
			}
			// targa //
		
		}
		
		if ( modo == 'code' ) {
		
			var error_div = 'formSearchCodiceCheck';
			
			// !!!!! VEDERE keyword_min_code PIU' SU !!!!! 
			
			// codice //
			if ( theForm.elements[ 'src_code' ].value.length < keyword_min_code ) {
				Display_error( theForm, 'src_code', error_div, "<b>Attenzione!</b> La chiave di ricerca è troppo corta." );
				return ( false );
			}
			if ( theForm.elements[ 'src_code' ].value == 'codice o sigla' ) {
				Display_error( theForm, 'src_code', error_div, "<b>Attenzione!</b> inserire un codice valido." );
				return ( false );
			}
			// codice //
		
		}
		
		theForm.elements[ 'okForm' ].value = true;
		ClickLoadingHard();
		return (true);
	}
	
	
	function SearchTarga_Validator( theForm ) {	

		var error_div = 'formSearchTargaCheck';
		
		// targa //
		if ( ( theForm.elements[ 'src_targa' ].value.length < 7 ) || ( theForm.elements[ 'src_targa' ].value.length > 12 ) ) {
			Display_error( theForm, 'src_targa', error_div, "<b>Attenzione!</b> la lunghezza della targa immessa potrebbe non essere corretta." );
			return ( false );
		}
		// targa //
		
		theForm.elements[ 'okForm' ].value = true;
		ClickLoadingHard();
		return (true);
	}
	
// --------------------------------------------------- 	
// --------------------------------------------------- 






// --------------------------------------------------- 	
// CHECK LOGIN FORM  	
// --------------------------------------------------- 	
	
	function Login_Validator( theForm, errorDiv ) {	

		var closebut_html = ' <div style="position: absolute; right: -12px; top: -2px;"><a href="#">x</a></div>';
		
		// Username
		if ( ( theForm.elements[ 'ck_username' ].value == "" ) || ( theForm.elements[ 'ck_username' ].value == "email" ) ) {
			
			$( "div#" + errorDiv ).fadeIn( 100, 
				function(){
					$( "div#" + errorDiv ).empty().append( '<b>Attenzione!</b> Inserire l\'indirizzo e-mail con cui ci si è registrati.' + closebut_html ).fadeIn( 100, 
						function(){
							theForm.elements[ 'ck_username' ].focus();
							$( "div#" + errorDiv + " a" ).click(
								function(){
									$( "div#" + errorDiv ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}({
			
			return ( false );
		}
		// Username //
		
		// Password
		if ( theForm.elements[ 'ck_password' ].value == "" ) {
			
			$( "div#" + errorDiv ).fadeIn( 100, 
				function(){
					$( "div#" + errorDiv ).empty().append( '<b>Attenzione!</b> Inserire la PASSWORD.' + closebut_html ).fadeIn( 100, 
						function(){
							theForm.elements[ 'ck_password' ].focus();
							$( "div#" + errorDiv + " a" ).click(
								function(){
									$( "div#" + errorDiv ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}({
			
			return ( false );
		}
		// Password //
				
		
								// !!!!! TEMPORANEA !!!!!
								// !!!!! TEMPORANEA !!!!!
								/*$( "div#formLoginCheck" ).fadeIn( 100, 
									function(){
										$( "div#formLoginCheck" ).empty().append( '<b>:--) SPIACENTI!</b> Siamo ancora in fase di lavorazione!' + closebut_html  ).fadeIn( 100, 
											function(){
												theForm.elements[ 'ck_password' ].focus();
												$( "div#formLoginCheck a" ).click(
													function(){
														$( "div#formLoginCheck" ).empty().fadeOut( 100 );
													});
												// End {"click close"}
											});
										// End {"fadeIn MSG"}
									});
								// End {"fadeIn Slert box"}({
								
								return ( false );*/
								// !!!!! TEMPORANEA !!!!!
								// !!!!! TEMPORANEA !!!!!
		
		
		theForm.okForm.value = true;
		return (true);
	}
	
	function Password_Validator( theForm ) {	

		var error_div = 'formContactsCheck';
		
		// E-mail
		if ( CheckEmail( theForm.elements[ 'email_rem' ].value.replace( /^\s+|\s+$/g, '' ) ) == 0 ) {
			Display_error( theForm, 'email_rem', error_div, "<b>Attenzione!</b> E-mail non valida o mancante." );
			return ( false );
		}
		// E-mail //	
		
		$( 'div#overlayer' ).fadeIn( 200, 
			function() {	
				//$( 'div#pagePopUp-close' ).remove();
				var newMarginTop = $( 'body' ).scrollTop() + 50;
				var p = { marginTop: newMarginTop + "px" };
				
				$( 'div#pagePopUp-inner' ).empty().animate( p, 10, 
					function() {
						//$( 'div#pagePopUp-close' ).remove();
						$( 'div#pagePopUp-inner' ).append( '<div style="width: 100%; height: 80px; background-color: #fff;"><div id="loadingPage"> ...<b>Invio in corso</b>... </div></div>' );
						$( 'div#pagePopUp' ).fadeIn( 100, 
							function() {
								//
							});
						// End {"fadeIn pagePopUp"} 
					});
				// End {"animate"} 	
			});
		// End {"fadeIn overlayer"} 	
		
		theForm.okForm.value = true;
		return ( true );
		
	}
	/*
	function Password_Validator( theForm ) {	

		// Email
		if ( CheckEmail( theForm.elements[ 'email_rem' ].value ) == 0 ) {
		//if ( ( !( theForm.elements[ 'email_rem' ].value.search(/^\w+((\+\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.([A-Za-z0-9])([A-Za-z0-9]?)([A-Za-z0-9]?)$/)!= -1)) || ( theForm.elements[ 'email_rem' ].value == "" ) ) {  
			
			var closebut_html = ' <div style="position: absolute; right: 4px; top: 2px;"><a href="#">x</a></div>';
		
			$( "div#formLoginCheck" ).fadeIn( 100, 
				function(){
					$( "div#formLoginCheck" ).empty().append( '<b>Attenzione!</b> E-MAIL inserita non valida! ' + closebut_html ).fadeIn( 100, 
						function(){
							theForm.elements[ 'email_rem' ].focus();
							$( "div#formLoginCheck a" ).click(
								function(){
									$( "div#formLoginCheck" ).empty().fadeOut( 100 );
								});
							// End {"click close"}
						});
					// End {"fadeIn MSG"}
				});
			// End {"fadeIn Slert box"}({
			
			return ( false );
		}
		// Email //
						
		theForm.okForm.value = true;
		return (true);
	}*/
// --------------------------------------------------- 	
// --------------------------------------------------- 




// --------------------------------------------------- 	
// --------------------------------------------------- 
// CHECK CART FORM  	
// - Vale sia per la form nel listing che per qella in dettagli
// - Se il "rel" dell'input è "GOMME" forza la quantità 
//   ad essere un numero pari
// --------------------------------------------------- 	
// --------------------------------------------------- 
	
	function CartTo_Validator( myFormId, myItemID ) {
		
		var myForm = $( '#' + myFormId );
		var message_ckCode = 'ATTENZIONE!\n\nVerificare di aver consultato la scheda prodotto e confrontato i codici articolo con il codice stampato nel ricambio da sostituire. \n\nQuesti tipi di articolo non possono essere ordinati in base alla sola descrizione. \n\nOrdini errati perchè con codici diversi saranno da ritenersi a carico del compratore. \n\nInserire nel carrello?';
		//var message_ckCode = 'ATTENZIONE!\n\nVerificare che il codice stampato sul vostro ricambio sia identico al codice del nostro. \nIl codice articolo può essere il codice del ricambio. \n\nQuesti tipi di articolo non possono essere ordinati in base alla sola descrizione. \n\nOrdini errati perchè con codici diversi saranno da ritenersi a carico del compratore.';
		
		if ( $( '#' + myFormId + ' :input[name=whichForm]').val() == 'details' ) {
			var myInputQty = 'edit-qty-' + myItemID + 'det';
		} else {
			var myInputQty = 'edit-qty-' + myItemID;
		}
		
		var myNum = $( '#' + myFormId + ' #' + myInputQty ).val();
		
		if ( myNum == '' || myNum == '0' || myNum == '00' || isNaN( myNum ) ) {
			alert( 'ATTENZIONE!\nInserire un numero valido.' );
			//myForm.elements[ 'qty['+ myItemID + ']' ].focus();
			$( '#edit-qty-' + myItemID ).focus().val( '1' );
			return ( false );
		} else {			
			if ( ( $( '#' + myInputQty ).attr( 'rel' ) == 'gomme' ) && ( myNum % 2 ) ) {
				alert( 'ATTENZIONE!\nQuesto articolo può essere acquistato solo a coppie.' );
				$( '#' + myInputQty ).focus().val( parseInt( myNum ) + parseInt( myNum % 2 ) );
				return ( false );
			} else {
				if ( $( '#' + myInputQty ).attr( 'rel' ) == 'butAlert' ) {
					if ( window.confirm( message_ckCode ) ) {
						$( '#' + myFormId + ' input[name="okForm"]' ).val( 'true' );
						return ( true );		
					} else {
						return ( false );				
					}
				}
				$( '#' + myFormId + ' input[name="okForm"]' ).val( 'true' );
				return ( true );	
			}
		}
		return ( false );
	}

// --------------------------------------------------- 	
// --------------------------------------------------- 





// --------------------------------------------------- 	
// Order Options Validator  	
// --------------------------------------------------- 	
function Order_Validator() {
	
	var error_div = 'formContactsCheck';
	var error_msg = '';
	var theForm = document.forms.FormOrderCheck;
	
	var grandTotal = $( '#FormOrderCheck input:hidden[name=grandTotal] ' ).val();
	//alert(grandTotal);
	
	if ( ( grandTotal == '#' ) || ( grandTotal == undefined ) || ( grandTotal == 0 ) || ( grandTotal == '' ) ) {
		error_msg = 'Attenzione! Dati mancanti.';
		$( '#areaShippingCharges' ).empty().html( '<div style="width: 100%; line-height: 30px; color: red; font-weight: bold; text-align: center;">' + error_msg + '</div>' );
		Display_error( theForm, 'edit-privacy', error_div, error_msg );
		return ( false );
	}

if ( ( $( '#FormOrderCheck #edit-ritiro-sede' ).attr( 'checked' ) == false ) && ( $( '#FormOrderCheck input[name=shippingid]' ).val() == undefined ) ) { 
	//alert($( '#FormOrderCheck input:radio[name=shippingid]' ).val());
	error_msg = 'Attenzione! Selezionare la destinazione della merce.';
	//$( '#areaShippingCharges' ).empty().html( '<div style="width: 100%; line-height: 30px; color: red; font-weight: bold; text-align: center;">' + error_msg + '</div>' );
	Display_error( theForm, 'edit-privacy', error_div, error_msg );
	return ( false );
}
//alert($( '#FormOrderCheck input:radio[name=shippingid]' ).val());
//return ( false );
	
	if ( ( $( '#FormOrderCheck #edit-cd_porto-assegnato' ).attr( 'checked' ) == true ) && ( $( '#FormOrderCheck #corriere_pa' ).attr( 'value' ) == '' ) ) {
		error_msg = 'Attenzione! Indicare il Corriere Espresso a cui siete abbonati.';
		//$( '#areaShippingCharges' ).empty().html( '<div style="width: 100%; line-height: 30px; color: red; font-weight: bold; text-align: center;">' + error_msg + '</div>' );
		Display_error( theForm, 'corriere_pa', error_div, error_msg );
		return ( false );
	}	
	
	if ( ( $( '#FormOrderCheck #edit-privacy' ).attr( 'checked' ) == false ) || ( $( '#FormOrderCheck #edit-condizioni' ).attr( 'checked' ) == false ) ) {
		error_msg = 'Attenzione! E\' obbligatorio accettare le condizioni di vendita e informativa sulla privacy.';
		//$( '#areaShippingCharges' ).empty().html( '<div style="width: 100%; line-height: 30px; color: red; font-weight: bold; text-align: center;">' + error_msg + '</div>' );
		Display_error( theForm, 'edit-privacy', error_div, error_msg );
		
		return ( false );
	}	
	
	
	
	
	$( 'div#overlayer' ).fadeIn( 200, 
		function() {	
			//$( 'div#pagePopUp-close' ).remove();
			var newMarginTop = $( 'body' ).scrollTop() + 50;
			var p = { marginTop: newMarginTop + "px" };
			
			$( 'div#pagePopUp-inner' ).empty().animate( p, 10, 
				function() {
					//$( 'div#pagePopUp-close' ).remove();
					$( 'div#pagePopUp-inner' ).append( '<div style="width: 100%; height: 80px; background-color: #fff;"><div id="loadingPage"> ...<b>Elaborazione corso</b>... </div></div>' );
					$( 'div#pagePopUp' ).fadeIn( 100, 
						function() {
							//
						});
					// End {"fadeIn pagePopUp"} 
				});
			// End {"animate"} 	
		});
	// End {"fadeIn overlayer"} 			
	
	return ( true );

	/*
	if ( ( grandTotal == '#' ) || ( grandTotal == undefined ) || ( grandTotal == 0 ) || ( grandTotal == '' ) ) {
		$( '#areaShippingCharges' ).empty().html( '<div style="width: 100%; line-height: 30px; color: red; font-weight: bold; text-align: center;">Attenzione! Dati mancanti.</div>' );
		return ( false );
	} else {
		
		$( 'div#overlayer' ).fadeIn( 200, 
			function() {	
				//$( 'div#pagePopUp-close' ).remove();
				var newMarginTop = $( 'body' ).scrollTop() + 50;
				var p = { marginTop: newMarginTop + "px" };
				
				$( 'div#pagePopUp-inner' ).empty().animate( p, 10, 
					function() {
						//$( 'div#pagePopUp-close' ).remove();
						$( 'div#pagePopUp-inner' ).append( '<div style="width: 100%; height: 80px; background-color: #fff;"><div id="loadingPage"> ...<b>Elaborazione corso</b>... </div></div>' );
						$( 'div#pagePopUp' ).fadeIn( 100, 
							function() {
								//
							});
						// End {"fadeIn pagePopUp"} 
					});
				// End {"animate"} 	
			});
		// End {"fadeIn overlayer"} 			
		
		
		return ( true );
	}*/
}
// --------------------------------------------------- 	




// --------------------------------------------------- 	
// CHECK INFO FORM  	
// (utilizza 'Display_error')
// --------------------------------------------------- 	
	
	function Info_Validator( theForm ) {	

		var error_div = 'formContactsCheck';
		
		// Nome
		if ( theForm.elements[ 'info_nome' ].value == "" ) {
			Display_error( theForm, 'info_nome', error_div, "<b>Attenzione!</b> Nome non valido o mancante." );
			return ( false );
		}
		// Nome //
				
		// E-mail
		if ( CheckEmail( theForm.elements[ 'info_email' ].value ) == 0 ) {
			Display_error( theForm, 'info_email', error_div, "<b>Attenzione!</b> E-mail non valida o mancante." );
			return ( false );
		}
		// E-mail //		
		
		// Oggetto
		if ( theForm.elements[ 'info_oggetto' ].value == "" ) {
			Display_error( theForm, 'info_oggetto', error_div, "<b>Attenzione!</b> Oggetto non valido o mancante." );
			return ( false );
		}
		// Oggetto //
		
		
		// Messaggio
		if ( theForm.elements[ 'messaggio' ].value == "" ) {
			Display_error( theForm, 'messaggio', error_div, "<b>Attenzione!</b> Messaggio mancante." );
			return ( false );
		}
		// Messaggio //	
		
		$( 'div#overlayer' ).fadeIn( 200, 
			function() {	
				//$( 'div#pagePopUp-close' ).remove();
				var newMarginTop = $( 'body' ).scrollTop() + 50;
				var p = { marginTop: newMarginTop + "px" };
				
				$( 'div#pagePopUp-inner' ).empty().animate( p, 10, 
					function() {
						//$( 'div#pagePopUp-close' ).remove();
						$( 'div#pagePopUp-inner' ).append( '<div style="width: 100%; height: 80px; background-color: #fff;"><div id="loadingPage"> ...<b>Invio in corso</b>... </div></div>' );
						$( 'div#pagePopUp' ).fadeIn( 100, 
							function() {
								//
							});
						// End {"fadeIn pagePopUp"} 
					});
				// End {"animate"} 	
			});
		// End {"fadeIn overlayer"} 	
		
		$( '#InfoForm input:hidden[name=okForm]' ).attr( 'value', '1' );
		
		//theForm.okForm.value = true;
		//alert(theForm.okForm.value);
		return ( true );
		
	}
// --------------------------------------------------- 	
// --------------------------------------------------- 


// --------------------------------------------------------
// Controllo P.IVA e COD.FISC. (prese dal vecchio sito)
// --------------------------------------------------------
function ControllaCF( cf ) {
	var validi, i, s, set1, set2, setpari, setdisp;
	if ( cf == '' ) {
		return '<b>Attenzione!</b> Codice Fiscale non valido o mancante.';
	}
	
	cf = cf.toUpperCase();
	
	if ( cf.length != 16 ) {
	    return "<b>Attenzione!</b> La lunghezza del codice fiscale non è corretta: il codice fiscale dovrebbe essere lungo esattamente 16 caratteri o essere uguale alla P.Iva..";
	}
	/*
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	
	for ( i = 0; i < 16; i++ ) {
	    if ( validi.indexOf( cf.charAt(i) ) == -1 ) {
	        return "<b>Attenzione!</b> Il codice fiscale contiene il carattere <b>" + cf.charAt(i) + "</b> non valido.<br>Inserire solo lettere e cifre.";
		}
	}
	
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	
	for ( i = 1; i <= 13; i += 2 ) {
	    s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	}
	for ( i = 0; i <= 14; i += 2 ) {
	    s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	}
	if ( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ) {
	    return "<b>Attenzione!</b> Il codice fiscale non è corretto: il codice di controllo non corrisponde.";
	}
	*/
	return "";
}

function ControllaPIVA( pi ) {
	if ( pi == '' ) {
		return '<b>Attenzione!</b> Partita Iva non valida o mancante.';
	}
	if ( pi.length != 11 ) {
	    return "<b>Attenzione!</b> La lunghezza della partita IVA non è corretta: la partita IVA è composta da 11 caratteri";
	}
	/*
	validi = "0123456789";
	for ( i = 0; i < 11; i++ ) {
	    if ( validi.indexOf( pi.charAt(i) ) == -1 ) {
			return "<b>Attenzione!</b> La partita IVA contiene il carattere <b>" + pi.charAt(i) + "</b> non valido. <br>Inserire solo cifre.";
		}
	}
	s = 0;
	for ( i = 0; i <= 9; i += 2 ) {
	    s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	}
	for ( i = 1; i <= 9; i += 2 ) {
	    c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
	    if( c > 9 )  c = c - 9;
	    s += c;
	}
	if ( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) {
	    return "<b>Attenzione!</b> La partita IVA non è valida: il codice di controllo non corrisponde.";
	}*/
	return "";
}
// --------------------------------------------------------







