google.load("jquery", "1.2.6");

var ajax_pageurl="http://www.hotelssamui.net/r24/ajax_rate.php";

function gp_currencySymbols() {
    $.getJSON("http://www.geoplugin.net/currency_symbols.gp?format=json&jsoncallback=?",
            function(data){
            var currencyCode = geoplugin_currencyCode();
            var fromCurr = '';
            $.each(data, function(i,item){
                if ( currencyCode == i ) {
                fromCurr = fromCurr + "<option value='"+i+"' selected>"+item.name+" "+(item.symbol?item.symbol:'')+"</option>";
                } else {
                fromCurr = fromCurr + "<option value='"+i+"'>"+item.name+" "+(item.symbol?item.symbol:'')+"</option>";
                }
                }); 
            $(fromCurr).appendTo("#gp_from");
            });
};
function gp_convertIt() 
{
    var rate = 0;
    var gp_to = document.getElementById('gp_from').value;
    var gp_from = "THB";
    var gp_amount = 1;

    $.getJSON( "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?", { from:gp_from, to:gp_to, amount:gp_amount }, 
            function(output){
            rate = output.to.amount;
            locat = $("#location_div").html();
            hotelname = $("#hotelname_div").html();
            $.post(ajax_pageurl,{lstr:locat,hstr:hotelname,rate_curr:rate,sym:gp_to},
                function(res) {
                $('#ajax_table').html(res);
                }
                );
            });

};

google.setOnLoadCallback(function() {
        $("#curTHB").click(function() {
            var rate = 0;
            var gp_to = "THB";
            var gp_from = "THB";
            var gp_amount = 1;
            $.getJSON( "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?", { from:gp_from, to:gp_to, amount:gp_amount }, 
                function(output){
                rate = output.to.amount;
                locat = $("#location_div").html();
                hotelname = $("#hotelname_div").html();
                $.post(ajax_pageurl,{lstr:locat,hstr:hotelname,rate_curr:rate,sym:gp_to},
                    function(res) {
                    $('#ajax_table').html(res);
                    });
                });
            });

        $("#curUSD").click(function() {
            var rate = 0;
            var gp_to = "USD";
            var gp_from = "THB";
            var gp_amount = 1;
            $.getJSON( "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?", { from:gp_from, to:gp_to, amount:gp_amount }, 
                function(output){
                rate = output.to.amount;
                locat = $("#location_div").html();
                hotelname = $("#hotelname_div").html();
                $.post(ajax_pageurl,{lstr:locat,hstr:hotelname,rate_curr:rate,sym:gp_to},
                    function(res) {
                    $('#ajax_table').html(res);
                    });
                });
            });

        $("#curEUR").click(function() {
            var rate = 0;
            var gp_to = "EUR";
            var gp_from = "THB";
            var gp_amount = 1;
            $.getJSON( "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?", { from:gp_from, to:gp_to, amount:gp_amount }, 
                function(output){
                rate = output.to.amount;
                locat = $("#location_div").html();
                hotelname = $("#hotelname_div").html();
                $.post(ajax_pageurl,{lstr:locat,hstr:hotelname,rate_curr:rate,sym:gp_to},
                    function(res) {
                    $('#ajax_table').html(res);
                    });
                });
            });

        $("#curCNY").click(function() {
            var rate = 0;
            var gp_to = "CNY";
            var gp_from = "THB";
            var gp_amount = 1;
            $.getJSON( "http://www.geoplugin.net/currency_converter.gp?jsoncallback=?", { from:gp_from, to:gp_to, amount:gp_amount }, 
                function(output){
                rate = output.to.amount;
                locat = $("#location_div").html();
                hotelname = $("#hotelname_div").html();
                $.post(ajax_pageurl,{lstr:locat,hstr:hotelname,rate_curr:rate,sym:gp_to},
                    function(res) {
                    $('#ajax_table').html(res);
                    });
                });
            });
});

