// JavaScript Document
// Enquiry form validation

//function Blank_TextField_Validator()
function validateStandard () 
 {

// for company name field  
if (document.enquiry.company_name.value == "") 
{
// If null display and alert box
alert("Please fill in the company name field.");
// Place the cursor on the field for revision
document.enquiry.company_name.focus();
// return false to stop further processing
return (false);
}


//for Length field
if (document.enquiry.length.value == "")
{
alert("Please fill in the building length field.");
document.enquiry.length.focus();
return (false);
}


// for width field
if (document.enquiry.width.value == "")
{
alert("Please fill in the building width field.");
document.enquiry.width.focus();
return (false);
}


// for building height field
if (document.enquiry.height.value == "")
{
alert("Please fill in the building height field.");
document.enquiry.height.focus();
return (false);
}


// for brick wall height field
if (document.enquiry.brick_wall_height.value == "")
{
alert("Please fill in the brick wall height field.");
document.enquiry.brick_wall_height.focus();
return (false);
}

// for radio button
if ( ( document.enquiry.brick_wall_thickness[0].checked == false ) && ( document.enquiry.brick_wall_thickness[1].checked == false ) ) 
{
	alert ( "Please choose brick wall thickness 5 inch or 10 inch" ); 
	return false; 
}


// For Name field
if (document.enquiry.name.value == "")
{
alert("Please fill in the contact name field.");
document.enquiry.name.focus();
return (false);
}


// For Address field
if (document.enquiry.address.value == "")
{
alert("Please fill in the address field.");
document.enquiry.address.focus();
return (false);
}


// For Phone no field
if (document.enquiry.phone_number.value == "")
{
alert("Please fill in the phone number field.");
document.enquiry.phone_number.focus();
return (false);
}
if (document.enquiry.phone_number.value !== "")  // Phone number format check
{
var stripped = document.enquiry.phone_number.value.replace(/[\(\)\.\-\ ]/g, ''); 
if (isNaN(parseInt(stripped))) {
      alert("The Phone number contains illegal characters.");
	document.enquiry.phone_number.focus();
return (false);
}	
}



//For Email Address field
if (document.enquiry.email_address.value == "")
{
alert("Please fill in the email address field.");
document.enquiry.email_address.focus();
return (false);
}

if (document.enquiry.email_address.value !== "")   // Email address format check
{
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 var address = document.enquiry.email_address.value;
 
   if(reg.test(address) == false) 
   {
      alert('Email address is invalid format');
      return false;
   }
}


// For Comments About Enquiry field
//if (document.enquiry.comments.value == "")
//{

//alert("Please fill in the comments about enquiry  field.");
//document.enquiry.comments.focus();
//return (false);
//}

return (true);
 }

