function clearErrMsg()
{
    document.all.errorbox.style.display="none";
    writeText("error_messge", "");
}

function showErrMsg(vMsg)
{
    document.all.errorbox.style.display="";
    writeText("error_messge", vMsg);
}

function checkEmptyMsg(formVar, text){	 
    //alert( formVar.value );
    //alert( text );
     
	if (trim(formVar.value).length < 1) {
        //alert( '1' );
		writeText("error_messge", text);
        //alert( '2' );
		document.all.errorbox.style.display="";
        //alert( '3' );
		formVar.value="";		
		if ( formVar.readonly != true){
            formVar.focus();
        }
        //alert( '4' );		
		return false;
	} 
	return true;
}
    
function writeText(id, str) {
    document.all[id].innerHTML = str;
    /*
	var strTag = str;

	if (document.all)
		document.all[id].innerHTML = strTag;
	else
		with (document[id].document) {
			open();
			write(strTag);
			close();
		}
    */
}

function trim(text){
	if(text != null){
	    cnt = text.length;
	    obj = new Array(cnt);
	    for(i = 0; i < cnt; i++){
	        obj[i] = text.charAt(i);
	    }
	    obj = obj.reverse();
	    retValue = "";
	    for(i = 0; i < cnt; i++){
	        if(obj[i] != " ") break;
	        if(obj[i] == " ") obj[i] = "";
	    }
	    obj = obj.reverse();
	    for(i = 0; i < cnt; i++){
	        retValue = retValue + obj[i].toString();
	    }
	}else{//null 
		retValue = "";
	}
    return retValue;
}
    
 
function checkEmpty(formVar, text)
{       
	if (trim(formVar.value).length < 1) {
		alert("" + text + "");
	
		formVar.value="";
		
		if ( formVar.readonly != true) formVar.focus();
		
		return false;
	} 
	return true;
}


function checkEmptyArray(vObj, vMsg) {

    if (vObj.length !=undefined) {
       for(iLoop=0; iLoop < vObj.length; iLoop++ ) {
           if (!checkEmpty(vObj[iLoop], vMsg)) return false;
       }
      
    } else {
        if (!checkEmpty(vObj, vMsg)) return false;
    }
    
    return true;
}
 
function checkLength(formVar, text, textlen)
{
	if (charBytesChk(formVar.value) < textlen) {
		alert("" + text + "  길이는 " + textlen + "자리 입니다!");
		formVar.focus();
		return false;
	}
	return true;
}

function checkLength2(formVar, text, textlen1, textlen2)
{
	if (charBytesChk(formVar.value) < textlen1 || charBytesChk(formVar.value) > textlen2) {
		alert("" + text + "는 " + textlen1 + "~" + textlen2 + "자 까지 가능합니다.");
		formVar.focus();
		return false;
	}
	return true;
}    

function fileUpCheck(vObj) {

    if (vObj.length !=undefined) {
 
       for(iLoop=0; iLoop < vObj.length; iLoop++ ) {
           if (!fileTypeCheck(vObj[iLoop])) return false;
       }
      
    } else {
        if (!fileTypeCheck(vObj)) return false;
    }
    
    return true;
}

