<!--
		
var CONST_ACCOUNT = "CRITE11116"
var CONST_LICENSE = "TN41-UU89-CR55-YF36"

var pcaIcon = new GIcon();
var pcaMarkers = new Array();
var pcaMap = new GMap(document.getElementById("pcaDivMap"));
var blnPostcode = true;
var strPostode = "";
			
pcaMap.addControl(new GSmallMapControl());
pcaMap.addControl(new GScaleControl());
pcaMap.addControl(new GMapTypeControl());


pcaIcon.image = "http://services.postcodeanywhere.co.uk/popups/pin.aspx?account_code=" + CONST_ACCOUNT + "&license_key=" + CONST_LICENSE + "&ex=.png";
pcaIcon.iconSize = new GSize(12, 20);
pcaIcon.shadowSize = new GSize(22, 20);
pcaIcon.iconAnchor = new GPoint(6, 20);
pcaIcon.infoWindowAnchor = new GPoint(5, 1);

function pcaMapDisplay(type){
	
	if (document.all||document.getElementById){
		obj = document.getElementById("pcaDivMap");
	} else {
		obj = MM_findObj("pcaDivMap");
	}
	v = "show";
	d = "";
	if (type == 0){
		v = "hide";
		d = "none";
	}
	if (obj.style){
		obj=obj.style;
		v=(v=='show')?'visible':(v='hide')?'hidden':v;
		obj.visibility=v;
		obj.display=d;
	}	
}

function pcaStockistDisplay(id){
	
	for (intCount = 0; intCount < arrStockists.length; intCount ++){
		arrOptions = arrStockists[intCount].split("|");
		if (arrOptions.length >= 4) {
			if (document.all||document.getElementById){
				obj = document.getElementById("pcaStockist_" + arrOptions[0]);
			} else {
				obj = MM_findObj("pcaStockist_" + arrOptions[0]);
			}
			if (obj != null){
				v = "hide";
				d = "none";
				if (arrOptions[0] == id){
					v = "show";
					d = "";
				}
				if (obj.style){
					obj=obj.style;
					v=(v=='show')?'visible':(v='hide')?'hidden':v;
					obj.visibility=v;
					obj.display=d;
				}
			}
		}
	}
}
			
function pcaStartSearch(){
	pcaMapDisplay(1);
	blnPostcode = true;
	pcaByLocationBegin(document.getElementById("txtLocation").value, CONST_ACCOUNT, CONST_LICENSE, "");
}
				
function pcaByLocationBegin(location, account_code, license_code, machine_id){
	var scriptTag = document.getElementById("pcaScript");
	var headTag = document.getElementsByTagName("head").item(0);
	var strUrl = "";

	document.getElementById("pcaLstLocations").length=0;

	strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	strUrl += "&action=lookup";
	strUrl += "&type=by_location";
	strUrl += "&location=" + escape(location);
	strUrl += "&account_code=" + escape(account_code);
	strUrl += "&license_code=" + escape(license_code);
	strUrl += "&machine_id=" + escape(machine_id);
	strUrl += "&callback=pcaByLocationEnd";

	if (scriptTag){
		try{
			headTag.removeChild(scriptTag);
		}
		catch (e){
			
		}
	}
	scriptTag = document.createElement("script");
	scriptTag.src = strUrl
	scriptTag.type = "text/javascript";
	scriptTag.id = "pcaScript";
	headTag.appendChild(scriptTag);
}

function pcaByLocationEnd(){
	if (pcaIsError){
		alert(pcaErrorMessage);
	} else {
		if (pcaRecordCount==0){
			alert("Sorry, no matching items found");
		} else {
			document.getElementById("pcaLstLocations").length=pcaRecordCount;
			for (intCounter=0; intCounter < pcaRecordCount; intCounter++){
				document.getElementById("pcaLstLocations").options[intCounter].text = pca_description[intCounter];
				document.getElementById("pcaLstLocations").options[intCounter].value = pca_id[intCounter];
			}
			if (pcaRecordCount==1){
				 pcaStoredNearestBegin(pca_id[0], "", "6", CONST_ACCOUNT, CONST_LICENSE, "");
			} else {
				document.getElementById("pcaDivLocations").style.display="";
			}
		}
	}
}
			   
