function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}


function initCap(str) {
var str = str.substring(0,1).toUpperCase() + str.substring(1,str.length).toLowerCase();

return str;
} 

$.extend($.fn.disableTextSelect = function() {
		return this.each(function(){
			if($.browser.mozilla){ 
				$(this).css('MozUserSelect','none');
			}else if($.browser.msie){ 
				$(this).bind('selectstart',function(){return false;});
			}else{
				$(this).mousedown(function(){return false;});
			}
		});
	});

$.ctrl = function(key, callback, args) {
    $(document).keydown(function(e) {
        if(!args) args=[];  
        if(e.keyCode == key.charCodeAt(0) && e.ctrlKey) {
            callback.apply(this, args);
            return false;
        }
    });
};



function trim(str) {
        return str.replace(/^\s+|\s+$/g,"");
    };

 
function daysInMonth(month, year){
	var datenextmonth;
	if ( ((month + 1) % 12) == 0){  
		datenextmonth = new Date(year+1, month+1, 1);
	}
	else {  
		datenextmonth = new Date(year, month+1, 1);
	}
	datenextmonth.setDate(datenextmonth.getDate() - 1);
	return datenextmonth.getDate();
}

function fill_selectbox(id, obj)
{
 
	
	for(var i = 0; i < obj.length;i++)
	{
		jQuery('#'+id).append('<option value="'+obj[i]+'">'+obj[i]+'</option')
		
	}
}


 
function addMonth(d,month){ 
var t = d; 
t.setMonth(d.getMonth()+ month) ;
 
 if (t.getDate() < d.getDate()) 
{ 
   t.setDate(0); 
 } 

return t;
}

 
function getCalendarDate(date1)
{
	
   var months = new Array(13);
   months[0]  = "1" ;
   months[1]  = "2";
   months[2]  = "3";
   months[3]  = "4";
   months[4]  = "5";
   months[5]  = "6";
   months[6]  = "7";
   months[7]  = "8";
   months[8]  = "9";
   months[9]  = "10";
   months[10] = "11";
   months[11] = "12";
   var now         = date1;
   var monthnumber = now.getMonth();
   var monthname   = months[monthnumber];
   var monthday    = now.getDate();
   var year        = now.getFullYear();
   
  if ($("#page_language").val()=="cn") {
	   
   var dateString = year +
                    ' &#24180 ' +
                    monthname +
					" &#26376";
				
   }
   
   if ($("#page_language").val()=="en") {
  			switch (monthname) {
   				case '1': v_monthname_en = 'Jan'; break;
   				case '2': v_monthname_en = 'Feb'; break;
   				case '3': v_monthname_en = 'Mar'; break;
   				case '4': v_monthname_en = 'Apr'; break;
   				case '5': v_monthname_en = 'May'; break;
   				case '6': v_monthname_en = 'Jun'; break;
   				case '7': v_monthname_en = 'Jul'; break;
   				case '8': v_monthname_en = 'Aug'; break;
   				case '9': v_monthname_en = 'Sep'; break;
   				case '10': v_monthname_en = 'Oct'; break;
   				case '11': v_monthname_en = 'Nov'; break;
   				case '12': v_monthname_en = 'Dec'; break;
				   			};

   var dateString = v_monthname_en + "/" + year;
   }
  if ($("#page_language").val()=="nl") {
	      
  			switch (monthname) {
   				case '1': v_monthname_nl = 'Jan'; break;
   				case '2': v_monthname_nl = 'Feb'; break;
   				case '3': v_monthname_nl = 'Mrt'; break;
   				case '4': v_monthname_nl = 'Apr'; break;
   				case '5': v_monthname_nl = 'Mei'; break;
   				case '6': v_monthname_nl = 'Jun'; break;
   				case '7': v_monthname_nl = 'Jul'; break;
   				case '8': v_monthname_nl = 'Aug'; break;
   				case '9': v_monthname_nl = 'Sep'; break;
   				case '10': v_monthname_nl = 'Okt'; break;
   				case '11': v_monthname_nl = 'Nov'; break;
   				case '12': v_monthname_nl = 'Dec'; break;
				   			};

var dateString = v_monthname_nl + "/" + year;
   }


   return dateString;
}  

function calcFlightDays() {
  v_days_B_S=$('#datepicker_depart1').val();
  v_days_E_S=$('#datepicker_depart2').val();

  v_days_B_S=v_days_B_S.substring(0,4)+'/'+v_days_B_S.substring(5,7)+'/'+v_days_B_S.substring(8,10);
  v_days_E_S=v_days_E_S.substring(0,4)+'/'+v_days_E_S.substring(5,7)+'/'+v_days_E_S.substring(8,10);
         
  v_days_B= new Date(v_days_B_S);
  v_days_E= new Date(v_days_E_S);
  v_days_between_B_AND_E=Math.ceil((v_days_E.getTime() - v_days_B.getTime())/1000/60/60/24);

  v_today = new Date();
  v_days_between_B_AND_NOW=Math.ceil((v_days_B.getTime() - v_today.getTime())/1000/60/60/24);
  return v_days_between_B_AND_E+"|"+v_days_between_B_AND_NOW;	
}

