// Load Enquiry Form
function load_enq_form() {
	var select_removal='';
	var select_pruning='';
	var select_tsg='';
	var select_trsr='';
	var select_hct='';
	var select_mulch='';
	var select_arborist='';
	if(location.pathname=='/tree-removal.html') select_removal=' selected';
	if(location.pathname=='/tree-pruning.html') select_pruning=' selected';
	if(location.pathname=='/tree-stump-grinding.html') select_tsg=' selected';
	if(location.pathname=='/tree-stump-removal.html') select_trsr=' selected';
	if(location.pathname=='/hedge-trimming.html') select_hct=' selected';
	if(location.pathname=='/taylors-mulch.html') select_mulch=' selected';
	if(location.pathname=='/arborist-services.html') select_arborist=' selected';

	if($('enq_form')) {
		$('enq_form').update('\
						<div class="box_top">\
							<span>Get a Free Online Quote</span>\
						</div>\
\
						<div class="box_middle">\
							<form onsubmit="return validate_enq();" class="enquiry" method="post" action="enquiry.php">\
								<table cellspacing="0" cellpadding="0" border="0">\
									<tr>\
										<td class="row">* Name:</td>\
										<td>\
											<input value="" id="name" name="name" size="18">\
										</td>\
									</tr>\
									<tr>\
										<td class="row">* E-mail:</td>\
										<td>\
											<input value="" id="email" name="email" size="18">\
										</td>\
									</tr>\
									<tr>\
										<td class="row">* Phone:</td>\
										<td>\
											<input value="" id="phone" name="phone" size="18">\
										</td>\
									</tr>\
									<tr>\
										<td class="row">* Address:</td>\
										<td>\
											<input value="" id="address" name="address" size="18">\
										</td>\
									</tr>\
									<tr>\
										<td colspan="2">\
											<BR>\
											Type of Service:\
										</td>\
									</tr>\
									<tr>\
										<td colspan="2">\
											<select name="service" onchange="if(this.value==\'Mulch Sales\') { $(\'mulch\').show(); $(\'m\').value=1; } else { $(\'mulch\').hide(); $(\'m\').value=0; }">\
												<option value="">Please Select</option>\
												<option value="Tree Removal"'+select_removal+'>Tree Removal</option>\
												<option value="Tree Pruning"'+select_pruning+'>Tree Pruning</option>\
												<option value="Tree and Stump Grinding"'+select_tsg+'>Tree &amp; Stump Grinding</option>\
												<option value="Tree Root and Stump Removal"'+select_trsr+'>Tree Root and Stump Removal</option>\
												<option value="Hedge Cutting and Trimming"'+select_hct+'>Hedge Cutting &amp; Trimming</option>\
												<option value="Mulch Sales"'+select_mulch+'>Mulch Sales</option>\
												<option value="Arborist Services"'+select_arborist+'>Arborist Services</option>\
											</select>\
										</td>\
									</tr>\
									<tr id="mulch" style="display:none;">\
										<td colspan="2">\
											Mulch<BR>\
											<select name="mulch">\
												<option value="25 cubic metres - $385(incl GST)">25 cubic metres - $385(incl GST)</option>\
												<option value="15 cubic metres - $275(incl GST)">15 cubic metres - $275(incl GST)</option>\
												<option value="7 cubic metres - $165(incl GST)">7 cubic metres - $165(incl GST)</option>\
											</select>\
										</td>\
									</tr>\
									<tr>\
										<td colspan="2">\
											<BR>\
											Details / Questions:\
										</td>\
									</tr>\
									<tr>\
										<td colspan="2">\
											<textarea name="comments"></textarea>\
										</td>\
									</tr>\
									<tr>\
										<td colspan="2">\
											<BR>\
											<center>\
												<input type="image" title="Submit" value="Submit" src="images/submit_button.gif">\
												<input type="hidden" value="submit" id="mode" name="mode">\
												<input type="hidden" id="m" value="0" name="m">\
											</center>\
										</td>\
									</tr>\
								</table>\
							</form>\
						</div>\
		');
	}
}

// Validate Enquiry Form
function validate_enq() {
	var name = document.getElementById( "name" );
	var email = document.getElementById( "email" );
	var phone = document.getElementById( "phone" );
	
	var sError = "";
	if ( name.value.length == 0 ) {
		sError += "Please enter your contact name.\n";
	}

	// Validate Email
	if ( email.value.length == 0 ) {
		sError += "Please enter your email address.\n";
	} else {

		var str = email.value;
		var patt1 = new RegExp("^[a-z][a-zA-Z0-9_.-]*@[a-zA-Z0-9_.-]+\.[a-z]{2,4}$");
		var result = patt1.test(str);
		if ( !result ) {
			sError += "The email is not valid.\n";
		}
	}

	// Validate Phone
	if ( phone.value.length == 0 ) {
		sError += "Please enter your telephone number.\n";
	} else {

		var str = phone.value;
		var newphone = str.replace(/(\s|\(|\)|-)/gi, "");
		var patt1 = new RegExp("[0-9]{10}");
		var result = patt1.test(newphone);
		if ( !result ) {
			sError += "Please include the phone number area code.\n";
			phone.select();
		}
	}

	if ( sError.length == 0 ) {
		return true;
	}
	else {
		alert( sError );
		return false;
	}
}


Event.observe(window, 'load', function() {

	load_enq_form();


});