// Flash Embed 스크립트 -- 사용예 : <script>swf("/images/flash/a.swf", 100, 50) 
function swf(src, w, h) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	html = '';
	html += '<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=8,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="swliveconnect" value="true">';
	html += '<embed src="'+src+'" quality=high bgcolor="#f7f4ed" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}


// Flash Embed 스크립트 -- 사용예 : <script>embed_flash("/images/flash/a.swf", 100, 50) 
function swf_tran(src, w, h) {
	var src_arr = src.split("/");
	var src_file = src_arr[src_arr.length -1]
	var src_id = src_file.substr(0,src_file.length-4);
	//alert(src_id);

	html = '';
	html += '<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=7,0,0,0" id="'+src_id+'" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#ffffff">';
	html += '<param name="wmode" value="transparent">';
	html += '<param name="swliveconnect" value="true">';
	html += '<embed src="'+src+'" quality=high bgcolor="#ffffff" width="'+w+'" height="'+h+'" swliveconnect="true" id="'+src_id+'" name="'+src_id+'" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed>';
	html += '<\/object>';
	document.write(html);
}


// 단어수 체크
function wordCounter(field, maxlimit) {


	var wordcounter=1;
	var in_data = field.value;
	var val_len = in_data.length;


	for (x=0; x< val_len; x++)
    {

		if ((in_data.charAt(x) == " " || in_data.charAt(x) == "\n") && (in_data.charAt(x-1) != " " || in_data.charAt(x) == "\n")) wordcounter++;
		if (wordcounter > maxlimit) {
			break;
		}
	}

	if(wordcounter > maxlimit) {
		alert ("free text – maximum "+maxlimit+" words");
		field.value = in_data.substring(0, x);
		return;
	}
}



// 종료된 이벤트 (이벤트  수정하려할 경우)
function closed_event() {
	alert ("This event is closed.");
}



/*
function notLogin(url){
	alert ("온라인으로 신청하시려면 먼저 로그인 하셔야 합니다.");
	window.location="/member/index.php?GoUrl="+url
}
*/

// 부메뉴 레이어 숨김/보이기 함수
function Show_Hide(no) { 
	var i,p,v,obj,obj2

	for (i=1; i<6; i++) {
		if(obj=document.getElementById("Layer"+i)) {
		//obj=document.getElementById("Layer"+i);
		obj2=obj.style;
		v=(i==no)?'visible':'hidden';
		obj2.visibility=v; 
		}
	}
}	



// 공백 check(space 처리)
// null => true
function chk_null(toCheck) 
{
    for (var i = 0; i < toCheck.length; i++)
        if (toCheck.substring(i, i+1) != " ") return false;
        
    return true;
}

// 공백 check (값이 없을경우 true)
// null => true
function chk_null2(toCheck)
{
    var chkstr = toCheck + "";
        
    if ((chkstr == "") || (chkstr == null)) 
    {
        return true;
    }

    return false;
}

// 숫자 check
function chk_num1(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++)
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) return false;
   }
   return true;
}


// 숫자, ".", "-" 만 존재하면 true
function chk_num2(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if ( (toCheck.substring(j,j+1) == ".") || (toCheck.substring(j,j+1) == "-") ) continue;
         return false;
      }
   }
   
   return true;
}

// 숫자, "-" 만 존재하면 true

function chk_num3(toCheck) 
{
   for (j = 0; j < toCheck.length ; j++) 
   {
      if ( (toCheck.substring(j,j+1) < "0") || (toCheck.substring(j,j+1) > "9") ) 
      {
         if (toCheck.substring(j,j+1) == "-") continue;
         return false;
      }
   }
   
   return true;
}

// 한글 check
function chk_hangul(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890`!@#$%^&*()-=_+~[]\{}|,./<>? ";

    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

// 한글이 한글자라도 들어가는가?
// 한글이 있으면 true, 없으면 false;
function chk_hangul_one(toCheck)
{
	var result = false;

	var pattern = /^[가-힣]+$/;

    for (i=0; i< toCheck.length; i++)
    {
		if (pattern.test(toCheck.substring(i,i+1)))
		{
			result = true;
		}
	}
	return result;
}

// 한글 입력이 안되도록.
function deny_hangul(w) {

	var pattern = /^[ㅏ-ㅣㄱ-ㅎ가-힣]+$/;
    for (i=0; i< w.value.length; i++)
    {
		if (pattern.test(w.value.substring(i,i+1)))
		{
			w.value = w.value.substring(0, i);
		}
	}

}


//영어,숫자, _ 만 가능
function chk_hangul2(toCheck) 
{
    var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
        
            if (idcheck == str.charAt(j)) break;
                
            if (j+1 == str.length)
            {
                return false;
            }
        }
    }
    return true;
}

// 한글, 영문만 입력가능
function chk_hangul3(toCheck) 
{
    var str = "1234567890`!@#$%^&*()-=_+~[]\{}|,./<>?";
    
    for (i=0; i< toCheck.length; i++)
    {
        idcheck = toCheck.charAt(i);
        
        for ( j = 0 ;  j < str.length ; j++)
        {
            if (idcheck == str.charAt(j)){
				return false;
			}                
            if (j+1 == str.length) break;
        }
    }
    return true;
}


