window.onresize=wResize;

function wResize(){
	if (typeof aResize == 'function') { aResize(); }	// change layout of top and bottom
	if (typeof bResize == 'function') { bResize(); }	// change layout of main contents
}
function smsgo(txt){
	window.open("./_alone/sendsms.php?rcv="+txt,"smsgo","width=250,height=280");
}
function smsgo_ord(txt){
	window.open("./_alone/sendsms.php?rcv=ord@"+txt+"@a","smsgo","width=250,height=320");
}

function catTog(num){
	if (confirm("상태를 바꾸시겠습니까?")){
		$.ajax({
		  type: "POST", 
		  url: "./c_ajax/main_ajax.php",
		  dataType: "text",
		  data: ({
				"wr":"cat_toggle",
				"seq":num
				 }),
		  error:function(xhr,status,e){       //에러 발생시 처리함수
				alert(xhr+"\n"+status+"\n"+e);
			},
	
		  success: function(txt){
			 //alert(txt);
			if (txt=="ok"){
				document.location.reload(); 
			} else {
				alert(txt);
			}
		  }
		 });

		
		
		
		
	}
	
}
function jusoCallBack(aid,roadFullAddr,roadAddrPart1,addrDetail,roadAddrPart2,engAddr,jibunAddr,zipNo,admCd,rnMgtSn,bdMgtSn){
	/*document.getElementById('roadFullAddr').value = roadFullAddr;
	document.getElementById('roadAddrPart1').value = roadAddrPart1;
	document.getElementById('addrDetail').value = addrDetail;
	document.getElementById('roadAddrPart2').value = roadAddrPart2;
	document.getElementById('engAddr').value = engAddr;
	document.getElementById('jibunAddr').value = jibunAddr;
	document.getElementById('zipNo').value = zipNo;
	document.getElementById('admCd').value = admCd;
	document.getElementById('rnMgtSn').value = rnMgtSn;
	document.getElementById('bdMgtSn').value = bdMgtSn; */

	document.getElementById(aid+'_address1').value = roadAddrPart1;
	document.getElementById(aid+'_address2').value = addrDetail+" "+roadAddrPart2;
	document.getElementById(aid+'_post').value = zipNo;
}

function goPopup(txt){
	var pop = window.open("/_alone/jusoPopup.php?aid="+txt,"pop","width=570,height=420, scrollbars=yes, resizable=yes"); 
}
function viewKuwa(num,txt){
	$('#viewkuwa_img').attr("src","./files/shop_ex/"+num+"/"+num+"_a"+txt+".jpg");
	$('#viewkuwa').show();
	
	popupToCenter('#viewkuwa');

}
function viewit(idx,num){
	wrapWindowByMask();
	$('#'+idx).show();
	if(num>0){
		//callall(idx,num);
	}
	//$('#'+idx).css("z-index",10000);
	popupToCenter('#'+idx);
}
function offit(){
	$("form").each(function(){this.reset();})
	$('.flbox').hide();
	$('.mobile_menu').hide();
	//$('#mask').fadeTo("slow",0);    
	$('#mask, .window').hide();
}
function popupToCenter(txt) {
	$(txt).css("position","absolute");
	$(txt).css("top",(($(window).height()-$(txt).outerHeight())/2)+$(window).scrollTop());
	$(txt).css("left",(($(window).width()-$(txt).outerWidth())/2)+$(window).scrollLeft());
	}
function wrapWindowByMask(){
        //화면의 높이와 너비를 구한다.
        var maskHeight = $(document).height();  
        var maskWidth = $(window).width();  

        //마스크의 높이와 너비를 화면 것으로 만들어 전체 화면을 채운다.
        $('#mask').css({'width':maskWidth,'height':maskHeight});  

        //애니메이션 효과
        $('#mask').fadeIn(300);      
        //$('#mask').fadeTo("slow",0.2);    
}


