﻿// JScript File
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}


function AppendMultiColCell( oTable, iRowNum, sHtml) {
    var iCurrNum = oTable.iCurrNum =  oTable[ "iCurrNum"] != null ? oTable.iCurrNum +1 : 0;
    while( oTable.rows.length < iRowNum) oTable.insertRow();
    otd = oTable.rows[ iCurrNum % iRowNum].insertCell();
    otd.innerHTML = sHtml;
    otd.id = iCurrNum;
}


function Swf(src,width,height, flashVars, wMode, bgColor, id, salign, scale, allowScriptAccess, flashServerVars, style, sMode){
	wMode = wMode == null ? wMode : 'transparent';
	bgColor = bgColor != null ? bgColor : '#ffffff';
	sMode = sMode != null ? sMode : "DirectWrite";
	
	var sTag = '';
	sTag += '<object type="application/x-shockwave-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0"  id="' +id + '" width="'+width+'" height="'+height+'" style="'+style+'" flashServerVars="'+flashServerVars+'"   ControlType="Flash" >';
	sTag += '<param name="src" value="'+src+'">';
	sTag += '<param name="movie" value="'+src+'">';
	sTag += '<param name="quality" value="high">';
	sTag += '<param name="bgcolor" value="' + bgColor + '">';
	sTag += '<param name="menu" value="false">';
	sTag += '<param name="scale" value="' +scale +'">';
	sTag += '<param name="salign" value="' +salign +'">';
	sTag += '<param name="flashvars" value="' +flashVars + '&sObjectID=' + id+ '&">';
	sTag += '<param name="wmode" value="' + wMode + '">';
	sTag += '<param name="play" value="1">';
	sTag += '<param name="allowScriptAccess" value="' + allowScriptAccess + '">';
	sTag += '<\/object>';
	//alert( html);
	switch( sMode) {
	    case "DirectWrite": document.write(sTag); break;
	    case "GetTag": return sTag;
	}
	eval( "window." +id +"= document.getElementById( '" + id + "');");
}

function GotoMenu( sMenuFilePath, sMenuName) {
    var xmlDoc = GetXMLDoc( sMenuFilePath);
    var oNode  = FindSingleNode( xmlDoc.documentElement, "Menu[@sMenuName='" + sMenuName + "']");
   if( oNode != null) GotoUrl(  oNode.getAttribute( "sUrl") );
}

function GotoUrl( sUrl) {
    location.href= sUrl;
}

function FindSingleNode( oNode, sXPathExpress) {
    var oMatchedNode = oNode.selectSingleNode( sXPathExpress);
    if(oMatchedNode != null) return oMatchedNode;
    else if(oNode.hasChildNodes()) {
            var nodes=oNode.childNodes.length;
            for(var i=0; i<oNode.childNodes.length; i++) {
                   oMatchedNode = FindSingleNode(oNode.childNodes(i), sXPathExpress);
                   if( oMatchedNode != null) return oMatchedNode; 
            } 
    }
}

function GetXMLNodeAttribute( sFilePath, sAttributeName, sXPathExpress) {
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    var currNode;
    xmlDoc.async = false;
    xmlDoc.load( sFilePath);

    xmlDoc.setProperty("SelectionLanguage", "XPath");
    currNode = xmlDoc.documentElement.selectSingleNode( sXPathExpress);
    
    return currNode != null ? currNode.getAttribute( sAttributeName) : null;
}

function GetXMLDoc( sFilePath) {
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    var currNode;
    xmlDoc.async = false;
    xmlDoc.load( sFilePath);
    return xmlDoc
}

function GetXMLNode( oNode, sXPathExpress) {
    xmlDoc.setProperty("SelectionLanguage", "XPath");
    return oNode.selectSingleNode( sXPathExpress);
}

//alert( GetXMLNodeAttribute( "books.xml", "id", "book[@id='bk102']"));
//var xmlDoc = GetXMLDoc( "books.xml");
//var xmlNode = GetXMLNode( xmlDoc.documentElement, "book[@id='bk102']");
//xmlNode = GetXMLNode( xmlNode, "author");
//alert( xmlNode.text);


