var $j = jQuery;

var noDraggable = true;
var IS_RESIZING = false;

String.prototype.trim = function() {
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}

function StringBuffer() {
	this.buffer = [];
}

StringBuffer.prototype.clear = function clear() {
	this.buffer = [];
}

StringBuffer.prototype.toString = function toString() {
	return this.buffer.join("");
};

StringBuffer.prototype.append = function append(str) {
	this.buffer.push(str);
	return this;
};

Date.prototype.add = function add(type, term) {
	if(type == "year") {
		var isLastDay = false;
		var thisYear = this.getFullYear();
		var thisMonth = this.getMonth() + 1;
		var thisDate = this.getDate();

		if(thisMonth == 2) {
			var lastDay = (thisYear%400 == 0 || thisYear%4 == 0 && thisYear%100 != 0) ? 29 : 28;
			if(thisDate == lastDay) isLastDay = true;
		}

		if(isLastDay) {
			var lastDay = this.getLastDay(this.getFullYear()+term, thisMonth);
			this.setDate(lastDay);
		}

		this.setFullYear(this.getFullYear() + term);
	}

	else if(type == "month") {
		var isLastDay = false;
		var thisYear = this.getFullYear();
		var thisMonth = this.getMonth() + 1;
		var thisDate = this.getDate();
		var termMonth = thisMonth + term;

		if(thisMonth == 1 || thisMonth == 3 || thisMonth == 5 || thisMonth == 7 || thisMonth == 8 || thisMonth == 10 || thisMonth == 12) {
			if(thisDate == 31) isLastDay = true;
		} else if(thisMonth == 2) {
			var lastDay = (thisYear%400 == 0 || thisYear%4 == 0 && thisYear%100 != 0) ? 29 : 28;
			if(thisDate == lastDay) isLastDay = true;
		} else {
			if(thisDate == 30) isLastDay = true;
		}

		if(termMonth < 0) {
			var year = this.getFullYear() + Math.floor(termMonth / 12);
			var month = (termMonth % 12) + 12;

			if(isLastDay) {
				var lastDay = this.getLastDay(year, month);
				this.setDate(lastDay);
			}

			this.setFullYear(year);
			this.setMonth(parseInt(month, 10) - 1);
		}
		else if(termMonth > 12) {
			var year = this.getFullYear() + Math.floor(termMonth / 12);
			var month = (termMonth % 12);

			if(isLastDay) {
				var lastDay = this.getLastDay(year, month);
				this.setDate(lastDay);
			}

			this.setFullYear(year);
			this.setMonth(parseInt(month, 10) - 1);
		}
		else {
			var year = this.getFullYear();
			var month = parseInt(termMonth, 10);

			if(isLastDay) {
				var lastDay = this.getLastDay(year, month);
				this.setDate(lastDay);
			}

			this.setMonth(month - 1);
		}
	}

	else if(type == "day") {
		this.setTime(this.getTime() + (1000*60*60*24*term));
	}
}

Date.prototype.getLastDay = function getLastDay(year, month) {
	var lastDay = 0;
	var thisYear = 0;
	var thisMonth = 0;

	if(parseInt(month, 10) < 1 || parseInt(month, 10) > 12) {
		return null;
	}

	if(year == null || month == null) {
		thisYear = this.getFullYear();
		thisMonth = this.getMonth() + 1;
	} else {
		thisYear = year;
		thisMonth = month;
	}

	if(thisMonth == 1 || thisMonth == 3 || thisMonth == 5 || thisMonth == 7 || thisMonth == 8 || thisMonth == 10 || thisMonth == 12) {
		lastDay = 31;
	} else if(thisMonth == 2) {
		lastDay = (thisYear%400 == 0 || thisYear%4 == 0 && thisYear%100 != 0) ? 29 : 28;
	} else {
		lastDay = 30;
	}

	return lastDay;
}

Date.prototype.format = function format(format) {
	if(format == null) {
		return this.getFullYear() + "/" + (this.getMonth()+1) + "/" + this.getDate();
	} else if(format == "time") {
		return this.getFullYear() + "/" + (this.getMonth()+1) + "/" + this.getDate() + " " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds();
	} else {
		return this.getFullYear() + "/" + (this.getMonth()+1) + "/" + this.getDate();
	}
}

function setDraggable(val)
{
	noDraggable = val;
}

function initialize(leftPos)
{
	moveBarInit(leftPos);
	contentHeightInit();
	resizeHdlr();
}

