var limit = 0;
var searchInput = '';

;function dummy() {
}

function addCountry(){
	
	$("#country-element").html("<input type='text' name='country' />")
	
}


function searchBVNHotels() {

	limit = 0;
	clearNietOK();
	
	var searchHotelBox = $('#searchHotelsBox').val();
	if(searchHotelBox == ""){
		
		searchHotelBox = "--";	
	}
	
	searchInput = searchHotelBox + "/" + $('#searchHotelsCountry').val();
	
//	$('#maps_search_results').css({ 'opacity':'0.9'});
			$.get("/ontvangst/hotels/search/" + searchInput + "/0",{}, function(data) {
		
		hotelData = $(data);
		placeHotels(hotelData, limit);
					
	}, "json");
	
}

function searchMapsHotel() {
	var searchInput = $('#searchMapsBox').val();
	var searchLocation = $('#searchMapsLocation').val();
	
	
	if(searchInput != "" && searchLocation != ""){
	
		findHotel();
	}
	else if(searchInput == ""){
		
		alert("Enter an hotelname etc.");
	}
	else if(searchLocation == ""){
		
		alert("Enter an place and/or country name");
	}
}

function searchHotelbyID() {
	searchInput = $('#searchBVNidBox').val();
	
	$.get("/ontvangst/hotels/search_id/" + searchInput,{}, function(data) {
		
		hotelData = $(data);
//		placeHotels(hotelData, limit);
		showHotelbyID(hotelData);
		
		fillForm(hotelData);
		
		$('#uitleg').show();
					
	}, "json");	
	
}

function fillForm(hotelData) {

	$('#searchMapsBox').val(hotelData[0].hotelname);		
	$('#searchMapsLocation').val(hotelData[0].country);		
	
	$('#id').val(hotelData[0].id);

	$('#hotelname').val(hotelData[0].hotelname);
	$('#address_post').val(hotelData[0].address_post);
	$('#postcode').val(hotelData[0].postcode);
	$('#city').val(hotelData[0].city);
	$('#province').val(hotelData[0].province);

	//angepast
	$('#country').val(hotelData[0].google_country);

	$('#phone').val(hotelData[0].phone);
	$('#email').val(hotelData[0].email);
	$('#web').val(hotelData[0].web);	

	$('#lat').val(hotelData[0].lat);	
	$('#lng').val(hotelData[0].lng);	
	$('#googleurl').val(hotelData[0].googleurl);	

	$('#checked').val(hotelData[0].checked);	
	
	
	
	//alert("test");
}

function nietOK(id) {
	$('#hotel').val(hotels[id].hotelname);
	$('#hotel').attr('readonly', true)
	$('#nietOK_form').show();
	window.location.href = "#form";
}

function clearNietOK() {
	$('#hotel').val('');
	$('#nietOK_form').hide();
}

function next50() {

	limit = limit + 50;
	
	$.get("/ontvangst/hotels/search/" + searchInput + "/" + limit,{}, function(data) {
		
		hotelData = $(data);
		placeHotels(hotelData, limit);
					
	}, "json");
	
}

function previous50() {

	limit = limit - 50;
	
	$.get("/ontvangst/hotels/search/" + searchInput + "/" + limit,{}, function(data) {
		
		hotelData = $(data);
		placeHotels(hotelData, limit);
					
	}, "json");
	
}

function selectLocation(id) {
	
	//alert(markers[id]);
	if(markers[id] != undefined){
		GEvent.trigger(markers[id], "click");
	}
}

function selectHotel(id) {  // functie voor addHotel 
	
	
	selectLocation(id);
	
	if(searchResults[id] != undefined){
		
		var hotelname = ""
		if(searchResults[id].titleNoFormatting != ""){
			
			hotelname = "" + searchResults[id].titleNoFormatting;
		}
	
		var streetAddress = "" + searchResults[id].streetAddress;
		var city = "" + searchResults[id].city;
		var region = "" + searchResults[id].region;
		var phoneNumber = "";
		if(searchResults[id].phoneNumbers != undefined){
		
			phoneNumber = "" + searchResults[id].phoneNumbers[0].number;
		}
		var fax = "" + searchResults[id].fax;
		var country = "" + searchResults[id].country;
		var googleurl = "" + searchResults[id].url;
		var lat = "" + searchResults[id].lat;
		var lng = "" + searchResults[id].lng;
				
		$('#hotelname').val(hotelname);
		$('#address_post').val(streetAddress);	
		$('#city').val(city);	
		$('#province').val(region);	
		$('#country').val(country);	
		$('#phone').val(phoneNumber);	
		$('#fax').val(fax);	
		$('#googleurl').val(googleurl);	
		$('#lat').val(lat);	
		$('#lng').val(lng);

		$('#google_hotelname').val(hotelname);
		$('#google_address').val(streetAddress);
		$('#google_city').val(city);
		$('#google_country').val(country);	

		if (!$('#country').val()) {
		    $('#country').append(
		        $('<option></option>').attr('label',country).attr('value', country).html(country)
		    );
		    $('#country').val(country);
		}		
	}
	
	
	
	window.location.href = "#form";
}



function viewHotel(id) {
	selectLocation(id);
		
}


