function SearchBox(id, lang, displayType) {
  if (id == null || displayType == null || lang == null) { alert('Missing Arguments'); return; }
  var container = (typeof(id) == "string") ? document.getElementById(id) : id;
  var protocol = window.location.protocol + '//';
  var host = 'dev.mytelus.com';
  var currIdx = 0;
  if (window.location.host != host) host = 'www.mytelus.com';
  var searchUrl, buttonImgOff, buttonImgOn, yahooImg, input, inputWidth;

  var tabs = new Array();
  if (lang == 'en') {
    tabs.push(new Tab('World', 'web'));
    tabs.push(new Tab('Canada', 'canada'));
    tabs.push(new Tab('myTELUS', 'site'));
    searchUrl = 'http://www.mytelus.com/search/results.do?';
  } else if (lang == 'fr') {
    tabs.push(new Tab('Monde', 'web'));
    tabs.push(new Tab('Canada', 'canada'));
    searchUrl = 'http://recherche.globetrotter.net/search/french/results.do?lp=fr&in=gtf&';
  }

  if (displayType == 'header' || displayType == 'header_short') {
    inputWidth = 310;
    buttonImgOff = protocol + host + '/global/images/search/' + lang + '/button_search_off.gif';
    buttonImgOn = protocol + host + '/global/images/search/' + lang + '/button_search_on.gif';
    yahooImg = protocol + host + '/global/images/search/' + lang + '/pwd_by_yahoo_header.gif';
  } else if (displayType == 'header_narrow') {
    inputWidth = 225;
    buttonImgOff = protocol + host + '/global/images/search/' + lang + '/button_search_small_off.gif';
    buttonImgOn = protocol + host + '/global/images/search/' + lang + '/button_search_small_on.gif';
    yahooImg = protocol + host + '/global/images/search/' + lang + '/pwd_by_yahoo_footer.gif';
  } else if (displayType == 'footer') {
    inputWidth = 160;
    buttonImgOff = protocol + host + '/global/images/search/' + lang + '/button_search_small_off.gif';
    buttonImgOn = protocol + host + '/global/images/search/' + lang + '/button_search_small_on.gif';
    yahooImg = protocol + host + '/global/images/search/' + lang + '/pwd_by_yahoo_footer.gif';
  } 

  var preLoad = new Image();
  preLoad.src = buttonImgOn;
  
  this.display = function() {
    container.innerHTML = '';
    container.style.fontSize = '11px';

    if (displayType != 'header_short') {
      var divTab = document.createElement('div');
      divTab.style.textAlign = 'center';
      divTab.style.width = inputWidth  + 'px';
      for (var i = 0; i < tabs.length; i++) {
        divTab.appendChild(tabs[i].elm);
        if (i < tabs.length - 1) divTab.appendChild(document.createTextNode(' | '));
      }
      container.appendChild(divTab);
    }

    var f = document.createElement('form');
    f.style.margin = '0px';
    f.onsubmit = submit;
    container.appendChild(f);

    input = document.createElement('input');
    input.type = 'text';
    input.style.width = inputWidth + 'px';
    input.style.border = '1px solid #96ca89';
    input.style.background = '#ffffff url(' + protocol + host + '/global/images/search/bg_input.gif) repeat-x top left';
    f.appendChild(input);

    var a = document.createElement('a');
    a.href = '#';
    a.onclick = submit;
    f.appendChild(a);

    var img1 = document.createElement('img');
    img1.src = buttonImgOff;
    img1.alt = 'Search';
    if (lang == 'fr')
        img1.alt = 'Recherche';
    img1.onmouseover = function() { this.src = buttonImgOn; }
    img1.onmouseout = function() { this.src = buttonImgOff; }
    img1.style.border = 'none';
    img1.style.marginTop = '-3px';
    img1.style.verticalAlign = 'middle';
    a.appendChild(img1);

    var img2 = document.createElement('img');
    img2.src = yahooImg;
    img2.alt = 'Powered by Yahoo!';
    if (lang == 'fr') img2.alt = 'Présenté par Yahoo!';
    img2.style.border = 'none';
    img2.style.verticalAlign = 'middle';
    if (displayType == 'footer') {
      f.appendChild(document.createElement('br'));
    } else {
      img2.style.marginTop = '-5px';
    }
    f.appendChild(img2);
  }

  function submit() {
    var query = escape(input.value.replace(/ /g, '+'));
    if (query == '') return false;
    var url = searchUrl + 'p=' + tabs[currIdx].type + '&q=' + query;
    window.top.location = url;
    return false;
  }

  function Tab(name, type) {
    this.name = name;
    this.type = type;
    this.elm = document.createElement('a');
    this.elm.appendChild(document.createTextNode(name));
    this.elm.style.fontFamily = 'arial,helvetica,sans-serif';
    this.elm.style.fontSize = '11px';
    this.elm.style.color = '#333333';
    if (tabs.length == 0) { setActive(this.elm); }
    else { setPassive(this.elm); }
    this.elm.onclick = function () {
      input.focus();
      for (var i = 0; i < tabs.length; i++) {
        if (tabs[i].elm == this) { currIdx = i; setActive(tabs[i].elm); }
        else { setPassive(tabs[i].elm); }
      }
      return false;
    }
    function setActive(elm) {
      elm.removeAttribute('href');
      elm.style.fontWeight = 'bold';
      elm.style.textDecoration = 'none';
      elm.onmouseover = null;
      elm.onmouseout = null;
    }
    function setPassive(elm) {
      elm.setAttribute('href','#');
      elm.style.fontWeight = 'normal';
      elm.style.textDecoration = 'none';
      elm.onmouseover = function() { this.style.textDecoration = 'underline'; }
      elm.onmouseout = function() { this.style.textDecoration = 'none'; }
    }
  }
}
