
function checkForm( f )
{
	for (var i=0; i<f.elements.length; i++) 
    {
        if ( f.elements[i].getAttribute("msg") ) 
        {
            if ( isEmpty( f.elements[i].value ) ) 
            {
                
                var splitData = f.elements[i].getAttribute("msg").split("||");

                var msgData = "";

                if( splitData.length )
                {
                    for( var kk = 0; kk < splitData.length; kk++ )
                    {
                        msgData += splitData[kk] + "\n";
                    }
                }
                else
                {
                    msgData = f.elements[i].getAttribute("msg");
                }

                if( (f.elements[i].type && f.elements[i].type!="hidden" && f.elements[i].type!="select-one") )
                {
                    ErrMsg( f.elements[i], msgData )
                }
                else
                {
                    alert( msgData  );
                }
                return false;
            }
        }
    }

	return true;
}

function len_chk(obj){
    var f = document.form1;

    if(obj.value.length > 150){
        alert("글자수는 150자로 제한됩니다.");
        obj.value = obj.value.substring(0,150);
        obj.focus();
    }
}

function len_chk_mae(obj){
    var f = document.form1;

    if(obj.value.length > 400){
        alert("글자수는 400자로 제한됩니다.");
        obj.value = obj.value.substring(0,400);
        obj.focus();
    }
}

function len_chk_250(obj){
    var f = document.form1;

    if(obj.value.length > 250){
        alert("글자수는 250자로 제한됩니다.");
        obj.value = obj.value.substring(0,250);
        obj.focus();
    }
}
function len_chk_250E(obj){
    var f = document.form1;

    if(obj.value.length > 400){
        alert("Characters are limited to400 characters.");
        obj.value = obj.value.substring(0,400);
        obj.focus();
    }
}
function openWin(url,winName,width,height,scroll)
{
    window.open( url , winName,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + scroll + ",resizable=no,width=" + width + ",height=" + height);
    return ;
}

function openWinCenter(url,winName,width,height,scroll)
{
	var sw=screen.availWidth;
	var sh=screen.availHeight;

	 //열 창의 포지션
	var px=(sw-width)/2;
	var py=(sh-height)/2;

    window.open( url , winName,"toolbar=no,location=no,directories=no,status=no,menubar=no,left="+px+",top=" +py+ ",scrollbars=" + scroll + ",resizable=no,width=" + width + ",height=" + height);
    return ;
}


function isEmpty( data )
{
    for( var i = 0 ; i < data.length ; i++ )
    {
        if( data.substring( i , i + 1 ) != " " )
        {
            return false;
        }
    }
    return true;
}

// 메세지를 출력하고, Object로 focus를 돌려준다.
function ErrMsg( obj, msg )
{
    try
    {
        alert( msg );

        if( obj.type == "select-one" )
        {
            obj.focus();
        }
        else
        {
            obj.focus();
            obj.select();
        }
        return false;
    }
    catch(errorObject)
    {
        var msg = errorObject.description + "\n\n"
               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
	    alert(msg);
        return false;
    }
}

//숫자만 입력가능하게함 사용예<   OnKeyPress="numChk()"   >
function numChk()
{
    if ((event.keyCode<48) || (event.keyCode>57))
        event.returnValue=false;
}

function numDotChk()
{
    if ((event.keyCode != 46) && (event.keyCode<48) || (event.keyCode>57))
    {
        event.returnValue=false;
    }
}

function numSemiChk()
{
    if ((event.keyCode != 46) && (event.keyCode<48) || (event.keyCode>58))
    {
        event.returnValue=false;
    }
}


function chkCommID( str )
{
	var check = false;

	for(var i=0; i<str.length; i++)
	{
		var oneChar = str.charAt(i)

		if(( (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) || (oneChar >= 0 && oneChar <= 9) ))
		{
			check = true;
		}
		else
		{
			check = false;
			break;
		}
	}

	return check;
}


