jQuery.fn.tooltip = function() {
  if($('#tooltip-content').length == 0)
  {
    $('body').append('<div id="tooltip-content"></div>');
  }
  return $(this).each(function(){
    var pos = $(this).offset();
    var w = $(this).width();
    var ww = $(window).width();
    var leftpos;
    if(pos.left + w + 165 > ww)
    {
      leftpos = pos.left - 165 - 20;
    } else {
      leftpos = pos.left + w + 1;
    }

    $(this).mouseover(function() {
      $('#tooltip-content').css( { 'left' : (leftpos) + 'px', 'top' : (pos.top) + 'px' } );
      if($(this).attr('title') != "")
	      $(this).attr('title2', $(this).attr('title'));
      $('#tooltip-content').html($(this).attr('title2')).fadeIn('fast');
      $(this).attr('title', '');
    });
    $(this).mouseout(function() {
      $('#tooltip-content').hide();
			$(this).attr('title2',$('#tooltip-content').text());
    });
  });
};
(function($) {
	
	$.alerts = {
		
		verticalOffset: -75,
		horizontalOffset: 0,
		repositionOnResize: true,
		overlayOpacity: .01,
		overlayColor: '#FFF',
		draggable: true,
		okButton: '&nbsp;OK&nbsp;',
		cancelButton: '&nbsp;Cancel&nbsp;',
		dialogClass: null,
		
		alert: function(message, title, callback) {
			if( title == null ) title = 'Alert';
			$.alerts._show(title, message, null, 'alert', function(result) {
				if( callback ) callback(result);
			});
		},
		
		confirm: function(message, title, callback) {
			if( title == null ) title = 'Confirm';
			$.alerts._show(title, message, null, 'confirm', function(result) {
				if( callback ) callback(result);
			});
		},
			
		prompt: function(message, value, title, callback) {
			if( title == null ) title = 'Prompt';
			$.alerts._show(title, message, value, 'prompt', function(result) {
				if( callback ) callback(result);
			});
		},
		
		_show: function(title, msg, value, type, callback) {
			
			$.alerts._hide();
			$.alerts._overlay('show');
			
			$("BODY").append(
			  '<div id="popup_container">' +
			    '<h1 id="popup_title"></h1>' +
			    '<div id="popup_content">' +
			      '<div id="popup_message"></div>' +
				'</div>' +
			  '</div>');
			
			if( $.alerts.dialogClass ) $("#popup_container").addClass($.alerts.dialogClass);
			
			var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 
			
			$("#popup_container").css({
				position: pos,
				zIndex: 99999,
				padding: 0,
				margin: 0
			});
			
			$("#popup_title").text(title);
			$("#popup_content").addClass(type);
			$("#popup_message").text(msg);
			$("#popup_message").html( $("#popup_message").text().replace(/\n/g, '<br />') );
			
			$("#popup_container").css({
				minWidth: $("#popup_container").outerWidth(),
				maxWidth: $("#popup_container").outerWidth()
			});
			
			$.alerts._reposition();
			$.alerts._maintainPosition(true);
			
			switch( type ) {
				case 'alert':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						callback(true);
					});
					$("#popup_ok").focus().keypress( function(e) {
						if( e.keyCode == 13 || e.keyCode == 27 ) $("#popup_ok").trigger('click');
					});
				break;
				case 'confirm':
					$("#popup_message").after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_ok").click( function() {
						$.alerts._hide();
						if( callback ) callback(true);
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback(false);
					});
					$("#popup_ok").focus();
					$("#popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
				break;
				case 'prompt':
					$("#popup_message").append('<br /><input type="text" size="30" id="popup_prompt" />').after('<div id="popup_panel"><input type="button" value="' + $.alerts.okButton + '" id="popup_ok" /> <input type="button" value="' + $.alerts.cancelButton + '" id="popup_cancel" /></div>');
					$("#popup_prompt").width( $("#popup_message").width() );
					$("#popup_ok").click( function() {
						var val = $("#popup_prompt").val();
						$.alerts._hide();
						if( callback ) callback( val );
					});
					$("#popup_cancel").click( function() {
						$.alerts._hide();
						if( callback ) callback( null );
					});
					$("#popup_prompt, #popup_ok, #popup_cancel").keypress( function(e) {
						if( e.keyCode == 13 ) $("#popup_ok").trigger('click');
						if( e.keyCode == 27 ) $("#popup_cancel").trigger('click');
					});
					if( value ) $("#popup_prompt").val(value);
					$("#popup_prompt").focus().select();
				break;
			}
			
			if( $.alerts.draggable ) {
				try {
					$("#popup_container").draggable({ handle: $("#popup_title") });
					$("#popup_title").css({ cursor: 'move' });
				} catch(e) { /* requires jQuery UI draggables */ }
			}
		},
		
		_hide: function() {
			$("#popup_container").remove();
			$.alerts._overlay('hide');
			$.alerts._maintainPosition(false);
		},
		
		_overlay: function(status) {
			switch( status ) {
				case 'show':
					$.alerts._overlay('hide');
					$("BODY").append('<div id="popup_overlay"></div>');
					$("#popup_overlay").css({
						position: 'absolute',
						zIndex: 99998,
						top: '0px',
						left: '0px',
						width: '100%',
						height: $(document).height(),
						background: $.alerts.overlayColor,
						opacity: $.alerts.overlayOpacity
					});
				break;
				case 'hide':
					$("#popup_overlay").remove();
				break;
			}
		},
		
		_reposition: function() {
			var top = (($(window).height() / 2) - ($("#popup_container").outerHeight() / 2)) + $.alerts.verticalOffset;
			var left = (($(window).width() / 2) - ($("#popup_container").outerWidth() / 2)) + $.alerts.horizontalOffset;
			if( top < 0 ) top = 0;
			if( left < 0 ) left = 0;
			
			// IE6 fix
			if( $.browser.msie && parseInt($.browser.version) <= 6 ) top = top + $(window).scrollTop();
			
			$("#popup_container").css({
				top: top + 'px',
				left: left + 'px'
			});
			$("#popup_overlay").height( $(document).height() );
		},
		
		_maintainPosition: function(status) {
			if( $.alerts.repositionOnResize ) {
				switch(status) {
					case true:
						$(window).bind('resize', $.alerts._reposition);
					break;
					case false:
						$(window).unbind('resize', $.alerts._reposition);
					break;
				}
			}
		}
		
	}
	
	jAlert = function(message, title, callback) {
		$.alerts.alert(message, title, callback);
	}
	
	jConfirm = function(message, title, callback) {
		$.alerts.confirm(message, title, callback);
	};
		
	jPrompt = function(message, value, title, callback) {
		$.alerts.prompt(message, value, title, callback);
	};
	
})(jQuery);var datePickerRentDefaultOptions = {
'firstDay'        : 1,
'dateFormat'      : 'dd.mm.yy',
'minDate'         : '+1d',
'maxDate'         : '+12m',
'monthNames'      : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
'monthNamesShort' : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
'showAnim'        : 'fadeIn',
'onSelect'        : function(dateText, inst) {
    var dateStart = $('#dateStart').datepicker('getDate');
    var dateEnd   = $('#dateEnd').datepicker('getDate');
    switch(this.id)
    {
      case 'dateStart':
        if(dateStart > dateEnd)
        {
          $('#dateEnd').val(dateText);
        }
        break;
      case 'dateEnd':
        if(dateEnd < dateStart)
        {
          $('#dateStart').val(dateText);
        }
        break;
      default:
        break;
    }
  }
};

