//Function : PCL, Post Code Look-up
/*function ctl(url){	
	if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = populateList;
	}
	else if (window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) populateList()
		};
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load(url);
}
*/
function ctl(url) {
    var parms = {
        type: 'GET',
        url: url,
        dataType: 'xml',
        success: callSuccess,
        error: callFail
    };

    jQuery.ajax(parms);
}

function callSuccess(data, textStatus, XMLHttpRequest)
{
    populateList(data);
}

function callFail()
{
    if (typeof(console) !== 'undefined')
        console.log("populate cities dropdown failed");
}

function populateList(xmlDoc)
{
    var selector = document.getElementById('ls');
    if (!selector)
        return;
    selector = jQuery(selector);

    var htmlList = [];

    var items = jQuery(xmlDoc.documentElement).find('item');

    items.each(function() {
        htmlList.push('<option value="');
        htmlList.push(jQuery(this).children('value').text());
        htmlList.push('">');
        htmlList.push(jQuery(this).children('name').text());
        htmlList.push('</option>');
    });

    var html = htmlList.join(' ');
    
    selector.html(html);

    if (items.length < 2)
        selector.attr('disabled', true);
    else
        selector.removeAttr('disabled');
}
