//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  20110311 와이솔
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

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 MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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;
}


/*---------------------------------
	문자열의 공백여부 체크
true 	: 미입력 / 미선택  	
false 	: 입력	/	선택			
---------------------------------*/
function jsChkBlank(str)
{
    if (str == "" || str.split(" ").join("") == ""){
    	return true;
	}
    else{
    	return false;
	}
}
/*---------------------------------
	폼 값의 입력/선택 여부
true 	: 미입력 / 미선택  	
false 	: 입력	/	선택			
---------------------------------*/

function jsFormNullChk(formElement){
	
	var em = formElement;
	
	if ( em.type == "text" || em.type == "password" || em.type == "textarea" || em.type == "file" || em.type == "hidden" ) {
		if(jsChkBlank(em.value)){
			return true;
		}
	}else if (em.type == "select-one"){
		if (!em.value) {
			return true;
		}
	}else if(em.type == "checkbox") {
		if (!em.checked) {
			return true;
		}
	}else { // radio
		var emLen = em.length;
		var emChk = false;
		
		if (emLen>0){
			for(var i=0;i<emLen;i++){
				if (em[i].type=="radio"&&em[i].checked){
					alert('true');
		 			emChk= true;
		 			break;
		 		}
			}
		}
		if(!emChk){ 
			return true;
		}
	}
		
	return false;
	
}


/******************************************************************************
//체크박스 전체선택 & 선택해제
******************************************************************************/
var chk_val = false

function ChkAll(){
    if (!chk_val){
        if (document.dFrm.IdxArr != null ){
            if (document.dFrm.IdxArr.length != null ){
                for (i = 0; i < document.dFrm.IdxArr.length; i++ ){
                    document.dFrm.IdxArr[i].checked = true;
                }
            }else {
                document.dFrm.IdxArr.checked = true;
            }
        }
        chk_val = true;
    }else {
        if (document.dFrm.IdxArr != null ){
            if (document.dFrm.IdxArr.length != null ){
                for (i = 0; i < document.dFrm.IdxArr.length; i++ ){
                    document.dFrm.IdxArr[i].checked = false;
                }
            }else {
                document.dFrm.IdxArr.checked = false;
            }
        }
        chk_val = false;
    }
}


/******************************************************************************
// 파일 다운로드 팝업
******************************************************************************/
function fnFileDown(tbl,ufn,fn){
	window.open('../Downloader.asp?tbl='+tbl+'&ufn='+ufn+'&fn='+fn,'dnpop','width=10,height=10');	
}

/******************************************************************************
// 달력 팝업
******************************************************************************/
function popCal(f,d){
	winOpen('/inc/pop_cal.asp?form='+f+'&DIV='+d ,'cal' ,203 ,210 ,'no' ,100 ,100)
		
}

/******************************************************************************
// 팝업 오픈 함수
******************************************************************************/

function winOpen(url, win, width, height, scroll, left, top)
{
	var width	= width		? width		: (screen.width);
	var height	= height	? height	: (screen.height);
	var left	= left		? left		: (screen.width-width)/2;
	var top		= top		? top		: (screen.height-top)/2;
	var scroll	= scroll	? "yes"		: "no";
	var params	= "width="+width+",height="+height+",left="+left+",top="+top+",status=no,toolbar=no,menubar=no,location=no,fullscreen=no,resizable=no,scrollbars="+scroll;
	win = window.open(url,win,params)
	win.focus();
}

function getCookie(strName)
{

	var strArg = new String(strName + "=");
	var nArgLen, nCookieLen, nEnd;
	var i = 0, j;

	nArgLen    = strArg.length;
	nCookieLen = document.cookie.length;

	if(nCookieLen > 0) {

		while(i < nCookieLen) {

			j = i + nArgLen;

			if(document.cookie.substring(i, j) == strArg) {

				nEnd = document.cookie.indexOf (";", j);

				if(nEnd == -1) nEnd = document.cookie.length;

				return unescape(document.cookie.substring(j, nEnd));

			}

			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0) break;
		}
	}

	return null;
}


function setCookie(strName, strValue, dateExpires, strPath, strDomain, isSecure)
{

	var strCookie;
	
	if(strName == "") return ;
	
	strCookie = strName + "=" + escape(strValue) +
		((dateExpires) ? "; expires=" + dateExpires.toGMTString() : "")  +
		((strPath)     ? "; path="    + strPath : "") +
		((strDomain)   ? "; domain="  + strDomain : "") +
		((isSecure)    ? "; secure" : "");
	
	document.cookie = strCookie;

}