var datePickerDobDefaultOptions = {
'firstDay'        : 1,
'dateFormat'      : 'dd.mm.yy',
'monthNames'      : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
'monthNamesShort' : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
'showAnim'        : 'fadeIn',
'changeYear'      : true,
'changeMonth'     : true,
'defaultDate'     : new Date(1980, 0, 1),
'maxDate'         : new Date(),
'yearRange'       : '-40:+40',
'onSelect'        : function(dateText, inst) {
    if($(this).hasClass('ajax-save'))
    {
      $(this).closest("form").submit();
    }
  }
};

var datePickerDefaultOptions = {
'firstDay'        : 1,
'dateFormat'      : 'dd.mm.yy',
'monthNames'      : ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
'monthNamesShort' : ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
'showAnim'        : 'fadeIn'
};

function callConfirm(element, message, title)
{
  url = element.getAttribute('href');
  // <base href=""> auslesen und vor "url" stellen, sonst geht der Link vom aktuellen Verzeichniss aus
  thebase = document.getElementsByTagName("base"); 
  basehref = thebase[0].href; 
  jConfirm(message, title, function(r) {
    if(r == true)
    {
      // prüfen ob in url bereits ein 'http' vorhanden ist -> IE7 hat im Element href bereits die base-url enthalten, IE8 allerdings nicht!
      var checkhttp = url.search(/http.+/);
      if (checkhttp != -1)
      {
        // IE8
        document.location.href = url;
      }
      else
      {
        // IE7
        document.location.href = basehref+url;
      }
    }
    return r;
  });
}
$(function () {
  var elFormId = document.getElementById('formid');
  if(elFormId)
  {
    // AJAX-Check
    $("#formid").closest("form.ajax").submit(function() {
      $.post($(this).attr('action') + '?ajax=1', $(this).serializeArray(), function(response) {
        var errorCount = 0;
        $(".errorDisplay").empty();
        $.each(response, function(fieldId, arrText) {
          errorCount++;
          var errorContainer = $('#' + fieldId + '-Errors');
          $.each(arrText, function(index, strText) {
            errorContainer.append('<p>' + strText + '</p>');
          });
        });
        if(errorCount == 0)
        {
          $("#formid").closest("form").unbind('submit').submit();
        }
      }, "json");
      return false;
    });
  }
  
  // Datepicker
  $(".datepicker").datepicker(datePickerDefaultOptions);
  $(".datepicker-rent").datepicker(datePickerRentDefaultOptions);
  $(".datepicker-dob").datepicker(datePickerDobDefaultOptions);
  $(".datepicker").attr('readonly', 'true');
  $(".datepicker-rent").attr('readonly', 'true');
  $(".datepicker-dob").attr('readonly', 'true');
  
  // Vista-Inputs
  $("input.vista").change(function() {
    if($(this).attr('value') == '' || $(this).attr('value') == $(this).attr('title'))
    {
      $(this).attr('value', $(this).attr('title'));
      $(this).addClass('empty');
    } else {
      $(this).removeClass('empty');
    }
  })
  .change();
  $("input.vista").focus(function() {
    if($(this).hasClass('empty'))
    {
      $(this).attr('value', '');
    }
    $(this).removeClass('empty');
  });
  $("input.vista").blur(function() {
    $(this).change();
  });
  $('form.vista').submit(function() {
    $.each($(this).find('input.vista'), function() {
      if($(this).hasClass('empty'))
      {
        $(this).attr('value', '');
      }
    });
    return true;
  });

  // Tooltips
  $('.tooltip').tooltip();
  
  $('ul.rentalsteps li').mouseover(function() {
  $(this).addClass('over');
  });
  $('ul.rentalsteps li').mouseout(function() {
  $(this).removeClass('over');
  });

  // Rent-Steps
  // Misc
  autoCompletion_init('q,land,cityName');
  stayInSession();
});

