function check_form(f, lang){
	// check_form(this, 'e') 식으로 lang 에 값이 들어오면 영문으로 나온다. @ 수정 2007.3.12
	var fLen = f.elements.length;

	var obj;
	var types;
	var value;
	var msg;
	var req;	
	var max;		
	var min;		
	var aznum;
	var num;		
	var az;		
	var nohan;
	var email;

	for(i=0; i<fLen; i++){
		obj	= f.elements[i];
		types	= toUpperCase(obj.getAttribute("type"));
		value	= obj.value;                
		msg	= obj.getAttribute("msg");  
		req	= obj.getAttribute("req");  
		max	= obj.getAttribute("max");  
		min	= obj.getAttribute("min");  
		aznum	= obj.getAttribute("aznum");
		num	= obj.getAttribute("num");  
		az	= obj.getAttribute("az");   
		nohan	= obj.getAttribute("nohan");
		email	= obj.getAttribute("email");
		
		maxi	= obj.getAttribute("maxi");  
		mini	= obj.getAttribute("mini");

		if(req != null){
			if(value.length < 1){
				if (!lang) alert(msg+" 항목을 입력하세요");
				else alert("Fill the field '"+msg +"', please.");
				obj.focus();
				return false;
			}
		}

		if(min != null && value.length>0){
			if(parseInt(min) == 0){
				if(value.length < 1){
					if (!lang) alert(msg+" 항목을 입력하세요");
					else alert("Fill the field '"+msg+"', please.");
					obj.focus();
					return false;
				}
			}else if(value.length < parseInt(min)){
				
				if (!lang) alert(msg+" 항목을 "+ min+"자 이상 입력하세요");
				else alert(msg+"Use more than "+ min+" characters or numbers, please.");
				
				obj.focus();
				return false;
			}
		}

		if(max != null){
			if(value.length > parseInt(max)){
				if (!lang)  alert(msg+" 항목을 "+ max+"자 이하로 입력하세요");
				else alert(msg+"Use fewer than "+ max+" characters or numbers, please.");
				obj.focus();
				return false;
			}
		}
		

		if(aznum != null && value.length>0){
		    if (!/^[a-zA-Z0-9]+$/.exec(value)) {
				if (!lang) alert(msg+" 항목은 영문과 숫자로만 입력하세요");
				else alert("Fill the field '"+msg+"' with characters or numbers, please.");
				obj.focus();
				return false;
			}
		}

		if(num != null && value.length>0){
		    if (!/^[0-9]+$/.exec(value)) {
				if (!lang) alert(msg+" 항목은 숫자로만 입력하세요");
				else alert("Fill the field '"+msg+"' with numbers, please.");
				obj.focus();
				return false;
			}
		}
		
		if(az != null && value.length>0){
		    if (!/^[a-zA-Z]+$/.exec(value)) {
				if (!lang) alert(msg+" 항목은 영문으로만 입력하세요");
				else alert("Fill the field '"+msg+"' with characters, please. ");
				obj.focus();
				return false;
			}
		}


		if(email != null && value.length>0){
		    if (!/^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/.exec(value)) {
				if (!lang) alert(msg+" 항목을 확인하세요");
				else alert("Fill the field '"+msg+"', please.");
				obj.focus();
				return false;
			}
		}
		
		//2007.5.3 새로추가 (숫자의 크기비교, 예, 달력)
		if(mini != null && value.length>0){
			 if(value < parseInt(mini)){
				//alert(value);
				if (!lang) alert(msg+" 항목을 "+ mini+" 이상으로 입력하세요");
				else alert(msg+"Use more than "+ mini+" characters or numbers, please.");
				obj.focus();
				return false;
			}
		}

		if(maxi != null && value.length>0){
			if(value > parseInt(maxi)){
				if (!lang)  alert(msg+" 항목을 "+ maxi+" 이하로 입력하세요");
				else alert(msg+"Use fewer than "+ maxi+" characters or numbers, please.");
				obj.focus();
				return false;
			}
		}
		


	}// for

	return true;
}



// 문자 길이 반환 (영문 1byte, 한글 2byte 계산)
function getLen(str) {
	var len;
    var temp;

    len = str.length;
    var tot_cnt = 0;

    for(k=0;k < len;k++){
    	temp = str.charAt(k);
    	if(escape(temp).length > 4)
    		tot_cnt += 2;
    	else
    		tot_cnt++;
    }
    return tot_cnt;
}
// 대문자 변환 ex) toUpperCase(문자)
function toUpperCase(str) {
	var ret;
	str != null ? ret = str.toUpperCase() : ret = "";
	return ret;
}	


function init_form(f){

	var fLen = f.elements.length;
	var obj;
	var ival;
	var ival_temp= null;
	var type;

	for(i=0; i<fLen; i++){
		obj	= f.elements[i];
		type = toUpperCase(obj.getAttribute("type"));
		ival = obj.getAttribute("ival");
	
		if(ival!=null && type=="SELECT-ONE"){
			for(j=0;j<obj.options.length;j++){
				if(obj.options[j].value == ival) obj.options[j].selected = true;
			}
		}

		if (ival!=null && (type == "CHECKBOX")) {
			if (obj.value == ival) obj.checked = true;
		}

		if (ival!=null && (type == "RADIO")) {
			if (obj.value == ival) obj.checked = true;
		}
	}
}

/*
<script language="javascript" src="checkForm.js"></script>

<script language="javascript">
function check(f){
	if(check_form(f)){
		return true;
	}else{
		return false;
	}
}
</script>

 onSubmit="return check_form(this);">
<script language="javascript">
init_form(document.form);
</script>
*/
