﻿var toastBarValue = {
	docHeight:0,
	docWidth:0
}
    	
$(document).ready(function() {
	// 토스트바
	var loc = document.location.href;
	if(loc.indexOf("203.239.145.24") > -1 || loc.indexOf("203.239.145.23") > -1 || loc.indexOf("203.239.145.22") > -1 || loc.indexOf("203.239.145.21") > -1 || loc.indexOf("www.thebodyshop.co.kr") > -1 ){
		if(loc.indexOf("Bodymain.aspx") > -1 || loc.indexOf("/shop/product/first.aspx") > -1 || loc.indexOf("/brand/culture/first.aspx") > -1 || loc.indexOf("/shop/membership_no/cart.aspx") > -1 || loc.indexOf("/shop/mypage/cart.aspx") > -1 || loc.indexOf("/shop/mypage/Index.aspx") > -1 || loc == "http://www.thebodyshop.co.kr/" || loc == "http://203.239.145.21/" || loc == "http://203.239.145.22/" || loc == "http://203.239.145.23/" || loc == "http://203.239.145.24/"){
			var fixedScrollHeight = 0;
			
			// 크기 구할 레이어 생성
			$("<div/>", {
				id:"divDocSize",
				css:{
					position:"absolute",
					left:"0px",
					top:"0px",
					width:"100%",
					height:"100%",
					zIndex:0
				}
			}).appendTo($("body"));
			
			toastBarValue.docHeight = $("div.#divDocSize").height();
			toastBarValue.docWidth = $("div.#divDocSize").width();
			fixedScrollHeight = $(document).height() - $("div.#divDocSize").height();
			
			$("div#divDocSize").remove();
	
	
			//alert(toastBarValue.docHeight);
			//alert(toastBarValue.docWidth);
			//alert($("#toastBarLayer div:even").length);
			$("<div/>", {
				id:"toastBar",
				css:{
					position:"absolute",
					left:((toastBarValue.docWidth - 992) / 2) + "px",
					top:toastBarValue.docHeight + "px", //178
					width:"992px",
					height:"167px",
					//backgroundColor:"white",
					zIndex:9999
				}
			}).appendTo($("body")).html($("#toastBarLayer").html());
	
			$("#toastBarLayer").remove();
			
			/*
			$("#toastBar div:even").each(function(i){
			});
			*/

			openToastBarLayers();
				
			setTimeout(function(){
				$("#toastBar").animate({top:"-=178"}, 1000);
			}, 1100);
			
			$(window).scroll(function(e) {
				if($(document).scrollTop() > fixedScrollHeight){ return; }
				$("#toastBar").css({
					top: (((toastBarValue.docHeight - 178) + $(document).scrollTop())) + "px"
				});
			});
			
			//alert($("#toastBar").html());

		}
	}
	
	if(document.location.href.indexOf("new.aspx") > -1){
		$("p.location:eq(0)").html('<a>쇼핑홈</a><span>신제품</span>');
	}else if(document.location.href.indexOf("first_pro.aspx") > -1){
		$("p.location:eq(0)").html('<a>쇼핑홈</a><span>전제품 카테고리</span>');
	}else if(document.location.href.indexOf("event.aspx") > -1){
		$("p.location:eq(0)").html('<a>쇼핑홈</a><span>쇼핑기획전</span>');
	}else if(document.location.href.indexOf("p_raw") > -1){
		$("p.location:eq(0)").html('<a>쇼핑홈</a><span>원료별 제품</span>');
	}

/*
	$("img").each(function() {
		//alert($(this).attr("src").indexOf("png"));
		if ($(this).attr("src").indexOf("png") > -1) {
			//fixPNG(this);
		}
	});
*/

  $("ul#categorDepth>li").each(function(i){
  	$(this).mouseover(function(){
  		$("div.cateall_over:eq(" + $(this).index() + ")").show();
  	}).mouseout(function(){
  		$("div.cateall_over").hide();
  	});
  });
  
  $("div.cateall_over").each(function(i){
  	$(this).mouseover(function(){
  		$("div.cateall_over:eq(" + $(this).index() + ")").show();
  	}).mouseout(function(){
  		$(this).hide();
  	});
  });

	$("#globalKeyword").keyup(function(E){
		if(E.keyCode == 13){
			searchGlobal();
		}
	}).val("Search").click(function(E){
		if($(this).val() == "Search"){
			$(this).val("");
		}
	}).blur(function(E){
		if($(this).val() == ""){
			$(this).val("Search");
		}
	});
});

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) {
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
        var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
        var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' ";
        var imgStyle = "display:inline-block;" + myImage.style.cssText;
        var strNewHTML = "<span " + imgID + imgClass + imgTitle
                      + " style=\"" + "width:" + myImage.width
                      + "px; height:" + myImage.height
                      + "px;" + imgStyle + ";"
                      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
        myImage.outerHTML = strNewHTML;
    }
}

