var membershipPath = "";
//제품 퀵뷰
function go_PrdtQuickView(prdtCd){
	$('#dialogA').dialog('destroy');
	$('#QuickViewLoad').load("/product/quick_view.jsp?prdtCd="+prdtCd);

}
//제품 퀵뷰_유형별
function go_PrdtQuickView(prdtCd,lineNm){
	$('#dialogA').dialog('destroy');
	if (lineNm != null && lineNm != '')
	{
		$('#QuickViewLoad').load("/product/quick_view.jsp?prdtCd="+prdtCd+"&lineNm="+encodeURL(lineNm));
	}else{
		$('#QuickViewLoad').load("/product/quick_view.jsp?prdtCd="+prdtCd);
	}
}
//제품크게보기
function BigImgView(prdtCd){
	//$('#dialogA').dialog('destroy');
	openDialog("/product/bigImgView.jsp?prdtCd="+prdtCd);
}


//gateway 팝업
function go_gateway(gate){
	$('#dialogA').dialog('destroy');
	$('#GateDiv').load("/gateway_pop.jsp?gate="+gate);
	return;
}

//gateway 팝업 닫기
function go_gatewayClose(){
	$('#dialogA').dialog('destroy');
	return;
}


//공통기능 

//프린트
function go_Print(){
	print();
}


//제품바로가기
function goPrdView(prdtCd){
	location.href="/product/detail.jsp?prdtCd="+prdtCd;
}

//제품바로가기_유형별
function goPrdView(prdtCd,lineNm,lineCd){
	if (lineNm != null && lineNm != '' && lineCd != null && lineCd != '')
	{
		location.href="/product/detail.jsp?prdtCd="+prdtCd+"&lineNm="+encodeURL(lineNm)+"&lineCd="+lineCd;;
	}else{
		location.href="/product/detail.jsp?prdtCd="+prdtCd;
	}

}


//Ashop
function go_Ashop(prdtCd){
	alert("Ashop");
}

function go_Qna(siteCd,prdtCd){
	goMS("PDCS",siteCd);
	//alert("상품문의 : "+siteCd + " | " + prdtCd);
}



//문진
function go_Munjin(siteCd){
	goMS("BTSN",siteCd);
}

/* 2010-04-29 영문에서 사용안하는 Javascript Function
//구입처.
function go_Store(siteCd,prdtCd){
	$('#dialogA').dialog('destroy');
	openDialog("/util/store/storeLayer.jsp");
}


//구입처.
function go_Store(){
	$('#dialogA').dialog('destroy');
	openDialog("/util/store/storeLayer.jsp");
}


function goMS(MSTP,siteCd){
	var jspURL;

	switch( MSTP ) {
		case 'MYPG' : 
			jspURL	= membershipPath + "mypage/index.jsp?siteCd=" + siteCd;
			break;
		case 'BTPT' : 
			jspURL	= membershipPath + "mypage/benefit/btyPoint.jsp?siteCd=" + siteCd;
			break;
		case 'SHCS' : 
			jspURL	= membershipPath + "utility/counselor/counselorFind.jsp?siteCd=" + siteCd;
			break;
		case 'SHST' : 
			jspURL	= membershipPath + "utility/findstore/findstore.jsp?siteCd=" + siteCd;
			break;
		case 'FIID' : 
			jspURL	= membershipPath + "member/findid/findid.jsp?siteCd=" + siteCd;
			break;
		case 'FIPW' : 
			jspURL	= membershipPath + "member/findpw/findpw.jsp?siteCd=" + siteCd;
			break;
		case 'MBJN' : 
			jspURL	= membershipPath + "member/join/join.jsp?siteCd=" + siteCd;
			break;
		case 'BTSN' : 
			jspURL	= membershipPath + "fun/beautynSolutions/index.jsp?siteCd=" + siteCd;
			break;
		case 'PDCS' : 
			jspURL	= membershipPath + "utility/custservice/counselForm.jsp?siteCd=" + siteCd;
			break;
		case 'SVAM' :	//서비스이용약관
			jspURL	= membershipPath + "utility/service/agreement.jsp?siteCd=" + siteCd;
			break;
		case 'SVPP' :	//개인정보취급방침
			jspURL	= membershipPath + "utility/service/privacyPolicy.jsp?siteCd=" + siteCd;
			break;
		case 'CSFQ' :	//고객서비스센터
			jspURL	= membershipPath + "utility/custservice/faq.jsp?siteCd=" + siteCd;
			break;
		case 'RNAC' :	//약관동의,실명인증 2010.04.02 C9요청 추가.
			jspURL	= membershipPath + "member/login/realNameAuth.jsp?siteCd=" + siteCd;
			break;
		default : 
			jspURL	= "about:blank";
	}

		var MSpopup = window.open(  jspURL, 'MemberShip' );
		MSpopup.focus();
}
*/

