var ajax = new Array();
/*
function getCityList(sel)
{
    var countryCode = sel.options[sel.selectedIndex].value;
    document.getElementById('town').options.length = 0;    // Empty city select box
    if(countryCode.length>0){
        var index = ajax.length;
        ajax[index] = new sack();
        
        ajax[index].requestFile = '/js/getCities.php?countryCode='+countryCode;    // Specifying which file to get
        ajax[index].onCompletion = function(){ createCities(index) };    // Specify function that will be executed after file has been found
        ajax[index].runAJAX();        // Execute AJAX function
    }
}
*/
var n_counties = ["Antrim","Armagh","Down","Fermanagh","Derry","Tyrone"];

function check_north(val){
	res = false;
	for(i=0;i<n_counties.length;i++){
		if(val==n_counties[i])
			res = true;
	}
	if(res)
	    jQuery("#btcode").show();
	else
		jQuery("#btcode").hide();	
}

function getCityList(sel)
      {
        var countryCode = sel.options[sel.selectedIndex].value;
		check_north(sel.options[sel.selectedIndex].text);
        document.getElementById('town').options.length = 0;    // Empty city select box
        var opts = document.getElementById('town').options;
        if(countryCode.length>0){
             var obj = document.getElementById('town');
             jQuery.getJSON('/js/getCities.php?countryCode=' + countryCode, function(data) {
                jQuery.each(data.opts, function(i,item){
                  if (item.selected)
                    opts[opts.length] = new Option(item.name,item.id,true);
                  else
                    opts[opts.length] = new Option(item.name,item.id,false);
                 
                });
              
             });
        }
      }
function createCities(index)
{
    var obj = document.getElementById('town');
    eval(ajax[index].response);    // Executing the response from Ajax as Javascript code    
}
