/*
 * Help Tool Tips
 *
 * Depends:
 *	helptips.js
 */

$j(document).ready(function(){
  var $j = jQuery.noConflict();													 
  $j("body").append('<div id="helptip"></div>');
  var helptips ="";

  $j("img.helptip").hover(
    // mouse over
		function() {
      if( !$j(this).attr("title") ) { return; }
      helptips = $j(this).attr("title");
      $j(this).removeAttr("title");

      var offset = $j(this).offset();
      $j("#helptip")
        .css("top", (offset.top-50) +"px")
        .css("left", (offset.left+20) +"px")
        .html( helptips )
			  .fadeIn();
		},
    // mouse out
		function() {
			$j("#helptip").fadeOut();
      $j(this).attr('title', helptips);
		}
	);

});


// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function my_ajax_request(path) {
  return new Ajax.Request(path, {asynchronous:true, evalScripts:true, method:'get', on404:function(request){alert('ページが見つかりません。');}, onFailure:function(request){alert('ただいま大変混雑しているか、不具合が発生しております。ブラウザの再読み込みボタンを押してから再試行しても駄目な場合は、しばらくたってからお試しください。');}, onLoaded:function(request){document.body.style.cursor='default';}, onLoading:function(request){document.body.style.cursor='wait';}, onSuccess:function(request){if (request.getResponseHeader('Content-Type').indexOf('text/html')>=0) {document.body.innerHTML=request.responseText;};}});
}

function enableAllButtons() {
  $A(document.getElementsByTagName('button')).each(function(item) {item.disabled=false});
}



function roundToUnit(obj, unit, min, max) {
  var v = parseInt(obj.val());
  if (isNaN(v) ) {
    v = unit;
  } else {
    v = Math.round(v / unit) * unit;
  }
  if (min != null && v < min) {
    v = Math.ceil(min / unit) * unit;
  } else if (max != null && v > max) {
    v = Math.floor(max / unit) * unit;
  }
  obj.val(v);
  return v;
}

function toggleSearch() {
  jQuery(document).ready(function($){
    if ($("#ssbox1").css("display") == "none") {
      showSearch();
    } else {
      hideSearch();
    }
  });
}

function showSearch() {
  jQuery(document).ready(function($){
    $("#ssbox1").show();
    $("#tabstage").hide();
    $("#ssearch").addClass("sel");
  });
}

function hideSearch() {
  jQuery(document).ready(function($){
    $("#ssbox1").hide();
    $("#tabstage").show();
    $("#ssearch").removeClass("sel");
  });
}

function tabChange(tabObj, tab) {
  hideSearch();
  jQuery(document).ready(function($){
    $("#tabstage").html($(tabObj).html());
    $("#tabmenu li.sel").removeClass("sel");
    var li = $(tab).parent().get(0);
    $(li).addClass("sel");
    tabSelected = tabObj;
  });
}

function on_change_price_condition(value) {
  switch (value) {
  case "limit":
  case "limit_on_open":
  case "limit_on_close":
  case "limit_or_market":
    $('limit_price_box').show();
    $('stop_price_box').hide();
    break;
  case "stop":
    $('limit_price_box').hide();
    $('stop_price_box').show();
    break;
  case "stop_limit":
    $('limit_price_box').show();
    $('stop_price_box').show();
    break;
  default:
    $('limit_price_box').hide();
    $('stop_price_box').hide();
  }
}
