//Javascript designed by Darcy Broda; Darcy owns all the copyrights to this site, its design and code-->
function validate() {
	var fobjc;
	fobjc = 'document.contact';
	if (fobjc.name.value.length===0){
		alert('Please fill in your name.');
		fobjc.name.focus();
		return false;
	} 
	if (fobjc.email.value.length===0){
		alert('Please fill in your email.');
		fobjc.email.focus();
		return false;
	}
	
	var filter = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (!filter.test(fobjc.email.value)) {
		alert('Invalid Email, Please fill in your email address.');
		fobjc.email.focus();
		return false;
	} 
	
	if (fobjc.subject.value.length===0){
		alert('Please fill in a subject for your message.');
		fobjc.subject.focus();
		return false;
	}
	if (fobjc.comments.value.length===0){
		alert('Please enter your comments.');
		fobjc.comments.focus();
		return false;
	}
	
	if (fobjc.captcha.value.length===0){
		alert('Please fill out the form validation.\nIt is case-sensitive, please double check or refresh the captcha.');
		fobjc.captcha.focus();
		return false;
	}
	return true;
}

function validatequote() {
	var formobj;
	formobj = document.requestquote;
	if (formobj.name.value.length===0){
		alert('Please fill in your name.');
		formobj.name.focus();
		return false;
	}
	if (formobj.email.value.length===0){
		alert('Please fill in your email.');
		formobj.email.focus();
		return false;
	}
	var filter = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (!filter.test(formobj.email.value)) {
		alert('Invalid email, please fill in your email address.');
		formobj.email.focus();
		return false;
	} 
//<?php
//$tests = array( "314-555-4000",
//           "800-555-4400",
//           "(314)555-4000",
//           "314.555.4000",
//           "555-4000",
//           "aasdklfjklas",
//           "1234-123-12345"
//          );
//
//$regex = "/
//            \(?     # optional parentheses
//              \d{3} # area code
//            \)?     # optional parentheses
//            [-\s.]? # separator is either a dash, a space, or a period.
//              \d{3} # 3-digit prefix
//            [-\s.]  # another separator
//              \d{4} # 4-digit line number
//           /x";
//
//foreach ($tests as $test) {
//    if (preg_match($regex, $test)) { 
//        echo "Matched on $test<br />";
//    }
//    else {
//        echo "Failed match on $test<br />";
//     }
//}
//?>
	if (isNaN(formobj.phone.value) || (formobj.phone.value.length<10)){
		alert('Please fill in your phone number.\n It must contain 10 digits.');
		formobj.phone.focus();
		return false;
	}
	if (formobj.address.value.length===0){
		alert('Please fill in your address.');
		formobj.address.focus();
		return false;
	}
	if (formobj.postalcode.value.length===0){
		alert('Please fill in your postal code.');
		formobj.postalcode.focus();
		return false;
	}
	var pcode = /^[A-Z]\d[A-Z]\d[A-Z]\d$/i;
	if (!pcode.test(formobj.postalcode.value)){
		alert('Invalid postal code, please re-enter your postal code.');
		formobj.postalcode.focus();
		return false;
	}
	if (formobj.city.value.length===0){
		alert('Please select your city.');
		formobj.city.focus();
		return false;
	}
	if (formobj.medium.value.length===0){
		alert('We\'d love to know how you heard about us, please select from the dropdown menu.');
		formobj.medium.focus();
		return false;
	}
	if (!formobj.interior.checked && !formobj.exterior.checked && !formobj.commercial.checked && !formobj.strata.checked) {
		alert('Please select at least one service.');
		return false;
	}
	if (formobj.captcha.value.length===0){
		alert('Please fill out the form validation.\nIt is case-sensitive, please double check or refresh the captcha.');
		formobj.captcha.focus();
		return false;
	}
	return true;
}
function doPopups() {
	if (!document.getElementsByTagName) {return false};
	var links = document.getElementsByTagName('a');
	for (var i=0; i<links.length; i++) {
		if (links[i].className.match('popup')){
			links[i].onclick = function() {
				window.open(this.href,'PrivacyPolicy','width=400,height=600,toolbar=no,resizable=no,scrollbars=no,status=no,menubar=no');
				return false;
			}
			return false;
		}
	}
}
window.onload = doPopups;