/*
작성자 : bughyuk@gmail.com
*/

/* 노드 합류 */
function appendChild(p_objParent, p_objChild) {
	if(p_objParent) {
		try {
			if(typeof(p_objChild) == "string") {
				p_objParent.appendChild(createText(p_objChild));

				switch(p_objParent.nodeName) {
					case "A" :
						if(p_objParent.title == "") {
							setAttribute(p_objParent, "title", p_objChild);
						}

						break;
				}
			} else {
				p_objParent.appendChild(p_objChild);
			}
		} catch(E) {
		}
	}
}

/* 자식노드 지우기 */
function deleteChild(p_objNode) {
	if(p_objNode) {
		if(checkVariable(p_objNode.hasChildNodes)) {
			if(p_objNode.hasChildNodes()) {
				for(i = (p_objNode.childNodes.length - 1); i >= 0; i --) {
					p_objNode.removeChild(p_objNode.childNodes[i]);
				}
			}

			return true;
		} else {
			return false;
		}
	}
}

/* 변수 체크 */
function checkVariable(p_objValue) {
	if(p_objValue == undefined) {
		return false;
	} else {
		if(p_objValue !== null) {
			return typeof(p_objValue);
		} else {
			return false;
		}
	}
}

/* 엘리먼트 생성 */
function createElement(p_strNode, p_objDocument, p_strType, p_strName, p_strCheck) {
	var f_objReturn = null,
		f_objDocument = p_objDocument || document,
		f_strNode = p_strNode.toUpperCase(),
		f_strType = p_strType || "",
		f_strName = p_strName || "",
		f_strCheck = p_strCheck || "";

	switch(f_strNode) {
		case "A" :
			f_objReturn = f_objDocument.createElement(f_strNode);
			f_objReturn.tabStop = true;

			try {
				f_objReturn.tabIndex = document.nTab ++;
			} catch(E) {
			}
			break;
		case "INPUT" :
			if(document.objBrowser.strGroup == "ie" && (f_strType == "radio" || f_strType == "checkbox")) {
				f_objReturn = f_objDocument.createElement("<input type=\"" + f_strType + "\" name=\"" + f_strName + "\" " + f_strCheck + " />");
			} else {
				f_objReturn = f_objDocument.createElement("INPUT");

				if(f_strType != "") {
					setAttribute(f_objReturn, "type", f_strType);
				}

				if(f_strName != "") {
					setAttribute(f_objReturn, "name", f_strName);
				}

				if(f_strCheck != "") {
					eval("f_objReturn." + f_strCheck + " = true");
				}
			}
			break;
		case "SCRIPT" :
			f_objReturn = f_objDocument.createElement("SCRIPT");
			setAttribute(f_objReturn, "language", "javascript");
			setAttribute(f_objReturn, "type", "text/javascript");
			break;
		case "LINK" :
			f_objReturn = f_objDocument.createElement("LINK");
			f_objReturn.rel = "stylesheet";
			break;
		case "TABLE" :
			f_objReturn = f_objDocument.createElement("TABLE");
			setAttribute(f_objReturn, "cellpadding", "0");
			setAttribute(f_objReturn, "cellspacing", "0");
			break;
		case "P" :
			f_objReturn = f_objDocument.createElement("P");
			f_objReturn.bMovable = false;
			break;
		default :
			f_objReturn = f_objDocument.createElement(f_strNode);

			if(f_strType != "") {
				setAttribute(f_objReturn, "type", f_strType);
			}

			if(f_strName != "") {
				setAttribute(f_objReturn, "name", f_strName);
			}

			if(f_strCheck != "") {
				void("f_objReturn." + f_strCheck + " = true");
			}
	}

	return f_objReturn;
}

