var GlobalPopup = {
	showLayerPopup: function(url, width, height) {
		var windowWidth = width + 14;
		var windowHeight = height + 28;

		var iframe = '<iframe scrolling="no" frameborder="no"';
		iframe += ' name="popup" id="popup" src="'+url+'" width="'+width+'" height="'+height+'"></iframe>';

		var quickViewHtml = '';
		quickViewHtml += '<table width="'+ windowWidth +'" height="'+ windowHeight +'" border="0" cellpadding="0" cellspacing="0">\n';
		quickViewHtml += '	<tr>\n';
		quickViewHtml += '		<td width="7" height="21" style="line-height:0px;">\n';
		quickViewHtml += '			<img src="../../image/view/quickview_01.gif" width="7" height="21" alt=""></td>\n';
		quickViewHtml += '		<td id="quickViewDivTitleBar" align="right" valign="middle" style="line-height:0px;" background="../../image/view/quickview_02.gif"><a href="javascript:GlobalPopup.closeQuickViewDiv();"><img src="../../image/view/quickview_close.gif" border="0" align="absmiddle"></a></td>\n';
		quickViewHtml += '<td width="7" height="21" style="line-height:0px;">\n';
		quickViewHtml += '			<img src="../../image/view/quickview_03.gif" width="7" height="21" alt=""></td>\n';
		quickViewHtml += '	</tr>\n';
		quickViewHtml += '	<tr>\n';
		quickViewHtml += '		<td width="7" background="../../image/view/quickview_04.gif">&nbsp;</td>\n';
		quickViewHtml += '  <td style="line-height:0px;background-color:#eeeeee">'+iframe+'</td>\n';
		quickViewHtml += '		<td width="7" background="../../image/view/quickview_06.gif"></td>\n';
		quickViewHtml += '  </tr>\n';
		
		quickViewHtml += '	<tr>\n';
		quickViewHtml += '		<td  width="7" height="7" style="line-height:0px;">\n';
		quickViewHtml += '			<img src="../../image/view/quickview_07.gif" width="7" height="7" alt=""></td>\n';
		quickViewHtml += '		<td height="7" background="../../image/view/quickview_08.gif"></td>\n';
		quickViewHtml += '  <td width="7" height="7" style="line-height:0px;">\n';
		quickViewHtml += '			<img src="../../image/view/quickview_09.gif" width="7" height="7" alt=""></td>\n';
		quickViewHtml += '	</tr>\n';
		quickViewHtml += '</table>\n';

		var oBody = getBody();
		
		// left, top 계산 : 화면 중앙에 오도록
		var windowTop = 130;
		var windowLeft = (document.documentElement.clientWidth - windowWidth) / 2 ;
		
		windowTop = oBody.top + windowTop;

		if (windowLeft <0)
		{
			windowLeft = 0;
		}

		windowTop = 0;
		windowLeft = 0;

		var quickViewDiv = document.createElement('div');
		quickViewDiv.innerHTML = quickViewHtml;
		quickViewDiv.id = 'quickViewDiv';
		quickViewDiv.style.position = 'absolute';
		quickViewDiv.style.top = windowTop + 'px';
		quickViewDiv.style.left = windowLeft + 'px';
		quickViewDiv.style.width = windowWidth + 'px';
		quickViewDiv.style.height = windowHeight + 'px';
		quickViewDiv.style.textAlign = 'center';
		quickViewDiv.style.zIndex = '500000';
		document.body.appendChild(quickViewDiv);

	},

	popSendSms:  function(phoneNumber) {
		this.PopWindow('/pepbox-cms/system/sendSms.html?cmd=view&phoneNumber=' + phoneNumber,'popSendSms', '', '324','328','true');
	},

	openMailtoListForSms:  function() {
		this.PopWindow('/main/global/popMailtoListForSms.jsp?','popMailtoListForSms', '', '324','328','true');
	},

	openCertMobile: function() {
		this.PopWindow('/main/global/certMobileStep1.jsp?','certMobile', '', '500','200','true');
	},

	popFriendRequest: function(friendId) {
		this.PopWindow('/main/mypepbox/friendRequestForm.jsp?friendId=' + friendId,'friendRequestForm', '', '390','380','true');
	},

	popHelpMovie:function() {
		this.PopWindow('/main/info/popHelpMovie.jsp', 'helpMovie', '', '890','600','true');
	},
	
	popGroupInfo:function() {
		this.PopWindow('/main/order/popGroupInfo.jsp', 'popGroupInfo', '', '450','368','true');
	},

	popProductInfo: function() {
		var productSeq = 8;
		try
		{
			productSeq = document.f1.productSeq.value;	
		}
		catch (e)
		{
		}

		this.PopWindow('/main/order/popProductInfo.jsp?productSeq=' + productSeq,'popProductInfo', '', '522','647','true');
	},

	popProductPriceInfo: function() {
		var productSeq = 8;
		try
		{
			productSeq = document.f1.productSeq.value;	
		}
		catch (e)
		{
		}

		this.PopWindow('/main/order/popProductInfo.jsp?productSeq=' + productSeq,'popProductInfo', '', '522','647','true');

		// this.PopWindow('/main/order/popProductPriceInfo.jsp?productSeq=' + productSeq,'popProductPriceInfo', '', '522','490','true');
	},

	popTotalAlbumTitleInfo: function() {
		var productType = 1;
		try
		{
			productType = GetRadioValue(document.f1.productType);	
		}
		catch (e)
		{
		}

		this.PopWindow('/main/order/popTotalAlbumTitleInfo.jsp?productType=' + productType,'popTotalAlbumTitleInfo', '', '522','560','true');
	},

	popAlbumTitleInfo: function() {
		var productType = 1;
		try
		{
			productType = GetRadioValue(document.f1.productType);	
		}
		catch (e)
		{
		}

		this.PopWindow('/main/order/popAlbumTitleInfo.jsp?productType=' + productType,'popAlbumTitleInfo', '', '522','540','true');
	},

	goMail: function(enc_seq) {
		this.PopWindow('/main/global/albumMailForm.jsp?encAlbumSeq=' + enc_seq,'albumMailForm', '', '552','590','true');
	},

	goLogView: function(enc_seq) {
		this.PopWindow('/main/pepbox/logView.jsp?encAlbumSeq=' + enc_seq,'logView', 'resizable=1,scrollbars=1', '800','590','true');
	},

	goHanaTV: function(type) {
		this.PopWindow('/main/hanatv/' + type + 'pop01.jsp','hanatvpop', '', '400','300','true');
	},

	Album: function(seq, encSeq, title, cgSeq, scaleWidth, scaleHeight, scalemode, 
						contents, memberSeq, nickName, regDate, hitCount, 
						recommendCount, configFile, styleSeq, styleName, stylePrice, stillCut, commentCount) {
		this.seq 				= seq;
		this.encSeq				= encSeq;
		this.title                  = title;
		this.cgSeq                 = cgSeq;
		this.scaleWidth           = scaleWidth;
		this.scaleHeight         = scaleHeight;
		this.scalemode           = scalemode;
		this.contents			= contents;
		this.memberSeq			= memberSeq;
		this.nickName			= nickName;
		this.regDate			= regDate;
		this.hitCount              = hitCount;
		this.recommendCount           = recommendCount;
		this.configFile 		= configFile.trim();
		this.styleSeq			= styleSeq;
		this.styleName			= styleName;
		this.stylePrice			= stylePrice;
		this.stillCut			= stillCut;
		this.commentCount           = commentCount;
	},

	quickViewAlbumForOrder: function(enc_seq) {
		// Ajax Call
		var param = '_uid=' + (new Date()).getTime()
			+ '&cmd=view_auth'
			+ '&enc_seq=' + enc_seq;

		var url = '/main/pepbox/albumServlet';
		new Ajax.Request(url, {
			parameters: param,
			onSuccess: function(xmlHttp) {
				GlobalPopup.printAlbum(xmlHttp, 'order');
			},
			onFailure: function(xmlHttp) {
				alert('서버 연결에 실패했습니다. 새로고침 후 다시 이용해 주세요.');
			}
		});
	},

	quickViewAlbum: function(enc_seq) {
		// Ajax Call
		var param = '_uid=' + (new Date()).getTime()
			+ '&cmd=view_auth'
			+ '&enc_seq=' + enc_seq;

		var url = '/main/pepbox/albumServlet';
		new Ajax.Request(url, {
			parameters: param,
			onSuccess: function(xmlHttp) {
				GlobalPopup.printAlbum(xmlHttp, '');
			},
			onFailure: function(xmlHttp) {
				alert('서버 연결에 실패했습니다. 새로고침 후 다시 이용해 주세요.');
			}
		});
	},

	printAlbum: function(xmlHttp, type) {
		var xml = xmlHttp.responseXML;
		var record_data = xml.getElementsByTagName("record");

		var windowOtherWidth = 14;
		var windowOtherHeight = 28;

		if (type == 'order')
		{
			windowOtherHeight = 59;
		}

		if(record_data){
			for(var row=0;row<record_data.length;row++){
				
				if (record_data.item(row).hasChildNodes() 
					&& record_data.item(row).childNodes.length > 1)
				{
					var rows = record_data.item(row);

					var album = new GlobalPopup.Album(
						GetValue(rows, "seq")
						,GetValue(rows, "enc-seq")
						,GetValue(rows, "title")
						,GetValue(rows, "cg-seq")
						,GetValue(rows, "scale-width")
						,GetValue(rows, "scale-height")
						,GetValue(rows, "scalemode")
						,GetValue(rows, "contents")
						,GetValue(rows, "member-seq")
						,GetValue(rows, "nick-name")
						,GetValue(rows, "regdate")
						,GetValue(rows, "hit-count")
						,GetValue(rows, "recommend-count")
						,GetValue(rows, "config-file")
						,GetValue(rows, "style-seq")
						,GetValue(rows, "style-name")
						,GetValue(rows, "style-price")
						,GetValue(rows, "still-cut")
					);

					// 앨범 크기 보정 : 퀵뷰이므로 최대 500 을 넘지 않도록 함
					var windowWidth = 400;
					var windowHeight = 400;

					// 실제 크기 그대로 사용
					windowWidth = album.scaleWidth*1 + windowOtherWidth;
					windowHeight = album.scaleHeight*1 + windowOtherHeight;

					var objTag = "";
					objTag = "<embed src='" + pepboxUrl + "/MediaPlayer/base.swf?styleConfig="+ album.configFile 
						+"&service=0&userSeq=0&pepboxSeq="+ album.seq 
						+"&rootAccess=1&rootDomain="+ pepboxUrl +"' ";
					objTag += "	 quality='high' allowFullScreen='true' bgcolor='#ffffff' width='"+ album.scaleWidth +"' height='" + album.scaleHeight + "' name='pepbox' scale='"+ album.scalemode +"' align='LT' allowScriptAccess='always' ";
					objTag += "	 type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";

					var quickViewHtml = '';
					quickViewHtml += '<table width="'+ windowWidth +'" height="'+ windowHeight +'" border="0" cellpadding="0" cellspacing="0">\n';
					quickViewHtml += '	<tr>\n';
					quickViewHtml += '		<td width="7" height="21" style="line-height:0px;">\n';
					quickViewHtml += '			<img src="../../image/view/quickview_01.gif" width="7" height="21" alt=""></td>\n';
					quickViewHtml += '		<td id="quickViewDivTitleBar" align="right" valign="middle" style="line-height:0px;" background="../../image/view/quickview_02.gif"><a href="javascript:GlobalPopup.closeQuickViewDiv();"><img src="../../image/view/quickview_close.gif" border="0" align="absmiddle"></a></td>\n';
					quickViewHtml += '<td width="7" height="21" style="line-height:0px;">\n';
					quickViewHtml += '			<img src="../../image/view/quickview_03.gif" width="7" height="21" alt=""></td>\n';
					quickViewHtml += '	</tr>\n';
					quickViewHtml += '	<tr>\n';
					quickViewHtml += '		<td width="7" background="../../image/view/quickview_04.gif">&nbsp;</td>\n';
					quickViewHtml += '  <td style="line-height:0px;">' + objTag + '</td>\n';
					quickViewHtml += '		<td width="7" background="../../image/view/quickview_06.gif"></td>\n';
					quickViewHtml += '  </tr>\n';
					
					if (type == 'order') {
						quickViewHtml += '	<tr>\n';
						quickViewHtml += '		<td width="7" background="../../image/view/quickview_04.gif"></td>\n';
						quickViewHtml += '		<td bgcolor="#d3dfef" style="padding-top:8px;color:#000000;font-family:굴림;">';
						quickViewHtml += '<a href="javascript:CartControl.addItem(\'' + album.seq + '\',\'' + album.title.replace('"', '&quot;').replace('\'', '\\\'') + '\', \'' + album.stillCut + '\', \'' + album.cgSeq + '\', \'' + album.stylePrice + '\', \'0\');GlobalPopup.closeQuickViewDiv();">';
						quickViewHtml += '<img src="/image/mypepbox/btn_cartin.gif"/></a> </td>\n';
						quickViewHtml += '		<td width="7" background="../../image/view/quickview_06.gif"></td>\n';
						quickViewHtml += '  </tr>\n';
					} 

					quickViewHtml += '	<tr>\n';
					quickViewHtml += '		<td  width="7" height="7" style="line-height:0px;">\n';
					quickViewHtml += '			<img src="../../image/view/quickview_07.gif" width="7" height="7" alt=""></td>\n';
					quickViewHtml += '		<td height="7" background="../../image/view/quickview_08.gif"></td>\n';
					quickViewHtml += '  <td width="7" height="7" style="line-height:0px;">\n';
					quickViewHtml += '			<img src="../../image/view/quickview_09.gif" width="7" height="7" alt=""></td>\n';
					quickViewHtml += '	</tr>\n';
					quickViewHtml += '</table>\n';

					this.closeQuickViewDiv();

					this.makeGrayBackDiv();

					var oBody = getBody();
										
					// left, top 계산 : 화면 중앙에 오도록
					var windowTop = (document.documentElement.clientHeight - windowHeight) / 2;
					if (windowTop <0)
					{
						windowTop = 0;
					}

					windowTop = oBody.top + windowTop;

					var windowLeft = (document.documentElement.clientWidth - windowWidth) / 2;
					if (windowLeft <0)
					{
						windowLeft = 0;
					}

					var quickViewDiv = document.createElement('div');
					quickViewDiv.innerHTML = quickViewHtml;
					quickViewDiv.id = 'quickViewDiv';
					quickViewDiv.style.position = 'absolute';
					quickViewDiv.style.top = windowTop + 'px';
					quickViewDiv.style.left = windowLeft + 'px';
					quickViewDiv.style.width = windowWidth + 'px';
					quickViewDiv.style.height = windowHeight + 'px';
					quickViewDiv.style.textAlign = 'center';
					quickViewDiv.style.zIndex = '500000';
					document.body.appendChild(quickViewDiv);

				} else {
					alert('존재하지 않는 앨범이거나 이미 삭제된 앨범입니다.');
				}
			}
		}
	},
	
	hideElement: function ( elmID )
	{
		var	ie=document.all;

		if( ie )
		{
			var len = document.all.tags( elmID ).length;
			for(var i = 0; i < len; i++ )
			{
				obj = document.all.tags( elmID )[i];
				if( !obj || !obj.offsetParent )
				{
					continue;
				}

				obj.style.visibility = "hidden";
			}
		}
	},

	showElement: function( elmID )
	{
		var	ie=document.all;

		if( ie )
		{
			for( i = 0; i < document.all.tags( elmID ).length; i++ )
			{
				obj = document.all.tags( elmID )[i];

				if( !obj || !obj.offsetParent )
				{
					continue;
				}
				obj.style.visibility = "";
			}
		}
	},

	makeGrayBackDiv:function() {
		// select 박스 제거
		this.hideElement('SELECT');

		var bg = $('GrayBackDiv');
		if(!bg)
		{
			bg = document.createElement('div');
			bg.setAttribute('id','GrayBackDiv');
			bg.className = 'GrayBackDiv';
			bg.style.zIndex = '400000';
			document.body.appendChild(bg);
		}

		var oBody = getBody();
		if(oBody.height > document.body.scrollHeight)
			bg.style.height = oBody.height+'px';
		else
			bg.style.height = document.body.scrollHeight+'px';
		bg.style.display = 'block';
		document.body.width = '100%';
	},

	makeLoadingDiv:function() {
		// select 박스 제거
		this.hideElement('SELECT');

		var bg = $('LoadingDiv');
		if(!bg)
		{
			bg = document.createElement('div');
			bg.setAttribute('id','LoadingDiv');
			bg.className = 'GrayBackDiv';
			document.body.appendChild(bg);
		}

		var oBody = getBody();
		if(oBody.height > document.body.scrollHeight)
			bg.style.height = oBody.height+'px';
		else
			bg.style.height = document.body.scrollHeight+'px';
		bg.style.display = 'block';
		document.body.width = '100%';
	},

	closeLoadingDiv: function() {
		this.showElement('SELECT');

		if ($('LoadingDiv') != null)
		{
			$('LoadingDiv').innerHTML = '';
			document.body.removeChild($('LoadingDiv'));
		}
	},

	closeQuickViewDiv: function() {
		this.showElement('SELECT');

		if ($('quickViewDiv') != null)
		{
			$('quickViewDiv').innerHTML = '';
			try
			{
				document.body.removeChild($('GrayBackDiv'));
			}
			catch (e)
			{
			}

			try
			{
				document.body.removeChild($('quickViewDiv'));
			}
			catch (e)
			{
			}
		}
	},

	popCouponDown: function(couponSeq) {
		if (_isLogin) {
			this.PopWindow('/main/coupon/couponDown.jsp?couponSeq=' + couponSeq,'popCouponDown', '', '300','230','true');
		} else {
			if (confirm('로그인 후 이용하실 수 있습니다.\n\n로그인 페이지로 이동하겠습니까?')) {
				document.location.href = '../global/login.jsp?returnURL=../coupon/couponList.jsp';
			}
		}
	},

	PopWindow: function(the_url,win_name,features, my_width, my_height, is_center) { //v3.0
		try
		{
			if(window.screen)if(is_center)if(is_center=="true"){
				var myLeft = (screen.width-my_width)/2;
				var myTop = (screen.height-my_height)/2;
				features+=(features!='')?',':'';
				features+=',left='+myLeft+',top='+myTop;
			}
			
			popWindow = window.open(the_url,win_name,features+((features!='')?',':'')+'width='+my_width+',height='+my_height);
			popWindow.focus();
			return popWindow;
		}
		catch (e)
		{
			//alert('잘못된 URL 입니다.');
		}
	},

	goParentUrl: function(url) {
		try {
			opener.window.location.href=url;
		} catch (e) {
			window.open(url);
		}
		self.close(); 
	},

	showProgramNotRunMsg: function() {
		var flashUrl = '/util/msgbox/msgbox.swf';
		var windowWidth = 518;
		var windowHeight = 446;

		// left, top 계산 : 화면 중앙에 오도록
		var windowTop = Math.floor((document.documentElement.clientHeight - windowHeight) / 2);
		if (windowTop <0)
		{
			windowTop = 0;
		}

		var windowLeft = Math.floor((document.documentElement.clientWidth - windowWidth) / 2);
		if (windowLeft <0)
		{
			windowLeft = 0;
		}

		var bg = document.createElement('div');
		bg.id = 'GrayBackDiv';
		bg.className = 'GrayBackDiv';
		document.body.appendChild(bg);
		bg.onclick = function(){GlobalPopup.closeQuickViewDiv();};

		var quickViewDiv = document.createElement('div');
		quickViewDiv.innerHTML = objTag;
		quickViewDiv.id = 'quickViewDiv';
		quickViewDiv.style.position = 'absolute';
		quickViewDiv.style.top = windowTop + 'px';
		quickViewDiv.style.left = windowLeft + 'px';
		quickViewDiv.style.width = windowWidth + 'px';
		quickViewDiv.style.height = windowHeight + 'px';
		quickViewDiv.style.border = '0px solid blue';
		quickViewDiv.style.textAlign = 'center';
		quickViewDiv.style.zIndex = '500000';
		quickViewDiv.style.backgroundColor = '#ffffff';
		document.body.appendChild(quickViewDiv);
	},

	popDvdSample:function() {
		var url = '/main/order/popDvdSample.jsp';		
		this.PopWindow(url,'popDvdSample', '', '452','471','true');
	},

	popMovieSample:function() {
		var url = '/main/order/popMovieSample.jsp';		
		this.PopWindow(url,'popMovieSample', '', '452','471','true');
	},
	popWeddingSample:function() {
		var url = '/main/order/popWeddingSample.jsp';		
		this.PopWindow(url,'popWeddingSample', '', '452','471','true');
	},

	popCdSample:function() {
		var url = '/main/order/popPcSaveSample.jsp';
		
		this.PopWindow(url,'popCdSample', '', '1004','698','true');
	},

	popPcSaveSample:function() {
		this.popCdSample();
	},

	popDeliveryInfo:function(deliveryNo) {
		deliveryNo = deliveryNo.replace(/-/g,'');
		var url = 'http://www.hydex.net/ehydex/jsp/home/distribution/tracking/tracingView.jsp?InvNo=' + deliveryNo;  //현대
		if(deliveryNo.length == 12){
			url = "http://www.hanjin.co.kr/transmission/transmission.jsp?wbl_num=" + deliveryNo;  //한진
		}
		this.PopWindow(url,'popDeliveryInfo', 'resizable=yes,scrollbars=yes', '600','400','true');
	},

	outWriter: function(id, val) {
		$(id).innerHTML = val;
	},

	goHelp: function() {
		window.open('http://www.pepbox.com/main/brd/list.jsp?brd_id=faq&brd_seq=57&mode=view');
	},

	goConvertForHanatv: function(albumSeq) {
		this.PopWindow('/main/hanatv/requestConvertForm.jsp?albumSeq=' + albumSeq,'hanatvpop', '', '400','300','true');
	}
}