function toggleReview(index, total) {
	
	//reset all other blocks
	for(i=0;i<total;i++) {
		if(i != index) {
			id1 = 'review_'+i+'_small';
			id2 = 'review_'+i+'_full';
			displayTEXTBLOCK(id1);
			hideTEXTBLOCK(id2);
		}
	}
	
	//toggle current block
	id1 = 'review_'+index+'_small';
	id2 = 'review_'+index+'_full';
	toggleTEXTBLOCK(id1);
	toggleTEXTBLOCK(id2);
}

function logIt(filename) {
	
	FirstName = '';
	if(typeof(document.booking_form.FirstName) == 'object') {
		FirstName = document.booking_form.FirstName.value;
	}

	Name = '';
	if(typeof(document.booking_form.Name) == 'object') {
		Name = document.booking_form.Name.value;
	}
	
	Street = '';
	if(typeof(document.booking_form.Street) == 'object') {
		Street = document.booking_form.Street.value;
	}
	StreetNumber = '';
	if(typeof(document.booking_form.StreetNumber) == 'object') {
		StreetNumber = document.booking_form.StreetNumber.value;
	}
	Zipcode = '';
	if(typeof(document.booking_form.Zipcode) == 'object') {
		Zipcode = document.booking_form.Zipcode.value;
	}
	City = '';
	if(typeof(document.booking_form.City) == 'object') {
		City = document.booking_form.City.value;
	}
	Country = '';
	if(typeof(document.booking_form.Country) == 'object') {
		Country = document.booking_form.Country.value;
	}
	Email = '';
	if(typeof(document.booking_form.Email) == 'object') {
		Email = document.booking_form.Email.value;
	}
	Phone = '';
	if(typeof(document.booking_form.Phone) == 'object') {
		Phone = document.booking_form.Phone.value;
	}

	Workphone = '';
	if(typeof(document.booking_form.Workphone) == 'object') {
		Workphone = document.booking_form.Workphone.value;
	}
	
	PeriodBegin = '';
	if(typeof(document.booking_form.PeriodBegin) == 'object') {
		PeriodBegin = document.booking_form.PeriodBegin.value;
	}
	
	SearchId = '';
	if(typeof(document.booking_form.SearchId) == 'object') {
		SearchId = document.booking_form.SearchId.value;
	}
	
	Duration = '';
	if(typeof(document.booking_form.Duration) == 'object') {
		Duration = document.booking_form.Duration.value;
	}

	param = 'Filename='+filename+'&FirstName='+FirstName+'&Name='+Name+'&Street='+Street+'&StreetNumber='+StreetNumber+'&Zipcode='+Zipcode+'&City='+City+'&Country='+Country+'&Email='+Email+'&Phone='+Phone+'&Workphone='+Workphone+'&PeriodBegin='+PeriodBegin+'&SearchId='+SearchId+'&Duration='+Duration;
	
	new Ajax.Request("/logit.php", {
        parameters:param,
		method:'get',
		generateUniqueUrl:true,
        onSuccess: function(response) {
			if (response.responseText) {
                //do nothing
            } else {
                //showError("");
            }
        },
        onFailure: function(response) {
            //showError("");
        },
        onException: function(request, ex) {
            //showError("");
        }
    });
}

function updateRadius(value) {
	document.getElementById('radius').value=value;
	document.getElementById('full-search-ambit').checked=true;
	document.getElementById('offset').value=document.getElementById('current_offset').value;
	document.search_full.submit();
	return false;
}

function switchCriterias(ID, VALUE) {
	
	if(VALUE) {
		document.getElementById(ID).checked=true;
	} else {
		document.getElementById(ID).checked=false;
	}
	document.getElementById('offset').value=document.getElementById('current_offset').value;
	document.search_full.submit();
	return false;
}

function silent_submit(formname, updatefield) {
	set_form_field(formname, updatefield);
	eval('document.'+formname+'.submit();');
}

function set_form_field(formname, updatefield, value) {
	if(value == null) value = 1;
	//alert('document.'+formname+'.'+updatefield+'.value="'+value+'";');
	eval('document.'+formname+'.'+updatefield+'.value="'+value+'";');
}

function switchtossl(formname, updatefield, obj) {
	if(document.URL.indexOf('https') == -1) {
		window.scrollTo(0, 0);
		busy('busy',70, '/images/'+lang+'/busy_ssl.gif');
		silent_submit(formname, updatefield);
	} else {
		togglePayment(obj);
		checkPaymentSelection();
	}
}

