function getHttprequest(URL) {
    var xmlhttp = null;

    if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    } else {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open('GET', URL,false);

    xmlhttp.onreadystatechange = function() {
        if(xmlhttp.readyState==4 && xmlhttp.status == 200 && xmlhttp.statusText=='OK') {
            responseText = xmlhttp.responseText;
        }
    };
    xmlhttp.send('');
    return responseText = xmlhttp.responseText;
}


/**
 * setTimeout 으로 이동되면 스크롤을 Event로 핸들링 처리함
 * made by ul
 */

var aMoveNodes		= [];
var pageHeight		= 0;
var movePosY		= 0;

function set_move_banner()
{
	var isNode	= false;
	var aMoveNodeIds = [];
	aMoveNodeIds[aMoveNodeIds.length] = document.getElementById('r_scroll_area') ? 'r_scroll_area' : 'scroll_banner_r';
	aMoveNodeIds[aMoveNodeIds.length] = document.getElementById('l_scroll_area') ? 'l_scroll_area' : 'scroll_banner_l';

	for(var i=0; i<aMoveNodeIds.length; i++) {
		var node = document.getElementById(aMoveNodeIds[i]);

		if(node) {
			aMoveNodes.push(node);
			isNode = true;
		}
	}

	if(!isNode) return false;

	pageHeight = document.body.scrollHeight;
	_setScroll();

	window.onscroll = _setScroll;

	function _setScroll()
	{
		var top_y = document.body.scrollTop;
		var isMove = false;

		for(var i=0; i<aMoveNodes.length; i++) {

			if(document.body.scrollHeight <= pageHeight) {
				aMoveNodes[i].style.marginTop = top_y+'px';
				movePosY = top_y; isMove = true;
			}

			if(isMove == false && movePosY > top_y) {
				aMoveNodes[i].style.marginTop = top_y+'px';
			}
		}
	}
}

function move_banner()
{
}

// 최근본상품 스크립트 시작 jsyoon 05/11/21
var timerID = null;
var np_active;
var np_speed;
var dspcnt;

function ScrollUp(){
	if(parseInt(obj[np_active].style.top) == 0){
		alert('최근 본 첫상품입니다.');
		return;
	}
	if(document.getElementById){
		if(parseInt(obj[np_active].style.top) < 0){
			obj[np_active].style.top = parseInt(obj[np_active].style.top) + np_speed + "px";
		}
		//timerID = setTimeout("ScrollUp("+np_speed+")",30);
	}
}

function ScrollDown(){
	if(document.getElementById){
		var remain_height = parseInt(obj[np_active].style.height) + (parseInt(obj[np_active].style.top));
		if(remain_height <= (dspcnt * np_speed)){
			alert('최근 본 마지막상품입니다.');
			return;
		}
		if(parseInt(obj[np_active].style.top) > document.getElementById('cont').offsetHeight - obj[np_active].offsetHeight){
			obj[np_active].style.top = parseInt(obj[np_active].style.top) - np_speed + "px";
		}
		//timerID = setTimeout("ScrollDown("+np_speed+")",30);
	}
}

function ScrollStop(){
	if(document.getElementById){
		clearTimeout(timerID);
	}
}

function ScrollPageInit(rowcnt, rowlimit) {
	var tbl_row =  document.getElementById("tbl_row0");
	var inner_width = 0;
	var inner_height = 0;
	var cont_obj;
	var tmp_obj;
	dspcnt = rowlimit;
	np_active = 0;
	if(tbl_row == undefined || rowcnt <= 0)
		return;
	else {
		//inner_width = parseInt(tbl_row.width);
		// 타이틀이미지의 크기를 불러와서 리스트 테이블 넓이로설정
		var rview_timg = new Image();
		rview_timg.src = document.getElementById("rviewpdt_img").src;
		inner_width = rview_timg.width;
		for(var i=0; i < rowcnt; i++){
			tmp_obj = document.getElementById("tbl_row" + i);
			if (tmp_obj != null) tmp_obj.width = inner_width;
		}
		//리스트 테이블 높이설정
		inner_height = parseInt(tbl_row.height);
		if(inner_width <= 0 || inner_height <= 0)
			return;
		np_speed = inner_height;
		cont_obj = document.getElementById("cont");
		cont_obj.style.width = inner_width;
		cont_obj.style.height = (rowcnt > rowlimit ? (inner_height * rowlimit + 1) : (inner_height * rowcnt + 1)) + 'px';
	}
	if(document.getElementById){
	var	obj = document.getElementById("cont").getElementsByTagName("DIV");
		obj['inner_row'].style.visibility = "visible";
		obj['inner_line'].style.visibility = "visible";
		obj['inner_row'].style.height = (inner_height * rowcnt) + 'px';
		obj['inner_row'].style.width = inner_width + 'px';
		obj['inner_row'].style.top = 0;
	}
	if(document.addEventListener){
		for(i=0;i<document.getElementsByTagName('a').length;i++){
			document.getElementsByTagName('a')[i].style.position = "relative";
		}
	}
    return obj;
}
// 최근본상품 끝

