function setupRtsObserver() {
	if(RunTillSold.enabled) {
		rts = new rtsObserver();
		if(view != 'newad') {
			rts.observeRts();
		}
	} else {
		console.log('RunTillSold is disabled.');
	}
	
	
}
var rtsObserver = Class.create();
rtsObserver.prototype = {
	initialize: function() {
		this.catSelect = $('ClassifiedAdClassifiedChildCatId');
		this.totalWeeks = $('ClassifiedAdBillTotalWeeks');
		this.billableWeeks = $('ClassifiedAdBillBillableWeeks');
		this.oldTotalWeeks = null;
		this.oldBillableWeeks = null;
		this.rtsElement = $('ClassifiedAdBillIsRts');
		this.rtsContainer = $('runtillsold');
		this.catData = catrates;  // Array from adcostJS.ctp
		this.checkRtsAbility.bind(this);
		this.checkRtsStatus.bind(this);
		this.hideRtsContainer.bind(this);
		this.showRtsContainer.bind(this);
		if(this.checkRtsAbility() || this.checkRtsStatus()) {
			this.showRtsContainer();
		} else {
			this.hideRtsContainer();
		}
		this.catSelect.observe('change', this.observeCats.bind(this));
		this.rtsElement.observe('change', this.observeRts.bind(this));
	},
	
	observeCats: function() {
		if(this.checkRtsAbility() == true) {
			this.showRtsContainer();
		} else {
			this.hideRtsContainer();
		}
		//ac.calcCost();
		refreshPreview(true);

		
	},
	
	observeRts: function() {
		if(this.rtsElement.checked) {
			//backup current week data (if any)
			this.oldTotalWeeks = this.totalWeeks.value;
			if(!null === this.billableWeeks) {
				this.oldBillableWeeks = this.billableWeeks.value;
			}
			
			this.totalWeeks.value = RunTillSold.totalWeeks;
			this.billableWeeks.value = RunTillSold.billedWeeks;
			hideWeekEditButton();
			
			if($('rundates')) {
				//hide rundates and show alternate rundate info
				$('rundates').hide();
				$('altrundates').innerHTML = '<p>With the run til sold option, the ad will run for 12 weeks.  The weekly rate will be billed for 4 weeks. All enhancements (bold words, images, borders, links, over word limit) will be billed for 6 weeks</p>';
				$('altrundates').show(); //just in case it's hidden
				//also hide the add weeks form fields -- not needed
				$('addweeks').hide();
			}
		} else {
			//restore old week data (if any)
			if(this.oldTotalWeeks && this.oldBillableWeeks) {
				this.totalWeeks.value = this.oldTotalWeeks;
				this.billableWeeks.value = this.oldBillableWeeks;
			}
			if($('rundates')) {
				$('rundates').show();
				$('altrundates').hide();
				$('addweeks').show();
			}
		}
		ac.calcCost();
	},
	
	checkRtsAbility: function() {
		var currentCatId = this.catSelect.value;
		if(currentCatId) {
			if(this.catData[currentCatId].is_rts) {
				return true;
			}
		}
		
		return false;
	},
	
	checkRtsStatus: function() {
		if(this.rtsElement.checked) {
			return true;
		}
		return false;
	},
	
	hideRtsContainer: function() {
		this.rtsContainer.hide();
	},
	
	showRtsContainer: function() {
		this.rtsContainer.show();
	}
};
