	// This code has been lifed from Links of London
	// It has been cut down but mught not be needed at all.
	var address_lookup_count = 0;
	
	CheckPostCodeReturnAddress = function (postcode, moniker, Id)
	{
		address_lookup_count = address_lookup_count+1;
		if(address_lookup_count > 1){
			//ShowHideLookup("GB",1);
			
			}
		
		CurrentIndex = Id;
		
		if (moniker)
		{
			if ('refinemore' == postcode)
			{
				autofillAddress.SetAjaxVars( {'postcode' : 'refinemore', 'moniker' :moniker} );
			}
			else
			{
				//used to send a final address
				autofillAddress.SetAjaxVars( { 'postcode' :'', 'moniker' :moniker} );
			}
			autofillAddress.ReqTimeOut();
			moniker ="";
		}
		else
		{
				
				
				
				if  ("" !=document.getElementById(MainArray[CurrentIndex][0]).value )
				{
							if  ("GB" ==document.getElementById(MainArray[CurrentIndex][1]).value)
							{	
									if (postcode)
									{ //this happens if the user is choosing a postcode from a ajax generated list
										enteredpost = postcode;
										document.getElementById(MainArray[CurrentIndex][0]).value = postcode;
									}
									else
									{
										enteredpost = document.getElementById(MainArray[CurrentIndex][0]).value;
									}
							
								//line1 = document.getElementById('line1').value;
								//line2 = document.getElementById('line2').value;
								
								line1 = '';
								line2 = '';
								countrycode = document.getElementById(MainArray[CurrentIndex][1]).value;
								

								//OLD eval("autofillAddress"+CurrentIndex+".SetAjaxVars( { 'postcode' : enteredpost, 'line1' : line1, 'line2' : line2, 'countrycode' :countrycode, 'moniker' :'' } );");
								//OLD eval("autofillAddress"+CurrentIndex+".ReqTimeOut();");
								
								eval("autofillAddress.SetAjaxVars( { 'postcode' : enteredpost, 'line1' : line1, 'line2' : line2, 'countrycode' :countrycode, 'moniker' :'' } );");
								eval("autofillAddress.ReqTimeOut();");
								
								
								//DisableLookup(CurrentIndex);
								
							}
							else
							{
								alert ("This feature only works for the UK");
							}			
				}
				else
				{
					alert ("This feature requires you to have entered in a valid UK postcode and address.");
				}
		} 
		return false;
	}
	
	
										
										
										
									


fillboxes = function(address)

	{
		

		document.getElementById('first_set_of_fileds').style.display = 'block';
		var addressarray = address.split("|");

		

		IfDefinedFiledsArray = (typeof(window['FieldsArray']) == "undefined")?  false: true;

		if (IfDefinedFiledsArray == false)

		{

				//basic transposing

				document.getElementById('txt_line10').value= addressarray[1];

				document.getElementById('txt_line20').value= addressarray[3];

		

				//translation rules for translating the key|value pairs passed in as a string

				var len = addressarray.length;

				 for (var n = 0; n < len; n++)

				{

				  if (addressarray[n]== 'County') { document.getElementById('txt_county0').value= addressarray[n+1] ;}

				  if (addressarray[n]== 'Postcode') {document.getElementById('txt_postcode0').value= addressarray[n+1];}

				  if (addressarray[n]== 'Town') {document.getElementById('txt_cit0y').value= addressarray[n+1];}

				}

				

				document.getElementById('postcodereturncontent').innerHTML=' ';

				



		}

		else

		{

					//basic transposing

				document.getElementById('txt_line10').value= addressarray[1];

				document.getElementById('txt_line20').value= addressarray[3];

		

				//translation rules for translating the key|value pairs passed in as a string

				var len = addressarray.length;

				
				var LondonExeption = 'no';
				var townname = '';
				for (var n = 0; n < len; n++)

				{

					 if (LondonExeption == 'no') 
					 {
					 
							 if ( (addressarray[n]== 'County') && (addressarray[n+1] != '') ) 
							 { 
								document.getElementById('txt_county0').value= addressarray[n+1] ;
							 }
							 
							 if ( (addressarray[n]== 'PNR county') && (addressarray[n+1] != '') ) 
							 { 
								document.getElementById('txt_county0').value= addressarray[n+1] ;
							 }
					 }
				 
				 
				 
				 
				  

				  	if (addressarray[n]== 'Postcode') {document.getElementById(MainArray[CurrentIndex][0]).value= addressarray[n+1];}

				  	if (addressarray[n]== 'Town') 
				  	{
						document.getElementById('txt_city0').value= addressarray[n+1];
						
						if (addressarray[n+1].toLowerCase()=='london')
						{
							LondonExeption = 'yes';	
						}
					}
				  
				  

				}

				/*
				if (document.getElementById(FieldsArray[CurrentIndex][7]).value=='')
				{
						document.getElementById(FieldsArray[CurrentIndex][7]).value=document.getElementById(FieldsArray[CurrentIndex][5]).value;
				}
				*/

				

				document.getElementById(MainArray[CurrentIndex][2]).innerHTML=' ';

		}

		//clear down the post code search interface

		DisableLookup(CurrentIndex);
		//ShowHideElements(true,CurrentIndex);

	}