function check_gonggu()
{
	alert('공동구매 기간이 아닙니다');
}

function poll_form_submit( form )
{

        select_no_length = form.select_no.length;
	is_checked = false;

        for( i = 0; i < select_no_length; i++ )
        {
		if( form.select_no[i].checked )
		{
			is_checked = true;
			break;
		}
        }

	if( !is_checked )
	{
		alert( '설문항목을 선택해주세요.' );
		return false;
	}

	return true;
}

function sMmove( sLink )
{
	document.location.href = 'http://' + sLink;
	oWin.close();
}

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 DeleteRecentView() {
    var count = 0;
    var cnt = document.CheckBox.length;
    var obj = document.CheckBox;

    if(cnt == undefined){
        cnt = 1; //언디파인드이면 1을 강제로 주고
    }

    for (var i=0;i < cnt;i++){
        if (obj[i].checked==true){
            var url = '/Front/?url=DeleteRecentView&prdNum=' + obj[i].value;
            getHttprequest(url);
            count++;
        }
    }

    if(count == 0) {
        alert('하나는 선택하세요');
        return ;
    }

    //createHiddenIframe();
    //document.getElementById('hidden_ifr').src = '/Front/?url=DeleteRecentView&sPrdInfo=' + sPrdInfo;

    document.location.reload();
}

function notice_popup(is_popup_check, mp_width, mp_height, mp_left_p, mp_top_p, mp_scrollbars)
{
	if (getCookie("mp_is_popup") == "") {
		mp_option = 'status:false;';
		mp_option += 'dialogWidth: ' + mp_width + 'px;';
		mp_option += 'dialogHeight: ' + mp_height + 'px;';
		mp_option += 'help:no; dialogLeft:' + mp_left_p + 'px;';
		mp_option += 'dialogTop:' + mp_top_p + ';';
		mp_option += 'status:no;scroll:' + mp_scrollbars + ';';

		url = '/admin/php/d/popup_r.php';
		url_name = 'echosting_shop_pop';

		var oWin = showModelessDialog( url, window, mp_option );
	}
}

function echosting_js_init()
{
	// 좌,우측 움직이는 배너
	set_move_banner();
	//window.setInterval( "set_move_banner()", scroll_time );
	//window.setTimeout( "set_move_banner()", scroll_time );
	loginForm();
	ecFrameCheck();
}
if( window.attachEvent )  // IE의 경우
    window.attachEvent( "onload", echosting_js_init);
else  // IE가 아닌 경우.
    window.addEventListener( "load", echosting_js_init, false );




function ecFrameCheck()
{
    var aCookie = document.cookie.split(';');
    for(var i=0; i<aCookie.length; i++) {
        if(aCookie[i].indexOf('ecframe_set') >= 0) {
            var aFrameInfo = aCookie[i].split('=');
            if(opener) {
				return;
			}
            if(parent == self && aFrameInfo[1] == 'F') {
                ec_setCookie('ecframe_set', '');
                window.location.href='/Front/?return_url='+escape(new String(document.location.href));
            }
        }
    }
}

function ec_setCookie(name, value, expires, path, domain, secure)
{
    path = '/';
    expires = 0;
    if(expires != 0) {
        var dd = new Date(expires * 1000);
        var expst = '; expires='+dd.toGMTString();
    } else expst = '';

    var cookstr = name + '=' + value +
        ((expires == 0) ? '' : (expst)) +
        ((path == null) ? '' : ('; path=' + path)) +
        ((domain == null) ? '' : ('; domain=' + domain)) +
        ((secure == true) ? '; secure' : '');
    document.cookie = cookstr;
}


