var orgPage = $.cookie("nowPage")
var orgPageSize = $.cookie("pageSize")

function js_ListCD(obj) 
{
	$.cookie("orgPage", orgPage)
	$.cookie("orgPageSize", orgPageSize)
	location.href = $(obj).attr("href");
}

function js_GetContentsInfo(gidx, cate) 
{
	$.getJSON("/web/1cut_list_ajax.asp"
		, {
			"mode" : "contentsInfo"
			,"gidx" : gidx
			,"catid" : cate
			,"nowpage" : 1
			,"pagesize" : 1
			,"searchdvn" : "org_gno"
			,"searchtxt" : gidx
			,"goodstype" : "GTCD"
			,"orderby" : "new"
			,"datatype" : "userview"
		}
		, function (res) 
		{
			if (res.GOODS.length==0) 
			{
				alert("현재 데이터가 없습니다.");
				history.back();
			}
			else 
			{
				var tmpimgsrc = "";
				var cpno = "";
				$.each(res.GOODS, function (i, item) 
				{
					tmpimgsrc = (item.file_server_url) ? item.file_server_url + item.file_server_nickname + "/Thumbnail/" + item.cp_no + "/List/" + (parseInt(item.original_goods_no/100)+1) + "/" + item.original_goods_no + "/list_170.jpg" : "/upload/noimg_170.gif";
					if (cate=="`CSFW`")
					{
						$(".viewContentsCD:eq(0)").attr({"src":tmpimgsrc});
						$(".viewContentsCD:eq(1)").text(item.uci_code);
						$(".viewContentsCD:eq(2)").text(item.contents_name);
						$(".viewContentsCD:eq(7)").text(item.regist_time_org.substr(0,10));
						$("#contentsExplainCD").html(item.description);//.replaceAll("\n","<br>"));
					}
					else 
					{
						$(".viewContentsCD:eq(0)").attr({"src":tmpimgsrc});
						$(".viewContentsCD:eq(1)").text(item.uci_code);
						$(".viewContentsCD:eq(2)").text(item.cpname);
						$(".viewContentsCD:eq(3)").text(item.contents_name);
						$(".viewContentsCD:eq(4)").text(item.image_count + " cut");
						$(".viewContentsCD:eq(5)").text(item.regist_time.substr(0,10));
						//$(".viewContentsCD:eq(8)").html(item.description.replaceAll("\n","<br>"));
						$("#contentsExplainCD").html(item.description.replaceAll("\n","<br>"));
					}

					if (item.popup_url) 
					{
						$(".popuplink").click(function(){
							window.open((item.popup_url.substr(0,7)=='http://')?item.popup_url:'http://www.freegine.com' + item.popup_url, '_blank', 'scrollbars=yes,width=' + item.popup_width + ', height=' + item.popup_height);
						}).addClass("hand");
					}
					else 
					{
						$(".popuplink").hide();
					}

					if (item.cpname == "프리진")
					{
						$("#d_cpdown").show();
					}
					cpno = item.cp_no;
				});
				$(".viewContentsCD:eq(0)").load(function(){
					if ($(this).width()>170) $(this).width(170);
				});
				js_GetGoodsInfo(gidx, cate);
				js_GetLicenseUserList(gidx, cpno, "cd");
				
				js_GetSampleList("USER", gidx, "CD");
				
				// 8월 프리진CD 1만원 할인 이벤트 쿠폰
				if (cpno == "780416") $(".Oct_EvtICON").removeClass("dsnone");

				// 샘플이미지 크기 조정
				//js_SetLoadImage(".viewContentsCD:eq(8) img", 700);
			}
		}
	);
}

function js_GetGoodsInfo(gidx, cate) 
{
	$.getJSON("/web/1cut_view_act.asp"
		, {
			"mode" : "goodsInfo"
			,"gidx" : gidx
			,"catid" : cate
		}
		, function (res) 
		{
			template = $(".priceArea").html();
			var tmpHtml = "";
			var goods_apply_code = "";
			var tmpx = "";
			var tmpy = "";
			var tmpd = "";
			$.each(res.GOODS, function (i, item) 
			{
				//if (item.file_name || cate=="`CSFW`") 
				//{
					if (cate=="`CSFW`") // 소프트웨어
					{
						$(".viewContentsCD:eq(4)").text(js_GetCodeName(item.use_dvn));
						$(".viewContentsCD:eq(5)").text(js_GetCodeName(item.language_code));
						$(".viewContentsCD:eq(6)").text(js_GetCodeName(item.license_type1));
						tmpHtml += Common.format(template
							, item.goods_no
							, item.distribution_code
							, item.producer
							, item.version
							, item.os_code.substr(1,3)
							, js_AddComma(item.user_count)
							, js_AddComma(item.fixed_price)
							, js_AddComma(item.selling_price)
						);
						goods_apply_code = item.goods_apply_code;
					}
					else // 소프트웨어 이외
					{
						tmpHtml += Common.format(template
							, item.goods_no, (item.goods_apply_code), (item.distribution_code)
							, (item.dpi==999)?"Vector":item.dpi
							, (item.width_size + "x" + item.height_size == "0x0")?"Free":item.width_size + "x" + item.height_size
							, (item.file_format)
							, item.production_tool + ' ' + item.tool_version
							, js_AddComma(item.fixed_price)
                            , js_AddComma(item.selling_price));
						goods_apply_code = item.goods_apply_code;
						if (i==0) 
						{
							tmpx = item.width_size;
							tmpy = item.height_size;
							tmpd = item.dpi;
						}
						//js_SetSeparatePrice(item.selling_price);

						//최대가격 뽑기위해 살짝추가 cd : 0, 1cut : 1
						js_SetMaxPrice(item.selling_price, 0);
					}
				//}
			});
			$(".priceArea").empty().append(tmpHtml).show();
			if (goods_apply_code=="UPPT") {
				$(".priceArea").parent().find(".ppt").hide(); 
			} else {
				//if (cate!="CFLA" && cate!="CILL") 
				//{
					$(".px2cm2:eq(0)").val(tmpx);
					$(".px2cm2:eq(1)").val(tmpy);
					$(".px2cm2:eq(2)").val(tmpd);
					if (tmpx>0 && tmpy>0) js_calPx2Cm('px2cm2');
				//}
			}
			js_GetList(1);

            // 기획전 관련
            //if (location.hash=="#sadobass") 
            //{
                js_SetEventPrice(gidx);
            //}
		}
	);
}