function bookmark(url,title){

      if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
        window.external.AddFavorite(url,title);
      } else if (navigator.appName == "Netscape") {
        window.sidebar.addPanel(title,url,"");
      } else {
        alert("use CTRL+D to bookmark this site.");
      }
      return false;
}

function set_session(session_name,session_val)
{
    $.session(session_name, session_val);
    alert($.session(session_name));
}

function get_base_url()
{
	var base_url;
	var url = location.href.substring(0,location.href.lastIndexOf('/')+1);

	var a = document.createElement("a");
	a.href=url;
	//hide it from view when it is added
	a.style.display="none";//add it
	document.body.appendChild(a);//read the links "features"
	var path = a.pathname.split("/");

	base_url = (a.protocol+'//'+a.hostname+'/');		//server
/*
	if(document.all) //IE
		base_url = (a.protocol+'//'+a.hostname+'/'+path[0]+'/');		//localhost
	else	//FIREFOX
		base_url = (a.protocol+'//'+a.hostname+'/'+path[1]+'/');		//localhost
*/

	return base_url;
}


function getAbsolutePath()
{
    var loc = window.location;
    //var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);

    //var path = loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));
    var arr_path = loc.href.split("/");
    var index = arr_path.length-2;
    if(arr_path[arr_path.length-1]!='' && arr_path[arr_path.length-1]!='#')
        index = arr_path.length-1;

    return arr_path[index];
}

function log_out()
{
	var baseurl = get_base_url();
	var url = baseurl+"tripleasia/logout/";
	$("#div-logout").load(url);
}

function set_cookie_by_currency(symbol,url)
{
     set_cookie_by_value('tripleasia_currencies',symbol);
     //alert( $.cookie("currencies") );
     redirect(url);
}

function set_cookie_lang_cur(iso_name,iso,symbol_name,symbol)
{//alert('cur = '+symbol_name);
        days=1000;

        //name = 'tripleasia_lang';

        $.cookie(iso_name, iso, {expires: days, path: '/'});

        //name = 'tripleasia_currencies';
        if(symbol != '' && symbol_name != '')
	{
            set_cookie_by_value(symbol_name,symbol);
        }
        redirect();
}

function redirect(url){

    TypeofUrl = typeof(url);

    if(TypeofUrl=='undefined'){
        url = location.href.substring(0,location.href.lastIndexOf('')+1);
    }
    var a = document.createElement("a");
    a.href=url;
    //hide it from view when it is added
    a.style.display="none";//add it
    document.body.appendChild(a);//read the links "features"/**/
    if(document.all) //IE
            window.location=a.protocol+'//'+a.hostname+'/'+a.pathname;
    else	//FIREFOX
            window.location=a.protocol+'//'+a.hostname+a.pathname;

}

function set_cookie_by_value(name,data)
{
        //name = 'tripleasia_currencies';
        //alert(data);
	days=1000;

        $.cookie(name, data, {expires: days, path: '/'});
}

function showLang(id,show)
{
        Item = document.getElementById(id);
        if (show)
            Item.style.display='';
        else
            Item.style.display='none';
}


//jQuery
function getHotels() {
    var language = $.cookie('tripleasia_lang');
    var city = $("#city").val();
    var partner = $("#partner").val();
    var css_style = $("#city").attr("class");
    var baseurl = get_base_url();
   $("#div-hotel").load(baseurl+"tripleasia/get-hotels-by-city/", {'city': city, 'partner' : partner, 'language':language, 'css': css_style, 'param': 'getRoomtypes()'});
}

function getHotelsAutoComplete(q)
{
    Typeofq = typeof(q);
    q       = (Typeofq!='undefined') ? q : '';

    if(q.length > 0){
        var baseurl     = get_base_url();
        var language    = $.cookie('tripleasia_lang');

        $.ajax({
            type    : "POST",
            url     : baseurl+"tripleasia/get-search-hotels/",
            data    : "q="+q+"&language="+language,
            success : function(result){
                        $("#search_hotels").removeClass('searchLoader');
                        $('#result-search').addClass('searchbox');
                        $("#result-search").html( result );
                        $('#result-search').show();
                        $("#result-search ul li:first-child").addClass('selected-hotels');
                    }
        });
    }else{
        disableHotelsAutoComplete();
    }
}

function getAreaAutoComplete(q,city_id)
{
    Typeofq = typeof(q);
    q       = (Typeofq!='undefined') ? q : '';

    if(q.length > 0){
        var baseurl     = get_base_url();
        var language    = $.cookie('tripleasia_lang');

        $.ajax({
            type    : "POST",
            url     : baseurl+"tripleasia/get-search-area/",
            data    : "city_id="+city_id+"&q="+q+"&language="+language,
            success : function(result){
                        $("#area_text").removeClass('searchLoader');
                        $('#result-search-area').addClass('searchbox');
                        $("#result-search-area").html( result );
                    }
        });
    }else{
        disableAreaAutoComplete();
    }
}

function disableHotelsAutoComplete()
{
    $('#result-search').hide();
    $("#search_hotels").removeClass('searchLoader');
    $('#result-search').removeClass('searchbox');
    setTimeout(function(){
        $("#result-search").children().remove();
    }, 200);
}

function disableAreaAutoComplete()
{
    setTimeout(function(){
        $("#area_text").removeClass('searchLoader');
        $('#result-search-area').removeClass('searchbox');
        $("#result-search-area").children().remove();
    }, 50);

}

function get_data_from_search_hotels(detected_str, hotels_id, country_id, city_id, area_id, getClass, hotels_path)
{
        $('#search_hotels').attr('class', getClass + ' searchSelectedOption');
        $('#search_hotels').val(detected_str);

        $('#hotels_path').val(hotels_path);
        $('#hotels_id').val(hotels_id);
        $('#country_id').val(country_id);
        $('#city_id').val(city_id);
        $('#area_id').val(area_id);

        disableHotelsAutoComplete();
}

function get_data_from_search_area(detected_str, area_id)
{
    $('#area_text').val(detected_str);
    $('#area_id').val(area_id);

    disableAreaAutoComplete();
}

function getArea() {
    var language = $.cookie('tripleasia_lang');
    var action = 'getHotels()';
    var city = $("#city").val();
    var css_style = $("#city").attr("class");
    var baseurl = get_base_url();

   $("#div-area").load(baseurl+"tripleasia/get-area-by-city/", {'city': city, 'language':language, 'css': css_style, 'param': action});
}

function getCountry() {
    var language = $.cookie('tripleasia_lang');
    var region = $("#region").val();
    var css_style = $("#region").attr("class");
    var baseurl = get_base_url();

    $("#div-country").load(baseurl+"tripleasia/get-country-by-region/", {'region': region, 'language':language, 'css': css_style, 'param': 'getCity()'});
}

function getCity() {
    var language = $.cookie('tripleasia_lang');
    var action = 'getHotels()';
    var country = $("#country").val();
    var css_style = $("#country").attr("class");
    var baseurl = get_base_url();

    $("#div-city").load(baseurl+"tripleasia/get-city-by-country/", {'country': country, 'language':language, 'css': css_style, 'param': action});
}

function getRoomtypes() {
    var hotel = $('#hotel').val();
    var partner = $('#partner').val();
    var css_style = $("#hotel").attr("class");
    var baseurl = get_base_url();

    $("#div-roomtype").load(baseurl+"tripleasia/get-roomtypes-by-hotels/", {'hotel': hotel,'partner': partner, 'css': css_style});
}

function searchHotelsBox() {
    var resultBox   = $('div#result-search').html();
    var searchText  = $('#search_hotels').val();

    if(resultBox!=''){
        return false;
    }
    if(searchText==''){
        alert("Please search and choose result");
        return false;
    }else{
        $("#hotels_form").submit();
        return true;
    }
}

function searchToursBox() {
    var country = $("#country").val();
    var inspriration = $("#inspriration").val();
    var duration = $("#duration").val();
    //var baseurl = get_base_url();

    if ((country == null || country == '') && (inspriration == null || inspriration == '') && (duration == null || duration == '')) {
        alert("Please select filter.");
        return false;
    }

    $("#tours_form").submit();
    return true;
}

