// 플래시메뉴 와 플래시관련

function JS_viewObj(objhtml){
	document.write(objhtml);
}
function flashWrite(url,w,h,id,bg,vars,win){

 var flashStr=
 "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
 "<param name='allowScriptAccess' value='always' />"+
 "<param name='movie' value='"+url+"' />"+
 "<param name='FlashVars' value='"+vars+"' />"+
 "<param name='wmode' value='"+win+"' />"+
 "<param name='menu' value='false' />"+
 "<param name='quality' value='high' />"+
 "<param name='bgcolor' value='"+bg+"' />"+
 "<embed src='"+url+"' FlashVars='"+vars+"' wmode='"+win+"' menu='false' quality='high' bgcolor='"+bg+"' width='"+w+"' height='"+h+"' name='"+id+"' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
 "</object>";
 document.write(flashStr);

}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);



 
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_showHideLayers() { //v3.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
obj.visibility=v; }
}

 

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}



//첩부글 아이콘
function listview_icon() {
	iconview.style.visibility = 'visible';
}

function select_icon(i) {
	document.newicon.src = '../images/emoticon_face'+i+'.gif';
	iconview.style.visibility = 'hidden';
}

function select_menu() {
alert("ff");
}

//init_layer('<?=$inited_layer?>'); //서브메뉴레이어
 


// 클릭하면 본문보이기
function remarkview(id) {
	eval("document.all.remark"+id).style.display = "";
	eval("document.all.remarkd"+id).style.display = "";
}
function remarkhidd(id) {
	eval("document.all.remark"+id).style.display = "none";
	eval("document.all.remarkd"+id).style.display = "none";
}


// 팝업창 띄우기
var gonggi1 = null;
var imgwin = null;

function open_notice(url) {
	var notice = window.open ( url, "notice", "toolbar=no, menubar=no, scrollbars=no, resizable=no, width=505, height=452, left=200, top=0");
}

function open_win1(url,fromwin,w,h) {
  
if (fromwin == 1){  
  if (imgwin != null){ 
    imgwin.close();
  }
  	
  if ( !gonggi1 || gonggi1.closed ){ 
     gonggi1=window.open ( url, "gonggi1", "toolbar=no, menubar=no, scrollbars=yes, resizable=no, width=" + w + ", height=" + h + ", left=200, top=0");
  }else{
     gonggi1.location.href = url; 
  } 
 
}else{
 
  if (gonggi1 != null){ 
    gonggi1.close();
  }
    
  if ( !imgwin || imgwin.closed ){ 
     imgwin=window.open ( url, "imgwin", "toolbar=no, menubar=no, scrollbars=no, resizable=no, width=" + w + ", height=" + h + ", left=200, top=0");
  }else{
     imgwin.location.href = url; 
  } 
 
}  
}

function CaricaFoto(img){ 
        foto1= new Image(); 
        foto1.src=(img); 
        Controlla(img); 
} 
function Controlla(img){ 
        if((foto1.width!=0)&&(foto1.height!=0)){ 
                viewFoto(img); 
        } 
        else{ 
                funzione="Controlla('"+img+"')"; 
                intervallo=setTimeout(funzione,20); 
        } 
} 
function viewFoto(img){
        largh=foto1.width + 30;
        altez=foto1.height + 20;

		window_left = (screen.width-largh)/2;
		window_top = (screen.height-altez)/2;

        stringa="width="+largh+",height="+altez+",left="+window_left+",top="+window_top+",resizable="+1+",scrollbars=yes";
        image_view=window.open(img,"",stringa);
        image_view.document.write("<html><head><meta HTTP-EQUIV='imagetoolbar' CONTENT='no'><title> </title></head><body leftmargin=0 marginwidth=0 topmargin=0 marginheight=0><img src="+img+" onclick='self.close()' style=cursor:hand></body></html>");
        image_view.document.close();
}


// 즐겨찾기
 