function moveBarInit(leftPos)
{
	if(leftPos != null) {
		leftPos = parseInt(leftPos, 10);

		if(isNaN(leftPos) || leftPos == "") leftPos = 200;

		if(leftPos < 200) leftPos = 200;
		if(leftPos > 500) leftPos = 500;

		$j("div.s_scroll").css("left", leftPos + "px");
		$j("#leftMenuDiv").css("width", (leftPos + 5) + "px");
		$j("#leftMenuDiv_Child").css("width", (leftPos - 10) + "px");
		$j("#mboxList").css("width", (leftPos - 20) + "px");
		$j("#mainDiv").css("left", (leftPos + 5) + "px");
	}

	if( noDraggable )
	{
		$j("div.s_scroll").draggable({
			helper: 'clone',
			axis: 'x',
			opacity: '0.7',
			iframeFix: true,
			stop: function(event, ui) {
				this.style.position = "";
				var leftPos = parseInt(ui.position.left);

				if(leftPos < 200) leftPos = 200;
				if(leftPos > 350) leftPos = 350;

				$j("div.s_scroll").css("left", leftPos + "px");
				$j("#leftMenuDiv").css("width", (leftPos + 5) + "px");
				$j("#leftMenuDiv_Child").css("width", (leftPos - 10) + "px");
				$j("#mboxList").css("width", (leftPos - 20) + "px");
				$j("#mainDiv").css("left", (leftPos + 5) + "px");

				if(navigator.appVersion.indexOf("MSIE 6.0") > -1) {
					var width = document.documentElement.clientWidth;
					var leftMenuWidth = document.getElementById("leftMenuDiv").clientWidth;
					try {
						if(IE6_PADDING == null) IE6_PADDING = 0;
						document.getElementById("mainDiv").style.width = (width - leftMenuWidth - IE6_PADDING) + "px";
					} catch(err) {}
				}

				$j.post("envBasic.ds", {act:'setLeftBarPosition', leftPos:leftPos}, function (data) {
					if( data == "ER" )
					{
						alert("Fail to save a left bar position.");
					}
				});

				try {
					titleResize();
				} catch (err) { }
			}
		});
	}
}

function contentHeightInit(val)
{
	if(document.getElementById("sScroll") == null) {

		$j("div.s_scroll").css("height", "0px");
		$j("div.contents").css("height", "0px");
		$j("#footer").css("marginTop", "10px");
		$j("#footer").css("marginBottom", "10px");

		var leftHeight = $j("p.user_id").height() + $j("#side_mailmenu").height() + $j("#mboxList").height();
		$j("div.side").css("height", (leftHeight + 30) + "px");
		$j("#leftMenuDiv_Child").css("height", (leftHeight + 30) + "px");
		$j("div.s_scroll").css("height", (leftHeight + 30) + "px");

		var contentHeight = $j(document).height();

		$j("div.side").css("height", contentHeight + "px");
		$j("#leftMenuDiv_Child").css("height", contentHeight + "px");
		$j("div.s_scroll").css("height", contentHeight + "px");
		$j("div.contents").css("height", (contentHeight-10) + "px");

	} else {

		var height = 0;
		var bodyHeight = $j("div.contents").height() + 10;
		var leftHeight = 0;

		// 일정관리인 경우
		if($j(".work_schedule").size() > 0)
		{
			if(navigator.appVersion.indexOf("MSIE 6.0") > -1 || navigator.appVersion.indexOf("MSIE 7") > -1) {
				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + 113;
			} else {
				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + $j("#side_mailmenu").outerHeight();
			}

			// alert($j("#sCalendar").outerHeight()+":"+$j("div.work_schedule").outerHeight()+":"+$j("div.my_schedule").outerHeight()+":"+$j("div.public_schedule").outerHeight());

			leftHeight = leftHeight + $j("#sCalendar").outerHeight();
			leftHeight = leftHeight + $j("div.work_schedule").outerHeight();
			leftHeight = leftHeight + $j("div.my_schedule").outerHeight();
			leftHeight = leftHeight + $j("div.public_schedule").outerHeight();

			if(navigator.appVersion.indexOf("MSIE") == -1) {
				leftHeight = leftHeight + 100;
			}
		}
		// 게시판인 경우
		else if($j("div.tr_board").size() > 0)
		{
			if(navigator.appVersion.indexOf("MSIE 6.0") > -1 || navigator.appVersion.indexOf("MSIE 7") > -1) {
				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + 113;
			} else {
				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + $j("#side_mailmenu").outerHeight();
			}

			leftHeight = leftHeight + $j("div.mail").outerHeight();
			leftHeight = leftHeight + $j("div.tr_board").outerHeight() + 10;

			if(navigator.appVersion.indexOf("MSIE") == -1) {
				leftHeight = leftHeight + 50;
			}
		}
		// 그외에 모든 것
		else
		{
		    leftHeight = $j(".login_id_user").outerHeight() + $j(".mail").outerHeight() + $j(".tr_mail").outerHeight() + 30;
		    /*
			if(navigator.appVersion.indexOf("MSIE 6.0") > -1 || navigator.appVersion.indexOf("MSIE 7") > -1) {

//			    var tempVal = $j("#side_mailmenu").outerHeight() - 1000 + 30;
//              Catholic 일 경우 user_id, user_account 가 없다.
//				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + tempVal + $j(".tr_mail").outerHeight() + 10;
				leftHeight = $j(".login_id_user").outerHeight() + $j("#side_mailmenu").outerHeight() + $j(".tr_mail").outerHeight() + 30;
			}else {
//				leftHeight = $j(".user_id").outerHeight() + $j(".user_account").outerHeight() + $j("#side_mailmenu").outerHeight() + $j(".tr_mail").outerHeight() + 10;
				leftHeight = $j(".login_id_user").outerHeight() + $j("#side_mailmenu").outerHeight() + $j(".tr_mail").outerHeight() + 30;
			}
			*/
		}

		//alert($j(".user_id").height()+":"+$j(".user_account").height()+":"+$j("#side_mailmenu").height()+":"+$j(".tr_mail").height());
		//alert("leftHeight["+leftHeight+"], document.documentElement.clientHeight["+document.documentElement.clientHeight+"], document.body.offsetHeight["+document.body.offsetHeight+"], bodyHeight["+bodyHeight+"]");

		if(!window.innerWidth)
		{
			//strict mode
			if(!(document.documentElement.clientWidth == 0))
			{
				width = document.documentElement.clientWidth;
				// alert("2 : " + document.documentElement.clientHeight+","+document.body.offsetHeight+","+bodyHeight);
				height = Math.max(leftHeight, document.documentElement.clientHeight, document.body.offsetHeight, bodyHeight);
			}
			//quirks mode
			else
			{
				height = Math.max(leftHeight, document.body.clientHeight, document.body.scrollHeight, document.body.offsetHeight, bodyHeight);
			}
		}
		//w3c
		else
		{
			height = Math.max(leftHeight, document.documentElement.clientHeight, document.body.scrollHeight, document.body.offsetHeight, bodyHeight);
		}

		document.getElementById("leftMenuDiv").style.height = height+"px";
		document.getElementById("leftMenuDiv_Child").style.height = height+"px";
		document.getElementById("sScroll").style.height = height+"px";
	}

	if(navigator.appVersion.indexOf("MSIE 6.0") > -1) {

		var width = document.documentElement.clientWidth;

		if( document.getElementById("leftMenuDiv") != null )
		{
			var leftMenuWidth = document.getElementById("leftMenuDiv").clientWidth;

			try {
				if(IE6_PADDING == null) IE6_PADDING = 0;

				if(parseInt(width - leftMenuWidth - IE6_PADDING, 10) < 700)
				{
				    document.getElementById("mainDiv").style.width = "700px";
				}
				else
				{
				    document.getElementById("mainDiv").style.width = (width - leftMenuWidth - IE6_PADDING) + "px";
				}

			} catch(err) { }
		}

	}

	if( val == "1" )
	{
		return true;
	}
}