function searchIdeasBox() {
    var form_action = $("#form_action").val();
    var baseurl = get_base_url();

    $("#ideas_form").attr("action", baseurl+"triple-ideas/inspirations/"+form_action);
    $("#ideas_form").submit();
    return true;
}

function chg_action(data){
    $("#form_action").val(data);
}

function accessMyaccount() {
    $("#login_form").submit();
}

//BEGIN : delete last viewed
function delete_last_viewed(last_viewed_id, show_all)
{
    var baseurl             = get_base_url();
    var last_viewed         = $.cookie("tripleasia_last_viewed");
    var arr_last_viewed     = last_viewed.split(',');
    var last_viewed_change  = '';
    $.each(arr_last_viewed,function(key,value){

        if(value!=last_viewed_id && value!='')
            last_viewed_change += value+',';

    })
    $.cookie("tripleasia_last_viewed", last_viewed_change, {expires: 0, path: '/'});

    $("#div-show-last-viewed").load(baseurl+"hotels/show-last-viewed/",{'show_all' : show_all});
    return false;
}

function clear_last_viewed()
{
    var date = new Date();
    date.setTime(date.getTime());

    $.cookie("tripleasia_last_viewed", null, {path: '/'});

    $("#lastViewed_box").remove();
    return false;
}

function show_all_last_viewed(show_all)
{
    var baseurl = get_base_url();
    $("#div-show-last-viewed").load(baseurl+"hotels/show-last-viewed/",{'show_all' : show_all});
    return false;
}
//END : delete last viewed

//Begin : Hotels photo
//$("#hotel-photo-thumb").click(function(){
function change_photo(picture_path)
{
    var baseurl = get_base_url();
    //alert('<img src="'+baseurl+picture_path+'">');
    $("#img-gallery").html('<img src="'+picture_path+'" width="241" height="181">');
}
//});
//End : Hotels photo

function search_roomtypes()
{
        var check_in = $("#check_in").val();
        var check_out = $("#check_out").val();
        var room = $("#room").val();
        var adult = $("#adult").val();
        var child = $("#child").val();

        $("#div-roomtype-list").html("loading...");
        $("#div-roomtype-list").load(baseurl+"hotels/hotel-roomtypes-search-result/", {'action': 'search','check_in': check_in,'check_out':check_out,'room': room,'adult': adult,'child': child});

}

function hotelsBooking(id) {
    $("#hotels_booking_form"+id).submit();
}

function step_booking_hotels(step_booking,step_origin)
{
    //Begin : hotel booking step
        var ContractName        = $('input[name="ContractName"]').val();
        var SHRUI               = $('input[name="SHRUI"]').val();
        var RTcharacteristic    = $('input[name="RTcharacteristic"]').val();
        var RTtype              = $('input[name="RTtype"]').val();
        var RTcode              = $('input[name="RTcode"]').val();
        var Boardtype           = $('input[name="Boardtype"]').val();
        var Boardcode           = $('input[name="Boardcode"]').val();
        var IncomingOffice      = $('input[name="IncomingOffice"]').val();

        var hotel_id            = $('input[name="hotel_id"]').val();
        var partners_id         = $('input[name="partners_id"]').val();
        //var check_in            = $('input[name="check_in"]').val();
        //var check_out           = $('input[name="check_out"]').val();
        //var night               = $('input[name="night"]').val();
        var room                = $('input[name="room"]').val();
        //var pax_adult           = $('input[name="pax_adult"]').val();
        //var pax_child           = $('input[name="pax_child"]').val();
        var grand_total         = $('input[name="grand_total"]').val();
        var title               = ((step_origin)? ((step_booking == 2)? $('select[name="title"] option:selected').val():$('input[name="title"]').val()):$('input[name="title"]').val());
        var first_name          = $('input[name="first_name"]').val();
        var last_name           = $('input[name="last_name"]').val();
        var email_address       = $('#div-hotels-booking input[name="email_address"]').val();
        var confirm_email_address = $('input[name="confirm_email_address"]').val();
        var zipcode             = $('input[name="zipcode"]').val();
        var address             = ((step_origin)? ((step_booking == 2)? $('textarea[name="address"]').val():$('input[name="address"]').val()):$('input[name="address"]').val());
        var city                = ((step_origin)? ((step_booking == 2)? $('select[name="city"] option:selected').val():$('input[name="city"]').val()):$('input[name="city"]').val());
        var country             = ((step_origin)? ((step_booking == 2)? $('select[name="country"] option:selected').val():$('input[name="country"]').val()):$('input[name="country"]').val());
        var telephone           = $('input[name="telephone"]').val();
        var passport_no         = $('input[name="passport_no"]').val();
        var arrival_no          = $('input[name="arrival_no"]').val();
        var arrival_time        = $('input[name="arrival_time"]').val();//((step_origin)? ((step_booking == 2)? $('select[name="arrival_time"] option:selected').val():$('input[name="arrival_time"]').val()):$('input[name="arrival_time"]').val());
        var departure_no        = $('input[name="departure_no"]').val();
        var departure_time      = $('input[name="departure_time"]').val();//((step_origin)? ((step_booking == 2)? $('select[name="departure_time"] option:selected').val():$('input[name="departure_time"]').val()):$('input[name="departure_time"]').val());
//        var travel_type = ((step_origin)? ((step_booking == 2)? $('input:radio[name=travel_type]:checked').val():$('input[name="travel_type"]').val()):$('input[name="travel_type"]').val());//$('input:radio[name=travel_type]:checked').val()//$('input[name="travel_type"]').val();
//        var newsletter = ((step_origin)? ((step_booking == 2)? $('input:checkbox[name=newsletter]:checked').val():$('input[name="newsletter"]').val()):$('input[name="newsletter"]').val());//$('input[name="newsletter"]').val();

        var h_titlename         = new Array();
        var h_firstname         = new Array();
        var h_lastname          = new Array();
        var h_email_address     = new Array();
        var h_telephone         = new Array();
        var h_special_request   = new Array();

	for(var i = 0; i < room; i++){
            h_titlename[i]      = ((step_booking != 2)? (($('select[name="h_titlename['+i+']"] option:selected').val()!='' && $('select[name="h_titlename['+i+']"] option:selected').val())? $('select[name="h_titlename['+i+']"] option:selected').val():$('input[name="h_titlename['+i+']"]').val()):$('input[name="h_titlename['+i+']"]').val());
            h_firstname[i]      = $('input[name="h_firstname['+i+']"]').val();
            h_lastname[i]       = $('input[name="h_lastname['+i+']"]').val();
            h_email_address[i]  = $('input[name="h_email_address['+i+']"]').val();
            h_telephone[i]      = $('input[name="h_telephone['+i+']"]').val();
            h_special_request[i] = ((step_booking != 2)?  (($('textarea[name="h_special_request['+i+']"]').val()=='' || $('textarea[name="h_special_request['+i+']"]').val())? $('textarea[name="h_special_request['+i+']"]').val():$('input[name="h_special_request['+i+']"]').val()):$('input[name="h_special_request['+i+']"]').val());//$('input[name="special_requests"]').val();
        }

            var baseurl         = get_base_url();

        $("#div-hotels-booking").load(baseurl+"hotels-booking/change-hotels-step-booking/", {
            'action'            : 'search',
            'step_booking'      : step_booking,

            'ContractName'      :ContractName,
            'SHRUI'             : SHRUI,
            'RTcharacteristic'  : RTcharacteristic,
            'RTtype'            : RTtype,
            'RTcode'            : RTcode,
            'Boardtype'         : Boardtype,
            'Boardcode'         : Boardcode,
            'IncomingOffice'    : IncomingOffice,

            'hotel_id'          : hotel_id,
            'partners_id'       : partners_id,
            //'check_in'          : check_in,
            //'check_out'         : check_out,
            //'night'             : night,
            //'room'              : room,
            //'pax_adult'         : pax_adult,
            //'pax_child'         : pax_child,
            'grand_total'       : grand_total,
            'title'             : title,
            'first_name'        : first_name,
            'last_name'         : last_name,
            'email_address'     : email_address,
            'confirm_email_address': confirm_email_address,
            'zipcode'           : zipcode,
            'address'           : address,
            'city'              : city,
            'country'           : country,
            'passport_no'       : passport_no,
            'arrival_no'        : arrival_no,
            'arrival_time'      : arrival_time,
            'departure_no'      : departure_no,
            'departure_time'    : departure_time,
            'telephone'         : telephone,
//                    'travel_type': travel_type,
//                    'newsletter': newsletter,
            'h_titlename[]'     : h_titlename,
            'h_firstname[]'     : h_firstname,
            'h_lastname[]'      : h_lastname,
            'h_email_address[]' : h_email_address,
            'h_telephone[]'     : h_telephone,
            'h_special_request[]': h_special_request
        },function(){
            if($('#div-hotels-booking').parent().hasClass('step_box1')){
                var changeHeight    = $('#div-hotels-booking').height();
                $('#div-hotels-booking').parent().css('height',changeHeight+'px');
            }
            $("#id-step-booking").html(step_booking);
        });
        
    //End : hotel booking step
}

