function formValidation(){
if (testField('name') && testField('company') && testField('phone') && testField('city') && testField('email'))
{
submitForm(document.forms["form1"])
//alert ("valid");
}

else{
document.getElementById('errormessage').style.display = '';
//alert ("invalid");
}

}

function testField(element){
var nonWS;
var fieldValue;
	if (element != 'email')
	{
		fieldValue = document.getElementById(element).value;
		nonWS = fieldValue.replace(/^\s*|\s*$/g,'');

		if(fieldValue != '' && nonWS.length != 0)
			return true;
		else 
			return false;
	}
	else{
		fieldValue = document.getElementById(element).value;
		nonWS = fieldValue.replace(/^\s*|\s*$/g,'');

		if(fieldValue == '' && nonWS.length == 0)
			return true;
		else{
		if (validateEmail(element))
			return true;
		else
			return false;
		}
		
	}
} 

function validateEmail(element){
var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
str = document.getElementById(element).value;
if(str.match(emailRegEx)){
return true;
}
else{
return false;
}
}

function submitForm(theform) {
  var status = AjaxRequest.submit(
    theform
    ,{
      'onSuccess':function(req){ 
		//alert(req.responseText); 
		document.getElementById('errormessage').style.display = 'none';
		document.getElementById('oform').style.display = 'none';
		document.getElementById('confirmation').style.display = '';
		
}
    }
  );
  return status;
}