function load_price_rate(){
  var date = new Date();
  var body_param = 'pair=' + encodeURIComponent($('price_pare').value) + '&chart_type=' + encodeURIComponent($('chart_type').value);
  new Ajax.Request('/market/price_rate_data' , {
    method: 'post',
    postBody: body_param,
    onSuccess: function(conn, obj) {
      if (!obj) { obj = eval('(' + conn.responseText + ')'); }
      if (obj.cd == undefined)
        $('cd').innerHTML         = '';
      else
        $('cd').innerHTML         = obj.cd;
      if (obj.ask == undefined)
        $('ask').innerHTML        = '';
      else
        $('ask').innerHTML        = obj.ask;
      if (obj.bid == undefined)
        $('bid').innerHTML        = '';
      else
        $('bid').innerHTML        = obj.bid;
      if (obj.bidhigh == undefined)
        $('bidhigh').innerHTML    = '';
      else
        $('bidhigh').innerHTML    = obj.bidhigh;
      if (obj.asklow == undefined)
        $('asklow').innerHTML     = '';
      else
        $('asklow').innerHTML     = obj.asklow;
      $('chart_img').innerHTML  = '<img src="http://rate.gaikaex.net/html/lzca/img/' + obj.pair_num + '_AF_' + $('chart_type').value + 'CHART.gif?' + date.getTime() + '" width="140" height="140" name="chartimg">';
    },
    onException: function(conn, e) {
      // alert(e.number + ':' + e.description);
    }
  });
}

function load_all_charts(chart_type){
  var date = new Date();
  if(chart_type == undefined) chart_type = $('chart_type').value;
  if($('chart_type').value != chart_type) $('chart_type').value = chart_type;
  var body_param = 'chart_type=' + chart_type.escapeHTML();
  new Ajax.Request('/market/all_chart_data' , {
    method: 'post',
    postBody: body_param,
    onSuccess: function(conn, obj) {
      if (!obj) { obj = eval('(' + conn.responseText + ')'); }
      // チャートgif入れ替え
      var key = '';
      for(key in obj.pair_num) {
        $(key).innerHTML = '<img src="http://rate.gaikaex.net/html/lzca/img/' + obj.pair_num[key].toString() + '_AF_' + chart_type + 'CHART.gif?' + date.getTime() + '" width="140" height="140" name="chartimg_' + key + '" alt="' + key + '">';
      }
      for(key in obj.chart_types) {
        if(obj.chart_types[key][0] != undefined) {
          if(obj.chart_types[key][0] == chart_type) {
            $(obj.chart_types[key][0]).innerHTML = obj.chart_types[key][1];
          } else {
            $(obj.chart_types[key][0]).innerHTML = '<a href="javascript:load_all_charts(\'' + obj.chart_types[key][0] + '\');">' + obj.chart_types[key][1] + '</a>';
          }
        }
      }
    },
    onException: function(conn, e) {
      //alert(e.number + ':' + e.description);
    }
  });
}

function reload_chart(pair){
  var date = new Date();
  var chart_type = $('chart_type').value;
  var body_param = 'chart_type=' + chart_type.escapeHTML();
  new Ajax.Request('/market/all_chart_data' , {
    method: 'post',
    postBody: body_param,
    onSuccess: function(conn, obj) {
      if (!obj) { obj = eval('(' + conn.responseText + ')'); }
      // チャートgif入れ替え
      var key = '';
      for(key in obj.pair_num) {
        if(key == pair)
          $(key).innerHTML = '<img src="http://rate.gaikaex.net/html/lzca/img/' + obj.pair_num[key].toString() + '_AF_' + chart_type + 'CHART.gif?' + date.getTime() + '" width="140" height="140" name="chartimg_' + key + '" alt="' + key + '">';
      }
    },
    onException: function(conn, e) {
      //alert(e.number + ':' + e.description);
    }
  });
}