function resizeHdlr()
{
	$j(window).bind("resize", function(event) {
	    if(IS_RESIZING) return;
	    IS_RESIZING = true;

	    window.setTimeout(function()
	    {
    		contentHeightInit();
    		IS_RESIZING = false;
	    }, 200);

	    event.stopPropagation();
	});
}

function mailWrite(url, form)
{
	if(top.topframe != null && top.topframe != "undefined")
		top.topframe.selectActiveBtn();
	if(url == null) url = "mailwrite.ds?act=basic";

	$j.ajax({
		url: "mailwrite.ds?act=getComposerType",
		type: "post",
		success: function(data) {
			if(data == "1") {
				var option = "width=900,height=600,left=50,top=50,toolbar=no,status=no,scrollbars=yes,resizable=yes";

				if(form != null) {
					var date = new Date();
					var windowName = date.getTime();

					window.open("", windowName, option);
					form.action = url;
					form.target = windowName;
					form.submit();
					form.target = "";
				} else {
					window.open(url, "", option);
				}
			} else {
				if(form != null) {
					if(form.target == null || form.target != "POSTIAN_MAIN") {
						form.target = "";
					}
					form.action = url;
					form.submit();
				} else {
					self.location.href = url;
				}
			}
		},
		error: function() {
			if(form != null) {
				form.action = "mailwrite.ds?act=basic";
				form.target = "";
				form.submit();
			} else {
				self.location.href = "mailwrite.ds?act=basic";
			}
		}
	});
}

function mailRead()
{
	self.location.href = "maillist.ds?act=list";
	if(top.topframe != null && top.topframe != "undefined")
		top.topframe.selectActiveBtn();
}

function join(sourceString, targetString, delimter)
{
	if(sourceString == null) sourceString = "";
	if(targetString == null) targetString = "";
	if(delimter == null) delimter = ",";

	if(sourceString == null || sourceString == "")
	{
		sourceString = targetString
	}
	else if(sourceString != "" && targetString != "")
	{
		sourceString += delimter + targetString;
	}

	return sourceString;
}

function convertSize(size)
{
	size = parseInt(size, 10);

	if( size < 1024 )
	{
		return size + " Byte";
	}
	else if( size >= 1024 && size < 1024000 )
	{
		return Math.round(size/1024) + " KB";
	}
	else if( size >= 1024000 )
	{
		return Math.round(size/1024000) + " MB";
	}
}

