function POPUP(href, top, left, width, height, style) {
  if (style==1) {
    var win = window.open(href, 'POPUP', "status=no,resizable=no,scrollbars=yes,menubar=no,toolbar=no,location=no,directories=no,copyhistory=no,width="+width+",height="+height+",top="+top+",left="+left);
  } else if (style==2) {
    var win = window.open(href, 'POPUP', "status=no,resizable=no,scrollbars=no,menubar=no,toolbar=no,location=no,directories=no,copyhistory=no,width="+width+",height="+height+",top="+top+",left="+left);
  }
  if (win.window) { win.window.focus(); } else { win.focus(); }
}

function HINFO(id,vc,oc,date) {
  var url = 'http://'+document.location.host+'/site/hotelinfobox.html?id='+id+'&vc='+vc+'&oc='+escape(oc)+'&date='+date;
  if (arguments.length == 5) {
    url += '&tab=' + arguments[4];
  }
  if (id == 0 || (vc == '' && oc == '')) {
    alert('Zu diesem Angebot liegen uns momentan keine weiteren Details vor!');
  } else {
    var win = window.open(url,'HINFO', 'width=780,height=585,scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,copyhistory=no');
    if (win.window) { win.window.focus(); } else { win.focus(); }
  }
}

function VIDADO(iff,lc,vc,hotel,ort) {
  if (iff == 0) {
    alert('Zu diesem Angebot liegen uns momentan keine weiteren Details vor!');
  } else {
    var url = 'http://www.vidado.com/content_page/lmweb.php?KID=615000&IFF='+iff+'&VA='+vc+'&CRS_CODE='+escape(lc)+'&HNAME='+escape(hotel)+'&ORT='+escape(ort);
    win = window.open(url,'VIDADO', 'width=610,height=465,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizable=no,directories=no,copyhistory=no');
    if (win.window) { win.window.focus(); } else { win.focus(); }
  }
}

function initCalendar(elementId, altElementId, minDate, maxDate, dateFormat) {
  var toggleElements = [];
  if (arguments.length == 6 && $.browser.msie && /6.0/.test(navigator.userAgent)) {
    toggleElements = arguments[5];
  }

  var showCurrentAtPos = 0;
  if (elementId == '#DATUM_BIS') {
    showCurrentAtPos = 2;
  }

  $(elementId).datepick($.extend({},
  $.datepick.regional['de'], {
    minDate: minDate,
    maxDate: maxDate,
    firstDay: 1,
    changeFirstDay: false,
    duration: 0,
    showStatus: false,
    showCurrentAtPos: showCurrentAtPos,
    showOn: 'both',
    buttonImage: '/site/images/cal.gif',
    buttonImageOnly: true,
    buttonText: 'Kalender',
    altField: altElementId,
    altFormat: 'ymmdd',
    dateFormat: dateFormat,
    gotoCurrent: true,
    numberOfMonths: 3,
    stepMonths: 3,
    changeMonth: false,
    changeYear: false,
    prevText: '&#x25c4;',
    nextText: '&#x25ba;',
    beforeShow: function() {
      if (toggleElements.length > 0) {
        $.each(toggleElements, function() {$('#'+this).toggle()});
      }
    },
    onClose: function() {
      if (toggleElements.length > 0) {
        $.each(toggleElements, function() {$('#'+this).toggle()});
      }
    }
  }));
}

