var geographyAjax = new Array();

function refreshGeography(pickupCountryId, pickupCitySelId, pickupLocationSelId, dropoffCountrySelId, dropoffCitySelId, dropoffLocationSelId, url){
        var pickupCitySel = document.getElementById(pickupCitySelId);
        var pickupCityId = isValidList(pickupCitySel) ? pickupCitySel.options[pickupCitySel.selectedIndex].value : null;
        var pickupLocationSel = document.getElementById(pickupLocationSelId);
        var pickupLocationId = isValidList(pickupLocationSel) ? pickupLocationSel.options[pickupLocationSel.selectedIndex].value : null;
        var dropoffCountrySel = document.getElementById(dropoffCountrySelId);
        var dropoffCountryId = isValidList(dropoffCountrySel) ? dropoffCountrySel.options[dropoffCountrySel.selectedIndex].value : null
        var dropoffCitySel = document.getElementById(dropoffCitySelId);
        var dropoffCityId = isValidList(dropoffCitySel) ? dropoffCitySel.options[dropoffCitySel.selectedIndex].value : null
        var dropoffLocationSel = document.getElementById(dropoffLocationSelId);
        var dropoffLocationId = isValidList(dropoffLocationSel) ? dropoffLocationSel.options[dropoffLocationSel.selectedIndex].value : null;

        var index = geographyAjax.length;       
        geographyAjax[index] = new sack();
        geographyAjax[index].requestFile = url + '?pickUpCountry.id='+ pickupCountryId;
        if(pickupCityId!=null) geographyAjax[index].requestFile = geographyAjax[index].requestFile + '&pickUpCity.id='+ pickupCityId;
        if(pickupLocationId!=null) geographyAjax[index].requestFile = geographyAjax[index].requestFile + '&pickUpLocation.id='+ pickupLocationId;
        if(dropoffCountryId!=null) geographyAjax[index].requestFile = geographyAjax[index].requestFile + '&dropOffCountry.id='+ dropoffCountryId;
        if(dropoffCityId!=null) geographyAjax[index].requestFile = geographyAjax[index].requestFile + '&dropOffCity.id='+ dropoffCityId;
        if(dropoffLocationId!=null) geographyAjax[index].requestFile = geographyAjax[index].requestFile + '&dropOffLocation.id='+ dropoffLocationId;
//        alert(geographyAjax[index].requestFile);
        geographyAjax[index].onCompletion = function(){ refreshGeographySelects(pickupCitySelId, pickupLocationSelId, dropoffCountrySelId, dropoffCitySelId, dropoffLocationSelId, index) };	// Specify function that will be executed after file has been found
        geographyAjax[index].runAJAX();		// Execute AJAX function
}

function refreshGeographySelects(pickupCitySelId, pickupLocationSelId, dropoffCountrySelId, dropoffCitySelId, dropoffLocationSelId, index){
	eval(geographyAjax[index].response);	// Executing the response from Ajax as Javascript code
}

function isValidList(select){    
    return select.selectedIndex>=0 && select.options.length>select.selectedIndex;
}

function syncTime(pickup, dropOff){
    var pickupSel=document.getElementById(pickup);    
    var dropOffSel=document.getElementById(dropOff);    
    if(pickupSel!=null && dropOffSel!=null){
        dropOffSel.selectedIndex = pickupSel.selectedIndex;
    }    
}