function slider_default(current, field, min, max, slider, track) {
	
	totrange = $R(min,max);
	
	new Control.Slider(slider,track,{ 
		range: totrange,
		values: totrange,
		sliderValue: current,
		onSlide:function(v){ 
		},
		onChange:function(v){
			changeVALUE(field, v);
		}
	});
}

function slider_distance(current, field, slider, track) {

	totrange = $R(0,4);
	new Control.Slider(slider,track,{ 
		range: totrange,
		values: totrange,
		sliderValue:current,
		onSlide:function(v){ 
		},
		onChange:function(v){
			x = 0;
			if(v == 1) x = 200;
			if(v == 2) x = 500;
			if(v == 3) x = 1000;
			if(v == 4) x = 5000;
			changeVALUE(field, x);
		}
	});
}

function changeVALUE(ELEMENT, VALUE) {
	var e = document.getElementById('small-search-'+ELEMENT);
	if(e != null) {
		e.value = VALUE;
	}
	document.search_small.submit();
	return false;
}

function preload_images() {
    for (var i = 0; i < arguments.length; i++){
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};

function regionmode(mode, formname) {
	eval('document.'+formname+'.region_mode.value=mode;');
}

function updateGeoSelect(obj, formname, regionevent) {
	if(regionevent) eval('document.'+formname+'.RegionEvent.value=1;');
	eval('document.'+formname+'.offset.value=0;');
	eval('document.'+formname+'.LastEventName.value=obj.name;');
	eval('document.'+formname+'.LastEventValue.value=obj.value;');
	eval('document.'+formname+'.submit();');
}

function toggleVALUE(ELEMENT) {
	var e = document.getElementById('small-search-'+ELEMENT);
	if(e != null) {
		if (e.value == 1) {
			e.value = 0;
		} else {
			e.value = 1;
		}
	}
	document.search_small.submit();
	return false;
}

function toggleHEADLINE(TEXTBLOCK) {
	var h = document.getElementById('HEADLINE-'+TEXTBLOCK);
	if(h != null) {
		if (h.className == "search_small_headline_open") {
			h.className = 'search_small_headline_closed';
		} else {
			h.className = 'search_small_headline_open';
		}
	}
	return false;
}

// wechselt den style der headline
function toggleHEADLINEBYBLOCK(TEXTBLOCK) {
	var e = document.getElementById(TEXTBLOCK);
	var h = document.getElementById('HEADLINE-'+TEXTBLOCK);
	if(e != null) {
		if (e.style.display == '') e.style.display = "none";
		
		if (e.style.display == "none") {
			h.className = 'search_small_headline_closed';
		} else {
			h.className = 'search_small_headline_open';
		}
	}
	return false;
}


function toggleService(ID) {
	
	//hide all
	divs = document.getElementsByTagName('div');
	for (i = 0; i < divs.length; i++) {
		id = document.getElementsByTagName('div')[i].id;
		if (id.match(/[0-9]+_content/)) {
			hideTEXTBLOCK(id);
		} else if(id.match(/[0-9]+_headline/)) {
			document.getElementsByTagName('div')[i].className  = 'object_service';
		}
	}
	
	// display clicked
	displayTEXTBLOCK(ID+'_content');
	var element = document.getElementById(ID+'_headline');
	if(element != null) {
		element.className  = 'object_service_active';
	}
	
	var iframe = document.getElementById('iframe_'+ID);
	if(iframe != null) iframeHeight(iframe);
}

function change_date(field1, field2) {
	var date1 = get_date(field1);
	var date2 = get_date(field2);
	
	settime = date1.getTime() + (7 * 24 * 60 * 60000);
	date2.setTime(settime);	
	
	var e = document.getElementById(field2);
	if(e != null) {
		e.value = formate_date(date2.getDate()) + '.' + formate_date(date2.getMonth() + 1) + '.' + date2.getFullYear();
	}
}

function get_date(date_id) {
	
	var e = document.getElementById(date_id);
	if(e != null) {
		var date = e.value;
		var dsplit = date.split('.');
		dyear = new Number(dsplit[2]);
		dmonth = new Number(dsplit[1]) - 1;
		dday = new Number(dsplit[0]);
		return new Date(dyear, dmonth, dday);
	}
}

function formate_date(d) {
	d1 = new Number(d);
	d2 = (d1 < 10) ? "0" + d1 : d1;		
	return d2;
}

function select(offset) {
	document.search_full.offset.value=offset;
	document.search_full.submit();
}

function detail(host, searchid, company) {
	//var wWidth = screen.availWidth/4*3;
	var wWidth = 800;
	var wHeight = screen.availHeight/4*3;
	var PeriodBegin = document.search_full.PeriodBegin.value;
	var Duration = document.search_full.Duration.value;
	var Adults = document.search_full.persons.value;
	var URL = host+"/houseinfo.php?SearchId=" + searchid + "&PeriodBegin=" + PeriodBegin + "&Duration=" + Duration+"&Adults="+Adults;
	var detailsWindow = window.open(URL, "details", "menubar=no,status=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,width="+ wWidth +",height="+ wHeight+",left=100,top=100");
	detailsWindow.focus();
}

function popup(url) {
	var wWidth = screen.availWidth/4*3;
	var wHeight = screen.availHeight/4*3;
	var printWindow = window.open(url, "print", "menubar=no,status=no,location=no,resizable=yes,scrollbars=yes,toolbar=no,width="+ wWidth +",height="+ wHeight+",left="+ (wWidth/2) +",top="+ (wHeight/2));
	printWindow.focus();
}

// blendet Textblock ein und aus
function toggleTEXTBLOCK(TEXTBLOCK) {
	var e = document.getElementById(TEXTBLOCK);
	if(e != null) {
		if (e.style.display == '') e.style.display = "none";
		if (e.style.display == "none") {
			e.style.display = "block";
			e.style.visibility = "visible";
		} else {
			e.style.display = "none";
		}
	}
	return false;
}

function displayTEXTBLOCK(TEXTBLOCK) {
	var e = document.getElementById(TEXTBLOCK);
	if(e != null) {
		if (e.style.display == '') e.style.display = "none";
		e.style.display = "block";
	}
	return false;
}

function hideTEXTBLOCK(TEXTBLOCK) {
	var e = document.getElementById(TEXTBLOCK);
	if(e != null) {
		if (e.style.display == '') e.style.display = "none";
		e.style.display = "none";
	}
	return false;
}


function spinner(THIS) {
	eval(THIS).parentNode.style.backgroundPosition = '50% 2px';
	eval(THIS).parentNode.style.backgroundRepeat = 'no-repeat';
	eval(THIS).parentNode.style.backgroundImage = 'url(/images/spinner.gif)';
}

function unspinner(THIS) {
	eval(THIS).parentNode.style.backgroundImage = '';
}


function busy(ID,OPACITY,IMAGE) {
	
	if (IMAGE == null){
		IMAGE = '/images/busy.gif';
	}
	
	ELEMENT = document.getElementById(ID);

	if(ELEMENT != null) {
		
		if (navigator.appName.indexOf('Netscape') != -1 && parseInt(navigator.appVersion) >= 5) {
			ELEMENT.style.MozOpacity = OPACITY/100;
		} else if (navigator.appName.indexOf('Microsoft') != -1 && parseInt(navigator.appVersion) >= 4) {
			ELEMENT.style.setAttribute('filter', 'Alpha(Opacity='+OPACITY+')', 'false');
		}

		ELEMENT.style.display = 'inline';
		ELEMENT.style.backgroundRepeat = 'no-repeat';
		ELEMENT.style.backgroundPosition = 'center 300px';
		window.setTimeout("ELEMENT.style.backgroundImage = 'url("+IMAGE+")';", 100);
	}
}

function unbusy(ID) {
	
	ELEMENT = document.getElementById(ID);
	if(ELEMENT != null) {
		ELEMENT.style.display = 'none';
	}
}

function loading(ID) {
  var e = document.getElementById(ID);
  e.innerHTML = '<div style="width:48px;height:48px;"><img src="/images/loading.gif" alt="please wait"></div>';
}

function cursor_wait() {
	document.body.style.cursor = 'wait';
}

function cursor_clear() {
	document.body.style.cursor = 'default';
}

function sortresult(Order, Direction) {
	document.search_full.Order.value=Order;
	document.search_full.Direction.value=Direction;
	document.search_full.submit();
}

function changeTravelStartDate(date) {

	var date = String(date);

	var dsplit = date.split('-');
	dyear = dsplit[0];
	dmonth = dsplit[1];
	dday = dsplit[2];

	if(dmonth.length == 1) dmonth = '0'+dmonth;
	if(dday.length == 1) dday = '0'+dday;

	//alert(dyear+'-'+dmonth+'-'+dday);
	document.booking_form.PeriodBegin.value = dyear+'-'+dmonth+'-'+dday;
}

function swapImg(id, file, width) {

	image = document.getElementById(id);
	if(image != null) {
		image.src = file;
		if(width) image.width = width;
		
		//alert(image.src);
	}
}

function togglePayment(obj) {
	
	//var c = document.getElementById('creditcard');
	//if(c) c.style.display = "none";

	//var b = document.getElementById('bankcollection');
	//if(b) b.style.display = "none";

	//var i = document.getElementById('invoice');
	//if(i) i.style.display = "none";

	//var j = document.getElementById('assignment');
	//if(j) j.style.display = "none";

	//var e = document.getElementById(obj.value);
	//if(e) e.style.display = "block";

	hideTEXTBLOCK('creditcard');
	hideTEXTBLOCK('creditcard-info');
	
	hideTEXTBLOCK('bankcollection');
	hideTEXTBLOCK('bankcollection-info');

	hideTEXTBLOCK('invoice');
	hideTEXTBLOCK('invoice-info');

	hideTEXTBLOCK('assignment');
	hideTEXTBLOCK('assignment-info');

	displayTEXTBLOCK(obj.value);
	
	return false;
}

function toggleChildrenDetails() {

	var children = document.getElementById('Children');
	var babies = document.getElementById('Babies');
	
	if(children.value > 0 || babies.value > 0) {
		displayTEXTBLOCK('ChildrenDetailsBlock');
	} else {
		hideTEXTBLOCK('ChildrenDetailsBlock');
	}
}

function togglePetsDetails() {

	var pets = document.getElementById('Pets');
	
	if(pets.value > 0) {
		displayTEXTBLOCK('PetsDetailsBlock');
	} else {
		hideTEXTBLOCK('PetsDetailsBlock');
	}
}


function checkPaymentSelection() {
	
	if(typeof(company) == 'undefined') company = '';
	
	if(company=='ns') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_6');
		hideTEXTBLOCK('booking_info_7');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
					displayTEXTBLOCK('booking_info_5');
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_3');
					break;
				case 'invoice':
					displayTEXTBLOCK('booking_info_5');
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_4');
					displayTEXTBLOCK('booking_info_3');
					break;
				case 'bankcollection':
					displayTEXTBLOCK('booking_info_5');
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_3');
					if(typeof(country.value) != 'undefined' && country.value != 'DE') displayTEXTBLOCK('booking_info_6');
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 30 && days > 14) {
				hideTEXTBLOCK('booking_info_3');
				displayTEXTBLOCK('booking_info_7');
			}
			if(days<= 14) {
				hideTEXTBLOCK('invoice');
				hideTEXTBLOCK('booking_info_3');
				hideTEXTBLOCK('booking_info_4');
				
				// change value if possible
				for(i=0;i<payment.length;i++) {
					if(payment.options[i].value == 'bankcollection') {
						payment.value = 'bankcollection';
						break;
					}
				}
				
				displayTEXTBLOCK('bankcollection');
				displayTEXTBLOCK('booking_info_2');
			}
		}
	}

	if(company=='er') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_7');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					break;
				case 'creditcard':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					break;
				case 'assignment':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_3');
					if(typeof(country.value) != 'undefined' && country.value != 'DE' && country.value != 'NL' && country.value != 'BE') displayTEXTBLOCK('booking_info_5');
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 42) {
				hideTEXTBLOCK('booking_info_2');
				displayTEXTBLOCK('booking_info_4');
			}
			
			if(days<= 14) {
				hideTEXTBLOCK('booking_info_3');
				displayTEXTBLOCK('booking_info_7');
				
				// change value if possible
				for(i=0;i<payment.length;i++) {
					if(payment.options[i].value == 'creditcard') {
						payment.value = 'creditcard';
						break;
					}
				}
				displayTEXTBLOCK('creditcard');
			}
		}
	}

	if(company=='ihv3') {

		var payment = document.getElementById('Payment');
		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_5');
					break;
				case 'creditcard':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_5');
					break;
				case 'invoice':
				case 'check':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_3');
					displayTEXTBLOCK('booking_info_5');
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 29) {
				hideTEXTBLOCK('booking_info_2');
				displayTEXTBLOCK('booking_info_4');
			}
		}
	}

	if(company=='wo') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_6');
		hideTEXTBLOCK('booking_info_7');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
				case 'creditcard':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					break;
				case 'invoice':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_3');
					displayTEXTBLOCK('booking_info_4');
					break;
				case 'bankcollection':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					if(typeof(country.value) != 'undefined' && country.value != 'DE') displayTEXTBLOCK('booking_info_5');
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 44) {
				hideTEXTBLOCK('booking_info_2');
				hideTEXTBLOCK('booking_info_3');
				hideTEXTBLOCK('booking_info_4');
				displayTEXTBLOCK('booking_info_6');
				displayTEXTBLOCK('booking_info_7');
				
				if(payment.value == 'invoice') {
					hideTEXTBLOCK('invoice');
					
					// change value if possible
					for(i=0;i<payment.length;i++) {
						if(payment.options[i].value == 'bankcollection') {
							payment.value = 'bankcollection';
							break;
						}
					}

					displayTEXTBLOCK('bankcollection');
				}
			}
		}
	}
	
	if(company=='dc') {

		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_4');
		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
		displayTEXTBLOCK('booking_info_3');
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 42) {
				hideTEXTBLOCK('booking_info_3');
				displayTEXTBLOCK('booking_info_4');
			}
		}
	}

	if(company=='fr') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_6');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					break;
				case 'invoice':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					displayTEXTBLOCK('booking_info_3');
					break;
				case 'bankcollection':
					displayTEXTBLOCK('booking_info_1');
					displayTEXTBLOCK('booking_info_2');
					if(typeof(country.value) != 'undefined' && country.value != 'DE') displayTEXTBLOCK('booking_info_6');
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 28 && days > 14) {
				hideTEXTBLOCK('booking_info_3');
				hideTEXTBLOCK('booking_info_2');
				displayTEXTBLOCK('booking_info_4');
			}
			if(days<= 14) {
				hideTEXTBLOCK('booking_info_2');
				hideTEXTBLOCK('booking_info_3');
				displayTEXTBLOCK('booking_info_4');
				displayTEXTBLOCK('booking_info_5');
				
				if(payment.value == 'invoice') {
					hideTEXTBLOCK('invoice');

					// change value if possible
					for(i=0;i<payment.length;i++) {
						if(payment.options[i].value == 'bankcollection') {
							payment.value = 'bankcollection';
							break;
						}
					}

					displayTEXTBLOCK('bankcollection');
				}
			}
		}
	}

	if(company=='ic') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var interval = document.getElementById('Interval');
		var periodbegin = document.getElementById('PeriodBegin');

		var creditcardexpirymonth = document.getElementById('CreditCardExpiryMonth');
		var creditcardexpiryyear = document.getElementById('CreditCardExpiryYear');

		hideTEXTBLOCK('booking_info_1');
		hideTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');

		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case '':
					displayTEXTBLOCK('booking_info_1');
					break;
				case 'bankcollection':
					displayTEXTBLOCK('booking_info_1');
					if(typeof(country.value) != 'undefined' && country.value != 'DE' && country.value != 'AT') displayTEXTBLOCK('booking_info_5');
					break;
				case 'creditcard':
					displayTEXTBLOCK('booking_info_1');
					break;
			}
		}
		
		if(typeof(interval.value) != 'undefined') {
			if(interval.value == 'B') {
				displayTEXTBLOCK('booking_info_2');
			} else {
				hideTEXTBLOCK('booking_info_2');
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 30) {
				hideTEXTBLOCK('booking_info_2');
				displayTEXTBLOCK('booking_info_3');
				if(typeof(interval.value) != 'undefined')  interval.value = 'G';
			} else {
				
				if(creditcardexpiryyear.value > 0 && creditcardexpirymonth.value > 0) {
					$stamp_preiodbegin = getStamp(periodbegin.value);
					$stamp_preiodbegin = $stamp_preiodbegin-(60*60*24*30); // -30 Tage
					$stamp_expiry = getStamp('1.'+creditcardexpirymonth.value+'.'+creditcardexpiryyear.value);
					days = calculateDiff($stamp_preiodbegin, $stamp_expiry);
					
					if(typeof(interval.value) != 'undefined') {
						if(days < 0 && interval.value == 'B') {
							displayTEXTBLOCK('booking_info_4');
						} else {
							hideTEXTBLOCK('booking_info_4');
						}
					}
				}
			}
		}
	}

	if(company=='tr') {
		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
	}

	if(company=='si') {
		displayTEXTBLOCK('booking_info_1');
	}	
	
	if(company=='pv') {
		displayTEXTBLOCK('booking_info_1');
	}	

	if(company=='js') {
		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
		displayTEXTBLOCK('booking_info_3');
	}	

	if(company=='hh') {
		displayTEXTBLOCK('booking_info_1');
	}	

	if(company=='bc') {
		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
	}
	
	if(company=='cs1' || company=='cm' || company=='ec' || company=='cc') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_6');
		
		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case 'invoice':
					displayTEXTBLOCK('booking_info_4');
					break;
				case 'bankcollection':
					if(typeof(country.value) != 'undefined' && country.value != 'DE') {
						displayTEXTBLOCK('booking_info_5');

						// change value if possible
						for(i=0;i<payment.length;i++) {
							if(payment.options[i].value == 'invoice') {
								payment.value = 'invoice';
								break;
							}
						}

						hideTEXTBLOCK('bankcollection');
					}
					break;
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if(days<= 60) {
				hideTEXTBLOCK('booking_info_2');
				displayTEXTBLOCK('booking_info_3');
				if(typeof(payment.value) != 'undefined' && payment.value == 'bankcollection') {
					
					displayTEXTBLOCK('booking_info_6');

					// change value if possible
					for(i=0;i<payment.length;i++) {
						if(payment.options[i].value == 'invoice') {
							payment.value = 'invoice';
							displayTEXTBLOCK('invoice');
							break;
						}
					}
					
					hideTEXTBLOCK('bankcollection');
				}
			}
		}
	}
	
	if(company=='edom' || company=='adr') {

		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
		hideTEXTBLOCK('booking_info_3');
		hideTEXTBLOCK('booking_info_4');
		hideTEXTBLOCK('booking_info_5');
		hideTEXTBLOCK('booking_info_6');
		hideTEXTBLOCK('booking_info_7');
		hideTEXTBLOCK('booking_info_8');
		
		if(typeof(payment.value) != 'undefined') {
			switch(payment.value) {
				case 'invoice':
					displayTEXTBLOCK('booking_info_3');
					break;
				case 'creditcard':
					displayTEXTBLOCK('booking_info_5');
					break;
				case 'bankcollection':
					if(typeof(country.value) != 'undefined' && country.value != 'DE') {
						displayTEXTBLOCK('booking_info_4');

						// change value if possible
						for(i=0;i<payment.length;i++) {
							if(payment.options[i].value == 'invoice') {
								payment.value = 'invoice';
								hideTEXTBLOCK('bankcollection');
								break;
							}
						}
					}
					break;
			}
			
			//outside DE creditcard only
			if(payment.value != 'creditcard') {
				if(typeof(country.value) != 'undefined' && country.value != 'DE') {
					hideTEXTBLOCK('booking_info_4');
					hideTEXTBLOCK('booking_info_3');
					hideTEXTBLOCK('bankcollection');
					displayTEXTBLOCK('booking_info_8');
					displayTEXTBLOCK('booking_info_5');
					displayTEXTBLOCK('creditcard');
					// change value if possible
					for(i=0;i<payment.length;i++) {
						if(payment.options[i].value == 'creditcard') {
							payment.value = 'creditcard';
							break;
						}
					}
				}
			}
		}
		
		if(typeof(periodbegin.value) != 'undefined' && periodbegin.value != '') {
			days = calculateDiff(getToday(), getStamp(periodbegin.value));
			if((company=='edom' && days<= 28) || (company=='adr' && days<= 37)) {
				if(typeof(payment.value) != 'undefined' && payment.value == 'bankcollection') {
					hideTEXTBLOCK('booking_info_4');
					displayTEXTBLOCK('booking_info_6');

					// change value if possible
					for(i=0;i<payment.length;i++) {
						if(payment.options[i].value == 'invoice') {
							payment.value = 'invoice';
							hideTEXTBLOCK('bankcollection');
							//displayTEXTBLOCK('creditcard');
							break;
						}
					}
				}
			}
			
			if(days<= 28 && typeof(payment.value) != 'undefined' && payment.value == 'invoice') {
				displayTEXTBLOCK('booking_info_7');
			} else {
				hideTEXTBLOCK('booking_info_7');
			}
		}
	}
	
	if(company=='if' || company=='hap' || company=='snot' || company=='th' || company.match(/fe__/g) || company.match(/itea__/g)) {
		
		var payment = document.getElementById('Payment');
		var country = document.getElementById('Country');
		var periodbegin = document.getElementById('PeriodBegin');

		displayTEXTBLOCK('booking_info_1');
		displayTEXTBLOCK('booking_info_2');
		
		if(payment != null && typeof(payment.value) != 'undefined' && payment.value == 'invoice') {
			displayTEXTBLOCK('booking_info_3');
		} else {
			hideTEXTBLOCK('booking_info_3');
		}
	}
}