/*
+------------------------------------------+--------------------------------------------------------------+
| GetByteLength(val)                       | 해당문자열의 글자수(Byte) 반환                               |
+------------------------------------------+--------------------------------------------------------------+
| TnLoginMsg()                             | 로그인 안내 메시지 출력                                      |
+------------------------------------------+--------------------------------------------------------------+
| jsChklogin(blnlogin)                     | 로그인여부 확인 후 로그인페이지 이동                         |
+------------------------------------------+--------------------------------------------------------------+
| islogin()                                | 로그인여부 확인 (true or false)                              |
+------------------------------------------+--------------------------------------------------------------+
| getCookie(name)                          | name에 해당하는 쿠키값 접수                                  |
+------------------------------------------+--------------------------------------------------------------+
| FlashEmbed(fid,fn,wd,ht,para,tranYn)     | 플레시파일 출력                                              |
+------------------------------------------+--------------------------------------------------------------+
| WMVEmbed(fid,fn,wd,ht,startYn)           | 미디어파일 출력                                              |
+------------------------------------------+--------------------------------------------------------------+
| jsChkNull(type,obj,msg)	               | INPUT태그 BOX의 Value값 체크,CHECKBOX의 체크여부			  |
|										   |	,RADIOBUTTON의 선택여부,SELECT태그 BOX의 선택여부 체크    |
+------------------------------------------+--------------------------------------------------------------+
| jsChkBlank(str)				           | 문자열 공백체크	                                          |
+------------------------------------------+--------------------------------------------------------------+
| Trim(v)	  							   | 문자열 좌우 공백제거                                         |
+------------------------------------------+--------------------------------------------------------------+
| Replace(val, find, change)			   | 문자열내 특정문자 교체                                       |
+------------------------------------------+--------------------------------------------------------------+
| isNumeric( value )					   | 숫자여부 확인 (true or false)                                |
+------------------------------------------+--------------------------------------------------------------+
| onlyNumber(obj,evt) 					   | 숫자만 입력받기                                              |
+------------------------------------------+--------------------------------------------------------------+
| popupResize(innerWidth)				   | 팝업창 자동 리사이즈		              					  |
+------------------------------------------+--------------------------------------------------------------+
| winOpen(url, win, width, height, scroll, left, top)	| 팝업 오픈 함수				    			  |
+------------------------------------------+--------------------------------------------------------------+

*/


function GetByteLength(val){
 	var real_byte = val.length;
 	for (var ii=0; ii<val.length; ii++) {
  		var temp = val.substr(ii,1).charCodeAt(0);
  		if (temp > 127) { real_byte++; }
 	}

   return real_byte;
}


function TnLoginMsg(){
	alert('로그인 후 사용하세요.');
}


//로그인 후 로그인 페이지 팝업처리
function jsChklogin(blnLogin){
	if (blnLogin == "True"){
		return true;
	}
	if(confirm("로그인 하시겠습니까?")){
			var winLogin = window.open('/login/PopLoginPage.asp','popLogin','width=400,height=300');
			winLogin.focus();
	}
	return false;

}

//로그인 여부 확인(쿠키)
function islogin() {
	if(getCookie('uinfo')) {
		return "True";
	} else {
		return "False";
	}
}

