//City Selection - 'FIND A LOCATION' box function
function select_country(idx) {
var f=document.find_location;
f.select_country.options[idx].selected = true; 
f.select_country.size=1;
}

function select_city(idx) {
var f=document.find_location;
f.select_city.options.length=null;
for(var i=0; i<cities[idx].length; i++) {
	f.select_city.options[i]=new Option(cities[idx][i], i); 
    } 
f.select_city.size=1;
var f=document.find_location;
f.select_service.options.length=null;
f.select_service.options[0]=new Option("-- Select City Above --", 0);
}

function select_service(idc,idx) {
var g=document.find_location;
g.select_service.options.length=null;
for(var i=0; i<(services[idx][idc]).length; i++) {
    if (services[idx][idc][i][0].toLowerCase()=='office space' ||
        services[idx][idc][i][0].toLowerCase()=='meeting rooms' ||  
        services[idx][idc][i][0].toLowerCase()=='virtual office' ||
        services[idx][idc][i][0].toLowerCase()=='-> select service')
	g.select_service.options[i]=new Option(services[idx][idc][i][0], services[idx][idc][i][1]); 
    }    
g.select_service.size=1;
}

function selectCityCountry(serviceId)
{
    var f=document.find_location;
    
    var unorderedServiceCount = 0;
    for (var countryCount=1; countryCount < cities.length;countryCount++)
    {
        //alert(cities[countryCount]);
        //unorderedCityCount++;
        
        //unorderedServiceCount++;
        for (var cityCount=1; cityCount < cities[countryCount].length;cityCount++)
        {        
            //aggiungo al contatore 1 -select city.
            //unorderedServiceCount--;
            if (services[countryCount]!=undefined && services[countryCount][cityCount]!=undefined)
            for (var serviceCount=1; serviceCount < services[countryCount][cityCount].length;serviceCount++)
            {
                
                unorderedServiceCount++;
                if (unorderedServiceCount==serviceId)
                {
                    
                    select_country(countryCount);
                    select_city(countryCount);
                    select_service(cityCount,countryCount);
                    f.select_city.selectedIndex=cityCount;
                    if (serviceCount < f.select_service.options.length)
                    f.select_service.selectedIndex=serviceCount;
                }
                 if (unorderedServiceCount==serviceId)
                break;
            }    
            if (unorderedServiceCount==serviceId)
                break;
           
        }  
        if (unorderedServiceCount==serviceId)
                break;
    }
}

function set_href() {
   var option_services = document.find_location.select_service;
   var url =option_services.options[option_services.selectedIndex].value;
   if(url=="none" || url=='select_service' || url=='0' || url==0)
   {
       if (document.find_location.select_country.selectedIndex<=0)
           alert("Please select a country");
       else if (document.find_location.select_city.selectedIndex<=0)
           alert("Please select a city");
       else if (document.find_location.select_service.selectedIndex<=0)
           alert("Please select a service");
       else
           alert("No page set for this service");
   }else
   {
      document.location.href=option_services.options[option_services.selectedIndex].value;
   }
}


var tmpFunc = window.onload; 
window.onload = function() { 

document.find_location.select_country.onchange=function(){select_city(this.selectedIndex);};
document.find_location.select_city.onchange=function(){select_service(this.selectedIndex,document.find_location.select_country.selectedIndex);};
if (tmpFunc != undefined)
tmpFunc(); 
}
