function updatePropertyStatus() {
	var current_link = this;
	$.getJSON($(this).attr('href'), function(data){
			if (data.status == 'hold') {
				$(current_link).attr('class', 'hold').text('offline');
				$(current_link).attr('href', $(current_link).attr('href').replace(/hold/,'vacancy'));
			} else if (data.status == 'vacancy') {
				$(current_link).attr('class', 'vacancy').text('online');
				$(current_link).attr('href', $(current_link).attr('href').replace(/vacancy/,'no_vacancy'));
			} else if (data.status == 'no_vacancy') {
				$(current_link).attr('class', 'no_vacancy').text('offline');
				$(current_link).attr('href', $(current_link).attr('href').replace(/no_vacancy/,'deleted'));
			}else if (data.status == 'deleted') {
				$(current_link).attr('class', 'deleted').text('deleted');
				$(current_link).attr('href', $(current_link).attr('href').replace(/deleted/,'hold'));
			}

	});
	return false;
}

function updateAgentStatus() {
	var current_link = this;
	$.getJSON($(this).attr('href'), function(data){
			if (data.status == 'hold') {
				$(current_link).attr('class', 'hold').text('hold');
				$(current_link).attr('href', $(current_link).attr('href').replace(/hold/,'approved'));
			} else if (data.status == 'approved') {
				$(current_link).attr('class', 'valid').text('approved');
				$(current_link).attr('href', $(current_link).attr('href').replace(/valid/,'banned'));
			} else if (data.status == 'banned') {
				$(current_link).attr('class', 'banned').text('banned');
				$(current_link).attr('href', $(current_link).attr('href').replace(/banned/,'approved'));
			}
	});
	return false;
}

function updateAgentForward() {
	var current_link = this;
	$.getJSON($(this).attr('href'), function(data){

			if (data.direct_email == '1') {
				$(current_link).attr('class', 'no_forward').text('Yes');
				$(current_link).attr('href', $(current_link).attr('href').replace(/Yes/,'No'));
			}
			if (data.direct_email == '0') {
				$(current_link).attr('class', 'no_forward').text('No');
				$(current_link).attr('href', $(current_link).attr('href').replace(/No/,'Yes'));
			}
	});
	return false;
}

function updateBuildingStatus() {
	var current_link = this;
	$.getJSON($(this).attr('href'), function(data){
			if (data.status == 'Active') {
				$(current_link).attr('class', 'Active').text('online');
				$(current_link).attr('href', $(current_link).attr('href').replace(/Active/,'Inactive'));
			} else if (data.status == 'Inactive') {
				$(current_link).attr('class', 'Inactive').text('offline');
				$(current_link).attr('href', $(current_link).attr('href').replace(/Inactive/,'Deleted'));
			} else if (data.status == 'Deleted') {
				$(current_link).attr('class', 'Deleted').text('deleted');
				$(current_link).attr('href', $(current_link).attr('href').replace(/Deleted/,'Active'));
			}
	});
	return false;
}

$(function(){
	$('a.property.hold, a.property.vacancy, a.property.no_vacancy, a.property.deleted').click(updatePropertyStatus);
    $('a.user.hold, a.user.valid, a.user.banned, a.user.deleted').click(updateAgentStatus);
    $('a.building.Active, a.building.Inactive, a.building.Deleted').click(updateBuildingStatus);
    $('a.agent.forward, a.agent.no_forward').click(updateAgentForward);
});