jQuery.extend({
	random: function(X) {
	    return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});

function search_va (form) {
	day_from = form.choice_date_from_day.options[form.choice_date_from_day.selectedIndex].value;
	month_from = form.choice_date_from_monthyear.options[form.choice_date_from_monthyear.selectedIndex].value;
	day_to = form.choice_date_to_day.options[form.choice_date_to_day.selectedIndex].value;
	month_to = form.choice_date_to_monthyear.options[form.choice_date_to_monthyear.selectedIndex].value;
	category = form.choice_category.options[form.choice_category.selectedIndex].value;
	
	if (form.choice_free_search.value != "Suchwort")
		freesearch = form.choice_free_search.value;
	else
		freesearch = "";
	
	url = "http://event.toubiz.de/btt/default/index.php?search_action=1&choice_date_from_day=" + day_from + "&choice_date_from_monthyear=" + month_from + "&choice_date_to_day=" + day_to + "&choice_date_to_monthyear=" + month_to + "&choice_category=" + category + "&choice_free_search=" + freesearch;
	//alert(url);
	popup(800,600,url);
}

function search_toubiz (form) {
	
	timesearch = 0;
	choice_house_category = form.choice_house_category.options[form.choice_house_category.selectedIndex].value;
	choice_arrival_day = form.choice_arrival_day.options[form.choice_arrival_day.selectedIndex].value;
	choice_arrival_monthyear = form.choice_arrival_monthyear.options[form.choice_arrival_monthyear.selectedIndex].value;
	choice_number_night = form.choice_number_night.options[form.choice_number_night.selectedIndex].value;
	
	if (choice_arrival_day != "")
		timesearch = timesearch + 1;
	if (choice_arrival_monthyear != "")
		timesearch = timesearch + 1;
	if (choice_number_night != "")
		timesearch = timesearch + 1;
	
	if (timesearch == 3) {
		
		choice_time_type = 2;
		choice_arrival_period = "default%23arrival_period%23yes";
		
		if (form.only_bookable.checked == true)
			url = "http://www2.toubiz.de/btt/default/search.php?search_action=1&search_new=1&choice_arrival_period=" +choice_arrival_period+ "&choice_time_type=" + choice_time_type + "&choice_arrival_day=" + choice_arrival_day + "&choice_arrival_monthyear=" + choice_arrival_monthyear + "&choice_number_night=" + choice_number_night + "&choice_house_category=" + choice_house_category + "&choice_house_property[]=btt%23accounting_vacancy_mode%23bookable&sort=tip";
		else
			url = "http://www2.toubiz.de/btt/default/search.php?search_action=1&search_new=1&choice_arrival_period=" +choice_arrival_period+ "&choice_time_type=" + choice_time_type + "&choice_arrival_day=" + choice_arrival_day + "&choice_arrival_monthyear=" + choice_arrival_monthyear + "&choice_number_night=" + choice_number_night + "&choice_house_category=" + choice_house_category + "&sort=tip";
		
		popup(800,600,url);
		
	} else if (timesearch < 3 && timesearch != 0) {
		
		alert("Bitte geben Sie einen Anreisetag, einen Anreisemonat und ihre Reisedauer an!")
			
    } else {
    	
    	choice_arrival_period = "default%23arrival_period%23no";
    	
		if (form.only_bookable.checked == true)
			url = "http://www3.toubiz.de/btt/default/search.php?search_action=1&search_new=1&choice_arrival_period=" +choice_arrival_period+ "&choice_house_category=" + choice_house_category + "&choice_house_property[]=btt%23accounting_vacancy_mode%23bookable&sort=tip";
		else
			url = "http://www2.toubiz.de/btt/default/search.php?search_action=1&search_new=1&choice_arrival_period=" +choice_arrival_period+ "&choice_house_category=" + choice_house_category + "&sort=tip";			    	
		
		popup(920,700,url);
	
	}
	
}

function popup(w,h,ziel) {
  h = h - 20; var x=0, y=0, parameter="";
  if (w < screen.availWidth || h < screen.availHeight) {
    x = (screen.availWidth - w - 12) / 2;
    y = (screen.availHeight - h - 104) / 2;
    if (window.opera) y = 0; // Opera positioniert unter den Symbolleisten
    if (x<0 || y<0) { x=0; y=0; }
    else parameter = "width=" + w + ",height=" + h + ",";
  }
  parameter += "left=" + x + ",top=" + y;
  parameter += ",menubar=0,location=0,toolbar=0,status=0";
  parameter += ",resizable=1,scrollbars=1";
  var Fenster = window.open(ziel,"",parameter);
  if (Fenster) Fenster.focus();
  return !Fenster;
}

function popmap(ziel) {
  var w = 820;
  var h = 680; 
  h = h - 20; var x=0, y=0, parameter="";
  if (w < screen.availWidth || h < screen.availHeight) {
    x = (screen.availWidth - w - 12) / 2;
    y = (screen.availHeight - h - 104) / 2;
    if (window.opera) y = 0; // Opera positioniert unter den Symbolleisten
    if (x<0 || y<0) { x=0; y=0; }
    else parameter = "width=" + w + ",height=" + h + ",";
  }
  parameter += "left=" + x + ",top=" + y;
  parameter += ",menubar=0,location=0,toolbar=0,status=0";
  parameter += ",resizable=1,scrollbars=1";
  var Fenster = window.open(ziel,"geomap",parameter);
  if (Fenster) Fenster.focus();
  return !Fenster;
}

function initDatePicker() {
    $.datepicker.regional['de'] = {
        showOn: 'both',
        buttonImage: '/design/de2/images/calendar.gif',
        buttonImageOnly: true,
        clearText: 'l&ouml;schen', clearStatus: 'aktuelles Datum l&ouml;schen',
        closeText: 'schlie&szlig;en', closeStatus: 'ohne &Auml;nderungen schlie&szlig;en',
        prevText: '&laquo; zur&uuml;ck', prevStatus: 'letzten Monat zeigen',
        nextText: 'vor &raquo;', nextStatus: 'n&auml;chsten Monat zeigen',
        currentText: 'heute', currentStatus: '',
        monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'],
        monthNamesShort: ['Jan','Feb','M&auml;r','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'],
        monthStatus: 'anderen Monat anzeigen',
        yearStatus: 'anderes Jahr anzeigen',
        weekHeader: 'Wo',
        weekStatus: 'Woche des Monats',
        dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
        dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
        dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
        dayStatus: 'Setze DD als ersten Wochentag',
        dateStatus: 'Wähle D, M d',
        dateFormat: 'D, dd.mm.yy', firstDay: 1, 
        initStatus: 'Wähle ein Datum',
        minDate: 0,
        maxDate: 730,
        isRTL: false
    };
    $.datepicker.setDefaults($.datepicker.regional['de']);
    $("#dateinput_arrival").datepicker();
    $("#dateinput_departure").datepicker();
}

