howManyHotelsToDisplay=5;   //how many hotels to display

//Set_Cookie( 'mycookie', 'visited 9 times', 30, '/', '', '' );
function Set_Cookie( 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 Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}  //end Get_Cookie


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
//check if the cookie was deleted
/*
Delete_Cookie('test', '/', '');
( Get_Cookie( 'test' ) ) ? alert( Get_Cookie('test')) : alert( 'it is gone');
*/





function unique_first(a){       //keeps first appearance of the element
   var r = new Array();
   o:for(var i = 0, n = a.length; i < n; i++)
   {
      for(var x = 0, y = r.length; x < y; x++)
      {
         if(r[x]==a[i]) continue o;
      }
      r[r.length] = a[i];
   }
   return r;
}
function unique_last(a)   //keeps LAST appearance of the element
{
   var r = new Array();
   o:for(var i = 0, n = a.length; i < n; i++) {
      for(var x = i + 1 ; x < n; x++)
      {
         if(a[x]==a[i]) continue o;
      }
      r[r.length] = a[i];
   }
   return r;
}





/*=====================================================================*/
/*=====================  START hotel stuff     ========================*/
/*=====================================================================*/


howManyHotelsToDisplayMainPage=7;   //how many hotels to display on main page

arrExtraInfoMainPage=new Array();      //text to be added after visited hotels on main page
/*rrExtraInfoMainPage[0]="<div style='font-size:14px;'>TEXT 1</div>" */
arrExtraInfoMainPage[0]="<div><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Trendy Specials:</H1></div><div style='margin-bottom:5px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div style='margin-bottom:5px;'><a href='http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php' title='Trendy Beauty & Health Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy behe5.jpg' alt='Trendy Beauty & Health Hotels'	class='banner'></a></div><div style='margin-bottom:5px;'><A Href='http://www.trendy-hotels.nl/winingdining/trendy-wining-en-dining-hotels.php' title='Trendy Wining & Dining Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy-wining-and-dining.jpg' alt='Trendy Wining & Dining Hotels' class='banner'/></A></div><div style='margin-bottom:5px;'><A Href='http://www.trendy-hotels.nl/Urbanhotels/' title='Top 10 Urban Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendyurbanhotels.jpg' alt='Top 10 Urban Hotels' class='banner'></a></div>"

arrExtraInfoMainPage[1]="<div><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Trendy Specials:</H1></div><div style='margin-bottom:5px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div style='margin-bottom:5px;'><a href='http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php' title='Trendy Beauty & Health Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy behe5.jpg' alt='Trendy Beauty & Health Hotels'	class='banner'></a></div><div style='margin-bottom:5px;'><A Href='http://www.trendy-hotels.nl/winingdining/trendy-wining-en-dining-hotels.php' title='Trendy Wining & Dining Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy-wining-and-dining.jpg' alt='Trendy Wining & Dining Hotels' class='banner'/></A></div><div><a href='http://www.trendy-hotels.nl/top10.php' title='Top 10 Trendy Hotels'><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Bekijk ook onze Top 10!</H1></a></div></div>"

arrExtraInfoMainPage[2]="<div><div style='margin-bottom:3px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div style='margin-bottom:3px;'><a href='http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php' title='Trendy Beauty & Health Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy behe5.jpg' alt='Trendy Beauty & Health Hotels' class='banner'></a></div><div style='margin-bottom:2px;'><A Href='http://www.trendy-hotels.nl/winingdining/trendy-wining-en-dining-hotels.php' title='Trendy Wining & Dining Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy-wining-and-dining.jpg' alt='Trendy Wining & Dining Hotels' class='banner'/></A></div></div>"

arrExtraInfoMainPage[3]="<div><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Trendy Specials:</H1><div style='margin-bottom:5px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div style='margin-bottom:5px;'><a href='http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php' title='Trendy Beauty & Health Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy behe5.jpg' alt='Trendy Beauty & Health Hotels'	class='banner'></a></div></div>"

arrExtraInfoMainPage[4]="<div><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Trendy Specials:</H1><div style='margin-bottom:10px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div><a href='http://www.trendy-hotels.nl/top10.php' title='Top 10 Trendy Hotels'><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Bekijk ook onze Top 10!</H1></a></div></div>"

arrExtraInfoMainPage[5]="<div><div style='margin-bottom:5px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div></div>"

arrExtraInfoMainPage[6]="<div><a href='http://www.trendy-hotels.nl/top10.php'><H1 style='font-size:13px; margin-bottom:5px; color:#3E0074;'>Bekijk ook onze Top 10!</H1></a></div>"


