

// Handle the ajax for this page

function getStores(region) {
 
  var url;
    
		
		url = '/ajax/getStores.asp?' +
            'region=' + region ;
		


  if (window.ActiveXObject) // for IE
  {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) // for other browsers
  {
    httpRequest = new XMLHttpRequest();
  }

  httpRequest.open("GET", url, true);
  httpRequest.onreadystatechange = function() {processRequest('listStores'); } ;
  httpRequest.send(null);

}


function listStores(xXML) {
	       
		   //alert("HERE")
		   
        var theCounter;
		var stores;
		stores="";
     
		if (xXML.getElementsByTagName("stores").length > 0 )
		{
			
			stores="";
			document.getElementById("stores_list").innerHTML= stores;
			document.getElementById("stores_nearest").innerHTML= stores;
			
			var theChildren = xXML.getElementsByTagName("stores");
			var theChild = theChildren[0];
	            

			//loop through the array 
			for (theCounter = 0; theCounter < theChild.getElementsByTagName("store").length; theCounter++) 
			{
			      
				stores=stores + "<div class='storeEntry'>"
				stores=stores + "<h3>" + theChild.getElementsByTagName("store_name")[theCounter].firstChild.nodeValue + "</h3>"
				stores=stores + "<p>" + theChild.getElementsByTagName("telephone")[theCounter].firstChild.nodeValue + "</p>"
				stores=stores + "<a class='viewButton btn_green_61 whitetext_bold' href='/storelocator/" + theChild.getElementsByTagName("href")[theCounter].firstChild.nodeValue + ".asp' title='View'><strong>View</strong></a>"
				
				if (theChild.getElementsByTagName("map_URL")[theCounter].firstChild.nodeValue!="none"){
					stores=stores + "<a class='mapButton btn_green_99 whitetext_bold' href='" + theChild.getElementsByTagName("map_URL")[theCounter].firstChild.nodeValue + "' target='_blank' title='Detailed Map'><strong>Detailed Map</strong></a>"
				}
				
				stores=stores + "</div>"
				stores=stores + "<div class='hr'><hr /></div>"
				
	            
			}	

			document.getElementById("stores_list").innerHTML= stores;
			
			var whichStores = document.getElementById('region4');
			//var shim = document.getElementById('iframe');
			var flash = document.getElementById('map');
			
			if(whichStores.style.display=='none'){
				whichStores.style.display='block';
				//shim.style.display='block';
				flash.style.display='none';
			}

		}
		else
		{
			alert ("Sorry, no stores are yet open in your area.");			
		}
		
    }



function getStoreByPostcode(postcode) {
 
  var url;
    
		
		url = '/ajax/getStoreByPostcode.asp?' +
            'postcode=' + postcode ;
		


  if (window.ActiveXObject) // for IE
  {
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  }
  else if (window.XMLHttpRequest) // for other browsers
  {
    httpRequest = new XMLHttpRequest();
  }

  httpRequest.open("GET", url, true);
  httpRequest.onreadystatechange = function() {processRequest('listNearest'); } ;
  httpRequest.send(null);

}


function listNearest(xXML) {
	       
        var theCounter;
		var stores;
		stores="";
     
		if (xXML.getElementsByTagName("stores").length > 0 )
		{
			
			stores="";
			document.getElementById("stores_nearest").innerHTML= stores;
			
			var theChildren = xXML.getElementsByTagName("stores");
			var theChild = theChildren[0];
	            

			//loop through the array 
			for (theCounter = 0; theCounter < theChild.getElementsByTagName("store").length; theCounter++) 
			{
			      
				stores=stores + "<div class='storeEntry nearest'>"
				stores=stores + "<h3>" + theChild.getElementsByTagName("store_name")[theCounter].firstChild.nodeValue + "</h3>"
				
				if (theChild.getElementsByTagName("telephone")[theCounter].firstChild.nodeValue!="-"){
					stores=stores + "<p>" + theChild.getElementsByTagName("telephone")[theCounter].firstChild.nodeValue + "</p>"
				}
				
				stores=stores + "<a class='viewButton btn_green_61 whitetext_bold' href='/storelocator/" + theChild.getElementsByTagName("href")[theCounter].firstChild.nodeValue + ".asp' title='View'><strong>View</strong></a>"
				
				if (theChild.getElementsByTagName("map_URL")[theCounter].firstChild.nodeValue!="none"){
					stores=stores + "<a class='mapButton btn_green_99 whitetext_bold' href='" + theChild.getElementsByTagName("map_URL")[theCounter].firstChild.nodeValue + "' target='_blank' title='Detailed Map'><strong>Detailed Map</strong></a>"
				}
				
				stores=stores + "</div>"
				stores=stores + "<div class='hr'><hr /></div>"
				
	            
			}	

			document.getElementById("stores_nearest").innerHTML= stores;

		}
		else
		{
			alert ("Sorry no stores found near that postcode.", "");			
		}
		
    }