//글로벌 사이트 띄우기
function goLang(url){
	var GlobalURL = url;
		var GLOBALpopup = window.open(  GlobalURL );
		GLOBALpopup.focus();
}

function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}

/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/

function decodeURL(str){
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }

    return s0;
}


//레퍼런스 소실방지 Script
function refRedirect(endTarget) {
	var logtrk_goURL = endTarget;
	// 아래라인은수정하지않습니다.
	var logtrk_ref = ""+document.referrer.replace(/\?/g, "%3F" ).replace(/&/g, "%26");
	var logtrk_param = ""+document.location.search.substr(1);
	if( logtrk_param != "" ) {
		if( logtrk_goURL.indexOf( "?" ) > 0 ) {
			logtrk_goURL = logtrk_goURL + "&" + logtrk_param;
		} else {
			logtrk_goURL = logtrk_goURL + "?" + logtrk_param;
		}
	}
	if( logtrk_ref != "" ) {
		if( logtrk_goURL.indexOf( "?" ) > 0 ) {
			logtrk_goURL = logtrk_goURL + "&source=" + logtrk_ref;
		} else {
			logtrk_goURL = logtrk_goURL + "?source=" + logtrk_ref;
		}
	}
	document.location = logtrk_goURL;
}

// form reset
function cancel(f){
	f.reset();
}
//문자열 자르기
function cutStr(str,limit){
	var tmpStr = str;
	var byte_count = 0;
	var len = str.length;
	var dot = "";

	for(i=0; i<len; i++){
		byte_count += chr_byte(str.charAt(i)); 
		if(byte_count == limit-1){
			if(chr_byte(str.charAt(i+1)) == 2){
				tmpStr = str.substring(0,i+1);
				dot = "..";
			}else {
				if(i+2 != len) dot = "..";
				tmpStr = str.substring(0,i+2);
			}
			break;
		}else if(byte_count == limit){
			if(i+1 != len) dot = "...";
			tmpStr = str.substring(0,i+1);
			break;
		}
	}
	return tmpStr+dot;
}

function chr_byte(chr){
	if(escape(chr).length > 4)
		return 2;
	else
	return 1;
}

//팝업 창 닫기
function fncPopClose(){
	window.close();
}

//키워드로 찾는 차로 리턴하기
function goKeywordSearch(strKeyword){
	document.location.href = "/product/product_search.jsp?keyword=" + encodeURIComponent(strKeyword);
}

// 이미지 가로세로 조절
function adjustImageWidth(target_img, maxWidth, maxHeight)
{
    var newHeight, newWidth;
    var newImg;
    newImg = new Image();
    newImg.src = target_img.src;
    imgw = newImg.width;
    imgh = newImg.height;
    if (imgw > maxWidth)
	{
        newWidth = maxWidth;
        newHeight = imgh;
        newWidth = Math.min(newWidth, Math.round((imgw*newHeight)/imgh));
        newHeight = Math.min(Math.round((imgh*newWidth)/imgw), newHeight);
    }
	else
	{
        newWidth = imgw;
        newHeight = imgh;
    }
    target_img.onload = null;
    target_img.src = newImg.src;
    target_img.width = newWidth;
    target_img.height = newHeight;
}

function adjustImageHeight(target_img, maxHeight)
{
    var newHeight, newWidth;
    var newImg;
    newImg = new Image();
    newImg.src = target_img.src;
    imgh = newImg.height;
	
    if (imgh > maxHeight)
        newHeight = maxHeight;

    target_img.height = newHeight;
}

function setCookie(name, value, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie; 
}


function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
	begin = dc.indexOf(prefix);
	if (begin != 0) return null;
	} else
	begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}
	
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
	document.cookie = name + "=" +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

/**
* 탭이미지에 마우스 오버, 아웃 이벤트 부여하여 롤오버효과 주기
*/
$.fn.tabImgOverNOut = function(){
	$("img[src*=off]", this).each(function(){
		$(this).bind("mouseover", function(){
			$(this).attr("src", $(this).attr("src").replace("_off", "_on"));
		});
		$(this).bind("mouseout", function(){
			$(this).attr("src", $(this).attr("src").replace("_on", "_off"));
		});
	});
};