function ShowHideElements(show,id)
{
		
		
		if ( (document.getElementById('showlookup'+id).checked) || (show === true) )
		{
			for (r=0; r<FieldsArray[id].length; r++)
			{
				if (document.getElementById(FieldsArray[id][r]))
				{
					document.getElementById(FieldsArray[id][r]).style.display = 'block';
				}
			}
			
			document.getElementById('first_set_of_fileds'+id).style.display = 'block';
			document.getElementById('second_set_of_fileds'+id).style.display = 'block';
			
			
		}
		else
		{
			
			// Verify if the first line of the address is not empty	
			if (document.getElementById(FieldsArray[id][1]).value == '')
			{
				for (r=0; r<FieldsArray[id].length; r++)
				{
					if (document.getElementById(FieldsArray[id][r]))
					{
						document.getElementById(FieldsArray[id][r]).style.display = 'none';
					}
				}
				
				document.getElementById(LinkArray[id][0]).style.display = 'none';
				document.getElementById('first_set_of_fileds'+id).style.display = 'none';
				document.getElementById('second_set_of_fileds'+id).style.display = 'none';
				
			}
			
		}
		
		
}



function ShowHideLookup(code,id)
{
	
	if ( (code != 'GB') || (document.getElementById('showlookup'+id).checked) )
	{
		for (r=0; r<LinkArray[id].length; r++)
			{
				document.getElementById(LinkArray[id][r]).style.display = 'none';
			}	
	
		ShowHideElements(true,id);	

	}
	else
	{
		
		if (document.getElementById('showlookup'+id).checked != true)
		{
			for (r=0; r<LinkArray[id].length; r++)
				{
					document.getElementById(LinkArray[id][1]).style.display = 'block';
				}

			ShowHideElements(false,id);		
			
		}
	}
			
}



function DisableLookup(id)
{
	/*
	document.getElementById('showlookup'+id).checked = true;
	document.getElementById(LinkArray[id][0]).style.display = 'none';	
	document.getElementById(LinkArray[id][1]).style.display = 'none';	
	document.getElementById(MainArray[id][2]).style.display = 'none';	
	
	*/
	ShowHideElements(true,id);
	
	//ShowHideLookup(false,id);
}




function showNotInTheList()
{
		document.getElementById(LinkArray[CurrentIndex][0]).style.display = 'block';	
}
function hideLookupButton()
{
		document.getElementById(LinkArray[CurrentIndex][1]).style.display = 'none';	
}




FieldsArray = new Array();
MainArray = new Array();
LinkArray = new Array();

CurrentIndex = 0;

BaseUrl = "ajax/postcode-lookup/";
         
