function SymbolCompleteSort(){};
SymbolCompleteSort.VOLUME_200_DAY_AVERAGE = 0;
SymbolCompleteSort.SYMBOL = 1;
SymbolCompleteSort.MARKET_CAPITALIZATION = 2;
SymbolCompleteSort.ADJUSTED_VOLUME_200_DAY_AVERAGE = 3;
SymbolCompleteSort.CURRENCY_ADJUSTED_VOLUME_200_DAY_AVERAGE = 4;
SymbolCompleteSort.CURRENCY_ADJUSTED_MARKET_CAPITALIZATION = 5;
SymbolCompleteSort.ADJUSTED_VOLUME_200_DAY_AVERAGE_UK = 6;
SymbolCompleteSort.ADJUSTED_VOLUME_200_DAY_AVERAGE_AU = 7;
SymbolCompleteSort.ADJUSTED_VOLUME_200_DAY_AVERAGE_CA = 8;

function SymbolComplete()
{
    this.myDataSource = null;  
    this.myAutoComp = null;  
    this.count = 0;
    this.domain = "";
    this.pushSymbolsToTop = "";
    this.sort = SymbolCompleteSort.VOLUME_200_DAY_AVERAGE;
    this.allowcountries = "";
    this.allowsymboltypes= "";
    this.allowexchanges= "";
    this.augmentYuiConnect();
};

