//document.writeln('<script language="VBScript" src="/system/js/lib.vb"></script>');
	
function set_modal(vWidth, vHeight, vTitle){
	var vText = '<div id="wrapper_modal"></div><div id="modal_body" style="width: ' + vWidth + 'px; height: ' + vHeight + 'px">';
	vText += '<ul>';
	vText += '<li class="modal_title"><span class="title"></span><span class="menu"><img src="/common/images/btn_close01.gif" onclick="close_modal()" style="cursor:pointer"></span></li><li id="modal_content"></li></ul></div>'

	$('#wrapper').append(vText);
	//$(vText).insertBefore('#wrapper');

	var vBG = '#EDEBE4 url(/system/images/title/' + vTitle + '.gif) no-repeat left top';
	$('li.modal_title').css('background',vBG);

	pos_modal();
}

function set_modal1(vWidth, vHeight, vTitle){
	var vText = '<div id="wrapper_modal"></div><div id="modal_body" style="width: ' + vWidth + 'px; height: ' + vHeight + 'px">';
	vText += '<ul>';
	vText += '<li class="modal_title"><span class="title"></span><span class="menu"><img src="/common/images/btn_close01.gif" onclick="confirm_modal()" style="cursor:pointer"></span></li><li id="modal_content"></li></ul></div>'

	$('#wrapper').append(vText);
	//$(vText).insertAfter('#wrapper');

	var vBG = '#EDEBE4 url(/system/images/title/' + vTitle + '.gif) no-repeat left top';
	$('li.modal_title').css('background',vBG);

	pos_modal();
}

function pos_modal(){
	var wWidth = $(window).width();
	var dWidth = $(document).width();

	var wHeight = $(window).height();
	var dHeight = $(document).height();

	var vWidth = dWidth;
	var vHeight = dHeight;

	if(wWidth < dWidth){
		vWidth = wWidth;
	}

	if(wHeight < dHeight){
		vHeight = dHeight;
	}


	$('#wrapper_modal').css({
		width: vWidth,
		height: vHeight
	});

	var vLeft = 0;
	var vTop = 0;
	var mWidth = $('#modal_body').width();
	var mHeight = $('#modal_body').height();
	var sTop = $(document).scrollTop();

	if(wHeight > mHeight){
		if(wHeight > dHeight){
			vTop = (wHeight - mHeight)/2
		}
		else{
			vTop = ((wHeight - mHeight)/2) + sTop
		}
	}

	if(vWidth > mWidth){
		vLeft = (vWidth - mWidth)/2;
	}	

	$('#modal_body').css({
		left: vLeft,
		top: vTop	
	});
}
	
	function close_modal(){
		$('#modal_body').remove();
		$('#wrapper_modal').remove();
	}

	
	function close_modal1(){
		$('#modal_body').remove();
		$('#wrapper_modal').remove();
	}
		

	function open_postal(){
		set_modal(508,408,'m_zipcode');

		var vText = '<div class="modal_note" style="height: 60px; 476px; margin-left: 24px;">Ã£°íÀÚÇÏ´Â Áö¿ªÀÇ µ¿/À¾/¸é/¸®/°Ç¹°¸íÀ» ÀÔ·ÂÇÏ¼¼¿ä.<br/>¼­¿ï½Ã °­³²±¸ »ï¼ºµ¿ÀÌ¶ó¸é »ï¼º ¶Ç´Â »ï¼ºµ¿ÀÌ¶ó°í ÀÔ·ÂÇÏ½Ã¸éµË´Ï´Ù.</div>';
		vText += '<dl class="modal_form" style="height: 40px;"><dd style="margin-left: 90px; margin-top: 8px; width: 64px;">Áö¿ª¸í</dd><dd class="v_bar1" style="height:31px"></dd>';
		vText += '<dd style="margin-top: 6px; width:140px;"><input type="text" name="postal_keyword" id="postal_keyword" class="input" style="width:110px;ime-mode: active" maxlength="30"></dd>';
		vText += '<dd style="width: 104px;"><img src="/system/images/button/search.gif" width="104" height="31" style="cursor:pointer" onclick="search_postal()"></dd></dl>';
		vText += '<div class="modal_dot"></div>';
		vText += '<div class="modal_note" style="height: 216px; 476px; margin-left: 24px;" id="postal_note"></div>';

		$('#modal_content').html(vText)
	}

	function search_postal(){
		var vKey = $('#postal_keyword').val();
		var vText = '';

		if(vKey.length < 1){
			alert('Ã£°íÀÚÇÏ´Â Áö¿ªÀÇ µ¿/À¾/¸é/¸®/°Ç¹°¸íÀ» ÀÔ·ÂÇÏ¼¼¿ä.');
			$('#postal_keyword').focus();		
		}
		else{
			var vQuery = 'postal_keyword=' + escape(vKey);

			$.ajax({
				type: 'GET',
				url: '/lib/postal/procedure_postal.asp',
				data: vQuery,
				dataType: 'json',
				success: function(objJSON){
					if(objJSON.code == '9'){
						if(objJSON.articles.length > 0){
							$.each(objJSON.articles, function(i, article){
								vText += '<dl style="width: 100%">';
								vText += '<dd style="width: 20px"><input type="radio" id="postal_code" name="postal_code" value1="' + article.code1 + '" value2="' + article.code2 + '" onclick="set_postal(this)" title="' +article.rec_address + '"></dd>';
								vText += '<dd style="width: 65px">' + article.code1 + '-' + article.code2 + '</dd>';
								vText += '<dd>' + article.address + '</dd>';
								vText += '</dl>';
							});
						}
						else{
								vText += '<dl style="width: 100%">';
								vText += '<dd style="width: 100%; text-align: center"><br/>°Ë»öµÈ ³»¿ëÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.<br/>Ã£°íÀÚÇÏ´Â Áö¿ªÀÇ µ¿/À¾/¸é/¸®/°Ç¹°¸íÀ» ´Ù½Ã È®ÀÎÇÏ¿© ÁÖ¼¼¿ä</dt>';
								vText += '</dl>';
						}
						$('#postal_note').html(vText);
					}
					else{
					}
				}
			});

		}
	}


	function set_postal(obj){
		$('#zip1').val($(obj).attr('value1'));
		$('#zip2').val($(obj).attr('value2'));
		$('#address1').val($(obj).attr('title'));

		close_modal();

		$('address2').focus();
	}


	function get_goods_tag(vTag, vLoc){
		var vReturn ='';

		if(vTag.length > 0){
			arrTag = vTag.split(',');
			for( i in arrTag){
				vReturn += '<span class="goods_tag' + arrTag[i] + '_' + vLoc + '"></span>';
			}
		}

		return vReturn
	}