function RedirectByForm( sPath, sMethod){
    sMethod = sMethod != null ? sMethod : "post"
    document.body.appendChild( document.createElement( "<form name='GotoByForm' method=" +sMethod +" action='" + sPath + "' ></form>"));
    if( arguments.length >2) {
        for( var i= 2; i < arguments.length; i+= 2) {
            document.forms["GotoByForm"].appendChild( document.createElement( "<input type='hidden' name='" + arguments[i]+ "' value='" + arguments[i +1] + "' >"));
        } 
    }
    document.forms["GotoByForm"].submit();
}




function ReloadByForm( oDocument) {
    oDocument = oDocument != null ? oDocument : document;
    oDocument.body.appendChild( oDocument.createElement( "<form name='Reload' method='post' ></form>"));
    oDocument.forms["Reload"].submit();
}


function GotoBoardArticle( sUrl, lFArticle, lArticle) {
    var fmGotoArticle = document.createElement( "<form name='fmGotoArticle' method=post action=''/>");
    fmGotoArticle.appendChild( document.createElement( "<input type=hidden name='lFArticle' />"));
    fmGotoArticle.appendChild( document.createElement( "<input type=hidden name='sMode' value='Read' />"));
    fmGotoArticle.appendChild( document.createElement( "<input type=hidden name='lArticle' />"));
    document.body.appendChild( fmGotoArticle);
    fmGotoArticle.action = sUrl;
    fmGotoArticle.children.lFArticle.value = lFArticle;
    fmGotoArticle.children.lArticle.value = lArticle;
    fmGotoArticle.submit();
}  

function DoNotAnything() { }


function getCookie( name ){
        var nameOfCookie = name + "=";
        var x = 0;
        while ( x <= document.cookie.length ){
                var y = (x+nameOfCookie.length);
                if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                        if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                                endOfCookie = document.cookie.length;
                return unescape( document.cookie.substring( y, endOfCookie ) );
                }
                x = document.cookie.indexOf( " ", x ) + 1;
                if ( x == 0 )
                break;
        }
        return "";
}


function setCookie( name, value, expiredays ) 
{ 
    var todayDate = new Date(); 
    todayDate.setDate( todayDate.getDate() + expiredays ); 
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
} 

// 체크후 닫기버튼을 눌렀을때 쿠키를 만들고 창을 닫습니다


function IsNotNull( oSrc, sFalseMessage) {
	if( GetValue( oSrc) != null) {
          return  true ;
    }
    else { 
		if( sFalseMessage != null) alert(sFalseMessage);
		if( oSrc["length"] != null) oSrc[0].focus();
		else oSrc.focus();
        false;
    }
}

function IsNotNum( oSrc, sFalseMessage) {
    var sValue = GetValue( oSrc);
	
	
    
    if( sValue != null &&  sValue.match( /[^0-9]+/ig) == null) {
        return  false;
    }
    else { 
		if( sFalseMessage != null) alert(sFalseMessage);
        oSrc.focus();
        return true;
    }
}


function GetValue( oSrc, sProperty) {
    var oTemp = oSrc;
    var sValue = "";
    var sProperty = sProperty == null ? "value" : sProperty;
    
    if( oTemp == null) alert( "입록된 컨트롤이 없습니다");
    else {
        switch( oTemp.type) {
            case "text" :
            case "password" :
            case "file" :
            case "textarea" :
                sValue = oTemp[sProperty].toString();
                break;
           	
            case "select" :
            case "select-one" :
            case "select-multiple" :
                if( oTemp["length"] != null) {
                    for( var j =0; j < oTemp.length; j++) {	
                        sValue += oTemp.options[j].selected ? oTemp[j][sProperty].toString() + "," : "";
                    }
                    sValue= sValue.substr( 0, sValue.length -1);
                }
                break;
            default:
                if( oTemp["length"] != null) {
                    switch( oTemp[0].type) {
                        case "checkbox" :
                        case "radio" :	
                            if( oTemp["length"] != null) {
                                for( var j =0; j < oTemp.length; j++) {	
                                    sValue += oTemp[j].checked ? oTemp[j][sProperty].toString()  +"," : "";
                                }
                                sValue= sValue.substr( 0,sValue.length -1);
                            }
                    }
                }
                else {
                   sValue= oTemp.checked ? oTemp[sProperty].toString() : "";
                    
                }
                break;
        }
        return sValue.length > 0 ? sValue : null;
    }
}

