//아너스 카드 등록 팝업
function pos_card_update(){
	if(!g4_member){
		alert("회원이시라면 로그인 후 이용하실 수 있으며,\n\n회원이 아니실 경우 회원가입 후 이용 하실 수 있습니다.");
	}else{
		window.open(g4_path+"/pos/pos.php","pos","width=400, height=200, scrollbars=no,top=200, left=300");
	}
}

//이미지의 사이즈를 재조정 합니다.
function ImageSize(MaxWidth){
	var NewImage = new Image(); 
	var Target=document.getElementsByName("resize_image[]");
	for(i=0; i<Target.length; i++){
		NewImage.src =Target[i].src;
		OldWidth = NewImage.width;
		OldHeight = NewImage.height;
		
		if(OldWidth > MaxWidth){
			NewHeight = parseFloat(OldWidth / OldHeight);
			Target[i].width = MaxWidth;
			Target[i].height = parseInt(MaxWidth / NewHeight);
		}
	}
}

function PrintHtml(DivID,rs){
	var cont=rs.responseText;

	document.getElementById(DivID).innerHTML=cont;
}

//팝업창을 오픈합니다.
function WinPop(url,w,h,s,PopName){
	if(!PopName){
		PopName=tb_time;
	}
	var BibleWindow=window.open(url,PopName,"width="+w+", height="+h+", scrollbars="+s);
}

//링크 이동
function goto_url(url){
	document.location.href=url;
}

function resizeImage(imageWidth, borderColor) {
    var target = document.getElementsByName('target_resize_image[]');
    var imageHeight = 0;

    if (target) {
        for(i=0; i<target.length; i++) { 
            // 원래 사이즈를 저장해 놓는다
            target[i].tmp_width  = target[i].width;
            target[i].tmp_height = target[i].height;
            // 이미지 폭이 테이블 폭보다 크다면 테이블폭에 맞춘다
            if(target[i].width > imageWidth) {
                imageHeight = parseFloat(target[i].width / target[i].height)
                target[i].width = imageWidth;
                target[i].height = parseInt(imageWidth / imageHeight);
                target[i].style.cursor = 'pointer';

                // 스타일에 적용된 이미지의 폭과 높이를 삭제한다
                target[i].style.width = '';
                target[i].style.height = '';
            }

            if (borderColor) {
                target[i].style.borderWidth = '1px';
                target[i].style.borderStyle = 'solid';
                target[i].style.borderColor = borderColor;
            }
        }
    }
}

//주문서 명세서 출력 팝업
function getOrderPrint(od_id){
	window.open(g4_path+"/store/order_print.php?od_id="+od_id,"order_print","width=800, height=800, scrollbars=yes");
}

//주문서 창고용 출력 팝업
function getBoxPrint(od_id){
	window.open(g4_path+"/store/box_print.php?od_id="+od_id,"box_print","width=800, height=800, scrollbars=yes");
}

//주문서 점주용 출력 팝업
function getListPrint(od_id){
	window.open(g4_path+"/store/order_list_print.php?od_id="+od_id,"order_list_print","width=800, height=800, scrollbars=yes");
}

//메세지함 호출
function memo(val,m){
	if(m=='write'){
		window.open(g4_path+"/store/memo/memo.write.php?mid="+val,"memo","width=800, height=700, scrollbars=no");
	}else if(m=='view'){
		window.open(g4_path+"/store/memo/memo.view.php?mno="+val,"memo","width=800, height=700, scrollbars=no");
	}else{
		window.open(g4_path+"/store/memo/memo.list.php","memo","width=800, height=700, scrollbars=no");
	}
}

//쿠키 생성
function setCookie(name, value, expiredays){
	var today = new Date();
	today.setDate( today.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + today.toGMTString() + ";";
}

//쿠키 값을 찾습니다.
function getCookieval(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//쿠키값을 반환합니다.
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieval (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function layer_display(idx){
	var Div=document.getElementById(idx);

	if(Div.style.display=="block"){
		Div.style.display="none";
	}else{
		Div.style.display="block";
	}
}

//체크박스를 제어합니다.
function getAllChk(){
	var Checked=false;
	var All=document.getElementById('chkall');
	var Chk=document.getElementsByName('chk[]');
	if(All.checked){
		for(var i=0; i<Chk.length; i++){
			Chk[i].checked=true;
		}
		Checked=true;
	}else{
		for(var i=0; i<Chk.length; i++){
			Chk[i].checked=false;
		}
		Checked=false;
	}
}
