function positionElement(tmp_element,tmp_v_element){if(window.innerWidth<tmp_element.clientWidth){tmp_element.style.left='0'+"px";}else{tmp_element.style.left=(window.innerWidth-tmp_element.clientWidth-40)+"px";}
var tmp=IVES.findPos(tmp_v_element);tmp_element.style.top=tmp[1]+tmp_v_element.clientHeight+10+"px";}
function showShim(boxoverObject){}
function hideShim(boxoverObject){}
function removeHighlights(evt){if(!evt){var evt=window.event;}
var targ=(window.event)?evt.srcElement:evt.target,rel_targ=(evt.relatedTarget)?evt.relatedTarget:evt.toElement;if(!rel_targ){return;}
while(rel_targ!==targ&&'BODY'!==rel_targ.tagName){rel_targ=rel_targ.parentNode;if(rel_targ===targ){return;}}
var suggestion=document.getElementById('company_suggestions'),suggestion_list=suggestion.getElementsByTagName('div'),i=suggestion_list.length,search_cik=document.getElementById('company_search_cik');search_cik.value='';while(i--){IVES.removeClass(suggestion_list[i],'current_suggestion');}
search_cik=null;suggestion_list=null;suggestion=null;}
function highlightChoice(evt)
{var ref=IVES.getEventTarget(evt);ref=IVES.findParent(ref,'DIV');if('DIV'!==ref.tagName||ref.className.indexOf('suggestion')===-1){return;}
var suggestion=document.getElementById('company_suggestions'),suggestion_list=suggestion.getElementsByTagName('div'),search_cik=document.getElementById('company_search_cik'),i=suggestion_list.length,tmp;while(i--){tmp=suggestion_list[i];if(tmp===ref){IVES.addClass(tmp,'current_suggestion');search_cik.value=tmp.getAttribute('cik');}else{IVES.removeClass(tmp,'current_suggestion');}}
tmp=null;search_cik=null;suggestion_list=null;suggestion=null;ref=null;}
function chooseCompany(ref)
{var page_url='/0002/company-browse.php',search_row=document.getElementById('company_search_'+ref.value);document.getElementById('company_search').value=search_row.getAttribute('company');document.getElementById('company_submit').focus();window.location=page_url+'?cik='+encodeURIComponent(ref.value);search_row=null;}
function makeChoice(evt){var ref=IVES.getEventTarget(evt),search_cik=document.getElementById('company_search_cik');ref=IVES.findParent(ref,'DIV');if(ref.tagName!=='DIV'){return;}
search_cik.value=ref.getAttribute('cik');if(search_cik){chooseCompany(search_cik);}
ref=null;search_cik=null;}
function showSuggestions(){var tmp=document.getElementById('company_suggestions');if(tmp){tmp.style.visibility='visible';showShim(tmp);}
tmp=null;}
function hideSuggestions()
{var tmp=document.getElementById('company_suggestions');tmp.style.visibility='hidden';hideShim(tmp);tmp=null;}
function clearSuggestions(evt){var ref=IVES.getEventTarget(evt),suggestions=document.getElementById('company_suggestions'),search_cik=document.getElementById('company_search_cik');if('INPUT'!==ref.tagName|'visible'!==suggestions.style.visibility){search_cik.value='';}
hideSuggestions();search_cik=null;suggestions=null;ref=null;}
function searchSuggest(company_xml_node){var comp_search=document.getElementById('company_search'),search_cik=document.getElementById('company_search_cik'),result_list=company_xml_node.getElementsByTagName('company'),list_len=result_list.length,suggestion=document.getElementById('company_suggestions'),i=0,tmp_div=document.createElement('div'),tmp_table=document.createElement('table'),tmp_tbody=document.createElement('tbody'),tmp_tr=document.createElement('tr'),tmp_td=document.createElement('td'),tmp,template,tmp_cik,tmp_name,tmp_ticker,name,s_cik,s_name,s_ticker;search_cik.value='';comp_search.className='';if(''===comp_search.value){removeAllChildNodes(suggestion);positionElement(suggestion,comp_search);showShim(suggestion);return;}
tmp_ticker=tmp_td.cloneNode(false);tmp_tr.appendChild(tmp_ticker);tmp_name=tmp_td.cloneNode(false);tmp_tr.appendChild(tmp_name);tmp_cik=tmp_td.cloneNode(false);tmp_tr.appendChild(tmp_cik);tmp_tbody.appendChild(tmp_tr);tmp_table.appendChild(tmp_tbody);tmp_div.appendChild(tmp_table);tmp_div.className='suggestions';removeAllChildNodes(suggestion);suggestion.style.visibility='visible';for(i=0;i<list_len;i++){tmp=result_list[i];name=formatTextNode(tmp.getElementsByTagName('name')[0].firstChild);s_cik=formatTextNode(tmp.getElementsByTagName('s_cik')[0].firstChild);s_name=formatTextNode(tmp.getElementsByTagName('s_name')[0].firstChild);s_ticker=formatTextNode(tmp.getElementsByTagName('s_ticker')[0].firstChild);tmp_div.setAttribute('company',name);tmp_div.setAttribute('cik',tmp.getAttribute('cik'));tmp_div.setAttribute('ticker',tmp.getAttribute('ticker'));tmp_div.id='company_search_'+tmp.getAttribute('cik');tmp_ticker.className='ticker';tmp_ticker.innerHTML=s_ticker;tmp_name.innerHTML=s_name;tmp_cik.className='cik';tmp_cik.innerHTML=s_cik;suggestion.appendChild(tmp_div.cloneNode(true));}
switch(suggestion.childNodes.length){case 0:comp_search.className='error';break;case 1:break;}
positionElement(suggestion,comp_search);showShim(suggestion);result_list=suggestion.getElementsByTagName('div');i=result_list.length;while(i--){tmp=result_list[i];if(tmp.className.indexOf('suggestion')!==-1){IVES.addEvent(tmp,'click',makeChoice,false);IVES.addEvent(tmp,'mouseover',highlightChoice,false);}}
tmp_ticker=null;tmp_name=null;tmp_cik=null;template=null;tmp=null;tmp_td=null;tmp_tr=null;tmp_tbody=null;tmp_table=null;tmp_div=null;suggestion=null;result_list=null;comp_search=null;}
function findCompanies()
{var search=document.getElementById('company_search'),settings={'method':'GET','response':'XML'},search_url='/ajx/company-search.php';if(search){IVES.ajax(settings,search_url,{'s':search.value},searchSuggest);}
settings=null;search=null;}
function companyNavigation(suggestions,key_code)
{var suggestion_list=suggestions.getElementsByTagName('div'),search_cik=document.getElementById('company_search_cik'),len_list=suggestion_list.length,i=len_list,current_index=0,suggestion_class='current_suggestion',current_selected=false,change_current=false,new_index=0;while(i--){if(suggestion_list[i].className.indexOf(suggestion_class)!==-1){current_index=i;current_selected=true;}}
switch(key_code){case 37:search_cik.value='';IVES.removeClass(suggestion_list[current_index],suggestion_class);break;case 38:if(current_selected&&0!==current_index){change_current=true;new_index=current_index-1;}else{search_cik.value='';hideSuggestions();}
break;case 39:case 13:if(current_selected){search_cik.value=suggestion_list[current_index].getAttribute('cik');chooseCompany(search_cik);hideSuggestions();return;}
break;case 40:if(!current_selected){change_current=true;new_index=0;}else if(current_index+1<len_list){change_current=true;new_index=current_index+1;}
break;}
if(change_current){IVES.removeClass(suggestion_list[current_index],suggestion_class);IVES.addClass(suggestion_list[new_index],suggestion_class);search_cik.value=suggestion_list[new_index].getAttribute('cik');}
suggestion_list=null;search_cik=null;}
function companyKeyCheck(evt){var key_code=(window.event)?event.keyCode:evt.keyCode,suggestions=document.getElementById('company_suggestions');if('visible'===suggestions.style.visibility&&key_code>=37&&key_code<=40){companyNavigation(suggestions,key_code);}else{findCompanies();}
key_code=null;suggestions=null;}
function validateCompanySearch(evt){var ref=IVES.getEventTarget(evt),search_cik=document.getElementById('company_search_cik');if('FORM'!==ref.tagName){return;}
if(search_cik&&search_cik.value){chooseCompany(search_cik);IVES.cancelEvent(evt);return false;}
ref.company_name.value=ref.company_search.value;search_cik=null;ref=null;return true;}
function initCompanyLookup(){var tmp=document.getElementById('company_search');if(tmp){tmp.setAttribute('autocomplete','off');}
tmp=document.getElementById('company_search');if(tmp){IVES.addEvent(tmp,'keyup',companyKeyCheck,false);}
tmp=document.getElementById('frm_company_lookup');if(tmp){IVES.addEvent(tmp,'submit',validateCompanySearch,false);}
tmp=document.getElementById('company_suggestions');if(tmp){IVES.addEvent(tmp,'mouseout',removeHighlights,false);}
IVES.addEvent(document,'click',clearSuggestions,false);tmp=null;}
