// JavaScript Document

function nav() {
	var allNavButtons = document.getElementById("header_navigation").getElementsByTagName("a");
	var URL = document.URL;
	if(URL.indexOf("index")!=-1){
		URL = URL.split("index")[0];	
	}
	var i;
	for(i=0; i<allNavButtons.length; i++){
		if(allNavButtons[i].href==URL){
			allNavButtons[i].className = allNavButtons[i].className.replace("off", "on");	
		}
	}
	
}


// define gallery arrays;
var largeImages = new Array;
var originalImages = new Array;
var thumbNails = new Array;

// define reusable variables
var productName = "";
var productCode = "";
var productPrice = "";
var originalImageSrc = "";

function loadGallery(galleryProductName, galleryProductCode, galleryProductPrice, originalImage){
	
	productName = galleryProductName;
	productCode = galleryProductCode;
	productPrice = galleryProductPrice;
	originalImageSrc = originalImage;
	
	var galleryPath = "/dynamic/viewextra.php?item=" + productCode + "&mode=gallery";
	var galleryAsText = "";
	
	// format price
	if(productPrice.indexOf("&pound;")!=-1)
	{
		productPrice = productPrice.replace("&pound;", "\u00A3");
	}
	
	// http request the gallery as text
	req = getreq();
	req.onreadystatechange = requestGalleryPath;
	req.open("GET", galleryPath, true);
	req.send(null);  
	
}

// http request 
function getreq() { // returns false if exists
	if(window.ActiveXObject) { // if IE
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				return;
			}
		}
	} 
	else if(window.XMLHttpRequest) { // if Mozilla, Safari, etc.
		return new XMLHttpRequest();
	}
}

function requestGalleryPath() {
	if(req.readyState == 4) {
		if(req.status == 200) {
			if(req.responseText.indexOf("viewitem_image_gallery")==-1)
			{
				document.getElementById("btns_container").style.display = "none";
				document.getElementById("image_browser_bottom_container_inner").innerHTML = document.getElementById("image_browser_bottom_container_inner").innerHTML + "<p style=\"text-align:center; padding:0px 0px 10px 0px;\">There is no gallery for this item</p>";
				document.getElementById("image_browser_bottom_container").style.display = "none";
				document.getElementById("main_image").src = originalImageSrc;
				opacity("loading_image", "100", "0", "1000");
				opacity("main_image", "0", "100", "1000");
			}
			else
			{
				galleryAsText = req.responseText.substring(req.responseText.indexOf("viewitem_image_gallery")+24, req.responseText.lastIndexOf(".jpg")+4);
				var i;
				var imageSplit = galleryAsText.split("|")
				var imgPrefix = "/catalogue/images/"
				var orginalImageSrcSplit = originalImageSrc.split(imgPrefix);
				for(i=0; i<imageSplit.length + 1; i++){
					if(i==0){
						
						largeImages[i] = imgPrefix + "large/" + orginalImageSrcSplit[1];
						originalImages[i] = originalImageSrc;
						thumbNails[i] = imgPrefix + "thumbs/" + orginalImageSrcSplit[1];
						var newLargeImage = new Image;
						newLargeImage.src = largeImages[i];
						var newOriginalImage = new Image;
						newOriginalImage.src = originalImages[i];
						var newThumbnail = new Image;
						newThumbnail.src = thumbNails[i];
					}
					
					else{
						largeImages[i] = imageSplit[i-1].split(":")[0];
						originalImages[i] = imageSplit[i-1].split(":")[0].replace(productCode + "/thumbs/", productCode + "/original/");
						thumbNails[i] = imageSplit[i-1].split(":")[1];
						var newLargeImage = new Image;
						newLargeImage.src = largeImages[i];
						var newOriginalImage = new Image;
						newOriginalImage.src = originalImages[i];
						var newThumbnail = new Image;
						newThumbnail.src = thumbNails[i];
					}
				}

			createGallery();
			}
		}
		else
		{
			//alert("no gallery");
			req = getreq();
			req.onreadystatechange = requestGalleryPath;
			req.open("GET", galleryPath, true);
			req.send(null);
		}
	}
}			

