File: /home/uaktdz7o5l3q/public_html/spicenice/spicenice_web/postcode3.html
<!DOCTYPE html>
<html>
<head>
<title>Google Maps API v3 Example: Distance Matrix</title>
<script src="//maps.googleapis.com/maps/api/js?sensor=false"></script>
<!--script src="js/jspostcode.js"></script-->
<link href="css/formstyle.css" rel="stylesheet" type="text/css" />
<link href="css/css_main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<script src="http://maps.googleapis.com/maps/api/distancematrix/output?parameters" type="text/javascript"></script>
<script>
function postit(postcodecheck){ //check postcode format is valid
test =postcodecheck; size = test.length
test = test.toUpperCase(); //Change to uppercase
while (test.slice(0,1) == " ") //Strip leading spaces
{test = test.substr(1,size-1);size = test.length
}
while(test.slice(size-1,size)== " ") //Strip trailing spaces
{test = test.substr(0,size-1);size = test.length
}
//document.details.pcode.value = test; //write back to form field
if (size < 6 || size > 8){ //Code length rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode";
return false;
}
if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode";
return false;
}
if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode";
return false;
}
if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode"; //document.details.pcode.focus();
return false;
}
if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode"; // document.details.pcode.focus();
return false;
}
if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode"; //document.details.pcode.focus();
return false;
}
count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
if (count1 != count2){//only one space rule
document.getElementById('outputDiv').innerHTML =test + " is not a valid postcode"; //document.details.pcode.focus();
return false;
}
calculateDistances(postcodecheck+' UK');
return true;
}
// End -->
</script>
<script>
// var map;
var geocoder;
var bounds = new google.maps.LatLngBounds();
var markersArray = [];
var origin1 = new google.maps.LatLng(51.36505,-0.090181);
//var destinationIcon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=D|FF0000|000000";
//var originIcon = "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=O|FFFF00|000000";
function initialize() {
geocoder = new google.maps.Geocoder();
}
function calculateDistances(destinationA) {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin1],
destinations: [destinationA],
travelMode: google.maps.TravelMode.DRIVING,
unitSystem: google.maps.UnitSystem.IMPERIAL,
avoidHighways: false,
avoidTolls: false
}, callback);
}
function callback(response, status) {
if (status != google.maps.DistanceMatrixStatus.OK) {
alert('Error was: ' + status);
} else {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
var outputDiv = document.getElementById('outputDiv');
outputDiv.innerHTML = '';
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
if (results[j].distance.value<=3924) {
outputDiv.innerHTML +="Spice.N.Ice will deliver to your address as you are"
+ ": " + results[j].distance.text + " away <br />";
}
else
{
outputDiv.innerHTML += "Spice.N.Ice does NOT deliver to your address"
+ ": " + results[j].distance.text + " If you place an order please come in to collect from our restaurant";
}
}
}
}
}
</script>
<SCRIPT TYPE="text/javascript">
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
if (keycode == 13)
{
postit(document.forms[0].address2.value);
return false;
}
else
return true;
}
//-->
</SCRIPT>
<script type="text/JavaScript">
function clearBox(thebox)
{
thebox.value = "";
document.getElementById('outputDiv').innerHTML = "";
}
</SCRIPT>
</head>
<body id="cBackground" onload="initialize()" >
<form class="myform" action="#" >
<div id="divform">
<div id="lsearch">
<input id="spostcode" style="text-transform:uppercase;" type="text" name="address2" value="ENTER POSTCODE" class="address_input" data-validate="validate('spostcode') on(keyup focus)" onclick="clearBox(this)" onKeyPress="return submitenter(this,event)" />
</div>
<div id="rsearch" class="submit">
<input id="btncheck" type="button" name="find" value="Check" onclick="postit(document.forms[0].address2.value)"/>
<!--//"calculateDistances(document.forms[0].address2.value+' UK');" -->
</div>
</div>
<div id="outputDiv">Please enter a valid UK postcode to check if we
deliver to your address</div>
</form>
</body>
</html>