/**
 * jQuery.query - Query String Modification and Creation for jQuery
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2009/8/13
 *
 * @author Blair Mitchelmore
 * @version 2.1.7
 * http://plugins.jquery.com/project/query-object
 * http://plugins.jquery.com/node/345/release?order=file_name&sort=desc
 **/
new function(settings) { 
  // Various Settings
  var $separator = settings.separator || '&';
  var $spaces = settings.spaces === false ? false : true;
  var $suffix = settings.suffix === false ? '' : '[]';
  var $prefix = settings.prefix === false ? false : true;
  var $hash = $prefix ? settings.hash === true ? "#" : "?" : "";
  var $numbers = settings.numbers === false ? false : true;
  
  jQuery.query = new function() {
    var is = function(o, t) {
      return o != undefined && o !== null && (!!t ? o.constructor == t : true);
    };
    var parse = function(path) {
      var m, rx = /\[([^[]*)\]/g, match = /^([^[]+)(\[.*\])?$/.exec(path), base = match[1], tokens = [];
      while (m = rx.exec(match[2])) tokens.push(m[1]);
      return [base, tokens];
    };
    var set = function(target, tokens, value) {
      var o, token = tokens.shift();
      if (typeof target != 'object') target = null;
      if (token === "") {
        if (!target) target = [];
        if (is(target, Array)) {
          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
        } else if (is(target, Object)) {
          var i = 0;
          while (target[i++] != null);
          target[--i] = tokens.length == 0 ? value : set(target[i], tokens.slice(0), value);
        } else {
          target = [];
          target.push(tokens.length == 0 ? value : set(null, tokens.slice(0), value));
        }
      } else if (token && token.match(/^\s*[0-9]+\s*$/)) {
        var index = parseInt(token, 10);
        if (!target) target = [];
        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
      } else if (token) {
        var index = token.replace(/^\s*|\s*$/g, "");
        if (!target) target = {};
        if (is(target, Array)) {
          var temp = {};
          for (var i = 0; i < target.length; ++i) {
            temp[i] = target[i];
          }
          target = temp;
        }
        target[index] = tokens.length == 0 ? value : set(target[index], tokens.slice(0), value);
      } else {
        return value;
      }
      return target;
    };
    
    var queryObject = function(a) {
      var self = this;
      self.keys = {};
      
      if (a.queryObject) {
        jQuery.each(a.get(), function(key, val) {
          self.SET(key, val);
        });
      } else {
        jQuery.each(arguments, function() {
          var q = "" + this;
          q = q.replace(/^[?#]/,''); // remove any leading ? || #
          q = q.replace(/[;&]$/,''); // remove any trailing & || ;
          if ($spaces) q = q.replace(/[+]/g,' '); // replace +'s with spaces
          
          jQuery.each(q.split(/[&;]/), function(){
            var key = decodeURIComponent(this.split('=')[0] || "");
            var val = decodeURIComponent(this.split('=')[1] || "");
            
            if (!key) return;
            
            if ($numbers) {
              if (/^[+-]?[0-9]+\.[0-9]*$/.test(val)) // simple float regex
                val = parseFloat(val);
              else if (/^[+-]?[0-9]+$/.test(val)) // simple int regex
                val = parseInt(val, 10);
            }
            
            val = (!val && val !== 0) ? true : val;
            
            if (val !== false && val !== true && typeof val != 'number')
              val = val;
            
            self.SET(key, val);
          });
        });
      }
      return self;
    };
    
    queryObject.prototype = {
      queryObject: true,
      has: function(key, type) {
        var value = this.get(key);
        return is(value, type);
      },
      GET: function(key) {
        if (!is(key)) return this.keys;
        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
        var target = this.keys[base];
        while (target != null && tokens.length != 0) {
          target = target[tokens.shift()];
        }
        return typeof target == 'number' ? target : target || "";
      },
      get: function(key) {
        var target = this.GET(key);
        if (is(target, Object))
          return jQuery.extend(true, {}, target);
        else if (is(target, Array))
          return target.slice(0);
        return target;
      },
      SET: function(key, val) {
        var value = !is(val) ? null : val;
        var parsed = parse(key), base = parsed[0], tokens = parsed[1];
        var target = this.keys[base];
        this.keys[base] = set(target, tokens.slice(0), value);
        return this;
      },
      set: function(key, val) {
        return this.copy().SET(key, val);
      },
      REMOVE: function(key) {
        return this.SET(key, null).COMPACT();
      },
      remove: function(key) {
        return this.copy().REMOVE(key);
      },
      EMPTY: function() {
        var self = this;
        jQuery.each(self.keys, function(key, value) {
          delete self.keys[key];
        });
        return self;
      },
      load: function(url) {
        var hash = url.replace(/^.*?[#](.+?)(?:\?.+)?$/, "$1");
        var search = url.replace(/^.*?[?](.+?)(?:#.+)?$/, "$1");
        return new queryObject(url.length == search.length ? '' : search, url.length == hash.length ? '' : hash);
      },
      empty: function() {
        return this.copy().EMPTY();
      },
      copy: function() {
        return new queryObject(this);
      },
      COMPACT: function() {
        function build(orig) {
          var obj = typeof orig == "object" ? is(orig, Array) ? [] : {} : orig;
          if (typeof orig == 'object') {
            function add(o, key, value) {
              if (is(o, Array))
                o.push(value);
              else
                o[key] = value;
            }
            jQuery.each(orig, function(key, value) {
              if (!is(value)) return true;
              add(obj, key, build(value));
            });
          }
          return obj;
        }
        this.keys = build(this.keys);
        return this;
      },
      compact: function() {
        return this.copy().COMPACT();
      },
      toString: function() {
        var i = 0, queryString = [], chunks = [], self = this;
        var encode = function(str) {
          str = str + "";
          if ($spaces) str = str.replace(/ /g, "+");
          return encodeURIComponent(str);
        };
        var addFields = function(arr, key, value) {
          if (!is(value) || value === false) return;
          var o = [encode(key)];
          if (value !== true) {
            o.push("=");
            o.push(encode(value));
          }
          arr.push(o.join(""));
        };
        var build = function(obj, base) {
          var newKey = function(key) {
            return !base || base == "" ? [key].join("") : [base, "[", key, "]"].join("");
          };
          jQuery.each(obj, function(key, value) {
            if (typeof value == 'object') 
              build(value, newKey(key));
            else
              addFields(chunks, newKey(key), value);
          });
        };
        
        build(this.keys);
        
        if (chunks.length > 0) queryString.push($hash);
        queryString.push(chunks.join($separator));
        
        return queryString.join("");
      }
    };
    
    return new queryObject(location.search, location.hash);
  };
}(jQuery.query || {}); // Pass in jQuery.query as settings object


function getVieportWidth() {
  try {
   var elDiv = document.createElement('div');
   elDiv.style.widht="100%";
   elDiv.style.height="5000px";
   document.body.appendChild (elDiv);
   var nViewportWidth = document.body.clientWidth;
   //alert("V2: "+nViewportWidth);
   document.body.removeChild(elDiv);
   return nViewportWidth;
  } catch(err) {
    //alert(err);
    return -1;
  }
}

function gupSimple(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if (results == null) {
    return null;
  } else {
    var res = results[1];
    return res;
  }
};
function gupMultiPars(_sName, _bTryAll, _nFromIndex) {
  var sUrl = window.location.href;
  var n1 = (!_nFromIndex) ? sUrl.indexOf("?") : _nFromIndex;
  if (-1 === n1) {
    return null;
  }
  var n2 = sUrl.indexOf(_sName+"=", n1);
  if (-1 === n2) {
    return null;
  }
  var n3 = sUrl.indexOf("&",n2);
  n3 = (n3 === -1) ? sUrl.length : n3;
  var sResult = sUrl.substring(n2+_sName.length+1,n3);
  if ((!_bTryAll) || ( (sResult != "") && (sResult != "-1") && (sResult != "-"))) {
    return sResult;
  } else {
    sResult = gupMultiPars(_sName, true, n3);
    return sResult;
  }
};
 
function getAdSenseChannel(_sAgentParam) {
  var sChannel = "-";
  if ((null !== _sAgentParam) && (_sAgentParam.indexOf("x") === 0)) {
    sChannel = "1524099894"; // lastminito_ASF
  } else {
    if ($(document).width() > 1238) {
      sChannel = "6854677933"; // AFS_bottom+right240
    } else if ($(document).width() > 1218) {
      sChannel = "3048880049"; // AFS_bottom+right220
    } else {
      sChannel = "3131458875"; // AFS_bottom
    }
  }
  return sChannel;
} 


function trim (zeichenkette) {
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}

function Search() {
 window.document.GO.DVON.value =  window.document.GO.M_VON.value + window.document.GO.D_VON.value;
 window.document.GO.DBIS.value =  window.document.GO.M_BIS.value + window.document.GO.D_BIS.value;
 // Rückflug in X Tagen
 //window.document.GO.TB.value=parseInt(window.document.GO.TB.value)-parseInt(window.document.GO.TV.value);

 // Abflughäfen
 window.document.GO.RW.value = "-";
 var sRw = null;
 if (window.document.GO.RW0.selectedIndex != 0) {
  sRw = window.document.GO.RW0.value;
 }
 if (window.document.GO.RW1.selectedIndex != 0) {
  if (null === sRw) {
   sRw = window.document.GO.RW1.value;
  } else {
   sRw = sRw+"x"+window.document.GO.RW1.value;
  }
 }
 if (window.document.GO.RW2.selectedIndex != 0) {
  if (null === sRw) {
   sRw = window.document.GO.RW2.value;
  } else {
   sRw = sRw+"x"+window.document.GO.RW2.value;
  }
 }
 if (window.document.GO.RW4.selectedIndex != 0) {
  if (null === sRw) {
   sRw = window.document.GO.RW4.value;
  } else {
   sRw = sRw+"x"+window.document.GO.RW4.value;
  }
 }
 if (null != sRw) {
  window.document.GO.RW.value = sRw;
 }

 /*----------------------Checkbox HA---------------------------------*/
 if (window.document.GO.HA2) {
  // nur, wenn die Optionen verfügbar sind
	 var sHa = null;
	 if (window.document.GO.HA2.checked) {
	  sHa = window.document.GO.HA2.value;
	 }
	 if (window.document.GO.HA3.checked) {
	  sHa = (sHa === null) ? "" : sHa+"&";
	  sHa += window.document.GO.HA3.value;
	 }
	 if (window.document.GO.HA4.checked) {
	  sHa = (sHa === null) ? "" : sHa+"&";
	  sHa += window.document.GO.HA4.value;
	 }
	 if (window.document.GO.HA6.checked) {
	  sHa = (sHa === null) ? "" : sHa+"&";
	  sHa += window.document.GO.HA6.value;
	 }
	 if (window.document.GO.HA7.checked) {
	  sHa = (sHa === null) ? "" : sHa+"&";
	  sHa += window.document.GO.HA7.value;
	 }
	 if (sHa !== null) {
	  window.document.GO.OPTS.value = sHa;
	 }
	/*--------------------------------------------------------------------------*/
	/* delete name attributes to keep url short and unique for caching */
	window.document.GO.D_VON.removeAttribute("name");
	window.document.GO.M_VON.removeAttribute("name");
	window.document.GO.D_BIS.removeAttribute("name");
	window.document.GO.M_BIS.removeAttribute("name");
	window.document.GO.RW0.removeAttribute("name");
	window.document.GO.RW1.removeAttribute("name");
	window.document.GO.RW2.removeAttribute("name");
	window.document.GO.RW4.removeAttribute("name");
	window.document.GO.HA2.removeAttribute("name");
	window.document.GO.HA3.removeAttribute("name");
	window.document.GO.HA4.removeAttribute("name");
	//window.document.GO.HA5.removeAttribute("name");
	window.document.GO.HA6.removeAttribute("name");
	window.document.GO.HA7.removeAttribute("name");
 }

//window.document.GO.XK4.removeAttribute("name");// hs

window.document.GO.submit(); 
/* restore name attributes for opera */
document.getElementById("D_VON").setAttribute("name", "D_VON");
document.getElementById("M_VON").setAttribute("name", "M_VON");
document.getElementById("D_BIS").setAttribute("name", "D_BIS");
document.getElementById("M_BIS").setAttribute("name", "M_BIS");

document.getElementById("RW0").setAttribute("name", "RW0");
document.getElementById("RW1").setAttribute("name", "RW1");
document.getElementById("RW2").setAttribute("name", "RW2");
document.getElementById("RW4").setAttribute("name", "RW4");

document.getElementById("HA2").setAttribute("name", "HA2");
document.getElementById("HA3").setAttribute("name", "HA3");
document.getElementById("HA4").setAttribute("name", "HA4");
//document.getElementById("HA5").setAttribute("name", "HA5");
document.getElementById("HA6").setAttribute("name", "HA6");
document.getElementById("HA7").setAttribute("name", "HA7");

/* window.location.href = "suchen.html"; */

}

var _gaq = _gaq || []; // for google analytics