function createWrapper(isUseFrame, isUseProgress)
{
	if(isUseFrame == true && $j("#backgound_wrapper_iframe").size() <= 0) {
		$j("body").append("<iframe id='backgound_wrapper_iframe' style='display:none;'></iframe>");
	}

	if(isUseProgress == true) {
		$j("body").append("<div id='backgound_wrapper_progress'></div>");
	}

    if($j("#backgound_wrapper").size() <= 0)
    {
	    $j("body").append("<div id='backgound_wrapper' style='display:none;'></div>");
	}

	var width = $j(document).width();
	var height = $j(document).height();

	$j("#backgound_wrapper").css("position", "absolute");
	$j("#backgound_wrapper").css("left", "0");
	$j("#backgound_wrapper").css("top", "0")
	$j("#backgound_wrapper").css("width", width);
	$j("#backgound_wrapper").css("height", height);
	$j("#backgound_wrapper").css("background-color", "gray");
	$j("#backgound_wrapper").css("z-index", "100");
	$j("#backgound_wrapper").css("filter", "Alpha(opacity=30)");
	$j("#backgound_wrapper").css("opacity", "0.3");
	$j("#backgound_wrapper").css("MozOpacity", "0.3");
	$j("#backgound_wrapper").css("display", "");

	if(isUseFrame == true) {
		$j("#backgound_wrapper_iframe").css("position", "absolute");
		$j("#backgound_wrapper_iframe").css("left", "0");
		$j("#backgound_wrapper_iframe").css("top", "0")
		$j("#backgound_wrapper_iframe").css("width", width);
		$j("#backgound_wrapper_iframe").css("height", height);
		$j("#backgound_wrapper_iframe").css("border", "0");
		$j("#backgound_wrapper_iframe").css("filter", "Alpha(opacity=0)");
		$j("#backgound_wrapper_iframe").css("opacity", "0.0");
		$j("#backgound_wrapper_iframe").css("MozOpacity", "0.0");
		$j("#backgound_wrapper_iframe").css("z-index", "99");
		$j("#backgound_wrapper_iframe").css("display", "");
	}

	if(isUseProgress == true) {
		var progressWidth = 300;
		var progressHeight = 200;

		var progressLeft = (width - progressWidth) / 2;
		var progressTop = (height - progressHeight) / 2;

		$j("#backgound_wrapper_progress").css("position", "absolute");
		$j("#backgound_wrapper_progress").css("left", progressLeft);
		$j("#backgound_wrapper_progress").css("top", progressTop)
		$j("#backgound_wrapper_progress").css("width", progressWidth);
		$j("#backgound_wrapper_progress").css("height", progressHeight);
		$j("#backgound_wrapper_progress").css("background-color", "#fff");
		$j("#backgound_wrapper_progress").css("z-index", "110");

		$j("#backgound_wrapper_progress").html("progressBar");
	}

	$j(window).bind("resize.backgound_wrapper", function(event) {
		if($j("#backgound_wrapper")[0])
		{
			$j("#backgound_wrapper").css("width", "0");

			var width = $j(document).width();
			var height = $j(document).height();

			$j("#backgound_wrapper").css("width", width);
			$j("#backgound_wrapper").css("height", height);
		}
	});
}

function removeWrapper()
{
	$j("#backgound_wrapper").remove();

	if($j("#backgound_wrapper_iframe").size() > 0) {
		$j("#backgound_wrapper_iframe").remove();
	}
}

/**
 *
 */
function openWin(file_, width_, height_, name_, scroll_, resizable_)
{

	var win_width = width_;
	var win_height = height_;
	var left = "50";
	var top = "50";
	var file = file_;
    var win_name = "";
    var scroll_type = "";
    var resize_type = "";

    var date = new Date();

    if( name_ == null )
    	win_name = "popup" + date.getTime();
    else
    	win_name = name_;

	if( scroll_ == null )
		scroll_type = "yes";
	else
		scroll_type = scroll_;

	if( resizable_ == null )
		resize_type = "yes";
	else
		resize_type = resizable_;

	var win_opt = "toolbar=no,width=" + win_width + ",height=" + win_height + ",left=" + left + ",top=" + top + ",status=no,scrollbars=" + scroll_type + ",resizable=" + resize_type;
	window.open(file, win_name, win_opt);
}

/**
 *
 */
function toggleCheck(name)
{
	var form = document.forms[0];

	var arrObj = document.getElementsByName(name);
	var length = arrObj.length;

	for( var i = 0; i < length; i++ )
	{
		if( form.toggle.checked )
		{
			arrObj[i].checked = true;
		}
		else
		{
			arrObj[i].checked = false;
		}
	}
}

/**
 *
 */
function showDiv(vpos, hpos, divId, imgObj, isIframe)
{
    if(isIframe == null) isIframe = false;

	hideDiv('*');

	if(imgObj != null) {
		showDivHdlr(vpos, hpos, divId, imgObj, isIframe);
	}

	$j(window).bind("resize.showDiv", function(event) {
		showDivHdlr(vpos, hpos, divId, imgObj, isIframe);
	});

	$j("#" + divId).show();
}

function showDivHdlr(vpos, hpos, divId, imgObj, isIframe)
{
	var left = 0;
	var top = 0;
	var width = 0;
	var height = 0;

	if( vpos == 'top' )
	{
		top = parseInt($j(imgObj).offset().top - $j("#" + divId).height() - 4);
	}
	else if( vpos == 'bottom' )
	{
		top = parseInt($j(imgObj).offset().top + $j(imgObj).height());
	}

	if( hpos == 'left' )
	{
		left = parseInt($j(imgObj).offset().left);
	}
	else if( hpos == 'right' )
	{
		left = parseInt($j(imgObj).offset().left + $j(imgObj).width() - $j("#" + divId).width() + 3);
	}

	$j(document).ready(function(){
		$j("#" + divId).css("left", left + "px");
		$j("#" + divId).css("top", top + "px");
	});

	if(isIframe == true) {
		width = $j("#" + divId).outerWidth();
		height = $j("#" + divId).outerHeight();

		if(document.getElementById(divId + "_iframe") == null)
		{
			$j("body").prepend("<iframe id='"+divId+"_iframe' frameborder='0px' class='layer_menu_iframe' style='border: 0px; position:absolute; left:"+left+"; top:"+top+"; margin:0px; border:0px; padding:0;'></iframe>");
		}

		left = $j("#" + divId).css("left");
		top = $j("#" + divId).css("top");

		$j("#" + divId + "_iframe")[0].style.left = left;
		$j("#" + divId + "_iframe")[0].style.top = top;

		$j("#" + divId + "_iframe").css("width", width + "px");
		$j("#" + divId + "_iframe").css("height", height + "px");
		$j("#" + divId + "_iframe").css("zIndex", 5000);
		$j("#" + divId + "_iframe").css("display", "");
		$j("#" + divId).css("zIndex", 5010);
	}
}