function calcNights2(typeDate,lan) {
  v_nights_B_S=$('#datepicker_checkin').val();
  v_nights_E_S=$('#datepicker_checkout').val();

  v_nights_B_S=v_nights_B_S.substring(0,4)+'/'+v_nights_B_S.substring(5,7)+'/'+v_nights_B_S.substring(8,10);
  v_nights_E_S=v_nights_E_S.substring(0,4)+'/'+v_nights_E_S.substring(5,7)+'/'+v_nights_E_S.substring(8,10);
         
  v_nights_B= new Date(v_nights_B_S);
  v_nights_E= new Date(v_nights_E_S);
  $('#nights').html(Math.ceil((v_nights_E.getTime() - v_nights_B.getTime())/1000/60/60/24));
  
  if (typeDate=='checkin') {
    v_weekday_hotel_n=v_nights_B.getDay();	
  } else {
	     v_weekday_hotel_n=v_nights_E.getDay(); 
  }
  
  switch (lan) {
	  case 'cn' :
  			switch (v_weekday_hotel_n) {
   				case 0: v_weekday_hotel = '星期日'; break;
   				case 1: v_weekday_hotel = '星期一'; break;
				case 2: v_weekday_hotel = '星期二'; break;
				case 3: v_weekday_hotel = '星期三'; break;
				case 4: v_weekday_hotel = '星期四'; break;
				case 5: v_weekday_hotel = '星期五'; break;
				case 6: v_weekday_hotel = '星期六'; break;
   			};
			break;
	  case 'en' :		
	  			switch (v_weekday_hotel_n) {
   				case 0: v_weekday_hotel = 'Sunday'; break;
   				case 1: v_weekday_hotel = 'Monday'; break;
				case 2: v_weekday_hotel = 'Tuesday'; break;
				case 3: v_weekday_hotel = 'Wednesday'; break;
				case 4: v_weekday_hotel = 'Thursday'; break;
				case 5: v_weekday_hotel = 'Friday'; break;
				case 6: v_weekday_hotel = 'Saturday'; break;
				};
				break;
  	  case 'nl' :		
	  			switch (v_weekday_hotel_n) {
   				case 0: v_weekday_hotel = 'Zondag'; break;
   				case 1: v_weekday_hotel = 'Maandag'; break;
				case 2: v_weekday_hotel = 'Dinsdag'; break;
				case 3: v_weekday_hotel = 'Woensdag'; break;
				case 4: v_weekday_hotel = 'Donderdag'; break;
				case 5: v_weekday_hotel = 'Vrijdag'; break;
				case 6: v_weekday_hotel = 'Zaterdag'; break;
				};
				break;			
      case 'tw' :
 			switch (v_weekday_hotel_n) {
   				case 0: v_weekday_hotel = '禮拜日'; break;
   				case 1: v_weekday_hotel = '禮拜一'; break;
				case 2: v_weekday_hotel = '禮拜二'; break;
				case 3: v_weekday_hotel = '禮拜三'; break;
				case 4: v_weekday_hotel = '禮拜四'; break;
				case 5: v_weekday_hotel = '禮拜五'; break;
				case 6: v_weekday_hotel = '禮拜六'; break;
   			};
			break;
       }
  
  if (typeDate=='checkin') {		
    $('#weekday_checkin').html(v_weekday_hotel);
  } else {
    $('#weekday_checkout').html(v_weekday_hotel);
  }
  
  return null;
} 

function flightWeekdays(typeDate,lan) {
  v_depart1_W_S=$('#datepicker_depart1').val();
  v_depart2_W_S=$('#datepicker_depart2').val();

  v_depart1_W_S=v_depart1_W_S.substring(0,4)+'/'+v_depart1_W_S.substring(5,7)+'/'+v_depart1_W_S.substring(8,10);
  v_depart2_W_S=v_depart2_W_S.substring(0,4)+'/'+v_depart2_W_S.substring(5,7)+'/'+v_depart2_W_S.substring(8,10);
         
  v_depart1_W= new Date(v_depart1_W_S);
  v_depart2_W= new Date(v_depart2_W_S);  
    
  if (typeDate=='depart1') {
    v_weekday_flight_n=v_depart1_W.getDay();	
  } else {
	     v_weekday_flight_n=v_depart2_W.getDay(); 
  }
   
  switch (lan) {
	  case 'cn' :
  			switch (v_weekday_flight_n) {
   				case 0: v_weekday_flight = '星期日'; break;
   				case 1: v_weekday_flight = '星期一'; break;
				case 2: v_weekday_flight = '星期二'; break;
				case 3: v_weekday_flight = '星期三'; break;
				case 4: v_weekday_flight = '星期四'; break;
				case 5: v_weekday_flight = '星期五'; break;
				case 6: v_weekday_flight = '星期六'; break;
   			};
			break;
	  case 'en' :		
	  			switch (v_weekday_flight_n) {
   				case 0: v_weekday_flight = 'Sunday'; break;
   				case 1: v_weekday_flight = 'Monday'; break;
				case 2: v_weekday_flight = 'Tuesday'; break;
				case 3: v_weekday_flight = 'Wednesday'; break;
				case 4: v_weekday_flight = 'Thursday'; break;
				case 5: v_weekday_flight = 'Friday'; break;
				case 6: v_weekday_flight = 'Saturday'; break;
				};
				break;
  	  case 'nl' :		
	  			switch (v_weekday_flight_n) {
   				case 0: v_weekday_flight = 'Zondag'; break;
   				case 1: v_weekday_flight = 'Maandag'; break;
				case 2: v_weekday_flight = 'Dinsdag'; break;
				case 3: v_weekday_flight = 'Woensdag'; break;
				case 4: v_weekday_flight = 'Donderdag'; break;
				case 5: v_weekday_flight = 'Vrijdag'; break;
				case 6: v_weekday_flight = 'Zaterdag'; break;
				};
				break;			
      case 'tw' :
 			switch (v_weekday_flight_n) {
   				case 0: v_weekday_flight = '禮拜日'; break;
   				case 1: v_weekday_flight = '禮拜一'; break;
				case 2: v_weekday_flight = '禮拜二'; break;
				case 3: v_weekday_flight = '禮拜三'; break;
				case 4: v_weekday_flight = '禮拜四'; break;
				case 5: v_weekday_flight = '禮拜五'; break;
				case 6: v_weekday_flight = '禮拜六'; break;
   			};
			break;
       }
  
  if (typeDate=='depart1') {		
    $('#weekday_depart').html(v_weekday_flight);
  } else {
    $('#weekday_return').html(v_weekday_flight);
  }
  
  return null;
} 

