//Start Omniture Reporting Test
function get_search_facets(url) {
	var params = url.match(/(?:index_html\/)(\S+)/);
	return (!params) ? ['no facets'] : $A(params[1].split('/')).invoke('match', /[^\+]+/).flatten().sort();

}

function get_project_name(url) {
	var name =  url.match(/directories\/([^\/]+)/)
	return (name)?name[1]:'unknown: ' + url.substr(0,60);
}

//s.prop7 = get_project_name(window.location.href) + ': ' + get_search_facets(window.location.href).join(', ')
//End Omniture Reporting Test

/*
Event.observe(window, 'load', function() {
var dfn_containers = $A([document.getElementsByClassName('rankingTable'),document.getElementsByClassName('control')]).flatten()
	set_definitions(dfn_containers);
});
*/

function handle_form(form_container, status) {
	if (status != 'disable' && status !='enable') { return false; }
	$A(form_container.getElementsByTagName('input')).invoke(status);
	if (status == 'disable') {
		$A(form_container.getElementsByTagName('label')).each( function(label){
				var input = label.getElementsByTagName('input')[0];
				if (input.type == 'text') {
					input.value = '$';
				}
				else { input.checked = false; }
				Event.observe(label, 'click', notify);
		} );
	}
	else {
		$A(form_container.getElementsByTagName('label')).each( function(label){
				Event.stopObserving(label, 'click', notify);
		} );	
	}
}

function notify(evt) {
	evt = (arguments[0].target)?arguments[0].target:arguments[0].srcElement;
	rating_control = evt.parentNode.getElementsByClassName('rating_control')[0];
	weight_warning = new Warning($('warning'), 'Please use these stars to select the importance of this category first.');
	weight_warning.raise_intermittent(rating_control, 4);
}

function serialize_controls() {

	function validate(control, validator) {
		if (!values[control] || typeof validator != 'function') { return; }
		//values[control] = validator(values[control])
	}
	function price_check(price) {
		if (price.value == "$" || price.value.length == 0) { return null; }
		price.value = price.value.replace(/,/, ''); //commas are legal, but we'll remove them
		price.value = price.value.replace(/\$/, ''); //asme for '$'.
		if ( price.value.match(/[^0-9]+/) ) {
			validation_failure_flag = "Home price must be a number. You entered " + price.value + ".";
			validation_failure_point = price
			return null;
		}
	}
	
	validation_failure_flag = false;
	validation_failure_point = null;
	values = document.data_parms;
	validate('home_price', price_check);
	values = values.serialize()
	sorted_weights = $H(weights).keys().sort(); //for caching purposes, URI param ordering should be consistent
	sorted_weights.each( function(weight) {
		        values += "&" + encodeURI(weight) + "=" + encodeURI(weights[weight].value);
		});

	if (validation_failure_flag) {
		
		field_validation_warning =  new Warning($('warning'), validation_failure_flag);
		field_validation_warning.raise(validation_failure_point, 6, [120, 0]);
	}

	else { window.location = 'http://www.usnews.com/directories/retirement/index_html?' + values; }
}

function reportToOmniture(sPropNumber, value) {
	s['prop' + sPropNumber] = value
}
