$(function() { $(".priceBlock").stick_in_parent({ parent: "#form_paynow" }); $("#starting_date").datepicker({ showAnim: "fadeIn", duration: 0, minDate: 3, maxDate: "2y", numberOfMonths: 2, showButtonPanel: true, dateFormat: 'yy-mm-dd' }); var substringMatcher = function(strs) { return function findMatches(q, cb) { if (q == '') { return cb( ["United States", "Canada", "Australia", "United Kingdom", "Germany", "France", "Italy", "Spain", "China", "Singapore", "Malaysia"]); } var matches, substringRegex; matches = []; substrRegex = new RegExp(q, 'i'); $.each(strs, function(i, str) { if (substrRegex.test(str)) { matches.push(str); } }); cb(matches); }; }; var nationality_map = ["afghanistan", "albania", "algeria", "american samoa", "andorra", "angola", "anguilla", "antarctica", "antigua and barbuda", "argentina", "armenia", "aruba", "australia", "austria", "azerbaijan", "bahamas", "bahrain", "bangladesh", "barbadian", "barbados", "belarus", "belgium", "belize", "benin", "bermuda", "bhutan", "bolivia", "botswana", "bouvet island", "brazil", "british indian ocean territory", "brunei darussalam", "bulgaria", "burkina faso", "burundi", "cambodia", "cameroon", "canada", "cape verde", "cayman islands", "central african republic", "chad", "chile", "china", "china HK", "christmas island", "colombia", "comoros", "congo", "cook islands", "costa rica", "croatia", "cuba", "cyprus", "czech republic", "czechoslovakia", "denmark", "djibouti", "dominica", "dominican republic", "east timor", "ecuador", "egypt", "el salvador", "equatorial guinea", "eritrea", "estonia", "ethiopia", "falkland islands", "faroe islands", "fiji", "finland", "france", "french guiana", "french polynesia", "gabon", "gambia", "georgia", "germany", "ghana", "gibraltar", "greece", "greenland", "grenada", "guadeloupe", "guam", "guatemala", "guernsey", "guinea", "guinea-bissau", "guyana", "haiti", "honduras", "hong kong", "hungary", "iceland", "india", "indonesia", "iran", "iraq", "ireland", "isle of man", "israel", "italy", "jamaica", "japan", "jersey", "jordan", "kazakhstan", "kazakhstan2", "kenya", "kiribati", "korea", "kuwait", "kyrgyzstan", "laos", "latvia", "lebanon", "lesotho", "liberia", "libyan arab jamahiriya", "liechtenstein", "lithuania", "luxembourg", "macau", "macedonia", "madagascar", "malawi", "malaysia", "maldives", "mali", "malta", "marshall islands", "martinique", "mauritania", "mauritius", "mayotte", "mexican", "micronesia", "moldova", "monaco", "mongolia", "montserrat", "morocco", "mozambique", "myanmar", "namibia", "nauru", "nepal", "netherlands", "netherlands antilles", "neutral zone", "new caledonia", "new zealand", "nicaragua", "niger", "nigeria", "niue", "norfolk island", "north korea", "northern mariana islands", "norway", "oman", "pakistan", "palau", "panama", "papua new guinea", "paraguay", "peru", "philippines", "pitcairn", "poland", "portugal", "puerto rico", "qatar", "reunion", "romania", "russian federation", "rwanda", "saint helena", "samoa", "san marino", "sao tome and principe", "saudi arabia", "scotland", "senegal", "seychelles", "sierra leone", "singapore", "slovakia", "slovenia", "solomon islands", "somalia", "south africa", "south georgia and the sandwich", "spain", "sri lanka", "sudan", "suriname", "swaziland", "sweden", "switzerland", "syrian arab republic", "taiwan", "tanzania", "thailand", "the republic of cote d'ivoire", "togo", "tokelau", "tonga", "trinidad and tobago", "tunisia", "turkey", "turkmenistan", "turks and caicos islands", "tuvalu", "uganda", "ukraine", "united arab emirates", "united kingdom", "united states", "unknown", "uruguay", "ussr", "uzbekistan", "vanuatu", "vatican city state", "venezuela", "vietnam", "virgin islands (british)", "virgin islands (u.s.)", "western sahara", "yemen", "yugoslavia", "zaire", "zambia", "zimbabwe"]; $('.nationality').typeahead({ hint: false, highlight: true, minLength: 0, classNames: { suggestion: 'tt-suggestion tt-selectable tt-suggestion-nationality' } }, { name: 'nationality_states', source: substringMatcher(nationality_map), limit: 10 }); function calc_price(msg_obj) { var cli_no = $('#cli_no').val(); var cli_grade = $('input[name=cli_grade]:checked').val(); var adult_number = $('#adult_number').val(); var child_number = $('#child_number').val(); var baby_number = $('#baby_number').val(); var starting_date = $('#starting_date').val(); $.ajax({ type: "post", dataType: "json", url: "https://www.chinahighlights.com/secureforms/price", data: { 'cli_no': cli_no, 'cli_grade': cli_grade, 'adult_number': adult_number, 'child_number': child_number, 'baby_number': baby_number, 'starting_date': starting_date }, success: function(data, textStatus) { if (data.result == 'true') { var price_data = data.value; $('#calc_adult_number').html(price_data.adult_number); $('#calc_adult_price').html(price_data.adult_price); if (price_data.child_number > 0) { $('#calc_child_number').html(price_data.child_number); $('#calc_child_price').html(price_data.child_price); } else { $('#calc_child_number').html(''); $('#calc_child_price').html('0'); } if (price_data.baby_number > 0) { $('#calc_baby_number').html(price_data.baby_number); $('#calc_baby_price').html(price_data.baby_price); } else { $('#calc_baby_number').html(''); $('#calc_baby_price').html('0'); } if (price_data.room_diff_price > 0) { $('#calc_room_diff_price').html(price_data.room_diff_price); } else { $('#calc_room_diff_price').html('0'); } $('#calc_totla_price').html(price_data.totla_price); $('#calc_totla_price_paynow').html(price_data.totla_price_paynow); $('#cli_price').val(price_data.totla_price); $('#totla_price_paynow').val(price_data.totla_price_paynow); return true; } else { $('#calc_adult_number').html(''); $('#calc_adult_price').html(''); $('#calc_child_number').html(''); $('#calc_child_price').html(''); $('#calc_baby_number').html(''); $('#calc_baby_price').html(''); $('#calc_room_diff_price').html(''); $('#calc_totla_price').html(''); $('#calc_totla_price_paynow').html(''); if (msg_obj == '') { alert(data.value); } else { $('#' + msg_obj).html(data.value); } return false; } }, error: function() { if (msg_obj == '') { alert('\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYCC'); } else { $('#' + msg_obj).html('\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u8054\u7cfbYCC'); } } }); } $('input[name=cli_grade]').change(function() { return calc_price(); }); $('#adult_number').change(function() { return calc_price(); }); $('#child_number').change(function() { return calc_price(); }); $('#baby_number').change(function() { return calc_price(); }); $('#starting_date').change(function() { return calc_price(); }); $('.forms_paynow_sumbit_button').click(function() { $('.requiredArea').remove(); var requirei = 0; var windowHeight = $(document).height(); var scrollTopWhere = windowHeight; var calcScrollTop = function($jqElement) { var visibleTop = $jqElement.offset().top - $jqElement.height(); scrollTopWhere = visibleTop < scrollTopWhere ? visibleTop : scrollTopWhere; } if ($('input[name="starting_date"]').val() == '') { $('
Please select your approximate arrival date
').appendTo('.datesArrival'); calcScrollTop($(".datesArrival")); requirei++; } if ($('#hotel_name').val() == '') { $('#hotel_name').parent().append('
Please offer your hotel information.
'); calcScrollTop($(".hotelBlock")); requirei++; } if ($('#realname').val() == '') { $('#realname').parents(".personalInfo").append('
Please enter your full name
'); calcScrollTop($("#realname").parents(".personalInfo")); requirei++; } if ($('#nationality').val() == '') { $('#nationality').parents(".personalInfo").append('
Please select your nationality
'); calcScrollTop($("#nationality").parents(".personalInfo")); requirei++; } if ($('#email').val() == '') { $('#email').parents(".personalInfo").append('
Please enter your email
'); calcScrollTop($("#email").parents(".personalInfo")); requirei++; } else { var emailPattern = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/; if (!emailPattern.test($('#email').val())) { $('#email').parents(".personalInfo").append('
Please verify your email
'); calcScrollTop($("#email").parents(".personalInfo")); requirei++; } } if (scrollTopWhere < windowHeight) { $("body,html").animate({ scrollTop: scrollTopWhere }) } if (requirei > 0) { return false; } return true; }); $('#starting_date').focus(function() { $('.datesArrival').children('.requiredArea').remove(); }) $('input[name="realname"],input[name="nationality"],input[name="email"]').focus(function() { $(this).parents(".personalInfo").children('.requiredArea').remove(); }); $('#hotel_name').focus(function() { $(this).siblings('.requiredArea').remove(); }); });