renderwidget = function(uri, width, records, cols, owners, objects, style, search) {

  bs_script = document.createElement('script');
  bs_script.type = 'text/javascript';
  bs_script.src = uri + 'static/js/searchbox.js';

  template = document.createElement('link');
  template.rel = 'stylesheet';
  template.type = 'text/css';
  template.href = uri + 'static/css/templates/' + style + '.css';
  
  var head = document.getElementsByTagName('head')[0];

  head.appendChild(bs_script);

  head.appendChild(template);

  // determine the host
  var hostname;

  if(self.location.hostname == "widgets.dimu.se") {
    hostname = "www.digitaltmuseum.se";
  } else if(self.location.hostname == "kit-espent:3001") {
    hostname = "www.digitaltmuseum.se";
  } else {
    hostname = "www.digitaltmuseum.no";
  }

  var inputsize = parseInt( parseInt(width) * 0.60 );

  // try and calculate thumbsize
  var tsize = parseInt( (parseInt(width) - 10 - (parseInt(cols) * 8)) / parseInt(cols) );

  var html = '';

  var re = /simple$/;
  
  if ( re.test(style) ) {
    style = style.slice(0, -7);
    
    html += '<div id="wcontainer" style="width: ' + width + 'px;">';
    html += ' <div id="wcontent"><div id="wcinner">';
    html += '  <a href="http://' + hostname + '/" id="wlogo-header"></a>';
    html += '  <div style="clear: both;">&nbsp;</div>';
    html += '  <form action="http://' + hostname + '" method="get">';
    html += '   <input type="text" name="q" style="width: ' + inputsize + 'px" class="winput">';

    var oar = owners.split(",");

    $(oar).each(function() {
      if( this != '' ) {
        html += '   <input type="hidden" name="owners[' + $(this) + ']" value="true" />';
      }
    });
    
    if ( objects == "All" ) {
       html += '   <input type="hidden" name="object_type" value="Unknown" />';
    } else {
       html += '   <input type="hidden" name="object_type" value="' + objects + '"/>';
    }

    html += '   <input type="submit" value="S&oslash;k" class="wbutton" />';

    html += '  </form>';
    html += '  <div style="clear: both;">&nbsp;</div>';
    html += ' </div></div>';
    html += '</div>';
  } else {
    html += '<div id="wcontainer" style="width: ' + width + 'px;">';
    html += ' <div id="wcontent"><div id="wcinner">';
    html += '  <a href="http://' + hostname + '/" id="wlogo-header"></a>';
    html += '  <div style="clear: both;">&nbsp;</div>';
    html += '  <form id="wsearchform" name="wsearchform" action="">';
    html += '   <input type="text" id="q" name="q" style="width: ' + inputsize + 'px" class="winput">';
    html += '   <input type="hidden" id="wuri" name="wuri" value="' + uri + '"/>';
    html += '   <input type="hidden" name="wrecords" value="' + records + '"/>';
    html += '   <input type="hidden" name="wcols" value="' + cols + '"/>';
    html += '   <input type="hidden" name="wthumbsize" value="' + tsize + '"/>';
    html += '   <input type="hidden" name="wowners" value="' + owners + '"/>';
    html += '   <input type="hidden" name="wobjects" value="' + objects + '"/>';
    html += '   <input type="hidden" name="wstyle" value="' + style + '"/>';
    html += '   <input type="hidden" name="wsearch" value="' + search + '"/>';
    html += '   <input type="submit" value="S&oslash;k" class="wbutton"/>';
    html += '  </form>';
    html += '  <div id="wsearchresult"><p>Angi s&oslash;keord og trykk "S&oslash;k"-knappen.</p></div>';
    html += '  <div style="clear: both;">&nbsp;</div>';
    html += '  <div id="wpager"></div>';
    html += ' </div></div>';
    html += '</div>';
  }

  document.write( html );
}

testing = function() {
  alert('just testing');
}