$(document).keydown(function(e){
//alert(e.target.nodeName);
	if(e.keyCode == 13){
		if(e.target.nodeName != "TEXTAREA")
			e.preventDefault();
	}
});

function enterPress(e, button) {
    if (e.keyCode == 13) {
        button.click();
    }
}

/*
* setLayer // div 레이어 팝업 띄우기

setLayer.show({
	id:"test",						// 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
	left:100,							// left 좌표 지정(지정하지 않으면 가로 가운데 정렬)
	top:100,							// top 좌표 지정(지정하지 않으면 세로 가운데 정렬)
	position:"absolute",	// position 지정(지정하지 않으면 "forceabsolute" -> 상위 태그 css의 position의 영향을 받지 않음 / "css"를 줄 경우 해당 레이어의 position, top, left 속성을 사용 함)
	bgcolor:"white",			// 오버레이(배경 불투명 레이어 생성 시 배경 색상 지정(지정하지 않으면 "gray")
	opacity:.4,						// 불투명도 지정(지정하지 않으면 0)
	scroll:false					// 마우스 스크롤 시 가운데 위치 교정 여부(지정하지 않으면 true / position이 forceabsolute, absolute일때만 작동)
});
		
setLayer.hide("test")		// #test 레이어 숨김(오버레이 있을 시 같이 사라짐 / 지정하지 않으면 마지막으로 생성된 레이어 숨김)

ex)
setLayer.show(); // 모든게 귀찮을 때. <div id="layerPopup">레이어</div> 를 html 내의 가로세로 가운데 위치에 띄우게 하되 스크롤이 있는 html의 경우 세로스크롤의 높이만큼 레이어 위치를 교정
setLayer.show({overlay:.4}); // 위와 같은 상황에서 레이더 뒷배경에 불투명 오버레이 적용

- require : jQuery 1.4.x
- author : saystone@wylielab.co.kr
*/
var setLayer = {
	id: "layerPopup",
	opacity: 0,
	wrapperId: "_divWrapper",
	overlayId: "_divOverlay",
	ie6Height: 0,
	show: function(options) {
		var options = (typeof arguments[0] != 'object') ? {} : arguments[0];
		options = {
			id: (typeof options.id == 'undefined') ? setLayer.id : options.id,
			left: (typeof options.left == 'undefined') ? -1 : options.left,
			top: (typeof options.top == 'undefined') ? -1 : options.top,
			opacity: (typeof options.opacity == 'undefined') ? 0 : options.opacity,
			position: (typeof options.position == 'undefined') ? "forceabsolute" : options.position,
			bgcolor: (typeof options.bgcolor == 'undefined') ? "gray" : options.bgcolor,
			scroll: (typeof options.scroll == 'undefined') ? true : options.scroll
		}

		// hide 메서드에서 사용하기 위해 셋팅
		this.id = options.id;
		this.opacity = options.opacity;

		var objLayerOverlay = $("#" + this.overlayId);
		//console.log(objLayerOverlay.length);
		if (objLayerOverlay.length == 1) {
			alert("이미 opacity를 사용하여 생성된 레이어가 존재합니다.");
			return;
		}

		var objLayer = $("#" + options.id) // 레이어의 id
		if (objLayer.length == 0) {
			alert("지정된 id 속성을 가진 레이어가 존재하지 않습니다. : " + options.id);
			return;
		}

		var docWidth = $(document).width(); // 스크롤 여백을 포함 한 document의 넓이
		var docHeight = $(document).height(); // 스크롤 여백을 포함 한 document의 높이
		var bodyHeight = $("body").height(); // 스크롤 여백을 제외 한 document의 넓이
		
		var scrollWidth = 0;

		/*
		if(typeof LOGINID != undefined){
			if(LOGINID == "saystone5"){
				alert("bodyHeight:"+bodyHeight);
				alert("docHeight:"+docHeight);
				alert("fixedHeight:"+$.height);

				bodyHeight = screen.height - 80;
				alert(bodyHeight);
				bodyHeight = document.body.offsetHeight / 2;
				alert(bodyHeight);

				var db = document.body;
				var dde = document.documentElement;

				var docHeight_ = Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight)
				alert(docHeight_);
			}
		}
		*/

		if ($.browser.msie) {
			scrollWidth = 20;
			if(parseInt($.browser.version) == 6){
				$("select").hide();
				//bodyHeight = (bodyHeight / 2) - 100;
				//bodyHeight = screen.height - 200;
				//bodyHeight = document.body.offsetHeight / 2;
				/*
				if(options.id == "popup" || options.id == "pop") {
					alert(bodyHeight);
					bodyHeight = bodyHeight -20;
					alert(bodyHeight);
				}	
				*/							
				
				var tempHeight = "";
				if(setLayer.ie6Height == 0){
					tempHeight = "100%";
				}else{
					tempHeight = setLayer.ie6Height + "px";
				}

				$("<div/>", {
					id:"tempHeight",
					css:{
						position:"absolute",
						left:"0px",
						top:"0px",
						width:"1px",
						height:tempHeight,
						zIndex:0
					}
				}).appendTo($("body"));

				if(setLayer.ie6Height == 0){
					setLayer.ie6Height = $("div#tempHeight").height();
					bodyHeight = $("div#tempHeight").height();
				}else{
					bodyHeight = setLayer.ie6Height;
				}
			}
		}
		var docScrollTop = $(document).scrollTop();
		//alert(docScrollTop);
		//console.log(docScrollTop);

		var layerWidth = objLayer.width(); // 레이어의 넓이
		var layerHeight = objLayer.height(); // 레이어의 높이

		var positionLeft, positionTop;
		// left 위치 지정 하지 않으면 가로 센터 정렬
		if (options.left == -1) {
			positionLeft = (docWidth - layerWidth) / 2 // 가로 가운데 정렬
		} else {
			positionLeft = options.left;
		}

		// top 위치 지정 하지 않으면 세로 센터 정렬
		if (options.top == -1) {
			positionTop = ((bodyHeight - layerHeight) / 2) + docScrollTop // 세로 가운데 정렬
		} else {
			positionTop = options.top;
		}


		// 해당 레이어의 css 속성을 따름
		if (options.position == "css") {
			options.position = objLayer.css("position");
			options.left = objLayer.css("left").replace(/\px/gi, "");
			options.top = objLayer.css("top").replace(/\px/gi, "");
		// 어떤 상위 태그의 position 속성에도 영향을 받지 않도록 body 밑에 래핑 레이어 생성
		} else if (options.position == "forceabsolute") {
			$("<div/>", {
				id: setLayer.wrapperId,
				css: {
				position: "absolute",
				left: positionLeft + "px",
				top: positionTop + "px",
				width: objLayer.width() + "px",
				height: objLayer.height() + "px",
				zIndex: 10000
			}
			}).appendTo("body").html(objLayer.html());

		}

		if (options.position == "forceabsolute"){
			objLayer = $("#" + this.wrapperId);
		}else{
			objLayer.css({
				position: options.position,
				left: positionLeft + "px",
				top: positionTop + "px",
				zIndex: 10001
			}).show();
		}

		// 스크롤 높이에 따라 세로 가운데 정렬
		if (options.position == "absolute" || options.position == "forceabsolute") {
			if (options.scroll == true) {
				$(window).scroll(function(e) {
						//console.log(((bodyHeight - layerHeight) / 2) + $(document).scrollTop());
						objLayer.css({
						top: (((bodyHeight - layerHeight) / 2) + $(document).scrollTop()) + "px"
					});
				});
			}
		}

		// opacity 값을 셋팅 했을때만 오버레이 레이어 생성
		if (options.opacity > 0) {
			$("<div/>", {
				id: setLayer.overlayId,
				css: {
					position: "absolute",
					left: 0,
					top: 0,
					width: (docWidth - scrollWidth) + "px",
					height: docHeight + "px",
					backgroundColor: options.bgcolor,
					display: "none",
					opacity: options.opacity,
					zIndex: 9999
				}
			}).appendTo("body").fadeIn(300);
		}
	},
	hide: function(id) {
		var id = (typeof id == 'undefined') ? setLayer.id : id;

		if (this.opacity == 0) {
			$("#" + id).hide();
			// 로그인 레이어 예외처리..
			if($("#_divOverlay").length > 0){
				$("#_divOverlay").fadeOut(300, function() {
					$(this).remove();
					if ($.browser.msie) {
						if(parseInt($.browser.version) == 6){
							if($("p.location:eq(0) select").length > 0){
								$("p.location:eq(1)").hide();
								$("p.location:eq(0)").show();
							}
						}
					}
				});
			}
		} else {
			try{
				console.log(id);
			}catch(E){
			}
			
			$("#" + id).hide();
			$("#" + setLayer.overlayId).fadeOut(300, function() {
				$(this).remove();
			});
		}

		$("#" + this.wrapperId).remove();


		if ($.browser.msie) {
			if(parseInt($.browser.version) == 6){
				$("select").show();				

				$("div#tempHeight").remove();
			}
		}
	}
}
//보물찾기 팝업
function open_treasure_pop()
{
if ((version >= 5.5) && (version < 7)) {
  setLayer.show({
    id: "divTreasure",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
    left: 200,
    top: 50,
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
}else {
  setLayer.show({
    id: "divTreasure",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
}
}


function open_loung_pop()
{
  setLayer.show({
    id: "LoungPop",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
}

function open_login_pop()
{
	/*
  setLayer.show({
    id: "popWrap",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
	*/
	var docWidth = $(document).width(); // 스크롤 여백을 포함 한 document의 넓이
	var docHeight = $(document).height(); // 스크롤 여백을 포함 한 document의 높이
	var scrollWidth = 0;

	if ($.browser.msie) {
		// 스크롤바 넓이 추가
		scrollWidth = 20;
	}
	
	$("<div/>", {
		id: "_divOverlay",
		css: {
			position: "absolute",
			left: 0,
			top: 0,
			width: (docWidth - scrollWidth) + "px",
			height: docHeight + "px",
			backgroundColor: "gray",
			display: "none",
			opacity: .5,
			zIndex: 9999
		}
	}).appendTo("body").fadeIn(300, function(){
		$("iframe[name=ifrLogin]").attr("src", "/membership/login_pop.aspx");
		$("#popLogin").show();
		
		// 셀렉트박스 예외처리
		if ($.browser.msie) {
			if(parseInt($.browser.version) == 6){
				if($("p.location:eq(0) select").length > 0){
					var dep1 = "<span>" + $('p.location:eq(0)>select:eq(0)>option:selected').text() + "</span>";
					var dep2 = "&nbsp;&gt;&nbsp;<span>" + $('p.location:eq(0)>select:eq(1)>option:selected').text() + "</span>";
					$("p.location:eq(1)").html('<div style="padding-top:3px;"><a>쇼핑홈</a>' + dep1 + dep2 + "</div>");
					$("p.location:eq(1)").show().css("height","17px");
					$("p.location:eq(0)").hide();
				}
			}
		}
		
		try{
			$.scrollTo(0, 500);
		}catch(E){
			window.scrollTo(0);
		}
	});
}

function open_preview_pop()
{
  setLayer.show({
    id: "showPop",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
}

function open_quantity_pop()
{
  setLayer.show({
    id: "popQuantity",     // 띄울 레이어의 id 지정(지정하지 않으면 #layerPopup 을 사용)
  	opacity: .5     // 불투명도 지정(지정하지 않으면 0)
  });
}

function open_quickshopping_pop(){
	$("iframe[name=ifrQuickShopping]").attr("src", "/shop/product/first_layer.aspx");
	setLayer.show({
		id:'popQuickShopping',
		opacity:.5
	});
}

function open_shoppingbag_pop(){
	$("iframe[name=ifrShoppingBag]").attr("src", "/shop/product/my_layer.aspx");
	setLayer.show({
		id:'popShoppingBag',
		opacity:.5
	});
}

function open_myshopping_pop(){
	if(document.getElementById('popMyShopping').style.display != 'none') {
		$('#ctl00_cphLocation_ucShop_Location1_ddlNavi').show();		
		$('#ctl00_cphLocation_ucShop_Location1_ddlNaviSub').show();		

		
		$('#popMyShopping').hide();
	}
	else {
		$('#ctl00_cphLocation_ucShop_Location1_ddlNavi').hide();		
		$('#ctl00_cphLocation_ucShop_Location1_ddlNaviSub').hide();		
		$('#popMyShopping').show();
		
	}

}

function close_myshopping_pop(){	
	$('#popMyShopping').hide();
	
}

function commaNum(num) {
	if (num < 0) { num *= -1; var minus = true }
	else var minus = false
	var dotPos = (num + "").split(".")
	var dotU = dotPos[0]
	var dotD = dotPos[1]
	var commaFlag = dotU.length % 3

	if (commaFlag) {
		var out = dotU.substring(0, commaFlag)
		if (dotU.length > 3) out += ","
	}
	else var out = ""
	for (var i = commaFlag; i < dotU.length; i += 3) {
		out += dotU.substring(i, i + 3)
		if (i < dotU.length - 3) out += ","
	}
	if (minus) out = "-" + out
	if (dotD) return out + "." + dotD
	else return out
}

function getItem(category, type){
	if(LOGINID == ""){
	    
                if(type == 1){
			    var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		        if(confirm(msg)){
			        if(category == "product"){
				        open_login_pop();
			        }else if(category == "quick"){
				        parent.setLayer.hide();
				        setTimeout(function(){
					        open_login_pop();
				        }, 200);
			        }
			        return;
		        }
		    }else if(type == 2){
			    var selector = "", PCD = "", url = "", msg = "";
    		
		        if(category == "product"){
			        selector = "ul.pro-list input[type=checkbox]:checked";
		        }else if(category == "quick"){
			        selector = "";
		        }
        		
		        
			url = "/shop/membership_no/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
		        
        		
		        $(selector).each(function(i){
			        PCD += $(this).val() + ",";
		        });
        	
		        if(PCD == ""){
			        alert("제품을 선택해 주세요.");
			        return;
		        }
        		
		        $.post("/shop/product/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			        if($.trim(result) == "success"){
				        if(type == 2 || type == 3){
					        if(confirm(msg)){
						        if(category == "product"){
							        document.location.href = url;
						        }else if(category == "quick"){
							        window.open(url);
						        }
					        }
				        }else if(type == 1){
					        document.location.href = url;
				        }
			        }else{
			        	if(type == 2){
					    		alert("제품코드 [" + result + "]는 현재 재고가 없습니다.");
					    	}
					    }
		        }, "text");
		    }else if(type == 3){
			    var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		        if(confirm(msg)){
			        if(category == "product"){
				        open_login_pop();
			        }else if(category == "quick"){
				        parent.setLayer.hide();
				        setTimeout(function(){
					        open_login_pop();
				        }, 200);
			        }
			        return;
		        }
		    }
		
                /*var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		        if(confirm(msg)){
			        if(category == "product"){
				        open_login_pop();
			        }else if(category == "quick"){
				        parent.setLayer.hide();
				        setTimeout(function(){
					        open_login_pop();
				        }, 200);
			        }
			        return;
		        }
		*/
	}else{
		var selector = "", PCD = "", url = "", msg = "";
		
		if(category == "product"){
			selector = "ul.pro-list input[type=checkbox]:checked";
		}else if(category == "quick"){
			selector = "";
		}
		
		if(type == 1){
			url = "/shop/pay/order.aspx";
		}else if(type == 2){
			url = "/shop/mypage/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
		}else if(type == 3){
			url = "/shop/mypage/wishlist.aspx";
			msg = "위시리스트에 제품을 담았습니다.\n\n확인 하시겠습니까?"
		}
		
		$(selector).each(function(i){
			PCD += $(this).val() + ",";
		});
	
		if(PCD == ""){
			alert("제품을 선택해 주세요.");
			return;
		}
		
		$.post("/shop/product/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			if($.trim(result) == "success"){
				if(type == 2 || type == 3){
					if(confirm(msg)){
						if(category == "product"){
							document.location.href = url;
						}else if(category == "quick"){
							window.open(url);
						}
					}
				}else if(type == 1){
					document.location.href = url;
				}
			}
		}, "text");
	}
}

function getItemSingle(type, PCD){
	if(LOGINID == ""){
	   
		var category = "product";
		
		if(type == 1){
			var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		    if(confirm(msg))
		    {
			    open_login_pop();
			    return;
		    }
		}else if(type == 2){
			url = "/shop/membership_no/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
			$.post("/shop/product/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			    if($.trim(result) == "success"){
				    if(type == 2 || type == 3){
					    if(confirm(msg)){
						    if(category == "product"){
							    document.location.href = url;
						    }else if(category == "quick"){
							    window.open(url);
						    }
					    }
				    }else if(type == 1){
					    document.location.href = url;
				    }
			    }else{
	        	if(type == 2){
			    		alert("제품코드 [" + result + "]는 현재 재고가 없습니다.");
			    	}
			    }
		    }, "text");
		}else if(type == 3){
			var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		    if(confirm(msg))
		    {
			    open_login_pop();
			    return;
		    }
		}
	    /*
		var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
		if(confirm(msg))
		{
			open_login_pop();
			return;
		}
	    */
	}else{
		var category = "product";
		
		if(type == 1){
			url = "/shop/pay/order.aspx";
		}else if(type == 2){
			url = "/shop/mypage/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
		}else if(type == 3){
			url = "/shop/mypage/wishlist.aspx";
			msg = "위시리스트에 제품을 담았습니다.\n\n확인 하시겠습니까?"
		}
	
		$.post("/shop/product/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			if($.trim(result) == "success"){
				if(type == 2 || type == 3){
					if(confirm(msg)){
						if(category == "product"){
							document.location.href = url;
						}else if(category == "quick"){
							window.open(url);
						}
					}
				}else if(type == 1){
					document.location.href = url;
				}
			}
		}, "text");
	}
}

