﻿/* VioletDevelopmentLaboratory.Net.Web.PageBase로 상속받는 페이지에 사용가능 */

/* ------------------------------ */
/* 기본 스크립트 */
/* ------------------------------ */
var userAgentString = navigator.userAgent.toLowerCase();

var VWebGlobal_WebBrowserInfo =
{
	IsIE : userAgentString.indexOf('msie') > -1,
	IsIE6 : userAgentString.indexOf('msie 6') > -1,
	IsIE7 : userAgentString.indexOf('msie 7') > -1,
	IsIE8 : userAgentString.indexOf('msie 8') > -1,
	IsGecko : userAgentString.indexOf('gecko') > -1,
	IsSafari : userAgentString.indexOf('applewebkit') > -1,
	IsOpera : userAgentString.indexOf('opera') > -1
}



var backPanel;
var forePanel;
var contentPanel;
var footerPanel;
//var shadowPanel;

var foreCssClass = 'VWebGlobal_MessagePanel';
var backColor = '#ffffff';
var backOpacity = 0.5;
//var shadowColor = '#000000';
//var shadowOpacity = 0.4;
//var shadowDistanceX = 5;
//var shadowDistanceY = 5;

function VWebGlobal_SetMessagePanel()
{
	//배경
//	backPanel = document.createElement('div');
//	if (VWebGlobal_WebBrowserInfo.IsIE6)
//	{
//		backPanel.style.position = 'absolute';
//	}
//	else
//	{
//		backPanel.style.position = 'fixed';
//		backPanel.style.width = '100%';
//		backPanel.style.height = '100%';
//		backPanel.style.top = '0px';
//		backPanel.style.left = '0px';
//	}
//	backPanel.style.backgroundColor = backColor;
//	backPanel.style.zIndex = '100';
//	backPanel.style.display = 'none';

//	document.getElementById('VWebPlaceHolder').appendChild(backPanel);

	//그림자
//	shadowPanel = document.createElement('div');
//	if (VWebGlobal_WebBrowserInfo.IsIE6)
//	{
//		shadowPanel.style.position = 'absolute';
//	}
//	else
//	{
//		shadowPanel.style.position = 'fixed';
//	}
//	shadowPanel.style.backgroundColor = shadowColor;
//	shadowPanel.style.zIndex = '101';
//	shadowPanel.style.display = 'none';

	//document.getElementById('VWebPlaceHolder').appendChild(shadowPanel);

	//배경, 그림자 불투명도
//	if (VWebGlobal_WebBrowserInfo.IsIE6 || VWebGlobal_WebBrowserInfo.IsIE7 || VWebGlobal_WebBrowserInfo.IsIE8)
//	{
//		backPanel.style.filter = 'alpha(opacity=' + (backOpacity * 100) + ')';
//		shadowPanel.style.filter = 'alpha(opacity=' + (shadowOpacity * 100) + ')';
//	}
//	else
//	{
//		backPanel.style.opacity = backOpacity;
//		shadowPanel.style.opacity = shadowOpacity;
//	}

	forePanel = document.createElement('div');
	if(VWebGlobal_WebBrowserInfo.IsIE6)
	{
		forePanel.style.position = 'absolute';
	}
	else
	{
		forePanel.style.position = 'fixed';
	}
	forePanel.className = foreCssClass;
	forePanel.style.zIndex = '103';
	forePanel.style.display = 'none';
                
	contentPanel = document.createElement('div');
	contentPanel.style.lineHeight = '150%';
	contentPanel.style.marginBottom = '10px';

	footerPanel = document.createElement('div');
	footerPanel.style.textAlign = 'center';
	footerPanel.innerHTML = '<input type="button" value="close" onclick="javascript:VWebGlobal_HideMessagePanel();" />'

	forePanel.appendChild(contentPanel);
	forePanel.appendChild(footerPanel);

	document.getElementById('VWebPlaceHolder').appendChild(forePanel);
}
function VWebGlobal_ShowBackPanel(panel)
{
//	shadowPanel.style.display = 'block';
//	shadowPanel.style.width = panel.offsetWidth + 'px';
//	shadowPanel.style.height = panel.offsetHeight + 'px';

//	if (VWebGlobal_WebBrowserInfo.IsIE6)
//	{
//		shadowPanel.style.top = (VWebGlobal_GetCurrentScrollY() + 10 + shadowDistanceY) + 'px';
//		shadowPanel.style.left = (VWebGlobal_GetCurrentScrollX() + 10 + shadowDistanceX) + 'px';
//	}
//	else
//	{
//		shadowPanel.style.top = '50%';
//		shadowPanel.style.left = '50%';
//		shadowPanel.style.marginTop = -(panel.offsetHeight / 2 - shadowDistanceY) + 'px';
//		shadowPanel.style.marginLeft = -(panel.offsetWidth / 2 - shadowDistanceX) + 'px';
//	}

//	backPanel.style.display = 'block';

//	if (VWebGlobal_WebBrowserInfo.IsIE6)
//	{
//		backPanel.style.width = (document.body.offsetWidth) + 'px';
//		backPanel.style.height = (document.body.offsetHeight) + 'px';
//	}
}
function VWebGlobal_HideBackPanel()
{
	//shadowPanel.style.display = 'none';
	//backPanel.style.display = 'none';
}