function hotels_booking()
{
    var ContractName        = $('input[name="ContractName"]').val();
    var SHRUI               = $('input[name="SHRUI"]').val();
    var RTcharacteristic    = $('input[name="RTcharacteristic"]').val();
    var hotel_id            = $('input[name="hotel_id"]').val();
    var partners_id         = $('input[name="partners_id"]').val();
    var check_in            = $('input[name="check_in"]').val();
    var check_out           = $('input[name="check_out"]').val();
    var night               = $('input[name="night"]').val();
    var room                = $('input[name="room"]').val();
    var pax_adult           = $('input[name="pax_adult"]').val();
    var pax_child           = $('input[name="pax_child"]').val();
    var grand_total         = $('input[name="grand_total"]').val();
    var title               = $('input[name="title"]').val();
    var first_name          = $('input[name="first_name"]').val();
    var last_name           = $('input[name="last_name"]').val();
    var email_address           = $('input[name="email_address"]').val();
    var confirm_email_address   = $('input[name="confirm_email_address"]').val();
    var zipcode                 = $('input[name="zipcode"]').val();
    var address             = $('input[name="address"]').val();
    var city                = $('input[name="city"]').val();
    var country             = $('input[name="country"]').val();
    var telephone           = $('input[name="telephone"]').val();
    var passport_no         = $('input[name="passport_no"]').val();
    var arrival_no          = $('input[name="arrival_no"]').val();
    var arrival_time        = $('input[name="arrival_time"]').val();
    var departure_no        = $('input[name="departure_no"]').val();
    var departure_time      = $('input[name="departure_time"]').val();
//    var travel_type = $('input[name="travel_type"]').val();//$('input:radio[name=travel_type]:checked').val()//$('input[name="travel_type"]').val();
//    var newsletter = $('input[name="newsletter"]').val();//$('input[name="newsletter"]').val();
    /*
    var title_step2 = $('input[name="title_step2[]"]').val();
    var first_name_step2 = $('input[name="first_name_step2[]"]').val();
    var last_name_step2 = $('input[name="last_name_step2[]"]').val();
    var email_address_step2 = $('input[name="email_address_step2[]"]').val();
    var telephone_step2 = $('input[name="telephone_step2[]"]').val();
    var special_requests = $('input[name="special_requests[]"]').val();//$('input[name="special_requests"]').val();
     */
    //alert($('textarea[name="special_requests"]').val());//special_requests = (special_requests == 'undefined')? special_requests:'';
//alert(step_booking+'---'+special_requests);
    var h_titlename         = new Array();
    var h_firstname         = new Array();
    var h_lastname          = new Array();
    var h_email_address     = new Array();
    var h_telephone         = new Array();
    var h_special_request   = new Array();

    var max_record = room;
    for(var i = 0; i < max_record; i++)
    {
        h_titlename[i]      = ((step_booking != 2)? (($('select[name="h_titlename['+i+']"] option:selected').val()!='' && $('select[name="h_titlename['+i+']"] option:selected').val())? $('select[name="h_titlename['+i+']"] option:selected').val():$('input[name="h_titlename['+i+']"]').val()):$('input[name="h_titlename['+i+']"]').val());
        h_firstname[i]      = $('input[name="h_firstname['+i+']"]').val();
        h_lastname[i]       = $('input[name="h_lastname['+i+']"]').val();
        h_email_address[i]  = $('input[name="h_email_address['+i+']"]').val();
        h_telephone[i]      = $('input[name="h_telephone['+i+']"]').val();
        h_special_request[i]= ((step_booking != 2)?  (($('textarea[name="h_special_request['+i+']"]').val()=='' || $('textarea[name="h_special_request['+i+']"]').val())? $('textarea[name="h_special_request['+i+']"]').val():$('input[name="h_special_request['+i+']"]').val()):$('input[name="h_special_request['+i+']"]').val());//$('input[name="special_requests"]').val();
        //alert($('textarea[name="special_requests"]').val());//special_requests = (special_requests == 'undefined')? special_requests:'';
    //alert(step_booking+'---'+special_requests);
        //alert($('select[name="title_step2['+i+']"] option:selected').val());
    }


    //alert(step_booking);
    /*var check_in = $("#check_in").val();
    var check_out = $("#check_out").val();
    var room = $("#room").val();
    var adult = $("#adult").val();
    var child = $("#child").val();
    var hotel_id = $("#hotel_id").val();*/
    var baseurl = get_base_url();
    //$("#div-hotels-booking").html("loading...");
//alert(baseurl+"hotels/insert-hotel-guest-records/");
    $.post(baseurl+"hotels-booking/insert-hotel-guest-records/", {
        'action': 'search',
        /*'step_booking': step_booking,*/
        'ContractName'      :ContractName,
        'SHRUI'             : SHRUI,
        'RTcharacteristic'  : RTcharacteristic,
        'hotel_id'          : hotel_id,
        'partners_id'       : partners_id,
        'check_in'          : check_in,
        'check_out'         : check_out,
        'night'             : night,
        'room'              : room,
        'pax_adult'         : pax_adult,
        'pax_child'         : pax_child,
        'grand_total'       : grand_total,
        'title'             : title,
        'first_name'        : first_name,
        'last_name'         : last_name,
        'email_address'     : email_address,
        'confirm_email_address' : confirm_email_address,
        'zipcode'               : zipcode,
        'address'               : address,
        'city'                  : city,
        'country'               : country,
        'passport_no'           : passport_no,
        'arrival_no'            : arrival_no,
        'arrival_time'          : arrival_time,
        'departure_no'          : departure_no,
        'departure_time'        : departure_time,
        'telephone'             : telephone,
//        'travel_type': travel_type,
//        'newsletter': newsletter,
        'h_titlename[]'         : h_titlename,
        'h_firstname[]'         : h_firstname,
        'h_lastname[]'          : h_lastname,
        'h_email_address[]'     : h_email_address,
        'h_telephone[]'         : h_telephone,
        'h_special_request[]'   : h_special_request});
    //document.sendform.submit();
    return false;
}