function zoomImage(ImageUrl){
	$("#zoomedImage").attr("src", ImageUrl);
	
	setLayer.show({
		id:'zoomImage',
		opacity: .5
	});
}

function searchGlobal(){
	$("#hiddenKeyword").val($("#globalKeyword").val());
	document.searchGlobal.submit();
}

function searchGlobalByValue(v){
	$("#hiddenKeyword").val(v);
	document.searchGlobal.submit();
}

function copyToClipboard(targetText){
	if (window.clipboardData){
	  window.clipboardData.setData("Text", targetText);
	}else if (window.netscape){
	  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
	  var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
	  if (!clip) return;
	  var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
	  if (!trans) return;
	  trans.addDataFlavor('text/unicode');
	  var str = new Object();
	  var len = new Object();
	  var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
	  var copytext = targetText;
	  str.data = copytext;
	  trans.setTransferData("text/unicode",str,copytext.length*2);
	  var clipid=Components.interfaces.nsIClipboard;
	  if (!clip) return false;
	  clip.setData(trans,null,clipid.kGlobalClipboard);
	}
	
	return false;
}

function quick_login(){
	setTimeout('open_login_pop()', 500);
}

function getCookie( name ) 
{ 
	var nameOfCookie = name + "="; 
	var x = 0; 
	while ( x <= document.cookie.length ) 
	{ 
		var y = (x+nameOfCookie.length); 
		if ( document.cookie.substring( x, y ) == nameOfCookie ) { 
				if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) 
						endOfCookie = document.cookie.length; 
				return unescape( document.cookie.substring( y, endOfCookie ) ); 
		} 
		x = document.cookie.indexOf( " ", x ) + 1; 
		if ( x == 0 ) 
				break; 
	 } 
	 return ""; 
}