// Email check
function chk_mail(toCheck) 
{
    // @표시 확인
    if (toCheck.indexOf('@') == -1 ) 
    { 
        return false; 
    }

    // .표시 확인
    if (toCheck.indexOf('.') == -1 ) 
    { 
        return false; 
    }
    
    // 한글 확인
    if ( chk_hangul(toCheck) == false ) 
    { 
        return false; 
    }
    
    return true;
}


// 주민번호 check
function chk_juminno(obj) 
{
	if (obj.length == 14) {
        var calStr1 = "2345670892345", biVal = 0, tmpCal, restCal;

        for (i=0; i <= 12; i++) {
                if (obj.substring(i,i+1) == "-") {
                        tmpCal = 1;
                }
                else {
                        biVal = biVal + (parseFloat(obj.substring(i,i+1)) * parseFloat(calStr1.substring(i,i+1)));
                }
        }

        restCal = 11 - (biVal % 11);

        if (restCal == 11) {
                restCal = 1;
        }

        if (restCal == 10) {
                restCal = 0;
        }
        if (restCal == parseFloat(obj.substring(13,14))) {
                return true;
        }
        else {
                return false;
        }
	}
	else {
		return false;
	}
}



// ID check
// id 의 길이는 minLength 이상, MaxLength 이하일경우 true
function chk_id(id, minLength, maxLength) {

	// 영문, 숫자, _ 만 가능
	var id_len = id.length;

	if (!chk_hangul2(id) || id_len < minLength || id_len > maxLength) return false;
	else return true;
}



// 필수항목 필드 체크 (fld:필드, txt: 필드String)
// 2007.04.05 박수일.
function chk_fileds_mandatory (fld, txt) {
	if(!fld.value) {
		alert (txt+" is Empty.");
		fld.focus();
		return false;
	}else return true;
}




// form check
// <input> tag에 아래사항을 check
// text : 해당 column 이름
// notnull : null check
// check
// - number : 숫자 check
// - date : 날자 check
// - mail : 메일 check
// - juminno : 주민번호 check
function chk_form(form) 
{
    var inx = 0; // 위치

    for ( ; inx < form.length; inx++)
    {
        //alert(inx);
        var column = form.elements[inx];
        
        var text = column.text;

        if ( (column.type == "text") || 
             (column.type == "password") || 
             (column.type == "textarea") ||
             (column.type == "file") )
        {
            // 필수항목 check
            if ( (column.notnull == "") && (chk_null(column.value)) ) 
            {
                alert ("Please enter your " + text);
                column.focus();
                return false;
            }
            
            // null이 아니면 check
            if( !chk_null(column.value) )
            {
                // 형태 check
                if ( (column.check == "number") && (!chk_num1(column.value)) )
                {
                    alert (text + " is only number");
                    column.focus();
                    return false;
                }
				
                else if ( (column.check == "date") && (!chk_date(column.value)) )
                {
                    alert (text + " is invalid date");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "mail") && (!chk_mail(column.value)) )
                {
                    alert ("Email address is invalid.");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "juminno") && (!chk_juminno(column.value)) )
                {
                    alert ("올바른 주민번호가 아닙니다.");
                    column.focus();
                    return false;
                }
                else if ( (column.check == "length") && (!chk_length(column.value,column.hlength)) )
                {
                    alert (column.hlength+"자까지 입력가능합니다.");
                    column.focus();
                    return false;
                }

                else if ( (column.check == "length3") && (!chk_length3(column.value,column.hlength) || !chk_num1(column.value)) )
                {
                    alert (text + "는(은) " + column.hlength + "글자의 숫자로 입력하세요.");
                    column.focus();
                    return false;
                }

				else if ( (column.check == "hangul") && (!chk_hangul2(column.value)) )
                {
                    alert (text + " 는(은) 영문,숫자,'_'만 입력가능합니다.");
                    column.focus();
                    return false;
                }
				else if ( (column.check == "hangul2") && (!chk_hangul3(column.value)) )
                {
                    alert (text + " 는(은) 영문,한글만 입력가능합니다.");
                    column.focus();
                    return false;
                }
				else if ( (column.check2 == "length2") && (!chk_length2(column.value,column.maxlen,column.minlen)) )
                {
                    alert (text + " 는(은) "+ column.minlen + " ~ " + column.maxlen +"자까지 입력가능합니다");
                    column.focus();
                    return false;
                }
				else if ( (column.check == "number3") && (!chk_num3(column.value)) )
                {
                    alert (text + " 는(은) 숫자,'-'만 입력가능합니다.");
                    column.focus();
                    return false;
                }

            }
        }
    }
  
    return true;
}

