
(function($) {

/*
 |/////////////////////////////////////////////////////////////////////////////////////////////////////
 |  * Name : oxProcedure()
 |  * Explanation : 공통 Procedure 클래스
 |*************************************************************************************
*/
OxProcedure = function() {


	/*
	 |=====================================================================================
	 |  * Name : (function) downloadFile
	 |  * Description : 파일 다운로드
	 |-------------------------------------------------------------------------------------
	*/
	this.downloadFile = function(inURL) {
		
		if (String(inURL).replace(/ /g, "") == "") {
			
			alert("파일명이 없습니다.");
			return;
		
		} else {
			
			var actionUrl = "/_setup/procedure/downloadFile.asp";
			var actionData = jQuery.trim(String(inURL).replace(/ /g, ""));
			
			var html = "";
			html = html + "";
			html = html + '<div id="widget_oxDownloadFile" style="display:none; padding:5px;">';
			html = html + '	<form name="form_oxDownloadFile" id="form_oxDownloadFile" method="post" action="'+actionUrl+'" target="frame_oxDownloadFile" onSubmit="javascript:return false;">';
			html = html + '		<input type="hidden" name="fileurl" id="fileurl" value="'+actionData+'" />';
			html = html + '	</form>';
			html = html + '	<iframe name="frame_oxDownloadFile" id="frame_oxDownloadFile" src="" width="0" marginwidth="0" height="0" marginheight="0" scrolling="auto" frameborder="1"></iframe>';
			html = html + '</div>';
			
			$("body").find("div[id='widget_oxDownloadFile']").remove();
			$("body").append($(html));
			
			var $widget_oxDownloadFile = $("div[id='widget_oxDownloadFile']");
			var $frame_oxDownloadFile = $("iframe[name='frame_oxDownloadFile']");
			var $form_oxDownloadFile = $("form[name='form_oxDownloadFile']");
			
			/*(begin) Debug ================================= */
//alert(			actionUrl+"?fileurl="+actionData);
			var debug = false; /* true | false */
			if (debug == true) {
				OxUtil.displayDebug(actionUrl+"?fileurl="+actionData);
				return;
			}
			/*(end) Debug =================================== */
			
			$form_oxDownloadFile.find(":input[name='fileurl']").val(actionData);
			$form_oxDownloadFile.attr("encoding","application/x-www-form-urlencoded");
			$form_oxDownloadFile.attr("enctype","application/x-www-form-urlencoded");
			$form_oxDownloadFile.submit();
		
		}
	
	}; //(fn) downloadFile
	/*
	 |=====================================================================================
	*/
	
	
	/*
	 |=====================================================================================
	 |  * Name : (function) downloadExcel
	 |  * Description : 액셀파일 다운로드
	 |-------------------------------------------------------------------------------------
	*/
	this.downloadExcel = function(inURL) {
		
		if (String(inURL).replace(/ /g, "") == "") {
			
			alert("파일명이 없습니다.");
		
		} else {
			
			var actionUrl = inURL;
			
			var html = "";
			html = html + "";
			html = html + '<div id="widget_oxDownloadExcel" style="display:none; padding:5px;">';
			html = html + '	<iframe name="frame_oxDownloadExcel" id="frame_oxDownloadExcel" src="" width="0" marginwidth="0" height="0" marginheight="0" scrolling="auto" frameborder="1"></iframe>';
			html = html + '</div>';
			
			$("body").find("div[id='widget_oxDownloadExcel']").remove();
			$("body").append($(html));
			
			var $widget_oxDownloadExcel = $("div[id='widget_oxDownloadExcel']");
			var $frame_oxDownloadExcel = $("iframe[name='frame_oxDownloadExcel']");
			
			/*(begin) Debug ================================= */
			var debug = false; /* true | false */
			if (debug == true) {
				OxUtil.displayDebug(actionUrl);
				return;
			}
			/*(end) Debug =================================== */
			
			$frame_oxDownloadExcel.attr("src",actionUrl);
		
		}
	
	}; //(fn) downloadExcel
	/*
	 |=====================================================================================
	*/
	
	
	/*
	 |=====================================================================================
	 |  * Name : (function) openIdCheck
	 |  * Description : 아이디 중복 확인창
	 |-------------------------------------------------------------------------------------
	*/
	this.openIdCheck = function(options) {
	
		var $element;
		var actionUrl = "";
		var actionData = "";
		
		var settings = $.extend({
			element: null, /* 결과를 리턴받을 Element명 */
			ownerId: "", /* 회원 소유 아이디 (중복체크에서 제외) */
			usingId: "", /* 사용하고자 하는 아이디 (필드에 입력된 값) */
			widgetName: "widget_idcheck", /* 창이름 */
			widgetType: "blind" /* 오픈창 형식 (blind | dialog | popup) */
			}, options);
		settings.element = jQuery.trim(settings.element);
		settings.ownerId = jQuery.trim(settings.ownerId).replace(/ /g, "");
		settings.usingId = jQuery.trim(settings.usingId).replace(/ /g, "");
		
		switch(settings.widgetType) {
			case "blind" :
				settings.widgetName = "widget_idcheck";
				settings.widgetType = "blind";
				actionUrl = "/_setup/procedure/idcheck_dialog.asp";
				break;
			case "dialog" :
				settings.widgetName = "widget_idcheck";
				settings.widgetType = "dialog";
				actionUrl = "/_setup/procedure/idcheck_dialog.asp";
				break;
			case "popup" :
				settings.widgetName = "widget_idcheck";
				settings.widgetType = "popup";
				actionUrl = "/_setup/procedure/idcheck_popup.asp";
				break;
			default :
				settings.widgetName = "widget_idcheck";
				settings.widgetType = "blind";
				actionUrl = "/_setup/procedure/idcheck_dialog.asp";
				break;
		}
		
		actionData = $.param(settings);
		
		$element = $(settings.element);
		
		var offset;
		var eleHeight;
		var posLeft = "center";
		var posTop = "center";
		
		
		if ( typeof($element) == "object" && typeof($element) != "undefined" ) {
		} else {
			alert("Element 요소가 불분명 합니다.");
			return false;
		}
		
		
		if (settings.widgetType == "popup") {
		
			OxUtil.openPopup({
				url: actionUrl+"?"+actionData,
				name: settings.widgetName,
				width: 400,
				height: 270,
				posX: "center",
				posY: "middle",
				style: {resizable: "no", scrollbars: "no"}
			});
		
		} else {
		
			/*(begin) Debug ================================= */
			var debug = false; /* true | false */
			if (debug == true) {
				OxUtil.displayDebug(actionUrl+"?"+actionData);
				return;
			}
			/*(end) Debug =================================== */
		
			offset = $element.offset();
			eleHeight = $element.height();
			posLeft = (offset.left - 2);
			posTop = (offset.top + eleHeight) + 6;
		
			var title = "▒ 아이디 중복 확인";
			$("body").find("#"+settings.widgetName).empty().remove();
			var $widget_idcheck = $('<div id="'+settings.widgetName+'"></div>')
				.css({'text-align':"center", overflow:'auto'})
				.appendTo("body")
				//.hide()
				.dialog({
					title: title,
					autoOpen: true,
					width: 400, height: 250,
					modal: false,
					draggable: true,
					resizable: false,
					show: 'blind',
					hide: 'blind',
					minWidth:50, minHeight: 50,
					maxWidth:400, maxHeight: 250,
					position: [posLeft , posTop],
					stack: true,
					closeOnEscape: false,
					buttons: {},
					open: function(e, ui) { OxUtil.showBlockUI($(this)); },
					close: function(e, ui) { $(this).empty().remove().dialog("close"); }
				})
				.load(actionUrl, actionData, function() {
					OxUtil.hideBlockUI($(this));
				});
		
		}
	
	}; //(fn) openIdCheck
	/*
	 |=====================================================================================
	*/
	
	
	/*
	 |=====================================================================================
	 |  * Name : (function) openZipcode
	 |  * Description : 우편번호 검색기
	 |-------------------------------------------------------------------------------------
	*/
	this.openZipcode = function(options) {
	
		var actionUrl = "";
		var actionData = "";
		//element_zip
		//element_addr
		//element_focus
		var settings = $.extend({
			widgetType: "blind", /* 오픈창 형식 (dialog | popup) */
			widgetName: "widget_zipcode", /* 창이름 */
			element_zip: null, /* 결과를 리턴받을 Element명 (우편번호) */
			element_addr: null, /* 결과를 리턴받을 Element명 (주소) */
			element_focus: null /* 결과를 리턴후 포커스가 위치할 Element명 */
			}, options);
		
		switch(settings.widgetType) {
			case "dialog" :
				settings.widgetName = "widget_zipcode";
				settings.widgetType = "dialog";
				actionUrl = "/_setup/procedure/zipcode_dialog.asp";
				break;
			case "popup" :
				settings.widgetName = "widget_zipcode";
				settings.widgetType = "popup";
				actionUrl = "/_setup/procedure/zipcode_popup.asp";
				break;
			default :
				settings.widgetName = "widget_zipcode";
				settings.widgetType = "dialog";
				actionUrl = "/_setup/procedure/zipcode_dialog.asp";
				break;
		}
		
		actionData = $.param(settings);
		
		if (settings.widgetType == "popup") {
		
			OxUtil.openPopup({
				url: actionUrl+"?"+actionData,
				name: settings.widgetName,
				width: 400,
				height: 370,
				posX: "center",
				posY: "middle",
				style: {resizable: "no", scrollbars: "no"}
			});
		
		} else {
		
			/*(begin) Debug ================================= */
			var debug = false; /* true | false */
			if (debug == true) {
				OxUtil.displayDebug(actionUrl+"?"+actionData);
				return;
			}
			/*(end) Debug =================================== */
		
			var title = "▒ 우편번호 검색";
			$("body").find("#"+settings.widgetName).empty().remove();
			var $widget_idcheck = $('<div id="'+settings.widgetName+'"></div>')
				.css({'text-align':"center", overflow:'auto'})
				.appendTo("body")
				//.hide()
				.dialog({
					title: title,
					autoOpen: true,
					width: 400, height: 340,
					modal: false,
					draggable: true,
					resizable: false,
					show: 'blind',
					hide: 'blind',
					minWidth:50, minHeight: 50,
					maxWidth:400, maxHeight: 250,
					position: ['center' , 'center'],
					stack: true,
					closeOnEscape: false,
					buttons: {},
					open: function(e, ui) { OxUtil.showBlockUI($(this)); },
					close: function(e, ui) { $(this).empty().remove().dialog("close"); }
				})
				.load(actionUrl, actionData, function() {
					OxUtil.hideBlockUI($(this));
				});
		
		}
	
	}; //(fn) openZipcode
	/*
	 |=====================================================================================
	*/
	

	/*
	 |=====================================================================================
	 |  * Name : openZipcode
	 |  * Description : 우편번호 검색창 띄우기
	 |  * Output :  Windows Object
	 |  * Parameters
	 |     inEleZip : 우편번호를 표시할 element ID명
	 |     inEleAddr1 : 메인주소를 표시할 element ID명
	 |     inEleAddr2 : 상세주소를 표시할 element ID명
	 |-------------------------------------------------------------------------------------
	*/
	this.openZipcode2 = function(inEleZip, inEleAddr1, inEleAddr2) {
	
		var url = "/_setup/procedure/zipcode.asp?eleZip=" + inEleZip + "&eleAddr1=" + inEleAddr1 + "&eleAddr2=" + inEleAddr2;
	
		var strAppVersion = navigator.appVersion;
		var xWidth = 400;
		var xHeight = 347;
		var plusHeight = 0;
		var iMyWidth;
		var iMyHeight;
		var winstyle = "";
		
		if(strAppVersion.indexOf("Windows NT 5.1")>-1) {// Windows XP 인 경우
			plusHeight = 6;
		}
		if(strAppVersion.indexOf("MSIE 7.0")>-1) {// IE 7 인 경우
			plusHeight += 30;
		}
		xHeight += plusHeight;
	
		iMyWidth = (window.screen.width/2) - (xWidth/2+50);
		iMyHeight = (window.screen.height/2) - (xHeight/2+50);
		
		var winstyle = "left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",height=" + xHeight + ",width=" + xWidth + ", toolbar=no, menubar=no,directories=no,resizable=no,status=no,scrollbars=no,location=no,copyhistory=no";
		
		var openWin = window.open(url, null, winstyle);
		
		if(openWin == null) {
			alert("차단된 팝업창을 허용해 주세요.");
		} else {
			openWin.focus();
		}
	
	}
	/*
	 |=====================================================================================
	*/
	
	
	/*
	 |=====================================================================================
	 |  * Name : openPreviewImage
	 |  * Description : 이미지보기창 띄우기
	 |  * Output :  Windows Object
	 |  * Parameters
	 |     inUrl : 이미지 경로
	 |-------------------------------------------------------------------------------------
	*/
	this.openPreviewImage = function(inUrl) {
	
		var url = "/_setup/procedure/previewImage.asp?fileurl=" + encodeURIComponent(inUrl); /* escape | encodeURIComponent */
		
		var winstyle = "left=0, top=0, height=50, width=50, toolbar=no, menubar=no, directories=no, resizable=no, status=no, scrollbars=no, location=no, copyhistory=no";
		
		var openWin = window.open(url, null, winstyle);
		
		if(openWin == null) {
			alert("차단된 팝업창을 허용해 주세요.");
		} else {
			openWin.focus();
		}
	
	}
	/*
	 |=====================================================================================
	*/

}; //(fn) OxProcedure
/*
 |/////////////////////////////////////////////////////////////////////////////////////////////////////
*/

})(jQuery);