function ClearSelect( oSelect) {
	oSelect.value = '';
	for( i=0 ; i <oSelect.options.length; i++) {
		oSelect.options[i].selected = false;
	}
}
function ClearRadio( sRadioName) {
	var oaRadio = document.getElementsByName( sRadioName);
	for( i=0 ; i <oaRadio.length; i++) {
		oaRadio[i].checked= false;
	}
}

function SetSelectValue( hSelect, sValue, sPropertyName) {

	var iLength = hSelect.options.length;
	if( sPropertyName == null) sPropertyName = 'value';
	for( i=0; i < iLength; i++) {
		if(eval("hSelect.options[i]['" + sPropertyName + "']") == sValue) {
			hSelect.options[i].selected = true;
			//alert(hSelect.options[i][sPropertyName]);
			break;
		}
	}
}
					
function GetSelectProperty( oSelect, sPropertyName) {
	var lKey = oSelect.value;
	for( var i= 0; i < oSelect.options.length; i++) {
		if( oSelect.options[i].value== lKey) {return oSelect.options[i][sPropertyName];}
	}
	return '';
}


function CheckSelected( sObjectName) {
	var oSelect = document.getElementsByName( sObjectName);
	if( oSelect != null && oSelect.length > 0 ) {
		for( var i =0; i < oSelect.length; i++) {
			if( oSelect[i].checked) return true;
		}
		return false;
	}
}
function CheckAllOrNot( oButton, sObjectID) {
	var oaObject = document.getElementsByName( sObjectID);
	if( oButton.checked) {
		for( var i=0; i < oaObject.length; i++) {
			oaObject[i].checked = true ;
		}
	}
	else {
		for( var i=0; i < oaObject.length; i++) {
			oaObject[i].checked = false ;
		}
	}
}

function ToggleVisible( sObjectName) {
	var oaObject = document.getElementsByName( sObjectName);
	if( oaObject["length"] != null) {
		sVisible = oaObject[0].style.display == 'inline' ? 'none' : 'inline';
		for( var i=0; i < oaObject.length; i++) {
			oaObject[i].style.display = sVisible;
		}
	}
	else {
		sVisible = oaObject.style.display == 'inline' ? 'none' : 'inline';
		oaObject[i].style.display = sVisible;
	}
}

function SetVisible( sObjectName, bVisible) {
	var oaObject = document.getElementsByName( sObjectName);
	if( oaObject["length"] != null) {
		sVisible = bVisible ? 'inline' : 'none';
		for( var i=0; i < oaObject.length; i++) {
			oaObject[i].style.display = sVisible;
		}
	}
	else {
		sVisible = bVisible ? 'inline' : 'none';
		oaObject[i].style.display = sVisible;
	}
}


//function CheckExistsInControl( sControlID, sContainerControlID) {

//	oControl = document.getElementById( sControlID);
//	oPControl = oControl;
//	while(oPControl.tagName!="BODY"){
//	    if( oPControl.id == sContainerControlID) return true;
//		oPControl = oPControl.offsetParent;
//	} 
//	return false;
//}

	


function OpenDiv(sID) {
	var divDialog= document.getElementById( sID);
	divDialog.style.position='absolute';
	divDialog.style.display = 'inline';
	divDialog.style.left = (document.body.clientWidth -divDialog.style.pixelWidth)/ 2 ;
	divDialog.style.top = (document.body.scrollTop + (document.body.clientHeight -divDialog.clientHeight ) /2);
}

function OpenDivBelowControl(sDivID, sControlID) {
	oDiv = document.getElementById( sDivID);
	oControl = document.getElementById( sControlID);
	var iLeftPos =0, iTopPos = 0;
	oPControl = oControl;
	while(oPControl.tagName!="BODY"){
		iLeftPos += oPControl.offsetLeft;
		iTopPos += oPControl.offsetTop;
		oPControl = oPControl.offsetParent;
	} ;
	
	oDiv.style.position='absolute';
	oDiv.style.display='inline';
	oDiv.style.left =iLeftPos;
	oDiv.style.top = iTopPos + oControl.offsetHeight +	2;

}

