// 드림위버에서 롤오버기능으로 생성하는 자바스크립트
function MM_preloadImages() { //v3.0
	var d = document;
	if (d.images)
	{
		if (!d.MM_p)
			d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for(i = 0; i < a.length; i++)
			if (a[i].indexOf("#") != 0)
			{
				d.MM_p[j]=new Image;
				d.MM_p[j++].src=a[i];
			}
	}
}

// 드림위버에서 롤오버기능으로 생성하는 자바스크립트
function MM_swapImgRestore() { //v3.0
	var i, x, a=document.MM_sr;
	for (i = 0; a && i < a.length && (x=a[i]) && x.oSrc; i++)
		x.src = x.oSrc;
}

// 드림위버에서 롤오버기능으로 생성하는 자바스크립트
function MM_findObj(n, d) { //v4.01
	var p, i, x;
	if (!d)
		d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if (!(x = d[n]) && d.all)
  		x = d.all[n];
	for (i = 0; !x && i < d.forms.length; i++)
		x = d.forms[i][n];
	for (i = 0; !x && d.layers && i < d.layers.length; i++)
		x = MM_findObj (n, d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}

// 드림위버에서 롤오버기능으로 생성하는 자바스크립트
function MM_swapImage() { //v3.0
	var i, j=0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length - 2); i += 3)
		if ((x = MM_findObj(a[i])) != null){
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				x.oSrc = x.src;
			x.src = a[i + 2];
		}
}

// 팝업 윈도우를 띄운다.
function openPopup( url, name, width, height, scroll )
{
	window.open( url, name, 'toolbar=no ,location=no ,directories=no ,status=yes ,menubar=no ,scrollbars=' + scroll + ' ,resizable=no ,width=' + width + ' ,height=' + height + ' left=' + (screen.width/2 - width/2) + ' top=' + (screen.height/2 - height/2));
}

// comment 태그로 처리된 오브젝트를 화면에 출력한다.
function objectWrite(element)
{
	document.write(document.getElementById(element).text);
	document.getElementById(element).id = "";
}

// 공통폼을 만들어 폼을 커밋을 내는 함수
function commSubmit(Action, name, value, Target)
{
	var names = name.split(",");
	var values = value.split(",");
	var html = "";
	var form = document.getElementById("commForm");
	for (i = 0; i < names.length; i++)
	{
		html = html + "<input type='hidden' name='" + names[i] + "' value='" + values[i] + "'>";
	}
	form.innerHTML = html;
	form.action = Action;
	if (typeof(Target) == "string")
	{
		form.target = Target;
	}
	form.submit();
	form.target = "actionFrame";
}

// 모달로 창을 띄우는 함수
function modalOpen(sURL, sMsg, sHeight, sWidth, sTop, sLeft, sResize)
{
	var sFeatures = new Array();

	sFeatures[0] = (sWidth > 0) ? "dialogWidth:"+sWidth+"px" : "dialgWidth:300px";
	sFeatures[1] = (sHeight > 0) ? "dialogHeight:"+sHeight+"px" : "dialogHeight:300px";
	sFeatures[2] = (sTop > 0) ? "dialogTop:"+sTop+"px" : "dialogTop:" + (screen.height/2 - sFeatures[1]/2) + "px";
	sFeatures[3] = (sLeft > 0) ? "dialogLeft:"+sLeft+"px" : "dialogLeft:" + (screen.width/2 - sFeatures[0]/2)  + "px";
	sFeatures[4] = (!sTop && !sLeft) ? "center:Yes" : "";
	sFeatures[5] = (sResize) ? "resizeable:" + sResize : "resizeable:No";
	sFeatures[6] = "help:No";
	sFeatures[7] = "status:No";
	sFeatures[8] = "scroll:No";

	sFeatures = sFeatures.join(";");

	return window.showModalDialog(sURL, sMsg, sFeatures);
}

// 함수가 있으면 실행하는 함수
// 첫변째 실행할 함수 문자열
// 두번째 실행할 함수가 있는 문서타겟 문자열
function callFunction(fun, target)
{
	if (typeof(fun) != "undefined" && fun.length > 0)
	{
		if (typeof(target) == "undefined")
		{
			if (typeof(eval(fun.substring(0, fun.indexOf("(")))) != "undefined")
			{
				return eval(fun);
			}
		}
		else
		{
			if (typeof(eval(target + "." + fun.substring(0, fun.indexOf("(")))) != "undefined")
			{
				return eval(target + "." + fun);
			}
		}
	}
}

