function get_location (dest, country, code, cc)	{
  var postcode = document.getElementById(code).value;
  
  if (!postcode)	{alert("Please enter a Postcode");document.getElementById(code).focus();}
  else if (!validate_pcode(postcode))	{document.getElementById(code).focus();}
  else	{
  
	  var httpreq  = getHTTPObject();
	  var url = "/includes/addresslist.php?postcode=" + postcode;
	  if (cc == 1){	url = url + '&cc=1';}
	  
	  if(cc != 1){ // location_label_div not present in control center postcode lookup
			document.getElementById('location_label_div').style.display = '';
			document.getElementById('location_label_div').style.height = '85px';
		}
		document.getElementById('location_div').style.display = '';
		document.getElementById('location_div').style.height = '85px';
		
		if (httpreq)	{
			httpreq.open("GET", url, true);
			httpreq.onreadystatechange = function () {
				if (httpreq.readyState == 4)	{
			  		document.getElementById(dest).innerHTML = httpreq.responseText;
				}
				return true;
			}
			httpreq.send(null);
		}
	}
}

function getHTTPObject() { 
	if (typeof XMLHttpRequest != 'undefined') { 
		return new XMLHttpRequest(); 
	} 
	try { 
		return new ActiveXObject("Msxml2.XMLHTTP"); 
	} 
	catch (e) { 
		try { 
			return new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (e) {
		} 
	} 
	return false; 
}

function getHTTPObjectog()
{
  var xmlhttp;
  try
  {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch (e)
  {
    try
    {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (E)
    {
      xmlhttp = false;
    }
  }
  xmlhttp = false;

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
  {
    try
    {
      xmlhttp = new XMLHttpRequest();
    }
    catch (e)
    {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function validate_pcode(test){ //check postcode format is valid
 //test = document.details.pcode.value; 
 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.getElementById('postcode').value = test; //write back to form field
 
if (!(test.match(/^[0-9A-Z\s]+$/)))	{		//  -- added by RF --
	alert(test + " is not a valid postcode - invalid characters");
	return false;
}
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   return false;
  }
//alert("Postcode Format OK");
return true;
}