function setCookie(name, value, expiredays)
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
	
function closeCookieLayer(CookieAndId){
	setCookie(CookieAndId, "done" , 1);
	$("#" + CookieAndId.toString()).hide();
}

function closeCookieLayer2(c, i){
	setCookie(c, "done" , 1);
	$("#" + i.toString()).hide();
}

/* 화면 가운데에 팝업
popc('압업주소','팝업이름', 가로, 세로, '스크롤여부'); */
function popc(Address, name, w, h, scroll){
	var scr = (scroll=="") ? "yes" : "no";
	var popwindow = null;
	var LeftPosition = (screen.width) ? (screen.width-w)/2:0;
	var TopPosition = (screen.height) ? (screen.height-h)/2:0;   
	var settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scr + ',resizable=no'
	popwindow = window.open(Address, name, settings);
	popwindow.focus();
}

/* 좌표 받는 팝업
pop('압업주소','팝업이름', 가로, 세로, 가로축, 세로축, '스크롤여부'); */
function pop(Address, name, w, h, l, t, scroll){
	var scr = "";
	if(scroll == ""){
		scr = "no";
	}else{
		scr = "yes";
	}
	var left = (l=="") ? 0 : l;
	var top = (t=="") ? 0 : t;
	var popwindow = null;
	var settings = 'height=' + h + ',width=' + w + ',top=' + top + ',left=' + left + ',scrollbars=' + scr + ',resizable=no'
	popwindow = window.open(Address, name, settings);
	popwindow.focus();
}

