	var account_code='FIRST11208';
	var machine_id='';

		var el_loading
		var el_address
		var el_div_add
		var el_div_add1
		
		function pcaByPostcodeBegin(info)
		   {
		   	info_arr = Split(info,"|")		   	
		   	el_postcode = info_arr[0]
		   	el_loading = info_arr[1]
		   	el_address = info_arr[2]
		   	el_div_add = info_arr[3]
		   	el_div_add1 = info_arr[4]
		   	
			var postcode = document.forms[0][el_postcode].value;
		      var scriptTag = document.getElementById("pcaScriptTag");
		      var headTag = document.getElementsByTagName("head").item(0);
		      var strUrl = "";
		      
		      document.getElementById(el_loading).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(el_loading).style.display = 'none';

			/*
			pcaIsError=false
			pcaRecordCount = 2
			var pca_description = new Array("abcd,sdfd,df","xyz,df,df")
			var pca_id = new Array("1","2")
			*/
				
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            document.getElementById(el_address).style.display = 'none';
		            //document.getElementById("btnFetch").style.display = 'none';
		            alert(pcaErrorMessage);
		            
		            document.getElementById(el_postcode).value="";
		            document.getElementById(el_div_add).style.display="";
		            document.getElementById(el_div_add1).style.display="";
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  document.getElementById(el_address).style.display = 'none';
					//document.getElementById("btnFetch").style.display = 'none';
		                  alert("Sorry, no matching items found. Please try another postcode.");
		                  
		                  document.getElementById(el_postcode).value="";
		                  document.getElementById(el_div_add).style.display="";
		                  document.getElementById(el_div_add1).style.display="";
		               }
		            else
		               {
						  document.forms[0][el_address].style.display = '';
						  //document.forms[0]["btnFetch"].style.display = '';
				  
						  for (i=document.forms[0][el_address].options.length-1; i>=0; i--){
							  document.forms[0][el_address].options[i] = null;
							}
						  for (i=0; i<pca_id.length; i++){
		                    document.forms[0][el_address].options[document.forms[0][el_address].length] = new Option(pca_description[i], pca_id[i]);
		                  }
		                  
		                  document.getElementById(el_div_add).style.display="none";
		                  document.getElementById(el_div_add1).style.display="none";
		               }
		         }
		   }
		
		var el_company
		var el_Address1
		var el_Address2
		var el_Town
		var el_county
		var el_postcode
		
		function pcaFetchBegin(el_list)
		   {
			
			el_list_arr = Split(el_list,"|")
			el_company = el_list_arr[0]
			el_Address1 = el_list_arr[1]
			el_Address2 = el_list_arr[2]
			el_Town = el_list_arr[3]
			el_county = el_list_arr[4]
			el_postcode = el_list_arr[5]
			
			var address_id = document.forms[0][el_address].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.forms[0][el_address].style.display = 'none';
		      //document.forms[0]["btnFetch"].style.display = 'none';
		   }

		function pcaFetchEnd()
		   {
		      
		      /*
		      pcaIsError = false
		      pcaRecordCount = 1
		      
				var pca_organisation_name = new Array("ABCD")
				var pca_line1 = new Array("5, raudat tahera st")
				var pca_line2 = new Array("Bharmal House")
				var pca_line3 = new Array("1st floor")
				var pca_line4 = new Array("Room no.2")
				var pca_line5 = new Array("Masjid")
				var pca_post_town = new Array("Mumbai")
				var pca_county = new Array("Maharashtra")
				var pca_postcode = new Array("400003")
		      */
		      
		      //Test for an error
		      if (pcaIsError)
		         {
		            //Show the error message
		            alert(pcaErrorMessage);
		         }
		      else
		         {
		            //Check if there were any items found
		            if (pcaRecordCount==0)
		               {
		                  alert("Sorry, no matching items found");
		               }
		            else
		               {
							ourDate = new Date( )
							
						  document.forms[0][el_company].value = '' + pca_organisation_name[0];
						  document.forms[0][el_Address1].value = '' + pca_line1[0];
						  document.forms[0][el_Address2].value = '' + pca_line2[0];
						  //document.forms[0]["line3"].value = '' + pca_line3[0];
						  //document.forms[0]["line4"].value = '' + pca_line4[0];
						  //document.forms[0]["line5"].value = '' + pca_line5[0];
						  document.forms[0][el_Town].value = '' + pca_post_town[0];
						  document.forms[0][el_county].value = '' + pca_county[0];
						  document.forms[0][el_postcode].value = '' + pca_postcode[0];
		               }
		         }
		   }
		   
		   
function Split(Expression, Delimiter)
{
	var temp = Expression;
	var a, b = 0;
	var array = new Array();

	if (Delimiter.length == 0)
	{
		array[0] = Expression;
		return (array);
	}

	if (Expression.length == '')
	{
		array[0] = Expression;
		return (array);
	}

	Delimiter = Delimiter.charAt(0);

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Delimiter);
		if (a == -1)
		{
			array[i] = temp;
			break;
		}
		else
		{
			b = (b + a) + 1;
			var temp2 = temp.substring(0, a);
			array[i] = temp2;
			temp = Expression.substr(b, Expression.length - temp2.length);
		}
	}

	return (array);
}
		   
		   