var account_code='EGMON11116';
var license_code='WZ11-UW49-FY76-UK25';
var machine_id='';

function pcaByPostcodeBegin()
   {
	  var postcode = document.frmOrderDelivery.postcode_search.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";
	  
	  document.getElementById("divLoading").style.display = '';
	  
	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=lookup";
	  strUrl += "&type=by_postcode";
	  strUrl += "&postcode=" + escape(postcode);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaByPostcodeEnd";
	  
	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  
	  
   }

function pcaByPostcodeEnd()
   {
	  document.getElementById("divLoading").style.display = 'none';
	  
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			document.getElementById("selectaddress").style.display = 'none';
			document.getElementById("btnFetch").style.display = 'none';
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				 document.getElementById('frm_error').innerHTML = "Sorry, no matching postcodes found. Please try another postcode."
			   }
			else
			   {
				  document.frmOrderDelivery.selectaddress.style.display = '';
				  document.frmOrderDelivery.btnFetch.style.display = 'block';
				  
				  for (i=document.frmOrderDelivery.selectaddress.options.length-1; i>=0; i--){
					  document.frmOrderDelivery.selectaddress.options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
					document.frmOrderDelivery.selectaddress.options[document.frmOrderDelivery.selectaddress.length] = new Option(pca_description[i], pca_id[i]);
				  }
			   }
		 }
   }

function pcaFetchBegin()
   {
	  var address_id = document.frmOrderDelivery.selectaddress.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";

	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=fetch";
	  strUrl += "&id=" + escape(address_id);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaFetchEnd";

	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  document.frmOrderDelivery.selectaddress.style.display = 'none';
	  document.frmOrderDelivery.btnFetch.style.display = 'none';
   }

function pcaFetchEnd()
   {
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				  document.getElementById('frm_error').innerHTML = "Sorry, no matching postcodes found"
			   }
			else
			   {
				  //document.frmOrderDelivery.company.value = '' + pca_organisation_name[0];
				  document.frmOrderDelivery.strOrderBillingAddress1.value = '' + pca_line1[0];
				  document.frmOrderDelivery.strOrderBillingAddress2.value = '' + pca_line2[0];
				  //document.frmOrderDelivery.line3.value = '' + pca_line3[0];
				  //document.frmOrderDelivery.line4.value = '' + pca_line4[0];
				  //document.frmOrderDelivery.line5.value = '' + pca_line5[0];
				  document.frmOrderDelivery.strOrderBillingTown.value = '' + pca_post_town[0];
				  document.frmOrderDelivery.strOrderBillingCounty.value = '' + pca_county[0];
				  document.frmOrderDelivery.strOrderBillingPostCode.value = '' + pca_postcode[0];
			   }
		 }
   }
   
function pcaByPostcodeBegin2()
   {
	  var postcode = document.frmOrderDelivery.postcode_search2.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";
	  
	  document.getElementById("divLoading").style.display = '';
	  
	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=lookup";
	  strUrl += "&type=by_postcode";
	  strUrl += "&postcode=" + escape(postcode);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaByPostcodeEnd2";
	  
	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  
	  
   }

function pcaByPostcodeEnd2()
   {
	  document.getElementById("divLoading").style.display = 'none';
	  
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			document.getElementById("selectaddress").style.display = 'none';
			document.getElementById("btnFetch2").style.display = 'none';
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				 document.getElementById('frm_error2').innerHTML = "Sorry, no matching postcodes found. Please try another postcode."
			   }
			else
			   {
				  document.frmOrderDelivery.selectaddress2.style.display = '';
				  document.frmOrderDelivery.btnFetch2.style.display = 'block';
				  
				  for (i=document.frmOrderDelivery.selectaddress2.options.length-1; i>=0; i--){
					  document.frmOrderDelivery.selectaddress2.options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
					document.frmOrderDelivery.selectaddress2.options[document.frmOrderDelivery.selectaddress2.length] = new Option(pca_description[i], pca_id[i]);
				  }
			   }
		 }
   }