function city_focus(v_city_focus) {
	 
  $('.city_displayed').removeClass('city_displayed_cur');
  $('.city_displayed').removeClass('city_displayed');
  $('.city_displayed').css({'display':'none'});
  
  if ( $("#page_name").val() == "flight" ) {
   	 $('.wd_cities_detail').each(function(){		 
		$(this).removeClass('city_displayed');
		$(this).removeClass('city_displayed_cur');
		$(this).css({'display':'none'});
		$(this).removeAttr('seq');
                    });  
  }
  
  if ( $("#page_name").val() == "hotel" ) {
	  	 $('.hotel_cities_detail').each(function(){		 
		   $(this).removeClass('city_displayed');
		   $(this).removeClass('city_displayed_cur');
		   $(this).css({'display':'none'});
		   $(this).removeAttr('seq');
                    });  
  }

  var v_cities_displayed_max=0;
  var v_cities_displayed_cur=0; 
  v_city_e_name='';
 

if (v_city_focus =='depart1_city_name') {
  v_cities_pos = $('#depart1_city_name').position(); 
  v_show_cities_left=v_cities_pos.left;
  v_show_cities_top=v_cities_pos.top + $('#depart1_city_name').height()+ 10;
  v_show_cities_width=250;
   
  
  $('#depart1_city_code').val("");  
  $('#depart1_city_name').val("");
  $('#depart1_city_name').removeClass('hints');
  $('.wd_cities_overlay [fav=EU]').css({'display':'block'});
  $('.wd_cities_overlay [fav=EU]').addClass('city_displayed');
     
  $('#wd_cities_list').css({'display':'block',
				   'position' : 'absolute',
				   'left':v_show_cities_left,
				   'top':v_show_cities_top,
				    'width':v_show_cities_width
					
				  });  
  
   $('.city_displayed').each(function(){
   v_cities_displayed_max = v_cities_displayed_max +1;
   
   $(this).attr('seq',v_cities_displayed_max);
    if (v_cities_displayed_cur == 0 ) {		
		$(this).addClass('city_displayed_cur');
		v_cities_displayed_cur = v_cities_displayed_cur+1;
	  };
   });
   
  } 
   
   
   if (v_city_focus =='arrive1_city_name') {
	 
  v_cities_pos = $('#arrive1_city_name').position(); 
  v_show_cities_left=v_cities_pos.left;
  v_show_cities_top=v_cities_pos.top + $('#arrive1_city_name').height()+ 10;
  v_show_cities_width=250;
   
  
  $('#arrive1_city_code').val("");  
  $('#arrive1_city_name').val("");
  $('#arrive1_city_name').removeClass('hints');
  $('.wd_cities_overlay [fav=CN]').css({'display':'block'});
  $('.wd_cities_overlay [fav=CN]').addClass('city_displayed');
     
  $('#wd_cities_list').css({'display':'block',
				   'position' : 'absolute',
				   'left':v_show_cities_left,
				   'top':v_show_cities_top,
				    'width':v_show_cities_width
					
				  });  
  

   
   $('.city_displayed').each(function(){
   v_cities_displayed_max = v_cities_displayed_max +1;
    
   $(this).attr('seq',v_cities_displayed_max);
    if (v_cities_displayed_cur == 0 ) {		
		$(this).addClass('city_displayed_cur');
		v_cities_displayed_cur = v_cities_displayed_cur+1;
	  };
   });
   
    
   
   
  } 

if (v_city_focus =='depart2_city_name') {
  v_cities_pos = $('#depart2_city_name').position(); 
  v_show_cities_left=v_cities_pos.left;
  v_show_cities_top=v_cities_pos.top + $('#depart2_city_name').height()+ 10;
  v_show_cities_width=250;
  //reset display city indicators
  
  $('#depart2_city_code').val("");  
  $('#depart2_city_name').val("");
  $('#depart2_city_name').removeClass('hints');
  $('.wd_cities_overlay [fav=CN]').css({'display':'block'});
  $('.wd_cities_overlay [fav=CN]').addClass('city_displayed');
     
  $('#wd_cities_list').css({'display':'block',
				   'position' : 'absolute',
				   'left':v_show_cities_left,
				   'top':v_show_cities_top,
				    'width':v_show_cities_width
					
				  });  
  
   $('.city_displayed').each(function(){
   v_cities_displayed_max = v_cities_displayed_max +1;
   
   $(this).attr('seq',v_cities_displayed_max);
    if (v_cities_displayed_cur == 0 ) {		
		$(this).addClass('city_displayed_cur');
		v_cities_displayed_cur = v_cities_displayed_cur+1;
	  };
   });
   
  } 

if (v_city_focus =='arrive2_city_name') {
  v_cities_pos = $('#arrive2_city_name').position(); 
  v_show_cities_left=v_cities_pos.left;
  v_show_cities_top=v_cities_pos.top + $('#arrive2_city_name').height()+ 10;
  v_show_cities_width=250;
  
  
  $('#arrive2_city_code').val("");  
  $('#arrive2_city_name').val("");
  $('#arrive2_city_name').removeClass('hints');
  $('.wd_cities_overlay [fav=EU]').css({'display':'block'});
  $('.wd_cities_overlay [fav=EU]').addClass('city_displayed');
     
  $('#wd_cities_list').css({'display':'block',
				   'position' : 'absolute',
				   'left':v_show_cities_left,
				   'top':v_show_cities_top,
				    'width':v_show_cities_width
					
				  });  
  
   $('.city_displayed').each(function(){
   v_cities_displayed_max = v_cities_displayed_max +1;
   
   $(this).attr('seq',v_cities_displayed_max);
    if (v_cities_displayed_cur == 0 ) {		
		$(this).addClass('city_displayed_cur');
		v_cities_displayed_cur = v_cities_displayed_cur+1;
	  };
   });
   
  } 
  
  if (v_city_focus =='stay_city_name') {
  v_cities_pos = $('#stay_city_name').position(); 
  v_show_cities_left=v_cities_pos.left;
  v_show_cities_top=v_cities_pos.top + $('#stay_city_name').height()+ 10;
  v_show_cities_width=250;
  
  
  $('#stay_city_code').val("");  
  $('#stay_city_name').val("");
  $('#stay_city_name').removeClass('hints');
  $('.hotel_cities_overlay [fav=Y]').css({'display':'block'});
  $('.hotel_cities_overlay [fav=Y]').addClass('city_displayed');
     
  $('#hotel_cities_list').css({'display':'block',
				   'position' : 'absolute',
				   'left':v_show_cities_left,
				   'top':v_show_cities_top,
				    'width':v_show_cities_width
					
				  });  
  
   $('.city_displayed').each(function(){
   v_cities_displayed_max = v_cities_displayed_max +1;
   
   $(this).attr('seq',v_cities_displayed_max);
    if (v_cities_displayed_cur == 0 ) {		
		$(this).addClass('city_displayed_cur');
		v_cities_displayed_cur = v_cities_displayed_cur+1;
	  };
   });
   
  } 
  

  return [v_cities_displayed_cur,v_cities_displayed_max];

  };  

