// JavaScript Document

function checkRequestAQuoteForm(form) {
	var name = trimString(form.name.value);
	form.name.value = name;
	var email = trimString(form.email.value);
	form.email.value = email;
	var code = trimString(form.recaptcha_response_field.value);
	
	if (name == "") {
		alert("Please enter your name.");
		return false;
	}
	if (email == "") {
		alert("Please enter your e-mail address.");
		return false;
	}
	if (emailCheck(email) == false)
		return false;
	if (code == "") {
		alert("Please enter security code");
		return false;
	}

	return true;
}
//---------------------------------------------------------------

/*
	Removes the spaces from begin of string and from end.
	It means, if string is "  string   " it makes "string"
	Params:
		str string [string witch need to check]
*/
function trimString (str) {

	while (str.charAt(0) == ' ')
		str = str.substring(1);
	while (str.charAt(str.length - 1) == ' ')
		str = str.substring(0, str.length - 1);

	return str;
}
//---------------------------------------------------------------

function emailCheck(email) {
	if (email.indexOf('@', 0) == -1) {
		alert("Please enter a valid email address.");
		return false;
	}
	
	if (email.indexOf('.', 0) == -1) {
		alert("Please enter a valid email address.");
		return false;
	}
	
	if (email.length<7) {
		alert("Email address too short.");
		return false;
	}
	
	return true;
}
//---------------------------------------------------------------