/* 속성 정의 */
function setAttribute(p_objElement, p_strProperty, p_unValue) {
	try {
		var f_strProperty = p_strProperty,
			f_unValue = p_unValue,
			f_objElement = null;

		f_objElement = p_objElement;

		switch(p_strProperty.toUpperCase()) {
			case "ALT" :
				f_objElement.alt = f_unValue;
				f_objElement.title = f_unValue;
				break;
			case "MEMO" :
				break;
			case "CELLPADDING" :
				if(checkVariable(f_objElement.cellpadding)) {
					f_objElement.cellpadding = f_unValue;
				} else {
					f_objElement.setAttribute("cellPadding", f_unValue);
				}

				break;
			case "CELLSPACING" :
				if(checkVariable(f_objElement.cellspacing)) {
					f_objElement.cellspacing = f_unValue;
				} else {
					f_objElement.setAttribute("cellSpacing", f_unValue);
				}

				break;
			case "VALIGN" :
				(document.objBrowser.strGroup == "ie") ? f_objElement.vAlign = f_unValue : f_objElement.setAttribute("vAlign", f_unValue);
				break;
			case "FRAMEBORDER" :
				f_objElement.setAttribute("frameBorder", f_unValue);
				break;
			case "CONTENTEDITABLE" :
				(document.objBrowser.strGroup == "ie") ? f_objElement.setAttribute("contentEditable", f_unValue) : f_objElement.setAttribute("contentEditable", "");
				break;
			case "COLSPAN" :
				if(checkVariable(f_objElement.colSpan)) {
					f_objElement.colSpan = f_unValue;
				} else {
					f_objElement.colspan = f_unValue;
				}

				break;
			case "ROWSPAN" :
				if(checkVariable(f_objElement.rowSpan)) {
					f_objElement.rowSpan = f_unValue;
				} else {
					f_objElement.rowspan = f_unValue;
				}

				break;
			case "ENCTYPE" :
				(document.objBrowser.strGroup == "ie") ? f_objElement.setAttribute("encoding", f_unValue) : f_objElement.setAttribute(f_strProperty, f_unValue);
				break;
			case "STYLE" :
				var f_arrValue1 = p_unValue.split(";"),
					f_arrValue2 = null,
					f_arrValue3 = null,
					f_strBuffer = "";

				for(var i = 0; i < f_arrValue1.length; i ++) {
					if(f_arrValue1[i]) {
						if(trim(f_arrValue1[i]) != "") {
							f_arrValue2 = f_arrValue1[i].split(":");
							f_arrValue3 = trim(f_arrValue2[0]).split("-");

							if(f_arrValue3[1]) {
								f_strProperty = f_arrValue3[0];

								for(var j = 1; j < f_arrValue3.length; j ++) {
									f_strBuffer = f_arrValue3[j];
									f_strProperty += f_strBuffer.substr(0, 1).toUpperCase();
									f_strProperty += f_strBuffer.substr(1, f_strBuffer.length);
								}
							} else {
								f_strProperty = f_arrValue3[0];
							}

							switch(f_strProperty.toUpperCase()) {
								case "FLOAT" :
									(document.objBrowser.strGroup == "ie") ? eval("f_objElement.style.styleFloat = \"" + trim(f_arrValue2[1]) + "\";") : eval("f_objElement.style.cssFloat = \"" + trim(f_arrValue2[1]) + "\";");
									break;
								default :
									try {
										eval("f_objElement.style." + f_strProperty + " = \"" + trim(f_arrValue2[1]) + "\";");
									} catch(E) {
									}
							}
						}
					}
				}
				break;
			case "ONCLICK" :
				if(document.objBrowser.strGroup == "ie") {
					f_unValue = function() {
						eval(p_unValue)
					};
				}

				f_objElement.setAttribute(f_strProperty, f_unValue);
				break;
			case "CLASS" :
				try {
					f_objElement.className = f_unValue;
				} catch(E) {
					f_objElement.setAttribute(f_strProperty, f_unValue);
				}

				break;
			case "CHECKED" :
				(p_unValue == "checked") ? f_objElement.setAttribute(f_strProperty, true) : f_objElement.setAttribute(f_strProperty, false);
				break;
			case "READONLY" :
				(p_unValue == "readonly") ? f_objElement.setAttribute("readOnly", true) : f_objElement.setAttribute("readOnly", false);
				break;
			case "MAXLENGTH" :
				(document.objBrowser.strGroup == "ie") ? f_objElement.maxLength = f_unValue : f_objElement.setAttribute(f_strProperty, f_unValue);
				break;
			case "SRC" :
				f_objElement.src = f_unValue;
				break;
			case "HREF" :
				f_objElement.href = f_unValue;
				break;
			case "FOR" :
				f_objElement.htmlFor = f_unValue;
				break;
			case "SELECTED" :
				f_objElement.selected = "selected";
				break;
			default :
				if(f_objElement.getAttribute(f_strProperty) === null) {
					eval("f_objElement." + f_strProperty + " = f_unValue");
				} else {
					f_objElement.setAttribute(f_strProperty, f_unValue);
				}
		}
	} catch(E) {
	}
}