function addHotelToCookie(hotel_id,page){
  if(hotel_id.length >0){   //only if an id is passed from $_GET
  if( Get_Cookie('c_visitedHotels') ){
      var str_allVisitedHotels =  Get_Cookie('c_visitedHotels')
      var arr_allVisitedHotels =  str_allVisitedHotels.split(',')
      arr_allVisitedHotels.push(hotel_id)
      arr_unique_allVisitedHotels = unique_last(arr_allVisitedHotels)
      var str_new_allVisitedHotels = arr_unique_allVisitedHotels.join(',')
      Set_Cookie('c_visitedHotels',str_new_allVisitedHotels,30,'/','','')
  }else{
      Set_Cookie('c_visitedHotels',hotel_id,30,'/','','')
  }
  }
  if(page=='mainpage'){
     displayVisitedHotels_mainPage()  //display the hotels reverse order main page
  }

  if(page=='normalpage'){
     displayVisitedHotels()  //display the hotels reverse order
  }

  //displayFavouriteHotels()
}  //end addHotelToCookie



function displayVisitedHotels_mainPage(){
    if( Get_Cookie('c_visitedHotels') ){
      var str_allVisitedHotels =  Get_Cookie('c_visitedHotels')
      var arr_allVisitedHotels =  str_allVisitedHotels.split(',')
      var arr_reverse_allVisitedHotels = arr_allVisitedHotels.reverse()
      var str_html_allVisitedHotels=''

     var lengthHotelVisited = arr_reverse_allVisitedHotels.length; //how many hotels are visited

     if(lengthHotelVisited>0){

        for(var i=0; i<lengthHotelVisited; i++){
        if(i<howManyHotelsToDisplayMainPage){
        //str_html_allVisitedHotels+='<div>Hotel: ' + arr_reverse_allVisitedHotels[i] + ' <a class="fav" href="javascript:addFavouriteHotelToCookie('+ arr_reverse_allVisitedHotels[i] +')">Add as Favourite</a>       </div>'

        //------------- ajax
         /**/      ajax_allVisitedHotels(arr_reverse_allVisitedHotels[i],'visitedHotelsAjax','vis')

          }else{
            break
            }
        }
        if(lengthHotelVisited<=howManyHotelsToDisplayMainPage){    //add EXTRA

           var diff_extra = howManyHotelsToDisplayMainPage-lengthHotelVisited //how many extra to display
           
           if(diff_extra==6){
              displayExtraDataMain(arrExtraInfoMainPage[0],'visitedHotelsExtra')
             }
           else if(diff_extra==5){
              displayExtraDataMain(arrExtraInfoMainPage[1],'visitedHotelsExtra')
             }
           else if(diff_extra==4){
              displayExtraDataMain(arrExtraInfoMainPage[2],'visitedHotelsExtra')
             }
           else if(diff_extra==3){
              displayExtraDataMain(arrExtraInfoMainPage[3],'visitedHotelsExtra')
             }
           else if(diff_extra==2){
              displayExtraDataMain(arrExtraInfoMainPage[4],'visitedHotelsExtra')
             }
           else if(diff_extra==1){
              displayExtraDataMain(arrExtraInfoMainPage[5],'visitedHotelsExtra')
             }
           else if(diff_extra==0){
              displayExtraDataMain(arrExtraInfoMainPage[6],'visitedHotelsExtra')
             }    
        }
        if(lengthHotelVisited>howManyHotelsToDisplayMainPage){    //add EXTRA
              displayExtraDataMain(arrExtraInfoMainPage[6],'visitedHotelsExtra') 
        }

     } else{ //no visited hotels, display ONLY EXTRA info arrExtraInfoMainPage

        for(var k=0; k<arrExtraInfoMainPage.length; k++){
          displayExtraDataMain(arrExtraInfoMainPage[k],'visitedHotelsExtra')
        }
     }



     //document.getElementById('visitedHotels').innerHTML=str_html_allVisitedHotels;
    }
    resetContainerHTML('visitedHotelsAjax')
     hideTitleFavVis()
}