var login_mallid        = '';
var login_host          = '';
var login_sessionid     = '';
function loginForm()
{
	var nodes = document.getElementsByTagName('form');

	var sslUrl = getCookie('ssl_url');

	var actionUrl = sslUrl ? unescape(sslUrl) : 'https://login2.simplexi.com/echosting/shop21.php';

	for(var i=0; i < nodes.length; i++)
	{

		if(nodes[i].name != 'login_f' && nodes[i].name != 'login_frm') continue;

        if (nodes[i].name == 'login_f') {
            if (document.location.href.toString().indexOf('url=Basketlogin') > 0) {
                document.login_f.redirect_url.value = '/Front/Order/?url=Address';
            }
        }

		var inpNodes = nodes[i].getElementsByTagName('input');
		for(var j=0; j<inpNodes.length; j++) {
			if(inpNodes[j].getAttribute('name') == 'is_ssl') {
				inpNodes[j].checked = true;
				//nodes[i].action = 'https://login.simplexi.com/echosting/shop20.php?secure=login&host='+new String(document.domain);
				nodes[i].action = actionUrl+'?secure=login&host='+encodeURI(new String(document.domain));
			}
		}

		nodes[i].onsubmit = function() {
			/*alert(this.action);
			return false;*/
			createHiddenIframe();

			var nodes = this.getElementsByTagName('input');
			for(var i=0; i<nodes.length; i++) {
				if(nodes[i].name == 'redirect_url') {
					nodes[i].value = escape(nodes[i].value);
				}
			}

			this.target = 'hidden_ifr';
			return true;
		};
	}
}


function createHiddenIframe() {
	if(!document.getElementById('hidden_div')) {
        var node = document.createElement('div');
        node.id = 'hidden_div';
        node.innerHTML = '<iframe src="about:blank" name="hidden_ifr" id="hidden_ifr" width="0" height="0"></iframe>';
        node.style.display = 'none';
        document.body.appendChild(node);
    }
}

// 한글 크기를 체크하는 함수 by jsyoon
function str_size_check(str){
        var strlen = str.length;
        var bsize = 0;
        for(i=0; i<strlen; i++){
                chr =   str.charAt(i);
                // 한글이면 2를 더한다.
                if (escape(chr).length > 4)
                {
                        bsize += 2;
                }
                // 그밖의 경우는 1을 더한다.
                else
                {
                        bsize++;
                }
        }
        return bsize;
}

function check_byte(frm, maxsize, msg){
        var txtval  = frm.value;
        var bsize = 0;
        bsize = str_size_check(txtval);
        if(bsize > maxsize){
                alert(msg);
                return false;
        } else {
		return true;
	}
}

// 입력폼의 문자가 숫자인지를 체크 by jsyoon
function checkDigit(inputval)
{
        inputstr = inputval.toString();
        for ( var i=0; i < inputstr.length; i++)
        {
                var onechar = inputstr.charAt(i);
                if ((onechar < "0" || onechar > "9"))
                {
                        return false;
                }
        }
        return true;
}
// 자바스크립트 number_format jsyoon
function number_format(str)
{
	str+='';

	var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})');

	while(objRegExp.test(str))
	{
		str = str.replace(objRegExp, '$1,$2');
	}

	return str;
}

var oldActionUrl = '';
// add 장정인
// date 2005.10.19
// login.simplexi.com을(ssl) 통하여 로그인 하기
function set_ssl_login( frm )
{

	var sslUrl = getCookie('ssl_url');
	var actionUrl = sslUrl ? unescape(sslUrl) : 'https://login2.simplexi.com/echosting/shop21.php';
    if (frm.is_ssl.checked) {
    	frm.action = actionUrl+'?secure=login&host='+encodeURI(new String(document.domain));
    } else {
        frm.action = '/Front/Member/?url=login';
    }
} // end of set_ssl_login()