function change_tabs(this_tab)
{
    var baseurl     = get_base_url();
    var boxHeight   = '';
    var contentBox  = '';
    var hotels_name = getAbsolutePath();
    var book_sbox1  = $('#tabs').parent().parent().next();
    var hotels_id   = $('#detail_hotels-roomtypes #hotel_id').val();

    $('div.mainboxbooking').css('margin-bottom','5px;');

    if(book_sbox1.hasClass('book_sbox1')){
        book_sbox1.css('height','auto');
    }

    if(hotels_id){
        update_user_online(hotels_id);
    }

    switch(this_tab){
        
        case 'hotels-description':
            $("#hotels-description").hide();
            $("#hotels-useful").hide();
            $("#hotels-observation").hide();
            $("ul.hotels-description").attr('class','hotels-description b_descript_on');
            $("ul.hotels-useful").attr('class','hotels-useful b_descript');
            $("ul.hotels-observation").attr('class','hotels-observation b_descript');

            $("#hotels-description").show();
        break;

        case 'hotels-useful':
            $("#hotels-description").hide();
            $("#hotels-useful").hide();
            $("#hotels-observation").hide();
            $("ul.hotels-description").attr('class','hotels-description b_descript');
            $("ul.hotels-useful").attr('class','hotels-useful b_descript_on');
            $("ul.hotels-observation").attr('class','hotels-observation b_descript');

            $("#hotels-useful").show();
        break;

        case 'hotels-observation':
            $("#hotels-description").hide();
            $("#hotels-useful").hide();
            $("#hotels-observation").hide();
            $("ul.hotels-description").attr('class','hotels-description b_descript');
            $("ul.hotels-useful").attr('class','hotels-useful b_descript');
            $("ul.hotels-observation").attr('class','hotels-observation b_descript_on');

            $("#hotels-observation").show();
        break;

        case 'make-a-booking':
            $("#make-a-booking").show();
            $("#hotel-description").hide();
            $("#hotel-facilities").hide();
            $("#hotel-location").hide();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").hide();
            $(".make-a-booking").attr('class','make-a-booking tab_selected');
            $(".hotel-description").attr('class','hotel-description');
            $(".hotel-facilities").attr('class','hotel-facilities');
            $(".hotel-location").attr('class','hotel-location');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery');
            $(".guest-reviews").attr('class','guest-reviews');

            if($.trim($("#make-a-booking").text()) == ''){
                $("#make-a-booking").load(baseurl+"hotels/hotels-load-tabs/", {
                    'tabs_load':'make-a-booking',
                    'hotels_name': hotels_name
                }, function() {
                    boxHeight   = $('div#make-a-booking').height();
                    contentBox  = $('div.mainboxbooking');

                    contentBox.css('height',(boxHeight+160)+'px');
                });
            }else{
                boxHeight   = $('div#make-a-booking').height();
                contentBox  = $('div.mainboxbooking');

                contentBox.css('height',(boxHeight+160)+'px');
            }

        break;

        case 'description':
            $("#make-a-booking").hide();
            $("#hotel-description").show();
            $("#hotel-facilities").hide();
            $("#hotel-location").hide();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").hide();
            $(".make-a-booking").attr('class','make-a-booking');
            $(".hotel-description").attr('class','hotel-description tab_selected');
            $(".hotel-facilities").attr('class','hotel-facilities');
            $(".hotel-location").attr('class','hotel-location');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery');
            $(".guest-reviews").attr('class','guest-reviews');

            if($.trim($("#hotel-description").text()) == ''){
                $("#hotel-description").load(baseurl+"hotels/hotels-load-tabs/", {
                    'tabs_load':'hotel-description',
                    'hotels_name': hotels_name
                }, function() {
                    boxHeight   = $('div#hotel-description').height();
                    contentBox  = $('div.mainboxbooking');

                    contentBox.css('height',(boxHeight+160)+'px');
                });
            }else{
                boxHeight   = $('div#hotel-description').height();
                contentBox  = $('div.mainboxbooking');

                contentBox.css('height',(boxHeight+160)+'px');
            }

        break;

        case 'facilities':
            $("#make-a-booking").hide();
            $("#hotel-description").hide();
            $("#hotel-facilities").show();
            $("#hotel-location").hide();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").hide();
            $(".make-a-booking").attr('class','make-a-booking');
            $(".hotel-description").attr('class','hotel-description');
            $(".hotel-facilities").attr('class','hotel-facilities tab_selected');
            $(".hotel-location").attr('class','hotel-location');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery');
            $(".guest-reviews").attr('class','guest-reviews');

            if($.trim($("#hotel-facilities").text()) == ''){
                $("#hotel-facilities").load(baseurl+"hotels/hotels-load-tabs/", {
                    'tabs_load':'hotel-facilities',
                    'hotels_name': hotels_name
                }, function() {
                    boxHeight   = $('div#hotel-facilities').height();
                    contentBox  = $('div.mainboxbooking');

                    contentBox.css('height',(boxHeight+160)+'px');
                });
            }else{
                boxHeight   = $('div#hotel-facilities').height();
                contentBox  = $('div.mainboxbooking');

                contentBox.css('height',(boxHeight+160)+'px');
            }

        break;

        case 'location':
            $("#make-a-booking").hide();
            $("#hotel-description").hide();
            $("#hotel-facilities").hide();
            $("#hotel-location").show();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").hide();
            $(".make-a-booking").attr('class','make-a-booking');
            $(".hotel-description").attr('class','hotel-description');
            $(".hotel-facilities").attr('class','hotel-facilities');
            $(".hotel-location").attr('class','hotel-location tab_selected');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery');
            $(".guest-reviews").attr('class','guest-reviews');

            if($.trim($("#hotel-location").text()) == ''){
                $("#hotel-location").load(baseurl+"hotels/hotels-load-tabs/", {
                    'tabs_load':'hotel-location',
                    'hotels_name': hotels_name
                }, function() {
                    boxHeight   = $('div#hotel-location').height();
                    contentBox  = $('div.mainboxbooking');

                    contentBox.css('height',(boxHeight+160)+'px');
                });
            }else{
                boxHeight   = $('div#hotel-location').height();
                contentBox  = $('div.mainboxbooking');

                contentBox.css('height',(boxHeight+160)+'px');
            }

        break;

        case 'gallery':
            $("#make-a-booking").hide();
            $("#hotel-description").hide();
            $("#hotel-facilities").hide();
            $("#hotel-location").hide();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").hide();
            $(".make-a-booking").attr('class','make-a-booking');
            $(".hotel-description").attr('class','hotel-description');
            $(".hotel-facilities").attr('class','hotel-facilities');
            $(".hotel-location").attr('class','hotel-location');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery tab_selected');
            $(".guest-reviews").attr('class','guest-reviews');

            $("#hotel-photo-gallery").show();

            boxHeight   = $('div.book_sbox_content div#hotel-photo-gallery').height();
            contentBox  = $('div.mainboxbooking');

            contentBox.css('height',(boxHeight+160)+'px');
            
        break;

        case 'reviews':
            $("#make-a-booking").hide();
            $("#hotel-description").hide();
            $("#hotel-facilities").hide();
            $("#hotel-location").hide();
            $("#hotel-photo-gallery").hide();
            $("#guest-reviews").show();
            $(".make-a-booking").attr('class','make-a-booking');
            $(".hotel-description").attr('class','hotel-description');
            $(".hotel-facilities").attr('class','hotel-facilities');
            $(".hotel-location").attr('class','hotel-location');
            $(".hotel-photo-gallery").attr('class','hotel-photo-gallery');
            $(".guest-reviews").attr('class','guest-reviews tab_selected');

            if($.trim($("#guest-reviews").text()) == ''){
                $("#guest-reviews").load(baseurl+"hotels/hotels-load-tabs/", {
                    'tabs_load':'guest-reviews',
                    'hotels_name': hotels_name
                }, function() {
                    boxHeight   = $('div#guest-reviews').height();
                    contentBox  = $('div.mainboxbooking');
                    
                    contentBox.css('height',(boxHeight+160)+'px');
                });
            }else{
                boxHeight   = $('div#guest-reviews').height();
                contentBox  = $('div.mainboxbooking');

                contentBox.css('height',(boxHeight+160)+'px');
            }

        break;
    }
}