function getToday() {

	var now = new Date();
	now_year = now.getYear();
	if (now_year < 999) now_year += 1900;
	now_month = now.getMonth();
	now_day = now.getDate();
	return new Date(now_year,now_month,now_day).getTime()/1000;
}

function getStamp(periodbegin) {

	if(periodbegin.match(/\./)) {
		var dsplit = periodbegin.split('.');
		dyear = dsplit[2];
		dmonth = dsplit[1];
		dmonth = dmonth-1;
		dday = dsplit[0];
	} else {
		var dsplit = periodbegin.split('-');
		dyear = dsplit[0];
		dmonth = dsplit[1];
		dmonth = dmonth-1;
		dday = dsplit[2];
	}
	if(dmonth.length == 1) dmonth = '0'+dmonth;
	if(dday.length == 1) dday = '0'+dday;
	
	return new Date(dyear,dmonth,dday).getTime()/1000;
}

function calculateDiff(stamp1, stamp2) {
	var diff = Math.floor(stamp2-stamp1);
	var days = Math.floor(diff/(60*60*24));
	return days;
}

function updateAMEX(value, div) {
	
	var c = document.getElementById(div);
	if(c != null) {
		if(value=='AX') {
			c.style.display = "block";
		} else {
			c.style.display = "none";
		}
	}
}

