function showLayer(width, height, customLayerID) {
	var innerLayer = "innerLayer";
	if (customLayerID != null && document.getElementById(customLayerID) != null)
		innerLayer = customLayerID;
	
	if ($("#backgroundLayer").length == 0){
		$("body").append($("<div/>").attr("id","backgroundLayer")
									.css({"position":"absolute"
									//, "background":"#000"
									, "top":"0px"
									, "left":"0px"
									//, "-ms-filter":"\"progid:DXImageTransform.Microsoft.Alpha(opacity=30)\""
									//, "filter":"progid:DXImageTransform.Microsoft.Alpha(opacity=30)"
									//, "opacity":"0.3"
									//, "-moz-opacity":"0.3"
									, "z-index":"9000"
									, "display":"none"})
		);
	}
	
	if ($("#" + innerLayer).length == 0){
		$("body").append($("<div/>").attr("id","innerLayer")
									.css({"position":"absolute"
									, "display":"none"
									, "padding":"0px"
									, "border":"3px solid #777"
									, "background":"#fff"
									, "z-index":"9001"})
		);
	} else {
		$("#" + innerLayer).css({"position":"absolute"
							, "display":"none"
							, "background":"#FFF"
							, "z-index":"9001"})
	}

	//IE6.0 ÀÌÇÏ ¹öÀü¿¡¼­´Â SelectBox°¡ ·¹ÀÌ¾î¸¦ Åë°úÇÏ±â ¶§¹®¿¡ ¾Èº¸ÀÌ°Ô Ã³¸®ÇÑ´Ù.	
	if (jQuery.browser.version == "6.0") {	
		$("select").each(function(){
			$(this).css("visibility","hidden");
		})
		
		$("select","#"+innerLayer).each(function(){
			$(this).css("visibility","visible");
		})
	}
		
	var backgroundHeight = document.body.clientHeight;
	if (document.body.scrollHeight > document.body.clientHeight)
		backgroundHeight = document.body.scrollHeight;
	
	var div = $("#backgroundLayer");
	div.css("width", document.body.scrollWidth)
			.css("height", backgroundHeight)
			.show();

	var left, top, scrollTop;
	if (document.body.scrollTop == 0)
		scrollTop = document.documentElement.scrollTop;
	else
		scrollTop = document.body.scrollTop;

	left = (document.body.clientWidth / 2) - width;
	top = (document.body.clientHeight / 2) - height + scrollTop;
	
	//div.css("top", scrollTop)
	//¿¡´©¸®ÀÎ °æ¿ì´Â °íÁ¤À§Ä¡°ª
	if (document.location.host.indexOf("enuri") > -1){
		try {
			var pos = cfGetEventPosition();
			$("#" + innerLayer).show().css("left", left + 100).css("top", pos.y - height);
		} catch(e){
			$("#" + innerLayer).show().css("left", left).css("top", top);
		}
	} else
		$("#" + innerLayer).show().css("left", left).css("top", top);
	
}

function hiddenLayer(customLayerID) {
	var innerLayer = "innerLayer";
	
	if (customLayerID != null && document.getElementById(customLayerID) != null)
		innerLayer = customLayerID;
		
	$("#backgroundLayer").css("display", "none");
	$("#" + innerLayer).css("display", "none");
	
	//IE6.0¿¡¼­ Ã³¸®
	if (jQuery.browser.version == "6.0") {	
		$("select").each(function(){
			$(this).css("visibility","visible");
		})
	}
}

