var currentSelection=-1;var docRef=null;var consoleRef=null;var resultsWindow=null;$(document).ready(function(){$('#selected_symbol').val("");$('#selected_symbol').keyup(function(e){switch(e.keyCode){case 38:navigate('up');break;case 40:navigate('down');break;case 13:var symStr=($("#autosuggest_list ul li").eq(currentSelection).text());var separator="-";symStr.toLowerCase();var array=symStr.split(separator);var selSym=array[0];stocksymbol=selSym.replace(/^\s+|\s+$/g,'');$("input#selected_symbol").val(stocksymbol);$('#selected_symbol').val(stocksymbol);$('#autosuggest_list').fadeOut(800);break;default:var searchStr=$('#selected_symbol').val();autosuggest(searchStr)}});$("#ajax-form").submit(function(e){$('#analysis').addClass('loading');e.preventDefault();$.post("stockanalysis/ci-index.php/ajax/submit",{selected_symbol:$("#selected_symbol").val()},function(data){if(data){$('#analysis').removeClass('loading');var tablestruct='<table class="analysistable" id="analysistable">'+data+'</table>';writeConsole($("#selected_symbol").val(),tablestruct)}})});for(var i=0;i<$("#autosuggest_list ul li").size();i++){$("#autosuggest_list ul li").eq(i).data("number",i)}$("#autosuggest_list ul li").hover(function(){currentSelection=$(this).data("number");setSelected(currentSelection)},function(){$("#autosuggest_list ul li").removeClass("itemhover")})});function setSelected(listitem){$("#autosuggest_list ul li").removeClass("itemhover");$("#autosuggest_list ul li").eq(listitem).addClass("itemhover")}function set_symbol(symbol_name){$('#selected_symbol').val(symbol_name);setTimeout("$('#autosuggest_list').fadeOut(500);",250)}function autosuggest(str){if(str!=null){if(str.length==0){$('#autosuggest_list').fadeOut(500)}else{$('#select_stock').addClass("loading");$.post('stockanalysis/ci-index.php/ajax/autosuggest',{'str':str},function(result){if(result){$('#autosuggest_list').html(result);$('#select_stock').removeClass("loading");$('#autosuggest_list').slideDown(1000,null);currentSelection=-1}})}}}function navigate(direction){if($("#autosuggest_list ul li .itemhover").size()==0){}if($("#autosuggest_list ul li").size()==0){currentSelection=-1}if(direction=='up'&&currentSelection!=-1){if(currentSelection!=0){currentSelection--}var symStr=($("#autosuggest_list ul li").eq(currentSelection).text());var separator="-";symStr.toLowerCase();var array=symStr.split(separator);var selSym=array[0];stocksymbol=selSym.replace(/^\s+|\s+$/g,'');$("input#selected_symbol").val(stocksymbol);$('#selected_symbol').val(stocksymbol)}else if(direction=='down'){if(currentSelection!=$("#autosuggest_list ul li").size()-1){currentSelection++}var symStr=($("#autosuggest_list ul li").eq(currentSelection).text());var separator="-";symStr.toLowerCase();var array=symStr.split(separator);var selSym=array[0];stocksymbol=selSym.replace(/^\s+|\s+$/g,'');$("input#selected_symbol").val(stocksymbol);$('#selected_symbol').val(stocksymbol)}setSelected(currentSelection)}function openResultsWindow(symbol,content){if(navigator.userAgent.indexOf('Chrome/')>0){if(resultsWindow){resultsWindow.close();resultsWindow=null}}resultsWindow=window.open('','Analyses','width=700,height=650,left=380,top=50,resizable,menubar=1,scrollbars=1');if(resultsWindow!=null){resultsWindow.document.write("<html><meta content=\"\"  charset=\"UTF-8\" />"+"<title>"+symbol+" : Share Navigator analyses</title>"+"<html xmlns=\"http://www.w3.org/1999/xhtml\">"+"<head profile=\"http://gmpg.org/xfn/11\">"+"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=EmulateIE7\" />"+"<meta name\keywords\" content=\"\"/>"+"<meta name=\"keyphrases\" content=\"\"/>"+"<meta name=\"Owner\" content=\"Share Navigator\" />"+"<meta name=\"author\" content=\"Keith Nolan (keith@reconfigr.com)\"   />"+"<meta http-equiv=\"content-language\" content=\"en-GB\" />"+"<meta name=\"robots\" content=\"index, follow\"/>"+"<meta name=\"distribution\" content=\"global\"/>"+"<meta name=\"resource-type\" content=\"document\"/>"+"<meta name=\"rating\" content=\"Safe for Kids\"/>"+"<link rel=\"stylesheet\" href=\"http://www.sharenavigator.ie/stockanalysis/css/styles.css\" type=\"text/css\" media=\"screen\" />"+"<link type=\"text/css\" href=\"css/styles.css\" rel=\"stylesheet\" />"+"<script type=\"text/javascript\"></script>"+"</head>"+"<body class=\"analysisbody\" onLoad=\"self.focus()\">"+"<div id=\"resultsheader\">"+"<img src=\"http://www.sharenavigator.ie/images/ShareNavigator-Logo.gif\" alt=\"Stock Market Training\" />"+"</div>"+content+"</body></html>");resultsWindow.focus();resultsWindow.document.close()}else{}}function writeConsole(symbol,content){openResultsWindow(symbol,content)}
