﻿function doSICSearchKeyDown(){
    if($F('txtSICSearch').length > 2){
        doSICSearch();
    }
    return false;
}
function doSICSearch()
{
    var oSIC = new SICcode();
    var sSearchTerms = $F('txtSICSearch');
    var oSearchResults = oSIC.getByQuery(sSearchTerms);
    var iResultCount = oSearchResults.length;
    var SICsearch = $('SIC-search');
    var sResults = '';
    var sQuote = "'";
    
    var divMore = $('SIC-search-more');
    
//    if(iResultCount > 10){
//          divMore.innerHTML = iResultCount + ' matches found. <a href="#" onclick="return doViewAll();">View all</a>';
//          divMore.style.display = 'block';                  
//    } else {
//        divMore.style.display = 'none';
//    }                  
                    
    if(iResultCount > 0){
     
        for(var i = 0; i < iResultCount; i++)
        {
            var displaySIC = "'" + oSearchResults[i].SICcode + " - " + oSearchResults[i].Description.replace(/\'/g,String.fromCharCode(92,39)) + "'"
            var displaySICCode = "'" + oSearchResults[i].SICcode + "'"
            sResults += '<li id="SIC-search'+ oSearchResults[i].SICID + '" class="SIC-search'+ oSearchResults[i].SICID + '"'
            
            //if(i > 10){
           //     sResults += ' style="display: none; padding-bottom:10px;" ';
            //} else {
                sResults += ' style="padding-bottom:10px;" ';
            //}
            
            sResults += '><a href="#" onclick="return doSICAdd(' + oSearchResults[i].SICID + ', ' + displaySICCode + ');" title="add this SIC"><img src="http://static.zubed.com/images/icons/add.gif" /> <span>' +  oSearchResults[i].SICcode + " - " + oSearchResults[i].Description + '</span></a></li>';
        }
       
        SICsearch.style.height = '300px';
    } else {
        sResults = '<li>No matching SICs found1</li>';
        SICsearch.style.height = '20px';
    }
    SICsearch.innerHTML = sResults;
    SICsearch.style.display = 'block';
    
    $('SIC-searchintro').style.display = "block";
}

function doViewAll()
{
    var ulSearchResults = $('SIC-search');
    
    var el = ulSearchResults.immediateDescendants();
    var count = el.length;
    var ret = -1;
    for(var i = 0; i < count; i++) {
        el[i].style.display = "block";
    }
    $('SIC-search-more').style.display = "none";
}

//function doSICDisplay()
//{
//    var oRequirement = new Requirement();
//    var oSearchResults = oRequirement.getSICs(iMemberID, iRequirementID);
//    var iResultCount = oSearchResults.length;
//    var sResults = '';
//    
//    if(iResultCount > 0){
//        
//        for(var i = 0; i < iResultCount; i++)
//        {
//            sResults += '<li id="SIC'+ oSearchResults[i].SICID + '"><a href="#" onclick="return doSICRemove(' + oSearchResults[i].SICID + ');" title="Remove this SIC"><img src="http://static.zubed.com/images/icons/delete.gif"/></a> ' +  oSearchResults[i].SIC + '</li>';
//        }
//       
//        
//    } else {
//        sResults = '<li>You have not selected any SICs for this requirement.</li>';
//    }
//    $('SIC-selected').innerHTML = sResults;
//    
//}

