var list_postcode = function (postcode)
{
    ajaxbox.open ('/checkout/ajax/address_select.php?postcode=' + postcode);
}

var set_address = function (postkey)
{
    // Look up details from postkey
    new Ajax.Request
    (
        '/checkout/ajax/get_address.php',
        {
            method: 'get',
            parameters: { postkey : postkey },
            onSuccess: function (transport)
            {	
                // Show the fields
                $('addressfields').show ();
                
                // Check for errors
                if (transport.responseXML.getElementsByTagName ('error')[0])
                {
                    alert (transport.responseXML.getElementsByTagName ('error')[0].firstChild.nodeValue);
                }
                else
                {
                    var address1 = transport.responseXML.getElementsByTagName ('property')[0].firstChild.nodeValue;
                    if(address1!='')
                    {
                        $('address1').value     =    transport.responseXML.getElementsByTagName ('property')[0].firstChild.nodeValue;
                    }
                    if(transport.responseXML.getElementsByTagName ('street')[0].firstChild.nodeValue!='')
                    {
                        $('address2').value     =   transport.responseXML.getElementsByTagName ('street')[0].firstChild.nodeValue;
                    }
                    if(transport.responseXML.getElementsByTagName ('town')[0].firstChild.nodeValue!='')
                    {
                        $('city').value         =     transport.responseXML.getElementsByTagName ('town')[0].firstChild.nodeValue;
                    }
                    if(transport.responseXML.getElementsByTagName ('postcode')[0].firstChild.nodeValue!='')
                    {
                        $('postcode').value     =     transport.responseXML.getElementsByTagName ('postcode')[0].firstChild.nodeValue;
                    }
                }
                alert(transport.responseXML.getElementsByTagName ('property')[0].firstChild.nodeValue);
                // Close the AJAXBox popup
                ajaxbox.end ();
            }
            
        }
    );
    
}
