
////////////////////////////////////////////////////////////////////////////////
// Copyright © Nww Online GmbH & Co. KG, 2008
// Autor : Florian Dütsch (florian.duetsch@nix-wie-weg.de)
//
// - Undokumentierte Fassung, siehe PHP-Version -
////////////////////////////////////////////////////////////////////////////////

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
  var dumped_text = "";
  if(!level) { 
    level = 0; 
  }

  //The padding given at the beginning of the line.
  var level_padding = "";
  for(var j=0;j<level+1;j++) {
    level_padding += "    ";
  }
  
  if(typeof(arr) == 'object') { //Array/Hashes/Objects
    for(var item in arr) {
      if (item) {
        var value = arr[item];    
        if(typeof(value) == 'object') { //If it is an array,
         dumped_text += level_padding + "'" + item + "' ...\n";
         dumped_text += dump(value,level+1);
        } else {
         dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
        }
      }
    }
  } 
  else { //Stings/Chars/Numbers etc.
   dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
  }
  return dumped_text;
}

function isObject(dataNode) {
  if (typeof(dataNode) != "object") { 
    return false;
  }
  else {
    return true; 
  }
}
 
////////////////////////////////////////////////////////////////////////////////
function NwwCookies() {
  var self = this;
  var NWW_PARTNER = "NixWieWegde";
  var data = {};
  var HOST_AGENTS = [
                { host: "aegypten-spezialist.de", agent: "aegyptspezi" },
                { host: "kroatien-links.de", agent: "kroatienlinks" },
                { host: "reiserat.de", agent: "reiserat" },
                { host: "diepauschalreise.de", agent: "diepauschalreise" },
                { host: "reisebuch.de", agent: "reisebuch" },
                { host: "lastminute-online.at", agent: "lmonlineat" },
                { host: "holiday-lotse.de", agent: "lindner" },
                { host: "energienetzwerk-oberpfalz.de", agent: "energieopf" },
				{ host: "travelkiss.de", agent: "travelkiss" },
                { host: "nwwo.de", agent: "nwwo" }];

  var host2agent = function(search_host) {
    for(var i = 0; i < HOST_AGENTS.length; i++) {
      var host = HOST_AGENTS[i].host;
      if(search_host.match(host + "$") == host) {
        return HOST_AGENTS[i].agent;
      }
    }
    return null;
  };
  
  var unserialize_nww_token = function(raw_cookie) {
    var parts = raw_cookie.split("|");
    var temp_data = {};
    for (var i = 0; i < parts.length; i += 2) {
      var obj = parts[i].substring(0,2);
      var key = parts[i].substring(2);
      var value = parts[i+1];
      if (typeof(temp_data[obj]) == "undefined") {
        temp_data[obj] = {};
      }
      temp_data[obj][key] = unescape(value);
    }
    return temp_data;
  };
  
  var serialize_data = function(data) {
    var temp_data  = [];
    for (var namespace in data) {
      if (namespace) {
        for (var member in data[namespace]) {
          if (member) {
            var value = escape_nww(data[namespace][member]);
            if (typeof(value) == "undefined") {
              value = "";
            }
            temp_data.push(namespace + member + "|" + value);
          }
        }
      }
    }
    return temp_data.join("|");
  };
    
  var serialize = function(data) {
    return serialize_data(data); 
  };
  
  var escape_nww = function(str) {
    if (str === null) {
      return "";
    }
    if (typeof(str) != "string") {
      return "";
    }
    str = str.replace(/\%/g,"%25");
    str = str.replace(/\|/g,"%7C");
    str = str.replace(/;/g,"%3B");    
    str = str.replace(/\=/g,"%3D");
    str = str.replace(/,/g,"%2C");
    str = str.replace(/\n/g,"%0A");
    str = str.replace(/\r/g,"%0D");
    str = str.replace(/\t/g,"%09");
    str = str.replace(/ /g,"%20");
    return str;
  };
  
  var internal_read_rawcookie = function(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i = 0; i < ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0) === ' ') {
        c = c.substring(1,c.length);
      }
      if (c.indexOf(nameEQ) === 0) {
        return c.substring(nameEQ.length,c.length);
      }
    }
    return null;    
  };
  var load_data = function() {
    var cookiedata = internal_read_rawcookie("nww_fc_bs_tmp");
    if(cookiedata === null) {
      cookiedata = internal_read_rawcookie("nww_fc_bs");
    }
    if(cookiedata === null) {
      data = {};
    } else {
      data = unserialize_nww_token(cookiedata);
    }
    if(!isObject(data.fc)) {
      data.fc = {};
    }
    if(!isObject(data.bs)) {
      data.bs = {};   
    }
    if(!isObject(data.bc)) { 
      data.bc = {};
    }
    if(!isObject(data.wa)) { 
      data.wa = {};
    }
    if(!isObject(data.dp)) { 
      data.dp = {};
    }
  };
  var save_data = function() {
    var expire = new Date();
    expire.setTime(expire.getTime() + 1000*60*60*24*63);
    document.cookie = "nww_fc_bs=" + serialize(data) + 
                      ";expires=" + expire.toGMTString() +
                      ";path=/;domain=.nix-wie-weg.de";
    document.cookie = "nww_fc_bs_tmp=" + serialize(data) +
                      ";path=/;domain=.nix-wie-weg.de";
  };
  var internal_get_param = function(key) {
    key = key.replace(/[\[]/g,"\\[").replace(/[\]]/g,"\\]");
    var regexS = "[\\?&]"+key+"=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if(results === null) {
      return null;
    } 
    else {
      return results[1] == "" ? null : results[1];
    }
  };
  var internal_parse_url = function(data) {
    var e=/^((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^#?\s]+)(#[\w\-]+)?$/;

    if(data.match(e)) {
      return { url: RegExp['$&'],
               protocol: RegExp.$2,
               host:RegExp.$3,
               path:RegExp.$4,
               file:RegExp.$6,
               hash:RegExp.$7 };
    } else {
      return { url:"", protocol:"",host:"",path:"",file:"",hash:"" };
    }
  };
  this.get_bs_pa = function() {
    return this.data.bs.pa;
  };
  this.get_request_agent = function() {
    var agent = internal_get_param("agent");
    if(agent === null && document.referrer) {
      var host = internal_parse_url(document.referrer).host;
      if(host.length > 0) {
        agent = host2agent(host);
      }
    }
    if(agent === null) {
      agent = NWW_PARTNER;
    }
    return agent;
  };
  var get_request_domain = function() {
    var wl = window.location;
    var p = 80;
    if(wl.port != "") {
      p = wl.port;
    }
    var url = wl.host + ":" + p + wl.pathname + wl.search;
    return url.substring(0, 200);
  };  
  var get_request_partner_id = function(agent) {
    if(agent == "Kelkoo") {
      return internal_get_param("tduid");
    } else if(agent == "zanox") {
      return internal_get_param("zanpid");
    }
    return null;
  };
  var get_time_string = function() {
    var d = new Date();
    var time = "";

    var i = d.getYear();
    if (i < 1000) { i += 1900; }
    time += i + "-" ;
    var month = d.getMonth() + 1;
    var h = "" + month;
    if (h.length <= 1) { h = "0" + h; }
    time += h + "-";
    h = "" + d.getDate();
    if (h.length <= 1) { h = "0" + h; }
    time += h + " ";
    h = "" + d.getHours();
    if (h.length <= 1) { h = "0" + h; }
    time += h + ":";
    h = "" + d.getMinutes();
    if (h.length <= 1) { h = "0" + h; }
    time += h + ":";
    h = "" + d.getSeconds();
    if (h.length <= 1) { h = "0" + h; }
    time += h ;

    return time;
  };
  this.set_firstcontact = function() {
    if(data.fc.pa === null) {
      data.fc.da = get_time_string();
      data.fc.pa = this.get_request_agent();
      data.fc.dn = get_request_domain();
    } 
  };
  this.set_watchagent = function() {
    if ((data.wa.tk === null)||(data.wa.tk == "undefined")) {
      data.wa.tk = "";
      data.wa.remind = 0;
      if ((this.get_watchagent_token() != "undefined") || 
          (typeof(this.get_watchagent_token()) != "undefined")) {
        data.wa.tk = this.get_watchagent_token();
        data.wa.remind = this.get_watchagent_remind();
      }
    }
  };
  this.set_display = function() {
    if ((data.dp.zm === null) || (data.dp.zm == "undefined")) {
      data.dp.zm = "100";
    }
    else {
      data.dp.zm = this.get_display_zoom();
    }
  };
  this.set_bookingsource = function() {
    var date = data.bs.da;
    var partner = data.bs.pa;
    var partner_id = data.bs.pi;
    var domain = data.bs.dn;
    var visit_count = data.bs.vc;
    var last_call = data.bs.lc;
    var subpartner1 = data.bs.s1;
    var subpartner2 = data.bs.s2;
    
    var request_agent = this.get_request_agent();
    var request_partner_id = get_request_partner_id(request_agent);
    var subpartner1_id = internal_get_param("subagent1");
    var subpartner2_id = internal_get_param("subagent2");
    
    var existing = request_agent == partner || 
                   (request_agent.toLowerCase() == NWW_PARTNER.toLowerCase() && partner !== null);
    
    if (partner_id != request_partner_id && request_partner_id !== null) {
      existing = false;
    }
      
    if ((subpartner1 != subpartner1_id || subpartner2 != subpartner2_id) &&
       request_agent.toLowerCase() != NWW_PARTNER.toLowerCase() &&
       (subpartner1_id !== null || subpartner2_id !== null)) {
      existing = false;
    }
    
    if (existing) {
      if (last_call < (parseInt(new Date().getTime() / 1000,10) - 120 * 60)) { 
        visit_count++;
      }
      last_call = parseInt(new Date().getTime() / 100, 10);
      if(request_partner_id !== null ||
         (request_agent != partner && 
          request_agent.toLowerCase() != NWW_PARTNER.toLowerCase())) {
        partner_id = request_partner_id;
      } 
    } else {
      date = get_time_string();
      partner = request_agent;
      partner_id = request_partner_id;
      domain = get_request_domain();
      visit_count = 1;
      last_call = parseInt(new Date().getTime() / 1000, 10);
      subpartner1 = subpartner1_id;
      subpartner2 = subpartner2_id;     
    }
    
    if(date !== null) {data.bs.da = date;}
    else {delete data.bs.da;}
    if(partner !== null) {data.bs.pa = partner;}
    else {delete data.bs.pa;}
    if(partner_id !== null) {data.bs.pi = partner_id;}
    else {delete data.bs.pi;}
    if(domain !== null) {data.bs.dn = domain;}
    else {delete data.bs.dn;}
    if(visit_count !== null) {data.bs.vc = visit_count;}
    else {delete data.bs.vc;}
    if(last_call !== null) {data.bs.lc = last_call;}
    else {delete data.bs.lc;}
    if(subpartner1 !== null) {data.bs.s1 = subpartner1;}
    else {delete data.bs.s1;}
    if(subpartner2 !== null) {data.bs.s2 = subpartner2;}
    else {delete data.bs.s2;}
  };
  this.dump = function() {
    return dump(data);
  };
  this.save_changes = function() {
    save_data();
  };
  this.get_bonuscode_value = function() {
    return data.bc.va;
  };
  this.get_bonuscode_timestamp = function() {
    return data.bc.ts;
  };
  this.get_bonuscode_agent = function() {
    return data.bc.ag;
  };
  this.set_bonuscode_value = function(value) {
    if(value !== null) {data.bc.va = value;}
    else {delete data.bc.va;}
  };
  this.set_bonuscode_timestamp = function(value) {
    if(value !== null) {data.bc.ts = value;}
    else {delete data.bc.ts;}
  };
  this.set_bonuscode_agent = function(value) {
    if(value !== null) {data.bc.ag = value;}
    else {delete data.bc.ag;}
  };
  this.set_subagent1 = function(value) {
    if(value !== null) {data.bs.s1 = value;}
  };
  this.set_watchagent_token = function(value) {
    if(value !== null) {data.wa.tk = value;}
    else {delete data.wa.tk;}
  };
  this.get_watchagent_token = function() {
    return data.wa.tk;
  };
  this.set_watchagent_remind = function(value) {
    if(value !== null) {data.wa.remind = value;}
    else {delete data.wa.remind;}
  };
  this.get_watchagent_remind = function() {
    return data.wa.remind;
  };
  this.set_display_zoom = function(value) {
    if (value !== null) {data.dp.zm = String(value);}
    else {delete data.dp.zm;}
  };
  this.get_display_zoom = function() {
  return parseInt(data.dp.zm, 10);
  };
  load_data();
}

var nwwCookies = new NwwCookies();
nwwCookies.set_firstcontact();
nwwCookies.set_bookingsource();
nwwCookies.set_watchagent();
nwwCookies.set_display();
nwwCookies.save_changes();
  function gone_offer_find_table() {
    var tables = document.getElementsByTagName("table");
    var table = false;
    for (var i=0;i<tables.length;i++) {
      if (tables[i].className == "tertab5") {
        table = tables[i];
        break;
      }
    }
    if (!table) throw Error;
    var tds = table.getElementsByTagName("td");
    for (var i=0;i<tds.length;i++) {
      if (tds[i].className == "tervakerror") {
        tds[i].innerHTML =
          '<img src="http://www.nix-wie-weg.de/layout/vakanz-fehler.gif">';
      }
    }
  }
function find_error_tab() {
  var tables = document.getElementsByTagName("table");
  for (var i=0; i<tables.length; i++) {
    if (tables[i].className == "errtab") {
      return tables[i];
    }
  }
  return null;
}

function get_booking_info(part) {
  if (typeof(str_hinfo) != "string") return null;
  var infos = str_hinfo.split("#");
  switch (part) {
    case "hotel": return infos[0]; break;
    case "city": return infos[1]; break;
    case "region": return infos[3]; break;
    case "country": return infos[4]; break;
  }
}

function get_destination_id() {
  if (typeof(mzielgeb) != "string") return null;
  return mzielgeb;
}

function no_offer_for_hotel() {
  if ((typeof(IFF) == "string") && (find_error_tab !== null)) {
    var errortab = find_error_tab();
    var div = document.createElement("div");
    div.innerHTML = '<div style="background:#f5f1de; border:1px solid #fff; padding: 4px; width:730px;"><div ><img src="http://www.nix-wie-weg.de/images/gone_offers/bad.gif" style="vertical-align:middle;" /> <strong>Derzeit gibt es leider keine konkreten Angebote für das Hotel ' + get_booking_info("hotel") + '.</strong></div><div style="padding:8px 0;"><img src="http://www.nix-wie-weg.de/images/gone_offers/good.gif" style="vertical-align:middle;" /> Sie haben folgende Möglichkeiten:    <ol style="list-style-position:inside; line-height:1.3em; font-size: 1.2em; padding-left:10px;"><li style="padding:8px 0 0 7px; color:#FFA129; font-weight:bold;"><span style="color:#0f8705; font-weight:normal;"><a href="#" onclick="openPersonalNewsWindow();return false;" style="text-decoration:underline">Ich möchte informiert werden</a>, sobald es Angebote für <strong>' + get_booking_info("hotel") + '</strong> gibt!</span></li><li style="padding:8px 0 0 7px; color:#FFA129; font-weight:bold;"><span style="color:#0f8705; font-weight:normal;">Wir helfen gerne pers&ouml;nlich weiter: 0961 / 634 69 0</span></li><li style="background:url(bubble.gif) center left no-repeat; padding:8px 0 0 7px; color:#FFA129; font-weight:bold;"><span style="color:#0f8705; font-weight:normal;"><a style="text-decoration:underline;" href="javascript:zum_hotel(1,0,' +  get_destination_id() + ');">Zurück zur Suchmaske</a></span></li></ol></div></div>';
    errortab.parentNode.insertBefore(div, errortab);
    errortab.parentNode.removeChild(errortab);
  }
}
params_storage = "";

function zur_suche(showresult) {
	
  if (typeof(uebergabe_hotel)== "undefined") params_storage = uebergabe;
  else params_storage = uebergabe_hotel;
  
  if (typeof tt_strecke != "undefined") {
    if (tt_strecke == "F") link_to("fluege", showresult)
    else if (tt_strecke == "P") link_to("pauschalreisen", showresult)
    else if (tt_strecke == "H") link_to("hotels", showresult)
    else if (tt_strecke == "FH") {
      if (typeof(TTHidFields[18]) == "undefined") {
	    hbit = 0;
      }
	  else {
	  	hbit = TTHidFields[18].split("#TT#");
	  }
	  link_to_fewo("fewo", showresult, parse_hotel_bit(hbit[1]));
	} 
	else link_to("lastminute", showresult)
  }
}           

function link_to(target, showresult){
  window.location.href = "http://www.nix-wie-weg.de/" + params_storage.replace("index.php", target + ".html") + "&showresult=" + showresult;
}

function link_to_fewo(target, showresult, hbitquery){
  window.location.href = "http://www.nix-wie-weg.de/" + params_storage.replace("index.php", target + ".html") + "&showresult=" + showresult + "&" + hbitquery;
}

function parse_hotel_bit(hbit){
  
  var hash = new Array();
  hash['schwimmbad']=0;
  hash['sauna']=0;
  hash['tv']=0;
  hash['kamin']=0;
  hash['rollstuhl']=0;
  hash['angeln']=0;
  hash['haustiere']=0;
  hash['geschirrspueler']=0;
  hash['wachmaschine']=0;
  hash['boot']=0;
  hash['tennis']=0;
  hash['garage']=0;
  hash['kinderbett']=0;
  hash['entf_meer']=0;
  hash['entf_lift']=0;

	

  if (hbit > 0) {
    var bits = dec2bin(hbit);
    var bit_stream = bits.reverse();
  }
  else bit_stream = "0";
  
  for(i=0;i<bit_stream.length;i++) {
  	x = i+1;
	c = bit_stream[i];
	if (bit_stream[i] == 1) {
	  if (x == 1) hash['schwimmbad'] = 1;
	  else if (x == 2) hash['sauna'] = 1;
	  else if (x == 3) hash['tv'] = 1;
	  else if (x == 4) hash['kamin'] = 1;
	  else if (x == 5) hash['rollstuhl'] = 1;
	  else if (x == 6) hash['angeln'] = 1;
	  else if (x == 7) hash['haustiere'] = 1;
	  else if (x == 8) hash['geschirrspueler'] = 1;
	  else if (x == 9) hash['waschmaschine'] = 1;
	  else if (x == 10) hash['boot'] = 1;
	  else if (x == 11) hash['tennis'] = 1;
	  else if (x == 12) hash['garage'] = 1;
	  else if (x == 13) hash['kinderbett'] = 1;
	  
	  else if (x == 14) hash['entf_meer'] = 1;
	  else if (x == 15) hash['entf_meer'] = 2;
	  else if (x == 16) hash['entf_meer'] = 3;
	  else if (x == 17) hash['entf_meer'] = 4;
	  else if (x == 18) hash['entf_meer'] = 5;
	  else if (x == 19) hash['entf_meer'] = 6;
	  
	  else if (x == 20) hash['entf_lift'] = 1;
	  else if (x == 21) hash['entf_lift'] = 2;
	  else if (x == 22) hash['entf_lift'] = 3;
	  else if (x == 23) hash['entf_lift'] = 4;
	  else if (x == 24) hash['entf_lift'] = 5;
	  else if (x == 25) hash['entf_lift'] = 6;
	}
  }
  
  var queryfy = new Array;
  for (var item in hash) {
  	queryfy.push(item + "=" + hash[item]);
  }

  return queryfy.join("&");          
}


function dec2bin(dec){
  var potencies = new Array(); // Creates an empty array that is used to fill in with potencies of 2
  var binary = new Array();
  for (var i = 0; i > -1; i++) // In theory an endless loop, that is only interrupted by "break"
  {
    var potency = Math.pow(2, i); // Calculates the potency 2^i
    if (potency > dec) {
      break;
    } // Maximal length is done, do not add to array but leave loop
    potencies[i] = potency; // Writes actual potency in the array
  }
  
  potencies.reverse(); // Turn array around, so that the biggest number is first and the lowest last
  for (var j = 0; j < potencies.length; j++) // This loop increases the variable (which is the divisor)
  {
    var position = potencies[j]; // Select actual potency desc. (32, 16, 8...)
    var zeroOne = parseInt(dec / position); // Integer value that is the result of dividing the number over actual potency (only "1" or "0" can be the result)
	binary.push(zeroOne);
    dec -= potencies[j] * zeroOne; // Substracts actual value * 0 [or 1]
  }
  return binary;
}
function logger(type, message) {
  enabled = "off";
  if (typeof(console) == 'object') {
    if (enabled!="off") {
      if (type == "warn") {
        console.log(message);
      }
      if (type == "info") {
        console.log(message);
      }
    }
  }
}

function getItemCount() {
  var token = nwwCookies.get_watchagent_token();
  var remind = nwwCookies.get_watchagent_remind();
  
  if ((token == "undefined") || (typeof(token) == "undefined")||
      (remind == "undefined") || (typeof(remind) == "undefined") ||
      (remind == "") || (token == "")) {
    return 0;
  }
   
  var remindVal = remind.toString().split(";");
  var count = parseInt(remindVal[0]);
  return count;
}

function isIffSaved(iff) {
  var token = nwwCookies.get_watchagent_token();
  var remind = nwwCookies.get_watchagent_remind();
  
  if ((token == "undefined") || (typeof(token) == "undefined") ||
      (remind == "undefined") || (typeof(remind) == "undefined") ||
      (remind == "") || (token == "")) {
    return false;
  }

  var remindVal = remind.toString().split(";");
  if (remindVal.length < 2) {
    return false;
  }
  for (var i=1;i<remindVal.length;i++) {
    if (parseInt(remindVal[i]) == parseInt(iff)) {
      return true;
    }
  }
  return false;
}

function findHeaderLink() {
  return document.getElementById("nww_merkimage");
}

function findSidebar() {
  return document.getElementById("nww_merkzettel");
}

function overwriteOfferBoxes() {
  var spans = document.getElementsByTagName("span");
  for (var i=0;i<spans.length;i++) {
    if ((spans[i].className == "nww_merklink")) {
      if (!isIffSaved(IFF)) {
        spans[i].innerHTML = '<a onclick="openPersonalNewsWindow();return false;" href="#" class="merkzttl">Angebot in meinen Merkzettel legen</a>';
      } else {
        spans[i].innerHTML = '<a onclick="openPersonalNewsWindow();return false;" href="#" class="merkzttl">Dieses Hotel liegt bereits im Merkzettel</a>';
      }
    }
  }
}

function overwriteSidebar() {
  text = "";
  offerCount = getItemCount();
 
  if (offerCount == 0) text = 'Es stehen <b>keine Angebote</b>';
  else if (offerCount == 1) text = 'Es steht <b>ein Angebot</b>';
  else text = 'Es stehen <b>'+ offerCount +' Angebote</b>'
  
  findSidebar().innerHTML = text + ' auf ihrem <a class="merkzttl" onclick="openPersonalNewsWindow(true);return false;" href="#"><b>Merkzettel</b></a>' ;
}

function overwriteHeaderlink() {
  var tableColumn = findHeaderLink();
  var remind = nwwCookies.get_watchagent_remind();
  if ((remind == "undefined") || (typeof(remind) == "undefined") || 
       (remind == "" ) || !isIffSaved(IFF)) {
    tableColumn.innerHTML = "<br /><br />" +
     '<a onclick="openPersonalNewsWindow();return false;" href="#">' +
        '<img src="http://www.nix-wie-weg.de/merkzettel/public/images/merkzettel-xs.gif" width="50" height="40" align="bottom" />' +
      '</a>';
  }
  else {
    tableColumn.innerHTML = "<br /><br />" +
     '<a onclick="openPersonalNewsWindow();return false;" href="#">' +
        '<img src="http://www.nix-wie-weg.de/merkzettel/public/images/merkzettel-xs-checked.gif" width="50" height="40" align="bottom" />' +
      '</a>';
  }
}

function getTTParams() {

  var params = new Array();
  
  params['termin'] = IBE.req.termin;
  params['termin'] = IBE.req.termin;
  params['ruecktermin'] = IBE.req.ruecktermin;
  params['iff'] = IFF;
  
  params['verpflegung'] = IBE.req.verpflegung;
  params['zimmer'] = IBE.req.zimmer;
  
  
  params['dauer'] = IBE.req.dauer;
  if (params['dauer'] == "") params['dauer'] = -1; 
  
  params['abflughafen'] = IBE.req.abflughafen;
  if (typeof(params['abflughafen']) == 'undefined' || params['abflughafen'] == "") params['abflughafen'] = "-1";
  
  params['personen'] = 0;
  params['kinder'] = new Array();
  
  var personenString = IBE.req.personen;
  var pers = personenString.split(";");

	for(var i=0;i<pers.length;i++) {
		if (pers[i] > 16) params['personen']++;
		if ((pers[i] <= 16) && (pers[i] >0)) params['kinder'].push(pers[i]);
	}
	
	if ((typeof params['kinder'][0]) == "string") params['kinder1'] = params['kinder'][0];
	if ((typeof params['kinder'][1]) == "string") params['kinder2'] = params['kinder'][1];
	if ((typeof params['kinder'][2]) == "string") params['kinder3'] = params['kinder'][2];
	
	return params;
}

function openPersonalNewsWindow(show) {
  if (!show) { 
    if (typeof(tt_strecke) == undefined || (tt_strecke != "LM" && tt_strecke != "P" && tt_strecke != "H")) {
      alert("Es können nur Lastminute- & Pauschalreisen, sowie Nur-Hotel-Angebote im Merkzettel verwalten werden.");
      throw "WrongTypeOfBooking";
    }
    params = getTTParams();
    var str = "http://www.nix-wie-weg.de/merkzettel/tt/"+
      params['iff']+"/"+
      "?abflug="+params['abflughafen']+
      "&dauer="+params['dauer']+
      "&termin="+params['termin']+
      "&zimmer="+params['zimmer']+
      "&verpflegung="+params['verpflegung']+
      "&ruecktermin="+params['ruecktermin']+
      "&personen="+params['personen'];
    if (params['kinder1']) str+= "&kinder1="+params['kinder1'];
    if (params['kinder2']) str+= "&kinder2="+params['kinder2'];
    if (params['kinder3']) str+= "&kinder3="+params['kinder3'];
    if ((tt_strecke == "LM") || (tt_strecke == "P")) str+= "&type=LM";
    else if (tt_strecke == "H") str+= "&type=HOTEL";
  }
  else {
    str = "http://www.nix-wie-weg.de/merkzettel/entry"
  }
  var width = 800;
  var height = screen.height - 200;
  var win_x = screen.width / 2 - width / 2;
  var win_y = screen.height / 2 - height / 2;
  window.open(str, 
    "merkzettel", 
    "width="+width+",height="+height+",scrollbars=yes",
    "top="+win_y+",left="+win_x);
}
 
function merkzettel_whereAmI() {
	overwriteSidebar();
	if ((typeof(IFF) != 'undefined') && (typeof(IBE) == 'object')) {
    overwriteHeaderlink();
    overwriteOfferBoxes();
	}
}

  function aff_test_for_vakanz() {
    if (typeof(anzeige_vakanz) == "string") {
      if (anzeige_vakanz == "") {
        return true;
      }
      else {
        return false;
      }
    }
    else {
      return true;
    }
  }

  function aff_find_table_by_class() {
    var tables = document.getElementsByTagName("table");
    var table = false;
    for (var i=0;i<tables.length;i++) {
      if ((tables[i].className == "botnav") ||
          (tables[i].className == "botnavALT")) {
        table = tables[i];
        break;
      }
    }
    return table;
  }

  function aff_track_click(short) {
    pageTracker._trackPageview("affiliate-redirect/"+short);
  }

  function aff_create() {

    var div  = document.createElement("div");
    var div_class = document.createAttribute("class");
    div_class.nodeValue = "vergleichstabelle";
    div.setAttributeNode(div_class);

    div.innerHTML += 'Vergleichen Sie ruhig: ';
    div.innerHTML += '<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=0"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/aidu.gif" width="83" height="21" alt="aidu" title="Angebote vergleichen bei Ab-in-den-Urlaub.de" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=1"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/travelscout24.gif" width="44" height="21" alt="travelscout24" title="Angebote vergleichen bei TravelScout24.de" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=2"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/lastminute.gif" width="60" height="21" alt="lastminute" title="Angebote vergleichen bei Lastminute.de" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=3"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/ltur.gif" width="37" height="21" alt="ltur" title="Angebote vergleichen bei Ltur.com" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=4"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/holidaycheck.gif" width="99" height="21" alt="holidaycheck" title="Angebote vergleichen bei Holidaycheck.de" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=5"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/weg.gif" width="60" height="21" alt="weg.de" title="Angebote vergleichen bei weg.de" /></a>';
    div.innerHTML += '&nbsp;&nbsp;<a target="_blank" href="http://www.nix-wie-weg.de/extern.php?id=6"><img onclick="aff_track_click(this.alt)" src="http://www.nix-wie-weg.de/images/partner/opodo.gif" width="84" height="21" alt="opodo" title="Angebote vergleichen bei Opodo" /></a>';
	div.innerHTML += '<div style="padding-top:8px;"><strong>Aber wir sind Testsieger mit dem <a target="_blank" class="underline" href="http://www.nix-wie-weg.de/info/news/testsieger-top-service-bei-nix-wie-wegde.html">besten Service</a>!</strong> (Test Mai 2009)</div>';
    
    return div;

  }
  function aff_insert(bottom_table, new_table) {
    var parent = bottom_table.parentNode
    parent.insertBefore(new_table, bottom_table.nextSibling);
  }