function pre_calc_new(sw,sh,kind){
	// 현수막,PET 기본가격 계산 210521
	// 가로, 세로, 종류 (A:현수막, B:PET)
	var rst=0;
	$.ajax({
		  type: "POST", 
		  url: "./_alone/matrix_ajax.php",
		  async: false,
		  dataType: "html",
		  data: ({
				"wr":"cal_banner_standard",
				"sw":sw,
				"sh":sh,
				"kind":kind
				 }),
		  error:function(xhr,status,e){       //에러 발생시 처리함수
				alert(xhr+"\n"+status+"\n"+e);
			},

		  success: function(txt){
			 // alert(txt);
			if (txt=="err"){
				//alert("전화문의 해주세요.")
				rst=99999999;
			} else {
				rst=txt;
				//alert(rst);
			}
			//alert("수정되었습니다.");
			}
		 });
	
	//console.log(kind+size+amt);
	return rst;
	
}
function pre_calc(sw,sh,kind){
	// 현수막,PET 기본가격 계산
	// 가로, 세로, 종류 (A:현수막, B:PET)
    sw=$('#frm_width').val()*1;
    sh=$('#frm_height').val()*1;
    sw=parseInt(sw);	//가로사이즈 정수화
	sh=parseInt(sh);	//세로사이즈 정수화
	sw = isNaN(sw) ? 0 : sw;
	sh = isNaN(sh) ? 0 : sh;

    if (sh>sw){ 
        st=sw;
        sw=sh;
        sh=st;
    }
    
    if (kind=="A"){
    

		    va=new Array(19);	//현수막 매트릭스
		    va[0]=new Array(20,20,20,22,22,25,27);
		    va[1]=new Array(20,20,22,23,25,27,30);
		    va[2]=new Array(20,20,22,25,26,27,32);
		    va[3]=new Array(21,21,25,26,29,33,39);
		    va[4]=new Array(22,23,25,29,33,39,45);
		    va[5]=new Array(23,25,30,32,35,42,49);
		    va[6]=new Array(24,27,32,35,42,48,54);
		    va[7]=new Array(27,35,37,41,48,52,58);
		    va[8]=new Array(29,36,39,44,48,58,64);
		    va[9]=new Array(30,38,45,49,52,58,67);
		    va[10]=new Array(32,42,48,52,58,62,72);
		    va[11]=new Array(35,48,52,56,62,70,82);
		    va[12]=new Array(40,48,56,60,67,75,82);
		    va[13]=new Array(44,52,60,65,72,85,92);
		    va[14]=new Array(47,56,63,68,75,89,98);
		    va[15]=new Array(49,58,67,72,80,91,105);
		    va[16]=new Array(52,60,72,75,84,95,110);
		    va[17]=new Array(55,65,75,79,84,104,113);
		    va[18]=new Array(57,70,79,84,93,115,122);
		    
		    sh_ar=99;
		
		    if (sh<=180) { sh_ar=6; }
		    if (sh<=150) { sh_ar=5; }
		    if (sh<=127) { sh_ar=4; }
		    if (sh<=110) { sh_ar=3; }
		    if (sh<=105) { sh_ar=2; }
		    if (sh<=90) { sh_ar=1; }
		    if (sh<=70) { sh_ar=0; }
		
		    if (sw<200) {sw_ar=1; sw_arx=8;}
	        if (sw<=190){sw_ar=1; sw_arx=5;}
	        if (sw<=180){sw_ar=1; sw_arx=0;}
	        if (sw<=170){sw_ar=0; sw_arx=7;}
	        if (sw<=160){sw_ar=0; sw_arx=3;}
	        if (sw<=150){sw_ar=0; sw_arx=0;}

		    if ((sw>=200)&&(sw<1000)){
		        sw_ar=Math.floor((sw/50)-2);
		        sw_arx=Math.round((((sw/50)-2)-sw_ar)*10);
		    }
		    if (sw>=1000) {sw_ar=99; sw_arx=0;}
		    
		    if ((sw_ar==99)||(sh_ar==99)){
			    xx=99999999;
		    } else {
			    x1=va[sw_ar][sh_ar];
			    console.log(sw_ar+" | "+sw_arx+" | "+sh_ar);
			    x2=va[sw_ar+1][sh_ar]; //1000
			    xr=Math.ceil((x2-x1)/10*sw_arx);
			    xx=(x1+xr)*1000;
		    }
    
    }

    if (kind=="B"){
			    vvt=new Array(5);	//PET 매트릭스
				vvt[0]=new Array(0,2,4,6,8,10,12,14,16,18);
				vvt[1]=new Array(8,13,18,22,28,33,39,45,51,57);
				vvt[2]=new Array(22,29,36,43,50,57,64,71,78,85);
				vvt[3]=new Array(47,55,63,71,79,87,95,103,111,119);
				vvt[4]=new Array(62,71,80,89,98,107,116,125,157,172);
				
					
					if (sw<100) { // 가로사이즈에 따른 범위선정 
						art_w=98;		// PET
					} else if ((sw>=100)&&(sw<200)) {
						art_w=0
					} else if ((sw>=200)&&(sw<300)) {
						art_w=1;
					} else if ((sw>=300)&&(sw<400)) {
						art_w=2;
					} else if ((sw>=400)&&(sw<500)) {
						art_w=3;
					} else {
						art_w=99;
					}
				
					
					if (sh<=60) { // 세로사이즈에 따른 PET범위선정
						art_h=0;
					} else if ((sh>60)&&(sh<=70)) {
						art_h=1;
					} else if ((sh>70)&&(sh<=80)) {
						art_h=2;
					} else if ((sh>80)&&(sh<=90)) {
						art_h=3;
					} else if ((sh>90)&&(sh<=100)) {
						art_h=4;
					} else if ((sh>100)&&(sh<=110)) {
						art_h=5;
					} else if ((sh>110)&&(sh<=120)) {
						art_h=6;
					} else if ((sh>120)&&(sh<=130)) {
						art_h=7;
					} else if ((sh>130)&&(sh<=140)) {
						art_h=8;
					} else if ((sh>140)&&(sh<=150)) {
						art_h=9;
					} else {
						art_h=99;
					}


				// PET 계산
				if (art_h==99||art_w==99) {
				fp=99999999;
				} else if (art_w==98) {
				fp=(vvt[0][art_h]+28)*1000;
				} else {
				fp=((vvt[art_w][art_h]+28)*1000)+(Math.ceil(	((vvt[art_w+1][art_h]-vvt[art_w][art_h])/10)*(Math.ceil(sw/10)-(Math.floor(sw/100)*10))	)*1000);
				}
				xx=fp;

	    
	    
    }
    if ((kind=="A")&&(xx<20000)){ xx=20000; }
    if ((kind=="B")&&(xx<28000)){ xx=28000; }
    
    return xx;
    

}



