function PostcodeLookupInterim(postcode, dropDownId, sectionId)
{

	var url = "/WebServices/PostcodeLookup.asmx/Interim";

	var response = new Ajax.Request(url, {
					method: 'post', 
					parameters: {postcode: postcode},
					onSuccess: function(e) {

						var response = e.responseText;
						
						response = response.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
						response = response.replace("<string xmlns=\"http://www.anyahindmarch.com/\">", "");
						response = response.replace("</string>", "");
						response = response.replace("<string xmlns=\"http://www.anyahindmarch.com/\" />", "");
						response = response.replace("\r\n", "");
						
						// if the response length is empty - the postcode anywhere account may need topping up
						
						if (response.length > 0)
						{
							var addressArray = response.split("|");
							var dropDown = document.getElementById(dropDownId);
							var data, newOption;
							
							for (var i = dropDown.options.length - 1; i >= 0; i --)
								dropDown.options[i] = null;

							newOption = new Option("Please select", "");
							dropDown.options[0] = newOption;
							for (var i = 0; i < addressArray.size(); i ++)
							{
								data = addressArray[i].split(",");
								newOption = new Option(data[0], data[1]);
								dropDown.options[i + 1] = newOption;
							}
							document.getElementById(sectionId).style.display = 'block';
							
						}
						
					},
					onFailure: function() {
					
					}
				});
				// we want to show the billing address regardless of whether the post code look up works
				jQuery('#ctl00_contentPlaceHolderListing_coShipping_billingAddress').removeClass('hide');
}

function PostcodeLookupFinal(postcodeSelect, address1Id, address2Id, cityId, countyId)
{
	var url = "/WebServices/PostcodeLookup.asmx/Final";
	
	var postcodeId = postcodeSelect.options[postcodeSelect.selectedIndex].value;
	
	var response = new Ajax.Request(url, {
        method: 'post', 
        parameters: {postcodeId: postcodeId},
        onSuccess: function(e) {

			var response = e.responseText;
			
			response = response.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
			response = response.replace("<string xmlns=\"http://www.anyahindmarch.com/\">", "");
			response = response.replace("</string>", "");
			response = response.replace("<string xmlns=\"http://www.anyahindmarch.com/\" />", "");
			
			if (response.length > 0)
			{
				var data = response.split("|");
				
				var address1 = document.getElementById(address1Id);
				var address2 = document.getElementById(address2Id);
				var city = document.getElementById(cityId);
				var county = document.getElementById(countyId);

				address1.value = data[0];
				address2.value = data[1];
				city.value = data[2];
				county.value = data[3];
			}
			
        },
		onFailure: function() {
		
		}
    });
}

function GetConcatenatedPostCode() {
    var concatenatedPostCode = '';
    
    jQuery(".postCodeSegment").each(function() {
        concatenatedPostCode = concatenatedPostCode + jQuery(this).val();
    });

    return concatenatedPostCode;
}

function GetConcatenatedPostCode2() {
    var concatenatedPostCode = '';

    jQuery(".postCodeSegment2").each(function() {
        concatenatedPostCode = concatenatedPostCode + jQuery(this).val();
    });

    return concatenatedPostCode;
}


			
			
