function ChangeCityRates(city){
	jQueryUI("#officerates").empty();
	for (var key in OfficesByCitites[city]){
		jQueryUI("#officerates").append( $('<option value="' + key + '">' + OfficesByCitites[city][key] + '</option>'));
	}
	if (SelectedOffices[city] !== 0){
		jQueryUI("#officerates [value='"+SelectedOffices[city]+"']").attr("selected", "selected");
	}
	else{
		jQueryUI("#officerates :first").attr("selected", "selected"); // seems to work without it, but ...
	}
	ChangeOfficeRates( jQueryUI("select#officerates").val() );
}

function formatDate(date) {

  var dd = date.getDate();
  if (dd < 10)
	dd = '0' + dd;

  var mm = date.getMonth()+1;
  if (mm < 10)
	mm = '0' + mm;

  var yyyy = date.getFullYear();

  return dd + '.' + mm + '.' + yyyy;
}

function ChangeOfficeRates(office){
	officeRate = OfficesRates[office];
	var CurDateCheck = new Date();

	if (formatDate(CurDateCheck) == ratesdate || true) {
		jQueryUI(jQueryUI('#cur_USD td')[1]).html(officeRate['BUY']['USD']);
		jQueryUI(jQueryUI('#cur_EUR td')[1]).html(officeRate['BUY']['EUR']);
		jQueryUI(jQueryUI('#cur_JPY td')[1]).html(officeRate['BUY']['JPY']);
		jQueryUI(jQueryUI('#cur_USD td')[2]).html(officeRate['SELL']['USD']);
		jQueryUI(jQueryUI('#cur_EUR td')[2]).html(officeRate['SELL']['EUR']);
		jQueryUI(jQueryUI('#cur_JPY td')[2]).html(officeRate['SELL']['JPY']);
	    jQueryUI(jQueryUI('#pcur_USD td')[1]).html(officeRate['BUY']['PUSD']);
		jQueryUI(jQueryUI('#pcur_EUR td')[1]).html(officeRate['BUY']['PEUR']);
		jQueryUI(jQueryUI('#pcur_JPY td')[1]).html(officeRate['BUY']['PJPY']);
		jQueryUI(jQueryUI('#pcur_USD td')[2]).html(officeRate['SELL']['PUSD']);
		jQueryUI(jQueryUI('#pcur_EUR td')[2]).html(officeRate['SELL']['PEUR']);
		jQueryUI(jQueryUI('#pcur_JPY td')[2]).html(officeRate['SELL']['PJPY']);
	}
	else{
		jQueryUI(jQueryUI('#cur_USD td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#cur_EUR td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#cur_JPY td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#cur_USD td')[2]).html('Í/Ä');
		jQueryUI(jQueryUI('#cur_EUR td')[2]).html('Í/Ä');
		jQueryUI(jQueryUI('#cur_JPY td')[2]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_USD td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_EUR td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_JPY td')[1]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_USD td')[2]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_EUR td')[2]).html('Í/Ä');
		jQueryUI(jQueryUI('#pcur_JPY td')[2]).html('Í/Ä');
	}
	SelectedOffices[jQueryUI("select#citiesrates").val()] = office;
}

function InitRatesData(){
	jQueryUI("#citiesrates").empty();
	first = -1;
	cnt = 0;
	for (var key in Cities){
		jQueryUI("#citiesrates").append( $('<option value="' + key + '">' + Cities[key] + '</option>'));
		if (cnt === 0){
			first = key;
		}
		cnt = cnt + 1;
	}
	ChangeCityRates(first);
}