function fileTypeCheck(vObj) {
    var vVal = vObj.value;
    
    if (trim(vVal).length < 1) return true;
    
     vFile = vVal.slice(vVal.lastIndexOf("\\") + 1);
       
    vVal = vVal.toUpperCase();	
 
    
    if ( vVal.indexOf(".HWP")  > 0) { return true; }
    else if( vVal.indexOf(".PPT")  > 0) { return true; }
    else if( vVal.indexOf(".PDF")  > 0) { return true; }
    else if( vVal.indexOf(".DOC")  > 0) { return true; }
    else if( vVal.indexOf(".XLS")  > 0) { return true; }
    else if( vVal.indexOf(".GUL")  > 0) { return true; }
    else if( vVal.indexOf(".GIF")  > 0) { return true; }
    else if( vVal.indexOf(".JPG")  > 0) { return true; }
    else if( vVal.indexOf(".TIF")  > 0) { return true; }
    else if( vVal.indexOf(".MP3")  > 0) { return true; }        
    else if( vVal.indexOf(".WMV")  > 0) { return true; }        
    else if( vVal.indexOf(".AVI")  > 0) { return true; }        
    else if( vVal.indexOf(".MPEG") > 0) { return true; }            
    else if( vVal.indexOf(".WMA")  > 0) { return true; }            
    else if( vVal.indexOf(".RA")   > 0) { return true; }            
    else if( vVal.indexOf(".ASF")  > 0) { return true; }            

    
    alert("확장자가 [" + vVal.slice(vVal.lastIndexOf(".") + 1)  + "]인 파일 확장자는 올릴 수 있습니다.");
    vObj.focus();
    return false;
	
}

/*
*email Check
*@param text: eMail Address
*@return none
*/
function EmailCheck(text){
    //ex) onBlur="EmailCheck(email)"
    atcnt = 0;      //@count
    atidx = 0;      //@index
    pocnt = 0;      //.count
    p1idx = 0;      //.first idx
    p2idx = 0;      //.last idx
 

    for(i=0; i<text.value.length; i++){
        if(text.value.charAt(i) == "@"){
            ++atcnt;
            atidx = i;
        }

        if(text.value.charAt(i) == "."){
            ++pocnt;
            if(p1idx == 0){
                p1idx = i;   
            }
            p2idx = i;
        }
    }

    if(text.value.length > 0 &&
        (text.value.length < 10 || atcnt != 1 || atidx < 4 || pocnt == 0 || pocnt > 3 ||
        ((p1idx > atidx) && p1idx-atidx < 3) ||
        ((p1idx < atidx) && atidx-p1idx < 3) || ((p1idx != p2idx) && p2idx-p1idx < 3))){
        text.select();
        text.focus;
        return false;
    }
    
    return true;
}

function checkRadioEmpty(formVar, vMag) {
    bFlag = false;
    
    if (formVar.length !=undefined) {
 
       for(iLoop=0; iLoop < formVar.length; iLoop++ ) {
          if (formVar[iLoop].checked) bFlag = true;
       }
      
    } else {
        if (formVar.checked) bFlag = true;  
    }
    
    if (!bFlag) alert(vMag);
    return  bFlag;    
}  

function checkRadioValue(formVar) {
    retVal = "";
    
    if (formVar.length !=undefined) {

       for(iLoop=0; iLoop < formVar.length; iLoop++ ) {  
        
          if (formVar[iLoop].checked == true) {
             if (retVal != "" ) retVal = retVal +",";
             retVal = retVal + formVar[iLoop].value; 
          }   
       }
      
    } else {
        if (formVar.checked) retVal =formVar.value; 
    }
    
    return  retVal;    
}  

function popupWin(winURL, winName, winWidth, winHeight, winOption) {

	var l = 16, t = 16; 	 
	var props = "";
 	
	if (winOption == "") {
		props += "toolbar=0,location=0,directories=0,status=0,menubar=0,";	 
		props += "scrollbars=1,resizable=0,copyhistory=0,";
	} else {
		props = winOption;
	}

	props += "width=" + winWidth + ",height=" + winHeight;

	if (window.screen && window.screen.availWidth) {

		l = Math.floor(((screen.availWidth - winWidth)/2) + 5);
		t = Math.floor((screen.availHeight - winHeight)/2);
		if (l < 0) l = 0;
		if (t < 0) t = 0;
		props += ",left=" + l + ",top=" + t;
	}

	window.open(winURL, winName, props);
	//aWinObj.focus();

}

function fileDownload(fileNo) {
    var winURL="/lib/file_download.php?file_no=" +fileNo;
	window.location.href=winURL;

}