function displayVisitedHotels(){
    if( Get_Cookie('c_visitedHotels') ){
      var str_allVisitedHotels =  Get_Cookie('c_visitedHotels')
      var arr_allVisitedHotels =  str_allVisitedHotels.split(',')
      var arr_reverse_allVisitedHotels = arr_allVisitedHotels.reverse()
      var str_html_allVisitedHotels=''

      for(var i=0; i<arr_reverse_allVisitedHotels.length; i++){
        if(i<howManyHotelsToDisplay){
        str_html_allVisitedHotels+='<div>Hotel: ' + arr_reverse_allVisitedHotels[i] + ' <a id="visfav" href="javascript:addFavouriteHotelToCookie('+ arr_reverse_allVisitedHotels[i] +')">Add as Favourite</a>       </div>'
        //alert(arr_reverse_allVisitedHotels[i])
        //------------- ajax
  /**/      ajax_allVisitedHotels(arr_reverse_allVisitedHotels[i],'visitedHotelsAjax','vis')

        }else{
          break
          }
      }
     //document.getElementById('visitedHotels').innerHTML=str_html_allVisitedHotels;
    }
    resetContainerHTML('visitedHotelsAjax')
     hideTitleFavVis()
}


function addFavouriteHotelToCookie(hotel_id){
  if( Get_Cookie('c_favouriteHotels') ){
      var str_allFavouriteHotels =  Get_Cookie('c_favouriteHotels')
      var arr_allFavouriteHotels =  str_allFavouriteHotels.split(',')
      arr_allFavouriteHotels.push(hotel_id)
      arr_unique_allFavouriteHotels = unique_last(arr_allFavouriteHotels)
      var str_new_allFavouriteHotels = arr_unique_allFavouriteHotels.join(',')
      Set_Cookie('c_favouriteHotels',str_new_allFavouriteHotels,30,'/','','')
  }else{
      Set_Cookie('c_favouriteHotels',hotel_id,30,'/','','')
  }
  displayFavouriteHotels()  //display the hotels
}  //end addFavouriteHotelToCookie


function displayFavouriteHotels(){
  var str_html_allFavouriteHotels=''
    if( Get_Cookie('c_favouriteHotels') ){
      var str_allFavouriteHotels =  Get_Cookie('c_favouriteHotels')
      var arr_allFavouriteHotels =  str_allFavouriteHotels.split(',')
      var arr_reverse_allFavouriteHotels = arr_allFavouriteHotels.reverse()
      /**/ resetContainerHTML('favouriteHotelsAjax')
      for(var i=0; i<arr_reverse_allFavouriteHotels.length; i++){
        str_html_allFavouriteHotels+='<div>Hotel: ' + arr_reverse_allFavouriteHotels[i] + ' <a class="visfav" href="javascript:removeFavouriteHotel('+ arr_reverse_allFavouriteHotels[i] +')">Remove from Favourites</a>       </div>'
        //alert(arr_reverse_allVisitedHotels[i])
        //------------------- ajax -------------------

/**/        ajax_allVisitedHotels(arr_reverse_allFavouriteHotels[i],'favouriteHotelsAjax','fav')

      }
    }
    //document.getElementById('favouriteHotels').innerHTML=str_html_allFavouriteHotels;
    resetContainerHTML('favouriteHotelsAjax')
     hideTitleFavVis()
} //end displayFavouriteHotels


function arrayRemoveElement(arrayName,arrayElement) {
    for(var i=0; i<arrayName.length;i++ ){
        if(arrayName[i]==arrayElement){  arrayName.splice(i,1); }
      }
  }


function removeFavouriteHotel(hotel_id){
    if( Get_Cookie('c_favouriteHotels') ){
      var str_allFavouriteHotels =  Get_Cookie('c_favouriteHotels')
      var arr_allFavouriteHotels =  str_allFavouriteHotels.split(',')
      arrayRemoveElement(arr_allFavouriteHotels, hotel_id)
      arr_unique_allFavouriteHotels = unique_last(arr_allFavouriteHotels)
      var str_new_allFavouriteHotels = arr_unique_allFavouriteHotels.join(',')
      Set_Cookie('c_favouriteHotels',str_new_allFavouriteHotels,30,'/','','')
    }
    displayFavouriteHotels()  //display the hotels
}


/*************************************************************************/
/*************************************************************************/
/************************************************************************
*/


//loadingAjaxImg = '<img src="ajax-loader.gif" /> ';
function getAjaxData(hid){
   //$('#responseAjax').html(loadingAjaxImg);  //LOADING gif
   requestPage = 'hotel_detailshp.php?hotelid=' + hid
        $.post(requestPage, function(data){
            $('#responseAjax').html(data);
          });
}

function resetContainerHTML(hcontainer){
 $('#' + hcontainer).empty();
 //$('#' + hcontainer).html(loadingAjaxImg);  //LOADING gif
}

