var rtnURL		= "";
var membershipPath = "";

//글로벌 사이트 띄우기
function goLang(LangType){
	var GlobalURL;

	switch( LangType ) {
		case 'K' : 
			GlobalURL	= "http://www.sulwhasoo.co.kr";	//운영
			//GlobalURL	= "http://220.64.135.40:8107";	//운영 TEST
			break;
		case 'E' : 
			GlobalURL	= "http://www.sulwhasoo.com/main.jsp";	//운영
			//GlobalURL	= "http://220.64.135.40:8110";	//운영 TEST
			break;
		case 'HC' : 
			GlobalURL	= "http://www.sulwhasoo.com.hk/main.jsp";	//운영
			//GlobalURL	= "http://china.sulwhasoo.com/main.jsp";	//운영 임시
			//GlobalURL	= "http://220.64.135.40:8111/main.jsp";		//운영TEST
			break;
		case 'HE' : 
			GlobalURL	= "http://www.sulwhasoo.com.hk/en/main.jsp";	//운영
			//GlobalURL	= "http://china.sulwhasoo.com/en/main.jsp";		//운영 임시
			//GlobalURL	= "http://220.64.135.40:8111/en/main.jsp";		//운영TEST
			break;
		case 'CN' : 
			GlobalURL	= "http://www.sulwhasoo.com.cn/main.jsp";	//운영
			//GlobalURL	= "http://220.64.86.41:8134/main.jsp";		//운영TEST
			break;

	}
		//var GLOBALpopup = window.open(  GlobalURL, 'Global' );
		var GLOBALpopup = window.open(  GlobalURL );
		GLOBALpopup.focus();

}

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

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

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


//사이트 문의
function go_inquiry(){
	$('#dialogA').dialog('destroy');
	openDialog("/util/inquiry/customer_inquiry.jsp");
	return;
}

//사이트 문의 레이어 팝업 닫기
function go_inquiryClose(){
	$('#dialogA').dialog('destroy');
	return;
}

//트위터
function go_Twitter(twTitle, twURL){
	window.open("http://twitter.com/home?status="+encodeURL(twTitle)+" | "+encodeURL(twURL), "SNSWINDOW","");
}
//미투데이
function go_Me2day(twTitle, twURL, tag){
	window.open("http://me2day.net/posts/new?new_post[body]="+encodeURL(twTitle)+" | "+encodeURL(twURL)+"&new_post[tags]="+encodeURL(tag), "SNSWINDOW","");
}

//제품바로가기
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;
	}

}

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();
}

//URL 체크하여 대표도메인 certiDomain(www.sulwhasoo.com.hk)이 아니면 무조건 certiDomain(www.sulwhasoo.com.hk)main으로 보내기
function goURLCheck(){	
	var addr = document.location.href;
	
	chinaCheckAddr = addr;
	chinaCheckAddr = chinaCheckAddr.replace("http://","");

	chinaCheckAddrDgit = chinaCheckAddr.split("/");

	if (chinaCheckAddrDgit[0].search(/[^0-9]/g)!=0 || chinaCheckAddrDgit[0]== "new.sulwhasooch.co.kr"){
		
		//개발서버는 제외
	}else{
		if (chinaCheckAddrDgit[0]!="www.sulwhasoo.com.hk"){
			refRedirect("http://www.sulwhasoo.com.hk/main.jsp");
		}
	}
}

//강제 실행 스크립트
//goURLCheck(); //강제 실행시 jquery onload function과 충돌 있음. page body onload로 이동.