function city_searchagain(v_city_focus,v_cities_displayed_cur,v_cities_displayed_max) {
	
  var    v_addspace_teller=0;
  var    v_addspace='';
      $('#addspace').html('');
      v_cities_displayed_max=0;
      v_cities_displayed_cur=0;
      v_city_e_name='';
 
	
	 
	if (v_city_focus == 'depart1_city_name') {
      $('.wd_cities_detail').removeClass('city_displayed');
      $('.wd_cities_detail').removeClass('city_displayed_cur');
      $('.wd_cities_detail').removeAttr('seq');	

      v_city_input=$('#depart1_city_name').val().toLowerCase();
      v_city_input=trim(v_city_input); 
     
     if ( v_city_input == "")  {
	   	$('.wd_cities_detail').each(function(){
		$(this).removeClass('city_displayed');
		$(this).css({'display':'none'});
	    });
        $('.wd_cities_overlay [fav=EU]').css({'display':'block'});
        $('.wd_cities_overlay [fav=EU]').addClass('city_displayed'); 
	 }
	 else {
        v_city_input_len=v_city_input.length;
     
     $('.wd_cities_detail').each(function(){												  
		v_city_e_name=$(this).attr('e_name');		
        if (! v_city_e_name == "") {
	   	 v_city_e_name=v_city_e_name.substr(0,v_city_input_len);
		};
		if (v_city_input == v_city_e_name) {
			$(this).css({'display':'block'});
			$(this).addClass('city_displayed');			
			v_addspace_teller=v_addspace_teller+1;
			if (v_addspace_teller==3) {
				v_addspace=v_addspace+'<br />';
				$('#addspace').html(v_addspace);
				v_addspace_teller=0;
			}			
		}
		 else
		{
		  $(this).css({'display':'none'});
		  $(this).removeClass('city_displayed');
		 };  								   
     });   
 
	 }  
	 
	  
      $('.city_displayed').each(function(){
      v_cities_displayed_max = v_cities_displayed_max +1;
      $(this).attr('seq',v_cities_displayed_max);  
          if (v_cities_displayed_cur == 0 ) {	
		     $(this).css({'display':'block'});
		     $(this).addClass('city_displayed_cur');
		      v_cities_displayed_cur = v_cities_displayed_cur+1;		
	       };
	   });  
	  
	}  

 
	if (v_city_focus == 'arrive2_city_name') {
      $('.wd_cities_detail').removeClass('city_displayed');
      $('.wd_cities_detail').removeClass('city_displayed_cur');
      $('.wd_cities_detail').removeAttr('seq');	

      v_city_input=$('#arrive2_city_name').val().toLowerCase();
      v_city_input=trim(v_city_input); 

     if ( v_city_input == "")   {
	   	$('.wd_cities_detail').each(function(){
		$(this).removeClass('city_displayed');
		$(this).css({'display':'none'});
	    });
        $('.wd_cities_overlay [fav=EU]').css({'display':'block'});
        $('.wd_cities_overlay [fav=EU]').addClass('city_displayed'); 
	 }
	 else {
        v_city_input_len=v_city_input.length;
     $('.wd_cities_detail').each(function(){												  
		v_city_e_name=$(this).attr('e_name');		
        if (! v_city_e_name == "") {
	   	 v_city_e_name=v_city_e_name.substr(0,v_city_input_len);
		};
		if (v_city_input == v_city_e_name)   {
			$(this).css({'display':'block'});
			$(this).addClass('city_displayed');			
			v_addspace_teller=v_addspace_teller+1;
			if (v_addspace_teller==2) {
				v_addspace=v_addspace+'<br />';
				$('#addspace').html(v_addspace);
				v_addspace_teller=0;
			}			
		}
		 else
		{
		  $(this).css({'display':'none'});
		  $(this).removeClass('city_displayed');
		 };  							   
     });   
	
	 }  
	 
	 
      $('.city_displayed').each(function(){
      v_cities_displayed_max = v_cities_displayed_max +1;
      $(this).attr('seq',v_cities_displayed_max);  
          if (v_cities_displayed_cur == 0 ) {
			  $(this).css({'display':'block'});
		     $(this).addClass('city_displayed_cur');
		      v_cities_displayed_cur = v_cities_displayed_cur+1;		
	       };
	   });  
	}  

 
	if (v_city_focus == 'arrive1_city_name') {
      $('.wd_cities_detail').removeClass('city_displayed');
      $('.wd_cities_detail').removeClass('city_displayed_cur');
      $('.wd_cities_detail').removeAttr('seq');	

      v_city_input=$('#arrive1_city_name').val().toLowerCase();
      v_city_input=trim(v_city_input); 

     if ( v_city_input == "")  {
	   	$('.wd_cities_detail').each(function(){
		$(this).removeClass('city_displayed');
		$(this).css({'display':'none'});
	    });
        $('.wd_cities_overlay [fav=CN]').css({'display':'block'});
        $('.wd_cities_overlay [fav=CN]').addClass('city_displayed'); 
	 }
	 else {
        v_city_input_len=v_city_input.length;
     $('.wd_cities_detail').each(function(){												  
		v_city_e_name=$(this).attr('e_name');		
        if (! v_city_e_name == "") {
	   	 v_city_e_name=v_city_e_name.substr(0,v_city_input_len);
		};
		if (v_city_input == v_city_e_name)   {
			$(this).css({'display':'block'});
			$(this).addClass('city_displayed');			
			v_addspace_teller=v_addspace_teller+1;
			if (v_addspace_teller==2) {
				v_addspace=v_addspace+'<br />';
				$('#addspace').html(v_addspace);
				v_addspace_teller=0;
			}			
		}
		 else
		{
		  $(this).css({'display':'none'});
		  $(this).removeClass('city_displayed');
		 };  							   
     });   
	
	 }  
	 
	 
      $('.city_displayed').each(function(){
      v_cities_displayed_max = v_cities_displayed_max +1;
      $(this).attr('seq',v_cities_displayed_max);  
          if (v_cities_displayed_cur == 0 ) {
			  $(this).css({'display':'block'});
		     $(this).addClass('city_displayed_cur');
		      v_cities_displayed_cur = v_cities_displayed_cur+1;		
	       };
	   });  
	}  


 
	if (v_city_focus == 'depart2_city_name') {
      $('.wd_cities_detail').removeClass('city_displayed');
      $('.wd_cities_detail').removeClass('city_displayed_cur');
      $('.wd_cities_detail').removeAttr('seq');	

      v_city_input=$('#depart2_city_name').val().toLowerCase();
      v_city_input=trim(v_city_input); 

     if ( v_city_input == "")  {
	   	$('.wd_cities_detail').each(function(){
		$(this).removeClass('city_displayed');
		$(this).css({'display':'none'});
	    });
        $('.wd_cities_overlay [fav=CN]').css({'display':'block'});
        $('.wd_cities_overlay [fav=CN]').addClass('city_displayed'); 
	 }
	 else {
        v_city_input_len=v_city_input.length;
     $('.wd_cities_detail').each(function(){												  
		v_city_e_name=$(this).attr('e_name');		
        if (! v_city_e_name == "") {
	   	 v_city_e_name=v_city_e_name.substr(0,v_city_input_len);
		};
		if (v_city_input == v_city_e_name)  {
			$(this).css({'display':'block'});
			$(this).addClass('city_displayed');			
			v_addspace_teller=v_addspace_teller+1;
			if (v_addspace_teller==3) {
				v_addspace=v_addspace+'<br />';
				$('#addspace').html(v_addspace);
				v_addspace_teller=0;
			}			
		}
		 else
		{
		  $(this).css({'display':'none'});
		  $(this).removeClass('city_displayed');
		 };  						   
     });   
	
	 } 
	 
	 
      $('.city_displayed').each(function(){
      v_cities_displayed_max = v_cities_displayed_max +1;
      $(this).attr('seq',v_cities_displayed_max);  
          if (v_cities_displayed_cur == 0 ) {
			  $(this).css({'display':'block'});
		     $(this).addClass('city_displayed_cur');
		      v_cities_displayed_cur = v_cities_displayed_cur+1;		
	       };
	   });  
	}  


 
	if (v_city_focus == 'stay_city_name') {
      $('.hotel_cities_detail').removeClass('city_displayed');
      $('.hotel_cities_detail').removeClass('city_displayed_cur');
      $('.hotel_cities_detail').removeAttr('seq');	

      v_city_input=$('#stay_city_name').val().toLowerCase();
      v_city_input=trim(v_city_input); 

    if ( v_city_input == "")   {
	   	$('.hotel_cities_detail').each(function(){
		$(this).removeClass('city_displayed');
		$(this).css({'display':'none'});
	    });
        $('.hotel_cities_overlay [fav=Y]').css({'display':'block'});
        $('.hotel_cities_overlay [fav=Y]').addClass('city_displayed'); 
	 }
	 else {
        v_city_input_len=v_city_input.length;
     $('.hotel_cities_detail').each(function(){												  
		v_city_e_name=$(this).attr('e_name');		
        if (! v_city_e_name == "") {
	   	 v_city_e_name=v_city_e_name.substr(0,v_city_input_len);
		};
		if (v_city_input == v_city_e_name)   {			
			$(this).css({'display':'block'});
			$(this).addClass('city_displayed');			
			v_addspace_teller=v_addspace_teller+1;
			if (v_addspace_teller==2) {
				v_addspace=v_addspace+'<br />';
				$('#addspace').html(v_addspace);
				v_addspace_teller=0;
			}			
		}
		 else
		{
		  $(this).css({'display':'none'});
		  $(this).removeClass('city_displayed');
		 };  							   
     });   
	
	 }  
	 
	 
      $('.city_displayed').each(function(){
      v_cities_displayed_max = v_cities_displayed_max +1;
      $(this).attr('seq',v_cities_displayed_max);  
          if (v_cities_displayed_cur == 0 ) {
			  $(this).css({'display':'block'});
		     $(this).addClass('city_displayed_cur');
		      v_cities_displayed_cur = v_cities_displayed_cur+1;		
	       };
	   });  
	}  

return [v_cities_displayed_cur,v_cities_displayed_max];
}  


