﻿/*---------- 
BETNOWFINDER
----------*/

/*---------- 
VALIDATION
----------*/
sBetNowFinderFormId = 'bnw-finder-form';
sBetNowFinderLabelId = 'bnw-finder-label';
sBetNowFinderQueryInput = 'search-term';
sBetNowFinderDefault = 'default';
sValidationMsg = '<span class="error-warning">&#160;</span>Please enter a sport, event or team name.';

document.addEvent('domready', function(){
    var eForm = $( sBetNowFinderFormId );
    if ( eForm ){
        eForm.addEvent('submit', function( e ) {
            var eLabel = $( sBetNowFinderLabelId );
            var sQueryInput = $( sBetNowFinderQueryInput );
            if ( sQueryInput ){
                var sQuery = sQueryInput.value.trim();
                //var sDefault = $( sBetNowFinderDefault ).value;
                //if (( sQuery.length == 0 ) || ( sDefault == sQuery )) {
                if (( sQuery.length == 0 ) ) {
                    eLabel.set('html', sValidationMsg);
                    eLabel.setStyle('color', '#008000');
                    sQueryInput.focus();
                    e.stop();
                }
                else
                {
                    eLabel.setStyle('color', '#c13036');
                }
            }
        });
    }
}); 

/*---------- 
AUTOSUGGEST
----------*/
/*
document.addEvent('domready', function() {
    
    var inputWord = $$('input.betNowFinder')[0]; // presuming betnowfinder is always gonna be the first input with class="textfield" in DOM
	
	// refer to http://www.clientcide.com/docs/3rdParty/Autocompleter for complete list of options
	
	new Autocompleter.Request.HTML(inputWord, '/Customer/AutocompleterFeed.aspx', {
		'indicatorClass': 'autocompleter-loading',
		'width': '359px',
		'markQuery': 'true',
		'postVar': 'findBox', // input to post
		'injectChoice': function(choice) {
			// choice is one li element
			var text = choice.getFirst();
			// the first element in this li is the span with the text
			var value = text.innerHTML;
			// inputValue saves value of the element for later selection
			choice.inputValue = value;
			// overrides the html with the marked query value (wrapped in a span)
			text.set('html', this.markQueryValue(value));
			// add the mouse events to the li element
			this.addChoiceEvents(choice);
		}
	});
});
*/