var common = new Object();

common.fakeAttributeSelectors = function() {
	/* IE <= v6 doesn't support attribute selectors, e.g. input[type='checkbox'], so
	we run a script to add classes to input fields equal to their type, in order to
	target them with css.

	based on http://www.dustindiaz.com/styling-inputs/
	*/
	if ( !document.getElementsByTagName )
		return;
	var inputs = document.getElementsByTagName('input');
	var inputLen = inputs.length;
	for ( i=0;i<inputLen;i++ ) {
		if ( inputs[i].getAttribute('type') )
		inputs[i].className += ' '+inputs[i].getAttribute('type');
	}
}

common.getTarget = function(e) {
	var target;
	if (!e) var e=window.event;
	if (e.target) target=e.target;
  	if (e.srcElement) target=e.srcElement;
	if (target.nodeType==3) target = target.parentNode; // defeat Safari bug
	return target;
}

common.showSpinner = function() {
	$('progress_spinner_container').style.display = 'block';
}

common.showSpinnerDelayed = function(ms) {
	common.spinnerWait = setTimeout("common.showSpinner()", ms);
}

common.hideSpinner = function() {
	if (common.spinnerWait)
		clearTimeout(common.spinnerWait);
	$('progress_spinner_container').style.display = 'none';
}

common.errorAlert = function() {
	alert("There was an unexpected error. Please reload the page and try again. If the error persists, please contact webmaster@axonadvisors.com, explaining the situation in which the error occurred. We apologize for the inconvenience.");
}

window.addEvent('domready', function() {
	// all form elements with .clearInitial will have their contents cleared on focus once
	$$('.clearInitial').addEvent('focus', function(e) {
		var target = common.getTarget(e);
		target.value = '';
		$(target).removeEvents('focus');
	});
});

window.addEvent('load', function() {
	common.fakeAttributeSelectors();
	
	$$('.selectall').each(function(el) {
		el.addEvent('click', function(ev) {
			this.focus();
			this.select();
		})
	})
});