//
var ajaxClassic = function(url, async, method) {
this.url = url;
this.async = async || false;
this.method = method || 'GET';
this.params = '';
this.req = null;
this.success = function() {};
this.fail = function(req) { alert('요청에 실패하였습니다.(' +req.status+ ' 에러)') };
this.ready = function() {};
this.param = function(name, value) {
if (name && typeof(value) != 'undefined' && value !== null) {
this.params += name + '=' + encodeURIComponent(value) + '&';
}
};
this.send = function(url, async, method) {
if (url) this.url = url;
else url = this.url;
if (async) this.async = async;
else async = this.async;
if (method) this.method = method;
else method = this.method;
var params = this.params.replace(/&$/, '');
if (method.match(/GET/i)) {
url += '?' + params;
params = '';
}
else if (!params) params = '?';
var req = {};
if (window.XMLHttpRequest) req = new XMLHttpRequest();
else if (window.ActiveXObject) req = new ActiveXObject("Microsoft.XMLHTTP");
else {
alert("지원하는 통신 객체가 존재하지 않습니다.");
return false;
}
var self = this;
req.onreadystatechange = function() {
if (async == true) {
if (req.readyState == 4) {
if (req.status == 200) self.success(req);
else if (req.status >= 12000 || req.status == 0) self.send();
else self.fail(req);
}
else self.ready(req);
}
}
try {
req.open(method, url, async);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.setRequestHeader('Cache-Control', 'no-cache');
req.setRequestHeader('Pragma', 'no-cache');
req.setRequestHeader('Expires', '-1');
req.setRequestHeader('If-Modified-Since', 'Thu, 1 Jan 1970 00:00:00 GMT');
req.send(params);
}
catch (e) {}
this.req = req;
if (async == false) {
if (req.status == 200) this.success(req);
else if (req.status >= 12000) self.send();
else this.fail(req);
}
};
this.dom = function() {
var req = this.req;
var response = req.responseXML;
return response.documentElement;
};
this.node = function(nodeName) {
var dom = this.dom();
return dom.getElementsByTagName(nodeName);
};
this.nodeValue = function(nodeName) {
var node = this.node(nodeName);
try {
var item = node.item(0);
if (item && item.childNodes) {
var nodeValue = '';
for (var i = 0; i < item.childNodes.length; i++) {
var child = item.childNodes.item(i);
nodeValue += child.nodeValue;
}
return nodeValue;
}
} catch (e) { alert(e.message); }
};
this.html = function() {
var req = this.req;
return req.responseText;
};
};
var call = {
cnt: 0,
pathMaxLen: 0,
loaded: 0,
funcSet: new Array(),
funcIndex: 0,
cssSet: new Array(),
css: function() {
var args = this.css.arguments;
for (var i = 0; i < args.length; i++) {
if (this.cssSet[args[i]]) continue;
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = args[i]; //Path of your Stylesheet files
link.media = 'screen';
document.getElementsByTagName('head')[0].appendChild(link);
this.cssSet[args[i]] = true;
}
},
createFunction: function(args) {
var func = escape(args[0]);
while (this.funcSet[func]) {
func += '::addFunc';
}
this.funcSet[func] = new Array();
var cnt = 0;
this.funcSet[func][0] = args[0];
for (var idx = 1; idx < args.length; idx++) {
this.funcSet[func][idx] = args[idx];
}
},
func: function() {
this.createFunction(this.func.arguments);
if (this.loaded == 1) return this.funcExec();
return false;
},
exec: function() {
if (this.loaded == 0) {
alert('확장 요소가 아직 구성되지 않았습니다. 몇 초 뒤에 시도하세요.');
return false;
}
this.createFunction(this.exec.arguments);
return this.funcExec();
},
funcExec: function() {
var returnValue;
for (var index in this.funcSet) {
var func = call.funcSet[index][0];
if (typeof(func) == 'string' || typeof(func) == 'function') {
var code = '';
if (typeof(func) == 'string') {
code += func + '(';
}
else if (typeof(func) == 'function') {
code += "call.funcSet['" +index+ "'][0](";
}
for (var idx = 1; idx < this.funcSet[index].length; idx++) {
code += "call.funcSet['" +index+ "'][" +idx+ "], ";
}
code = code.replace(/, $/, '');
code += ');';
try { returnValue = eval(code); }
catch (e) { alert(unescape(code) +': '+ e.message); }
}
}
this.funcSet = new Array();
this.funcIndex = 0;
return returnValue;
},
call: function() {
setTimeout(function() {
var script = document.createElement('script');
script.defer = true;
script.charset = 'utf-8';
script.src = '/proxy/js/auto.pl?' + (new Date()).getTime();
try {
document.getElementsByTagName('head').item(0).appendChild(script);
} catch (e) { alert(e.message); }
}, 1);
}
};
onload = function() { call.call() };
var em = {
name: function(idx) {
return document.getElementsByName(idx);
},
tags: function(idx) {
return document.getElementsByTagName(idx);
},
id: function(idx) {
return document.getElementById(idx);
},
all: function(idx) {
var id = this.id(idx);
if (id) return id;
else return this.name(idx).item(0);
},
childElement: function(element, attribute, key, depth) {
if (typeof(element) == 'string') {
element = em.all(element);
}
for (var i = 0; i < element.childNodes.length; i++) {
var node = element.childNodes.item(i);
if (node[attribute] == key) return node;
if (node.childNodes) {
var rNode = this.childElement(node, attribute, key, depth + 1);
if (rNode) return rNode;
}
}
},
value: function(idx) {
if (this.all(idx)) {
if (this.all(idx).value) return this.all(idx).value;
else if (this.all(idx).innerHTML) return this.all(idx).innerHTML;
else return '';
}
},
focus: function(name) {
try { this.all(name).focus(); }
catch (e) { return false; }
return true;
},
getParent: function(obj, tagName) {
var parent = obj;
while (parent = parent.parentNode) {
if (typeof(parent.tagName) == 'string' && parent.tagName.toLowerCase() == tagName) {
return $e(parent);
}
}
},
childDisable: function(element, disabled) {
for (var i = 0; i < element.childNodes.length; i++) {
var node = element.childNodes.item(i);
try {
node.disabled = disabled;
} catch (e) {}
if (node.childNodes) this.childDisable(node, disabled);
}
}
};
var $e = function(node) {
if (typeof node == 'string') {
node = em.all(node);
}
if (!node) return null;
var elementObject = {
click: function(func) { this.onclick = func },
mouseover: function(func) { this.onmouseover = func },
mousedown: function(func) { this.onmousedown = func },
mouseup: function(func) { this.onmouseup = func },
mouseout: function(func) { this.onmouseout = func },
keyup: function(func) { this.onkeyup = func },
keydown: function(func) { this.onkeydown = func },
execute: function(func) {
if (func) this.func = func;
if (typeof this.func == 'function') {
this.func();
}
},
getParent: function(tagName) {
if (tagName) return $e(em.getParent(this, tagName));
return $e(this.parentNode);
},
css: function() {
var cssPropertys = this.css.arguments;
if (typeof cssPropertys[0] == 'string') {
cssPropertys = [ cssPropertys ];
}
for (var i = 0; i < cssPropertys.length; i++) {
var name = cssPropertys[i][0];
var value = cssPropertys[i][1];
this.style[name] = value;
}
},
removeChilds: function() {
while (this.childNodes.length) {
this.removeChild(this.childNodes.item(0));
}
},
renewal: function(element) {
this.removeChilds();
this.appendChild(element);
},
autoText: function(option, optionChild) {
if (!$(this).attr('data-bigen')) {
$(this).attr('data-bigen', this.innerHTML);
}
else $(this).html($(this).attr('data-bigen'));
var optionBase = option.optionAnalyze();
var element = document.createElement('var');
while (this.childNodes.length) {
var child = this.childNodes.item(0);
var optionTag = optionBase;
optionTag.merge = true;
element.appendChild(this.innerHTML.image(optionTag));
this.removeChild(child);
}
this.renewal(element);
},
setAttr: function(name, value) { this[name] = value },
getElementsByAttribute: function(attrType, attrName, addArgs) {
attrName = attrName.toLowerCase();
var elementMatch = function(eName, name) {
var eNames = eName.split(/ /);
for (var i = 0; i < eNames.length; i++) {
if (eNames[i] && eNames[i].toLowerCase() == name.toLowerCase()) {
return true;
}
}
return false;
};
var isAddTerms = function(element) {
var result = true;
if (typeof addArgs == 'undefined') return result;
for (var i = 0; i < addArgs.length; i++) {
var type = addArgs[i].type;
var name = addArgs[i].name;
try { name.toLowerCase() } catch(e) { alert(e.message); }
if (elementMatch(element[type], name) == false) {
result = false;
}
}
return result;
};
var tags = this.getElementsByTagName('*');
var elements = [];
for (var i = 0; i < tags.length; i++) {
var element = tags[i];
var attribute = element[attrType];
if (attribute && elementMatch(attribute, attrName) == true && isAddTerms(element) == true) {
elements.push($e(element));
}
}
elements.item = function(index) { return this[index] };
return elements;
},
childDisable: function(disabled, child) {
if (!child) child = this;
for (var i = 0; i < child.childNodes.length; i++) {
var node = child.childNodes.item(i);
try {
node.disabled = disabled;
} catch (e) {}
if (node.childNodes) this.childDisable(disabled, node);
}
},
getRect: function() {
var rect = {
top: this.offsetTop,
left: this.offsetLeft,
width: this.offsetWidth,
height: this.offsetHeight
};
if (this.getBoundingClientRect) {
var obj = this.getBoundingClientRect();
if (!rect.top) rect.top = obj.top;
if (!rect.left) rect.left = obj.left;
if (!rect.width) rect.width = obj.right - obj.left;
if (!rect.height) rect.height = obj.bottom - obj.top;
}
else if (document.getBoxObjectFor) {
var obj = document.getBoxObjectFor(this);
if (!rect.top) rect.top = obj.y;
if (!rect.left) rect.left = obj.x;
if (!rect.width) rect.width = obj.width;
if (!rect.height) rect.height = obj.height;
}
return rect;
},
exif: function() {
var imgs = this.getElementsByTagName('img');
var keep = [];
var analyze = function(element) {
var img = element.img;
element.appendChild(img);
var span = $e(document.createElement('span'));
span.style.display = 'none';
element.appendChild(span);
img.onmouseover = function() {
var rect = img.getRect();
element.style.width = rect.width.str('px');
element.style.height = rect.height.str('px');
if (this.meta) {
span.style.display = '';
span.renewal(document.createTextNode(this.meta));
}
else {
var ax = new ajaxClassic();
ax.param('src', img.src);
ax.success = function() {
var result = this.node('result').item(0);
if (result) {
img.meta = result.getAttribute('meta');
img.onmouseover();
}
};
ax.send('/proxy/async/exif.pl', true);
}
};
img.onmouseout = function() { span.style.display = 'none' };
};
var change = function() {
var img = $e(imgs.item(0));
if (img) {
var span = document.createElement('span');
var rect = img.getRect();
span.style.width = rect.width.str('px');
span.style.height = rect.height.str('px');
img.parentNode.replaceChild(span, img);
span.img = img;
span.className = 'analyze-contents-image';
keep.push(span);
setTimeout(function() { change() }, 1);
}
else {
for (var i = 0; i < keep.length; i++) {
analyze(keep[i]);
}
}
};
setTimeout(function() { change() }, 1);
},
addEvent: function(handle, func) {
var self = this;
if (!self.eventHandle) self.eventHandle = [];
var eventName = 'on' + handle;
var eventHandle = self.eventHandle;
if (!eventHandle[eventName]) eventHandle[eventName] = [];
var handler = eventHandle[eventName];
var index = eventHandle.length;
handler.push(func);
self[eventName] = function(event) {
for (var i = 0; i < handler.length; i++) {
if (typeof handler[i] == 'function') {
handler[i](window.event ? window.event : event);
}
}
};
return {
index: index,
clear: function() { handler[index] = null }
};
}
}
node.extended = [];
for (var attribute in elementObject) {
try {
node[attribute] = elementObject[attribute];
node.extended.push(attribute);
} catch (e) {}
}
return node;
};
var $eTree = function() {
var cssSelectors = $eTree.arguments;
var selectedElements = [];
var selectorType = function(selector) {
switch (selector) {
case '#': return 'id';
case '.': return 'className';
default: return 'tagName';
}
};
var setSelector = function(selector, element, selectIndex) {
var selectorName = selector[selectIndex++].replace(/^\s+|\s+$/, '');
if (selectorName) {
var childs = [];
var first = selectorName.match(/^(.)([\w\-]+)/);
if (!first) {
first = selectorName.match(/^(.)/);
first[2] = '';
}
var firstType = selectorType(first[1]);
var firstName = firstType == 'tagName' ? first[1] + first[2] : first[2];
var addArgs = [];
if (selectorName = selectorName.replace(/^.[\w\-]+/, '')) {
var match = selectorName.match(/[^\w][\w\-]+/g);
if (match !== null) {
for (var i = 0; i < match.length; i++) {
var type = match[i].replace(/^(.).+$/, '$1');
var name = match[i].replace(/^./, '');
addArgs.push({ type: selectorType(type), name: name });
}
}
}
childs = element.getElementsByAttribute(firstType, firstName, addArgs);
for (var i = 0; i < childs.length; i++) {
if (selectIndex == selector.length) {
selectedElements.push(childs.item(i));
}
else {
setSelector(selector, childs.item(i), selectIndex);
}
}
}
};
var documentBody = $e(document.body);
var extended = documentBody.extended;
var cssSelector = [];
for (var i = 0; i < cssSelectors.length; i++) {
if (typeof cssSelectors[i] == 'object' && cssSelectors[i].nodeType) {
selectedElements.push(cssSelectors[i]);
}
else cssSelector.push(cssSelectors[i]);
}
var multiSelector = cssSelector.join(',').split(',');
for (var i = 0; i < multiSelector.length; i++) {
var selector = multiSelector[i].replace(/^\s+|\s+$/, '').split(' ');
setSelector(selector, documentBody, 0);
}
var object = {};
var executeFunction = function(method, args) {
var argument = '';
for (var i = 0; i < args.length; i++) {
argument += 'args[' +i+ '],';
}
argument = argument.replace(/,$/, '');
for (var i = 0; i < selectedElements.length; i++) {
var element = selectedElements[i];
eval("element[method](" +argument+ ");");
}
return object;
};
for (var i = 0; i < extended.length; i++) {
var extName = extended[i];
eval("object[extName] = function() { return executeFunction('" +extName+ "', object." +extName+ ".arguments) }");
}
return object;
}
/**
Number prototype
*/
Number.prototype.str = function(add) {
var string = new String(this);
return add ? string + add : string;
};
Number.prototype.num = function() { return Number(this); };
Number.prototype.format = function(tail) {
var format = this.str().reverse().replace(/(\d{3})(?=\d)(?!\d+\.)/g, '$1,').reverse();
return tail ? format.str(tail) : format;
};
Number.prototype.unitBase = function() {
switch (Number(this)) {
case 1: return '일';
case 2: return '이';
case 3: return '삼';
case 4: return '사';
case 5: return '오';
case 6: return '육';
case 7: return '칠';
case 8: return '팔';
case 9: return '구';
}
return '';
};
Number.prototype.unitLow = function() {
switch (Number(this)) {
case 1: return '십';
case 2: return '백';
case 3: return '천';
}
return '';
};
Number.prototype.unitHeigh = function() {
switch (Number(this)) {
case 1: return '만';
case 2: return '억';
case 3: return '조';
}
return '';
};
Number.prototype.unit = function() {
var num = this.str();
var len = num.length;
var buff = 4;
var tail = len % buff;
var loop = parseInt(len / buff) + (tail ? 1 : 0);
var returnValue = '';
var cnt = 0;
while (loop--) {
len = len - buff;
var chr = num.substr(len > 0 ? len : 0, (tail && loop == 0 ? tail : buff));
var loopChar = new Array(
chr.length >= 3 ? chr.substr(3, 1) : '',
chr.length >= 2 ? chr.substr(2, 1) : '',
chr.length >= 1 ? chr.substr(1, 1) : '',
chr.length >= 0 ? chr.substr(0, 1) : ''
);
if (chr != '0000') {
returnValue = cnt.unitHeigh() + returnValue;
}
var inCnt = 0;
for (var idx in loopChar) {
if (loopChar[idx]) {
if (loopChar[idx] != '0') {
returnValue = inCnt.unitLow() + returnValue;
}
returnValue = loopChar[idx].num().unitBase() + returnValue;
inCnt++;
}
}
cnt++;
}
return returnValue;
};
Number.prototype.week = function() {
switch(Number(this)) {
case 0: return '일';
case 1: return '월';
case 2: return '화';
case 3: return '수';
case 4: return '목';
case 5: return '금';
case 6: return '토';
default: return '';
}
return '';
};
Number.prototype.pad = function(length) {
var str = this.str();
while (str.length < length) {
str = '0' + str;
}
return str;
};
/**
String prototype
*/
String.prototype.str = function(add) {
var string = new String(this);
return add ? string + add : string;
};
String.prototype.reverse = function() { return this.match(/(.)/g).reverse().join('') };
String.prototype.num = function() {
var value = this;
value = Number(value.replace(/[^\.\d\-]/g, ''));
if (!isNaN(value) && typeof value === 'number') {
return value;
}
return 0;
};
String.prototype.repeat = function(len) {
var text = '';
while (len--) text += this;
return text;
};
String.prototype.clearTag = function(tag) {
var html = this;
tag = tag ? tag : '';
var reg = new RegExp('<' +tag+ '(.*?)>', 'gi');
var reg2 = new RegExp('<\/' +tag+ '(.*?)>', 'gi');
html = html.replace(/\n/g, '\\n');
html = html.replace(/\r/g, '\\r');
html = html.replace(/\r\n/g, '\\r\\n');
html = html.replace(reg, '');
html = html.replace(reg2, '');
html = html.replace(/\\r\\n/g, '\r\n');
html = html.replace(/\\r/g, '\r');
html = html.replace(/\\n/g, '\n');
return html;
};
String.prototype.codeLength = function() {
return escape(this).replace(/%u([^%]{4})/g, '11').replace(/%([^%]{2})/g, '1').length;
};
String.prototype.checkKssn = function() {
var kssn = this;
var number = new Array();
var check = new Array(2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5);
var checked = 0;
kssn = kssn.replace(/[^0-9]/, '');
if (kssn.length != 13) return false;
kssn = kssn.replace(/[^0-9]/, '');
kssn = kssn.replace(/([0-9])/g, "$1,");
kssn = kssn.replace(/([^0-9])$/, "");
number = kssn.split(/,/);
for (var i = 0; i <= 11; i++) checked = checked + number[i] * check[i];
if ((11 - (checked % 11)) % 10 != number[12]) return false;
else return true;
};
String.prototype.img = function(option) {
var image = this.image(option);
return image.innerHTML;
};
String.prototype.image = function(option) {
var size = option.size || 12;
var color = option.color || '000';
var back = option.back || 'fff';
var font = option.font || 1;
var merge = option.merge ? true : false;
var shadow = option.shadow || 0;
var scolor = option.scolor || '888';
var html = '';
var baseNode = document.createElement('var');
baseNode.className = 'autoImage';
//baseNode.style.display = 'inline-block';
//baseNode.style.zoom = 1;
baseNode.exported = function(node) {
node = $e(node);
node.renewal(this);
};
var param = 'font=' +font+ '&size=' +size+ '&color=' +color+ '&back=' +back+ '&shadow=' +shadow+ '&scolor=' +scolor;
if (merge == true) {
var text = encodeURIComponent(this);
var img = document.createElement('img');
img.alt = this;
img.src = '/proxy/font/get.pl?' +param+ '&text=' + text;
baseNode.appendChild(img);
}
else {
var strs = this.match(/(.)/g);
for (var i = 0; i < strs.length; i++) {
var str = strs[i].replace(/\'/g, '&\#039;');
if (!str.match(/\n|\r/)) {
var text = encodeURIComponent(str);
var img = document.createElement('img');
img.alt = str;
img.src = '/proxy/font/get.pl?' +param+ '&text=' + text;
baseNode.appendChild(img);
}
}
}
return baseNode;
};
String.prototype.partEncode = function(separator) {
var uri = this;
if (!separator) separator = '/';
var disjunct = uri.split(separator);
for (var i = 0; i < disjunct.length; i++) {
disjunct[i] = encodeURIComponent(disjunct[i]);
}
return disjunct.join(separator);
};
String.prototype.optionAnalyze = function() {
var option = this.split(':');
return {
font: option.shift(),
size: option.shift(),
color: option.shift(),
back: option.shift(),
shadow: option.shift(),
scolor: option.shift()
};
};
// 조사 판별
String.prototype.postposition = function(str1, str2) {
return this + ((this.charCodeAt(this.length - 1) - 0xAC00) % 28 ? str1 : str2);
};
String.prototype.quotes = function() {
var str = this;
str = str.replace(/\'(.*?)\'/g, '‘$1’');
str = str.replace(/\"(.*?)\"/g, '“$1”');
return str;
};
String.prototype.htmlEntity = function() { return this.replace(//, '>') };
/**
Do not use Array, Object prototype.
*/