// 메일 체크
function checkEmail(strEmail)
{
	var arrMatch = strEmail.match(/^(\".*\"|[A-Za-z0-9_-]([A-Za-z0-9_-]|[\+\.])*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9][A-Za-z0-9_-]*)+)$/);
	if( arrMatch == null )
	{
		return false;
	}

	var arrIP = arrMatch[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if( arrIP != null )
	{
		for( var i = 1 ; i <= 4 ; i++ )
		{
			if( arrIP[i] > 255 )
			{
				return false;
     		}
   		}
	}
	return true;
}

// 달력 생성
function Calendar( obj_year, obj_month, obj_day )
{
	var result = "false";
	    result = window.showModalDialog('/common/func/calendar.asp','Calendar','dialogWidth:365px;dialogHeight:295px; center:yes; help:no; status:no; scroll:no; resizable:no');

	if( result == null )
        return;

    if( result.length != 3 )
        return;

    if( obj_month != null && obj_day != null )
    {
        obj_year.value  = result[0];
        obj_month.value = result[1];
        obj_day.value   = result[2];
    }
    else
    {
        obj_year.value  = result[0] + "-" + result[1] + "-" + result[2];
    }
}



function toFindAddr( ckind )
{
    openWinCenter("/common/addr/addrFind.asp?ckind=" + ckind,"addr","520","350","yes");
}

function toAddZip( ZIPCODE, SIDO, GUGUN, DONG, BUNJI, ckind )
{
    var f = document.form1;

	var arrZipCode = ZIPCODE.split("-");

	var post1 = arrZipCode[0];
	var post2 = arrZipCode[1];

    strAddress = SIDO + " " + GUGUN + " " + DONG + " ";
   
    f.strPost1.value = post1;
    f.strPost2.value = post2;

    f.strAddress.value = strAddress;

    f.strAddressSub.focus();
}
function toChangeMail( value )
{
    var f = document.form1;

    f.strEmail2.value = value;

    if( isEmpty( value ) )
    {
        f.strEmail2.focus();
    }
}
 
function chkEnglish( str )
{
	var check = false;

	for(var i=0; i<str.length; i++)
	{
		if(( (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
		{
			check = true;
		}
		else
		{
			check = false;
			break;
		}
	}

	return check;
}

function chkEnglishReplaceUpper( obj )
{
	var check = false;

	var str = obj.value;

	obj.value = str.toUpperCase();
	
	for(var i=0; i<str.length; i++)
	{
		if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
		{
			check = true;
		}
		else
		{
			check = false;
			break;
		}
	}

	return check;
}

function toEnglishChange(obj)
{
	if( !isEmpty( obj.value ) )
	{
		if( !chkEnglishReplaceUpper(obj) )
		{
			var str = obj.value;
			var newStr = "";

			for(var i=0; i<str.length; i++)
			{
				if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
				{
					newStr += str.charAt(i);
				}
			}
			alert("영문으로만 입력해주세요.");
			obj.value = newStr;

			return;
		}
	}
}
function toEnglishChangeE(obj)
{
	if( !isEmpty( obj.value ) )
	{
		if( !chkEnglishReplaceUpper(obj) )
		{
			var str = obj.value;
			var newStr = "";

			for(var i=0; i<str.length; i++)
			{
				if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
				{
					newStr += str.charAt(i);
				}
			}
			alert("Please enter only in English.");
			obj.value = newStr;

			return;
		}
	}
}


function chkEnglishReplaceFirstUpper( obj )
{
	var check = false;

	var str = obj.value;
	obj.value = "";
	obj.value  = str.substring(0,1).toUpperCase();
	obj.value += str.substring(1).toLowerCase();
	
	for(var i=0; i<str.length; i++)
	{
		if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
		{
			check = true;
		}
		else
		{
			check = false;
			break;
		}
	}

	return check;
}
function toEnglishFirstChange(obj)
{
	if( !isEmpty( obj.value ) )
	{
		if( !chkEnglishReplaceFirstUpper(obj) )
		{
			var str = obj.value;
			var newStr = "";

			for(var i=0; i<str.length; i++)
			{
				if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
				{
					newStr += str.charAt(i);
				}
			}
			alert("영문으로만 입력해주세요.");
			obj.value = newStr;

			return;
		}
	}
}
function toEnglishFirstChangeE(obj)
{
	if( !isEmpty( obj.value ) )
	{
		if( !chkEnglishReplaceFirstUpper(obj) )
		{
			var str = obj.value;
			var newStr = "";

			for(var i=0; i<str.length; i++)
			{
				if(( str.charCodeAt(i) == 32 || (str.charCodeAt(i) >=65 && str.charCodeAt(i) <= 90) || (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122)))
				{
					newStr += str.charAt(i);
				}
			}
			alert("Please enter only in English.");
			obj.value = newStr;

			return;
		}
	}
}

// value가 숫자로만 되어있는지 체크한다.
function isDigitValue(value)
{
    try
    {
        inputStr = value;
        for( var i = 0 ; i < inputStr.length ; i++ )
        {
            var oneChar = inputStr.charAt(i)
            if (oneChar < "0" || oneChar > "9")
            {
                return false;
            }
        }
        return true;
    }
    catch(errorObject)
    {
        var msg = errorObject.description + "\n\n"
               + "Error Number : " + (errorObject.number>>16 & 0x1FFF) + "\n\n";
	    alert(msg);
        return false;
    }
}

function toDotData( obj )
{
    var val = obj.value;
    val = reduce_comma(val);
    
    if( isDigitValue(val) )
    {
        val = display_comma(val);
    }
    else
    {
        val = "";
    }

    obj.value = val;
}

function resizeIFrameInner(id) 
{ 
	var hideHeight = jQuery(document.body).height();

	var theFrame = jQuery("#"+id, parent.document.body);

	theFrame.height(jQuery(document.body).height() + 30);
} 


function resizeIFrame(id)
{
	var hideHeight = jQuery(document.body).height();

	var theFrame = jQuery("#"+id, parent.document.body);

	theFrame.height(jQuery(document.body).height() + 30);
}



function resizeIFrameDiv(divid, ifrmid)
{
	var hideHeight = jQuery("#"+divid).height();

	var theFrame = jQuery("#"+ifrmid, parent.document.body);

	theFrame.height(hideHeight);
}


var editorObjKey = "";
function _editorOpenFileManager(obKey)
{
    if( !isEmpty( obKey ) )
    {
        editorObjKey = obKey;

        var html = "/common/module/file/editor_file_attment.asp";

        SLB( html, 'iframe', 600, 140,  false, true );
    }
}

function _editorImgWrite(imgURL)
{
    if( !isEmpty( editorObjKey ) )
    {
        sHTML = "<p><img src=\""+imgURL+"\"></p>";
        oEditors.getById[editorObjKey].exec("PASTE_HTML", [sHTML]);
    }
}


function _toOneFileOpen( type )
{
    var html = "/common/module/file/one_file_attment.asp?fType="+type;

    SLB( html, 'iframe', 450, 140,  false, true );
}

function _toOneFileApply( type, file )
{
    var attFile = document.getElementById(type);

    if( attFile )
    {
        attFile.value = file;
    }

    SLB();
}

function _toOneOrgFileOpen( type )
{
    var html = "/common/module/file/one_orgfile_attment.asp?fType="+type;

    SLB( html, 'iframe', 450, 140,  false, true );
}

function _toOneOrgFileApply( type, orgFile, file )
{
    var attFile    = document.getElementById(type);
    var attOrgFile = document.getElementById("org_"+type);

    if( attFile )
    {
		if( attOrgFile )
		{
			attOrgFile.value = orgFile;
		}

		if( attFile )
		{
			attFile.value = file;
		}
    }

    SLB();
}

function tryReHeight()
{
}
function _toSearchFileData(type)
{
    var html = "/common/module/file/data_file_attment.asp?fType="+type;

    SLB( html, 'iframe', 450, 140,  false, true );
}

function _toSearchFileDataApply( type, realFile, file )
{
    parent.toFileDataApply( type, realFile, file );

    SLB();
}

function toMp4Down(b_idx)
{
    var html = "/down/lec_mp_file_down.asp?b_idx="+b_idx;

    SLB( html, 'iframe', 450, 200,  false, true );

}

/** 
 * 입력 값이 Object 인지를 반환.
 * returns true if a is an object, and array, or a function.
 * It returns false if a is a string, a number, a boolean, or null, or undefined.
 */        
function isObject(input) {
	return (input && typeof input == 'object') || isFunction(input);
} 

/**         
 * 입력 값이 Function 인지를 반환.
 */        
function isFunction(input) {
	return typeof input == 'function';
}

function resizeImageWidth(area, width) {
	var imgs;

	if(!isObject(area)) return;

	if(area.length == undefined) {
		imgs = area.getElementsByTagName("IMG");

		for(j=0; j< imgs.length; j++) {
			if(imgs[j].width>width){
				imgs[j].height = imgs[j].height * width / imgs[j].width;
				imgs[j].width = width;
			}
		}
	}
	else {
		for(i=0; i<area.length; i++) {
			imgs = area[i].getElementsByTagName("IMG");

			for(j=0; j< imgs.length; j++) {
				if(imgs[j].width>width){
					imgs[j].height = imgs[j].height * width / imgs[j].width;
					imgs[j].width = width;
				}
			}
		}
	}
}


    function display_comma(value) {

    var src;
    var i;
    var factor;
    var su;
    var Spacesize = 0;
    
    var String_val = value.toString();
    
    factor = String_val.length % 3;
    su = (String_val.length - factor) /3;
    src = String_val.substring(0,factor);

    for(i=0; i<su ; i++)
    {
       if ((factor==0)&&(i==0))
        {
             src += String_val.substring(factor+(3*i), factor+3+(3*i));
        }
        else 
        {
            if ( String_val.substring(factor+(3*i) - 1, factor+(3*i)) != "-" ) src +=",";
            src += String_val.substring(factor+(3*i), factor+3+(3*i));
        }
    }
    return src;
    }
    
    //delete comma 
    function reduce_comma(value) 
    {
    var x, ch;
    var i=0;
    var newVal="";
    for(x=0; x <value.length ; x++){
        ch=value.substring(x,x+1);
        if(ch != ",")  newVal += ch;
    }
    return newVal;
    }

/***********************************
설명 : textbox에 엔터 쳤을때 callback 함수 호출
***********************************/
function _comm_enter_callback(callback)
{
    if( event.keyCode == 13 )
    {
        callback();
    }
}