function setcookie(name, value, expires, path, domain, secure) {
	
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getcookie(name) {
	var split = new Array();
	//alert(document.cookie);
	split = document.cookie.split(";");
	for(var i=0; i<split.length;i++) {
		//alert(split[i]);
		if(split[i].match(".*"+name+".*")) {
			return (split[i].split("="))[1];
		}
	}
	return false;
}

function disableEnterKey(e, focus) {
     var key;

     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox

     if(key == 13) {
          f = document.getElementById(focus); f.focus();
		  return false;
     } else {
          return true;
	}
}

function claculatePrice(ID) {
	
	var sum = parseFloat(0);
	var currency = '&euro;'
	
	var element = document.getElementById(ID);
	
	ARR_VALUES = new Array();
	for(i=0; i<document.booking_form.elements.length; i++) {
		name = document.booking_form.elements[i].name;
		if(name.match(/block\[.*\]\[rooms_price_currency\]/)) {
			ARR_VALUES.push(name);
		}
	}
	
	if(element != null && ARR_VALUES.length > 0) {
		
		arr_values = new Array();
		for (var i = 0; i < ARR_VALUES.length; ++i) {
			temp = document.getElementById(ARR_VALUES[i]);
			if(temp != null) {
				arr_values.push(temp.value);
			}
		}

		for (var i = 0; i < arr_values.length; ++i) {

			split = arr_values[i].split('_');
			if(split.length == 3) {
				count = split[0];
				price = split[1].replace('.','');
				price = price.replace(',','.');
				currency = split[2];
				sum += parseFloat(price);
			}
		}
		
		if(currency == 'EUR') currency = '&euro;';
		
		sum = sum.toFixed(2);
		sum = sum.toString(10);
		sum = sum.replace('.',',');
		element.innerHTML = '<div class="rental_price">'+sum+' '+currency+'</div>';
	}
}

function updateDateSelect(value, formname) {
	
	if(!value) return false;
	
	//alert(value);
	
	if(formname == null) formname = 'booking_form';

	eval('var dayselect = document.'+formname+'.PeriodBeginDay;');
	eval('var monthselect = document.'+formname+'.PeriodBeginMonth;');
	
	if(value.match(/[0-9]*-[0-9]*-[0-9]*/g)) {
		tmp = value.split('-');
		if(tmp.length == 3) {
			
			value = tmp[1]-1+' '+tmp[0];
			if(tmp[2].indexOf(0) == 0) tmp[2] = tmp[2].substr(1);
			
			//alert(tmp[2]);
			
			//es koennen nur vorhandene options selectiert werden => ggf. option hinzufuegen
			if(monthselect.length == 0) {
				option = new Option(value, value, false, true);
				monthselect.options[0] = option;
			}
			monthselect.value = value;
			
			//es koennen nur vorhandene options selectiert werden => ggf. option hinzufuegen
			if(dayselect.length == 0) {
				option = new Option(tmp[2], tmp[2], false, true);
				dayselect.options[0] = option;
			}
			dayselect.value = tmp[2];
		}
	} else if(!value.match(/[0-9]* [0-9]*/g)) {
		return;
	}
	
	if(dayselect != null && monthselect != null) {
		tmp = value.split(' ');
		month = tmp[0];
		year = tmp[1];
		updateDaySelect(month, year, dayselect);
		updateMonthSelect(month, year, monthselect);
	}
	updatePeriodBegin(formname);
}


function updateMonthSelect(month, year, obj) {
	
	selected = obj.value;
	obj.length = 0;
	
	start = new Date();
	month = start.getMonth();
	year = start.getFullYear();
	countmonth = 12-month+12-1;
	
	for(var i=0; i<=countmonth;i++) {
		
		/*if(month+i == 12) {
			year++;month=0;i=0;
		}*/
		
		current = new Date(year,month+i,1);
		m = current.getMonth();
		y = current.getFullYear();
		index = m+' '+y;
		
		//if(i==3) checkMonth(y,m);
		//if(checkMonth(y,m)) {
		
			if(index==selected) {
				option = new Option(getMonthName(m)+' '+y, index, false, 1);
			} else {
				option = new Option(getMonthName(m)+' '+y, index, false, false);
			}
			obj.options[i] = option;
		//}
	}
}

function updateDaySelect(month, year, obj) {
	
	selected = parseInt(obj.value);
	obj.length = 0;
	
	daysofmonth = daysOfMonth(month, year);
	start = current_start = new Date(year,month,1);
	i=0;
	for (var k = 1; k <= daysofmonth; k++) {
		
		current = new Date(year,month,k);
		day = current.getDay(); // Wochentag als Wort
		
		if(checkDay(year,month,k)) {
		
			if(k===selected) {
				option = new Option(getDayName(day)+' '+k, k, false, true);
			} else {
				option = new Option(getDayName(day)+' '+k, k, false, false);
			}
			
			obj.options[i] = option;
			i++;
		}
	}
	
	if(!obj.length) {
		option = new Option('--', 0, false, true);
		obj.options[0] = option;
		updatePeriodBegin();
	}
}


function checkMonth(y,m) {
	if(typeof(casa_calendar) != 'undefined') {
		daysofmonth = daysOfMonth(m, y);
		for (var k = 1; k <= daysofmonth; k++) {
			if(checkDay(y,m,k)) {
				return 1;
			}
		}
		return 0;
	}
	return 1;
}

function checkDay(y,m,d) {
	
	m++;
	
	nextday = d+1;
	nextday = String(nextday);
	if(nextday.length < 2) nextday = '0'+nextday;
	
	previousday = d-1;
	previousday = String(previousday);
	if(previousday.length < 2) previousday = '0'+previousday;
	
	d = String(d);
	y = String(y);
	m = String(m);

	if(d.length < 2) d = '0'+d;
	if(m.length < 2) m = '0'+m;
	
	
	if(typeof(casa_calendar) != 'undefined') {
		if(typeof(casa_calendar[y+m+d]) != 'undefined' && casa_calendar[y+m+d].indexOf('available') == 0) {
			
			// checking if nextday is available
			/*if(typeof(casa_calendar[y+m+nextday]) != 'undefined' && casa_calendar[y+m+nextday] == 'available') {
				return 1;
			} else {
				return 0;
			}*/
			return 1;
			
		} else {
			// checking if day is lastday of unavailable period (nextday available but previous day unavailable)
			if(typeof(casa_calendar[y+m+nextday]) != 'undefined' && casa_calendar[y+m+nextday].indexOf('available') == 0) {
				//nextday is available => checking previousday
				if(typeof(casa_calendar[y+m+previousday]) == 'undefined' || casa_calendar[y+m+previousday].indexOf('available') != 0) {
					return 1;
				}
			}
			return 0;
		}
	}
	return 1;
}

function updatePeriodBegin(formname) {
	
	if(formname == null) formname = 'booking_form';
	
	eval('var dayselect = document.'+formname+'.PeriodBeginDay;');
	eval('var monthselect = document.'+formname+'.PeriodBeginMonth;');
	eval('var periodhidden = document.'+formname+'.PeriodBegin;');

	if(dayselect != null && monthselect != null && periodhidden != null) {
		if(dayselect.value != 0 && monthselect.value != 0) {
			tmp = monthselect.value.split(' ');
			year = tmp[1];
			month = tmp[0];month++;
			if(month<10) month='0'+month;
			day = dayselect.value;
			if(day<10) day='0'+day;
			index = new String(year+'-'+month+'-'+day);
			periodhidden.value = index;
			return 1;
		}
	}
	
	/*now = new Date();
	month = start.getMonth();
	day = start.getDate();
	year = start.getFullYear();
	index = new String(year+'-'+month+'-'+day);
	periodhidden.value = index;*/
	periodhidden.value = '';
	return 0;
}

function daysOfMonth(month, year) {

	var days = 31;
	if (month == 3 || month == 5 || month == 8 || month == 10) --days;
	
	if (month == 1) {
		days = days - 3;
		if (year % 4 == 0) days++;
		if (year % 100 == 0) days--;
		if (year % 400 == 0) days++;
	}
	
	return days;
}

function checkEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	}
	return true;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function iframeHeight(IFRAME) {
  //find the height of the internal page
  var height=IFRAME.contentWindow.document.body.scrollHeight;
  height += 5;
  //change the height of the iframe
  IFRAME.height=height;
}
