/*Element.implement({
	getSelected: function(){
		return new Elements($A(this.options).filter(function(option){
			return option.selected;
		}));
	}
});*/

function refineSearch( myForm, myDiv ) {
	new Ajax( 'http://www.stihlcareers.com/refineSearch.php?' + $(myForm).toQueryString(), {
		update: $(myDiv),
		method: 'get'
	} ).request();
}

var appCounter = 0;
var sections = 6;
var edTypes = [];
edTypes[0] = 'a High School Diploma or Equivalent';
edTypes[1] = 'an Associates Degree';
edTypes[2] = '1 to 3 Years College/University';
edTypes[3] = 'a Bachelor\'s Degree';
edTypes[4] = 'a Master\'s Degree';
edTypes[5] = 'a Doctorate';

function updateAppCounter() {
	appCounter++;
	if( appCounter >= sections && checkRequirements() === true ) {
		$('resumeSection').setStyle( 'display', 'block' );
	} else if( appCounter >= sections && checkRequirements() === false ) {
		$('resumeSection').setStyle( 'display', 'none' );
		//alert( 'A Bachelor\'s Degree is required for this position.' );
	}
	return;
}

function checkRequirements() {
	var vals = null, 
		ret = true,
		req = 0;
	if( breq && breq[$('position').getValue()] && breq[$('position').getValue()] > 0 ) {
		req = breq[$('position').getValue()];
		ret = false;
		if( $('degree') && $('degree').getValue() != '' ) {
			vals = $('degree').getValue();
			if( vals instanceof Array ) {
				vals.each( function(el) {
					if( el >= req ) {
						ret = true;
					}
				});
			} else if( vals >= req ) {
				ret = true;
			}
		}
	} 
	return ret;	
} 

function alertRequirements() {
	if( checkRequirements() === false ) {
		alert( 'A minimum of ' + edTypes[breq[$('position').getValue()]] + ' is required for this position.' );
	}
}

window.addEvent('domready', function() {
	var appEls = ['degree', 'discipline', 'institution', 'certifications', 'bsoftware', 'language', 'competencies'];
	appEls.each(function(item, index) {
		if( item && $(item) && $(item).getValue() != '' ) {
			updateAppCounter();
		}
	});	
});