/* 텍스트 생성 */
function createText(p_strValue, p_objDocument) {
	return (p_objDocument || document).createTextNode(p_strValue);
}


/* 해당 태그 엘리먼트 얻기 */
function getElements(p_strName, p_objElement) {
	return (p_objElement || document).getElementsByTagName(p_strName);
}

/* 앞뒤 공백 제거 */
function trim(p_strValue) {
	var f_strReturn = "";

	try {
		f_strReturn = p_strValue.replace(/(^\s*|\s*$|\n)/g, "");
	} catch(E) {
		return "";
	} finally {
		return f_strReturn;
	}
}


/* 이미지 리사이즈 */
function resizeImage(p_objValue, p_nWidth, p_nHeight, p_bLoad) {
	/*var f_bLoad = p_bLoad || false,
		f_strSrc = "";

	if(!f_bLoad) {
		window.onload = p_objValue.onload = function() {
			if(p_objValue.offsetWidth && p_objValue.offsetHeight) {
				var f_nCase = 0,
					f_nWidth = 0,
					f_nHeight = 0;

				if(checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
					if(p_nHeight == 0) {
						f_nCase = 2;
					} else if(p_nWidth == 0) {
						f_nCase = 3;
					} else {
						f_nCase = 1;
					}
				} else if(checkVariable(p_nWidth) && !checkVariable(p_nHeight)) {
					f_nCase = 2;
				} else if(!checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
					f_nCase = 3;
				}

				switch(f_nCase) {
					case 1 :
						f_nWidth = p_nWidth;
						f_nHeight = p_nHeight;

						p_objValue.width = p_nWidth;
						p_objValue.height = p_nHeight;
						break;
					case 2 :
						if(p_objValue.offsetWidth) {
							f_nWidth = (p_objValue.offsetWidth > p_nWidth) ? p_nWidth : p_objValue.offsetWidth;
						} else {
							f_nWidth = p_nWidth;
						}

						if(p_objValue.offsetHeight) {
							f_nHeight = p_objValue.offsetHeight;
						} else {
							f_nHeight = p_nHeight;
						}

						if(p_objValue.offsetWidth > f_nWidth) {
							f_nHeight = Math.round(f_nHeight * f_nWidth / p_objValue.offsetWidth);
							p_objValue.width = f_nWidth;
							p_objValue.height = f_nHeight;
						}
						break;
					case 3 :
						f_nWidth = p_objValue.offsetWidth;
						f_nHeight = (p_objValue.offsetHeight > p_nHeight) ? p_nHeight : p_objValue.offsetHeight;

						if(p_objValue.offsetHeight > f_nHeight) {
							f_nWidth = Math.round(f_nWidth * f_nHeight / p_objValue.offsetHeight);
							p_objValue.width = f_nWidth;
							p_objValue.height = f_nHeight;
						}
						break;
				}

				p_objValue.style.width = f_nWidth.toString() + "px";
				p_objValue.style.height = f_nHeight.toString() + "px";
			}
		}
	} else {
	p_objValue.onload = function() {
		var f_nCase = 0,
			f_nWidth = 0,
			f_nHeight = 0;

		if(checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
			if(p_nHeight == 0) {
				f_nCase = 2;
			} else if(p_nWidth == 0) {
				f_nCase = 3;
			} else {
				f_nCase = 1;
			}
		} else if(checkVariable(p_nWidth) && !checkVariable(p_nHeight)) {
			f_nCase = 2;
		} else if(!checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
			f_nCase = 3;
		}

		switch(f_nCase) {
			case 1 :
				f_nWidth = p_nWidth;
				f_nHeight = p_nHeight;

				p_objValue.width = p_nWidth;
				p_objValue.height = p_nHeight;
				break;
			case 2 :
				if(p_objValue.offsetWidth) {
					f_nWidth = (p_objValue.offsetWidth > p_nWidth) ? p_nWidth : p_objValue.offsetWidth;
				} else {
					f_nWidth = p_nWidth;
				}

				if(p_objValue.offsetHeight) {
					f_nHeight = p_objValue.offsetHeight;
				} else {
					f_nHeight = p_nHeight;
				}

				if(p_objValue.offsetWidth > f_nWidth) {
					f_nHeight = Math.round(f_nHeight * f_nWidth / p_objValue.offsetWidth);
					p_objValue.width = f_nWidth;
					p_objValue.height = f_nHeight;
				}
				break;
			case 3 :
				f_nWidth = p_objValue.offsetWidth;
				f_nHeight = (p_objValue.offsetHeight > p_nHeight) ? p_nHeight : p_objValue.offsetHeight;

				if(p_objValue.offsetHeight > f_nHeight) {
					f_nWidth = Math.round(f_nWidth * f_nHeight / p_objValue.offsetHeight);
					p_objValue.width = f_nWidth;
					p_objValue.height = f_nHeight;
				}
				break;
		}

		p_objValue.style.width = f_nWidth.toString() + "px";
		p_objValue.style.height = f_nHeight.toString() + "px";
	}
	}*/

	var _p_objValue = p_objValue;
	var _p_nWidth = p_nWidth;

	setInterval(function() {sizeImage(_p_objValue, 711)}, 200);
}