function initProductLinks()
{
  $("a.add-product,a.remove-product,a.discount-product").click(function() {
    $.post($(this).attr('href') + '?ajax=1', {}, function(response) {
      $('#products').html(response.html.products).find('.tooltip').tooltip();
      $('#checklist').html(response.html.checklist).find('.tooltip').tooltip();
      initProductLinks();
    }, "json");
    return false;
  });
  if($('#products').height() > $("#personTabBody").height())
  {
    $("#personTabBody").height($('#products').height() + 170);
  }
}
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 150;
		yOffset = -450;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
	$("a.preview").click(function(e){
    return false;
	});			
};

function changePersonName(id, name)
{
  if(name != '')
  {
  
    if($('.tab.personName'+id).text() != name)
    {
      $(".personName"+id).text(name);
      if($('#date_of_birth').attr('value') == '')
      {
        $('#date_of_birth').focus();
      }
    }
  }
}

function langselect()
{
  el  = document.getElementById('l');
  lang = el[el.selectedIndex].value;
  window.location.href=window.langbase_url+lang+'/';
}
function getPos(element)
{
	var eleft = etop = 0;
	if (element.offsetParent)
  {
		eleft = element.offsetLeft
		etop = element.offsetTop
		while (element = element.offsetParent)
    {
			eleft += element.offsetLeft
			etop += element.offsetTop
		}
	}
	return [eleft,etop];
}