function showDivPop(vpos, hpos, divId, imgObj, type)
{
	hideDiv('*');

	if(imgObj != null) {
		showDivHdlrPop(vpos, hpos, divId, imgObj, type);
	}

	$j(window).bind("resize.showDiv", function(event) {
		showDivHdlrPop(vpos, hpos, divId, imgObj, type);
	});

	$j("#" + divId).show();
}

function showDivHdlrPop(vpos, hpos, divId, imgObj, type)
{
	var left = 0;
	var top = 0;
	var width = 0;
	var height = 0;

	if( vpos == 'top' )
	{
		top = parseInt($j(imgObj).offset().top - $j("#" + divId).height() - 4);
	}
	else if( vpos == 'bottom' )
	{
		top = parseInt($j(imgObj).offset().top + $j(imgObj).height());
	}

	if( hpos == 'left' )
	{
		left = parseInt($j(imgObj).offset().left);
	}
	else if( hpos == 'right' )
	{
		left = parseInt($j(imgObj).offset().left + $j(imgObj).width() - $j("#" + divId).width() + 3);
	}

	$j(document).ready(function(){
		$j("#" + divId).css("left", left + "px");
		$j("#" + divId).css("top", top + "px");
		height = $j("#" + divId).outerHeight();

        if( type == "external" )
    	{
    	    if( height > 400 )
		        $j("div.layer_move").css("height", 400 + "px");
    	}
    	else
    	{
    	    if( height > 500 )
		        $j("div.layer_move").css("height", 500 + "px");
    	}
	});


}

function showDivExt(vpos, hpos, divId, imgObj, isIframe)
{
	if(isIframe == null) isIframe = false;

	hideDiv('*');

	var left = 0;
	var top = 0;
	var width = 0;
	var height = 0;

	if(imgObj != null) {
		if( vpos == 'top' )
		{
			top = parseInt($j("#" + imgObj).offset().top - $j("#" + divId).height() - 4);
		}
		else if( vpos == 'bottom' )
		{
			top = parseInt($j("#" + imgObj).offset().top + $j("#" + imgObj).height() + 4);
		}

		if( hpos == 'left' )
		{
			left = parseInt($j("#" + imgObj).offset().left);
		}
		else if( hpos == 'right' )
		{
			left = parseInt($j("#" + imgObj).offset().left + $j("#" + imgObj).width() - $j("#" + divId).width() + 3);
		}

		$j(document).ready(function(){
			$j("#" + divId).css("left", left + "px");
			$j("#" + divId).css("top", top + "px");
		});

		if(isIframe == true) {
			width = $j("#" + divId).outerWidth();
			height = $j("#" + divId).outerHeight();

			if(document.getElementById(divId + "_iframe") == null) {
				$j("body").append("<iframe id='"+divId+"_iframe' frameborder='0px' class='layer_menu_iframe' style='border: 0px; position:absolute; left:"+left+"; top:"+top+"; margin:0px; border:0px; padding:0;'></iframe>");
			}

			left = $j("#" + divId).css("left");
			top = $j("#" + divId).css("top");

			$j("#" + divId + "_iframe")[0].style.left = left;
			$j("#" + divId + "_iframe")[0].style.top = top;

			$j("#" + divId + "_iframe").css("width", width + "px");
			$j("#" + divId + "_iframe").css("height", height + "px");
			$j("#" + divId + "_iframe").css("z-index", 5000);
			$j("#" + divId).css("z-index", 5010);
		}
	}

	if(isIframe == true) {
		$j("#" + divId + "_iframe").show();
	}

	$j("#" + divId).show();
}

/**
 *
 */
function hideDiv(div_name)
{
	if( div_name == "*" )
	{
		$j(".layer_menu").hide();
		$j(".layer_menu_iframe").css("display", "none");
	}
	else
	{
		$j("#" + div_name).hide();
		$j("#" + div_name + "_iframe").css("display", "none");
	}

	$j(window).unbind("resize.showDiv");
}

function convertHtml(data)
{

}

function parseName(email)
{
	var result = parseEmail(email);

	return result[0];
}

function parseAddr(email)
{
	var result = parseEmail(email);

	return result[1];
}

function parseId(email)
{
	var result = parseEmail(email);

	return result[2];
}

function parseDomain(email)
{
	var result = parseEmail(email);

	return result[3];
}

