(function($) {
	$.extend({
		hx : {
			goTabNavigate : function(service,o,paramJson){
				var options = {
						step    : '',
						tabDiv  : "tabContents",
						baseTab : "baseTab" 
				};
				
				var config = $.extend({}, options, o);
				$('#' + config.baseTab).removeClass("step");
				for(var i=1;i<=6;i++){
					$('#'+config.baseTab).removeClass("step"+i);
				}
				
				
				$('#'+config.tabDiv).navigate(service,paramJson);
				$('#'+config.baseTab).addClass(config.step);
			} ,
			excelDownload : function(service,paramJson){
				httpSend(
						service, 
						paramJson,
						function(data) {
							var fileParam = { "filepath" : data.filepath };
							navigate("excelDownload", fileParam);
						},
						function() {
							alert("Excel 다운로드 실패!");
							return;
						}
					);
			},
			LayerOpen: function(o){
				var popClass = null2String(o.className,"pop_dialog af-default w900px");
				var targetObj = $('body');
				objId = null2String(o.popName,"DIV_POP_NAME");
				var html = '';
				html += '<div id="'+objId+'"  class="'+popClass+'" data-dialog-modal="true" data-type="dialog" tabindex="0"  data-converted="true"  data-dialog-movable="true" ></div>';
				
				var objForm = document.getElementById(objId);
				
				$(objForm).remove();
				objForm = null;
				
				
				if (objForm == null || objForm == undefined || typeof(objForm) != 'object') {
					targetObj.append(html);
				}
				
				$('#'+objId).hxLayerOpen(o);
			},
			equalsTo : function(sourceJson,targetJson) {
				var tempObj = (sourceJson.length ? sourceJson : [sourceJson]);
				//console.log('tempObj',tempObj);
				var strRtn = true;
				for (var name in tempObj[0]) {
					if(sourceJson[name] != targetJson[name]){
						strRtn = false;
						break;
						
					}
				}
				return strRtn;
			},
			InitForm : function(initFn){
				//$(document).ready(function(){
					initFn();
				//});
				
			},
			/**
             * Statements $.hc.alert({options})
             * options.message = Alert 메세지
             * options.callback = Alert 창 종료후 실행할 함수명
             * USAGE : $.hx.alert("경고");
             * USAGE : $.hx.alert({message:"경고",callback:fnCallBack});
             * options.callback에 지정한 함수는 페이지내에 function으로 존재해야한다.
             * options.callback는 필요시에만 선언한다.
             * NOT USAGE : $.hx.alert("경고", fnCallBack);
             */
			alert : function(o) {
				var $alertDialogElement = $('#hx_alert_dialog');
				
				if( typeof o == "string" && arguments.length == 1 ) {
					if( $alertDialogElement.length > 0 ) {
						$('#hx_alert_dialog_message').text(o);
						$('.hx_alert_dialog_close').unbind();
						$('.hx_alert_dialog_close').tap(function() {
							$alertDialogElement.close();
						});
					} else {
						alert(0);
					}
				} else if( typeof o == "object") {
					var options = {
						message : "",
						callback : ""
					};
					
					var config = $.extend({}, options, o);
					
					if( config.message == "" || typeof config.message == undefined ) {
						console.log("Message Attribute is not difined.");
						return;
					}
					
					if( $alertDialogElement.length > 0 ) {
						$('#hx_alert_dialog_message').text(config.message);
						$('.hx_alert_dialog_close').unbind();
						$('.hx_alert_dialog_close').tap(function() {
							$alertDialogElement.close();
							if(config.callback != "" && config.callback != null && typeof config.callback != "undefined") {
								if(typeof config.callback == "function") config.callback();
							}
						});
					} else {
						alert(config.message);
					}
				}

				$alertDialogElement.open();
			},
			
			/**
             * Statements $.hc.confirm({options})
             * options.title = confirm 창 헤더 텍스트
             * options.message = confirm 창 메세지
             * options.confirm = confirm 창 확인버튼 callback function
             * options.cancel = confirm 창 취소버튼 callback function
             * USAGE : $.hx.confirm({title:"SK hynix semiconductor(chongqing)",message:"확인하시겠습니까?",confirm:fnConfirmCallBack,cancel:fnCancelCallBack});
             * (options.confirm/options.cancel)에 지정한 함수는 페이지내에 function으로 존재해야한다.
             * (options.message/options.confirm)은 필수 옵션이다.
             * (options.title/options.cancel)은 필요시에만 선언한다.
             * USAGE : $.hx.confirm({message:"확인하시겠습니까?",confirm:fnConfirmCallBack});
             */
			confirm : function(o) {
				var options = {
					title : "",
					message : "",
					confirm : "",
					cancel : ""
				};
				
				var config = $.extend({}, options, o);
				
				if( config.message == "" || typeof config.message == undefined ) {
					console.log("Message Attribute is not difined.");
					return;
				}
				
				if( config.confirm == "" || typeof config.confirm == undefined ) {
					console.log("Confirm Attribute is not difined.");
					return;
				}
				
				var $confirmDialogElement = $('#hx_confirm_dialog');
				if( $confirmDialogElement.length > 0 ) {
					if( typeof config.title != "undefined" && config.title != "" ) {
						$('#hx_confirm_dialog_header_message').text(config.title);
						$('#hx_confirm_dialog_header').show();
					} else {
						$('#hx_confirm_dialog_header').hide();
					}
					
					$('#hx_confirm_dialog_message').text(config.message);
					
					$('.hx_cofirm_dialog_ok').unbind();
					$('.hx_cofirm_dialog_ok').tap(function() {
						$confirmDialogElement.close();
						if(typeof config.confirm == "function") config.confirm();
					});
					
					$('.hx_cofirm_dialog_close').unbind();
					$('.hx_cofirm_dialog_close').tap(function() {
						$confirmDialogElement.close();
						if(typeof config.cancel == "function") config.cancel();
					});
					
					$confirmDialogElement.open();
				} else {
					return;
				}
			},
			
			naviTitle : function(menucode) {
				// lnb title
				var $lnbTitle = $('.lnb_title');
				var topDepthTxt = $('#t_' + menucode.substr(0,3) + '00000').text();
				$lnbTitle.empty().append($('<h1>' + topDepthTxt + '</h1>'));
				
				var menus = new Array();
				
				function selectLnbNode(obj) {
					if(obj == null) {
						if(typeof menucode == 'undefined' || menucode == null) return;
						obj = $('#'+menucode);
					}
					menus.push(obj.attr('id'));
					if(!obj.closest('ul').hasClass('lnb_2d_ul')) {
						selectLnbNode(obj.closest('ul').parent());
					}
				}
				selectLnbNode();
				
				var $title = $('#titleArea');
				var $naviDiv = $('<div></div>').addClass("location");
				
				$title.empty();
				$title.append($('<h1>' + $('#'+menucode+' > a').text() + '</h1>'));
				$naviDiv.append($('<a></a>').attr('href', '/').text('Home')).append($('<img></img>').attr('src', '/content/css/images/location_arrow.png'));
				
				if(menus.length > 0) {
					// 1Depth
					$naviDiv.append($('<a></a>').attr('href', '#').text(topDepthTxt)).append($('<img></img>').attr('src', '/content/css/images/location_arrow.png'));
					
					menus.reverse();
					for(var i = 0; i < menus.length; i++) {
						var $childA = $('#'+menus[i]).find('a:eq(0)');
						if(i == menus.length-1) {
							$naviDiv.append($childA.text());
						} else {
							var $arrow = $('<img></img>').attr('src', '/content/css/images/location_arrow.png');
							$naviDiv.append($('<a></a>').attr('href', $childA.attr('href')).text($childA.text())).append($arrow);
						}
					}
				} else {
					// 1Depth
					$naviDiv.append(topDepthTxt);
				}
				
				$title.append($naviDiv);
			}
		}
	});
})(jQuery);