// Check if fm_url specified - for internal use only.
var domain;
if(undefined === window.fm_url) {
  domain = 'www.fridgemountain.com';
} else {
  domain = fm_url;
}

// Default to offers only, but allow either or both fm_type={All|Offer|Request}
var query_type;
if(undefined === window.fm_type) {
  query_type = '&values[Type]=Offer';
} else if (window.fm_type == 'All') {
  query_type = '&values[Type]=';
} else {
  query_type = '&values[Type]=' + encodeURIComponent(fm_type);
}

// Check for style variables.
var query_bg
if(undefined === window.fm_background) {
  query_bg = '';
} else {
  query_bg = '&style_bg=' + encodeURIComponent(fm_background);
}
var query_link_colour
if(undefined === window.fm_link_colour) {
  query_link_colour = '';
} else {
  query_link_colour = '&style_link_colour=' + encodeURIComponent(fm_link_colour);
}

// Check for panel format.  Default to 4x1 table.
var format
if(undefined === window.fm_format) {
  // Not specified so default to table4x1 format.
  format = 'table4x1';
} else {
  format = encodeURIComponent(fm_format);
}

// Check for panel height.
var iframe_height;
if(undefined === window.fm_panel_height) {
  iframe_height = '100px';
  if(format == 'small') {
    iframe_height = '80px';
  } else if(format == 'css') {
    iframe_height = '105px';
  }
} else {
  iframe_height = fm_panel_height;
}

// Build extra iframe attributes.
var iframe_extra_attribs = 'height="' + iframe_height + '"';

// Check for number of days to search over.
var query_days
if(undefined === window.fm_days) {
  query_days = '90';
} else {
  query_days = encodeURIComponent(fm_days);
}

// Check for distance to search over.
var query_miles
if(undefined === window.fm_range_miles) {
  query_miles = '30';
} else {
  query_miles = encodeURIComponent(fm_range_miles);
}

url = 'http://' + domain + '/services/givetake/guestsearchresults.do?cmd=giveTakeSearchCmd&submit=true&values%28PostCode%29=' +
      fm_postcode + '&scorePeriodDays=' + query_days + '&wantRange=' + query_miles + 
      '&categoryAttrName=wantFmCategory&values%28wantFmCategory%29=&values%28ItemStatus%29=%28null%29&format=' +
      format + query_bg + query_link_colour + query_type;

document.write('<iframe name="fridge-mountain-items"' +
               ' marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true"' +
               ' frameborder="0" scrolling="no" width="100%" ' +
               iframe_extra_attribs + ' src="' + url + '"></iframe>');