var _win, _sUrl;
function OpenDialog(sUrl, sName, sFeatures) {
    sFeatures = sFeatures != null ? sFeatures : 'menubar=yes,toolbar=yes,scrollbars=yes,status=yes,location=yes,resizable=yes';
	if( _win != null && !_win.closed && sUrl == _sUrl) _win.focus();
	else {
		_win = window.open( sUrl, sName, sFeatures);
		_sUrl = sUrl
		_win.focus();
	}
}

function CloseDiv(sID) {
	var divDialog= document.getElementById( sID);
	if( divDialog != null) divDialog.style.display = 'none';
}

function ConfirmDelete() {
	return confirm('삭제하시겠습니까?') 
  }

function ResizeWindow() {
    var oFrameOutline = document.getElementById( 'FrameOutline');
    var iOffsetWidth, iOffsetHeight, iWidth, iHeight;
    if(oFrameOutline == null) oFrameOutline = document.body;
    
    iWidth = oFrameOutline.scrollWidth < (screen.availWidth -60) ? oFrameOutline.scrollWidth :(screen.availWidth -60);
    iHeight = oFrameOutline.scrollHeight < (screen.availHeight -60) ? oFrameOutline.scrollHeight : (screen.availHeight -60);

    iOffsetWidth = iWidth - document.body.clientWidth;
    iOffsetHeight = iHeight - document.body.clientHeight;
	
	document.body.scroll = "auto";
	window.resizeBy( iOffsetWidth, iOffsetHeight);
	
}
function CenterWindow() {
    var iLeft = (screen.availWidth - document.body.offsetWidth) / 2; 
	var iTop = (screen.availHeight - document.body.offsetHeight) / 2 -30; 
    window.moveTo( iLeft, iTop);
}


function DatePicker(iYear, iMonth, iDay, sButtonID,sReturnID) {
	var divDatePicker = document.getElementById('divDatePicker');
	if(divDatePicker == null) {							
		var sDivDatePicker = 
		
	'	<div id="divDatePicker" style="display:none; border:1px solid #bbbbbb;padding:5px; background-color:white;" >'
+'			<script>'
+'				var divDatePicker = document.getElementById( \"divDatePicker\");'
+'				divDatePicker.iYear= null;'
+'				divDatePicker.iMonth= null;'
+'				divDatePicker.iDay= null;'
+'			<\/script>'
+'			<table cellspacing=0 >'
+'			<tr><td bgcolor=white align="center" class="HandCursor"  onclick="DatePicker( giYear -1, giMonth,giDay, null, null, \'inner\')" style="padding:3px;width:10px;"><<<\/td>'
+'			<td bgcolor=white align="center" class="HandCursor" style="padding:3px;" onclick="DatePicker( giYear, giMonth -1,giDay, null, null, \'inner\')"><<\/td>'
+'			<td bgcolor=white align="center" class="HandCursor" style="padding:3px;"><nobr style="font-size:14px;font-weight:bold;" id="sCurrDate"><\/nobr><\/td>'
+'			<td bgcolor=white align="center" class="HandCursor" style="padding:3px;" onclick="DatePicker( giYear, giMonth +1,giDay, null, null, \'inner\')">><\/td>'
+'			<td bgcolor=white align="center" class="HandCursor" style="padding:3px;" onclick="DatePicker( giYear +1, giMonth,giDay, null, null, \'inner\')">>><\/td>'
+'			<\/tr>'
+'			<tr><td colspan="6"><div id="divCalendar" ><\/div><\/td><\/tr>'
+'			<tr><td colspan=6  style="padding:3px;" align="right" ><a href ="#" onclick="javascript:document.all.divDatePicker.style.display=\'none\'; ">닫기<\/a><\/td>'
+'			<\/tr>'
+'			<\/table>'
+'		<\/div>';
																
			document.body.insertAdjacentHTML('beforeEnd', sDivDatePicker);
		divDatePicker = document.getElementById('divDatePicker');
	}
	
	if( sReturnID != null) divDatePicker.oReturn = document.getElementById(sReturnID);

	var dtToday = new Date();
	var iCurrYear = iYear == null ? dtToday.getFullYear() : iYear ;
	var iCurrMonth =iMonth == null ? dtToday.getMonth(): iMonth -1;; /*월은 0부터 11까지 지정한다*/
		if( iCurrMonth == -1) { iCurrYear -= 1; iCurrMonth = 11};
		else if( iCurrMonth == 12) { iCurrYear += 1; iCurrMonth = 0};
	var iCurrDay = iDay == null ? dtToday.getDate(): iDay ;
	var dtDate = new Date( iCurrYear, iCurrMonth ,iCurrDay );
	var dtDaysInMonth = new Date( new Date( iCurrMonth == 11 ? iCurrYear +1 : iCurrYear, iCurrMonth == 11 ? 0 : iCurrMonth +1, 1) -(24*60*60*1000));
	var	iDaysInMonth = dtDaysInMonth.getDate();/*그 달의 날수를 구하기 위해 다음달의 첫날을 구해서 하루를 뺀다*/
	var	iDayPosition = (new Date( iCurrYear, iCurrMonth, 1)).getDay();
//alert (iCurrMonth);
	
	var sHtml = "<table border=0 cellpadding=5 cellspacing=0 class=Table><thead><tr><td colspan=7></td></tr><tr><td>일</td><td>월</td><td>화</td><td>수</td><td>목</td><td>금</td><td>토</td></tr></thead><tr>";

	for( var i = 1; i<= 42; i++) {
		if( iDayPosition +1 <= i   && i <= iDaysInMonth +iDayPosition +1 -1)
			sHtml += "<td bgcolor=white align=right valign=middle style='cursor:hand' onclick='divDatePicker.oReturn.value=\"" + iCurrYear + "-" +( iCurrMonth +1) + "-" +(i -(iDayPosition +1) +1) + "\";document.all.divDatePicker.style.display=\"none\";'>" + (i -(iDayPosition +1) +1) +"</td>";
		else 
			sHtml += "<td bgcolor=white></td>";
		if( i %  7 == 0) sHtml += "</tr><tr>";
	}
	sHtml += "</tr></table>";

	document.all.divCalendar.innerHTML = sHtml;
	giYear = iCurrYear;
	giMonth = iCurrMonth +1;
	giDay = iCurrDay;
	
	var sCurrDate = document.getElementById( "sCurrDate");
	sCurrDate.innerHTML = giYear + "년 " + giMonth + "월";
	if(document.all.divDatePicker.style.display == "none")
		OpenDivBelowControl( 'divDatePicker', sButtonID);
	
}


