
function FilterForm(ch, day, start, limit) {

  this.today = 1268643600;

  if (ch == null)
    ch = 'def';
  if (day == null || day == 0)
    day = this.today;
  if (start == -1)
    start = null;
  if (limit == null)
    limit = 0;
  this.def_ch = ch;
  this.def_day = day;
  this.def_limit = limit;
  this.def_start = start;
  
  this.getToday = function() {
    return this.today;
  }

  this.getSelectedCh = function() {
    chSelect = document.forms['filterForm'].ch;
    return chSelect.options[chSelect.selectedIndex].value;

  };

  this.setSelectedCh = function(ch) {
    chSelect = document.forms['filterForm'].ch;
    for(i=0;chSelect.options.length;i++)
      if (chSelect.options[i].value == ch) {
        chSelect.selectedIndex=i;
        break;
      }
  };

  this.getSelectedDay = function() {
    daySelect = document.forms['filterForm'].day;
    return daySelect.options[daySelect.selectedIndex].value;
  };

  this.setSelectedDay = function(day) {
    daySelect = document.forms['filterForm'].day;
    for(i=0;i<daySelect.options.length;i++)
      if (daySelect.options[i].value == day) {
        daySelect.selectedIndex=i;
        break;
      }
  };

  this.getSelectedLimit = function() {
    limitSelect = document.forms['filterForm'].limit;
    return limitSelect.options[limitSelect.selectedIndex].value;
  };
  
  this.getSelectedLimitStr = function() {
    limitSelect = document.forms['filterForm'].limit;
    return limitSelect.options[limitSelect.selectedIndex].text;
  };

  this.setSelectedLimit = function(limit) {
    limitSelect = document.forms['filterForm'].limit;
    for(i=0;limitSelect.options.length;i++)
      if (limitSelect.options[i].value == limit) {
        limitSelect.selectedIndex=i;
        break;
      }
  };

  this.getSelectedStart = function() {
    startSelect = document.forms['filterForm'].start;
    return startSelect.options[startSelect.selectedIndex].value;
  };

  this.setSelectedStart = function(start) {
    startSelect = document.forms['filterForm'].start;
    for(i=0;startSelect.options.length;i++)
      if (startSelect.options[i].value == start) {
        startSelect.selectedIndex=i;
        break;
      }
  };

  this.render = function(fToC) {
    document.writeln('<div class="ffContainer">');
    document.writeln('<form action="/bla/" method="get" id="filterForm">');
    document.writeln('<div class="ffOptionBox"><label>Kanaler:</label><select name="ch">');

//    var channels = new Array('Danske','Andre danske kanaler','Regionale','Nordiske','Tyske','Internationale');
//    var channelVals = new Array('danske','andredanske','regionale','nordiske','tyske','internationale');
    var channels=new Array('Danske','Andre danske kanaler','Regionale','Nordiske','Tyske','Internationale')
    var channelVals=new Array('danske','andredanske','regionale','nordiske','tyske','internationale')
    if (!(typeof userChannels == 'undefined') && userChannels.length > 0) {
      var ch = new Array('Personlige');
      var chVal = new Array('user');
      channels = ch.concat(channels);
      channelVals = chVal.concat(channelVals);
    }
    for(i=0;i<channels.length;i++) {
      document.write("<option value='"+channelVals[i]+"'");
      str = location.href;
      if (channelVals[i] == this.def_ch)
        document.write(' SELECTED');
      document.writeln('>'+channels[i]+'</option>');
    }
    document.writeln("</select></div>");

    var values=new Array(1268557200,1268643600,1268730000,1268816400,1268902800,1268989200,1269075600,1269162000)
    var names=new Array('søndag d. 14 marts','I dag','tirsdag d. 16 marts','onsdag d. 17 marts','torsdag d. 18 marts','fredag d. 19 marts','lørdag d. 20 marts','søndag d. 21 marts')
    document.writeln('<div class="ffOptionBox"><label>Dag:</label><select name="day">');
    for(i=0; i<values.length; i++) {
      var opt='<option value="'+values[i]+'"';
      var str=location.href;
      if (values[i] == this.def_day)
        opt+=' SELECTED';
      if (values[i] < this.today )
        names[i]='I går';//opt+=' class="ffDropDownOld"';
      opt+='>'+names[i]+'</option>';
      document.writeln(opt);
    }

    document.writeln('</select></div>');

    var date = new Date();
    var hours = date.getHours();
    var past=true;
    document.writeln('<div class="ffOptionBox"><label>Tid:</label><select name="start">');
    for(i=0; i<24; i++) {
      var value;
      value=i+6;
      if (value>23)
        value-=24;
      var name;
      if (value<10)
        name="0"+value;
      else
        name=""+value;
      name+=":00";
      var opt='<option value="'+value+'"';
      var str=location.href;
      if (this.def_start == value || (this.def_start == null && value == hours))
        opt+=' SELECTED';
      if ( past && value == hours )
        past = false;
      if ( past )
        opt+=' class="ffDropDownOld"';
      opt+='>'+name+'</option>';
      document.writeln(opt);
    }
    document.writeln('</select></div>');

    var cats = new Array('Alle','Børn og unge','Dokumentar','Film','Livsstil','Musik','Natur & Miljø','Nyheder','Regional','Serier','Sport','Sundhed & Mad','Underholdning');
    var catVals = new Array(0,11854683,11848684,11825897,11830626,11847662,11838192,11840363,11870463,11831900,11792069,11837090,11844770);
    document.writeln('<div class="ffOptionBox"><label>Vis kun:</label><select name="limit" style="z-index:50;">');
    for(i=0;i<cats.length;i++) {
      document.write('<option value="'+catVals[i]+'"');
      if (catVals[i] == this.def_limit)
        document.write(' SELECTED');
      document.write('>'+cats[i]+'</option>');
    }
    document.writeln("</select></div>");
    //document.writeln('<div class="ffSubmitBox"><div class="ffOptionName"></div><input type="button" value="Vis" onClick="'+objName+'.submit();" /></div>');
    //t1.event1.fire
    document.writeln('<a href="javascript:'+fToC+';"><div id="visknap" class="visknap" onMouseOver="document.getElementById(\'visknap\').style.backgroundPosition=\'0px -22px\';" onMouseOut="document.getElementById(\'visknap\').style.backgroundPosition=\'0px 0px\';"  style="cursor: hand;">Vis</div></a>');
    document.writeln('</form><div style="clear:both;"></div></div>');

  };

}

FilterForm.buildQuery = function(ch,day,start,limit) {
  var query = "";
  if (day != 0)
    query += "day-"+escape(day);
  /*
  if (ch != "def")
    query += "ch-"+escape(ch);
  if (day != 0) {
    if (query.length > 0)
      query += "/";
    query += "day-"+escape(day);
  }
  */
  /*
  if (limit != 0) {
    if (query.length > 0)
      query += "/";
    query += "limit-"+escape(limit);
  }
  */
  //start is not sent to getLists anymore!
  /*
  if (start != "NOW") {
    if (query.length > 0)
      query += "/";
    query += "start-"+escape(start);
  }
  */
  if (query.length > 0)
      query += ".html";
  return query;
}