;(function ($) {

/*
 * jqog.js 0.01
 * openGion HYBS utilities
 * Date: 2008-09-03 rev 1
 */

	$.hybs = $.hybs || {};
	$.hybs.defaults = {
		sHybsSel	: "h_rowSel",
		sNoTsKey	: "h_noTrnsKey",
		sHybsRid	: "rid",
		sHybsKh		: "kh",
		sHybsCmd	: "command",
		sHybsCmdVal	: "commandVal",
		sCmdInit	: "INIT",
		sCmdNew		: "NEW",
		sCmdInsert	: "INSERT",
		sCmdCopy	: "COPY",
		sCmdModify	: "MODIFY",
		sCmdDelete	: "DELETE",
		sCmdEntry	: "ENTRY",
		sCmdView	: "VIEW",
		sCmdReset	: "RESET",
		sCmdUndo	: "UNDO",
		sEntryCls	: "entryBtn",
		sEditCls 	: "editBtn",
		sSelRow		: "SEL_ROW" // 5.0.0.4 (2009/10/01)
	};

	$.hybs.ogAlert = function(msg, opts) {
		// If jqModal is existed
		if($.jqm) {
			var jDlg = $('div.jqmAlert#ogdlg');
			if(!jDlg.length) {
				jDlg = $("<div class='jqmAlert' id='ogdlg'>"
							 +	 "<img class='jqmPrintSafe' src='../image/space_white.gif' height='1' width='1'>"
							 +	 "<div class='jqmAlertWindow'>"
							 +		 "<div class='jqmAlertTitle jqDrag'>"
							 +			 "<h1>エラーが発生しました。</h1><a href='#' class='jqmClose'>×</a>"
							 +		 "</div>"
							 +		 "<div class='jqmAlertContent'></div>"
							 +	 "</div>"
							 + "</div>").appendTo(document.body);
				if($.jqDnR) { jDlg.jqDrag('.jqDrag'); }
				jDlg.jqm({modal	: false,
									overlay: 0,
									onShow : function(h) { var z=(parseInt(h.w.css('z-index'))),
															jAw = h.w.find('.jqmAlertWindow').css('z-index',z+2),
															jPi = h.w.find('.jqmPrintSafe').css('z-index',z+1);
															h.w.show(); 
															jPi.css({width:jAw.outerWidth(),height:jAw.outerHeight()});},
									onHide : function(h) { h.w.find('.jqmAlertContent').html('');h.w.hide();if(h.o)h.o.remove(); }
				});
			}

				jDlg.find('.jqmAlertContent').html(msg + ($.browser.msie ? '<div>&nbsp</div>' : ''));
				jDlg.jqmShow();
		}
		else
			alert(msg);
	}

	$.hybs.ogLog = function(msg, opts) {
		if (window.console && window.console.error) {
			console.error(msg);
		}
	}

	$.hybs.getHValue = function(sFn) {
		var sDef = "";
		if(sFn) {
				jHObj = $('input:hidden[name=' + sFn + ']');
				return (jHObj[0] ? jHObj[0].value : sDef);
		}
		else return sDef;
	}

	$.hybs.getNoColId = function (jTab) {
		var nNoColId = -1;
		$('th:lt(3)', jTab).each(function(index) {
			if('No' == $(this).text()) nNoColId = index;
		});

		return nNoColId;
	}

	$.hybs.getHybsTr = function (jTr) {
		return (jTr.hasClass('row_0') || jTr.hasClass('row_1') || jTr.hasClass('row_hilight') || jTr.hasClass('row_sel')) ? jTr : jTr.parent();
	}

$.fn.extend({
	// resize view range
	resizeView : function(bFixHdr, bHdrSet) {
		return this.each(function(iTab) {
		  var oTab = this;
		  //ヘッダ複製式のヘッダ固定の確認
		  if(oTab.grid) { $(oTab).adjustSB(); }
		  else if($.hybsGrid) { $(oTab).hybsGrid().adjustSB(); }
		  else {
			//ヘッダ移動式のヘッダ固定へ
			if($.browser.msie) {
				var oHeads = oTab.getElementsByTagName("THEAD");
				var oHeader = (1 <= oHeads.length) ? oHeads[0] : null
				if(oHeader) {
					var nHeaderH = oHeader.offsetHeight;
					var divHide, oLayerDiv;
					divHide = oTab.parentNode;
					if(divHide && "divHide" == divHide.id) oLayerDiv = divHide.parentNode;
					if(oLayerDiv && "layer" == oLayerDiv.id) {
						if(bFixHdr) {
							scrollBar2();
							AdjustScroll2();
						}
						else if(parseInt(oLayerDiv.style.borderTopWidth) == (nHeaderH + 1)) {
							// Check header is fixed or not?
							var sDum, nChg = 0;
							sDum = (oTab.offsetHeight - nHeaderH) + "px";
							if(divHide.style.height != sDum) {
								divHide.style.height = sDum;
								divHide.scrollTop	 = nHeaderH;
								nChg |= 0x1;
							}
							sDum = oTab.offsetWidth + "px";
							if(divHide.style.width	!= sDum) {divHide.style.width	= sDum; nChg |= 0x2;}
							if(nChg) { SetScrollHeader(oLayerDiv, false); AdjustScroll2(); }
						}
					}
				}
			}
			else if($.browser.mozilla) {
				AdjustScroll2();
			}
		  }
		});
	}
});

/*
 * 4.3.5.0 (2008/02/01)
 *
 * jquery plugin
 * フォーカスが当ったとき
 */
 $.fn.focusin = function( fnc ){
	var self = this;
	 	if($.browser.msie){
	 		self.bind( "focusin", fnc );
	 	}
	 	else{
	 		self.focus( fnc );
	 	}
 	return self;
 }
 
 /*
 * 4.3.5.0 (2008/02/01)
 *
 * jquery plugin
 * フォーカスが外れたとき
 */
 $.fn.focusout = function( fnc ){
	var self = this;
	 	if($.browser.msie){
	 		self.bind( "focusout", fnc );
	 	}
	 	else{
	 		self.blur( fnc );
	 	}
 	return self;
 }

})(jQuery);
