function getQuestion(){
	return 'Как Вы оцениваете работу офиса?';
}

function getAndShowCityOfficesRatings(city){
	jQueryUI.post('/common/rating.php', { 'city': city, 'action' : 'get' }
		, function(data){showCityOfficesRatings(data);}).error(function (){});
}

function getAndShowCityOfficesRatingsAsHtml(city){
	jQueryUI.post('/common/rating.php', { 'city': city, 'action' : 'getHtml' }
		, function(data){showCityOfficesRatingsFromHtml(data);}, "json").error(function (){alert(1);});
}

function showCityOfficesRatingsFromHtml(data){
	for (var curOffice in data){
		var divId = curOffice;
		showOfficeRating(divId, data[curOffice]);
	}
}

function updateOfficeRating(office, vote){
	jQueryUI.post('/common/rating.php', { 'office': office, 'action' : 'update', 'vote' : vote }
		, function(data){showCityOfficesRatingsFromHtml(data);}, "json").error(function (){});
	//getAndShowCityOfficesRatingsAsHtml(office);
}

function showCityOfficesRatings(data){
	for (var office in data){
		formOfficeRatingHtml(office, data[office]);
	}
}

function formOfficeRatingHtml(office, officeData){
	if ( office != null ){
		var htmlText = 0 + officeData['VOTE_UP'] - officeData['VOTE_DOWN'];
		htmlText = getQuestion() + htmlText;
		var divId = '#' + office;
		showOfficeRating(divId, htmlText);
	}
}

function showOfficeRating(divId, htmlText){
	if ( divId != null ){
		var el = $('#' + divId);
		if ( el != null )
			el.html(htmlText);
	}
}