// object관련 script 파일
function set_Embed()
{
    var option = [];
	var src = '';
	var width = 0;
	var height = 0;
	var getType = '';

	this.init = function(src,width,height,getType) {
		this.src     = src;
		this.width    = width;
		this.height   = height;
		this.getType  = getType;
		this.parameter('movie', src);
	};

    this.parameter = function(key, value){
		option[option.length] = key+'|'+value;
    };

	this.show = function(getType) {
		var objectHtml = [];
		objectHtml.push('<object  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+this.width+'" height="'+this.height+'" >');

		for(var i=0; i<option.length; i++) {
			var opt = option[i].split('|');
			objectHtml.push('<param name="'+opt[0]+'" value="'+opt[1]+'" />');
		}
		objectHtml.push('<param name="allowScriptAccess" value="always" />');
		objectHtml.push('<embed src="'+this.src+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent" allowScriptAccess="always" width="'+this.width+'" height="'+this.height+'" name="objectTag" allowScriptAccess="always" swLiveConnect="true"></embed>');
		objectHtml.push('</object>');
		document.write(objectHtml.join(''));
	};
}

//전자보증보험 증권 내용 연결 팝업스크립트
function usafe_print(asMallId, asOrderId)
{
	var iXpos;
	var iYpos;

	iXPos = (screen.width  - 700) / 2;
	iYpos = (screen.height - 600) / 2;
	asOrderId = asOrderId.replace(/-/gi, '');
        url = "https://gateway.usafe.co.kr/esafe/InsuranceView.asp?mall_id="+asMallId+"&order_id="+asOrderId;
        winname = "uclick_win" ;
        //option = "toolbar=no location=no scrollbars=yes width=650 height=537 left="+iXpos+",top="+iYpos ;
        option = "toolbar=no location=no scrollbars=yes width=650 height=537" ;
        opener = window.open( url, winname, option ) ;
}
// 마우스 오른쪽클릭 사용금지
function disableMouseRightButton()
{
	if ((event.button==2) ||  (event.button==3))
	{
		alert("무단도용방지를 위하여 마우스 오른쪽\n\n 버튼은 사용하실 수 없습니다.");
		return false;
	}
}
//컨트롤키 및 펑션키 금지
function disableKeys()
{
	if((event.ctrlKey == true && (event.keyCode == 78 || event.keyCode == 82)) ||
		(event.keyCode >= 112 && event.keyCode <= 123))
	{
		event.keyCode = 0;
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

/**
	* 사용자 정의 함수
	*
	* @author 이경란<krlee2@simplexi.com>
	* @date 2008-05-28
	* sample
	* getLog('/front/php/b/board_list.php','myshop','c_1','')
**/
function getLog(sURL,path1,path2,path3)
{

	if (path1 == null) {
	    path1 = '';
	}
	if (path2 == null) {
	    path2 = '';
	}
	if (path3 == null) {
	    path3 = '';
	}

	if (sURL == '' && path1 == '' && path2 == '' && path3 == '' ){
		alert('sURL또는 path1또는 path2또는 path3를 입력하셔야합니다');
	}else if (sURL == ''){
		alert('sURL을 입력하셔야합니다');
	}else	if (path1 == ''&& path2 == '' && path3 == ''){
		alert('path1또는 path2를 입력하셔야합니다');
	}else if (sURL != '' && ( path1 != '' || path2 != '' || path3 != '' ) ){
        var path1_size = str_size_check(path1);
        var path2_size = str_size_check(path2);
        var path3_size = str_size_check(path3);
        var sURL_size = str_size_check(sURL);
        if(path1_size > 255) {
            alert("첫번째 인자가 너무 깁니다.");
            return;
        }
        if(path2_size > 255) {
            alert("두번째 인자가 너무 깁니다.");
            return;
        }
        if(path3_size > 255) {
            alert("세번째 인자가 너무 깁니다.");
            return;
        }
        if(sURL_size > 255) {
            alert("전달 URL의 길이가 너무 깁니다.");
            return;
        }
		location.href = "/front/php/get_log.php?sCliMode=Evnt&sURL="+sURL+"&path1="+path1+"&path2="+path2+"&path3="+path3;
	}
}


/**
 * 출석체크
 * param1 : 이벤트번호
 */
function AttendJoin(param1) {
    location.replace('/Front/Myshop/?url=setAttendEvent&param1='+param1);
}

function strchk(str, obj)
{
    if(!checkDigit(str)) {
        alert('숫자만 입력할 수 있습니다.');
        obj.value='';
        return false;
    }
}

function priceFormat (iNumber, sContryCode, numFlag){

	//나라별 소수점 정보
	var aDecimals = {
		'KR' : 0,
		'US' : 2,
		'JP' : 0,
		'CN' : 2,
		'EU' : 0
	};
	if (!numFlag) {
		numFlag = '';
	}
	return this.numberFormat(parseFloat(iNumber), aDecimals[sContryCode], '.', numFlag);
}

function numberFormat( number, decimals, dec_point, thousands_sep ) {
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? '.' : dec_point;
	var t = thousands_sep == undefined ? ',' : thousands_sep, s = n < 0 ? '-' : '';
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + '', j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}

function setPayLocation(sValue, pg_disp_type, sContryCode) {
	if (!sContryCode) sContryCode = 'KR';
	if (!pg_disp_type) pg_disp_type = 'S';
	var aData = {"KR":{"1":"\uffe6","2":"\uc6d0"},"JP":{"1":"\uffe5","2":""},"US":{"1":"\uff04","2":""},"CN":{"1":"","2":"\u5143"}};
	var aResult = aData[sContryCode];

	if (sContryCode == 'KR') {
		if (pg_disp_type == 'S') {
			aResult['2'] = '';
		} else if (pg_disp_type == 'D') {
			aResult['1'] = '';
		}
	}
	return aResult['1'] + sValue + aResult['2'];
}