function get_hotel_list(){

    var url         = location.href.substring(0,location.href.lastIndexOf('/')+1);
    var a           = document.createElement("a");
    a.href          = url;
    a.style.display = "none";

    document.body.appendChild(a);

    var path        = a.pathname.split("/");

    var baseurl     = get_base_url();
    var top_5       = (path[2]=='hotels-search-result') ? 1 : 0;

    var currencies  = $("select#currencies").val();
    var sort_by     = $("select#sort_by").val();
    var country_id  = $("#country_id").val();
    var city_id     = $("#city_id").val();
    var area_id     = $("#area_id").val();
    var check_in    = $("#check_in").val();
    var night       = $("select#night").val();
    var check_out   = $("#check_out").val();
    var room        = $("select#room").val();
    var NewGuestList    = {};

    var G = '';
    for(G=0;G<room;G++){
        NewGuestList[G] = {
            adult : $('SELECT[name="GuestList['+G+'][adult]"]').val(),
            child : $('SELECT[name="GuestList['+G+'][child]"]').val()
        }
    }

    //var adult       = $("select#adult").val();
    //var child       = $("select#child").val();

    $("#hotels-result").css('opacity',0.2);
    set_cookie_by_value('tripleasia_currencies',currencies);//set_cookie_lang_cur('tripleasia_lang', lang, 'tripleasia_currencies', currencies);
    $("#hotels-result").load(baseurl+"hotels/hotels-search-result/", {
        'action'    : 'search',
        'vaction'   : 'sort',
        'sort_by'   : sort_by,
        'top_5'     : top_5,
        'country_id': country_id,
        'city_id'   : city_id,
        'area_id'   : area_id,
        'check_in'  : check_in,
        'night'     : night,
        'check_out' : check_out,
        'room'      : room,
        'GuestList' : NewGuestList
        //'adult'     : adult,
        //'child'     : child
    }, function() {
        $("#hotels-result").css('opacity',1);
    });
}

function default_dropdown(field_id)
{
    var defualt_txt = $('#df_txt-'+field_id).text();
    var css_class   = $('#'+field_id).attr('class');
    var field       = $('#'+field_id).attr('name');
    return $('#div-'+field_id+'').html('<select class="'+css_class+'" id="'+field_id+'" name="'+field+'"><option selected="selected" value="">'+defualt_txt+'</option></select>');
}

function change_country(title_field)
{
    var title_field_    = '';
    title_field         = (typeof(title_field) != 'undefined') ? title_field : '';
    title_field_        = title_field+'_';
    title_field_        = (title_field_=='_') ? '' : title_field_;

    ($('#'+title_field_+'country_id').val()) ? getCity(title_field) : default_dropdown(title_field_+'city_id');

    default_dropdown(title_field_+'area_id');
    default_dropdown(title_field_+'hotels_id');
    default_dropdown(title_field_+'usefuls_id');
}

function change_city(title_field)
{
    var city_id = $('#city_id').val();

    $('#div-area').show();
    $('#div-area #area_text').val('');
    $('#div-area #area_id').val('');

    if(city_id==''){
        $('#div-area #area_text').attr('disabled','disabled');
    }else{
        $('#div-area #area_text').removeAttr('disabled');
    }
}

function getCity(title_field)
{
    var title_field_    = '';
    title_field         = (typeof(title_field) != 'undefined') ? title_field : '';
    title_field_        = title_field+'_';
    title_field_        = (title_field_=='_') ? '' : title_field_;

    var baseurl = get_base_url();
    var language    = $.cookie('tripleasia_lang');
    var country     = $('#'+title_field_+'country_id').val();
    var css_style   = $('#'+title_field_+'city_id').attr("class");
    var field       = $('#'+title_field_+'city_id').attr("name");

    $('#div-'+title_field_+'city_id').load(baseurl+"tripleasia/get-city-by-country/", {"language":language, "country": country, "css": css_style, "param": "change_city('"+title_field+"')", 'field' : field});
}

function check_AvailableRoom(){
    $("div#alert-room").dialog({
        modal: true,
        width: 700,
        buttons:[
                    {
                        text: "Go",
                        click: function() {
                                    var checked  = $("[name=alertroom]:checked").val();
                                    var form     = $("#alert-room form");
                                    if(checked!='search'){
                                        $(this).dialog("close");
                                        scrollTo('detail_hotels-roomtypes');
                                    }else{
                                        form.submit();
                                    }
                               }
                    }
                ]
    });
    $(".button-L").text('');
    $(".button-R").text('');
}

function scrollTo(selector_id){
    $('html,body').animate({
        scrollTop: $("#"+selector_id).offset().top
    }, 300);
}

function user_online(hotels_id){
    var baseurl     = get_base_url();

    $.ajax({
        type    : "POST",
        url     : baseurl+"tripleasia/store-online-user/",
        data    : "hotels_id="+hotels_id,
        success : function(insert_id){
                    get_user_online(hotels_id);
                    $(window).unload(function(){
                        delete_user_online(insert_id,hotels_id);
                    });
                }
    });
}

function update_user_online(hotels_id){
    var baseurl     = get_base_url();

    $.ajax({
        type    : "POST",
        url     : baseurl+"tripleasia/store-online-user/",
        data    : "hotels_id="+hotels_id,
        success : function(insert_id){
                    $(window).unload(function(){
                        delete_user_online(insert_id,hotels_id);
                    });
                }
    });
}

function get_user_online(hotels_id){
    var baseurl     = get_base_url();

        $.ajax({
            type    : "POST",
            url     : baseurl+"tripleasia/get-who-online/",
            data    : "hotels_id="+hotels_id,
            success : function(count_user){
                        var delay = (function(){
                            var timer = 0;
                            return function(callback, ms){
                                clearTimeout (timer);
                                timer = setTimeout(callback, ms);
                            };
                        })();

                        $('#userOnline_box #text-userOnline #user-text #user-count').text(count_user);
                        $('#userOnline_box').animate({opacity:1 , bottom: '10px'}, 700);

                        delay(function(){
                            $('#userOnline_box').animate({opacity:0 , bottom: '-135px'}, 700);
                        }, 7000 );
                    }
        });
}

function delete_user_online(insert_id,hotels_id){
    var baseurl     = get_base_url();
    var id          = insert_id;

    $.post(baseurl+"tripleasia/delete-who-online/", {"id":id, "hotels_id":hotels_id});
}

function goToPath(path)
{
    window.location = path;
}

function dateDiff(date1,date2){
    //dd-mm-yyyy
    date1           = date1.split("-");
    date2           = date2.split("-");

    var sDate       = new Date(date1[2],date1[1]-1,date1[0]);
    var eDate       = new Date(date2[2],date2[1]-1,date2[0]);
    var daysDiff    = Math.round((eDate-sDate)/86400000);

    return daysDiff;
}

function SearchOnChoice($this,getClass){
    $("#result-search ul li").removeClass('selected-hotels');
    $this.className=getClass+' selected-hotels';
}

function changeStepBooking(){
    var step_booking = $('input[name="step_booking"]').val();
    step_booking_hotels(step_booking,true);
}

function SearchAvailableRoom(){
    var language        = $.cookie('tripleasia_lang');
    var baseurl         = get_base_url();
    var country_id      = $("#country_id").val();
    var city_id         = $("#city_id").val();
    var area_id         = $("#area_id").val();
    var hotel_id        = $("#hotel_id").val();
    var check_in        = $("#check_in").val();
    var check_out       = $("#check_out").val();
    var room            = $("#room").val();
    var night           = $("#night").val();
    var NewGuestList    = {};

    var G = '';
    for(G=0;G<room;G++){
        NewGuestList[G] = {
            adult : $('SELECT[name="GuestList['+G+'][adult]"]').val(),
            child : $('SELECT[name="GuestList['+G+'][child]"]').val()
        }
    }

    $("#div-roomtype-list").css('opacity',0.2);
    $("#div-roomtype-list").load(baseurl+"hotels/hotel-roomtypes-search-result/", {
        'language'  : language,
        'action'    : 'search',
        'country_id': country_id,
        'city_id'   : city_id,
        'area_id'   : area_id,
        'hotel_id'  : hotel_id,
        'check_in'  : check_in,
        'check_out' : check_out,
        'room'      : room,
        'night'     : night,
        'GuestList' : NewGuestList

    }, function() {
        $("#div-roomtype-list").css('opacity',1);
    });
}