function parseEmail(email)
{
	var parseEmail = new Array(4);

	parseEmail[0] = "";
	parseEmail[1] = "";
	parseEmail[2] = "";
	parseEmail[3] = "";

	if( email == null )
	{
		return parseEmail;
	}

	var temp = Trim(email);

	if( temp == "" )
	{
		return parseEmail;
	}

	var pos = -1;

	var parseName   = "";
	var parseAddr   = "";
	var parseId     = "";
	var parseDomain = "";

	pos = temp.lastIndexOf("<");
	if( pos >= 0 )
	{
		parseName = Trim(temp.substring(0, pos));
		parseAddr = Trim(temp.substring(pos + 1));

		pos = parseAddr.lastIndexOf(">");
		if( pos >= 0 )
		{
			parseAddr = Trim(parseAddr.substring(0, pos));
		}
	}
	else
	{
		parseName = "";
		parseAddr = temp;
	}

	pos = parseAddr.lastIndexOf("@");
	if( pos >= 0 )
	{
		parseId = Trim(parseAddr.substring(0, pos));
		parseDomain = Trim(parseAddr.substring(pos + 1));
	}
	else
	{
		parseName = parseAddr;
		parseAddr = "";
	}

	parseEmail[0] = parseName;
	parseEmail[1] = parseAddr;
	parseEmail[2] = parseId;
	parseEmail[3] = parseDomain;

	return parseEmail;
}

function cutString(checkValue, byteLength)
{
	var result = checkValue;
	var len = checkValue.length;

	if( len > byteLength )
	{
		result = result.substring(0, byteLength);
		result += "...";
	}

	return result;
}

function displaySize(number)
{
	var result;
	var temp;
	var unit;

	if( number >= 1099511627776 )
	{
		result = number / 1099511627776;

		temp = result.toFixed(2);
		unit = "TB";
	}
	else if( number >= 1073741824 )
	{
		result = number / 1073741824;

		temp = result.toFixed(2);
		unit = "GB";
	}
	else if( number >= 1048576 )
	{
		result = number / 1048576;

		temp = result.toFixed(2);
		unit = "MB";
	}
	else
	{
		result = number / 1024;

		temp = result.toFixed(2);
		unit = "KB";
	}

	return temp + " " + unit;
}

function displayTime(timestamp)
{
	var now = new Date();

	var today = new Date();
	today.setTime(now.getTime());
	today.setHours(0);
	today.setMinutes(0);
	today.setMilliseconds(0);

	var comp = Number(today.getTime());
	timestamp = Number(timestamp);

	var param = new Date();
	param.setTime(timestamp);

	var result = "1970/01/01 00:00:00";

	if( timestamp >= comp )
	{
		result = "";

		if( param.getHours() < 10 )
		{
			result += "0";
		}

		result += param.getHours();
		result += ":";

		if( param.getMinutes() < 10 )
		{
			result += "0";
		}

		result += param.getMinutes();
		result += ":";

		if( param.getSeconds() < 10 )
		{
			result += "0";
		}

		result += param.getSeconds();
	}
	else
	{
		result = "";

		result += param.getFullYear();
		result += "/";

		if( param.getMonth() < 9 )
		{
			result += "0";
		}

		result += (param.getMonth() + 1);
		result += "/";

		if( param.getDate() < 10 )
		{
			result += "0";
		}

		result += param.getDate();
		result += " ";

		if( param.getHours() < 10 )
		{
			result += "0";
		}

		result += param.getHours();
		result += ":";

		if( param.getMinutes() < 10 )
		{
			result += "0";
		}

		result += param.getMinutes();
		result += ":";

		if( param.getSeconds() < 10 )
		{
			result += "0";
		}

		result += param.getSeconds();
	}

	return result;
}

function displayNumber(number, limitDigit)
{
	number = Number(number.toString());
	limitDigit = Number(limitDigit.toString());

	var limit = 0;
	var result = "";

	for( var i = 1; i <= limitDigit; i++ )
	{
		limit = 10 ^ i;

		if( number < limit )
		{
			result += "0";
		}
	}

	result += number;
}

function LTrim(str)
{
	var s = new String(str);

	if( s.substr(0, 1) == " " )
	{
		return LTrim(s.substr(1));
	}

	return s;
}

function RTrim(str)
{
	var s = new String(str);

	if( s.substr(s.length - 1, 1) == " " )
	{
		return RTrim(s.substring(0, s.length - 1))
	}

	return s;
}

function Trim(str, mode)
{
	if( mode == null )
	{
		return LTrim(RTrim(str));
	}
	else if( mode == 1 )
	{
		return LTrim(str);
	}
	else if( mode == 2 )
	{
		return RTrim(str);
	}

	return str;
}

function disableForm(form, isDisable)
{
	if( form.type == "text" || form.type == "textarea" )
	{
		form.value = "";
	}
	else if( form.type == "checkbox" )
	{
		form.checked = false;
	}

	form.disabled = isDisable;
}

function disableFormToggle(form)
{
	if( form.disabled )
	{
		disableForm(form, false);
	}
	else
	{
		disableForm(form, true);
	}
}

function getSelectFromIndex(selectForm)
{
	var result = "";

	for( var i = 0; i < selectForm.length; i++ )
	{
		if( selectForm.options[i].selected )
		{
			result = i;
			break;
		}
	}

	return result;
}

function getSelectFromValue(selectForm)
{
	var result = "";

	for( var i = 0; i < selectForm.length; i++ )
	{
		if( selectForm.options[i].selected )
		{
			result = selectForm.options[i].value;
			break;
		}
	}

	return result;
}

