function initServerConfiger(form) {
	$$('#' + form + ' .step').each( function(option) {
		option.getElements('.item').each( function(item) { 
			item.addEvent('click', function() {
				setSelected(this);
				comparePrices(this);
				updateTotal(true);
				updateSetup(true);
			}.bind(item));
		});
		
		comparePrices(option);
	});

	updateTotal(false);
	updateSetup(false);
}

function comparePrices(ele) {
	var obj = root = $(ele);
	if(!$chk(obj)) return false;
	
	//Find option item
	while(root.get('tag') != 'li') {
		root = root.getParent();
		if(!root) return false;
	}
	
	//Find selected item
	var currPrice;
	root.getElements('input').each( function(item) {
		if(item.get('type') == 'radio' && item.checked)	{
			currPrice = item.getParent().getElement('.price').get('text');
			if(currPrice != 'free' && currPrice != 'included') {
				currPrice = currPrice.toInt();
			} else {
				currPrice = 0;
			}
		}
	});
	if(!$chk(currPrice)) return false;
	
	//calculate the price comparisons and show it
	root.getElements('div').each( function(item) {
		var text;
		var price = item.getElement('.price').get('text');
		if(price != 'free' && price != 'included') {
			price = price.toInt();
		} else {
			price = 0;
		}
		
		var diff = price - currPrice;
		if(diff > 0) {
			text = "add $" + diff;
		} else if(diff < 0) {
			text = "subtract $" + -diff;
		} else {
			text = "";
		}
		
		if(item.getElement('.price').get('text') == 'included') {
			text = text=="" ? "[included]" : "[included, " + text + "]";
		} else if(text != "") {
			text = "[" + text + "]";
		}
		item.getElement('.compare').set('text', text);
	});
}

function setSelected(ele) {
	var obj = root = $(ele);
	
	//Find root item
	while(root.get('tag') != 'li') {
		root = root.getParent();
		if(!root) return false;
	}
	
	//remove the style from all elements
	root.getElements('.item').each( function(item) {
		if(item.hasClass('selected'))
			item.removeClass('selected');
	});
	
	// add the style for this element and set the radio button
	obj.getElement('input').set('checked', true);
	obj.addClass('selected');
}



function updateTotal(highlight) {
	var total = 0;
	$$('#managed .monthly .item').each( function(item) {
		if(item.getElement('input').checked) {
			var text = item.getElement('.price').get('text');
			total += text=='free' || text=='included' ? 0 : text.toFloat();
		}
	});
	total = total.round(2).toFixed(2);
	if($('total').get('text') != "$"+total) {
		$('total').set('text', "$"+total);
		if(highlight) $('total').highlight('#6c6');
	}
}

function updateSetup(highlight) {
	var total = 0;
	$$('#managed .onetime .item').each( function(item) {
		if(item.getElement('input').checked) {
			var text = item.getElement('.price').get('text');
			total += text=='free' || text=='included' ? 0 : text.toFloat();
		}
	});
	total = total.round(2).toFixed(2);
	if($('setup').get('text') != "$"+total) {
		$('setup').set('text', "$"+total);
		if(highlight) $('setup').highlight('#6c6');
	}
}