function getCancellationPolicy(POST){
    var baseurl         = get_base_url();

    $.fancybox.showActivity();
    $.ajax({
        type        : "POST",
        cache       : false,
        url         : baseurl+"hotels-booking/get-cancellation-policy/"+POST['roomTypeNo'],
        data        : POST,
        success     : function(data) {
            $.fancybox(data);
        }
    });
}

function getSummaryBooking(){
    var baseurl         = get_base_url();

    var form            = $('#hotels_booking_form');

    var hotel_id        = form.children('INPUT[name="hotel_id"]').val();
    var country_id      = form.children('INPUT[name="country_id"]').val();
    var city_id         = form.children('INPUT[name="city_id"]').val();
    var room            = form.children('INPUT[name="room"]').val();

    var AvailToken      = $('INPUT[name="AvailToken"]').val();
    var IncomingOffice  = form.children('INPUT[name="IncomingOffice"]').val();
    var RTtype          = form.children('INPUT[name="RTtype"]').val();
    var RTcode          = form.children('INPUT[name="RTcode"]').val();
    var Boardtype       = form.children('INPUT[name="Boardtype"]').val();
    var Boardcode       = form.children('INPUT[name="Boardcode"]').val();
    var ContractName    = form.children('INPUT[name="ContractName"]').val();
    var SHRUI           = form.children('INPUT[name="SHRUI"]').val();
    var RTcharacteristic= form.children('INPUT[name="RTcharacteristic"]').val();

    $('DIV#booking-summary-content').load(baseurl+"hotels-booking/hotels-booking-summary/", {
        'hotel_id'        : hotel_id,
        'country_id'      : country_id,
        'city_id'         : city_id,
        'room'            : room,

        'AvailToken'      : AvailToken,
        'IncomingOffice'  : IncomingOffice,
        'RTtype'          : RTtype,
        'RTcode'          : RTcode,
        'Boardtype'       : Boardtype,
        'Boardcode'       : Boardcode,
        'ContractName'    : ContractName,
        'SHRUI'           : SHRUI,
        'RTcharacteristic': RTcharacteristic
    });
}