function getItemCL(category, type){
	if(LOGINID == ""){
		if(type == 1){
	    var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
        if(confirm(msg)){
	        if(category == "product"){
		        open_login_pop();
	        }else if(category == "quick"){
		        parent.setLayer.hide();
		        setTimeout(function(){
			        open_login_pop();
		        }, 200);
	        }
	        return;
        }
    }else if(type == 2){
	    var selector = "", PCD = "", url = "", msg = "";
		
      if(category == "product"){
        selector = "ul.pro-list input[type=checkbox]:checked";
      }else if(category == "quick"){
        selector = "";
      }
  		
      if(type == 1){
        url = "/order/order.aspx";
      }else if(type == 2){
        url = "/order/cart.aspx";
        msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
      }else if(type == 3){
        url = "/order/wishlist.aspx";
        msg = "위시리스트에 제품을 담았습니다.\n\n확인 하시겠습니까?"
      }
  		
      $(selector).each(function(i){
        PCD += $(this).val() + ",";
      });
  	
      if(PCD == ""){
        alert("제품을 선택해 주세요.");
        return;
      }
  		
      $.post("/division/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
        if($.trim(result) == "success"){
	        if(type == 2 || type == 3){
		        if(confirm(msg)){
			        if(category == "product"){
				        document.location.href = url;
			        }else if(category == "quick"){
				        window.open(url);
			        }
		        }
	        }else if(type == 1){
		        document.location.href = url;
	        }
        }
      }, "text");
    }else if(type == 3){
	    var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
      if(confirm(msg)){
        if(category == "product"){
	        open_login_pop();
        }else if(category == "quick"){
	        parent.setLayer.hide();
	        setTimeout(function(){
		        open_login_pop();
	        }, 200);
        }
        return;
      }
    }
	}else{
		var selector = "", PCD = "", url = "", msg = "";
		
		if(category == "product"){
			selector = "ul.pro-list input[type=checkbox]:checked";
		}else if(category == "quick"){
			selector = "";
		}
		
		if(type == 1){
			url = "/order/order.aspx";
		}else if(type == 2){
			url = "/order/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
		}else if(type == 3){
			url = "/order/wishlist.aspx";
			msg = "위시리스트에 제품을 담았습니다.\n\n확인 하시겠습니까?"
		}
		
		$(selector).each(function(i){
			PCD += $(this).val() + ",";
		});
	
		if(PCD == ""){
			alert("제품을 선택해 주세요.");
			return;
		}
		
		$.post("/division/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			if($.trim(result) == "success"){
				if(type == 2 || type == 3){
					if(confirm(msg)){
						if(category == "product"){
							document.location.href = url;
						}else if(category == "quick"){
							window.open(url);
						}
					}
				}else if(type == 1){
					document.location.href = url;
				}
			}
		}, "text");
	}
}

