function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}

function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}

function trim(str) {
	return ltrim(rtrim(str));
}

function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function sendContactForm(lang_str){
	modulo = document.contact_us;
	
	if(trim(modulo.ragione_sociale.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Ragione Sociale' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Company' is required!";
		}
		alert(str_error);
		modulo.ragione_sociale.focus();
		return false;
	}
	
	if(trim(modulo.richiedente.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Richiedente' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Company' is required!";
		}
		alert(str_error);
		modulo.richiedente.focus();
		return false;
	}

	/*if(trim(modulo.email.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Email' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Email' is required!";
		}
		alert(str_error);
		modulo.email.focus();
		return false;
	}
	
	if(trim(modulo.indirizzo.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Indirizzo' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Address' is required!";
		}
		alert(str_error);
		modulo.indirizzo.focus();
		return false;
	}
	
	if(trim(modulo.citta.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Città' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'City' is required!";
		}
		alert(str_error);
		modulo.citta.focus();
		return false;
	}
	
	if(trim(modulo.cap.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'CAP' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Zip Code' is required!";
		}
		alert(str_error);
		modulo.cap.focus();
		return false;
	}
	
	if(trim(modulo.provincia.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Provincia' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Country' is required!";
		}
		alert(str_error);
		modulo.provincia.focus();
		return false;
	}*/
	
	if(trim(modulo.telefono.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Telefono' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Telephone' is required!";
		}
		alert(str_error);
		modulo.telefono.focus();
		return false;
	}
	
	/*if(trim(modulo.fax.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Fax' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Fax' is required!";
		}
		alert(str_error);
		modulo.fax.focus();
		return false;
	}
	
	if(trim(modulo.tipo_cavo.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Tipo Cavo' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Cable Type' is required!";
		}
		alert(str_error);
		modulo.tipo_cavo.focus();
		return false;
	}
	
	if(trim(modulo.t_isolamento.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Tensione d\' isolamento' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Rated voltage' is required!";
		}
		alert(str_error);
		modulo.t_isolamento.focus();
		return false;
	}
	
	if(trim(modulo.metri.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Metri' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Quantity' is required!";
		}
		alert(str_error);
		modulo.metri.focus();
		return false;
	}
	
	if(trim(modulo.imballo.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Imballo' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Packing' is required!";
		}
		alert(str_error);
		modulo.imballo.focus();
		return false;
	}
	
	if(trim(modulo.formazione.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Formazione' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Formation' is required!";
		}
		alert(str_error);
		modulo.formazione.focus();
		return false;
	}
	
	if(trim(modulo.m_isolamento.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Materiale Isolamento' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Insulation Material' is required!";
		}
		alert(str_error);
		modulo.m_isolamento.focus();
		return false;
	}
	
	if(trim(modulo.colore_conduttori.value) == ""){
		if(lang_str == "ita"){
			str_error = "Il campo 'Colore conduttori' è obbligatorio!"; 
		}
		else{
			str_error = "The field 'Color of conductors' is required!";
		}
		alert(str_error);
		modulo.colore_conduttori.focus();
		return false;
	}*/
	
	modulo.submit();
}