function city_updown(e,v_cities_displayed_cur,v_cities_displayed_max) {  
   v_cites_old_cur= v_cities_displayed_cur;
  if (	e.keyCode == 40 ) { 
	     v_cities_displayed_cur=v_cities_displayed_cur+1;  
    }
	else if (	e.keyCode == 38 ) {
		   v_cities_displayed_cur=v_cities_displayed_cur-1;		  
    };

  
  if (v_cities_displayed_cur > v_cities_displayed_max ) {
      v_cities_displayed_cur=1;
    } else if (v_cities_displayed_cur<1) {
      v_cities_displayed_cur=v_cities_displayed_max;
    }

  $('.city_displayed[seq='+v_cities_displayed_cur+']').addClass('city_displayed_cur');
  $('.city_displayed[seq='+v_cites_old_cur+']').removeClass('city_displayed_cur');;
 
   return [v_cities_displayed_cur,v_cities_displayed_max];
 };  


function city_choose(v_city_focus) {  
 if  ( $('.city_displayed_cur').attr('i_code')=='%hotlist' ) {
	return;
 }
 
   switch (v_city_focus) {
    case 'depart1_city_name' :	  
      $('#depart1_city_code').val($('.city_displayed_cur').attr('i_code'));
      $('#depart1_city_name').val($('.city_displayed_cur').html());      
      $('#arrive1_city_name').focus();	  
      break;
    case 'arrive1_city_name' :  	
      $('#arrive1_city_code').val($('.city_displayed_cur').attr('i_code'));
      $('#arrive1_city_name').val($('.city_displayed_cur').html()); 	  
	      //remove
        $('.city_displayed').removeClass('city_displayed_cur');
        $('.city_displayed').removeClass('city_displayed');
        $('.city_displayed').css({'display':'none'});
  
   	    $('.wd_cities_detail').each(function(){
		 
		$(this).removeClass('city_displayed');
		$(this).removeClass('city_displayed_cur');
		$(this).css({'display':'none'});
		$(this).removeAttr('seq');
                     });  
        $('#wd_cities_list').css({'display':'none'});	  
      $('#day_depart1').focus();	  
      break;
    case 'depart2_city_name' :  	    
      $('#depart2_city_code').val($('.city_displayed_cur').attr('i_code'));
      $('#depart2_city_name').val($('.city_displayed_cur').html());      
      $('#arrive2_city_name').focus();	  
       break;
    case 'arrive2_city_name' :  	
      $('#arrive2_city_code').val($('.city_displayed_cur').attr('i_code'));
      $('#arrive2_city_name').val($('.city_displayed_cur').html());
        //remove
        $('.city_displayed').removeClass('city_displayed_cur');
        $('.city_displayed').removeClass('city_displayed');
        $('.city_displayed').css({'display':'none'});  
   	    $('.wd_cities_detail').each(function(){		 
		$(this).removeClass('city_displayed');
		$(this).removeClass('city_displayed_cur');
		$(this).css({'display':'none'});
		$(this).removeAttr('seq');
                     });  
        $('#wd_cities_list').css({'display':'none'});
       $('#day_depart1').focus();	  
      break; 
	   case 'stay_city_name' :  	
        $('#stay_city_code').val($('.city_displayed_cur').attr('i_code'));
		$('#stay_country_code').val($('.city_displayed_cur').attr('c_code'));
        $('#stay_city_name').val($('.city_displayed_cur').html());
        //remove
        $('.city_displayed').removeClass('city_displayed_cur');
        $('.city_displayed').removeClass('city_displayed');
        $('.city_displayed').css({'display':'none'});  
   	    $('.hotel_cities_detail').each(function(){		 
		$(this).removeClass('city_displayed');
		$(this).removeClass('city_displayed_cur');
		$(this).css({'display':'none'});
		$(this).removeAttr('seq');
                     });  
		
        $('#hotel_cities_list').css({'display':'none'});
		$('#addspace').html('');
       $('#day_checkin').focus();	  
      break; 
     }	  
  };  