// 퀵메뉴 
//Float layer 
function initMoving(target, position, topLimit, btmLimit) { 
 if (!target) 
  return false; 

 var obj = target; 
 obj.initTop = position; 
 obj.topLimit = topLimit; 
 obj.bottomLimit = document.documentElement.scrollHeight - btmLimit; 

 obj.style.position = "absolute"; 
 obj.top = obj.initTop; 
 obj.left = obj.initLeft; 

 if (typeof(window.pageYOffset) == "number") { 
  obj.getTop = function() { 
  return window.pageYOffset; 
  } 
 } else if (typeof(document.documentElement.scrollTop) == "number") { 
  obj.getTop = function() { 
  return document.documentElement.scrollTop; 
  } 
 } else { 
  obj.getTop = function() { 
  return 0; 
  } 
 } 

 if (self.innerHeight) { 
  obj.getHeight = function() { 
  return self.innerHeight; 
  } 
 } else if(document.documentElement.clientHeight) { 
  obj.getHeight = function() { 
  return document.documentElement.clientHeight; 
  } 
 } else { 
  obj.getHeight = function() { 
  return 500; 
  } 
 } 

 obj.move = setInterval(function() { 
  if (obj.initTop > 0) { 
  pos = obj.getTop() + obj.initTop; 
  } else { 
  pos = obj.getTop() + obj.getHeight() + obj.initTop; 
  //pos = obj.getTop() + obj.getHeight() / 2 - 15; 
  } 

  if (pos > obj.bottomLimit) 
  pos = obj.bottomLimit; 
  if (pos < obj.topLimit) 
  pos = obj.topLimit; 

  interval = obj.top - pos; 
  obj.top = obj.top - interval / 3; 
  obj.style.top = obj.top + "px"; 
 }, 30) 
} 

/* 확대이미지 */
function PopupCenter(get_width,get_height) { //popup 창 가운데 띠우기
	horizontal = (screen.width-get_width)/2;
	vertical = (screen.height-get_height)/2;
	new_posi='width='+get_width+',height='+get_height+',top='+vertical+',left='+horizontal+',toolbar=no,scrollbars=no,menubar=no,status=no,resizable=no';
	return new_posi;
}

 
  
function PhotoWindows(p_url,p_witdh,p_height){  //photo windows 오픈
	var photo_win = null;
	if ( !photo_win || photo_win.closed ){
		photo_win = window.open('/js/photowindows.php?src='+p_url+'&p_witdh='+p_witdh+'&p_height='+p_height,'photo_win',PopupCenter(p_witdh,p_height));
	} else {
		photo_win.location.href = '/js/photowindows.php?src='+p_url+'&p_witdh='+p_witdh+'&p_height='+p_height;
	}
}

/*png투명처리*/
	function setPng24(obj) {
	    obj.width=obj.height=1;
	    obj.className=obj.className.replace(/\bpng24\b/i,'');
	
	    obj.style.filter =
	
	    "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	    obj.src=''; 
	    return '';
	}


/*서브메뉴*/
 function showNotice(show){
	if(show == "1"){
			document.getElementById('Notice01').style.display = '';
			document.getElementById('Notice02').style.display = 'none';
			document.getElementById('Notice03').style.display = 'none';
			document.getElementById('Notice04').style.display = 'none';
		}else if(show == "2"){
			document.getElementById('Notice01').style.display = 'none';
			document.getElementById('Notice02').style.display = '';
			document.getElementById('Notice03').style.display = 'none';
			document.getElementById('Notice04').style.display = 'none';
		}else if(show == "3"){
			document.getElementById('Notice01').style.display = 'none';
			document.getElementById('Notice02').style.display = 'none';
			document.getElementById('Notice03').style.display = '';
			document.getElementById('Notice04').style.display = 'none';
		}else if(show == "4"){
			document.getElementById('Notice01').style.display = 'none';
			document.getElementById('Notice02').style.display = 'none';
			document.getElementById('Notice03').style.display = 'none';
			document.getElementById('Notice04').style.display = '';
		}
}


// 오픈 윈도우
function openHzWin(open_page,w,h,win_name){
	var window_left = (screen.width-w)/2;
	var window_top = (screen.height-h)/2 - 30;
	window.open(open_page,win_name,'width='+w+',height='+h+',status=no,scrollbars=yes,top=' + window_top + ',left=' + window_left + '');
}

