/**
 * 공통 유틸
 * @author utsman
 */
var Util = {};
/**
 * 팝업 관련
 */
Util.PopUp = {
	/**
	 * 팝업 열기
	 * @param {Object} url
	 * @param {Object} width
	 * @param {Object} height
	 */
	open: function (url, width, height) {
		Util.PopUp.captureOpen(url, width, height, Util.PopUp.checkPosition);
	},
	/**
	 * 팝업 닫기
	 */
	close: function () {
		Dialog.cancelCallback();
	},
	openCore: function (url, options) {
		Dialog.info(url, options);
	},
	captureOpen: function (url, width, height, callback) {
		Util.PopUp.openCore(
			{ url: url }, 
			{
				id: "popup",
				className: "login",
				width: width,
				height: height,
				showEffectOptions: {
					duration: 0.3
				},
				hideEffectOptions: {
					duration: 0.3
				},
				recenterAuto: false,
				onShow: function () {
					Util.PopUp.checkShow(callback); 
				}
			} 				
		);
	},
	checkShow: function (callback) {
		if ($('popup')) {
			callback.call();
		} else {
			setTimeout(Util.PopUp.checkShow, 200); 
		}
	},
	checkPosition: function () {
		var top = $('popup').style.top.gsub('px', '');
		if (top < 0) {
			$('popup').setStyle({top: '0px'});
		}
	}
};

Util.getKeyCode = function (e) {
  var keyCode;
  if ("which" in e) {// NN4 & FF &amp; Opera
    keyCode = e.which;
	
  } else if ("keyCode" in e) {// Safari & IE4+
    keyCode = e.keyCode;
	
  } else if ("keyCode" in window.event) {// IE4+
    keyCode = window.event.keyCode;
	
  } else if ("which" in window.event) {
    keyCode = e.which;
	
  } else  {   
//  	alert("the browser don't support");  
  }
  return keyCode;
}

/**
 * 자바스크립트 trim
 */
String.prototype.ltrim = function() {
    var re = /\s*((\S+\s*)*)/;
    return this.replace(re, "$1");
}
 
String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

String.prototype.trim = function() {
	return this.ltrim().rtrim();
}
/**
 * 로딩 창
 * @param {Object} id
 */
Util.Loading = {
	tag: '<div style="text-align:center; padding:5px;"><img width="300" height="120" src="/mbnweb/image/common/img_loading.gif"/></div>',
	loaderId: '',
	show: function (id) {
		Util.Loading.loaderId = id;
		if ($(Util.Loading.loaderId)) {
			$(Util.Loading.loaderId).update(Util.Loading.tag);
		}
	},
	hide: function () {
		if ($(Util.Loading.loaderId)) {
			$(Util.Loading.loaderId).remove();
		}
	}	
}

///**
// * 로딩창 띄우기
// */
//Util.showLoadingPopup = function () {	
//	var img_width = 300;
//	var img_height = 120;	
//	var center_top = 0;
//	var center_left = 0;
//	
//	if (!$("pre_loading_popup") && !$("pre_loading_img")) {
//		var body = document.getElementsByTagName("body")[0];
//		var divEl = document.createElement("div");
//		
//		var bg_height = body.getWidth();
////		if (Prototype.Browser.IE) {
////			bg_height = document.body.scrollHeight;
////			
////		} else {
////			bg_height = document.documentElement.offsetHeight;
////		}
//		
//		center_top = (bg_height - img_height) /2 + document.body.scrollTop;
//		center_left = (document.body.clientWidth - img_width) /2  + document.body.scrollLeft;
//		
//		divEl.innerHTML += 
//		'<div id="pre_loading_popup" style=\'opacity:0.4; filter:alpha(opacity=40); -ms-filter:"alpha(opacity=40)"; background-color:#000000; display: none; position: absolute; top: 0pt; left: 0pt; z-index: 100; width: 100%; height: ' + 
//				bg_height + 'px;\' />';
//		divEl.innerHTML += "<div id='pre_loading_img' style='display: none; position:absolute; top:" + center_top + "px;left:" + center_left + "px;'><img src='/mbnweb/image/common/img_loading.gif' width='300' height='120' /></div>";
//
//		body.appendChild(divEl);		
//	}
//	
//	var loading_img = $("pre_loading_img");
//	loading_img.style.top = center_top + "px";		
//	loading_img.style.left = center_left + "px";	
//		
//	$("pre_loading_popup").show();	
//	loading_img.show();		
//} 
///**
// * 로딩창 숨기기
// */
//Util.hideLoadingPopup = function () {
//	if ($("pre_loading_popup") && $("pre_loading_img")) {
//		$("pre_loading_img").hide();
//		$("pre_loading_popup").hide();	
//	}	
//}