function city_keyup(v_city_focus, e,v_cities_displayed_cur,v_cities_displayed_max) {
 
  if (( e.keyCode == 38 ) || ( e.keyCode == 40 )) {
    v_key_action='updown';
 } else  if (  e.keyCode == 13 ) {
    v_key_action='choose';
 } else 
   {
    v_key_action='searchagain'; 
    }
       

   if (v_key_action=='searchagain') {
     var display_numbers=city_searchagain(v_city_focus,v_cities_displayed_cur,v_cities_displayed_max) ;
	 return display_numbers;
   }  
   
   if ( v_key_action=='updown') {
	   
	 var display_numbers=city_updown(e,v_cities_displayed_cur,v_cities_displayed_max);
     return display_numbers;
 }
  
   if ( v_key_action=='choose') {   
     city_choose(v_city_focus);	 
   }
}  

function error_messages(errno, v_page_language) {
  err_msg='';

  if (errno == 100) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择旅客人数';
    break;
   case 'tw' : 
    err_msg='請選擇旅客人數';
    break;
  case 'en':
   err_msg='Please select number of passengers';
  break;
  case 'nl':
   err_msg='Graag aantal passagiers aangeven';
    break;
   }
  }

  if (errno == 101) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='旅客人数不能超过九人';
    break;
   case 'tw' : 
    err_msg='旅客人數不能超過九人';
    break;
  case 'en':
   err_msg='Maximum number of passengers is 9';
    break;
   case 'nl':
   err_msg='Maximum aantal passagiers is 9';
    break;	
   }
  }

  if (errno == 102) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='每位成人只能携带一位婴儿';
    break;
	   case 'tw' : 
    err_msg='每位成人只能攜帶一位嬰兒';
    break;
   case 'en':
   err_msg='Each adult may only carry one infant.';
    break;
   case 'nl':
   err_msg='Elke volwassen mag maar 1 baby meenemen';
    break;   	
   }
  }

  if (errno == 103) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择启程出发城市';
    break;
	   case 'tw' : 
    err_msg='請選擇啟程出發城市';
    break;
   case 'en':
   err_msg='Please choose departure city.';
    break;
   case 'nl':
   err_msg='Graag vertrekstad aangeven';
    break;
   }
  }

  if (errno == 104) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择启程到达城市';
    break;
	   case 'tw' : 
    err_msg='請選擇啟程到達城市';
    break;
   case 'en':
   err_msg='Please choose arrival city.';
    break;
   case 'nl':
   err_msg='Graag aankomststad aangeven.';
    break;
   }
  }

  if (errno == 105) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择回程出发城市';
    break;
	   case 'tw' : 
    err_msg='請選擇回程出發城市';
    break;
   case 'en':
   err_msg='Please choose departure city';
    break;
   case 'nl':
   err_msg='Graag vertrekstad aangeven';
    break;
   }
  }

  if (errno == 106) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择回程到达城市';
    break;
	   case 'tw' : 
    err_msg='請選擇回程到達城市';
    break;
   case 'en':
   err_msg='Please choose arrival city';
    break;
   case 'nl':
   err_msg='Graag aankomststad aangeven.';
    break;  
   }
  }

  if (errno == 107) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='出发城市和到达城市不能相同';
    break;
	   case 'tw' : 
    err_msg='出發城市和到達城市不能相同';
    break;
   case 'en':
   err_msg='Departure and arrival cities should not be the same';
    break;
   case 'nl':
   err_msg='Vertrek- en aankomststad moeten niet dezelfde zijn';
    break;
   }
  }

  if (errno == 108) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，出发日期必须至少两天以后。';
    break;
	   case 'tw' : 
    err_msg='日期錯誤， 出發日期必須至少两天以後。';
    break;
   case 'en':
   err_msg='Departure date must be at least 2 days in the future';
    break;
   case 'nl':
   err_msg='Vertreksdatum moet minimum 2 dagen in de toekomst zijn';
    break;
   }
  }

  if (errno == 109) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，返程日期必须晚于出发日期。';
    break;
	   case 'tw' : 
    err_msg='日期錯誤，返程日期必須晚于出發日期。';
    break;
   case 'en':
   err_msg='Arrival date must be later than departure date';
    break;
   case 'nl':
   err_msg='Aankomstdatum moet later zijn dan vertreksdatum';
    break;
   }
  }



  if (errno == 111) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，离店日期不能早于入住日期。';
    break;
	   case 'tw' : 
    err_msg='日期錯誤，離店日期不能早於入住日期。';
    break;
   case 'en':
   err_msg='Checkin date must be earlier than checkout date';
    break;
   case 'nl':
   err_msg='Checkin datum moet eerder zijn dan checkout datum';
    break;
   }
  }

 

  if (errno == 113) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请输入数字。';
    break;
	   case 'tw' : 
    err_msg='請輸入數字';
    break;
   case 'en':
   err_msg='Please key in numbers only';
    break;
   case 'nl':
   err_msg='Graag alleen nummers intypen';
    break;
   }
  }


  if (errno == 114) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='价格必须高于零。';
    break;
   case 'tw' : 
    err_msg='價格必須高於零。';
    break;
   case 'en':
   err_msg='Amount must be greater than 0';
    break;
   case 'nl':
   err_msg='Bedrag moet groter zijn dan 0';
    break;
   }
  }
  
    if (errno == 115) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='旅客人数仅限1-2人。';
    break;
   case 'tw' : 
    err_msg='旅客人數僅限1-2人。';
    break;
	case 'en' : 
    err_msg='Maximum number of guests is 2';
    break;
	case 'nl' : 
    err_msg='Maximum aantal gasten is 2';
    break;
   }
  }

    if (errno == 116) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='请选择城市。';
    break;
	   case 'tw' : 
    err_msg='請選擇城市。';
    break;
   case 'cn' : 
    err_msg='Please choose city';
    break;
	case 'nl' : 
    err_msg='Kies een stad';
    break;
   }
  }

  if (errno == 117) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，出发日期不能早于此特价票规定最早出发日期。';
    break;
	   case 'tw' : 
    err_msg='。';
    break;
   case 'en':
   err_msg='Choosen departure date is earlier than the earliest departure date of this special offer';
    break;
   case 'nl':
   err_msg='Gekozen vertrekdatum is eerder dan de vroegste vertrekdatum van deze speciale aanbieding';
    break;
   }
  }

  if (errno == 118) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，出发日期不能晚于此特价票规定最迟日期。';
    break;
	   case 'tw' : 
    err_msg='。';
    break;
   case 'en':
   err_msg='Choose departure date is later than the latest departure date of this special offer';
    break;
   case 'nl':
   err_msg='Gekozen vertrekdatum is later dan de laatste vertrekdatum van deze speciale aanbieding';
    break;
   }
  }


  if (errno == 119) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='日期错误，回程日期不能晚于此特价票规定最晚回程日期。';
    break;
	   case 'tw' : 
    err_msg='。';
    break;
   case 'en':
   err_msg='Choose return date is later than the latest return date of this special offer';
    break;
    case 'nl':
   err_msg='Gekozen retourdatum is later dan de laatste retourdatum van deze speciale aanbieding';
    break;
   }
  }


  if (errno == 120) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='停留时间不得超过此特价票规定最长停留时间。';
    break;
	   case 'tw' : 
    err_msg='。';
    break;
   case 'en':
   err_msg='Staying time is longer than the longest staying time permitted by this special offer';
    break;
   case 'nl':
   err_msg='Verblijfsduur is langer dan de toegestaane verblijfsduur van deze specials aanbieding';
    break;
   }
  }
  
    if (errno == 121) {
  switch (v_page_language) {
   case 'cn' : 
    err_msg='停留时间不得少于此特价票规定最短停留时间。';
    break;
	   case 'tw' : 
    err_msg='。';
    break;
   case 'en':
   err_msg='Staying time is shorter than the shortest staying time permitted by this special offer';
    break;
   case 'nl':
   err_msg='Verblijfsduur is korter dan de minimum verblijfsduur van deze speciale aanbieding';
    break;
   }
  }

  alert(err_msg);
   
}