//tab 메뉴
function initTabMenu(tabContainerID) {
	var tabContainer = document.getElementById(tabContainerID);
	var tabAnchor = tabContainer.getElementsByTagName("span");
	var i = 0;

	for(i=0; i<tabAnchor.length; i++) {
		if (tabAnchor.item(i).className == "tab")
			thismenu = tabAnchor.item(i);
		else
			continue;

		thismenu.container = tabContainer;
		thismenu.targetEl = document.getElementById(tabAnchor.item(i).id.split("#")[1]);
		thismenu.targetEl.style.display = "none";
		thismenu.imgEl = thismenu.getElementsByTagName("img").item(0);
		if (thismenu.imgEl) {
			thismenu.onmouseover = function () {
				//this.onclick();
			}
		}
		thismenu.onmouseover = tabMenuClick;

		if (!thismenu.container.first)
			thismenu.container.first = thismenu;
	}
	tabContainer.first.onmouseover();
}
function tabMenuClick() {
	currentmenu = this.container.current;
	if (currentmenu != this) {
		if (currentmenu) {
			currentmenu.targetEl.style.display = "none";
			if (currentmenu.imgEl) {
				currentmenu.imgEl.src = currentmenu.imgEl.src.replace("_on.gif", ".gif");
			} else {
				currentmenu.className = currentmenu.className.replace(" on", "");
			}
		}

		this.targetEl.style.display = "block";
		if (this.imgEl) {
			this.imgEl.src = this.imgEl.src.replace(".gif", "_on.gif");
		} else {
			this.className += " on";
		}
		this.container.current = this;
	}
	return false;
}

//토글
function toggleLayer(whichLayer) {
  var elem, vis;
  if(document.getElementById) // this is the way the standards work
    elem = document.getElementById(whichLayer);
  else if(document.all) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if(document.layers) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

//셀렉트 점프
function MM_jumpMenu(selObj,restore){ //v3.0
 	window.open(selObj.options[selObj.selectedIndex].value, "_self");
	if (restore) selObj.selectedIndex=0;
}

//상품 찾기
function Good_Select(ref) {
	var window_left = (screen.width-1200)/2;
	var window_top = (screen.height-800)/2;
	window.open(ref,"Select",'width=1200,height=800,status=no,scrollbars=yes,top=' + window_top + ',left=' + window_left + '');
}
//상품상세
function changeImageThumb(imgSeq){
    document.imgform.PicMedium.src = imgSeq;
    return;
}
//ajax 컨텐츠 불러오기
function xmlhttpPost(strURL,idName) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            //updatepage(self.xmlHttpReq.responseText);
			document.getElementById(idName).innerHTML = self.xmlHttpReq.responseText;
        }
    }
    self.xmlHttpReq.send();
}

//jquery 컨텐츠 불러오기
function fLoadData(divID,strUrl){
	$.ajax({
		type: "POST",
		url: strUrl,
		data: "",
		success: function(resultText)
		{
			$(divID).html(resultText);
		},
		error: function() {
			alert("호출에 실패했습니다.");
		}
	});
}

//찜 담기
function goodZim(gcode,gcategory){
	if (confirm("해당 상품을 찜하시겠습니까?")){
		window.open('/shop/zzim.php?Mode=Add&gcode='+gcode+'&gcategory='+gcategory, 'actionIframe', '');
		
		if (confirm("찜하신 상품을 보시겠습니까?")){
			location.href('/shop/myshopping.php');
		}else{
			return;
		}

	}else{
		return;
	}
}

//찜 담기 아이프레임
function goodZimIframe(gcode,gcategory){
	if (confirm("해당 상품을 찜하시겠습니까?")){
		window.open('/shop/zzim.php?Mode=Add&gcode='+gcode+'&gcategory='+gcategory, 'actionIframe', '');
		
		if (confirm("찜하신 상품을 보시겠습니까?")){
			top.location.href('/shop/myshopping.php');
		}else{
			return;
		}

	}else{
		return;
	}
}

//찜 삭제
function goodZimDel(gcode){
	if (confirm("상품을 삭제하시겠습니까?")){
		window.open('/shop/zzim.php?Mode=Delete&gcode='+gcode, 'actionIframe', '');
		location.href('/shop/myshopping.php');
	}else{
		return;
	}
}
function goodZimDelMy(gcode){
	if (confirm("상품을 삭제하시겠습니까?")){
		window.open('/shop/zzim.php?Mode=Delete&gcode='+gcode, 'actionIframe', '');
		location.href('/shop/customer.php');
	}else{
		return;
	}
}