function pcaDoSelect(){
	blnPostcode = false;
	pcaStoredNearestBegin(document.getElementById("pcaLstLocations").value, "", "6", CONST_ACCOUNT, CONST_LICENSE, "");
	pcaStockistDisplay(pca_id[document.getElementById("pcaLstLocations").value]);
}
			
function pcaStoredNearestBegin(origin, units, items, account_code, license_code, machine_id){
			      
	var scriptTag = document.getElementById("pcaScript");
	var headTag = document.getElementsByTagName("head").item(0);
	var strUrl = "";
				  
	document.getElementById("pcaLstDistances").length=0;
	pcaMap.clearOverlays;
			      
	strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	strUrl += "&action=stored_nearest";
	strUrl += "&origin=" + escape(origin);
	strUrl += "&units=" + escape(units);
	strUrl += "&items=" + escape(items);
	strUrl += "&account_code=" + escape(account_code);
	strUrl += "&license_code=" + escape(license_code);
	strUrl += "&machine_id=" + escape(machine_id);
	strUrl += "&callback=pcaStoredNearestEnd";

	if (scriptTag) {
			try {
			    headTag.removeChild(scriptTag);
			}
		catch (e){
			
		}
	}
	scriptTag = document.createElement("script");
	scriptTag.src = strUrl
	scriptTag.type = "text/javascript";
	scriptTag.id = "pcaScript";
	headTag.appendChild(scriptTag);
	//document.forms['test']['url'].value = strUrl;
}

function pcaStoredNearestEnd(){

	if (pcaIsError){
		alert(pcaErrorMessage);
	} else {
		if (pcaRecordCount==0){
			alert("Sorry, no matching items found");
		} else {

			document.getElementById("pcaDivLocations").style.display="none";
			pcaMap.centerAndZoom(new GLatLng(pca_wgs84_latitude[0], pca_wgs84_longitude[0]),6);
			pcaMarkers.length = pcaRecordCount;
							
			for (i=0;  i<pcaRecordCount; i++){
									
				var point = new GLatLng(pca_wgs84_latitude[i], pca_wgs84_longitude[i]);    
																	
				var strLabel = "";
				strLabel = "<strong>" + pca_name[i] + "</strong><br />" + pca_description[i] + "<br /><br />" + "Distance: " + pca_distance[i] + " miles";
				for (intCount = 0; intCount < arrStockists.length; intCount ++){
					arrOptions = arrStockists[intCount].split("|");
					if (pca_id[i] == arrOptions[0]){
						strLabel = "<div class=\"map_content\" align=\"center\"><strong>" + arrOptions[1] + "</strong><br />";
						// + arrOptions[2];
						//if (arrOptions[3] != ""){
						//	strLabel += "<br />Tel: " + arrOptions[3];
						//}
						strLabel += "Distance: " + pca_distance[i] + " miles<br /><a href=\"javascript:pcaGetDirections('" + pca_origin_postcode[i] + "','" + pca_destination_postcode[i] + "')\">Get Directions</a></div>";	
					}
				}
				var marker = pcaCreateMarker(point, strLabel, i);
				pcaMarkers[i] = marker;									
				pcaMap.addOverlay(marker);
										
			}
									
			document.getElementById("pcaLstDistances").length=pcaRecordCount;
			for (intCounter=0; intCounter < pcaRecordCount; intCounter++){
				document.getElementById("pcaLstDistances").options[intCounter].text = pca_distance[intCounter] + " miles - " + pca_name[intCounter];
				document.getElementById("pcaLstDistances").options[intCounter].value = intCounter;
			}
								
			document.getElementById("pcaDivDistances").style.display="";
							
		}
	}
}