function re_init_dates() {

var v_cities_displayed_cur=0
var v_cities_displayed_max=0;
v_page_language=$("#page_language").val();
var v_days=[];
var v_months=[];
var v_years=[];

for (var teller=1; teller<=31; teller++) {
var v_str_days;
 if (teller < 10 ) {
 	v_str_days='0' + teller;
 }
 else
 {
	v_str_days=teller;
 }
	v_days.push(v_str_days);
}

if ( $("#page_name").val() == "flight" ) 
{

var v_id='day_depart1';
fill_selectbox(v_id,v_days);
var v_id='day_depart2';
fill_selectbox(v_id,v_days);

for (var teller=0; teller<=12; teller++) {
var v_begin_date = new Date();
if (v_begin_date.getDate()>27) {
 v_begin_date_t=v_begin_date.getTime()-60*1000*60*24*5; //set time 5 days back if its after 25th	
 v_begin_date=new Date(v_begin_date_t);
}
 
var v_date = addMonth(v_begin_date,teller);

v_monthnum = v_date.getMonth()+1;

if (v_monthnum < 10 ) {
 v_monthnum='0'+v_monthnum;	
}

v_yearnum = v_date.getFullYear();
 var v_datestring = getCalendarDate(v_date);
 $('#monthyear_depart1').append('<option value="'+v_yearnum+'-'+v_monthnum+'">'+v_datestring+'</option')
 $('#monthyear_depart2').append('<option value="'+v_yearnum+'-'+v_monthnum+'">'+v_datestring+'</option')
}



 var v_ini_depart1_date      =new Date();
 var v_ini_depart2_date      =new Date();
 var v_ini_today = new Date();
 v_ini_depart1_date.setDate(v_ini_today.getDate()+0);											  
 v_ini_depart2_date.setDate(v_ini_today.getDate()+0);
 v_ini_depart1_day=v_ini_depart1_date.getDate();
 v_ini_depart1_month=v_ini_depart1_date.getMonth();
 v_ini_depart1_year=v_ini_depart1_date.getFullYear();
 v_ini_depart1_month=v_ini_depart1_month+1;
 
 if (v_ini_depart1_month < 10 ) {
 v_ini_depart1_month='0'+v_ini_depart1_month;	
 }
 
 if (v_ini_depart1_day < 10 ) {
 v_ini_depart1_day='0'+v_ini_depart1_day;	
 }
 
 v_ini_depart2_day=v_ini_depart2_date.getDate();
 v_ini_depart2_month=v_ini_depart2_date.getMonth();
 v_ini_depart2_year=v_ini_depart2_date.getFullYear();
 v_ini_depart2_month=v_ini_depart2_month+1;
 if (v_ini_depart2_month < 10 ) {
 v_ini_depart2_month='0'+v_ini_depart2_month;	
 }

  if (v_ini_depart2_day < 10 ) {
 v_ini_depart2_day='0'+v_ini_depart2_day;	
 }


 $('#day_depart1').val(v_ini_depart1_day);
 $('#monthyear_depart1').val(v_ini_depart1_year+'-'+v_ini_depart1_month);
 $('#datepicker_depart1').val(v_ini_depart1_year+'-'+v_ini_depart1_month+'-'+v_ini_depart1_day);
 
$('#day_depart2').val(v_ini_depart2_day);
 $('#monthyear_depart2').val(v_ini_depart2_year+'-'+v_ini_depart2_month);
 $('#datepicker_depart2').val(v_ini_depart2_year+'-'+v_ini_depart2_month+'-'+v_ini_depart2_day);
 
 
}  //end of re_init_dates


if ( $("#page_name").val() == "hotel" )  {
 
 var v_id='day_checkin';
 fill_selectbox(v_id,v_days);
 var v_id='day_checkout';
 fill_selectbox(v_id,v_days);
  

for (var teller=0; teller<=12; teller++) {
var v_begin_date = new Date();
if (v_begin_date.getDate()>27) {
 v_begin_date_t=v_begin_date.getTime()-60*1000*60*24*5; //set time 5 days back if its after 25th	
 v_begin_date=new Date(v_begin_date_t);
}
 
var v_date = addMonth(v_begin_date,teller);
 
v_monthnum = v_date.getMonth()+1;

if (v_monthnum < 10 ) {
 v_monthnum='0'+v_monthnum;	
}

v_yearnum = v_date.getFullYear();
 var v_datestring = getCalendarDate(v_date);
 $('#monthyear_checkout').append('<option value="'+v_yearnum+'-'+v_monthnum+'">'+v_datestring+'</option')
 $('#monthyear_checkin').append('<option value="'+v_yearnum+'-'+v_monthnum+'">'+v_datestring+'</option')
}

 

 var v_ini_checkoutdate     =new Date();
 var v_ini_checkindate      =new Date();
 var v_ini_today = new Date();
 v_ini_checkoutdate.setDate(v_ini_today.getDate()+1);											  
 v_ini_checkindate.setDate(v_ini_today.getDate()+0);
 v_ini_checkoutday=v_ini_checkoutdate.getDate();
 v_ini_checkoutmonth=v_ini_checkoutdate.getMonth();

 v_ini_checkoutyear=v_ini_checkoutdate.getFullYear();
 v_ini_checkoutmonth=v_ini_checkoutmonth+1;
 if (v_ini_checkoutmonth < 10 ) {
 v_ini_checkoutmonth='0'+v_ini_checkoutmonth;	
 }
 
 if (v_ini_checkoutday < 10 ) {
 v_ini_checkoutday='0'+v_ini_checkoutday;	
 }
 
 v_ini_checkinday=v_ini_checkindate.getDate();
 v_ini_checkinmonth=v_ini_checkindate.getMonth();
 v_ini_checkinyear=v_ini_checkindate.getFullYear();
 v_ini_checkinmonth=v_ini_checkinmonth+1;
 if (v_ini_checkinmonth < 10 ) {
 v_ini_checkinmonth='0'+v_ini_checkinmonth;	
 }

  if (v_ini_checkinday < 10 ) {
 v_ini_checkinday='0'+v_ini_checkinday;	
 }

 
 $('#day_checkout').val(v_ini_checkoutday);
 $('#monthyear_checkout').val(v_ini_checkoutyear+'-'+v_ini_checkoutmonth);
 $('#datepicker_checkout').val(v_ini_checkoutyear+'-'+v_ini_checkoutmonth+'-'+v_ini_checkoutday);
 
 $('#day_checkin').val(v_ini_checkinday);
 $('#monthyear_checkin').val(v_ini_checkinyear+'-'+v_ini_checkinmonth);
 $('#datepicker_checkin').val(v_ini_checkinyear+'-'+v_ini_checkinmonth+'-'+v_ini_checkinday);
 
			  
	calcNights2('checkin',v_page_language);
	calcNights2('checkout',v_page_language);
	flightWeekdays('depart1',v_page_language);
	flightWeekdays('depart2',v_page_language);

} 

}