function ajax_allVisitedHotels(hid,hcontainer,vis_fav){
/*vis_fav = 'vis' or 'fav'*/
   requestPage = 'hotel_details.php?hotelid=' + hid + '&visfav='+ vis_fav
   //alert(requestPage)
        $.post(requestPage, function(data){
            $('#' + hcontainer).append(data);
          });
}

function displayExtraDataMain(data,hcontainer){
 $('#' + hcontainer).append(data);
}


function hideTitleFavVis(){
     $('#visitedHotelsAjax_title').css({'display': 'block'})
      //$('#favouriteHotelsAjax_title').css({'display': 'block'})
      $('#favouriteHotelsAjax_title').html('my FAV hotels:')

      //VIS
      if( Get_Cookie('c_visitedHotels') ){
        var str_allVisitedHotels =  Get_Cookie('c_visitedHotels')
        if (str_allVisitedHotels.length>0){
        }else{
          $('#visitedHotelsAjax_title').css({'display': 'none'})
        }
      }else{
         /* $('#visitedHotelsAjax_title').css({'display': 'none'}) 
         $('#visitedHotelsAjax_title').html('geen vis hotels') */
         $('#visitedHotelsAjax_title').html("<div style='margin-bottom:9px;'><A href='http://www.trendy-hotels.nl/Designhotels/' title='Top 10 Design Hotels'><img src='http://www.trendy-hotels.nl/graphics/designhotels.jpg' alt='Top 10 Design Hotels' class='banner' /></a></div><div style='margin-bottom:9px;'><a href='http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php' title='Trendy Beauty & Health Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy behe5.jpg' alt='Trendy Beauty & Health Hotels'	class='banner'></a></div><div style='margin-bottom:9px;'><A Href='http://www.trendy-hotels.nl/winingdining/trendy-wining-en-dining-hotels.php' title='Trendy Wining & Dining Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendy-wining-and-dining.jpg' alt='Trendy Wining & Dining Hotels' class='banner'/></A></div><div style='margin-bottom:9px;'><A Href='http://www.trendy-hotels.nl/Urbanhotels/' title='Top 10 Urban Hotels'><img src='http://www.trendy-hotels.nl/graphics/trendyurbanhotels.jpg' alt='Top 10 Urban Hotels' class='banner'></a></div><div style='margin-bottom:9px'><a href='http://www.trendy-hotels.nl/Trendy-Hotels-Google-Earth.php' title='Alle hotels op Google Earth'><img src='http://www.trendy-hotels.nl/graphics/googlearth2.jpg' alt='Alle hotels op Google Earth' class='banner'></a></div>")

         
       /*   "<div><H1 style=font-size:13px; margin-bottom:5px; color:#3E0074;>Trendy Specials:</H1></div><div style=margin-bottom:5px;><A href=http://www.trendy-hotels.nl/Designhotels/ title=Top 10 Design Hotels><img src=http://www.trendy-hotels.nl/graphics/designhotels.jpg alt=Top 10 Design Hotels class=banner /></a></div><div style=margin-bottom:5px;><a href=http://www.trendy-hotels.nl/beauty-health/trendy-beauty-and-health-hotels.php title=Trendy Beauty en Health Hotels><img src=http://www.trendy-hotels.nl/graphics/trendy behe5.jpg alt=Trendy Beauty en Health Hotels class=banner></a></div><div style=margin-bottom:5px;><A Href=http://www.trendy-hotels.nl/winingdining/trendy-wining-en-dining-hotels.php title=Trendy Wining & Dining Hotels><img src=http://www.trendy-hotels.nl/graphics/trendy-wining-and-dining.jpg alt=Trendy Wining & Dining Hotels class=banner></A></div><div style=margin-bottom:5px;><A Href=http://www.trendy-hotels.nl/Urbanhotels/ title=Top 10 Urban Hotels><img src=http://www.trendy-hotels.nl/graphics/trendyurbanhotels.jpg alt=Top 10 Urban Hotels class=banner></a></div>") */


      }

      //FAV
      if( Get_Cookie('c_favouriteHotels') ){
        var str_allVisitedHotels =  Get_Cookie('c_favouriteHotels')
        if (str_allVisitedHotels.length>0){

        }else{
          //$('#favouriteHotelsAjax_title').css({'display': 'none'})
          $('#favouriteHotelsAjax_title').html('No FAV hotels')

        }
      }else{
        // $('#favouriteHotelsAjax_title').css({'display': 'none'})
         $('#favouriteHotelsAjax_title').html('No FAV hotels')
      }
}


   $(document).ready(function() {

   });