// 쿠키를 가져온다
/*
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 FlashEmbed(fid,fn,wd,ht,para,tranYn)
{
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + wd + '" height="' + ht + '" id="' + fid + '" align="middle">');
	document.write('<param name="allowScriptAccess" value="always">');
	document.write('<param name="movie" value="' + fn + para + '">');
	document.write('<param name="menu" value="false">');
	document.write('<param name="quality" value="high">');
	if(tranYn=='Y') {
		document.write('<param name="wmode" value="transparent">');}
	document.write('<embed src="' + fn + para + '" menu="false" quality="high" wmode="transparent" width="' + wd + '" height="' + ht + '" name="' + fid + '" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

// 미디어플레이어 인베드 //
function WMVEmbed(fid,fn,wd,ht,startYn)
{
	document.write('<object ID="' + fid + '" WIDTH="' + wd + '" HEIGHT="' + ht + '"  classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab standby="Loading Microsoft?Windows? Media Player components..." type="application/x-oleobject">');
	document.write('<param name="Filename" value="' + fn + '">');
	if(startYn=='Y') {
		document.write('<param name="AutoStart" value="true">');}
	else {
		document.write('<param name="AutoStart" value="false">');}
	document.write('<param name="ShowControls" value="true">');
	document.write('<param name="ShowPositionControls" value="false">');
	document.write('<param name="ShowTracker" value="true">');
	document.write('<param name="ShowGotoBar" value="false">');
	document.write('<param name="ShowDisplay" value="false">');
	document.write('<param name="ShowStatusBar" value="true">');
	document.write('<embed type="application/x-mplayer2">');
	document.write('</object>');
}

// 이미지 상세보기 팝업
function popShowImg(v){
	  var p = (v);
	  w = window.open("/common/showimage.asp?img=" + v, "imageView", "width=10,height=10,status=no,resizable=yes,scrollbars=yes");
      w.focus();
}

//INPUT태그 BOX의 Value값 체크,CHECKBOX의 체크여부,RADIOBUTTON의 선택여부,SELECT태그 BOX의 선택여부 체크
function jsChkNull(type,obj,msg)
{

     switch (type) {
        // text, password, textarea, hidden
        case "text" :
        case "password" :
        case "textarea" :
        case "hidden" :
                if (jsChkBlank(obj.value)) {
					alert(msg);
					//obj.focus();
                    return false;
                }
                else {
                    return true;
                }
                break;
        // checkbox
        case "checkbox" :
                if (!obj.checked) {
					alert(msg);
                    return false;
                }
                else {
                    return true;
                }
                break;
        // radiobutton
        case "radio" :
                var objlen = obj.length;

                for (i=0; i < objlen; i++) {
                    if (obj[i].checked == true)
                        return true;
				}
                if (i == objlen) {
					alert(msg);
                    return false;
                }else{
					return true;
                }
                break;
        }

        // select list
        if (obj.type.indexOf("select") != -1) {
            if (obj.options[obj.selectedIndex].value == 0 || obj.options[obj.selectedIndex].value == ""){
				alert(msg);
                return false;
            }else{
                return true;
			}
        }

        return true;

}


// Trim
function Trim(v)
{
	return v.replace(/^(\s+)|(\s+)$/g, "");
}
// Replace 함수
function Replace(val, find, change) 
{
	return val.split(find).join(change);
}

// 숫자인지 체크
function isNumeric( value )
{
	//	end home arrow (35~40), backspace 8, tab 9, enter 13, delete 46,  num lock 144
	if ((value >= 48 && value <= 57) || (value >= 96 && value <= 105) || (value >= 35 && value <= 40) || value == 8 || value == 9 || value == 13 || value == 46 || value == 144)
		return true;
	else 
		return false;
}



// 숫자만 입력받기 IE, FF	onkeydown="onlyNumber(this,event);"
function onlyNumber(obj,evt) 
{
	var evCode = (!window.netscape) ? event.keyCode : evt.which;
	if (isNumeric(evCode)==false)
	{
		alert("숫자만 입력이 가능합니다.");
		if (!window.netscape) 
			event.returnValue=false;
		else
			obj.value = obj.value.substr(0,obj.value.length-1);
	}
}

// 팝업창 자동 리사이즈
// 팝업창에서 window.onload = popupResize;
// 온로드 이벤트를 이미 사용하고 있으면 
//	window.onload = function() {
//		popupResize();	// 추가
//	}

// 팝업창 자동리사이즈, Width를 지정하면 지정한대로
function popupResize(innerWidth)
{
	var strAgent = navigator.userAgent.toLowerCase();
	var strVersion = strAgent.substr(strAgent.indexOf("msie")+5,1);
    var IE	= strAgent.indexOf("MSIE") ?	true : false;
    
	if (IE)
	{
		var addHeight = (strVersion >=  7) ? 70 : 55;	// 7 이상은 URL창크기만큼 추가

		var innerBody = document.body;
		var innerHeight = innerBody.scrollHeight + (innerBody.offsetHeight - innerBody.clientHeight);
		if (!innerWidth)
			var innerWidth = innerBody.scrollWidth + (innerBody.offsetWidth - innerBody.clientWidth);

		innerWidth += 10;
		innerHeight += addHeight;
		window.resizeTo(innerWidth,innerHeight);
	}
	else					// FF
	{
		var Dwidth = parseInt(document.body.scrollWidth);
		var Dheight = parseInt(document.body.scrollHeight);
		var divEl = document.createElement("div");
		divEl.style.position = "absolute";
		divEl.style.left = "0px";
		divEl.style.top = "0px";
		divEl.style.width = "100%";
		divEl.style.height = "100%";
	    document.body.appendChild(divEl);
	    window.resizeBy(Dwidth-divEl.offsetWidth, Dheight-divEl.offsetHeight);
		document.body.removeChild(divEl);
	}
}




