
// receives the unique object id which also includes the target serial/model number.
function addRemv( FormId )
{
	// pass the varialbes to the CFC
var action = "remv";
var obj = document.getElementById(FormId);
var modelNum = obj.id.replace('checkBox-','');
if (obj.className == "brochureCheckBox" ){
	action = "add"
}
			 
http("POST", "/CFC/brochureControl.cfc", addRemv_Callback,
		'method=brochureModelAction'
		+ '&action=' + action
		+ '&modelNum=' + modelNum
		+ '&id=' + obj.id
	);

}

// process the 'addRemv' return from the CFC
function addRemv_Callback(result) {
	
	if (result.match('ERROR_01')) {
				alert("Brochure is full! Try removing something first.");
	}else if (result) {
		var obj = document.getElementById('checkBox-'+result);
			if (obj.className == "brochureCheckBox" ){
				obj.className = "brochureCheckBoxChecked";
			} else {
				obj.className = "brochureCheckBox";
			}
		updateBrochureListings();
	}
}

// Returns the number of homes in the brochure
function updateBrochureListings(){
	// sent request
	http("POST","/CFC/brochureControl.cfc", updateBrochureListings_Callback, 'method=updateBrochureListing');

}
// Process return request, sets the counter to the result and then checks to see if the 
// associated sentence should be plural or singular
function updateBrochureListings_Callback(result) {
	document.getElementById('brochList').innerHTML = result;
	document.getElementById('brochList2').innerHTML = result;
	if(result == 1)
	{
		document.getElementById('brochListText').innerHTML = "home in your brochure";
		document.getElementById('brochList2Text').innerHTML = "home in your brochure";
	}
	else{
		document.getElementById('brochListText').innerHTML = "homes in your brochure";
		document.getElementById('brochList2Text').innerHTML = "homes in your brochure";
	}
	
}