function onlyMoney(obj) {
	var oElement = obj;
	var charChk;

	for (var i = 0; i < oElement.value.length; i++) {
		charChk = oElement.value.charCodeAt(i);
		if ((charChk > 57 || charChk < 48) && charChk != 44) {
			alert("°ø¹é¾øÀÌ ¼ýÀÚ·Î¸¸ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
	
	obj.value = obj.value.split(",").join("").money();
}

function onlyNumber() {
	var oElement = (arguments[0] != null) ? arguments[0] : this;
	var charChk;

	for (var i = 0; i < oElement.value.length; i++) {
		charChk = oElement.value.charCodeAt(i);
		if (charChk > 57 || charChk < 48) {
			alert("°ø¹é¾øÀÌ ¼ýÀÚ·Î¸¸ ÀÔ·ÂÇØÁÖ¼¼¿ä.");
			oElement.value = oElement.value.substring(0, i);
			oElement.focus();
			return;
		}
	}
}
	
function autoHeight(obj, defaultHeight){
	var height = obj.scrollHeight;
	var thisObjHeight = 115;	//±âº» ³ôÀÌ°ª
	
	if (defaultHeight != null)
		thisObjHeight = defaultHeight;
	
	if (height > thisObjHeight)
		$(obj).css("height",obj.scrollHeight + "px");
	else
		$(obj).css("height",thisObjHeight + "px");
}
	
function ContentHeightCK(objID){
	var content = $("#" + objID);
	
	if (content.css("height").toLowerCase().replace("px","") < content.attr("scrollHeight"))
		content.css("height",content.attr("scrollHeight") + "px");
}
	
var maxTable = 0;
function autoScroll(tableID){
	var s_Table = $("#" + tableID).html().toLowerCase().split("</table>");
	$("#" + tableID + "_view").empty();
	
	for( var i=0;i<s_Table.length;i++){
		if (s_Table[i] != ""){
			$("#" + tableID + "_view").append(s_Table[i] + "</table>")
			window.setTimeout("fadeTable("+i+", '" + tableID + "')", (i*2000));
		}
	}
	maxTable = s_Table.length;
}

function fadeTable(i, tableID){
	if (i != 0 && i%3 == 0){
		$("#" + tableID + "_view table").each(function(e){
			if (e < i)
				$(this).css("display","none");
		})
	}
		
	$($("#" + tableID + "_view table")[i]).fadeIn("slow");
	
	if ((maxTable-2) == i){
		window.setTimeout("autoScroll('" + tableID + "')", 2000);
	}
}

function fGetXY(aTag){ 
	var oTmp = aTag; 
	var pt = new Point(0,0); 
	do { 
			pt.x += oTmp.offsetLeft; 
			pt.y += oTmp.offsetTop; 
			oTmp = oTmp.offsetParent; 
	} while(oTmp.tagName!="BODY"); 
	return pt; 
}

function Point(iX, iY){ 
	this.x = iX; 
	this.y = iY; 
}

// ¹®ÀÚ¿­ ¼Ó¼º

//¼ýÀÚ 3ÀÚ¸®¸¶´Ù ½°Ç¥ Ãß°¡
String.prototype.money = function() {
    var num = this.trim();

    while ((/(-?[0-9]+)([0-9]{3})/).test(num)) {
        num = num.replace((/(-?[0-9]+)([0-9]{3})/), "$1,$2");
    }

    return num;
};

//°ø¹éÁ¦°Å
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

//°ø¹éÁ¦°Å
String.prototype.Trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
};

//Æ¯Á¤ ¼ö¸¸Å­ 0 Ã¤¿ò
String.prototype.digits = function(cnt) {
	var digit = "";

	if (this.length < cnt) {
		for(var i = 0; i < cnt - this.length; i++) {
			digit += "0";
		}
	}

	return digit + this;
};

//±Û¾²±â Ã¼Å©
function max_write(maxByte, obj) {
	var temp;
	var maxLen = maxByte;

	var len = obj.value.length;

	for (i = 0; i < len; i++) {
		temp = obj.value.charAt(i);

		if (escape(temp).length > 4)
			maxLen -= 2;
		else
			maxLen--;

		if (maxLen < 0) {
			alert("³»¿ëÀº ¿µ¹® " + maxByte + "ÀÚ, ÇÑ±Û " + maxByte / 2 + "ÀÚ ÀÌ³»·Î ÀÛ¼ºÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
			obj.value = obj.value.substring(0, i);
			obj.focus();
			break;
		}
	}
}

//±æÀÌÃ¼Å©
function maxlength_check(maxlen, obj, returnYN) {
	var len = obj.value.length;
	var result;
	
	if (len > maxlen){
		alert(maxlen + "ÀÚ ÀÌ»ó ÀÛ¼ºÇÏ½Ç ¼ö ¾ø½À´Ï´Ù.");
		obj.value = obj.value.substring(0,maxlen);
		result = false;
	} else
		result = true;
		
	if (returnYN != null && returnYN)
		return result;
}

//pos.x xÁÂÇ¥, pos.y yÁÂÇ¥
function cfGetEventPosition(evt) {
	var e = evt || window.event;
	var b = document.body;
	var scroll = cfGetScrollOffset();
	var pos = {
 			x : e.pageX || e.clientX+scroll.x-b.clientLeft,
			y : e.pageY || e.clientY+scroll.y-b.clientTop
		}
	return pos;
}

function cfGetScrollOffset(win) {
	if (!win) win = self;
	var x = win.pageXOffset || win.document.body.scrollLeft || document.documentElement.scrollLeft || 0;
	var y = win.pageYOffset || win.document.body.scrollTop || document.documentElement.scrollTop || 0;
	return { x:x, y:y };
}

	
// °¡·Î, ¼¼·Î ÃÖ´ë »çÀÌÁî ¼³Á¤
//classObj class¸í
//maxWidth, maxHeight	: °¡·Î * ¼¼·Î ÃÖ´ë°ª
var errorCnt = 0;	//ErrorÈ½¼ö
function imageResize(classObj, maxWidth, maxHeight){
	$("." + classObj).each(function(i){
		errorCnt = 0;
		obj = $(this)
		setImageSize(obj, maxWidth, maxHeight);
	});
}

function setImageSize(obj, maxWidth, maxHeight){
	var width = obj.width();
	var height = obj.height();
	var resizeWidth, resizeHeight;

	// °¡·Î³ª ¼¼·ÎÀÇ ±æÀÌ°¡ ÃÖ´ë »çÀÌÁîº¸´Ù Å©¸é ½ÇÇà  
	if (width > maxWidth || height > maxHeight){
		// °¡·Î°¡ ¼¼·Îº¸´Ù Å©¸é °¡·Î´Â ÃÖ´ë»çÀÌÁî·Î, ¼¼·Î´Â ºñÀ² ¸ÂÃç ¸®»çÀÌÁî
		if(width > height){
			resizeWidth = maxWidth;
			resizeHeight = parseInt(Math.round(parseFloat(height * resizeWidth) / parseFloat(width)));
		// ¼¼·Î°¡ °¡·Îº¸´Ù Å©¸é ¼¼·Î´Â ÃÖ´ë»çÀÌÁî·Î, °¡·Î´Â ºñÀ² ¸ÂÃç ¸®»çÀÌÁî
		}else{
			resizeHeight = maxHeight;
			resizeWidth = parseInt(Math.round(parseFloat(width * resizeHeight) / parseFloat(height)));
		}
	// ÃÖ´ë»çÀÌÁîº¸´Ù ÀÛÀ¸¸é ¿øº» ±×´ë·Î
	}else{
		resizeWidth = width;
		resizeHeight = height;
	}
	
	var maxErrorCnt = 3;
	//ÀÌ¹ÌÁö »çÀÌÁî°¡ Á¤»óÀûÀ¸·Î Ã³¸®µÇÁö ¾ÊÀ¸¸é 1ÃÊ ÈÄ ¹Ýº¹( ÃÖ´ë3È¸ )
	if ((resizeWidth < 50 || resizeHeight < 50) && errorCnt < maxErrorCnt){
		errorCnt++;
		window.setTimeout(function(){
				setImageSize(obj, maxWidth, maxHeight);
			},1000);
	}else{
		if (errorCnt < maxErrorCnt)
			obj.css({"width":resizeWidth, "height":resizeHeight}).show();
	}
}
	
//Width¸¸ ¸®»çÀÌÁî
function imageResizeWidth(classObj, maxWidth){
	$("." + classObj).each(function(){
		var obj = $(this);
		var width = obj.width();
		var height = obj.height();
		var resizeWidth, resizeHeight;

		if (width > maxWidth){
			resizeWidth = maxWidth;
			resizeHeight = parseInt(Math.round(parseFloat(height * resizeWidth) / parseFloat(width)));
		} else {
			resizeWidth = width;
			resizeHeight = height;
		}

		obj.css({"width":resizeWidth, "height":resizeHeight}).show();
	});
}

//¸¶¿ì½º ¿ìÃø¹öÆ° ±ÝÁö
function rightMouse() {
	if (event.button == 2 || event.button == 3) {  
		//alert("¸¶¿ì½º ¿À¸¥ÂÊ ¹öÆ°À» »ç¿ëÇÏ½Ç¼ö ¾ø½À´Ï´Ù.");
		return false;  
	}
	return true;  
}
function rightMouseDenial(){
	document.oncontextmenu = new Function('return false');
	document.ondragstart = new Function('return false');
	document.onselectstart = new Function('return false');
	
	document.onmousedown = rightMouse;

	//ImageToolBox ±ÝÁö
	$("img").each(function(){
		$(this).attr("galleryImg",false);
	});
}

function char_filter(obj){
	var filterchar= ";$%'\"<>+\\-:=";
	var len = obj.value.length;
	var temp;
	
	for (i = 0; i < len; i++) {
		temp = obj.value.charAt(i);
		if (filterchar.indexOf(temp) > -1){
			alert("Æ¯¼ö¹®ÀÚ [ " + temp + " ]Àº(´Â) »ç¿ëÇÒ¼ö ¾ø´Â ¹®ÀÚ ÀÔ´Ï´Ù.");
			obj.value = obj.value.substring(0, i);
			obj.focus();
			break;
		}
	}
}