// 상위 셀렉트에 대한 하위 셀렉트 값을 설정한다.
function setSelect(select, jdbcid, param)
{
	window.open("/common/jsp/setSelect.jsp?select=" + select + "&jdbcid=" + jdbcid + "&" + param, "actionFrame");
}

function center()
{
	var x, y;
	if (self.innerHeight)
	{ // IE 외 모든 브라우저
		x = (screen.availWidth - self.innerWidth) / 2;
		y = (screen.availHeight - self.innerHeight) / 2;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict 모드
		x = (screen.availWidth - document.documentElement.clientWidth) / 2;
		y = (screen.availHeight - document.documentElement.clientHeight) / 2;
	}
	else if (document.body)
	{ // 다른 IE 브라우저( IE < 6)
		x = (screen.availWidth - document.body.clientWidth) / 2;
		y = (screen.availHeight - document.body.clientHeight) / 2;
	}
	window.moveTo(x,y);
}

/******************************************************************************
	내 용 : 현재 접속해있는 서버의 URL 중 Port앞부분까지의 주소 찾기
			 예) http://10.104.77.11
	파라미터 : 없음
******************************************************************************/
function getServerUrl()
{
	 if(vTempURL == "")
	 {
		 vTempURL = document.URL.substring(0, document.URL.lastIndexOf(":"));
	 }
	 return vTempURL;
}

/******************************************************************************
	내 용 : 현재 실행중인 브라우져의 버젼을 리턴
	파라미터 : 없음
******************************************************************************/
function getIEVersion()
{
	if(vIEVersion == "")
	{
		iidx = navigator.appVersion.indexOf('MSIE ');
		if(iidx > 0)
		{
			vIEVersion = parseInt(navigator.appVersion.substring(iidx+5, iidx+8));
		}
		else vIEVersion = 0;
	}
	return vIEVersion;
}

/**************************************************************************************
 *	내 용 : SelectBox 내의 항목들을 클리어 한다.
 *	파라미터 : fSelect - Select이름
 **************************************************************************************/
function clearSelectBox(fSelect)
{
	if 	(typeof(fSelect) != 'undefined' && typeof(fSelect.options) != 'undefined' && fSelect.options.length != 0)
	{
		fSelect.options.length = 1;
	}
}

// 해당 숫자만큼을 랜덤으로 순서를 정해 배열에 담아 가지고온다.
function eachRandomInt(limitNum)
{
	var ranN = new Array(limitNum)

	for (var i=0, y=0; i<limitNum; i++)
	{
		ranN[i] = (Math.floor(Math.random()*10000)%limitNum);
		for (y=0; y<i; y++)
		{
			while (ranN[y] == ranN[i])
			{
				ranN[i] = (Math.floor(Math.random()*10000)%limitNum);
				y=0;
			}
		}
	}
	return ranN
}

// 숫자에 3자리마다 콤마를 찍는 함수
function addCommas(strValue)
{
	sValue = "" + strValue;
	var objRegExp = new RegExp("(-?[0-9]+)([0-9]{3})");
	while(objRegExp.test(sValue))
	{
		sValue = sValue.replace(objRegExp, "$1,$2");
	}
	return sValue;
}

// 아이프레임의 높이를 문서의 길이에 맞추어서 자동으로 조절해준다.
function iframeAutoResize(id) {
	var iframeObj = parent.document.getElementById(id);
    iframeObj.height = document.body.scrollHeight;
}

// 클릭시 사선으로 박스가 쳐지는 것을 방지하는 기능
function autoBlur()
{
	if(event.srcElement.tagName == "A")
		document.body.focus();
}

// 하위 셀렉트박스를 상위 셀렉트박스에 맞게 세팅하는 함수
function setSubSelect(up, down, data)
{
	id = document.getElementById(up).value;
	k = 1;
	document.getElementById(down).options.length = k;
	for (i=0; i<data.length; i++)
	{
		if (data[i][0] == id)
		{
			k++;
			document.getElementById(down).options.length = k;
			document.getElementById(down).options[k-1].value = data[i][1];
			document.getElementById(down).options[k-1].text = data[i][2];
		}
	}
	document.getElementById(down).options.selectedIndex = 0;
}