$(document).ready(function(){
    getSummaryBooking();

    //LOAD Social Network Box//
    var baseurl = get_base_url();
    var url     = location.href.substring(0,location.href.lastIndexOf('/')+1);
    $("#div-social-box").text('loading...');
    $("#div-social-box").load(baseurl+"tripleasia/create_social_network/", {'url_share': url});

    $(document).scroll(function() {
        if($(document).scrollTop() > 600){
            var hotels_list = $('div.city_list ul').find('li[class="hideList"]');
            hotels_list.removeAttr('class');
            hotels_list.animate({opacity: 1}, 1000);
        }
    });

    var delay = (function(){
        var timer = 0;
        return function(callback, ms){
            clearTimeout (timer);
            timer = setTimeout(callback, ms);
        };
    })();

    var hotels_id   = $('#detail_hotels-roomtypes #hotel_id').val();

    if(hotels_id){
        delay(function(){
            /*if($('#div-roomtype-list ul li').length <= 0){
                check_AvailableRoom();
            }*/
            user_online(hotels_id);
        }, 1500 );
    }

    $('#userOnline_box img#close').click(function(){
        $('#userOnline_box').remove();
    });

    var dates2 = $( "input#check_in, input#check_out" ).datepicker({
            dateFormat: 'dd-mm-yy',
            changeMonth: true,
            numberOfMonths: 2,
            minDate : $('input#check_in_min_date').val(),
            onSelect: function( selectedDate ) {
                    var option = this.id == "check_in" ? "minDate" : "maxDate",
                            instance = $( this ).data( "datepicker" );
                            date = $.datepicker.parseDate(
                                    instance.settings.dateFormat ||
                                    $.datepicker._defaults.dateFormat,
                                    selectedDate, instance.settings );
                    dates2.not( this ).datepicker( "option", option, date );
            }
    });

    //BEGIN : search-hotels-box
    $('#hotels-search-box SELECT#room').change(function(){
        ChangeRoomCount($(this).val());
    });

    $("#hotels-search-box #night").change(function(){
        var check_in = $("#check_in").val();
        var night = $("#night").val();
        var baseurl = get_base_url();

        $("#div-checkout").text('loading...');
        $("#div-checkout").load(baseurl+"tripleasia/set-checkout-date/", {'check_in': check_in, 'night': night});
    });

    $("#hotels-search-box #country_id").change(function(){
        var baseurl     = get_base_url();
        var language    = $.cookie('tripleasia_lang');
        var country     = $("#country_id").val();
        var css_style   = $("#city_id").attr("class");

        $("#div-city_id").load(baseurl+"tripleasia/get-city-by-country/", {'country': country, 'language':language, 'css':css_style});
    });

    $("#hotels-search-box #city_id").change(function(){
        var baseurl     = get_base_url();
        var language    = $.cookie('tripleasia_lang');
        var city        = $("#city_id").val();
        var css_style   = $("#area_id").attr("class");
        var param       = 'get_hotel_list();';

        $("#div-area_id").load(baseurl+"tripleasia/get-area-by-city/", {'city': city, 'language':language, 'css':css_style, 'param':param});
    });
/*
    $("#search-hotels-box select#room").change(function(){
        var room    = $("select#room").val();
        var baseurl = get_base_url();

        //$("SELECT#adult").load(baseurl+"tripleasia/load-option-number/adult", {'room': room});
        //$("SELECT#child").load(baseurl+"tripleasia/load-option-number/child", {'room': room});
    });

    $("#search-hotels-box select#adult").change(function(){
        var room    = $("select#room").val();
        var adult   = $("select#adult").val();
        var baseurl = get_base_url();

        $("SELECT#child").load(baseurl+"tripleasia/load-option-number/child", {'room': room, 'adult' : adult});
    });
*/

//-------------------------- AUTO COMPLETE ---------------------------
    $("#search_hotels").keydown(function(e){
        if(e.which==13){
            if ( $.browser.msie ) {
                var resultBox       = $('div#result-search').html();
                var resultVal       = '';
                var resultValArr    = '';
                var detected_str    = '';
                var hotels_id       = '';
                var country_id      = '';
                var city_id         = '';
                var area_id         = '';
                var getClass        = '';
                var hotels_path     = '';

                if(resultBox!=''){
                    resultVal       = $("#result-search ul li.selected-hotels").attr('resultVal');
                    resultValArr    = resultVal.split("|");
                    detected_str    = resultValArr[0];
                    hotels_id       = resultValArr[1];
                    country_id      = resultValArr[2];
                    city_id         = resultValArr[3];
                    area_id         = resultValArr[4];
                    getClass        = resultValArr[5];
                    hotels_path     = resultValArr[6];
                    get_data_from_search_hotels(detected_str, hotels_id, country_id, city_id, area_id, getClass, hotels_path);
                }
            }
        }
    });


    $("#search_hotels").keyup(function(e){
        $("#search_hotels").attr('class','search_hotels');

        var left        = $("#search_hotels").offset().left;
        var top         = $("#search_hotels").offset().top+24;
        var qText       = $("#search_hotels").val();
        var qArr        = '';
        var q           = '';

        $("#result-search").css('left',left);
        $("#result-search").css('top',top);

        qArr            = qText.split(",");
        q               = $.trim(qArr[0]);

        if(q.length < 1){
            disableHotelsAutoComplete();
        }else{
            var position        = '';
            var Vtop            = '';
            var scrollTop       = '';

            var resultBox       = $('div#result-search').html();
            var resultVal       = '';
            var resultValArr    = '';
            var detected_str    = '';
            var hotels_id       = '';
            var country_id      = '';
            var city_id         = '';
            var area_id         = '';
            var getClass        = '';
            var hotels_path     = '';

            switch (e.which){
            case 13://Enter
                if ( !$.browser.msie ) {
                    if(resultBox!=''){
                        resultVal       = $("#result-search ul li.selected-hotels").attr('resultVal');
                        resultValArr    = resultVal.split("|");
                        detected_str    = resultValArr[0];
                        hotels_id       = resultValArr[1];
                        country_id      = resultValArr[2];
                        city_id         = resultValArr[3];
                        area_id         = resultValArr[4];
                        getClass        = resultValArr[5];
                        hotels_path     = resultValArr[6];
                        get_data_from_search_hotels(detected_str, hotels_id, country_id, city_id, area_id, getClass, hotels_path);
                    }
                 }
              break;
            case 38://Arrow Up
                position        = $("#result-search ul li.selected-hotels").prev().position();
                Vtop            = position.top;
                scrollTop       = $('#result-search').scrollTop();
                $("#result-search ul li.selected-hotels").prev().addClass('selected-hotels');
                $("#result-search ul li.selected-hotels").next().removeClass('selected-hotels');
                if(Vtop < 5){
                    $('#result-search').scrollTop(scrollTop-50);
                }
              break;
            case 40://Arrow Down
                position        = $("#result-search ul li.selected-hotels").next().position();
                Vtop            = position.top;
                scrollTop       = $('#result-search').scrollTop();
                $("#result-search ul li.selected-hotels").next().addClass('selected-hotels');
                $("#result-search ul li.selected-hotels").prev().removeClass('selected-hotels');
                if(Vtop > 340){
                    $('#result-search').scrollTop(scrollTop+50);
                }
              break;
            case 27://ESC
                disableHotelsAutoComplete();
            break;
            case 13://not use key such as left
            case 16://not use key such as left
            case 17://not use key such as left
            case 18://not use key such as left
            case 19://not use key such as left
            case 20://not use key such as left
            case 37://not use key such as left
            case 39://not use key such as left
            break;
            default:
                $("#search_hotels").addClass('searchLoader');
                delay(function(){
                      getHotelsAutoComplete(q);
                }, 200 );
            }
        }
    });

    $("#search_hotels").dblclick(function() {
        $("#search_hotels").attr('class','search_hotels');

        var left        = $("#search_hotels").offset().left;
        var top         = $("#search_hotels").offset().top+24;
        var qText       = $("#search_hotels").val();
        var qArr        = '';
        var q           = '';

        $("#result-search").css('left',left);
        $("#result-search").css('top',top);
        $("#search_hotels").select();

        qArr            = qText.split(",");
        q               = $.trim(qArr[0]);

        if(q.length > 0){
            $("#search_hotels").addClass('searchLoader');
            delay(function(){
                  getHotelsAutoComplete(q);
            }, 10 );
        }
    });

    $('body').click(function(e){
        var id = e.target.id;
        var condition_text1 = 'search_hotels';
        var condition_text2 = 'area_text';
//        var condition_text3 = 'current_account';
//        var condition_text4 = 'current_languages';
//        var condition_text5 = 'current_currency';

        id  = new String(id);

        if( id.indexOf( condition_text1 ) == -1 ) disableHotelsAutoComplete();
        if( id.indexOf( condition_text2 ) == -1 ) disableAreaAutoComplete();
//        if( id.indexOf( condition_text3 ) == -1 ) $('#div-current_account-box').hide();
//        if( id.indexOf( condition_text4 ) == -1 ) $('#div-current_languages-box').hide();
//        if( id.indexOf( condition_text5 ) == -1 ) $('#div-current_currency-box').hide();

    });
//------------------------
    $("#register_form #country_id, #cust_info_form #country_id, #div-hotels-booking #country_id").change(function(){
        var country_id = $("#country_id").val();

        if( country_id!='' ){
            change_country();
        }else{
            default_dropdown('city_id');
            $("#city_text").attr('disabled','disabled');
        }
        $('#div-area').hide();
    });
//-------------------------
    $("#register_form #area_text, #cust_info_form #area_text").keyup(function(){

        var left        = $("#area_text").offset().left;
        var top         = $("#area_text").offset().top+22;
        var width       = $("#area_text").width()+4;
        var city_id     = $("#city_id").val();
        var qText       = $("#area_text").val();
        var qArr        = '';
        var q           = '';

        $("#result-search-area").css('left',left);
        $("#result-search-area").css('top',top);
        $("#result-search-area").css('width',width);

        qArr            = qText.split(",");
        q               = $.trim(qArr[0]);

        if(q.length < 1){
            disableAreaAutoComplete();
        }else{
            delay(function(){
                  getAreaAutoComplete(q,city_id);
            }, 200 );
        }
    });

    $("#register_form #area_text, #cust_info_form #area_text").dblclick(function(){

        var left        = $("#area_text").offset().left;
        var top         = $("#area_text").offset().top+22;
        var width       = $("#area_text").width()+4;
        var city_id     = $("#city_id").val();
        var qText       = $("#area_text").val();
        var qArr        = '';
        var q           = '';

        $("#result-search-area").css('left',left);
        $("#result-search-area").css('top',top);
        $("#result-search-area").css('width',width);
        $("#area_text").select();

        qArr            = qText.split(",");
        q               = $.trim(qArr[0]);

        if(q.length < 1){
            disableAreaAutoComplete();
        }else{
            delay(function(){
                  getAreaAutoComplete(q,city_id);
            }, 10 );
        }
    });

//--------------------------------------------------------------------------

    //show/hide additional of search-hotels-box
    $("#additional-hide").hide();
    $("#additional-box").hide();

    $("#additional-show").click(function(){
        $("#additional-show").hide();
        $("#additional-hide").show();
        $("#additional-box").show();
    });

    $("#additional-hide").click(function(){
        $("#additional-show").show();
        $("#additional-hide").hide();
        $("#additional-box").hide();
    });
    //END : search-hotels-box


    //BEGIN : register
    $("#register #country").change(function(){
        var country = $("#country").val();
        var css_style = $("#country").attr("class");
        var baseurl = get_base_url();

        $("#div-city").load(baseurl+"tripleasia/get-city-by-country/", {'country': country, 'css': css_style, 'param': 'getHotels()'});
    });

    $("#register #city").change(function(){
        getHotels();
    });
    //END : register


    //BEGIN : login
    $("#action-login").click(function(){
        accessMyaccount();
    })
    //END : login

    //BEGIN : login
    /*$("#action-booking").click(function(){
        hotelsBooking();
    })*/
    //END : login

/*
    //BEGIN : sort result by search-hotels-box
    $("#sort_by").change(function(){
        var vaction = $("#vaction").val();
        var country = $("#country").val();
        var city = $("#city").val();
        var sort_by = $("#sort_by").val();
        var area = $("#area").val();
        var baseurl = get_base_url();

        $("#hotels-result").html("loading...");
        $("#hotels-result").load(baseurl+"hotels/hotels-search-result/", {'action': 'search', 'vaction': vaction, 'country': country, 'city': city, 'sort_by': sort_by, 'area': area});
    });
    //END : sort result by search-hotels-box
*/

    //BEGIN : currencies
    $("#currencies, #area_id, #sort_by").change(function(){
        get_hotel_list();
    });
    //END : currencies


    //BEGIN : serach near area by search-hotels-box
    $("#area").change(function(){
        var vaction = $("#vaction").val();
        var country = $("#country").val();
        var city = $("#city").val();
        var sort_by = $("#sort_by").val();
        var area = $("#area").val();
        var baseurl = get_base_url();

        $("#hotels-result").html("loading...");
        $("#hotels-result").load(baseurl+"hotels/hotels-search-result/", {'action': 'search', 'vaction': vaction, 'country': country, 'city': city, 'sort_by': sort_by, 'area': area});
    })
    //END : serach near area by search-hotels-box


    //BEGIN : display detail hotel
    var menu_hotels_selected = $.cookie('menu_hotels_selected');//alert(menu_hotels_selected);
    var date = 1000;
    var tab_booking = '';
    var tab_description = '';
    var tab_facilities = '';
    var tab_location = '';
    var tab_photo = '';
    var tab_reviews = '';

    if(menu_hotels_selected == null || menu_hotels_selected == '')
    {
        $("#make-a-booking").show();
        tab_booking = ' tab_selected'
    }
    else
        $("#make-a-booking").hide();
        $("#hotel-description").hide();
        $("#hotel-facilities").hide();
    if(menu_hotels_selected == 'location')
    {
        $("#hotel-location").show();
        tab_location = ' tab_selected'
    }
    else
        $("#hotel-location").hide();
    if(menu_hotels_selected == 'photo')
    {
        $("#hotel-photo-gallery").show();
        tab_photo = ' tab_selected'
    }
    else
        $("#hotel-photo-gallery").hide();
    if(menu_hotels_selected == 'reviews')
    {
        $("#guest-reviews").show();
        tab_reviews = ' tab_selected'
    }
    else
        $("#guest-reviews").hide();


    $(".make-a-booking").attr('class','make-a-booking'+tab_booking);
    $(".hotel-description").attr('class','hotel-description'+tab_description);
    $(".hotel-facilities").attr('class','hotel-facilities'+tab_facilities);
    $(".hotel-location").attr('class','hotel-location'+tab_location);
    $(".hotel-photo-gallery").attr('class','hotel-photo-gallery'+tab_photo);
    $(".guest-reviews").attr('class','guest-reviews'+tab_reviews);

    $.cookie("menu_hotels_selected", '', {expires: date , path: '/'});
    //var menu_hotels_selected = $.cookie('menu_hotels_selected');alert(menu_hotels_selected);

    $("#tabs li.make-a-booking").live('click',function(){
        change_tabs('make-a-booking');
    });
    $("#tabs li.hotel-description").live('click',function(){
        change_tabs('description');
    });
    $("#tabs li.hotel-facilities").live('click',function(){
        change_tabs('facilities');
    });
    $("#tabs li.hotel-location").live('click',function(){
        change_tabs('location');
    });
    $("#tabs li.hotel-photo-gallery").live('click',function(){
        change_tabs('gallery');
    });
    $("#tabs li.guest-reviews").live('click',function(){
        change_tabs('reviews');
    });

    /*$(".tabdescription ul.hotels-description").click(function(){
        $("#hotels-description").show();
        $("#hotels-useful").hide();
        $("#hotels-observation").hide();
        $("ul.hotels-description").attr('class','hotels-description b_descript_on');
        $("ul.hotels-useful").attr('class','hotels-useful b_descript');
        $("ul.hotels-observation").attr('class','hotels-observation b_descript');
    });

    $(".tabdescription ul.hotels-useful").click(function(){
        $("#hotels-description").hide();
        $("#hotels-useful").show();
        $("#hotels-observation").hide();
        $("ul.hotels-description").attr('class','hotels-description b_descript');
        $("ul.hotels-useful").attr('class','hotels-useful b_descript_on');
        $("ul.hotels-observation").attr('class','hotels-observation b_descript');
    });

    $(".tabdescription ul.hotels-observation").click(function(){
        $("#hotels-description").hide();
        $("#hotels-useful").hide();
        $("#hotels-observation").show();
        $("ul.hotels-description").attr('class','hotels-description b_descript');
        $("ul.hotels-useful").attr('class','hotels-useful b_descript');
        $("ul.hotels-observation").attr('class','hotels-observation b_descript_on');
    });*/

    $("#search-roomtypes").click(function(){
        SearchAvailableRoom();
    });
    //END : display detail hotel

/*
    //Begin : hotel booking step
    $("#booking-hotels").click(function(){
        //searchHotelsBox();
        var step_booking = $('input[name="step_booking"]').val();
        step_booking_hotels(step_booking,true);
    });
*/
    $("#hotels-booking-step1").click(function(){
        //searchHotelsBox();
        var step_booking = '1';
        step_booking_hotels(step_booking,false);
    });

    $("#hotels-booking-step2").click(function(){
        //searchHotelsBox();
        var step_booking = '2';
        step_booking_hotels(step_booking,false);
    });
    //End : hotel booking step


    //Begin : search-tours-box
    /*$("#search-tours").click(function(){
        searchToursBox();
    });*/
    //End : search-tours-box


    //Begin : search-triple-ideas-box
    /*$("#search-ideas").click(function(){
        searchIdeasBox();
    });*/
    //End : search-triple-ideas-box

//######################################### Tours ##############################
    //BEGIN : display detail tour
    $("#package-preview").show();
    $("#tour-description").hide();
    $("#photo-gallery").hide();
    $("#term-condition").hide();
    $("#tour-include").hide();
    $("#tour-exclude").hide();
    $("#cancellation").hide();
    $("#note").hide();
    $("#visa").hide();
    $("#route").hide();
    $(".package-preview").attr('class','package-preview tab_selected');
    $(".tour-description").attr('class','tour-description');
    $(".photo-gallery").attr('class','photo-gallery');
    $(".term-condition").attr('class','term-condition');
    $(".tour-include").attr('class','tour-include');
    $(".tour-exclude").attr('class','tour-exclude');
    $(".cancellation").attr('class','cancellation');
    $(".note").attr('class','note');
    $(".visa").attr('class','visa');
    $(".route").attr('class','route');

    $("#tabs li.package-preview").click(function(){
         var baseurl = get_base_url();
        if($.trim($("#package-preview").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#package-preview").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'package-preview', 'tours_name': tours_name});
        }
        $("#package-preview").show();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview tab_selected');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.tour-description,.link_more").click(function(){

         var baseurl = get_base_url();
        if($.trim($("#tour-description").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#tour-description").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'tour-description', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").show();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description tab_selected');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.photo-gallery").click(function(){
        var baseurl = get_base_url();
        if($.trim($("#photo-gallery").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#photo-gallery").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'photo-gallery', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").show();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery tab_selected');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.term-condition").click(function(){

        var baseurl = get_base_url();
        if($.trim($("#term-condition").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#term-condition").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'term-condition', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").show();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition tab_selected');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.tour-include").click(function(){

         var baseurl = get_base_url();
        if($.trim($("#tour-include").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#tour-include").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'tour-include', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").show();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include tab_selected');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.tour-exclude").click(function(){

         var baseurl = get_base_url();
        if($.trim($("#tour-exclude").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#tour-exclude").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'tour-exclude', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").show();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude tab_selected');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.cancellation").click(function(){

         var baseurl = get_base_url();
        if($.trim($("#cancellation").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#cancellation").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'cancellation', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").show();
        $("#note").hide();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation tab_selected');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.note").click(function(){

         var baseurl = get_base_url();
        if($.trim($("#note").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#note").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'note', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").show();
        $("#visa").hide();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note tab_selected');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route');
    });
    $("#tabs li.visa").click(function(){
         var baseurl = get_base_url();
        if($.trim($("#visa").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#visa").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'visa', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").show();
        $("#route").hide();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa tab_selected');
        $(".route").attr('class','route');
    });
    $("#tabs li.route").click(function(){
         var baseurl = get_base_url();
        if($.trim($("#route").text()) == '')
        {
            var tours_name = getAbsolutePath();
            $("#route").load(baseurl+"tours/tours-load-tabs/", {'tabs_load':'route', 'tours_name': tours_name});
        }

        $("#package-preview").hide();
        $("#tour-description").hide();
        $("#photo-gallery").hide();
        $("#term-condition").hide();
        $("#tour-include").hide();
        $("#tour-exclude").hide();
        $("#cancellation").hide();
        $("#note").hide();
        $("#visa").hide();
        $("#route").show();
        $(".package-preview").attr('class','package-preview');
        $(".tour-description").attr('class','tour-description');
        $(".photo-gallery").attr('class','photo-gallery');
        $(".term-condition").attr('class','term-condition');
        $(".tour-include").attr('class','tour-include');
        $(".tour-exclude").attr('class','tour-exclude');
        $(".cancellation").attr('class','cancellation');
        $(".note").attr('class','note');
        $(".visa").attr('class','visa');
        $(".route").attr('class','route tab_selected');
    });
    //END : display detail hotel

});






//jQuery