// object가 null인지 check
function chk_null_obj(Obj) 
{
    var check = false;
    var Radio = Obj;

    if (!Radio) return check;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ ) 
        {
            if ( Radio[i].checked == 1 ) 
            {
                check = true;
                break;
            }
        }
    }
    else
    {
        if ( Radio.checked == 1 ) 
        {
            check = true;
        }
    }

    return check
}


// 모든 object를 check함
function CheckAll(Obj) 
{
    var Radio = Obj.form.file;

    if (!Radio) return;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ )
            Obj.form.file[i].checked=1;
    }
    else 
    {
        Obj.form.file.checked=1;
    }
}


// 모든 object를 uncheck함 
function UnCheckAll(Obj) 
{
    var Radio = Obj.form.file;

    if (!Radio) return;

    if (Radio.length) 
    {
        for ( var i=0; i<Radio.length; i++ )
            Obj.form.file[i].checked=0;
    }
    else 
    {
        Obj.form.file.checked=0;
    }
}

// window 띄우기
function open_win(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window 띄우기, no scroll
function open_win1(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=No,resizable=no,menubar=no,border=0');
    msgWindow.focus()
}

// window 띄우기
function open_win_XY(URL, name, width, height) 
{
    msgWindow=window.open(URL,name,'location=0,toolbar=no,width='+width+',height='+height+',directories=no,status=no,scrollbars=Yes,resizable=Yes,menubar=no,border=0,screenX=0,screenY=0');
    msgWindow.focus()
}

// 기본 팝업창
function view_open(url,name,features) { 
    window.open(url,name,features);
}

// 버튼 롤오버
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_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_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];}
}


// 배너스크롤

var bNetscape4plus = (navigator.appName == "Netscape" && navigator.appVersion.substring(0,1) >= "4");
var bExplorer4plus = (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.substring(0,1) >= "4");

function CheckUIElements()
{
        var yMenuFrom, yMenuTo, yButtonFrom, yButtonTo, yOffset, timeoutNextCheck;

        if ( bNetscape4plus ) { // 네츠케이프 용 설정
                //yButtonFrom = document["divLinkButton"].top;
                //yButtonTo   = top.pageYOffset + top.innerHeight - 55;
                yMenuFrom   = document["divMenu"].top;
                yMenuTo     = top.pageYOffset + 5;   // 위쪽 위치
        }
       else if ( bExplorer4plus ) {  // IE 용 설정
                //yButtonFrom = parseInt (divLinkButton.style.top, 10);
                //yButtonTo   = document.body.scrollTop + document.body.clientHeight - 55;
                yMenuFrom   = parseInt (divMenu.style.top, 10);
                yMenuTo     = document.body.scrollTop + 1; // 위쪽 위치
        }

        timeoutNextCheck = 500;

        if ( Math.abs (yButtonFrom - (yMenuTo + 152)) < 6 && yButtonTo < yButtonFrom ) {
                setTimeout ("CheckUIElements()", timeoutNextCheck);
                return;
        }


        if ( yButtonFrom != yButtonTo ) {
                yOffset = Math.ceil( Math.abs( yButtonTo - yButtonFrom ) / 10 );
                if ( yButtonTo < yButtonFrom )
                        yOffset = -yOffset;

                if ( bNetscape4plus )
                        document["divLinkButton"].top += yOffset;
                else if ( bExplorer4plus )
                        divLinkButton.style.top = parseInt (divLinkButton.style.top, 10) + yOffset;

                timeoutNextCheck = 10;
        }
        if ( yMenuFrom != yMenuTo ) {
                yOffset = Math.ceil( Math.abs( yMenuTo - yMenuFrom ) / 20 );
                if ( yMenuTo < yMenuFrom )
                        yOffset = -yOffset;

                if ( bNetscape4plus )
                        document["divMenu"].top += yOffset;
                else if ( bExplorer4plus )
                        divMenu.style.top = parseInt (divMenu.style.top, 10) + yOffset;

                timeoutNextCheck = 10;
        }

        setTimeout ("CheckUIElements()", timeoutNextCheck);
}

function OnLoad()
{
        var y;


        // 페이지 로딩시 포지션
        if ( bNetscape4plus ) {
                document["divMenu"].top = top.pageYOffset + 135;
                document["divMenu"].visibility = "visible";
                //document["divLinkButton"].top = top.pageYOffset + top.innerHeight - 55;
                //document["divLinkButton"].visibility = "visible";
        }
        else if ( bExplorer4plus ) {
                divMenu.style.top = document.body.scrollTop + 135;
                divMenu.style.visibility = "visible";
               //divLinkButton.style.top = document.body.scrollTop + document.body.clientHeight - 55;
                //divLinkButton.style.visibility = "visible";
        }

        // initializing UI update timer
        CheckUIElements();
        //if ( bExplorer4plus )
        //        setTimeout ( "FlashTitleStepIt(255)", 10 );
        return true;
}