function pcaFetchBegin2()
   {
	  var address_id = document.frmOrderDelivery.selectaddress2.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";

	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=fetch";
	  strUrl += "&id=" + escape(address_id);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaFetchEnd2";

	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  document.frmOrderDelivery.selectaddress2.style.display = 'none';
	  document.frmOrderDelivery.btnFetch2.style.display = 'none';
   }

function pcaFetchEnd2()
   {
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				  document.getElementById('frm_error2').innerHTML = "Sorry, no matching postcodes found"
			   }
			else
			   {
				  //document.frmOrderDelivery.company.value = '' + pca_organisation_name[0];
				  document.frmOrderDelivery.strOrderShippingAddress1.value = '' + pca_line1[0];
				  document.frmOrderDelivery.strOrderShippingAddress2.value = '' + pca_line2[0];
				  //document.frmOrderDelivery.line3.value = '' + pca_line3[0];
				  //document.frmOrderDelivery.line4.value = '' + pca_line4[0];
				  //document.frmOrderDelivery.line5.value = '' + pca_line5[0];
				  document.frmOrderDelivery.strOrderShippingTown.value = '' + pca_post_town[0];
				  document.frmOrderDelivery.strOrderShippingCounty.value = '' + pca_county[0];
				  document.frmOrderDelivery.strOrderShippingPostCode.value = '' + pca_postcode[0];
			   }
		 }
   }


function pcaAdminByPostcodeBegin()
   {
	  var postcode = document.frm.postcode_search.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";
	  
	  document.getElementById("divLoading").style.display = '';
	  
	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=lookup";
	  strUrl += "&type=by_postcode";
	  strUrl += "&postcode=" + escape(postcode);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaByAdminPostcodeEnd";
	  
	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  
	  
   }

function pcaByAdminPostcodeEnd()
   {
	  document.getElementById("divLoading").style.display = 'none';
	  
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			document.getElementById("selectaddress").style.display = 'none';
			document.getElementById("btnFetch").style.display = 'none';
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				 document.getElementById('frm_error').innerHTML = "Sorry, no matching postcodes found. Please try another postcode."
			   }
			else
			   {
				  document.frm.selectaddress.style.display = '';
				  document.frm.btnFetch.style.display = 'block';
				  
				  for (i=document.frm.selectaddress.options.length-1; i>=0; i--){
					  document.frm.selectaddress.options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
					document.frm.selectaddress.options[document.frm.selectaddress.length] = new Option(pca_description[i], pca_id[i]);
				  }
			   }
		 }
   }

function pcaAdminFetchBegin()
   {
	  var address_id = document.frm.selectaddress.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";

	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=fetch";
	  strUrl += "&id=" + escape(address_id);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaAdminFetchEnd";

	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  document.frm.selectaddress.style.display = 'none';
	  document.frm.btnFetch.style.display = 'none';
   }

function pcaAdminFetchEnd()
   {
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				  document.getElementById('frm_error').innerHTML = "Sorry, no matching postcodes found"
			   }
			else
			   {
				  //document.frm.company.value = '' + pca_organisation_name[0];
				  document.frm.strAddress1.value = '' + pca_line1[0];
				  document.frm.strAddress2.value = '' + pca_line2[0];
				  //document.frm.line3.value = '' + pca_line3[0];
				  //document.frm.line4.value = '' + pca_line4[0];
				  //document.frm.line5.value = '' + pca_line5[0];
				  document.frm.strTown.value = '' + pca_post_town[0];
				  document.frm.strCounty.value = '' + pca_county[0];
				  document.frm.strPostCode.value = '' + pca_postcode[0];
			   }
		 }
   }



//