// 날자간격을 자동으로 세팅해주는 함수
function dateSet(fromdate, todate, term)
{
	$("#" + todate)[0].value = today;
	if (term == "1d") fDate = vfCalculateDate(today, "Day", -1);
	else if (term == "3d") fDate = vfCalculateDate(today, "Day", -3);
	else if (term == "7d") fDate = vfCalculateDate(today, "Day", -7);
	else if (term == "1m") fDate = vfCalculateDate(today, "Month", -1);
//	$(fromdate).value = vfCompleteDateFormat(fDate, "-");
	$("#" + fromdate)[0].value = fDate;
}

// 플래쉬를 만드는 스크립트
function CreateFlash(strSrcUrl, strId, nWidth, nHeight, strMode, bSameDomain, bgColor, strAlign)
{
	var strObject = "<object id=" + strId + " classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"";
	if(strAlign != "")
		strObject = strObject + " align=" + strAlign;
	strObject = strObject + " width=" + nWidth + " height=" + nHeight + ">";

	document.write(strObject);
	document.write("<param name=movie value=" + strSrcUrl + " />");
	document.write("<param name=quality value=\"high\" />");
	if(strMode != "")
		document.write("<param name=wmode value=" + strMode + " />");
	if(bgColor != "")
		document.write("<param name=bgcolor value=" + bgColor + " />");
	if(bSameDomain == true)
		document.write("<param name=allowScriptAccess value=\"sameDomain\" />");

	var strEmbed = "<embed src="+strSrcUrl+" quality=high type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\"" ;
	if(strMode  != "")
		strEmbed = strEmbed + " wmode=" + strMode;
	if(bgColor  != "")
		strEmbed = strEmbed + " bgcolor=" + bgColor;
	if(strAlign != "")
		strEmbed = strEmbed + " align=" + strAlign;
	if(bSameDomain == true)
		strEmbed = strEmbed + " allowScriptAccess=\"sameDomain\"";
	strEmbed = strEmbed + " width=" + nWidth + " height=" + nHeight + "></embed>";

	document.write(strEmbed);
	document.write("</object>");
}

//setCookie('name', 'value', cookie_time(hour));
// 쿠키값 저장하기
function setCookie(name, value)
{
	var expires = new Date();
	var path, domain, secure;

	//호출하는 인수의 배열 setCookie.arguments[0] ~ [setCookie.arguments.length-1]
	var argv = setCookie.arguments;

	//호출한함수의 인수 -  setCookie.arguments.length = arguments.length와 값이 같음!!,
	//대조 : setCookie.length 호출당하는 인수 갯수
	var argc = setCookie.arguments.length;

	if( argc > 2)
	{
		// argv[2]시간동안 쿠키 유효
		expires.setTime( expires.getTime() + (1000*60*60*argv[2]));
	}
	else
	{
		expires = null;
	}

	path = (argc > 3) ? argv[3] : null;
	domain = (argc > 4) ? argv[4] : null;
	secure = (argc > 5) ? argv[5] : false;

	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : (";expires=" + expires.toGMTString())) +
		((path == null) ? ";path=/" : (";path=" + path)) +
		((domain == null) ? "" : (";domain=" + domain)) +
		((secure == true) ? " ;secure" : "" );
}

//쿠키값 가져오기
function getCookie(name)
{
	var nameStr = name + "=";
	var nameLen = nameStr.length;
	var cookieLen = document.cookie.length; //쿠기값이 없을시 기본적으로 45이다. document.cookie.length >= 45

	// a로 지정시 : document.cookie ==> lucya=a; ASPSESSIONIDQGQQGLDC=GKDDHCPDJBOBAONCMJLHBCCN
	var i = 0;
	while (i < cookieLen)
	{
		var j = i + nameLen;
		if ( document.cookie.substring(i, j) == nameStr )
		{
			var end = document.cookie.indexOf(";", j); // ;의 위치
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(j, end)); //쿠키값 반환
		}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)
		{
			break;
		}
	}
	return "";
}

function menuPrint(bigTitle, smallTitle)
{
	top.middleMenu.innerHTML = bigTitle;
	top.bottomMenu.innerHTML = smallTitle;
	top.excel_frame = "";
	top.excel_file = "";
}