function createGallery(){
	if(thumbNails.length == "0" || thumbNails[0].indexOf("/awaiting_image.jpg")!=-1 || thumbNails[0] == "" || thumbNails[0] == " "){
		document.getElementById("main_image").src = "/images/awaiting_image.jpg";
		opacity("loading_image", "100", "0", "1000");
		opacity("main_image", "0", "100", "1000");
		//document.getElementById("zoom_container").style.display = "none";
		document.getElementById("btns_container").style.display = "none";
		document.getElementById("image_browser_bottom_container_inner").innerHTML = document.getElementById("image_browser_bottom_container_inner").innerHTML + "<p style=\"text-align:center; padding:0px 0px 10px 0px;\">There is no gallery for this item</p>";
		document.getElementById("image_browser_bottom_container").style.display = "none";
		return;
	}
	else{
		var thumbNailContainer = document.getElementById("btns_container");
		var zoomDescription = document.getElementById("buy_description").innerHTML.replace(/\"/g, "\'");
		var zoomContainer = document.getElementById("zoom_container");
		var zoomContainerInner = "";
		var breadcrumbs = document.getElementById("breadcrumbs").innerHTML.replace(/\"/g, "\'");
		breadcrumbs = breadcrumbs + "<li class=\'divider\'>&gt;</li>\n<li>" + productName + " - " + productPrice + "</li>";
		var i;
		for(i=0; i<thumbNails.length; i++){
			var thumbNail = document.createElement("li");
			var thumbNailDescription = thumbNails[i].substring(thumbNails[i].lastIndexOf("/")+1, thumbNails[i].lastIndexOf(".jpg")).replace(/_/g, " ").replace(/-/g, " ");
			var thumbInner = "";
			thumbInner = thumbInner + "<a href=\"javascript:swapMainImg(\'" + i + "\')\" title=\"" + productName + " - " + thumbNailDescription + "\" class=\"off\" id=\"img_btn_" + i + "\">\n";
			thumbInner = thumbInner + "<span class=\"image_browser_inner_container\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n<tr>\n<td valign=\"middle\" height=\"113\" width=\"113\" align=\"center\">"
			thumbInner = thumbInner + "<img src=\"" + thumbNails[i].replace(/#/g, "%23") + "\" onError=\"loadBtns(\'hide\', \'" + i + "\');\" onLoad=\"loadBtns(\'block\', \'" + i + "\');\" alt=\"" + productName + " - " + thumbNailDescription + "\" onclick=\"swapMainImg(\'" + i + "\')\" align=\"absmiddle\" />\n";
			thumbInner = thumbInner + "</td>\n</tr>\n</table></span>"
			//thumbInner = thumbInner + "<span class=\"image_browser_btn\"></span>";
			thumbInner = thumbInner + "</a>"
			thumbNail.innerHTML = thumbInner;
			thumbNailContainer.appendChild(thumbNail);
			
				var zoomCaption = thumbNails[i].substring(thumbNails[i].lastIndexOf("/")+1, thumbNails[i].lastIndexOf(".")).replace(/_/g, " ").replace(/-/g, " ");
				zoomContainerInner = zoomContainerInner + "<a href=\"" + largeImages[i].replace(/#/g, "%23") + "\" rel=\"gb_imageset[" + productName + "]\"";
				zoomContainerInner = zoomContainerInner + "id=\"zoom_" + i + "\"";
				zoomContainerInner = zoomContainerInner + "title=\"Zoom image of " + productName + "\"";
				zoomContainerInner = zoomContainerInner + "zoomtitle=\"<div class=\'zoom_content_container\'>";
				zoomContainerInner = zoomContainerInner + "<div class=\'zoom_content_left\'><span class=\'zoom_content_left_image_container\'><table width=\'100%\' cellpadding=\'0\' cellspacing=\'0\'><tr><td>";
				zoomContainerInner = zoomContainerInner + "<img src=\'" + thumbNails[i].replace(/#/g, "%23") + "\' alt=\'" + productName + " - " + zoomCaption + "\' class=\'zoom_micro_thumb\' />";
				zoomContainerInner = zoomContainerInner + "</td></tr></table></span></div>";
				zoomContainerInner = zoomContainerInner + "<div class=\'zoom_content_right'\><ul class=\'zoom_breadcrumbs\'>" + breadcrumbs + "</ul>\n<p>" + zoomCaption + "</p></div></div>";
				zoomContainerInner = zoomContainerInner + "<div class=\'zoom_description_container\'>" + zoomDescription + "</div>\">";
				zoomContainerInner = zoomContainerInner + "</a>\n"
		}
		zoomContainer.innerHTML = zoomContainerInner;
		//decoGreyboxLinks();
		var j;
		imageCells = thumbNailContainer.getElementsByTagName("td");
		for(j=0; j<imageCells.length; j++){

		}
	}
	
}

var imgBtns = 0;

function loadBtns(method, btn){
	if(method=="block")
	{
		document.getElementById("img_btn_" + btn).style.display = "block";
		if(imgBtns==thumbNails.length-1){
			setupImgBrowser();
			
		}
		imgBtns++;
	}
	else
	{
		document.getElementById("img_btn_" + btn).style.display = "none";
		if(imgBtns==thumbNails.length-1) {
			setupImgBrowser();
			
		}
		imgBtns++;
	}
}

function ie6(){
	if(navigator.userAgent.match("MSIE 6")){
		return true;	
	}
	else{
		return false;	
	}
}

function setupImgBrowser() {

	var btnContainer = document.getElementById("btns_container");
	var btns = btnContainer.getElementsByTagName("a");
	var blockBtns = 0;
	var hideBtns = 0;
	var onBtns = new Array();
	
	var i;
	for(i=0;i<btns.length;i++)
	{
		if(btns[i].style.display == "block")
		{
			onBtns[blockBtns] = btns[i];
			blockBtns++;
		}
		else
		{
			hideBtns++;
		}
	}

	if(onBtns[0]!=null && onBtns[0]!=="undefined")
	{
		//onBtns[0].className = "on";
		//document.getElementById("main_image").src = onBtns[0].getElementsByTagName("img")[0].src.replace("/thumbs/", "/original/");
		document.getElementById("main_image").src = originalImageSrc;
		opacity("loading_image", "100", "0", "1000");
		opacity("main_image", "0", "100", "1000");
		
	}
	
	if(blockBtns<2)
	{
		document.getElementById("btns_container").style.display = "none";
		document.getElementById("image_browser_bottom_container_inner").innerHTML = document.getElementById("image_browser_bottom_container_inner").innerHTML + "<p style=\"text-align:center; padding:0px 0px 10px 0px;\">There is no gallery for this item</p>";
		document.getElementById("image_browser_bottom_container").style.display = "none";
	}
	else
	{
		document.getElementById("btns_container").style.display = "block";
	}
	
	if(hideBtns==thumbNails.length)
	{
		document.getElementById("btns_container").style.display = "none";
		alert("no images");
	}

}




function opacity(id, opacStart, opacEnd, millisec) {

    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

function swapOpacity(id, opacStart, opacEnd, millisec, imgPath) {

    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {	
            setTimeout("swapChangeOpac(" + i + ",'" + id + "', '" + imgPath + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("swapChangeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
	
    }
}

function swapChangeOpac(opac, id, imgPath) {
    var object = document.getElementById(id).style;
    object.opacity = (opac / 100);
    object.MozOpacity = (opac / 100);
    object.KhtmlOpacity = (opac / 100);
    object.filter = "alpha(opacity=" + opac + ")";
	if(opac=="0")
		{
			document.getElementById(id).src = imgPath.replace("/thumbs/", "/original/");
			opacity("main_image", "0", "100", "300");
		}
} 

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 
			
	function swapMainImg(btn){
		var mainImg = document.getElementById("main_image");
		var imgBtn = document.getElementById("img_btn_" + btn)
		var imgPath = imgBtn.getElementsByTagName('img')[0].src;
		var allZoomBtns = document.getElementById("zoom_container").getElementsByTagName("a");
		var i;
		for(i=0; i<allZoomBtns.length; i++){
			allZoomBtns[i].style.display = "none";
			if(i == btn){
				allZoomBtns[i].style.display = "block";	
			}
		}
		//mainImg.src = imgPath;
		if(btn == 0){
			imgPath = imgPath.replace("/thumbs/", "/");
		}
		swapOpacity("main_image", "100", "0", "300", imgPath)
		
		resetBtns();
		imgBtn.className = "on";
		imgBtn.blur();
		return;
	}
			
	function resetBtns(){
	var btnContainer = document.getElementById("image_browser_bottom_container");
	var btns = btnContainer.getElementsByTagName("a");
	var i;
	for(i=0;i<btns.length;i++)
		{
			btns[i].className = "off";
		}	
	}
	
	
function extraInfo(sectionNumber){
	var allExtraInfoButtonsContainer = document.getElementById("extra_info_buttons_container");
	var allExtraInfoButtons = allExtraInfoButtonsContainer.getElementsByTagName("a");
	var allExtraInfoPanesContainer = document.getElementById("extra_info_inner");
	var allExtraInfoPanes = allExtraInfoPanesContainer.getElementsByTagName("div");
	
	// switch buttons on
	var i;
	for(i=0; i<allExtraInfoButtons.length; i++){
		allExtraInfoButtons[i].className = "off"
		if(i == sectionNumber){
			allExtraInfoButtons[i].className = "on";
			allExtraInfoButtons[i].blur();
		}
	}
	
	// swap content pane
	var extraInfoPaneNumber = 0;
	var j;
	for(j=0; j<allExtraInfoPanes.length; j++){
		if(allExtraInfoPanes[j].className == "related_info"){
			allExtraInfoPanes[j].style.display = "none";
			if(extraInfoPaneNumber == sectionNumber){
				allExtraInfoPanes[j].style.display = "block";	
			}
			extraInfoPaneNumber++
		}
	}
}

var imageArrayNumber = 0;
function checkImg(img, count){
	var extensions = ["gif", "png", "bmp"];
	var imgString = img.src.substring(0, img.src.lastIndexOf("/")+1);
	var imgPathWithoutExtension = img.src.substring(0, img.src.lastIndexOf(".")+1);
	var imgName = imgPathWithoutExtension.split(imgString)[1].split(".")[0];
	img.src = imgString + "awaiting_image.jpg"; 
	img.id = "check_image_" + imageArrayNumber;
	
	if(document.getElementById("cart")!=null){
		document.getElementById("cart").innerHTML = document.getElementById("cart").innerHTML + "<div id=\"" + imgName + "_container\" style=\"display:none;\"></div>";
	}
	else{
		var newImgContainer = document.createElement("div");
		newImgContainer.id = imgName + "_container";
		newImgContainer.style.display = "none";
		document.body.appendChild(newImgContainer)
	}
	var newImagesString = "";
	var i;
	for(i=0; i<extensions.length; i++){
		newImagesString = newImagesString + "<img src=\"" + imgPathWithoutExtension + extensions[i] + "\" onload=\"swapImg(\'" + imgPathWithoutExtension + extensions[i] + "\', \'" + img.id + "\')\" />\n";		
	}
	document.getElementById(imgName + "_container").innerHTML = newImagesString;
	imageArrayNumber++
}

function swapImg(imgSrc, img){
	document.getElementById(img).src = imgSrc;
	return;
}

//callback
var callBackForm = "";
var allCallBackFormLines = "";
var callBackPageTracker = "";

function callBackRefresh(){
	callBackForm = document.getElementById("call_back_form");
	callBackPageTracker = callBackForm.page_tracker;
	allCallBackFormLines = callBackForm.getElementsByTagName("input");
	callBackPageTracker.value = document.URL;
	var i;
	for(i=0; i<allCallBackFormLines.length; i++){
		allCallBackFormLines[i].className = "text call_back";
		if(allCallBackFormLines[i].value == ""){
			allCallBackFormLines[i].value = line.getAttribute("defaultValue");	
		}
	}
}

function callBack(line){
	if(line.value == line.getAttribute("defaultValue")){
		line.value = "";
	}
	else if(line.value == ""){
		line.value = line.getAttribute("defaultValue");	
	}
	else{
		return;	
	}
}

function callBackRequest(){
	callBackRefresh();
	
	var i;
	for(i=0; i<allCallBackFormLines.length; i++){
		if(allCallBackFormLines[i].type.match("text")){
			if(allCallBackFormLines[i].value == allCallBackFormLines[i].getAttribute("defaultValue") || allCallBackFormLines[i].value == ""){
				allCallBackFormLines[i].className = allCallBackFormLines[i].className + " error_line";
				allCallBackFormLines[i].focus();
				alert("You must enter a " + allCallBackFormLines[i].getAttribute("defaultValue") + ".");
				return;
			}
			if(allCallBackFormLines[i].getAttribute("name").toLowerCase().match("phone")){
				if(allCallBackFormLines[i].value.length < 10){
					allCallBackFormLines[i].className = allCallBackFormLines[i].className + " error_line";
					allCallBackFormLines[i].focus();
					alert("You must enter your full phone number including area code.")
					return;
				}
			}
		}
	}
	
	callBackForm.submit();
}

function numbersonly(e) {
	var unicode=e.charCode? e.charCode : e.keyCode;
	if (unicode!=8){ //if the key isn’t the backspace key (which we should allow)
		if (unicode<48||unicode>57){ //if not a number return false //disable key press
			return false;
		}
	else{
		return true;
	}	
}}



function createLinkedItems(LinkedItemsText){
	var linkedItemsPanel = document.getElementById("linked_products");
	var linkedProductsAsText = LinkedItemsText;
	var linkedItems = "";
	var linkedItemNumber = 0;
	var newlinkedProductsAsText;
	var linkedItemLineNumber = 0;
	var linkedItemsContainer = document.getElementById("view_item_linked_item_container_" + linkedItemLineNumber);
	var linkedItemDelimeter = "<!--/VIEWITEM_LINKED_ITEM-->";
	if(LinkedItemsText.indexOf(linkedItemDelimeter)!=-1){
		//linkedProductsAsText = linkedProductsAsText.replace(/^\s*|\s*$/g, "").replace(/\n/g, "");
		newlinkedProductsAsText = linkedProductsAsText.split(linkedItemDelimeter);
		//if(linkedProductsAsText.length > 4){
		//	var newLine = document.createElement("ul");
		//	newLine.id = "view_item_linked_item_container_" + linedItemLineNumber;
		//	newLine.className = "inner_link_container";
		//	linkedItemsPanel.appendChild(newLine);
		//	linedItemLineNumber++;
		//}
		var i;
		for(i=0; i<newlinkedProductsAsText.length; i++){

			if(linkedItemNumber == 4){
				linkedItemLineNumber++;
				var newLine = document.createElement("ul");
				newLine.id = "view_item_linked_item_container_" + linkedItemLineNumber;
				newLine.className = "inner_link_container";
				linkedItemsPanel.appendChild(newLine);
				linkedItemNumber = 0;
				linkedItems = "";
			}
			linkedItems = linkedItems + newlinkedProductsAsText[i];
			document.getElementById("view_item_linked_item_container_" + linkedItemLineNumber).innerHTML = linkedItems;
			linkedItemNumber++;
		}
	}
}

function abbreviate(id, abbLength){
	var newLength;
	
	if(abbLength){
		newLength = abbLength	
	}
	else{
		newLength = 50;	
	}
	
	var prodNameContainer = document.getElementById(id)
	var prodName = prodNameContainer.innerHTML;
	if(prodName.length > newLength){
		prodName = prodName.substring(0, newLength);
		if(prodName.substring(prodName.length-1, prodName.length) == " "){
			prodName = prodName.substring(0, newLength - 1);
		}
		prodNameContainer.innerHTML = prodName + "...";
	}	
}

function LinkedBuy(what,which)
	{
		var x = document.getElementById(which).value;
		var y = parent.location.search;
		if(x > 0)
		{
			parent.location.href = "/dynamic/add2basket.php?add_quantity=" + x + "&add_item=" + what + "&add_from=viewitem&add_uri=" + y;
		}
		else
		{
			alert("No Quantity Specified");
		}
		return true;
	}
	

//var popUp = "<div id=\"map_marker\"><img src=\"images/layout/map_logo.jpg\" id=\"hbp_map_logo\" /><h2 class=\"map_title\">HBP Systems Ltd</h2>Enterprise House, Woodhouse Road, DN16 1BD, UK<br /><span class=\"map_links\"><a href=\"mailto:info@hbpsystems.com\" title=\"Send Email to HBP Systems Now\" class=\"map_text_link\">info@hbpsystems.com</a> | <a href=\"http://www.hbpsystems.com\" title=\"HBP Systems Home\" class=\"map_text_link\">www.hbpsystems.com</a></span></span></div>"
var popUp = "<table><tr><td>Get directions to Charmed Interiors</td></tr><tr><td><form action=\"javascript:setDirections('popUpFromAddress');\"><input type=\"text\" size=\"25\" id=\"popUpFromAddress\" value=\"\" /></form></td></tr></table>";
var submittedFromAddress = "";
function loadMap(){
if (GBrowserIsCompatible()) { 
		var geocoder = null;
		var addressMarker;
		map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
		//map.addControl(new GOverviewMapControl(new GSize(50,50)) );
		GEvent.addListener(gdir, "load", onGDirectionsLoad);
        GEvent.addListener(gdir, "error", handleErrors);
        map.enableDoubleClickZoom();
		map.enableScrollWheelZoom();
		map.setCenter(center, 7);
		map.setMapType(G_NORMAL_MAP);
		addOverlays();
}
	else {
			document.getElementById("google_map_container").style.display = "none";
			document.getElementById("map_image").style.display = "block";
	}
}

function addOverlays(){
		var locationIcon = new GIcon();
        locationIcon.iconSize = new GSize(50, 50);
        locationIcon.image = "images/charmed_interiors_logo.png";
        //locationIcon.shadowSize = new GSize(37, 34);
        locationIcon.iconAnchor = new GPoint(25, 25);
        locationIcon.infoWindowAnchor = new GPoint(25, 25);
        locationIcon.infoShadowAnchor = new GPoint(18, 25);
        markerOptions = { icon: locationIcon };
        var marker = new GMarker(center, markerOptions);
        map.addOverlay(marker);
        //marker.openInfoWindowHtml(popUp);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(popUp);											 
			}
		)
}


function resetMap() {
		map.clearOverlays();
		map.setZoom(7);
		map.panTo(center);
		addOverlays();
		//map.addOverlay(marker);
        //marker.openInfoWindowHtml(popUp);
	}
	
function setDirections(directionsInput) {
		var fromAddress = document.getElementById(directionsInput).value;
		processing();
		//var fromAddress = document.getElementById("fromAddress").value;
		//if(fromAddress=="")
			//{alert("Please enter either a postcode, or a street and town and try again.");resetMap();return;}
		var toAddress = "Charmed Interiors @ 52.6039, 0.3612";
		
		//map.clearOverlays();
		submittedFromAddress = fromAddress;
      	gdir.load("from: " + fromAddress + " to: " + toAddress);
}

function handleErrors(){
		processing();
		
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	   {
	     alert("We couldn't find your exact address \"" + submittedFromAddress + "\". This may be because the address you specified is relatively new, incorrect, or you may have to be more specific.\n\nPlease try again.\n\nIf this problem persists, please contact Charmed Interiors on 01366 384 126");
		 resetMap();
		 return;
	   }
	   if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	   {	
	     	alert("Your directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code + "\n\nPlease try again, putting either postcode or street and town in to the directions box");
			resetMap();
			return;
	   }
	   if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	   {
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		 resetMap();
		 return;
	   }
	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	  if (gdir.getStatus().code == G_GEO_BAD_KEY)
	  {
	     alert("We could not process your query at this present time.\n\n Please contact HBP on 01724 400 300 with the following error:\n\n Error code: " + gdir.getStatus().code + " - Map Key Invalid");
		 resetMap();
		 return;
	  }
	  if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	  {
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		 resetMap();
		 return;
	  }
	   else {
	   		alert("Please check your address and try again.");
	   		resetMap();
	   		return;
		}
	   
		}

function onGDirectionsLoad(){ 

}
function processing(){

}
