var bookmarkurl="http://www.hellohotello.com"
var bookmarktitle="Hello Hotello"


function addbookmark(){
	if (window.sidebar) {
	    // versione FF
	    //window.sidebar.addPanel(document.title, location.href,'');
		window.sidebar.addPanel("HelloHotello", "http://www.hellohotello.com",'');
	} else if( window.external ) {
	    // versione IE
	    window.external.AddFavorite("http://www.hellohotello.com","HelloHotello"); 
	}
}

function initFunctionsHome(path,languageCode){
	
	//initAjax();
	initCalendarHome(path,languageCode);
	initAutoSuggest();
	$('#ui-datepicker-div').hide();
}

function initFunctions(path,languageCode){
	//$.historyInit(callback, "index.html"); 
	
	//initAjax();
	initAutoSuggest();
	initTabs();
	initCalendar(path,languageCode);
	//initCalendarHome(path,languageCode);
	initPrettyPhoto();
	$('#ui-datepicker-div').hide();
}

function initAjax(){
	$("a[rel^='ajax']").click(function(e) {
		e.preventDefault();
		$.historyLoad(this.href.replace(/^.*#/, ''));
		return false;
	});	
}

function initAutoSuggest(){
	var options = {
			script: "./utilservlet?action=602&",
			varname: "value",
			json: false,
			timeout: 10000,
			maxentries: 10,
			delay: 0,
			cache: false,
			shownoresults: false,
			minchars: 1
	};
	var as = new bsn.AutoSuggest('stringSearch', options);
}

function callback(hash)
{
	var url=hash+'&fullPage=false';
	// hash doesn't contain the first # character.
	if(hash) {
		$.ajax({ 
			method: "post",
			url: url,
			cache: false,
			beforeSend: function(){
				$("#loading").toggle();
			}, 
			complete: function(){
				initAjax();
				$("#loading").toggle();
			}, 
			success: function(html){
				$('#main').html(html); 
			} 
		});
	} else {
		$("#main").load('./main.jsp');
	} 
}

function initTabs(){	
	$(".tab").click(function(e) {
		e.preventDefault();
		$("li.active").removeClass();
		$(this.parentNode).addClass("active");
		$(".tab_attivo").slideUp();
		//$(".tab_attivo").hide();
		$(".tab_attivo").removeClass();
		$("#tab_"+this.name).addClass("tab_attivo");	
		$("#tab_"+this.name).slideDown("slow");
		//$("#tab_"+this.name).show();
	});
}


//Calendar

function initCalendar(path, languageCode) {
	$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['it']));

	$(".datepicker").datepicker(
		{
			showOn: 'button', 
			buttonImage: path+'/img/calendario.gif', 
			buttonImageOnly: true,
			minDate: '+0D', 
			maxDate: '+11M'		
		},$.datepicker.regional[languageCode]
	);
}

function initCalendarHome(path, languageCode) {
	/*$.datepicker.setDefaults($.extend({showMonthAfterYear: false}, $.datepicker.regional['fr']));*/
	

	$(".datepickerhome").datepicker(
		{
			showOn: 'button', 
			buttonImage: path+'/images/cal.gif', 
			buttonImageOnly: true,
			minDate: '+0D', 
			maxDate: '+11M'
			
		},$.datepicker.regional[languageCode]
	);
	
}


function initPrettyPhoto(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
}

function showHideFilter(componentId){
	$("#"+componentId).toggle();
}

function showHideAvaibility(componentId){
	$("#"+componentId).toggle();
}

function hideComponent(componentId){
	$("#"+componentId).hide();
}

function showComponent(componentId){
	$("#"+componentId).show();
}

function showHideRoomInfo(componentId){
	//alert(componentId);
	$("#"+componentId).toggle();
}

function showSearchHotel(componentId){
	$("#"+componentId).toggle();
}

function changeHotelPhoto(url_300, url_original){
	var el1 = document.getElementById('url_max_300');
	el1.src=url_300;
	el1.title=url_original;
}

function changeLanguage(component, path){
	var languageCode = component.value;
	$.ajax({ 
		method: "post",
		url: path+"/utilservlet?action=200&languageCode="+languageCode,
		cache: false,
		beforeSend: function(){
			$("#loading").toggle();
		}, 
		complete: function(){
			$("#loading").toggle();
		}, 
		success: function(html){
			location.reload(true);
		} 
	});
}

function changeLanguageHome(component, path){
	var languageCode = component.name;
	$.ajax({ 
		method: "post",
		url: path+"/utilservlet?action=200&languageCode="+languageCode,
		cache: false,
		beforeSend: function(){
			$("#loading").toggle();
		}, 
		complete: function(){
			$("#loading").toggle();
		}, 
		success: function(html){
			location.reload(true);
		} 
	});
}

function sortResult(value, path){
	$.ajax({ 
		method: "post",
		url: path+"/utilservlet?action=63&type="+value,
		cache: false,
		beforeSend: function(){
			$("#loading").toggle();
		}, 
		complete: function(){
			$("#loading").toggle();
		}, 
		success: function(html){
			location.reload(true);
		} 
	});
}

function loadFilter(path, value){
	$.ajax({ 
		method: "post",
		url: path+"/utilservlet?action=71"+value,
		cache: false,
		beforeSend: function(){
			$("#loading").toggle();
		}, 
		complete: function(){
			$("#loading").toggle();
		}, 
		success: function(html){
			location.reload(true);
		} 
	});
}

function closeFrame(path){
	$.prettyPhoto.close();
	document.location.href=path;
}

function openPrettyPhoto(hotelId, checkIn, interval, languageCode){
	var parameters='';
	var blocks = document.getElementsByName('block');
    for(i = 0; i < blocks.length; i++)
    {   
    	if(blocks[i].value>0){
    		parameters=parameters+'&nr_rooms_'+blocks[i].id+'='+blocks[i].value;
    	}
    }
    $.prettyPhoto.open('https://secure.booking.com/book.html?aid=318693&hostname=www.hellohotello.com&hotel_id='+hotelId+'&checkin='+checkIn+'&interval='+interval+'&lang='+languageCode+parameters+'&stage=1&iframe=true&width=92%&height=86%','HelloHotello','');
}