function pcaByPostcodeBeginManageDelivery()
   {
	  var postcode = document.frmOrderDelivery.postcode_search.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";
	  
	  document.getElementById("divLoading").style.display = '';
	  
	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=lookup";
	  strUrl += "&type=by_postcode";
	  strUrl += "&postcode=" + escape(postcode);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaByPostcodeEndManageDelivery";
	  
	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  
	  
   }

function pcaByPostcodeEndManageDelivery()
   {
	  document.getElementById("divLoading").style.display = 'none';
	  
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			document.getElementById("selectaddress").style.display = 'none';
			document.getElementById("btnFetch").style.display = 'none';
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				 document.getElementById('frm_error').innerHTML = "Sorry, no matching postcodes found. Please try another postcode."
			   }
			else
			   {
				  document.frmOrderDelivery.selectaddress.style.display = '';
				  document.frmOrderDelivery.btnFetch.style.display = 'block';
				  
				  for (i=document.frmOrderDelivery.selectaddress.options.length-1; i>=0; i--){
					  document.frmOrderDelivery.selectaddress.options[i] = null;
					}
				  for (i=0; i<pca_id.length; i++){
					document.frmOrderDelivery.selectaddress.options[document.frmOrderDelivery.selectaddress.length] = new Option(pca_description[i], pca_id[i]);
				  }
			   }
		 }
   }







function pcaFetchBeginManageDelivery()
   {
	  var address_id = document.frmOrderDelivery.selectaddress.value;
	  var scriptTag = document.getElementById("pcaScriptTag");
	  var headTag = document.getElementsByTagName("head").item(0);
	  var strUrl = "";

	  //Build the url
	  strUrl = "http://services.postcodeanywhere.co.uk/inline.aspx?";
	  strUrl += "&action=fetch";
	  strUrl += "&id=" + escape(address_id);
	  strUrl += "&account_code=" + escape(account_code);
	  strUrl += "&license_code=" + escape(license_code);
	  strUrl += "&machine_id=" + escape(machine_id);
	  strUrl += "&callback=pcaFetchManageDelivery";

	  //Make the request
	  if (scriptTag)
		 {
			//The following 2 lines perform the same function and should be interchangeable
			headTag.removeChild(scriptTag);
			//scriptTag.parentNode.removeChild(scriptTag);
		 }
	  scriptTag = document.createElement("script");
	  scriptTag.src = strUrl
	  scriptTag.type = "text/javascript";
	  scriptTag.id = "pcaScriptTag";
	  headTag.appendChild(scriptTag);
	  
	  document.frmOrderDelivery.selectaddress.style.display = 'none';
	  document.frmOrderDelivery.btnFetch.style.display = 'none';
   }

function pcaFetchManageDelivery()
   {
	  //Test for an error
	  if (pcaIsError)
		 {
			//Show the error message
			alert(pcaErrorMessage);
		 }
	  else
		 {
			//Check if there were any items found
			if (pcaRecordCount==0)
			   {
				  document.getElementById('frm_error2').innerHTML = "Sorry, no matching postcodes found"
			   }
			else
			   {
				  //document.frmOrderDelivery.company.value = '' + pca_organisation_name[0];
				  document.frmOrderDelivery.strAddress1.value = '' + pca_line1[0];
				  document.frmOrderDelivery.strAddress2.value = '' + pca_line2[0];
				  if (pca_line3[0] != '')
				  {
					document.frmOrderDelivery.strAddress2.value = document.frmOrderDelivery.strAddress2.value + ', ' + pca_line3[0];
				  }
				  //document.frmOrderDelivery.line3.value = '' + pca_line3[0];
				  //document.frmOrderDelivery.line4.value = '' + pca_line4[0];
				  //document.frmOrderDelivery.line5.value = '' + pca_line5[0];
				  document.frmOrderDelivery.strTown.value = '' + pca_post_town[0];
				  document.frmOrderDelivery.strCounty.value = '' + pca_county[0];
				  document.frmOrderDelivery.strPostCode.value = '' + pca_postcode[0];
			   }
		 }
   }