function getItemSingleCL(type, PCD){
	if(LOGINID == ""){
		var category = "product";
		
		if(type == 1){
			var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
	    if(confirm(msg))
	    {
		    open_login_pop();
		    return;
	    }
		}else if(type == 2){
			url = "/order/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
			$.post("/division/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			    if($.trim(result) == "success"){
				    if(type == 2 || type == 3){
					    if(confirm(msg)){
						    if(category == "product"){
							    document.location.href = url;
						    }else if(category == "quick"){
							    window.open(url);
						    }
					    }
				    }else if(type == 1){
					    document.location.href = url;
				    }
			    }
		    }, "text");
		}else if(type == 3){
			var msg = "더바디샵 회원만 이용 가능 합니다.\n\n지금 로그인 하시겠습니까?";
	    if(confirm(msg))
	    {
		    open_login_pop();
		    return;
	    }
		}
	}else{
		var category = "product";
		
		if(type == 1){
			url = "/order/order.aspx";
		}else if(type == 2){
			url = "/order/cart.aspx";
			msg = "장바구니에 제품을 담았습니다.\n\n확인 하시겠습니까?";
		}else if(type == 3){
			url = "/order/wishlist.aspx";
			msg = "위시리스트에 제품을 담았습니다.\n\n확인 하시겠습니까?"
		}
	
		$.post("/division/commonShop_ajax.aspx", { type : type, PCD : PCD + "," }, function(result){
			if($.trim(result) == "success"){
				if(type == 2 || type == 3){
					if(confirm(msg)){
						if(category == "product"){
							document.location.href = url;
						}else if(category == "quick"){
							window.open(url);
						}
					}
				}else if(type == 1){
					document.location.href = url;
				}
			}
		}, "text");
	}
}

