
/**
 * Autocomplete Javascript.
 * ['londonsearchbusiness', 'Business Search', 'wfSACBusiness'],
 */

window.addEvent('domready', function(){
  var ls = [
    ['londonsearchinput', 'Search Takeaways - Location or Postcode', 'wfSACTopic']
  ];
  var dEvent = '';
  ls.each(function(el) {
    $(el[0]).value = el[1];
    $(el[0]).addEvent('blur', function(e) {
      if ($(el[0]).value == '')
        $(el[0]).value = el[1];
    });
    $(el[0]).addEvent('focus', function(e) {
      if ($(el[0]).value == el[1])
        $(el[0]).value = '';
    });
    var completer1 = new Autocompleter.Ajax.Json($(el[0]), wgScriptPath + '/', {
      delay: 2,
      minLength: 2,
      postData: {action:'ajax',rs: el[2] },
      ajaxOptions: {method:'get',onComplete:function(resp,st){tokens=Json.evaluate(resp)}},
      postVar: 'rsargs',
      injectChoice: function(choice) {
        var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
        el.inputValue = choice[0];
        this.addChoiceEvents(el).injectInside(this.choices);
      },
      onSelect: function(choice) {
        tokens.each(function(tok){
          if(tok[0]==choice.value){
	    window.location = tok[2];
	  }
        });
      }
    });
  });
  
   /*NP >>*/
  if($('businessname')){
  	 var completerBus = new Autocompleter.Ajax.Json('businessname', wgScriptPath + '/', {
        delay: 2,
        minLength: 1,
        postData: {action:'ajax',rs: 'wfSACBusiness' },
        postVar: 'rsargs',
        ajaxOptions: {method:'get',
          onComplete:function(resp,st){
            tokens=Json.evaluate(resp);
          }
        },
        injectChoice: function(choice) {
          var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
          el.inputValue = choice[0];
          this.addChoiceEvents(el).injectInside(this.choices);
        },
        onSelect: function(choice) {
       
        }
     });

  }
  /* << NP*/
  
  if($('fe-eventtype')){
    var completermain = new Autocompleter.Ajax.Json('fe-eventtype', wgScriptPath + '/', {
        delay: 2,
        minLength: 1,
        postData: {action:'ajax',rs: 'wfSACEventType' },
        postVar: 'rsargs',
        ajaxOptions: {method:'get',
          onComplete:function(resp,st){
            tokens=Json.evaluate(resp);
          }
        },
        injectChoice: function(choice) {
          var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
          el.inputValue = choice[0];
          this.addChoiceEvents(el).injectInside(this.choices);
        }
     });
   }
   if($('specialisation1')){
     var completerEvA = new Autocompleter.Ajax.Json('specialisation1', wgScriptPath + '/', {
              delay: 100,
              minLength: 1,
              postData: {action:'ajax',rs: 'wfSACSpecialisation_1'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
   }
     
   if($('specialisation2')){
     var completerEvB = new Autocompleter.Ajax.Json('specialisation2', wgScriptPath + '/', {
              delay: 100,
              minLength: 1,
              postData: {action:'ajax',rs: 'wfSACSpecialisation_2'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
   }
      
   if($('specialisation3')){
    var completerEvC = new Autocompleter.Ajax.Json('specialisation3', wgScriptPath + '/', {
              delay: 100,
              minLength: 1,
              postData: {action:'ajax',rs: 'wfSACSpecialisation_3'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
  }

  if($('fe-sector')){
    var completermain = new Autocompleter.Ajax.Json('fe-sector', wgScriptPath + '/', {
        delay: 2,
        minLength: 2,
        postData: {action:'ajax',rs: 'wfSACSector' },
        postVar: 'rsargs',
        ajaxOptions: {method:'get',
          onComplete:function(resp,st){
            tokens=Json.evaluate(resp);
          }
        },
        injectChoice: function(choice) {
          var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
          el.inputValue = choice[0];
          this.addChoiceEvents(el).injectInside(this.choices);
        }
     });
  }

  if($('fe-specialisation1')){
     var completer2a = new Autocompleter.Ajax.Json('fe-specialisation1', wgScriptPath + '/', {
              delay: 100,
              minLength: 2,
              postData: {action:'ajax',rs: 'wfSACSpecialisation1'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
  }

  if($('fe-specialisation2')){
     var completer2b = new Autocompleter.Ajax.Json('fe-specialisation2', wgScriptPath + '/', {
              delay: 100,
              minLength: 2,
              postData: {action:'ajax',rs: 'wfSACSpecialisation2'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
   }
   
  if($('fe-specialisation3')){
     var completer2c = new Autocompleter.Ajax.Json('fe-specialisation3', wgScriptPath + '/', {
              delay: 100,
              minLength: 2,
              postData: {action:'ajax',rs: 'wfSACSpecialisation3'},
              postVar: 'rsargs',
              ajaxOptions: {method:'get',
                onComplete:function(resp,st){
                  tokens=Json.evaluate(resp);
                }
              },
              injectChoice: function(choice) {
                var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
                el.inputValue = choice[0];
                this.addChoiceEvents(el).injectInside(this.choices);
              }
           });
  } 

  if($('venue-input')){
	var aucvenue = new Autocompleter.Ajax.Json('venue-input',wgScriptPath + '/',{
		delay: 1000,
		minLength: 1,
		postData: {action: 'ajax',rs: 'wfACgetVenue'},
		postVar: 'rsargs',
		ajaxOptions: {method:'get',
            onComplete:function(resp,st){
              tokens=Json.evaluate(resp);
            }
          },
          injectChoice: function(choice) {
            var el = new Element('li').setHTML(this.markQueryValue(choice[0]));
            el.inputValue = choice[0];
            this.addChoiceEvents(el).injectInside(this.choices);
          }
	});
  }

  

}); 