var ac_q = ac_cityName = new Array('Abtenau', 'Achenkirch', 'Alpbach', 'Altenmarkt/Zauchensee', 'Aspangberg', 'Au/Bregenzerwald', 'Axamer Lizum', 'Bad Gastein', 'Bad Hofgastein', 'Bad Kleinkirchheim', 'Bichlbach', 'Bischofshofen', 'Bramberg am Wildkogel', 'Brand', 'Brixen im Thale', 'Buchau', 'Donnersbach - Planneralm', 'Eben i. Pongau', 'Ellmau', 'Feichten/Kaunertal', 'Fieberbrunn', 'Filzmoos', 'Fiss', 'Flachau', 'FÃ¼gen', 'Fulpmes', 'GaltÃ¼r', 'Gaschurn', 'Gerlos â€“ GmÃ¼nd', 'GmÃ¼nd (NÃ–)', 'Going', 'GÃ¶stling', 'Gries im Sellrain', 'Grossarl', 'Gschnitz', 'Hallstatt', 'Heiligenblut', 'Hermagor-Sonnleitn', 'Hinterglemm', 'Hinterstoder', 'Hintertux', 'HochfÃ¼gen', 'Hochimst', 'Hochkrimml', 'HochsÃ¶lden', 'Holzgau', 'Igls', 'Irdning (Riesneralm)', 'Irdning (Tauplitz)', 'Ischgl', 'Itter', 'Jerzens', 'Kals', 'Kaltenbach', 'Kappl', 'Kaprun', 'Katschberg', 'Kirchberg', 'KitzbÃ¼hel', 'KÃ¶nigsleiten-Wald', 'KÃ¶tschach', 'Krimml', 'KÃ¼htai', 'Lackenhof', 'Lanersbach', 'Lech', 'Leogang', 'Lermoos', 'Lienz  ', 'Lofer', 'Maria Alm', 'Matrei', 'Maurach', 'Mayrhofen', 'Mellau', 'MÃ¶nichkirchen', 'MÃ¼hlbach am HochkÃ¶nig', 'Mutters', 'Nassfeld Sonnenalpe', 'Nauders', 'Neukirchen', 'Neustift', 'Oberau-WildschÃ¶nau', 'Obergurgl', 'Oberndorf', 'Obertauern', 'Obertraun', 'Ã–tz', 'Pertisau-Achensee', 'Pettneu', 'Planneralm', 'Ramsau-Ort', 'Raumsau-West', 'Ried im Oberinntal', 'Rofan-Achensee', 'Saalbach', 'Saalfelden', 'Scheffau', 'Schladming - Rohrmoos', 'See im Paznaun', 'Seefeld', 'Semmering', 'Serfaus', 'Sillian', 'SÃ¶lden', 'St Ã„gyd', 'St Anton/Arlberg', 'St Gallenkirch', 'St Jakob i. Defr.', 'St Johann im Pongau', 'St Johann in Tirol', 'St Michael', 'St. Jakob i. H. ', 'St. Leonhard', 'Steinach am Brenner', 'Stuben', 'Tannheim', 'Telfes im Stubai', 'Traisen', 'Trins', 'TrÃ¶polach', 'Uttendorf', 'Vent', 'Wagrain', 'Warth', 'Werfenweng', 'Westendorf', 'Zams Landeck Fliess', 'Zell am See', 'Zell am Ziller', 'Garmisch-Partenkirchen Zugspitze', 'Nesselwang', 'RÃ¶merstein', 'Albiez Montrond', 'Alpe D\'huez', 'Alpe du grand serre', 'Areches Beauford', 'Argeles Gazost', 'Argentiere', 'Auris en oisans', 'Auron', 'Aussois', 'Avoriaz', 'Ax les Thermes', 'Bagnieres de Luchon', 'Bareges', 'Bernex', 'Bessans', 'BOLQUERE   ', 'Bourg St. Maurice', 'Bozel', 'Briancon', 'Brides les bains', 'Cauterets', 'Ceillac', 'Chalmazel', 'Chamonix', 'Chamonix Les Praz', 'CHAMONIX SUD', 'Champagny en vanoise', 'Chamrousse', 'Chatel', 'Chinaillon', 'Combloux', 'Correncon en vercors', 'Courchevel 1300', 'Courchevel 1550', 'Courchevel 1650', 'Courchevel 1850', 'Courchevel 1850', 'Crest Voland', 'EGAT', 'Embrun', 'Eyne', 'Flaine', 'Font Romeu', 'Gourette', 'Guzet Neige', 'Habere Poche', 'Isola 2000', 'L\'Argentiere la bessee', 'La Chapelle D\'Abondance', 'La Clusaz', 'La Colmiane Valdeblore', 'La Feclaz', 'La Foux D\'allos', 'La Juoue du loup', 'La Mongie', 'LA NORMA', 'La Plagne - Belle-Plagne', 'La Plagne - Bellecote', 'La Plagne - Centre Aime', 'La Plagne - Les Coches', 'La Plagne - Montalbert', 'La Plagne - Villages', 'La Plagne 1800', 'La Plagne Montchavin', 'La RosiÃ¨re', 'La Tania', 'La Toussuire', 'Lanslebourg val cenis', 'Lanslevillard val cenis', 'Le Chinaillon (Le Gd Bornand)', 'Le Collet D Allevard', 'Le Corbier', 'Le Grand bornand', 'Le Mont Dore', 'Le Praz de lys', 'Le Sauze ', 'Lelex', 'Les 7 Laux', 'Les Agudes', 'Les Angles', 'Les Arcs 1600', 'Les Arcs 1800', 'Les Arcs 1950', 'Les Arcs 2000', 'Les Carroz d\'araches', 'Les Contamines Montjoie', 'Les Contamines-Mont Joie', 'Les deux Alpes', 'Les Gets', 'Les Houches', 'Les Menuires', 'Les Menuires Reberty', 'Les Orres', 'Les Rousses', 'Les Saisies', 'MANIGOD LA CROIX FRY', 'MegÃ¨ve', 'Megeve (Demi Quartier)', 'Meribel', 'Meribel les Allues', 'Meribel Mottaret', 'Mijoux', 'Montgenevre', 'Montriond', 'Morillon 1100', 'Morillon Village', 'Morzine', 'Notre Dame de Bellecombe', 'Orcieres Melette', 'Oz en oisans', 'Peisey Vallandry', 'Pelvoux', 'Peyragudes', 'Piau Engally', 'Plateau d\'assy', 'Pra Loup', 'Pralognan la Vanoise', 'Praz sur arly', 'Puy St. Vincent', 'Reallon', 'Risoul 1850', 'Risoul 1851', 'Saint Colomban-Villards', 'Saint Francois Longchamp', 'Saint gervais les bains', 'Saint Jean D\'Arves', 'Saint Jean de Sixt', 'Saint Layr', 'Saint Leger Les Melezes', 'Saint Martin de Belleville', 'Saint Sorlin D\'arves', 'Sainte foy en Tarentaise', 'Samoens', 'Samoens 1600', 'Savignac Les Ormeaux', 'Serre Chevalier 1200 (Briancon)', 'Serre Chevalier 1400', 'Serre Chevalier Chantemerle', 'Serre Chevalier Villeneuve', 'Sixt fer a Cheval', 'St Pierre dels Forctas', 'Super Lioran', 'Superdevoluy', 'Termignon', 'Thollon les Memises', 'Tignes Lavachet', 'Tignes le Lac', 'Tignes les Boisses', 'Tignes les Breviere', 'Tignes val Claret', 'Val d\'isere', 'Val Thorens', 'Valberg', 'Valfrejus', 'Valloire', 'Vallouise', 'Valmeinier 1500', 'Valmeinier 1800', 'Valmorel', 'Vars', 'Vaujany', 'Villard de lans', 'Villard reculas', 'Alleghe', 'Alta Badia   ', 'Andalo', 'Antholz Obertal', 'Arabba', 'Ascoli Piceno', 'Badia', 'Bardonecchia', 'Bormio', 'Bormio 2000', 'Breuil Cervinia', 'Brixen', 'Bruneck-Reischach', 'Campitello di Fassa ', 'Canazei', 'Caspoggio', 'Cavalese', 'Champoluc', 'Chiesa Valmalenco', 'Claviere', 'Cortina d\'Ampezzo', 'Courmayeur', 'Falcade', 'Folgaria', 'Gossensass', 'Hafling', 'Innichen', 'La Thuile', 'LavazÃ¨', 'Livigno', 'Madesimo', 'Madonna di Campiglio', 'Meran-Meran 2000', 'Meransen', 'Moena', 'Nevegal', 'Olang', 'Passo Tonale', 'Piancavallo', 'Pozza di Fassa', 'Pragelato', 'Ratschings', 'Ridnaun', 'Rivisondoli', 'Roccaraso', 'San Martino d. Castrozza', 'Sand in Taufers', 'Sankt Christina', 'Sankt Walburg', 'Sauze d\'Oulx', 'Schnals', 'Sestriere', 'St Ulrich', 'Stern in Abtei', 'Sterzing', 'Toblach', 'Vigo di Fassa', 'Welschnofen', 'Wolkenstein', 'Andermatt', 'Arosa', 'Bad Ragaz', 'Bettmeralp', 'Brigels', 'Celerina', 'Crans Montana', 'Davos-Dorf', 'Davos-Platz', 'Disentis', 'Engelberg', 'Fiesch', 'Flims', 'GrÃ¤chen', 'Grindelwald', 'Gstaad', 'Interlaken / Matten', 'Kandersteg', 'Klosters', 'Laax 2', 'Le ChÃ¢ble â€“ Verbier', 'Lenk', 'Lenzerheide', 'Leysin', 'Meiringen', 'Morgins', 'Riederalp', 'Rougemont', 'Saanen-Gstaad', 'Saas-Almagell', 'Saas-Fee', 'Samnaun', 'Savognin', 'Silvaplana', 'Silvaplana-Surlej', 'St Moritz', 'St Moritz 3 Bad', 'St Moritz Bad', 'Verbier', 'Veysonnaz', 'Villars', 'Wangs', 'Wildhaus', 'Zermatt', 'Zuoz', 'Zweisimmen', 'Cerny Dul', 'Filipovice', 'Harrachov', 'JesenÃ­k', 'Karlov', 'Lipno nad Vltavou', 'LudvÃ­kov', 'Miroslav LipovÃ¡ LÃ¡znÄ›', 'Mlade Buky', 'OstruÅ¾nÃ¡', 'PetrÃ­kov', 'Spindleruv Mlyn', 'Tanvald', 'ZlatÃ© Hory', 'Arinsal', 'Canillo', 'El Tarter', 'Encamp', 'Grau Roig', 'La Massana', 'La Massana / Pal', 'Pas de la Casa', 'Soldeu');
var ac_land_de = new Array('Abchasien', 'Afghanistan', 'Ã„gypten', 'Albanien', 'Algerien', 'Andorra', 'Angola', 'Antigua und Barbuda', 'Ã„quatorialguinea', 'Argentinien', 'Armenien', 'Aserbaidschan', 'Ã„thiopien', 'Australien', 'Bahamas', 'Bahrain', 'Bangladesch', 'Barbados', 'Belgien', 'Belize', 'Benin', 'Bergkarabach (Republik)', 'Bhutan', 'Bolivien', 'Bosnien und Herzegowina', 'Botsuana', 'Brasilien', 'Brunei', 'Bulgarien', 'Burkina Faso', 'Burundi', 'Chile', 'China, Republik (Taiwan)', 'China, Volksrepublik', 'Cookinseln', 'Costa Rica', 'DÃ¤nemark', 'Deutschland', 'Dominica', 'Dominikanische Republik', 'Dschibuti', 'Ecuador', 'El Salvador', 'ElfenbeinkÃ¼ste', 'Eritrea', 'Estland', 'Fidschi', 'Finnland', 'Frankreich', 'Gabun', 'Gambia', 'Georgien', 'Ghana', 'Grenada', 'Griechenland', 'Guatemala', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Honduras', 'Indien', 'Indonesien', 'Irak', 'Iran', 'Irland', 'Island', 'Israel', 'Italien', 'Jamaika', 'Japan', 'Jemen', 'Jordanien', 'Kambodscha', 'Kamerun', 'Kanada', 'Kap Verde', 'Kasachstan', 'Katar', 'Kenia', 'Kirgisistan', 'Kiribati', 'Kolumbien', 'Komoren', 'Kongo, Demokratische Republik', 'Kongo, Republik', 'Korea, Demokratische Volksrepublik', 'Korea, Republik', 'Kroatien', 'Kuba', 'Kuwait', 'Laos', 'Lesotho', 'Lettland', 'Libanon', 'Liberia', 'Libyen', 'Liechtenstein', 'Litauen', 'Luxemburg', 'Madagaskar', 'Malawi', 'Malaysia', 'Malediven', 'Mali', 'Malta', 'Marokko', 'Marshallinseln', 'Mauretanien', 'Mauritius', 'Mazedonien', 'Mexiko', 'Mikronesien', 'Moldawien', 'Monaco', 'Mongolei', 'Montenegro', 'Mosambik', 'Myanmar', 'Namibia', 'Nauru', 'Nepal', 'Neuseeland', 'Nicaragua', 'Niederlande', 'Niger', 'Nigeria', 'Niue', 'Norwegen', 'Oman', 'Ã–sterreich', 'Osttimor', 'Pakistan', 'PalÃ¤stinensische Autonomiegebiete', 'Palau', 'Panama', 'Papua-Neuguinea', 'Paraguay', 'Peru', 'Philippinen', 'Polen', 'Portugal', 'Ruanda', 'RumÃ¤nien', 'Russland', 'Salomonen', 'Sambia', 'Samoa', 'San Marino', 'SÃ£o TomÃ© und PrÃ­ncipe', 'Saudi-Arabien', 'Schweden', 'Schweiz', 'Senegal', 'Serbien', 'Seychellen', 'Sierra Leone', 'Simbabwe', 'Singapur', 'Slowakei', 'Slowenien', 'Somalia', 'Somaliland', 'Spanien', 'Sri Lanka', 'St. Kitts und Nevis', 'St. Lucia', 'St. Vincent und die Grenadinen', 'SÃ¼dafrika', 'Sudan', 'SÃ¼dossetien', 'Suriname', 'Swasiland', 'Syrien', 'Tadschikistan', 'Tansania', 'Thailand', 'Togo', 'Tonga', 'Transnistrien', 'Trinidad und Tobago', 'Tschad', 'Tschechien', 'Tunesien', 'TÃ¼rkei', 'TÃ¼rkische Republik Nordzypern', 'Turkmenistan', 'Tuvalu', 'Uganda', 'Ukraine', 'Ungarn', 'Uruguay', 'Usbekistan', 'Vanuatu', 'Vatikanstadt', 'Venezuela', 'Vereinigte Arabische Emirate', 'Vereinigtes KÃ¶nigreich GroÃŸbritannien und Nordirland', 'Vereinigte Staaten von Amerika', 'Vietnam', 'WeiÃŸrussland', 'Westsahara', 'Zentralafrikanische Republik', 'Zypern');
var ac_land_en  = new Array('Andorra', 'United Arab Emirates', 'Afghanistan', 'Antigua and Barbuda', 'Anguilla', 'Albania', 'Armenia', 'Netherlands Antilles', 'Angola', 'Antarctica', 'Argentina', 'American Samoa', 'Austria', 'Australia', 'Aruba', 'Azerbaijan', 'Bosnia and Herzegovina', 'Barbados', 'Bangladesh', 'Belgium', 'Burkina Faso', 'Bulgaria', 'Bahrain', 'Burundi', 'Benin', 'Bermuda', 'Brunei Darussalam', 'Bolivia', 'Brazil', 'Bahamas', 'Bhutan', 'Bouvet Island', 'Botswana', 'Belarus', 'Belize', 'Canada', 'Cocos Islands', 'Democratic Republic of the Congo', 'Central African Republic', 'Republic of the Congo', 'Switzerland', 'CÃ´te d\'Ivoire', 'Ivory Coast', 'Cook Islands', 'Chile', 'Cameroon', 'China', 'Colombia', 'Costa Rica', 'Cuba', 'Cape Verde', 'Christmas Island', 'Cyprus', 'Czech Republic', 'Germany', 'Djibouti', 'Denmark', 'Dominica', 'Dominican Republic', 'Algeria', 'Ecuador', 'Estonia', 'Egypt', 'Western Sahara', 'Eritrea', 'Spain', 'Ethiopia', 'Finland', 'Fiji', 'Falkland Islands', 'Federated States of Micronesia', 'Faroe Islands', 'France', 'Gabon', 'United Kingdom', 'Grenada', 'Georgia', 'French Guiana', 'Ghana', 'Gibraltar', 'Greenland', 'Gambia', 'Guinea', 'Guadeloupe', 'Equatorial Guinea', 'Greece', 'South Georgia and the South Sandwich Islands', 'Guatemala', 'Guam', 'Guinea-Bissau', 'Guyana', 'Hong Kong', 'Heard Island and McDonald Islands', 'Honduras', 'Croatia', 'Haiti', 'Hungary', 'Indonesia', 'Ireland', 'Israel', 'India', 'British Indian Ocean Territory', 'Iraq', 'Iran', 'Iceland', 'Italy', 'Jamaica', 'Jordan', 'Japan', 'Kenya', 'Kyrgyzstan', 'Cambodia', 'Kiribati', 'Comoros', 'Saint Kitts and Nevis', 'North Korea', 'South Korea', 'Kuwait', 'Cayman Islands', 'Kazakhstan', 'Laos', 'Lebanon', 'Saint Lucia', 'Liechtenstein', 'Sri Lanka', 'Liberia', 'Lesotho', 'Lithuania', 'Luxembourg', 'Latvia', 'Libya', 'Morocco', 'Monaco', 'Moldova', 'Madagascar', 'Marshall Islands', 'Macedonia', 'Mali', 'Myanmar', 'Mongolia', 'Macau', 'Northern Mariana Islands', 'Martinique', 'Mauritania', 'Montserrat', 'Malta', 'Mauritius', 'Maldives', 'Malawi', 'Mexico', 'Malaysia', 'Mozambique', 'Namibia', 'New Caledonia', 'Niger', 'Norfolk Island', 'Nigeria', 'Nicaragua', 'Netherlands', 'Norway', 'Nepal', 'Nauru', 'Niue', 'New Zealand', 'Oman', 'Panama', 'Peru', 'French Polynesia', 'Papua New Guinea', 'Philippines', 'Pakistan', 'Poland', 'Saint Pierre and Miquelon', 'Pitcairn Islands', 'Puerto Rico', 'Occupied Palestinian Territories', 'Portugal', 'Palau', 'Paraguay', 'Qatar', 'Reunion', 'Romania', 'Russia', 'Rwanda', 'Saudi Arabia', 'Solomon Islands', 'Seychelles', 'Sudan', 'Sweden', 'Singapore', 'Saint Helena', 'Slovenia', 'Svalbard and Jan Mayen Islands', 'Slovakia', 'Sierra Leone', 'San Marino', 'Senegal', 'Somalia', 'Suriname', 'Sao Tome and Principe', 'El Salvador', 'Syria', 'Swaziland', 'Turks and Caicos Islands', 'Chad', 'French Southern and Antarctic Lands', 'Togo', 'Thailand', 'Tajikistan', 'Tokelau', 'Turkmenistan', 'Tunisia', 'Tonga', 'East Timor', 'Turkey', 'Trinidad and Tobago', 'Tuvalu', 'Taiwan', 'Tanzania', 'Ukraine', 'Uganda', 'United States Minor Outlying Islands', 'United States of America', 'Uruguay', 'Uzbekistan', 'Vatican City State', 'Saint Vincent and the Grenadines', 'Venezuela', 'British Virgin Islands', 'U.S. Virgin Islands', 'Vietnam', 'Vanuatu', 'Wallis and Futuna', 'Samoa', 'Yemen', 'Mayotte', 'Yugoslavia', 'South Africa', 'Zambia', 'Zimbabwe');
var ac_land = ac_land_de.concat(ac_land_en);
var input;
var ac_index;
RegExp.escape = function(text) {
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}
function autoCompletion_init(ids)
{
  var a_id  = ids.split(',');
  for(i=0;i<a_id.length;i++)
  {
    id  = a_id[i];
    element = document.getElementById(id);
    if(element)
    {
      element.onkeyup     = autoCompletion_update;
      element.onfocus     = autoCompletion_update;
//      element.onmouseover = autoCompletion_update;
//      element.onmouseout  = autoCompletion_setTimeout;
      element.onfocus     = autoCompletion_update;
      element.onblur      = autoCompletion_setTimeout;
      element.setAttribute("autocomplete","off");
    }
  }
}
function autoCompletion_switch(id)
{
  try
  {
    window.input  = document.getElementById(id);
  } catch(e)
  {
    return false;
  }
  if(window.input)
  {
    if(window.input)
    {
      if(window.input.tagName=='INPUT')
      {
        window.ac_index = eval('window.ac_'+id);
        list  = document.getElementById('acdisplay');

        a_pos = getPos(window.input);
        list.style.position = 'absolute';
        list.style.left = a_pos[0]+'px';
        list.style.top = a_pos[1]+window.input.offsetHeight+1+'px';
      }
    }
  }
}
function autoCompletion_update(e)
{
  autoCompletion_clearTimeout();
  if (!e) e = window.event;
  if (e.target) target = e.target;
  else if (e.srcElement) target = e.srcElement;
  id  = target.getAttribute('id');
  autoCompletion_switch(id, e);
  keycode = e.keyCode;
  matches = autoCompletion_search(target);
  if(matches.length>=0 && matches.length<=100)
  {
    autoCompletion_buildUI(matches);
  } else {
    autoCompletion_clearUI(matches);
  }
  autoCompletion_monitor(matches.length+' matches');
  return true;
}
function autoCompletion_setTimeout(e)
{
  window.to = window.setTimeout("autoCompletion_hideUI()", 200);
}
function autoCompletion_clearTimeout(e)
{
  window.clearTimeout(window.to);
}
function autoCompletion_buildUI(matches)
{
  autoCompletion_clearUI();
  query = window.input.value;
  rx_primary    = new RegExp("^("+RegExp.escape(query)+")(.*)$", "gi");
  rx_secondary  = new RegExp("^(.+)("+RegExp.escape(query)+")(.*)$", "gi");
  list  = document.getElementById('acdisplay');
  len   = matches.length;
  for(i=0;i<len&&i<5;i++)
  {
    var item      = document.createElement('li');
    var span      = document.createElement('span');
    var link      = document.createElement('a');
    link.setAttribute('href', '#search');
    link.onclick      = autoCompletion_click;
    var text      = matches[i];
    if(text.match(rx_primary))
    {
      text_marked   = text.replace(rx_primary, "$1");
      text_unmarked = text.replace(rx_primary, "$2");
      if(text_unmarked==text_marked)
      {
        text_unmarked = '';
      }
      var marked    = document.createTextNode(text_marked);
      span.appendChild(marked);
      span.className = 'primary';
      var unmarked  = document.createTextNode(text_unmarked);
      link.appendChild(span);
      link.appendChild(unmarked);
    } else {
      part1 = document.createTextNode(text.replace(rx_secondary, "$1"));
      part2 = document.createTextNode(text.replace(rx_secondary, "$2"));
      span.appendChild(part2);
      span.className = 'secondary';
      part3 = document.createTextNode(text.replace(rx_secondary, "$3"));
      sec   = document.createTextNode(part1+part2+part3);
      link.appendChild(part1);
      link.appendChild(span);
      link.appendChild(part3);
    }
    item.appendChild(link);
    list.appendChild(item);
  }
  if(i>0)
  {
    list.style.display='';
//    list.onmouseover  = autoCompletion_clearTimeout;
//    list.onmouseout   = autoCompletion_setTimeout;
  }
}
function autoCompletion_click(e)
{
  if (!e) e = window.event;
  if (e.target) target = e.target;
  else if (e.srcElement) target = e.srcElement;
  input = window.input;
  switch(target.tagName)
  {
    case 'A':
      el_a    = target;
      el_span = target.getElementsByTagName('SPAN')[0];
      break;
    case 'SPAN':
      el_a    = target.parentNode;
      el_span = target;
      break;
  }
  text  = '';
  parts = el_a.childNodes.length;
  for(i=0;i<parts;i++)
  {
    part = el_a.childNodes[i];
    if(part.nodeType==3)
    {
      text += part.nodeValue;
    } else {
      text += part.firstChild.nodeValue;
    }
  }
  input.value = text;
  autoCompletion_clearUI();
  switch(input.getAttribute('id'))
  {
    case 'q':
      document.getElementById('search').submit();
      break;
    case 'land':
      break;
  }
  return false;
}
function autoCompletion_clearUI()
{
  list  = document.getElementById('acdisplay');
  first = list.firstChild;
  while(list.childNodes.length>0)
  {
    list.removeChild(list.firstChild);
  }
  autoCompletion_hideUI();
}
function autoCompletion_hideUI()
{
  list  = document.getElementById('acdisplay');
  list.style.display='none';
}
function autoCompletion_search(el_input)
{
  if(el_input.tagName=='INPUT')
  {
    needle  = el_input.value.toLowerCase();
    rx  = new RegExp('^.*'+RegExp.escape(needle)+'.*$', 'gi');
    len = window.ac_index.length;
    result_primary    = new Array();
    result_secondary  = new Array();
    for(i=0;i<len;i++)
    {
      value = window.ac_index[i];
      haystack = value.toLowerCase();
      if(haystack.length >= needle.length)
      {
        if(haystack.substr(0, needle.length) == needle)
        {
          result_primary.push(value);
        } else if (haystack.match(rx))
        {
          result_secondary.push(value);
        }
      }
    }
    re = result_primary.concat(result_secondary);
  } else {
    re = false;
  }
  return re;
}
function autoCompletion_monitor(value)
{
  return false;
  var monitor = document.getElementById('monitor').firstChild;
  monitor.nodeValue = value;
}
function stayInSession()
{
  window.stayInTimeout = window.setTimeout("goToBookingList()", 720000); // 12m
 }
function goToBookingList()
{
  window.location.href = home_url + 'rent/';
}

function getWinWidth(){
	var win = window;
	
	width = win.innerWidth ? win.innerWidth : win.document.body.clientWidth;
	
	if(checkBrowserName('MSIE')){  
		width+= 20;
		version = navigator.appVersion.substring(17,24);
		if(version == "MSIE 8.")
		{
			width+= 1;
			compatibititymode = document.documentMode;
			if(compatibititymode == 8)// 8 = kein Kompatibilitätsmodus
			{
				width-= 17;
			}
		}
 	}  
//	if(checkBrowserName('opera')){  
//	}  
//	if(checkBrowserName('safari')){  
//	}  
//	if(checkBrowserName('firefox')){  
//	}  

	return width;
}

function checkBrowserName(name){  
	var agent = navigator.userAgent.toLowerCase();  
	if (agent.indexOf(name.toLowerCase())>-1) {  
		return true;  
	}  
	return false;  
}
function doOnResize()
{
	width = getWinWidth();
	if(width <= 1100)
	{
			$("#content_home")
			.css("right",(15) + "px");
	}
	else
	{
			$("#content_home")
			.css("right",(100) + "px");		
	}
	// Tooltips
  $('.tooltip').tooltip();
}