function pcaReCentre(){
					
	pcaMap.panTo(new GLatLng(pca_wgs84_latitude[document.getElementById("pcaLstDistances").value], pca_wgs84_longitude[document.getElementById("pcaLstDistances").value]));
					
	var strLabel = "";
	strLabel = "<strong>" + pca_name[document.getElementById("pcaLstDistances").value] + "</strong><br />" + pca_description[document.getElementById("pcaLstDistances").value] + "<br /><br />" + "Distance: " + pca_distance[document.getElementById("pcaLstDistances").value] + " miles";
	for (intCount = 0; intCount < arrStockists.length; intCount ++){
		arrOptions = arrStockists[intCount].split("|");
		if (pca_id[document.getElementById("pcaLstDistances").value] == arrOptions[0]){
		    blnPostcode = true;
		    var strPostcode = pca_origin_postcode[document.getElementById("pcaLstDistances").value].replace(/^\s*|\s*$/g,'');
			strLabel = "<div class=\"map_content\" align=\"center\"><strong>" + arrOptions[1] + "</strong><br />";
			// + arrOptions[2];
			//if (arrOptions[3] != ""){
			//	strLabel += "<br />Tel: " + arrOptions[3];
			//}
			if (!isNaN(strPostcode)){
			    blnPostcode = false;
			}
			strLabel += "Distance: " + pca_distance[document.getElementById("pcaLstDistances").value] + " miles<br />";
			if (blnPostcode){
			    strLabel += "<a href=\"javascript:pcaGetDirections('" + strPostcode + "','" + pca_destination_postcode[document.getElementById("pcaLstDistances").value] + "')\">Get Directions</a></div>";
			} else {
			    strLabel += "<form name=\"postcode_search\" style=\"padding: 0; margin: 0;\"><input type=\"text\" name=\"Postcode\" id=\"Postcode\" value=\"Your Postcode\" size=\"14\" maxlength=\"14\" onfocus=\"javascript:if (this.value == 'Your Postcode'){this.value='';}\" onkeypress=\"setPostcode(this.value)\" onkeyup=\"setPostcode(this.value)\" onblur=\"setPostcode(this.value)\" class=\"formfield\" />&nbsp;<a href=\"javascript:pcaGetDirections2('" + pca_destination_postcode[document.getElementById("pcaLstDistances").value] + "')\"><img src=\"images\\get-directions-button.png\" border=\"0\" title=\"Get Directions\" align=\"middle\" /></a></form></div>";
			}	
		}
	}
	pcaMarkers[document.getElementById("pcaLstDistances").value].openInfoWindowHtml(strLabel);
	pcaStockistDisplay(pca_id[document.getElementById("pcaLstDistances").value]);
			
}
			   

function pcaCreateMarker(point, info, number){
			
	var marker = new GMarker(point,pcaIcon);
			
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(info);
	});
			
	return marker;
}

function pcaGetDirections(origin, destination){
	var strURL = "http://maps.google.co.uk/maps?f=d&hl=en&saddr=" + origin + ", UK&daddr=" + destination + ", UK"	
	
	var intWidth = 0;
	var intHeight = 0;
				
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		intWidth = document.body.clientWidth;
		intHeight = document.body.clientHeight;
	} else {
		intWidth = window.outerWidth;
		intHeight = window.outerHeight;
	}
	var intTop = 0;
	var intLeft = 0;
	var intWindowWidth = 800;
	var intWindowHeight = 800;
	intTop = ((intHeight - intWindowHeight) / 2);
	intLeft = ((intWidth - intWindowWidth) / 2);
	var strWindowName = name;
	var strOptions = "toolbar=0" +
	",directories=0" +
	",status=0" +
	",menubar=0" +
	",resizable=yes" +
	",scrollbars=yes" +
	",width=" + intWindowWidth +
	",height=" + intWindowHeight +
	",top=" + intTop +
	",left=" + intLeft;
	win2 = window.open(strURL,'Directions',strOptions);
	win2.focus();
}

function pcaGetDirections2(destination){
    if (strPostode == ""){
        alert("Please enter a postcode");
    } else {
    	pcaGetDirections(strPostode, destination);
    }
}

function setPostcode(varPostcode){
    strPostode = varPostcode;
}

//pcaMapDisplay(0);

//-->