var Controls = {
  setAdults: function(selected, mode) {
    var html = '';
    if (mode == 'long') {
      var options = ['1|1 Erwachsener','2|2 Erwachsene','3|3 Erw/1 Zimmer','4|4 Erw/1 Zimmer'];
    } else {
      var options = ['1|1 Erw.','2|2 Erw.','3|3 Erw.','4|4 Erw.'];
    }
    html = this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setChild: function(blank, selected) {
    var mode = 'long';
    if (arguments.length == 3) {
      mode = arguments[2];
    }

    if (selected == '') {
      document.write('<option value="18" selected="selected">'+blank+'</option>');
    } else {
      document.write('<option value="18">'+blank+'</option>');
    }

    if (mode == 'long') {
      if (selected == 1) {
        document.write('<option value="1" selected="selected">Baby</option>');
      } else {
        document.write('<option value="1">Baby</option>');
      }
      for(var i = 2; i < 15; i++) {
        if (selected == i) {
          document.write('<option value="'+i+'" selected="selected">'+i+' Jahre</option>');
        } else {
          document.write('<option value="'+i+'">'+i+' Jahre</option>');
        }
      }
    } else if (mode == 'short') {
      if (selected == 1) {
        document.write('<option value="1" selected="selected">&lt;2 J.</option>');
      } else {
        document.write('<option value="1">&lt;2 J.</option>');
      }
      for(var i = 2; i < 15; i++) {
        if (selected == i) {
          document.write('<option value="'+i+'" selected="selected">'+i+' J.</option>');
        } else {
          document.write('<option value="'+i+'">'+i+' J.</option>');
        }
      }
    }
  },

  setDestinations: function(blank, selected) {
    var html = '';
    var selected_found = false;

    if (selected == '') {
      selected_found = true;
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }

    var favorites = ['#|beliebte Reiseziele','AYT|Türkische Riviera','PMI|Mallorca','/HRG/SSH/|Ägypten','LPA|Gran Canaria','FUE|Fuerteventura','TEN|Teneriffa','ACE|Lanzarote','FNC|Madeira','/VRA/HOG/|Kuba','CUN|Mexiko (Cancun)','PUJ|Dom. Republik','HKT|Thailand','DPS|Bali'];
    html += this.getOptionsHTML(favorites, '|', '#', selected, 0, 1);

    var destinations = ['R|B|Balearen','Z|FOM|Formentera','Z|IBZ|Ibiza','Z|PMI|Mallorca','Z|MAH|Menorca','R|C|Kanaren','Z|FUE|Fuerteventura','Z|LPA|Gran Canaria','Z|GOM|La Gomera','Z|SPC|La Palma','Z|ACE|Lanzarote','Z|TEN|Teneriffa','R|E|Spanisches Festland','Z|BCN|Barcelona','Z|ALC|Costa Blanca','Z|CBR|Costa Brava','Z|REU|Costa Dorada','Z|XRY|Costa de la Luz','Z|AGP|Costa del Sol','Z|LEI|Golf von Almeria','Z|MAD|Madrid','Z|SVQ|Sevilla','Z|VLC|Valencia','R|D|Portugal, Madeira','Z|FAO|Algarve','Z|PDL|Azoren','Z|LIS|Lissabon','Z|LIU|Lissabons K&uuml;ste','Z|FNC|Madeira','R|F|T&uuml;rkei','Z|ADA|Adana','Z|BJV|Bodrums Buchten','Z|IST|Istanbul','Z|ASR|Kappadokien','Z|DLM|Lykische K&uuml;ste','Z|HTY|S&uuml;dt&uuml;rkei','Z|ADB|T&uuml;rk. Nord-&Auml;g&auml;is','Z|AYT|T&uuml;rk. Riviera','Z|TXX|T&uuml;rkei Spezial','R|M|&Auml;gypten','Z|NIL|Nil + Baden','Z|NKB|Nil + Kairo + Baden','Z|NKF|Nilkreuzfahrten','Z|RRE|&Auml;gypten Kulturreisen','Z|ALY|Alexandria','Z|ASW|Assuan','Z|HRG|Hurghada','Z|CAI|Kairo','Z|EKR|Kairo + Baden','Z|LXR|Luxor','Z|RMF|Marsa Alam','Z|SSH|Sharm El Sheikh','Z|TCP|Taba','R|G|Griechische Inseln','Z|AOK|Karpathos','Z|EFL|Kefalonia','Z|CFU|Korfu','Z|KGS|Kos','Z|KRE|Kreta','Z|PVK|Lefkas','Z|MJT|Lesbos','Z|JMK|Mykonos','Z|JNX|Naxos','Z|PAS|Paros','Z|RHO|Rhodos','Z|SMI|Samos','Z|JTR|Santorini','Z|THS|Thassos','Z|ZTH|Zakynthos','R|H|Griechenland','Z|SKG|Chalkidiki','Z|IOA|Epirus','Z|KVA|Kavala','Z|GPA|Peloponnes','Z|KLX|Peloponnes','Z|VOL|Thessalien','R|I|Italien','Z|BDS|Brindisi','Z|NAP|Golf von Neapel','Z|ISH|Ischia','Z|SUF|Kalabrien','Z|MXP|Mailand (Malpensa)','Z|FCO|Rom','Z|OLB|Sardinien','Z|CTA|Sizilien','Z|VCE|Venedig','R|J|Tunesien, Marokko','Z|AGA|Marokko (Agadir)','Z|RAK|Marokko (Marrakesch)','Z|DJE|Tunesien (Djerba)','Z|NBE|Tunesien (Enfidha)','Z|MIR|Tunesien (Monastir)','Z|TUN|Tunesien (Tunis)','R|Y|Sonst. Mittelmeerziele','Z|DBV|Kroatien (Dubrovnik)','Z|SPU|Kroatien (Split)','Z|MLA|Malta','Z|ECN|Nordzypern','Z|ZYP|Zypern','R|K|Bulgarien, Osteuropa','Z|VAR|Bulgarien (Goldstrand)','Z|SOF|Bulgarien (Sofia)','Z|BOJ|Bulgarien (Sonnenstrand)','R|L|Rest-Europa','Z|TXL|Berlin-Tegel','Z|HAM|Hamburg','Z|LJU|Llubljana (Slowenien)','Z|STN|London (GB)','Z|MUC|M&uuml;nchen','Z|CDG|Paris','Z|VIE|Wien (A)','R|N|Vorderer Orient','Z|TLV|Israel (Tel Aviv)','Z|AMM|Jordanien (Amman)','Z|BEY|Libanon','Z|MCT|Oman (Maskat)','Z|AUH|V.A.E. (Abu Dhabi)','Z|DXB|V.A.E. (Dubai)','Z|FJR|V.A.E. (Fujairah)','Z|RKT|V.A.E. (Ras Al Khaimah)','Z|SHJ|V.A.E. (Sharjah)','Z|UML|V.A.E. (Umm Al Quwain)','R|X|Afrika','Z|BVC|Kapverden (Boa Vista)','Z|SID|Kapverden (Sal)','Z|MBA|Kenia','Z|ZNZ|Sansibar','R|O|Kuba','Z|HAV|Havanna','Z|HOG|Holguin','Z|VRA|Varadero','R|P|Dom. Republik','Z|POP|Puerto Plata','Z|PUJ|Punta Cana','Z|AZS|Samana','Z|SDQ|Santo Domingo','R|Q|Karibik','Z|ANU|Antigua','Z|AUA|Aruba','Z|NAS|Bahamas (Nassau)','Z|BGI|Barbados','Z|MBJ|Jamaika','Z|CUR|Nied. Antillen (Curacao)','Z|SJU|Puerto Rico','Z|UVF|St. Lucia (Vieux Fort)','Z|TAB|Tobago','Z|PMV|Venezuela (Isla Margarita)','R|R|USA, Kanada','Z|RSW|Ft. Myers,FL','Z|JFK|New York, NY','Z|EWR|Newark, NY','R|S|Mexico, S&uuml;damerika','Z|REC|Brasilien (Recife)','Z|SSA|Brasilien (Salv.d.Bahia)','Z|SJO|Costa Rica','Z|CUN|Mexiko (Cancun)','R|T|Thailand','Z|BKK|Bangkok','Z|UTP|Golf von Thailand','Z|TKL|Khao Lak','Z|TDX|Ko Chang / Ko Kood','Z|USM|Koh Samui','Z|KBV|Krabi','Z|HKT|Phuket','R|U|Indischer Ozean','Z|DPS|Bali','Z|MLE|Malediven (Mal&eacute;)','Z|MRU|Mauritius','Z|SEZ|Seychellen (Mahe)','Z|CMB|Sri Lanka','R|V|Asien, China','Z|PEK|China (Peking)','Z|PVG|China (Shanghai-D.Pong)','Z|HKG|Hong Kong','Z|SGN|Vietnam (Ho-Chi-Minh)'];
    var region_style = ' style="color:#fff;background-color:#002070;font-weight:bold;"';
    html += '<optgroup label="alle Reiseziele">';
    for(var i = 0; i < destinations.length; i++) {
      var option = destinations[i].split('|');
      if (option[0] == 'R') {
        if (!selected_found && (option[1] == selected)) {
          selected_found = true;
          html += '<option value="'+option[1]+'" selected="selected"'+region_style+'>'+option[2]+'</option>';
        } else {
          html += '<option value="'+option[1]+'"'+region_style+'>'+option[2]+'</option>';
        }
      } else {
        if (!selected_found && (option[1] == selected)) {
          selected_found = true;
          html += '<option value="'+option[1]+'" selected="selected">'+option[2]+'</option>';
        } else {
          html += '<option value="'+option[1]+'">'+option[2]+'</option>';
        }
      }
    }
    html += '</optgroup>';
    document.write(html);
  },

  setAirports: function(blank, selected) {
    var html = '';
    var options = [
      '#|Abflugregion','N|Nord','O|Ost','S|S&uuml;d','W|West','M|Mitte','B|Berlin',
      '#|Abflughafen','AOC|Altenburg','AMS|Amsterdam (NL)','AGB|Augsburg','MLHxBSL|Basel (CH)','SXF|Berlin Sch&ouml;nefeld','TXL|Berlin Tegel','BLL|Billund (DK)','BRE|Bremen','BRU|Br&uuml;ssel','DTM|Dortmund','DRS|Dresden','DUS|D&uuml;sseldorf','EIN|Eindhoven (NL)','ENS|Enschede (NL)','ERF|Erfurt','FRA|Frankfurt/Main','HHN|Frankfurt/Hahn','FDH|Friedrichshafen','GDN|Gdansk (PL)','GVA|Genf (CH)','GRZ|Graz (A)','GRQ|Groningen (NL)','HAM|Hamburg','HAJ|Hannover','HOQ|Hof','INN|Innsbruck (A)','FKB|Karlsruhe','KTW|Katowice (PL)','CGN|K&ouml;ln/Bonn','CPH|K&oslash;benhavn (DK)','KLU|Klagenfurt (A)','LEJ|Leipzig','LNZ|Linz (A)','LUX|Luxemburg (L)','LBC|L&uuml;beck','LGG|L&uuml;ttich (B)','MST|Maastricht (NL)','MUC|M&uuml;nchen','FMO|M&uuml;nster','FNB|Neubrandenburg','NRN|Niederrhein/Weeze','NUE|N&uuml;rnberg','PAD|Paderborn','RLG|Rostock','SCN|Saarbr&uuml;cken','SZG|Salzburg (A)','SZW|Schwerin','STR|Stuttgart','SXB|Strasbourg (F)','WAW|Warszawa (PL)','VIE|Wien (A)','WRO|Wroclaw (PL)','ZRH|Z&uuml;rich (CH)','ZQW|Zweibr&uuml;cken',
      '#|Weitere Regionen','AMSxENSxEINxGRQ|Niederlande','INNxLNZxSZGxVIE|&Ouml;sterreich','MLHxZRHxBSL|Schweiz','LUXxLGGxMST|Belgien/Luxemburg','CPHxBLL|Dankmark','GDNxWROxKTWxWAW|Polska'
    ];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setTravelDuration: function(blank, selected) {
    var html = '';
    var options = ['#|genau','7,7|1 Woche','14,14|2 Wochen','21,21|3 Wochen','#|flexibel','3,0|ab 3 Tagen','4,0|ab 4 Tagen','5,0|ab 5 Tagen','6,0|ab 6 Tagen','7,0|ab 7 Tagen','8,0|ab 8 Tagen','9,0|ab 9 Tagen','10,0|ab 10 Tagen','11,0|ab 11 Tagen','12,0|ab 12 Tagen','13,0|ab 13 Tagen','14,0|ab 14 Tagen','15,0|ab 15 Tagen','16,0|ab 16 Tagen','17,0|ab 17 Tagen','18,0|ab 18 Tagen','19,0|ab 19 Tagen','20,0|ab 20 Tagen','21,0|ab 21 Tagen'];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setCategory: function(blank, selected, style) {
    if (style == 'list') {
      if (selected == '') {
        document.write('<option value="" selected="selected">'+blank+'</option>');
      } else {
        document.write('<option value="">'+blank+'</option>');
      }
      for(var i = 2; i < 6; i++) {
        if (selected == i) {
          document.write('<option value="'+i+'" selected="selected">min. '+i+' Sterne</option>');
        } else {
          document.write('<option value="'+i+'">min. '+i+' Sterne</option>');
        }
      }
    }
    if (style == 'checkboxes') {
      if (selected == '') {
        document.write('<input type="radio" name="ST" value="" checked="checked">&nbsp;'+blank+'<br>');
      } else {
        document.write('<input type="radio" name="ST" value="">&nbsp;'+blank+'<br>');
      }
      var BR = '<br>';
      for(var i = 2; i < 6; i++) {
        if (selected == i) {
          document.write('<input type="radio" name="ST" value="'+i+'" checked="checked">&nbsp;<img src="/site/images/stars/'+i+'_search.gif" alt="" border="0"><br>');
        } else {
          document.write('<input type="radio" name="ST" value="'+i+'">&nbsp;<img src="/site/images/stars/'+i+'_search.gif" alt="" border="0"><br>');
        }
      }
    }
  },

  setBoarding: function(blank, selected, style) {
    var html = '';
    // '4|Vollpension'
    var options = ['2|&Uuml;bernachtung','3|Fr&uuml;hst&uuml;ck','1|Halbpension','6|All Inclusive'];
    if (style == 'list') {
      if (selected == '') {
        html += '<option value="" selected="selected">'+blank+'</option>';
      } else {
        html += '<option value="">'+blank+'</option>';
      }
      html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    }
    if (style == 'checkboxes') {
      if (selected == '') {
        html += '<input type="radio" name="VA" value="" checked="checked">&nbsp;'+blank+'<br>';
      } else {
        html += '<input type="radio" name="VA" value="">&nbsp;'+blank+'<br>';
      }
      for(var i = 0; i < options.length; i++) {
        var option = options[i].split('|');
        if (selected == option[0]) {
          html += '<input type="radio" name="VA" value="'+option[0]+'" checked="checked">&nbsp;'+option[1]+'<br>';
        } else {
          html += '<input type="radio" name="VA" value="'+option[0]+'">&nbsp;'+option[1]+'<br>';
        }
      }
    }
    document.write(html);
  },

  setRoomtypes: function(blank, selected) {
    var html = '';
    var options = ['2|Einzelzimmer','1|Doppelzimmer','9|Familienzimmer','3|Appartement','4|Studio','5|Bungalow','6|Suite','7|Fly &amp; Drive'];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setPriceRange: function(blank, selected) {
    var html = '';
    var options = ['0,300|bis 300 &euro; pro Person','0,400|bis 400 &euro; pro Person','0,500|bis 500 &euro; pro Person','0,600|bis 600 &euro; pro Person','0,700|bis 700 &euro; pro Person','0,800|bis 800 &euro; pro Person','0,900|bis 900 &euro; pro Person','0,1000|bis 1.000 &euro; pro Person'];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setAttributes: function(blank, selected) {
    var html = '';
    // '3|kinderfreundlich','6|gr. Sportangebot','7|Wellness'
    if (arguments.length == 2) {
      var selected = arguments[1];
    } else {
      var selected = App.getParamValue('HA', '');
    }
    var options = ['1|direkt am Strand','2|strandnah'];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setBrands: function(blank, selected) {
    var html = '';
    var options = [
      '#|Veranstalter','FLY|1-2 Fly','5VF|5 vor Flug','ALL|Alltours','ARD|Arado Tours','ATT|ATT','ATK|Attika Reisen','BEN|BENTOUR','BGT|BGtours','BIG|BigXtra','BU|Bucher Reisen','CLT|Classic Tours','CBM|Club Blaues Meer','DEM|Demed','DIS|Discount Travel','ECC|ECCO Reisen','ER|Engel Reisen','ETI|Express Travel Int.','PACK|Ferienknaller.de','FLC|fly consult','FTI|FTI Touristik','GLA|Glauch Reisen','GTI|GTI Travel','HHT|H&H Tur','HERM|Hermes','HUC|Holiday & Co.','ITS|ITS','ITT|Internet Tele Touristik','JAHN|Jahn Reisen','MED|Medina','MWR|Meiers Weltreisen','MISR|MISR Travel','MOT|monorama Touristik','NAZ|Nazar','NEC|Neckermann Reisen','OFT|OFT Reisen','OGER|&Ouml;ger Tours','OLI|Olimar','PHX|Phoenix Reisen','PLR|Pl&auml;rrer','ROY|Royal Holidays','SLR|Schauinsland Reisen','SPAR|Spartip Reisen','ST|SunTrips','TOC|Thomas Cook Reisen','TJAE|Tjaereborg','TUI|TUI',
      '#|Hotelmarke','10|Barcel&#243;','14|Blau','21|Calimera','4|Dunas','16|Grupotel','7|H10','5|Hesperia','15|Hipotel','13|Iberostar','9|Ifa','6|LTI','12|Meli&#225;','8|Occidental','1|Princess','17|RIU','18|Red Sea Hotels','19|Riva','11|Seaside','20|Sheraton','2|Sol','3|Sunrise Beach'
    ];
    if (selected == '') {
      html += '<option value="" selected="selected">'+blank+'</option>';
    } else {
      html += '<option value="">'+blank+'</option>';
    }
    html += this.getOptionsHTML(options, '|', '#', selected, 0, 1);
    document.write(html);
  },

  setPager: function(numpages, stepsize, selected) {
    var html = '';
    var pos = 0;
    for(var i = 1; i <= numpages; i++) {
      if (selected == pos) {
        html += '<option value="'+pos+'" selected="selected">Seite '+i+'</option>';
      } else {
        html += '<option value="'+pos+'">Seite '+i+'</option>';
      }
      pos += stepsize;
    }
    document.write(html);
  },

  getOptionsHTML: function(options, itemSeparator, groupSeparator, selected, indexData, indexLabel) {
    var html = '';
    var hasGroups = false;
    for(var i = 0; i < options.length; i++) {
      var option = options[i].split(itemSeparator);
      if (option[indexData] == groupSeparator) {
        hasGroups = true;
        if (i > 0) { html += '</optgroup>'; }
        html += '<optgroup label="'+ option[indexLabel] + '">';
      } else {
        if (selected == option[indexData]) {
          html += '<option value="'+option[indexData]+'" selected="selected">'+option[indexLabel]+'</option>';
        } else {
          html += '<option value="'+option[indexData]+'">'+option[indexLabel]+'</option>';
        }
      }
    }
    if (hasGroups) { html += '</optgroup>'; }
    return html;
  }
}