function getSelectFromText(selectForm)
{
	var result = "";

	for( var i = 0; i < selectForm.length; i++ )
	{
		if( selectForm.options[i].selected )
		{
			result = selectForm.options[i].text;
			break;
		}
	}

	return result;
}

function getSelectValueByText(selectForm, val)
{
	var result = "";

	for( var i = 0; i < selectForm.length; i++ )
	{
		if( selectForm.options[i].text == val )
		{
			result = selectForm.options[i].value;
			break;
		}
	}

	return result;
}

function getSelectTextByValue(selectForm, val)
{
	var result = "";

	for( var i = 0; i < selectForm.length; i++ )
	{
		if( selectForm.options[i].value == val )
		{
			result = selectForm.options[i].text;
			break;
		}
	}

	return result;
}

function moveUpSelect(selectForm)
{
	var selectedIndex = getSelectFromIndex(selectForm);

	if( selectedIndex == -1 || selectedIndex == 0 )
	{
		return;
	}

	var selectedText = getSelectFromText(selectForm);
	var selectedValue = getSelectFromValue(selectForm);

	selectForm.options[selectedIndex].text = selectForm.options[selectedIndex - 1].text;
	selectForm.options[selectedIndex].value = selectForm.options[selectedIndex - 1].value;

	selectForm.options[selectedIndex - 1].text = selectedText;
	selectForm.options[selectedIndex - 1].value = selectedValue;

	selectForm.options[selectedIndex].selected = false;
	selectForm.options[selectedIndex - 1].selected = true;
}

function moveDownSelect(selectForm)
{
	var selectedIndex = getSelectFromIndex(selectForm);

	if( selectedIndex == -1 || selectedIndex == selectForm.length - 1 )
	{
		return;
	}

	var selectedText = getSelectFromText(selectForm);
	var selectedValue = getSelectFromValue(selectForm);

	selectForm.options[selectedIndex].text = selectForm.options[selectedIndex + 1].text;
	selectForm.options[selectedIndex].value = selectForm.options[selectedIndex + 1].value;

	selectForm.options[selectedIndex + 1].text = selectedText;
	selectForm.options[selectedIndex + 1].value = selectedValue;

	selectForm.options[selectedIndex].selected = false;
	selectForm.options[selectedIndex + 1].selected = true;
}

function moveTopSelect(selectForm)
{
	var selectedIndex = getSelectFromIndex(selectForm);

	if( selectedIndex == -1 )
	{
		return;
	}

	var selectedText = getSelectFromText(selectForm);
	var selectedValue = getSelectFromValue(selectForm);

	var arrObj = new Array;

	for( var i = 0; i < selectedIndex; i++ )
	{
		arrObj[i] = selectForm.options[i];
	}

	for( var i = selectedIndex - 1; i >= 0; i-- )
	{
		selectForm.options[i + 1].text = arrObj[i].text;
		selectForm.options[i + 1].value = arrObj[i].value;
	}

	selectForm.options[0].text = selectedText;
	selectForm.options[0].value = selectedValue;

	selectForm.options[selectedIndex].selected = false;
	selectForm.options[0].selected = true;
}

function moveBottomSelect(selectForm)
{
	var selectedIndex = getSelectFromIndex(selectForm);

	if( selectedIndex == -1 )
	{
		return;
	}

	var selectedText = getSelectFromText(selectForm);
	var selectedValue = getSelectFromValue(selectForm);

	var arrObj = new Array;

	for( var i = selectedIndex + 1; i < selectForm.length; i++ )
	{
		arrObj[i] = selectForm.options[i];
	}

	for( var i = selectedIndex + 1; i < selectForm.length; i++ )
	{
		selectForm.options[i - 1].text = arrObj[i].text;
		selectForm.options[i - 1].value = arrObj[i].value;
	}

	selectForm.options[selectForm.length - 1].text = selectedText;
	selectForm.options[selectForm.length - 1].value = selectedValue;

	selectForm.options[selectedIndex].selected = false;
	selectForm.options[selectForm.length - 1].selected = true;
}

function dateFormat(d)
{ // 2자리 숫자료 변경
	var str = new String();

	if( parseInt(d, 10) < 10 )
	{
		str = "0" + parseInt(d, 10);
	}
	else
	{
		str = "" + parseInt(d, 10);
	}

	return str;
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function getCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;

	while (i < clen) {
		//while open
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	} //while close

	return null;
}

