
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}


/**
 * Sprachen fuer den Datepicker
 */

var regional = {
	de: {
		closeText: 'schließen',
		prevText: '&#x3c;zurück',
		nextText: 'vor&#x3e;',
		currentText: 'heute',
		monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'],
		monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'],
		dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
		dayNamesShort: ['Son','Mon','Die','Mit','Don','Fre','Sam'],
		dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
		firstDay: 1,
		dateFormat: 'DD, d. MM yy',
		isRTL: false,
		showButtonPanel: false,
		dateDateFormat: 'd. mmmm yyyy',
		checkinTitle: 'Klicken, um das Datum zu ändern',
		checkoutTitle: 'Klicken, um das Datum zu ändern'
	},
	cz: {
		closeText: 'blízko',
		prevText: '&#x3c;zpěd',
		nextText: 'před&#x3e;',
		currentText: 'dnes',
		monthNames: ['leden','únor','březen','duben','květen','červen', 'červenec','srpen','září','říjen','listopad','prosinec'],
		monthNamesShort: ['led','úno','bře','du','kvě','čer', 'čer','srp','zář','říj','lis','pro'],
		dayNames: ['neděle','pondělí','úterý','středa','čtvrtek','pátek','sobota'],
		dayNamesShort: ['ne','po','út','st','čt','pá','so'],
		dayNamesMin: ['ne','po','út','st','čt','pá','so'],
		firstDay: 1,
		dateFormat: 'DD, d. m. yy',
		showButtonPanel: false,
		isRTL: false,
		dateDateFormat: 'd. m. yyyy',
		checkinTitle: 'click to change the date',
		checkoutTitle: 'click to change the date'
	},
	en: {
		closeText: 'close',
		prevText: '&#x3c;previous',
		nextText: 'next&#x3e;',
		currentText: 'today',
		monthNames: ['January','February','March','April','May','June', 'July','August','Septembre','October','November','December'],
		monthNamesShort: ['Jan','Feb','Mar','Apr','May','Jun', 'Jul','Aug','Sep','Oct','Nov','Dec'],
		dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
		dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
		dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
		firstDay: 1,
		dateFormat: 'DD, d MM, yy',
		showButtonPanel: false,
		isRTL: false,
		dateDateFormat: 'd. mmmm, yyyy',
		checkinTitle: 'click to change the date',
		checkoutTitle: 'click to change the date'
	}
}

var r = regional[language];
var languageChanged = true;
 
jQuery(function($){
		var rd = {
			closeText: r.closeText,
			prevText: r.prevText,
			nextText: r.nextText,
			currentText: r.currentText,
			monthNames: r.monthNames,
			monthNamesShort: r.monthNamesShort,
			dayNames: r.dayNames,
			dayNamesShort: r.dayNamesShort,
			dayNamesMin: r.dayNamesMin,
			firstDay: r.firstDay,
			dateFormat: r.dateFormat,
			isRTL: r.isRTL
		}
	$.datepicker.setDefaults(rd);
});

Date.dayNames = r.dayNames;
Date.abbrDayNames = r.dayNamesShort;
Date.monthNames = r.monthNames;
Date.abbrMonthNames = r.monthNamesShort;
Date.firstDayOfWeek = r.firstDay;
Date.format = r.dateDateFormat;

var date = {};
date['today'] = new Date();
date['todayStr'] = date.today.getDayName() + ", " + date.today.asString();
date['tommorow'] = date.today.addDays(1);
date['tommorowStr'] = date.tommorow.getDayName() + ", " + date.tommorow.asString();

$(document).ready(
	function(){
		/**
		Hauptnavigation animieren
		*/
		jqueryslidemenu.buildmenu("naviMain", {}, false);
		jqueryslidemenu.buildmenu("naviMain2", {}, false);
		
		
		/**
		Sprachenwechsel abfragen
		*/
		languageChanged = ($.readCookie("language") !== language) ? true : false;
		$.setCookie("language", language, {duration: 1});
		
		
		/**
		Checkin- und Checkout-Feld Werte setzen:
		- Attr: Title
		- Attr: Value
			- Wenn Sprache gewechselt wurde
			- oder wenn Cookie vorhanden ist und das Feld leer ist
			- oder wenn das Feld leer ist
			
		Datepicker aktivieren
		*/
		var checkin = $("#miniForm_checkin");
		if (checkin.length){
			checkin.attr("title", r.checkinTitle);
			checkin.datepicker({minDate: '+0D', maxDate: '+12M'});
			var cookieCheckin = $.readCookie("miniForm_checkin");
			var checkinEmpty = (checkin.attr("value").length) ? false : true; 
			if (languageChanged) checkin.val(date.todayStr);
			else if (cookieCheckin != null && checkinEmpty) checkin.val(cookieCheckin);
			else if (checkinEmpty) checkin.val(date.todayStr);
		}
		
		var checkout = $("#miniForm_checkout");
		if (checkout.length){
			checkout.attr("title", r.checkoutTitle);
			checkout.datepicker({minDate: '+1D', maxDate: '+12M +1D'});
			var cookieCheckout = $.readCookie("miniForm_checkout");
			var checkoutEmpty = (checkout.attr("value").length) ? false : true;
			if (languageChanged) checkout.val(date.tommorowStr);
			else if (cookieCheckout != null && checkoutEmpty) checkout.val(cookieCheckout);
			else if (checkoutEmpty) checkout.val(date.tommorowStr);
		}
		
		
		/**
		Wenn der MiniForm-Button oder ein Link aktiviert wird, die Daten aus dem Formular in einem Cookie speichern
		*/
		var btn = $("#miniForm_submit");
		if (btn.length)	btn.click(function () { setCookieMiniForm(); });
		
		$("a").click(function () { setCookieMiniForm(); });
			
		var setCookieMiniForm = function () {
			if (checkin.length) $.setCookie("miniForm_checkin", checkin.val(), {duration: 1});
			if (checkout.length) $.setCookie("miniForm_checkout", checkout.val(), {duration: 1});
		}
		
		
		
		/**
		Popup
		*/
		var popup = $("div#popup");
		if (popup.length){
			var cookiePopup = $.readCookie("popup");
			
			var displayPopup = "display";
			if (cookiePopup == null || isEntrypage){
				$.setCookie("popup", "display", {duration: 1});
			} else {
				displayPopup = cookiePopup;
			}
			if (displayPopup == "display"){
				popup.draggable();
				popup.bind('dragstop', function(event, ui) {
				});
				$("div#popup div#close a").click(
					function (){
						$.setCookie("popup", "hide", {duration: 1});
						popup.fadeOut(1000);
						return false;
					}
				);
			} else {
				popup.hide();
			}
		}
		
	}
);