//
// 날개메뉴 1.0
//

//var m = window.open( '', 'aaa');
var timeoutNextCheck, bNotFirst, oWingMenu1, oWingMenu2;
function MoveWingMenu( sWingMenu1ID, sWingMenu2ID) {
    
	if( !bNotFirst ) {
		oWingMenu1 = document.getElementById( sWingMenu1ID);
		oWingMenu1.iOriginalTop = oWingMenu1.style.pixelTop;
		if( sWingMenu2ID != null) {
			oWingMenu2 = document.getElementById( sWingMenu2ID);
			oWingMenu2.iOriginalTop = oWingMenu2.style.pixelTop;
		}
		bNotFirst = true;
	}
	
	var chk_i;
	var iMenu1Y, iMenu1YTarget, iOffsetY, timeoutNextCheck;
	var wndWidth = parseInt(document.body.clientWidth);
	
	iMenu1Y = oWingMenu1.style.pixelTop;
	iMenu1YTarget = document.body.scrollTop + oWingMenu1.iOriginalTop; // 위쪽 위치
	timeoutNextCheck = 500;

	
	if ( iMenu1Y != iMenu1YTarget ) {
		iOffsetY = Math.ceil( Math.abs( parseInt(iMenu1YTarget) - parseInt(iMenu1Y) ) / 10 );
		if ( iMenu1YTarget < iMenu1Y ){
			iOffsetY = -iOffsetY;
			
		}
		
		oWingMenu1.style.pixelTop += iOffsetY;
		if( oWingMenu2 != null) oWingMenu2.style.pixelTop += iOffsetY;

		timeoutNextCheck = 10;
		//m.document.write(oWingMenu1.style.pixelTop+ "<br>");
	}
	
		setTimeout ("MoveWingMenu()", timeoutNextCheck);
}

//div는position:relative 또는 absolute를 꼭써줘야함
//MoveWingMenu('rQuick', 'rQuick2');