function calculate_13(kind,size,amt){
	var rst=0;
	$.ajax({
		  type: "POST", 
		  url: "./_alone/matrix_ajax.php",
		  async: false,
		  dataType: "html",
		  data: ({
				"wr":"cal_13",
				"kind":kind,
				"size":size,
				"amt":amt
				 }),
		  error:function(xhr,status,e){       //에러 발생시 처리함수
				alert(xhr+"\n"+status+"\n"+e);
			},

		  success: function(txt){
			 // alert(txt);
			if (txt=="err"){
				alert("전화문의 해주세요.")
				rst=999999999;
			} else {
				rst=txt;
				//alert(rst);
			}
			//alert("수정되었습니다.");
			}
		 });
	
	//console.log(kind+size+amt);
	return rst;

}
function calculate_9(kind,size,amt){
	var rst=0;
	$.ajax({
		  type: "POST", 
		  url: "./_alone/matrix_ajax.php",
		  async: false,
		  dataType: "html",
		  data: ({
				"wr":"cal_9",
				"kind":kind,
				"size":size,
				"amt":amt
				 }),
		  error:function(xhr,status,e){       //에러 발생시 처리함수
				alert(xhr+"\n"+status+"\n"+e);
			},

		  success: function(txt){
			 // alert(txt);
			if (txt=="err"){
				alert("전화문의 해주세요.")
				rst=999999999;
			} else {
				rst=txt;
				//alert(rst);
			}
			//alert("수정되었습니다.");
			}
		 });
	
	//console.log(kind+size+amt);
	return rst;

}

function guid() {
  function _s4() {
    return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
  }
  return _s4() + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + _s4() + _s4();
}


function openPrvWin(num){
	window.open("./index.php?page=preview&do=a&onum="+num);
}

function find_zip(txt){
	window.open("_alone/zipcode.php?frm="+txt,"findzip","width=500,height=160,scrollbars=no,resizable=no");
	}
function find_zip_frmid(txtid,txt){
	window.open("_alone/zipcode.php?frm="+txt+"&id="+txtid,"findzip","width=500,height=160,scrollbars=no,resizable=no");
	}