/**
 * 숫자나 문자열을 통화(Money) 형식으로 만든다.
 * 단, 양수만 허용한다.
 * &lt;input type="text" name="test" value="" onkeyup="this.value=toCurrencyPositive(this.value);"&gt;
 * or
 * var num = toCurrency(document.form[0].text.value);
 * @param	amount	"1234567"
 * @return	currencyString "1,234,567"
 * @see #toCurrency(amount)
 */
function toCurrencyPositive(amount){
    var firstChar = amount.substr(0,1);
    if(firstChar == "-"){
        amount = amount.substring(1, amount.length);
    }
    return toCurrency(amount);
}


function toCurrency(amount){
var data = amount.split('.');
    var sign = "";

    var firstChar = data[0].substr(0,1);
    if(firstChar == "-"){
        sign = firstChar;
        data[0] = data[0].substring(1, data[0].length);
    }

    data[0] = data[0].replace(/\D/g,"");
    if(data.length > 1){
        data[1] = data[1].replace(/\D/g,"");
    }

    firstChar = data[0].substr(0,1);

    //0으로 시작하는 숫자들 처리
    if(firstChar == "0"){
        if(data.length == 1){
            return sign + parseFloat(data[0]);
        }
    }

    var comma = new RegExp('([0-9])([0-9][0-9][0-9][,.])');

    data[0] += '.';
    do {
        data[0] = data[0].replace(comma, '$1,$2');
    } while (comma.test(data[0]));

    if (data.length > 1) {
        return sign + data.join('');
    } else {
        return sign + data[0].split('.')[0];
    }
}

/**
 * 주어진 값(val)을 소수점이하 num자리수에서 반올림한값을 리턴
 *
 * @param val 반올림할 값
 * @param num 반올림할 자리수
 * @return number
 */
function round(val, num){
    val = val * Math.pow(10, num - 1);
    val = Math.round(val);
    val = val / Math.pow(10, num - 1);
    return val;
}

/**
 * ,이 있는 숫자를 순수한 숫자로 바꿔준다. (+), (-) 허용
 *
 * @param num
 * @return number
 */
function toNormalNum( num ) {
    num = num.replace(/,/g, '');
    var args = Number(num);
    return args;
}

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 View_Large_Picture(Code) {
	largh=540 + 30;
    altez=653 + 20;
 
	window_left = (screen.width-largh)/2;
	window_top = (screen.height-altez)/2;
 
	window.open('/html/view_img.php?Code='+Code,'SmallWindow','width=540,height=653,scrollbars=no,resizable=0,left='+window_left+',top='+window_top);  
}

function orderAll(){
	if (confirm("장바구니에 담긴 모든 상품을 주문하시겠습니까?")){
		window.open('/shop/order_process.php?Operation=all', 'actionIframe', '');
		location.href('/shop/order.php');
	}else{
		return;
	}
}
function orderOne(no){
	if (confirm("해당 상품을 주문하시겠습니까?")){
		window.open('/shop/order_process.php?Operation=one&no='+no, 'actionIframe', '');
		location.href('/shop/order.php');
	}else{
		return;
	}
}
//배송조회
function viewDel(Url){
	win_name = "delWindow";
	w = 1000;
	h = 800;
	var window_left = (screen.width-w)/2;
	var window_top = (screen.height-h)/2 - 30;
	window.open(Url,win_name,'width='+w+',height='+h+',status=yes,scrollbars=yes,top=' + window_top + ',left=' + window_left + '');
}

//대신택배
function f_tracking(billno){
	var billno1=billno.substring(0,4);
	var billno2=billno.substring(4,7);
	var billno3=billno.substring(7,13);
	var window_url="http://home.daesinlogistics.co.kr/daesin/jsp/d_freight_chase/d_general_process2.jsp?billno1="+billno1+"&billno2="+billno2+"&billno3="+billno3;
	var window_option="left=30,top=30,width=650,height=450,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no";
	var window_name="tracking";
	window.open(window_url,window_name,window_option);
}

//적립금 부여
function addPoint(id,name){
	tb_show('적립금 내역 입력', '/html/mileage_add.php?height=220&amp;width=550&id='+id+'&name='+name);
}