SymbolComplete.prototype.SetAllowCountries = function(s){ 
    this.allowcountries = s;
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 
SymbolComplete.prototype.SetAllowSymbolTypes = function(s){
    this.allowsymboltypes = s;
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 
SymbolComplete.prototype.SetAllowExchanges = function(s){
    this.allowexchanges = s;
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 

SymbolComplete.prototype.SetSort = function(s){
    this.sort = s;
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 

SymbolComplete.prototype.EnablePushSymbolsToTop = function(){
    this.pushSymbolsToTop = "1";
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 

SymbolComplete.prototype.DisablePushSymbolsToTop = function(){
    this.pushSymbolsToTop = "";
    this.myDataSource.flushCache();
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort + '&ptt=' + this.pushSymbolsToTop; 
} 

SymbolComplete.prototype.EnableAutoHighlight = function(){
    this.myAutoComp.autoHighlight = true;
}

SymbolComplete.prototype.DisableAutoHighlight = function(){
    this.myAutoComp.autoHighlight = false;
}

SymbolComplete.prototype.EnableDelimiter = function(delimiter){
    this.myAutoComp.delimChar = delimiter;
}

SymbolComplete.prototype.DisableDelimiter = function(){
    this.myAutoComp.delimChar = '';
}

SymbolComplete.prototype.Enable = function()
{
    this.myAutoComp.minQueryLength = 1;
}
SymbolComplete.prototype.Disable = function()
{
    this.myAutoComp.minQueryLength = -1;
}
SymbolComplete.prototype.Disable = function()
{
    this.myAutoComp.minQueryLength = -1;
}


SymbolComplete.prototype.Setup = function(textb, container, count, delay, formatFunc,domain,useIFrame)
{
 
    var mySchema = ["Results","","Symbol","Name","CountryCode"];   

    this.domain = domain;
    try{document.domain = domain}catch(err){}
    var bodyelement = document.getElementsByTagName("BODY")[0]
    this.count = count;
    var iframe = document.createElement("IFRAME");
    iframe.id="iframesc";
    iframe.src= SCIFrameBridgeUrl + "?" + this.domain;
    iframe.style.display = "none"
    bodyelement.appendChild(iframe);
    
    this.myDataSource = new YAHOO_DJ_SC.widget.DS_XHR(myServer, mySchema);  
    this.myDataSource.responseType =  YAHOO_DJ_SC.widget.DS_XHR.TYPE_JSON ; 
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort; 
    
    this.myAutoComp = new YAHOO_DJ_SC.widget.AutoComplete(textb,container, this.myDataSource)
    this.count = count
    this.myAutoComp.maxResultsDisplayed = count;
    this.myAutoComp.queryDelay = delay;
    this.myAutoComp.allowBrowserAutocomplete = false;
    if (useIFrame != null) this.myAutoComp.useIFrame = useIFrame;
    this.myAutoComp.typeAhead = false;
    this.myAutoComp.formatResult = function(aResultItem, sQuery){var s = new param;s.setValue(aResultItem[3]+":"+aResultItem[1]);var s1 = formatFunc(sQuery,s,aResultItem[1],aResultItem[2],aResultItem[3]);aResultItem[0]=s.getValue();return s1};
}



SymbolComplete.prototype.SetupDynamicScript = function(textb, container, count, delay, formatFunc,useIFrame)
{
 
    var mySchema = ["Results","","Symbol","Name","CountryCode"];   

    var bodyelement = document.getElementsByTagName("BODY")[0]
    this.count = count;
    
    this.myDataSource = new YAHOO_DJ_SC.widget.DS_XHR(myServer, mySchema);  
    this.myDataSource.responseType =  YAHOO_DJ_SC.widget.DS_XHR.TYPE_JSON ; 
    this.myDataSource.scriptQueryAppend = 'count=' + this.count + '&license=' + SCkey + '&allowcountries=' + this.allowcountries + '&allowexchanges=' + this.allowexchanges + '&allowtypes=' + this.allowsymboltypes + '&sort=' + this.sort; 
    this.myDataSource.useDynamicScript = true;

    this.myAutoComp = new YAHOO_DJ_SC.widget.AutoComplete(textb,container, this.myDataSource)
    this.count = count
    this.myAutoComp.maxResultsDisplayed = count;
    this.myAutoComp.queryDelay = delay;
    this.myAutoComp.allowBrowserAutocomplete = false;
    if (useIFrame != null) this.myAutoComp.useIFrame = useIFrame;
    this.myAutoComp.typeAhead = false;
    this.myAutoComp.formatResult = function(aResultItem, sQuery){var s = new param;s.setValue(aResultItem[3]+":"+aResultItem[1]);var s1 = formatFunc(sQuery,s,aResultItem[1],aResultItem[2],aResultItem[3]);aResultItem[0]=s.getValue();return s1};
}

SymbolComplete.prototype.augmentYuiConnect = function()    
{    
    if (YAHOO_DJ_SC && YAHOO_DJ_SC.util.Connect)    
    {    
        YAHOO_DJ_SC.util.Connect.asyncRequest = function(method, uri, callback, postData)    
           {    
            var iframe = document.getElementById("iframesc")    
               if(iframe.contentWindow.makeconnection){    
                 return iframe.contentWindow.makeconnection(method, uri, callback, postData);    
                 }    
           };    
           YAHOO_DJ_SC.util.Connect.asyncRequest2 = function(method, uri, callback, postData)    
           {    
            var o = this.getConnectionObject();    
     
                 if(!o){    
                      return null;    
                 }    
                 else{    
                      if(this._isFormSubmit){    
                          if(this._isFileUpload){    
                             this.uploadFile(o.tId, callback, uri, postData);    
                             this.releaseObject(o);    
     
                             return;    
                          }    
     
                          //If the specified HTTP method is GET, setForm() will return an    
              //encoded string that is concatenated to the uri to    
              //create a querystring.    
              if(method.toUpperCase() == 'GET'){    
                             if(this._sFormData.length != 0){    
                               // If the URI already contains a querystring, append an ampersand    
                             // and then concatenate _sFormData to the URI.    
                             uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData;    
                             }    
                             else{    
                               uri += "?" + this._sFormData;    
                             }    
                          }    
                          else if(method.toUpperCase() == 'POST'){    
                             //If POST data exist in addition to the HTML form data,    
                      //it will be concatenated to the form data.    
                      postData = postData?this._sFormData + "&" + postData:this._sFormData;    
                          }    
                      }    
     
                      o.conn.open(method, uri, true);    
     
                      if(this._use_default_xhr_header){    
                          if(!this._default_headers['X-Requested-With']){    
                             this.initHeader('X-Requested-With', this._default_xhr_header, true);    
                          }    
                      }    
                      if(this._isFormSubmit || (postData && this._use_default_post_header)){    
                          this.initHeader('Content-Type', this._default_post_header);    
                          if(this._isFormSubmit){    
                             this.resetFormState();    
                          }    
                      }    
     
                      if(this._has_default_headers || this._has_http_headers){    
                          this.setHeader(o);    
                      }    
     
                      this.handleReadyState(o, callback);    
                      o.conn.send(postData || null);    
     
                      return o;    
            }    
        };    
    }    
}    
  


function param()
{
    this.array = new Array(1);

    this.setValue = function(v) { this.array[0] = v; }
    this.getValue = function()  { return this.array[0]; }
}
    

function InstallLibrary(target)
{
    var t = target||window;
    t.SymbolComplete = new SymbolComplete();
};
InstallLibrary();