function showReceiptBycash(ord_num,auth_val){
	window.open('_alone/receipt.php?ord_num='+ord_num+'&auth_val='+auth_val,'rec','width=640,height=500,toolbar=no,menubar=no,location=no,scrollbars=auto,status=no,resizable=no,fullscreen=no');
}
function onlynum(str) {
	if (isNaN(str.value)) {
		alert("숫자만 넣어주세요.");
		str.focus();
		str.select();
	}
}
function shopgo(num,str){
	location.href="./index.php?page=shop&do=listb&sch_kind="+num+"&sch_word="+encodeURI(str);
	
}
function searchgo(txt,str){
	location.href="./index.php?page=shop&do=a&sch_kind="+txt+"&sch_word="+encodeURI(str);
	
}
function number_format (number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/number_format    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival    // +      input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +   improved by: davook
    // +   improved by: Brett Zamir (http://brett-zamir.me)
    // +      input by: Jay Klehr
    // +   improved by: Brett Zamir (http://brett-zamir.me)    // +      input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // +   improved by: Theriault
    // +      input by: Amirouche
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    
	// *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *    example 10: number_format('1.20', 2);
    // *    returns 10: '1.20'    // *    example 11: number_format('1.20', 4);
    // *    returns 11: '1.2000'
    // *    example 12: number_format('1.2000', 3);
    // *    returns 12: '1.200'
    // *    example 13: number_format('1 000,50', 2, '.', ' ');    // *    returns 13: '100 050.00'
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
}
function isNull(obj) {
	return (typeof obj != "undefined" && obj != null && obj != "") ? false : true;
}
/*
 jQuery.fn.serializeObject = function() { 
  var obj = null; 
  try { 
      if(this[0].tagName && this[0].tagName.toUpperCase() == "FORM" ) { 
          var arr = this.serializeArray(); 
          if(arr){ obj = {}; 
          jQuery.each(arr, function() { 
              obj[this.name] = this.value; }); 
          } 
      } 
  }catch(e) { 
      alert(e.message); 
  }finally {} 
  return obj; 
} */
$.fn.serializeObject = function() {
  "use strict"
  var result = {}
  var extend = function(i, element) {
    var node = result[element.name]
    if ("undefined" !== typeof node && node !== null) {
      if ($.isArray(node)) {
        node.push(element.value)
      } else {
        result[element.name] = [node, element.value]
      }
    } else {
      result[element.name] = element.value
    }
  }

  $.each(this.serializeArray(), extend)
  return result
}


var Base64 = {

			// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

		  // public method for encoding
		  encode : function (input) {
			  var output = "";
			  var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
			  var i = 0;

			  input = Base64._utf8_encode(input);

			  while (i < input.length) {

				  chr1 = input.charCodeAt(i++);
				  chr2 = input.charCodeAt(i++);
				  chr3 = input.charCodeAt(i++);

				  enc1 = chr1 >> 2;
				  enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
				  enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
				  enc4 = chr3 & 63;

				  if (isNaN(chr2)) {
					  enc3 = enc4 = 64;
				  } else if (isNaN(chr3)) {
					  enc4 = 64;
				  }

				  output = output +
					  this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
					  this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

			  }

			  return output;
		  },

		  // public method for decoding
decode : function (input) {
			 var output = "";
			 var chr1, chr2, chr3;
			 var enc1, enc2, enc3, enc4;
			 var i = 0;

			 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

			 while (i < input.length) {

				 enc1 = this._keyStr.indexOf(input.charAt(i++));
				 enc2 = this._keyStr.indexOf(input.charAt(i++));
				 enc3 = this._keyStr.indexOf(input.charAt(i++));
				 enc4 = this._keyStr.indexOf(input.charAt(i++));

				 chr1 = (enc1 << 2) | (enc2 >> 4);
				 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				 chr3 = ((enc3 & 3) << 6) | enc4;

				 output = output + String.fromCharCode(chr1);

				 if (enc3 != 64) {
					 output = output + String.fromCharCode(chr2);
				 }
				 if (enc4 != 64) {
					 output = output + String.fromCharCode(chr3);
				 }

			 }

			 output = Base64._utf8_decode(output);

			 return output;

		 },

		 // private method for UTF-8 encoding
_utf8_encode : function (string) {
				   string = string.replace(/\r\n/g,"\n");
				   var utftext = "";

				   for (var n = 0; n < string.length; n++) {

					   var c = string.charCodeAt(n);

					   if (c < 128) {
						   utftext += String.fromCharCode(c);
					   }
					   else if((c > 127) && (c < 2048)) {
						   utftext += String.fromCharCode((c >> 6) | 192);
						   utftext += String.fromCharCode((c & 63) | 128);
					   }
					   else {
						   utftext += String.fromCharCode((c >> 12) | 224);
						   utftext += String.fromCharCode(((c >> 6) & 63) | 128);
						   utftext += String.fromCharCode((c & 63) | 128);
					   }

				   }

				   return utftext;
			   },

			   // private method for UTF-8 decoding
_utf8_decode : function (utftext) {
				   var string = "";
				   var i = 0;
				   var c = c1 = c2 = 0;

				   while ( i < utftext.length ) {

					   c = utftext.charCodeAt(i);

					   if (c < 128) {
						   string += String.fromCharCode(c);
						   i++;
					   }
					   else if((c > 191) && (c < 224)) {
						   c2 = utftext.charCodeAt(i+1);
						   string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
						   i += 2;
					   }
					   else {
						   c2 = utftext.charCodeAt(i+1);
						   c3 = utftext.charCodeAt(i+2);
						   string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
						   i += 3;
					   }

				   }

				   return string;
			   },

URLEncode : function (string) {
				return escape(this._utf8_encode(string));
			},

			// public method for url decoding
URLDecode : function (string) {
				return this._utf8_decode(unescape(string));
			}
		}