function VWebGlobal_ShowMessagePanel(message, enableCloseButton)
{
	contentPanel.innerHTML = message;

	if(!enableCloseButton)
	{
		footerPanel.style.display = 'none';
	}

	forePanel.style.display = 'block';

	if (VWebGlobal_WebBrowserInfo.IsIE6)
	{
		forePanel.style.top = (VWebGlobal_GetCurrentScrollY() + 10) + 'px';
		forePanel.style.left = (VWebGlobal_GetCurrentScrollX() + 10) + 'px';
	}
	else
	{
		forePanel.style.top = '50%';
		forePanel.style.left = '50%';
		forePanel.style.marginTop = -(forePanel.offsetHeight / 2) + 'px';
		forePanel.style.marginLeft = -(forePanel.offsetWidth / 2) + 'px';
	}

	//VWebGlobal_ShowBackPanel(forePanel);
}
function VWebGlobal_HideMessagePanel()
{
	forePanel.style.display = 'none';

	//VWebGlobal_HideBackPanel();
}

function VWebGlobal_ShowPanel(panelID)
{
	var panel = document.getElementById(panelID);

	panel.style.display = 'block';

	if (VWebGlobal_WebBrowserInfo.IsIE6)
	{
		panel.style.position = 'absolute';
		panel.style.top = (VWebGlobal_GetCurrentScrollY() + 10) + 'px';
		panel.style.left = (VWebGlobal_GetCurrentScrollX() + 10) + 'px';
	}
	else
	{
		panel.style.position = 'fixed';
		panel.style.top = '50%';
		panel.style.left = '50%';
		panel.style.marginTop = -(panel.offsetHeight / 2) + 'px';
		panel.style.marginLeft = -(panel.offsetWidth / 2) + 'px';
	}
	panel.style.zIndex = '102';

	//VWebGlobal_ShowBackPanel(panel);
}
function VWebGlobal_HidePanel(panelID)
{
	var panel = document.getElementById(panelID);

	panel.style.display = 'none';

	//VWebGlobal_HideBackPanel();
}









function VWebGlobal_SelectCheckBox(sender, controlID, checkboxIDMatch) {
	var checkboxContainer = document.getElementById(controlID);

	var inputs = checkboxContainer.getElementsByTagName('input')

	for (var i = 0; i < inputs.length; i++) {
		var item = inputs.item(i);

		if (item.id.indexOf(checkboxIDMatch) > -1) {
			item.checked = sender.checked;
		}
	}
}








var imageWidthArray = null;

function VWebGlobal_ImageResize()
{
	var threadContainer = document.getElementById('ThreadContentDiv');

	if (VWebGlobal_WebBrowserInfo.IsIE6)
	{
		if (imageWidthArray == null)
		{
			imageWidthArray = new Array(threadContainer.getElementsByTagName('img').length);

			for (var i = 0; i < threadContainer.getElementsByTagName('img').length; i++)
			{
				var image = threadContainer.getElementsByTagName('img')[i];

				imageWidthArray[i] = image.offsetWidth;

				image.style.width = '100%';
			}
		}

		for (var i = 0; i < threadContainer.getElementsByTagName('img').length; i++)
		{
			var image = threadContainer.getElementsByTagName('img')[i];

			if (imageWidthArray[i] >= threadContainer.offsetWidth)
			{
				image.style.width = '100%';
			}
			else
			{
				image.style.width = imageWidthArray[i] + 'px';
			}
		}
	}
	else
	{
		for (var i = 0; i < threadContainer.getElementsByTagName('img').length; i++)
		{
			var image = threadContainer.getElementsByTagName('img')[i];

			image.style.width = 'auto';

			if (image.offsetWidth >= threadContainer.offsetWidth)
			{
				image.style.width = '100%';
			}
		}
	}
}
function VWebGlobal_CallImageResize()
{
	setInterval('VWebGlobal_ImageResize();', 2000);
}


function VWebGlobal_SliceText(text, maxLength)
{
	if (text.length > maxLength)
	{
		document.write(text.substring(0, maxLength - 3) + '...');
	}
	else
	{
		document.write(text);
	}
}

function VWebGlobal_GetCurrentScrollX()
{
	if (VWebGlobal_WebBrowserInfo.IsSafari)
	{
		return document.body.scrollLeft;
	}
	else
	{
		return document.documentElement.scrollLeft;
	}
}
function VWebGlobal_GetCurrentScrollY()
{
	if (VWebGlobal_WebBrowserInfo.IsSafari)
	{
		return document.body.scrollTop;
	}
	else
	{
		return document.documentElement.scrollTop;
	}
}
function VWebGlobal_SetCurrentScroll()
{
	var hiddenFieldX = document.getElementById('VWebCurrentScrollX');
	var hiddenFieldY = document.getElementById('VWebCurrentScrollY');

	hiddenFieldX.value = VWebGlobal_GetCurrentScrollX();
	hiddenFieldY.value = VWebGlobal_GetCurrentScrollY();
}