function resizeImage2(p_objValue, p_nWidth, p_nHeight, p_bLoad) {
	var _p_objValue = p_objValue;
	var _p_nWidth = p_nWidth;

	setInterval(function() {sizeImage(_p_objValue, _p_nWidth)}, 200);
}

function sizeImage(p_objValue, p_nWidth, p_nHeight, p_bLoad) {
			if(p_objValue.offsetWidth && p_objValue.offsetHeight) {
				var f_nCase = 0,
					f_nWidth = 0,
					f_nHeight = 0;

				if(checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
					if(p_nHeight == 0) {
						f_nCase = 2;
					} else if(p_nWidth == 0) {
						f_nCase = 3;
					} else {
						f_nCase = 1;
					}
				} else if(checkVariable(p_nWidth) && !checkVariable(p_nHeight)) {
					f_nCase = 2;
				} else if(!checkVariable(p_nWidth) && checkVariable(p_nHeight)) {
					f_nCase = 3;
				}

				switch(f_nCase) {
					case 1 :
						f_nWidth = p_nWidth;
						f_nHeight = p_nHeight;

						p_objValue.width = p_nWidth;
						p_objValue.height = p_nHeight;
						break;
					case 2 :
						if(p_objValue.offsetWidth) {
							f_nWidth = (p_objValue.offsetWidth > p_nWidth) ? p_nWidth : p_objValue.offsetWidth;
						} else {
							f_nWidth = p_nWidth;
						}

						if(p_objValue.offsetHeight) {
							f_nHeight = p_objValue.offsetHeight;
						} else {
							f_nHeight = p_nHeight;
						}

						if(p_objValue.offsetWidth > f_nWidth) {
							f_nHeight = Math.round(f_nHeight * f_nWidth / p_objValue.offsetWidth);
							p_objValue.width = f_nWidth;
							p_objValue.height = f_nHeight;
						}
						break;
					case 3 :
						f_nWidth = p_objValue.offsetWidth;
						f_nHeight = (p_objValue.offsetHeight > p_nHeight) ? p_nHeight : p_objValue.offsetHeight;

						if(p_objValue.offsetHeight > f_nHeight) {
							f_nWidth = Math.round(f_nWidth * f_nHeight / p_objValue.offsetHeight);
							p_objValue.width = f_nWidth;
							p_objValue.height = f_nHeight;
						}
						break;
				}

				p_objValue.style.width = f_nWidth.toString() + "px";
				p_objValue.style.height = f_nHeight.toString() + "px";
			}

return {width: (f_nWidth || ""), height: (f_nHeight || "")}
}


function getCookie(p_strName) {
	var f_arrCookies = document.cookie.split("; ");
	var f_arrSep = new Array();

	for(var i = 0; i < f_arrCookies.length; i ++){
		f_arrSep = f_arrCookies[i].split("=");

		if(p_strName == f_arrSep[0]) {
			return f_arrSep[1];
			break;
		}
	}

	return null;
}

function setCookie( name, value, expiredays ){
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function incomma(str){
	str = ""+str+"";
	var retValue = "";

	for(iii=0; iii<str.length; iii++){
		if(iii > 0 && (iii%3)==0){
			retValue = str.charAt(str.length - iii -1) + "," + retValue;
		}
		else{
			retValue = str.charAt(str.length - iii -1) + retValue;
		}
	}

	if(retValue=="0"){
		return "";
	}

	return retValue;
}