// JavaScript Document var json_company_list = [ {"name":"Communisis Plc","url":"communisis", "epic": "(CMS)"}, {"name":"Daisy Group plc","url":"daisy-group-plc", "epic": "(DAY)"}, {"name":"Gresham Computing Plc","url":"gresham-computing-plc", "epic": "(GHT)"}, {"name":"IDOX Plc","url":"idox-plc", "epic": "(IDOX)"}, {"name":"Intelligent Environments Group Plc","url":"intelligent-environments-group-plc", "epic": "(IEN)"}, {"name":"K3 Business Technology Group Plc","url":"k3-business-technology-group-plc", "epic": "(KBT)"}, {"name":"Maxima Holdings Plc","url":"maxima-holdings-plc", "epic": "(MXM)"}, {"name":"Monitise Plc","url":"monitise-plc", "epic": "(MONI)"}, {"name":"Norcon plc","url":"norcon-plc", "epic": "(NCON)"}, {"name":"Parity Group Plc","url":"parity-group-plc", "epic": "(PTY)"}, {"name":"Portrait Software Plc","url":"portrait-software-plc", "epic": "(PST)"}, {"name":"Trafficmaster Plc","url":"trafficmaster-plc", "epic": "(TFC)"}, {"name":"Workplace Systems International","url":"workplace-systems-international", "epic": "(WSI)"}, {"name":"Xploite Plc","url":"xploite-plc", "epic": "(XPT)"}]; window.addEvent('domready',function() { $('company_search').addEvent('keydown', function(event){ if(event.key == "down"){ if($('options').style.display != "none"){ var options = $('options').getChildren('span'); if(options.length > 0){ var selectKey = 0; $each(options, function(value, key){ if(value.className == "option-company-over"){ value.className = "option-company"; selectKey = key+1; } }); if(selectKey > options.length - 1) selectKey = 0; options[selectKey].className = "option-company-over"; } } } else if(event.key == "up"){ if($('options').style.display != "none"){ var options = $('options').getChildren('span'); if(options.length > 0){ var selectKey = 0; var rev = new Array(); for(var i = options.length - 1; i >= 0; i--){ rev.push(options[i]); } $each(rev, function(value, key){ if(value.className == "option-company-over"){ value.className = "option-company"; selectKey = key+1; } }); if(selectKey > rev.length - 1) selectKey = 0; rev[selectKey].className = "option-company-over"; } } } if(event.key == "enter"){ var options = $('options').getChildren('span'); if(options.length > 0){ $each(options, function(value, key){ if(value.className == "option-company-over"){ $('company_search').value = value.innerHTML; gotoCompany(value.id); } }); } } }); }); function getMatchingCompanies( query ) { var response = new Object(); response.query = query; response.results = new Array(); json_company_list.each( function(company){ if( company.name.toLowerCase().indexOf(query.toLowerCase()) >= 0 ) { response.results.push(company); } }); if(response.results.length < 1){ response.results.push({"name":"No results found for "+query+"", "url":"null"}) } return response; } function gotoCompany(url){ if(url == "null") return false; else window.location = "/tearsheet/"+url; } function matchCheck(input){ var matches = null; if(input.value.length > 1) matches = getMatchingCompanies(input.value); if(matches){ if( !$('options') ) { $('top_nav').setStyles({'position':'relative'}); new Element( 'div', {'id': 'options'}) .inject( $(document).getElement('input#company_search'), 'after' ) .setStyles({ 'top': 16 + 'px', 'left': 176 + 'px', 'display': 'block', 'overflow-x': 'hidden', 'position':'absolute' }); } else $('options').setStyles({'display':'block'}); $('options').empty(); var index = 0; for(var i = 0; i < matches.results.length; i++){ var text = ""; if(matches.results[i].url == "null") text = matches.results[i].name; else text = matches.results[i].name; index = i; new Element('span', {'id':matches.results[i].url, 'class':'option-company', 'html':text, 'events': { 'click': function(){ if(this.id != "null"){ $('company_search').value = this.innerHTML; $('options').style.display = "none"; gotoCompany(this.id); } }, 'mouseover':function(){ this.className = 'option-company-over'; }, 'mouseout':function(){ this.className = 'option-company'; } } }) .inject($('options'), 'bottom'); } } else { if($('options')) $('options').setStyles({'display':'none'}); } }