/*  search */

//var extendedSearchFields = 'tx_gastroportal_restaurant_name,tx_gastroportal_restaurant_tastes,tx_gastroportal_restaurant_price_from,tx_gastroportal_pi2_tx_gastroportal_restaurant_price_to,tx_gastroportal_restaurant_offers';
var extendedSearchFields = 'tx_gastroportal_restaurant_tastes,tx_gastroportal_restaurant_price_from,tx_gastroportal_restaurant_price_to,tx_gastroportal_restaurant_offers';
var isExtendedSearch = false;

// Show and hide extended search fields

function extendedSearch(){
	f = extendedSearchFields.split(',');
	if(!isExtendedSearch){
		for(i=0;i<f.length;i++){
			$(f[i]).style.display = 'block';
		}
		isExtendedSearch = true;
		$('extendedSearchButton').innerHTML = 'Einfache Suche';
	}
	else {
		for(i=0;i<f.length;i++){
			$(f[i]).style.display = 'none';
		}
		isExtendedSearch = false;
		$('extendedSearchButton').innerHTML = 'Ereiterte Suche';
	}
	return false;
}


var searchFormPrefix = 'tx_gastroportal_pi2_tx_gastroportal_restaurant_';
var bigImage = null;
x = 320;
function showBigImage(imgsrc,name,city) {
	if(!bigImage){
		d = document.createElement('div');
		idAttr = document.createAttribute('id');
		idAttr.nodeValue = 'bigImageWrapper';
		d.setAttributeNode(idAttr);
		document.getElementsByTagName("body")[0].appendChild(d);
	}
	bigImage = $('bigImageWrapper');
	d.innerHTML = '<h3 class="tx_gastroportal_pi2-title">' + name + '</h3>' + city + '<br /><img src="' + imgsrc + '" id="bigImage" />';
	bigImage.style.position = 'absolute';
	bigImage.style.left = (x + 20) + "px";
	bigImage.style.top 	= (y) + "px";
	bigImage.style.display = "block";
	//alert(" x: "  + x + " y: " + y + "Scroll: " + document.body.scrollTop);
}

function hideImage(){
	bigImage.style.display = "none";
}


var customFormCheckFunction = function(){
		if($F(searchFormPrefix + 'city_custom')=='' && $Sel('city')==''){
			alert('Bitte eine Stadt auswählen oder eingeben');
			focusField('city_custom');
			return false;
		}
		n = $$('div#tx_gastroportal_restaurant_numberOfRooms  input');
		if($F(n[0])=='' && $F(n[1])=='' && $F(n[2])==''){
			$('tx_gastroportal_restaurant_numberOfRooms').style.border = '1px solid red';
			alert('Bitte eine Zimmeranzahl auswählen');
			n[0].focus();
			return false;
		}
		if((parseInt($F(n[0])) + parseInt($F(n[1])) + parseInt($F(n[2]))) > 3){
			alert('Es können nur maximal 3 Zimmer auf einmal gebucht werden!');
			n[0].focus();
			return false;
		}
		numError = false;
		n.each(function(p){
				if(isNaN($F(p))){
					focusField(p);
					numError = true;
					 
				}
			});
		if(numError){
			alert('Bitte nur ganze Zahlen in den rot umrandeten Feldern eingeben!');
			return false;
		}
		searchLightbox.activate();																														
		return true;
};

function focusField(id){
	if(typeof id == 'string')i = $(searchFormPrefix + id);
	else i = id;
	i.style.border = '2px solid red';
	i.focus();
	window.scrollBy(0,-100);
}
	

function $Sel(id){
	id = searchFormPrefix + id;
	if($(id) && $(id).type == 'select-one'){
		return $(id).options[$(id).selectedIndex].value;
	}
	else return '';
}

var errorLabels = {};

function showImg(imgSrc){
	$('tx-gastroportal-pi2_imagePoster').src = imgSrc;
}

function getRoute(){
	var url = 'http://maps.google.de/maps?daddr=' + $('daddr').value;
	var saddr = $('saddr').value;
	if(saddr)url = url + '&saddr=' + saddr;
	$('getRouteLink').href = url;
	return true;
}