function setCookie(name, value)
{
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function isNormality(org)
{
	for ( var i = 0 ; i < org.length ; i++ )
	{
		if ( org.charAt(i) == '' )
			return false;
	}

	var regExp = new RegExp();
	regExp = /[,\[\]{}<>\';\"]/;

	if( regExp.test(org) )
		return false;
	return true;
}

function checkIP(value)
{
	if(value.indexOf("~") > 0) {
		var ip = value.split("~");
		for(var i=0; i<ip.length; i++) {
			var temp = ip[i].trim().split(".");

		    if(temp.length != 4) {
		    	return false;
		    }

		    if( chkIpNum( temp[0], 1) && chkIpNum( temp[1], 2) && chkIpNum( temp[2], 3) && chkIpNum( temp[3], 4) ) {
		        continue;
		    } else {
		    	return false;
		    }
		}
		return true;
	} else {
	    if ( value == "255.255.255.255" )
	    	return false;

	    var temp = value.split(".");

	    if(temp.length != 4) {
	    	return false;
	    }

	    if( chkIpNum( temp[0], 1) && chkIpNum( temp[1], 2) && chkIpNum( temp[2], 3) && chkIpNum( temp[3], 4) ) {
	        return true;
	    } else {
	    	return false;
	    }
	}
}

function chkIpNum( ipObj, position )
{
	if( ipObj != '0' ) {
      ipObj = ipObj.replace( new RegExp( '^0+','g') ,'');
    }

	var minNum = 1;
    if( position ==2 || position ==3 ) {
        minNum = 0;
    }

	if(isNumeric(ipObj)) {
		if( !(ipObj.match( /\d{1,3}/ ) && ipObj >=minNum && ipObj <= 255) ) {
	        return false;
	    }
	} else {
		if( !(ipObj.match( /\d{1,3}|[*?~]/ )) ) {
	        return false;
	    }
	}

    return true;
}

function logout()
{
	parent.location = "logout.ds";
}

function formDisableEnter(e)
{
	if( event.keyCode == 13 && e.srcElement.type != "textarea" )
	{
		return false;
	}
}

function setComma(val)
{
    return Number(String(val).replace(/\..*|[^\d]/g, "")).toLocaleString().slice(0, -3);
}

function DetectBrowser()
{
	var arrNavi = new Array(2);

	var userAgent = navigator.userAgent;

	var iPhone = /iPhone OS (\d+\_\d+)/;
	var Android = /Android (\d+\.\d+)/;
	var Netscape = /Navigator[\/\s](\d+\.\d+\.\d+\.\d+)/;
	var FireFox = /Firefox[\/\s](\d+\.\d+(\.\d+)?)/;
	var MSIE = /MSIE (\d+\.\d+);/;
	var Opera = /Opera[\/\s](\d+\.\d+)/;
	var Safari = /Version[\/\s](\d+\.\d+\.\d+)\sSafari[\/\s](\d+\.\d+)/;
	var Chrome = /Chrome[\/\s](\d+\.\d+\.\d+\.\d+)/;
	var Mozilla = /Mozilla[\/\s](\d+\.\d+).*\;[\/\s]rv\:(\d+\.\d+\.\d+)/;

	if( iPhone.test(userAgent) )
	{
		arrNavi[0] = "iphone";
		arrNavi[1] = RegExp.$1;
	}
	else if( Android.test(userAgent) )
	{
		arrNavi[0] = "android";
		arrNavi[1] = RegExp.$1;
	}
	else if( Netscape.test(userAgent) )
	{
		arrNavi[0] = "netscape";
		arrNavi[1] = RegExp.$1;
	}
	else if( FireFox.test(userAgent) )
	{
		arrNavi[0] = "firefox";
		arrNavi[1] = RegExp.$1;
	}
	else if( MSIE.test(userAgent) )
	{
		arrNavi[0] = "msie";
		arrNavi[1] = RegExp.$1;
	}
	else if( Opera.test(userAgent) )
	{
		arrNavi[0] = "opera";
		arrNavi[1] = RegExp.$1;
	}
	else if( Safari.test(userAgent) )
	{
		arrNavi[0] = "safari";
		arrNavi[1] = RegExp.$1 + " (" + RegExp.$2 + ")";
	}
	else if( Chrome.test(userAgent) )
	{
		arrNavi[0] = "chrome";
		arrNavi[1] = RegExp.$1;
	}
	else if( Mozilla.test(userAgent) )
	{
		arrNavi[0] = "mozilla";
		arrNavi[1] = RegExp.$2;
	}
	else
	{
		arrNavi[0] = "unknown";
		arrNavi[1] = 0;
	}

	return arrNavi;
}

function resizeIframe(id)
{
    var obj = document.getElementById(id);
    var Body;
    var H, Min;

    // 최소 높이 설정 (너무 작아지는 것을 방지)
    Min = 200;

    var contentHeight = $j(document).height();
/*
	$j("div.side").css("height", contentHeight + "px");
	$j("#leftMenuDiv_Child").css("height", contentHeight + "px");
	$j("div.s_scroll").css("height", contentHeight + "px");
	$j("div.contents").css("height", (contentHeight-10) + "px");
*/
    // DOM 객체 할당
    try
    {
        if (!document.all && obj.contentWindow.document.location.href == 'about:blank')
        {
            setTimeout("resizeIframe('" + id + "')", 10);
            return;
        }

        Body = obj.contentWindow.document.getElementsByTagName('BODY');
        Body = Body[0];

        if (this.Location != obj.contentWindow.document.location.href)
        {
            H = contentHeight;
            obj.style.height =  (H < Min ? Min : H) + 'px';
            this.Location = obj.contentWindow.document.location.href;
        }
    }
    catch(e)
    {
        setTimeout("resizeIframe('" + id + "')", 10);
        return;
    }

    setTimeout("resizeIframe('" + id + "')", 100);
}

function iframeResize(id)
{
    var userAgent = navigator.userAgent;
    var iframeHeight;
    if( userAgent.indexOf("MSIE") != -1 )
    {
        iframeHeight = document.body.scrollHeight;
    }
    else
    {
        iframeHeight = $j(document).height();
    }

    parent.document.getElementById(id).height= iframeHeight + 20 + "px";
}


