//var is_debug = true; var is_debug = false; function onBackPressed(){ history.back(-1); } function parseJwt (token) { var base64Url = token.split('.')[1]; var base64 = base64Url.replace('-', '+').replace('_', '/'); return JSON.parse(window.atob(base64)); }; var date = new Date(); var year = date.getFullYear(); var month = date.getMonth()+1 var day = date.getDate(); if(month < 10){ month = "0"+month; } if(day < 10){ day = "0"+day; } var sToday = year+""+month+""+day; function get_chart_day_hour(){ var now_timestamp = fetch_unix_timestamp() - 60*60*24; var today_string = new Date(now_timestamp * 1000).yyyy_mm_dd(); var aHour = new Array(); for (h=0; h<24; h++){ var m = h; if(h<10){ m = '0' + h; } aHour[h] = today_string + " " + m; } return aHour; } function get_chart_day_y_hour(){ var aHour = new Array(); for (h=0; h<24; h++){ var m = h; if(h<10){ m = '0' + h; } aHour[h] = m; } return aHour; } function get_chart_week_date(){ var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); for (i=0; i<7; i++){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[i] =new Date(today_timestamp * 1000).yyyy_mm_dd(); } aDate.reverse(); return aDate; } function get_chart_month_date(){ var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); for (i=0; i<30; i++){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[i] =new Date(today_timestamp * 1000).yyyy_mm_dd(); } aDate.reverse(); return aDate; } function get_chart_year_date(){ var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); var num = 0; for (i=0; i<365; i=i+30){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[num++] =new Date(today_timestamp * 1000).yyyy_mm(); } aDate.reverse(); return aDate; } function get_chart_year_y_axis(){ var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); var num = 0; for (i=0; i<365; i=i+30){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[num++] =new Date(today_timestamp * 1000).mm(); } aDate.reverse(); return aDate; } function get_chart_month_y_axis(){ var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); for (i=0; i<30; i++){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[i] =new Date(today_timestamp * 1000).mm_dd(); } aDate.reverse(); return aDate; } function get_chart_weekday_of_week(){ var weekday = new Array(7); weekday[0] = "Sun"; weekday[1] = "Mon"; weekday[2] = "Tue"; weekday[3] = "Wed"; weekday[4] = "Thu"; weekday[5] = "Fri"; weekday[6] = "Sat"; var now_timestamp = fetch_unix_timestamp(); var aDate = new Array(); for (i=0; i<7; i++){ var today_timestamp = now_timestamp - (60*60*24)*(i); aDate[i] = weekday[new Date(today_timestamp * 1000).getDay()]; } aDate.reverse(); return aDate; } fetch_unix_timestamp = function() { //return parseInt(new Date().getTime().toString().substring(0, 10)); return Math.floor(new Date().getTime() / 1000); } Date.prototype.yyyymmdd = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [this.getFullYear(), (mm>9 ? '' : '0') + mm, (dd>9 ? '' : '0') + dd ].join(''); }; Date.prototype.yyyy_mm_dd = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [this.getFullYear(), (mm>9 ? '' : '0') + mm, (dd>9 ? '' : '0') + dd ].join('-'); }; Date.prototype.yyyy_mm = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [this.getFullYear(), (mm>9 ? '' : '0') + mm ].join('-'); }; Date.prototype.mm_dd = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [ (mm>9 ? '' : '0') + mm, (dd>9 ? '' : '0') + dd ].join('-'); }; Date.prototype.mm = function() { var mm = this.getMonth() + 1; // getMonth() is zero-based var dd = this.getDate(); return [ (mm>9 ? '' : '0') + mm ].join('-'); }; function getMaxOfArray(numArray) { return Math.max.apply(null, numArray); } function getMinOfArray(numArray) { return Math.min.apply(null, numArray); } function timeToMonDay(time){ var month = time.substring(5,7); var day = time.substring(8,10); return parseInt(month)+"월 "+parseInt(day)+"일"; } function timeToAMPMKorStr(time){ var hour = time.substring(11,13); var min = time.substring(14,16); var sec = time.substring(17,19); var ampm = "오전 "; if(hour >= 12){ ampm = "오후 "; hour = hour % 12; } return ampm + " " + hour + ":" + min + ":" + sec; } function korStrToTime(time){ var kor = ""; var hour = time.substring(0,2); var min = time.substring(2,4); if(hour>12){ return "오후 " + (hour-12) + ":" + min; } else if(hour==12){ return "오후 " + hour + ":" + min; } else{ return "오전 " + hour + ":" + min; } } function toW(v){ var returnValue = new Array(); v = parseFloat(v); if(v<10000){ returnValue[0] = v.toFixed(1); returnValue[1] = "W"; }else{ returnValue[0] = (v/1000).toFixed(3); returnValue[1] = "kW"; } return returnValue; } function toWh(v){ var returnValue = new Array(); v = parseFloat(v); if(v<10000){ returnValue[0] = v.toFixed(3); returnValue[1] = "Wh"; }else{ returnValue[0] = v.toFixed(1); returnValue[1] = "kWh"; } return returnValue; } String.prototype.replaceAll = function(org, dest) { return this.split(org).join(dest); } var userAgent = navigator.userAgent.toLowerCase(); function go_history_back() { if (document.referrer.indexOf("/b2c/main/b2cMain.kps") > -1) { top.location.href = "/b2c/main/b2cMain.kps"; } else if (document.referrer.indexOf("/b2c/main/b2cMain.kps") > -1) { top.location.href = "/b2c/main/b2cMain.kps"; } else { if ( (userAgent.search("iphone") > -1) || (userAgent.search("ipod") > -1) || (userAgent.search("ipad") > -1) ) { history.back(); } else if(userAgent.search("androidapp") > -1){ window.AndroidHistory.goBack(); } else { top.location.href = document.referrer; } } } function go_logout() { top.location.href = "/member/logoutAction.kps"; } function popupAlert(pMessage, vFunction) { $(".popup-alert.init #popup-message").html(pMessage); $(".popup-alert.init").show(); $(".popup-alert.init .bg-popup").show(); $('#container').css('overflow-y', 'hidden'); popupAlertEvent(vFunction); } function popupConfirm(pMessage, vFunction) { $(".popup-alert.popup-confirm #popup-message").html(pMessage); $(".popup-alert.popup-confirm").show(); $(".popup-alert.popup-confirm .bg-popup").show(); $('#container').css('overflow-y', 'hidden'); popupAlertEvent(vFunction); } function sumArray(array) { for (var index = 0, // The iterator length = array.length, // Cache the array length sum = 0; // The total amount index < length; // The "for"-loop condition sum += array[index++] // Add number on each iteration ) ; return sum; } function dateInput(n, m) { document.getElementById("srtDate").value = ""; document.getElementById("endDate").value = ""; var date = new Date(); var start = new Date(Date.parse(date) - n * 1000 * 60 * 60 * 24); var today = new Date(Date.parse(date) - m * 1000 * 60 * 60 * 24); var yyyy = start.getFullYear(); var mm = start.getMonth() + 1; var dd = start.getDate(); if (mm < 10) { mm = "0" + mm; } if (dd < 10) { dd = "0" + dd; } var t_yyyy = today.getFullYear(); var t_mm = today.getMonth() + 1; var t_dd = today.getDate(); if (t_mm < 10) { t_mm = "0" + t_mm; } if (t_dd < 10) { t_dd = "0" + t_dd; } document.getElementById("srtDate").value = yyyy + "-" + mm + "-" + dd; document.getElementById("endDate").value = t_yyyy + "-" + t_mm + "-" + t_dd; // $("div.tab-area1.tab-4.tab-event > div > // button.tab.on").removeClass("on"); } Array.prototype.unique = function(a) { return function() { return this.filter(a) } }(function(a, b, c) { return c.indexOf(a, b + 1) < 0 }); Array.prototype.sortUnique = function() { this.sort(); var last_i; for (var i = 0; i < this.length; i++) if ((last_i = this.lastIndexOf(this[i])) !== i) this.splice(i + 1, last_i - i); return this; } var Base64 = { _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", 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; }, 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; }, _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; }, _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; } } /** * PHP 함수 number_format 같이 천자리마다 ,를 자동으로 찍어줌 * * @param num * number|string : 숫자 * @param decimals * int default 0 : 보여질 소숫점 자리숫 * @param dec_point * char default . : 소수점을 대체 표시할 문자 * @param thousands_sep * char default , : 천자리 ,를 대체 표시할 문자 * @returns {string} */ function number_format(num, decimals, dec_point, thousands_sep) { num = parseFloat(num); if (isNaN(num)) return '0'; if (typeof (decimals) == 'undefined') decimals = 0; if (typeof (dec_point) == 'undefined') dec_point = '.'; if (typeof (thousands_sep) == 'undefined') thousands_sep = ','; decimals = Math.pow(10, decimals); num = num * decimals; num = Math.round(num); num = num / decimals; num = String(num); var reg = /(^[+-]?\d+)(\d{3})/; var tmp = num.split('.'); var n = tmp[0]; var d = tmp[1] ? dec_point + tmp[1] : ''; while (reg.test(n)) n = n.replace(reg, "$1" + thousands_sep + "$2"); return n + d; } function setCookie(cname, cvalue, exdays) { $.cookie(cname, (cvalue), { expires : exdays, path : '/' }); } function getCookie(cname) { return ($.cookie(cname)); } function removeCookie(cname) { return $.removeCookie(cname, { path : '/' }); } function clearAllCookie() { var cookies = $.cookie(); for ( var cookie in cookies) { $.removeCookie(cookie, { path : '/' }); } } function debug(o) { if(is_debug){ if (window.console) { console.log(o); } } } var Base64 = { _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode : function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode : function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode : function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode : function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }