

// 체크박스 전체 선택/취소
function checkBoxAll(obj1, obj2){
	if( obj2.length > 1 ){
		for( idx = 0 ; idx < obj2.length ; idx++ ){
			obj2[idx].checked = obj1.checked;
		}
	}else{
		 obj2.checked = obj1.checked;
	}
}





/********************************************************************
*
*	Form Check Script
*							2001.09.28
*					by fid_web3team
********************************************************************/


	String.prototype.isid = function() {
		if (this.search(/[^A-Za-z0-9_-]/) == -1)
			return true;
		else 
			return false;
	}

	String.prototype.istel = function() {
		if (this.search(/[^0-9_-]/) == -1)
			return true;
		else 
			return false;
	}

	String.prototype.isalpha = function() {
		if (this.search(/[^A-Za-z]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.isnumber = function() {
		if (this.search(/[^0-9]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.isdecimal = function() {
		if (this.search(/[^.0-9]/) == -1)
			return true;
		else
			return false;
	}



	String.prototype.isjumin = function() {
		var jumin= this
		if (jumin.length  != 13) 
			return false;
		tval=jumin.charAt(0)*2 + jumin.charAt(1)*3 + jumin.charAt(2)*4
		+ jumin.charAt(3)*5 + jumin.charAt(4)*6 + jumin.charAt(5)*7
		+ jumin.charAt(6)*8+ jumin.charAt(7)*9 + jumin.charAt(8)*2
		+ jumin.charAt(9)*3 + jumin.charAt(10)*4 + jumin.charAt(11)*5;

		tval2=11- (tval % 11);
		tval2=tval2 % 10;
		
		if (jumin.charAt(12)==tval2 &&  (jumin.charAt(6)=="1" ||jumin.charAt(6)=="2")) {
			return true;
		}
		else{
			return false ;
		}
	}

	String.prototype.isemail = function() {
		if (this.search(/(.+)@.+\..+/) == -1)
			return false;
		else {
			for(var i=0; i < this.length;i++)
				if (this.charCodeAt(i) > 256)
					return false;
			return true;
		}
	}

	String.prototype.isdate = function() {
		if (this.search(/\d{4}\.\d{2}\.\d{2}/) == -1 && this.search(/\d{4}\-\d{2}\-\d{2}/) == -1)
			return false;
		else {
			return true;
		}
	}

	String.prototype.strLen = function() {
		var temp;
		var set = 0;
		var mycount = 0;

		for( k = 0 ; k < this.length ; k++ ){
			temp = this.charAt(k);

			if( escape(temp).length > 4 ) {
				mycount += 2
			}
			else mycount++;
		}

		return mycount;
	}

	String.prototype.ltrim = function() {
		var i, j = 0;
		var objstr

		for ( i = 0; i < this.length ; i++){
			if (this.charAt(i) == ' ' ){
				j = j + 1;
			}
			else{
				break;
			}
		}
		return this.substr(j, this.length - j+1)  
	}

	String.prototype.rtrim = function() {
		var i, j = 0;

		for ( i = this.length - 1; i >= 0 ; i--){
			if (this.charAt(i) == ' ' ){
				j = j + 1
			}
			else{
				break;
			}
		}
		return 	this.substr(0, this.length - j);
	}

	String.prototype.trim = function() {
		return this.replace(/\s/g, "");
	}

	function _cmdfocus(formobj){
		formobj.select();
		formobj.focus();
	}

	function checkJumin(formValue){

	}




function chkdate(cmbYear, cmbMonth, cmbDay){
	var selectmonth = cmbMonth.selectedIndex;
	var monthday, i;
	selectmonth = selectmonth + 1;

	// 평년일때 날자처리
	if (selectmonth == 1) monthday = 31;
	if (selectmonth == 3) monthday = 31;
	if (selectmonth == 4) monthday = 30;
	if (selectmonth == 5) monthday = 31;
	if (selectmonth == 6) monthday = 30;
	if (selectmonth == 7) monthday = 31;
	if (selectmonth == 8) monthday = 31;
	if (selectmonth == 9) monthday = 30;
	if (selectmonth == 10) monthday = 31;
	if (selectmonth == 11) monthday = 30;
	if (selectmonth == 12) monthday = 31;
	if (selectmonth == 13) monthday = 30;

	// 윤년처리
	if(selectmonth == 2) {
		var y = cmbYear.value;
		if ((y % 4) == 0) {
			if ((y % 100) == 0) {
				if ((y % 400) == 0) {
					monthday = 29;
				}else {
					monthday = 28;
				}
			}else { 
				monthday = 29;
			}
		}else { 
			monthday = 28;
		}
	}

	cmbDay.length = monthday;
	for(i=0 ; i < monthday ;i++) {
		if (i < 9) {
			var option = new Option(i+1,'0'+(i+1));
			}
		else {
			var option = new Option(i+1, i+1);
			}
		cmbDay.options[i] = option;
	}
	return true;
}	
	
function companyCheck(obj) { // 사업자 번호 체크

		var li_temp, li_lastid;
		biz_value = new Array(10);

		var ju = obj.value; 

		biz_value[0] = ( parseFloat(ju.substring(0 ,1)) * 1 ) % 10;
		biz_value[1] = ( parseFloat(ju.substring(1 ,2)) * 3 ) % 10;
		biz_value[2] = ( parseFloat(ju.substring(2 ,3)) * 7 ) % 10;
		biz_value[3] = ( parseFloat(ju.substring(3 ,4)) * 1 ) % 10;
		biz_value[4] = ( parseFloat(ju.substring(4 ,5)) * 3 ) % 10;
		biz_value[5] = ( parseFloat(ju.substring(5 ,6)) * 7 ) % 10;
		biz_value[6] = ( parseFloat(ju.substring(6 ,7)) * 1 ) % 10;
		biz_value[7] = ( parseFloat(ju.substring(7 ,8)) * 3 ) % 10;
		li_temp = parseFloat(ju.substring(8, 9)) * 5 + "0";
		biz_value[8] = parseFloat(li_temp.substring(0,1)) + parseFloat(li_temp.substring(1,2));
		biz_value[9] = parseFloat(ju.substring(9,10));
		li_lastid = (10 - ( ( biz_value[0] + biz_value[1] + biz_value[2] + biz_value[3] + biz_value[4] + biz_value[5] + biz_value[6] + biz_value[7] + biz_value[8] ) % 10 ) ) % 10;


		if (biz_value[9] == li_lastid) {
			return true; 
		} else { 
			alert("not biz number. checking"); 
			obj.focus(); 
			return false; 
		} 
		
	}

	// 문자열의 값을 바이트수로 변환하여 리턴 
	function getBytes(str) {    
	    var i, ch, bytes;
	    var app, isNe = 0;
	
	    if(str == '') {
	        return 0;
	    }
   
	    app = navigator.appName;
	    
	    if(app == 'Netscape') {
	        isNe = 1;
	    }

	    for(i = 0, bytes = 0; i < str.length; i++) {
	        ch = str.charAt(i);

	        if(isInt(ch)) {
	            bytes++;            
	        } else if(isLower(ch)) {
	            bytes++;
	        } else if(isUpper(ch)) {
	            bytes++;
	        } else if(isEtc(ch)) {
	            bytes++;
	        } else {
	            bytes += 2;
	          
	            if(isNe) {
	                i++;
	            }
	        }
	    }
	    
	    return bytes;
	}


	// 폼 필드 클리어

	function formClear(form)
	{
		form.reset();
	}



	// TEXT => HTML
	function encodeHTMLSpecialChar(encodeStr) {
		regexp1 = /</gi;  // < => &lt;
		regexp2 = /\n/gi; // enter => <BR> 
		regexp3 = /\s/gi; // blank =>  &nbsp; 
        encodeStr = encodeStr.replace(regexp1, "&lt;");
        encodeStr = encodeStr.replace(regexp2, "<br>");
        encodeStr = encodeStr.replace(regexp3, "&nbsp;");
		return encodeStr;
	}

	//체크박스 전체 선택 / 해제

	function checkAll(obj1, obj2){ 
		if( obj2 != null ){
			if (obj2.length > 1 ){			
				for (i=0;i<obj2.length;i++) {
					obj2[i].checked = obj1.checked;
				}
			} else {
				obj2.checked = obj1.checked;
			}
		}
	} 

	//체크박스 전체 선택 

	function checkTrueAll(obj){ 
		if( obj != null ){
			if (obj.length > 1 ){			
				for (i=0;i<obj.length;i++) {
					obj[i].checked = true;
				}
			} else {
				obj.checked = true;
			}
		}
	} 


	//체크박스 선택 체크

	function checkBoxChecked(obj){ 
		var checked = false;
		if( obj != null ){
			if (obj.length > 1 ){			
				for (i=0;i<obj.length;i++) {
					if( obj[i].checked == true ){
						checked = true;
						break;
					}
				}
			} else {
				checked = obj.checked;
			}
		}

		return checked;
	} 

	//체크박스 선택 체크

	function checkBoxCheckedValue(obj, splitChar){ 
		var checked = "";
		if( obj != null ){
			if (obj.length > 1 ){
				for (i=0;i<obj.length;i++) {
					if( obj[i].checked == true ){
						if( checked != "" ) checked = checked + splitChar;
						checked = checked + obj[i].value;
					}
				}
			} else {
				checked = obj.value;
			}
		}

		return checked;
	}


	// 파일의 확장자

	function getFileExtension( filePath ){
		var lastIndex = -1;
		lastIndex = filePath.lastIndexOf('.');
		var extension = "";

		if ( lastIndex != -1 ) {
			extension = filePath.substring( lastIndex+1, filePath.len );
		} 
		return extension;
	}


	// 파일을 선택 후 포커스 이동시 호출

	function uploadImg_Check( value ){
		var src = getFileExtension(value);
		if (src == "") {
			alert("not File");
			return;
		} else if ( !((src.toLowerCase() == "gif") || (src.toLowerCase() == "jpg") || (src.toLowerCase() == "jpeg")) ) {
			alert('gif 와 jpg 파일만 지원합니다.');
			return;
		}
		LoadImg( value);
	}


	// 이미지 로드하기

	function LoadImg(value)	{
		var imgInfo = new Image();
		imgInfo.onload = img_Load;
		imgInfo.src = value;
	}

	function img_Load()	{
		var imgSrc, imgWidth, imgHeight, imgFileSize;

		// 파일 사이즈 체크 Byte 단위( 1Kb=1024Byte ) 1메가까지 가능

		var maxFileSize = 1024000; 
		imgSrc = this.src;
		imgWidth = this.width;
		imgHeight = this.height;
		imgFileSize = this.fileSize;

		if (imgSrc == "" || imgWidth <= 0 || imgHeight <= 0){
			alert('그림파일을 가져올 수 없습니다.');
			return;
		} 

		if (imgFileSize > maxFileSize){
			alert('선택하신 그림 파일은 허용 최대크기인 ' + parseInt(maxFileSize/1024) + ' KB 를 초과하였습니다.');
			return;
		} 
	}

	function uploadFile_Check( value ){
		var src = getFileExtension(value);
		if (src == "") {
			alert("not File");
			return false;
		} else if ( src.toLowerCase() == "exe" || src.toLowerCase() == "com" || src.toLowerCase() == "bat" || src.toLowerCase() == "dll" ) {
			alert("실행파일은 업로드 하실 수 없습니다.");
			return false;
		}
		LoadFile(value);
		return true;
	}

	// 이미지를 제외한 파일 체크

	function LoadFile(value)	{
		var fileInfo = new Image();
		fileInfo.onload = file_Load;
		fileInfo.src = value;
	}


	function file_Load()	{
		var fileSrc, fileFileSize;

		// 파일 사이즈 체크 Byte 단위( 1Kb=1024Byte ) 1메가까지 가능

		var maxFileSize = 1024000; 
		fileSrc = this.src;		
		fileFileSize = this.fileSize;

		if (fileSrc == ""){
			alert('파일을 가져올 수 없습니다.');
			return;
		} 

		if (fileFileSize > maxFileSize){
			alert('선택하신 파일은 허용 최대크기인 ' + parseInt(maxFileSize/1024) + ' KB 를 초과하였습니다.');
			return;
		} 
	}

	 
	function replaceHTML(strText){
		
		var rep1 = new RegExp("&lt;"  ,"g");
		var rep2 = new RegExp("&gt;"  ,"g");
		var rep4 = new RegExp("&quot;" ,"g");
		var rep3 = new RegExp("&#034;","g");
		var rep5 = new RegExp("&amp;" ,"g");
		
	
		strText = strText.replace(rep1,"<");
		strText = strText.replace(rep2,">");
		strText = strText.replace(rep3,"\"");
		strText = strText.replace(rep4,"\"");
		strText = strText.replace(rep5,"&");

		return strText;
	}










	function checkform(formField, checkName, message, maxlength, minlength) {	
	

	if(checkName!='radio' )
		formValue = formField.value.ltrim().rtrim();

		if(checkName != 'jumin'){
			if (formField == null ) {
				return false;
			}
			if(checkName!='selbox' && checkName!='radio' ){
				if (formValue == '' && minlength > 0){
					alert(message + " 필수입력 항목입니다.");
					_cmdfocus(formField);
					return false;
				}
			
				if ( formValue.strLen() < minlength) {
					alert(message + " 최소 " + minlength + "자이상 입력하세요.");
					_cmdfocus(formField);
					return false;
				}

				if (formValue.strLen() > maxlength) {
					alert(message + " 최대 " + maxlength + "자까지 입력 가능합니다.");
					_cmdfocus(formField);
					return false;
				}

			}
		}		

		switch(checkName) {
			case "" :
				return true;
			case "alpha" :
				if (formValue.isalpha()) {
					return true;
				} else {
					alert(message + " 영문자만 입력 가능 합니다.");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "number" :

				if (formValue.isnumber()) {
					return true;
				} else {
					alert(message + " 숫자만 입력 가능 합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "decimal" :
				if (formValue.isdecimal()) {
					return true;
				} else {
					alert(message + " 숫자와 소숫점(.)만 입력 가능 합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "id" :
				if (formValue.isid()) {
					return true;
				} else {
					alert(message + " 영문자와 숫자만 입력 가능 합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			
			case "tel" :
				if (formValue.istel()) {
					return true;
				} else {
					alert(message + " 숫자와 - 만 입력 가능합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "email" :
				if (formValue.isemail()) {
					return true;
				} else {
					alert(message + " 이메일 형식이 틀립니다. 다시 입력해 주세요(형식: account@localhost.com");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "selbox" :
				var checkSel =false;
				for( var i=1; i<formField.options.length; i++) {
					if(formField.options[i].selected){
						checkSel =true;
						break;
					}
				}
				if (checkSel) {
					return true;
				} else {
					alert(message + " 선택해 주세요");
						return false;
				}
				
				break;
			case "radio" :
				var checkSel =false;
				for( var i=0; i<formField.length; i++) {
					if(formField[i].checked){
						checkSel =true;
						break;
					}
				}
				if (checkSel) {
					return true;
				} else {
					alert(message + " 선택해 주세요");
						return false;
				}
				
				break;
			case "date" :
				if (formValue.isdate()) {
					return true;
				} else {
					alert(message + " 날짜 형식이 틀립니다. 다시 입력해 주세요(형식: 1999.09.09)");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "jumin" :
				if(formValue.strLen() != 13){
					alert("주민등록번호를 정확히 입력해주세요");
					//_cmdfocus(formField);		
					return false
				}

				if (formValue.isjumin()) {
					return true;
				} else {
					alert("주민등록번호를 정확히 입력해주세요");
					//_cmdfocus(formField);		
					return false;
				}
				break;

			case "biznum" :
				if(formValue.strLen() != 10){
					alert("사업자등록번호를  정확히 입력해주세요");
					_cmdfocus(formField);		
					return false
				}

				if (checkBizNum(formValue)) {
					return true;
				} else {
					alert("사업자등록번호를 정확히 입력해주세요");
					_cmdfocus(formField);		
					return false;
				}
				break;
			
		}
	}
	

