/**
* 라디오 하나도 선택안했을시 메시지 출력
* @ obj
* @return  라디오 박스가 하나라도 선택 되었을시 true
*/
function radioChk(obj) {
 var radiolength = obj.length; //라디오 버튼 개수를 알아냄
 if (!radiolength) radiolength=1; //라디오 버튼이 하나라면

 for (i=0; i<radiolength; i++) {
  if (obj[i].checked) break;
  if (radiolength==(i+1)) { //라디오 갯수만큼 루프를 다 돌때까지도 선택된 사항이 없다면
   alert(obj[i].title+"을(를) 선택해 주십시오.");
   obj[0].focus();
   return false;
  }
 }
 return true;
}

function radioChk2(obj, str) {
 var radiolength = obj.length; //라디오 버튼 개수를 알아냄
 if (!radiolength) radiolength=1; //라디오 버튼이 하나라면

 for (i=0; i<radiolength; i++) {
  if (obj[i].checked) break;
  if (radiolength==(i+1)) { //라디오 갯수만큼 루프를 다 돌때까지도 선택된 사항이 없다면
   alert(str+"을(를) 선택해 주십시오.");
   obj[0].focus();
   return false;
  }
 }
 return true;
}

//라디오값
function radioValue(obj) {
	var str;
	var radiolength = obj.length; 
	if (!radiolength) radiolength=1; 

	for (i=0; i<radiolength; i++) {
		if (obj[i].checked) {
			str = obj[i].value;
			break;
		}
	}
	return str;
}

// 첨부이미지사이즈체크
function FnImgSize(obj)
{
	var objImg = new Image();
	obj = eval(obj);
	objImg.src = obj.value;
	var nFileSize = objImg.fileSize;
	
	return nFileSize;
}

// 팝업창 가운데 위치에 띄우기
function NewWindow(mypage, myname, w, h, opt)  
{
	var winl = (screen.width - w) / 2; 
	var wint = (screen.height - h) / 2 - 100; // 정가운데보다 조금 위에
	if(opt=="") opt = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+opt;
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

// 팝업창 위치조정
function NewWindow2(mypage, myname, w, h, left, opt)  
{
	//var winl = (screen.width - w) / 2; 
	var winl = left; 
	var wint = (screen.height - h) / 2 - 100; // 정가운데보다 조금 위에
	if(opt=="") opt = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+opt;
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

/**
* '숫자'만 허용하기
* 입력값이 숫자가 아닐경우 입력문자를 취소하고 메시지를 출력함
* onKeyPress="fnChkNum()" --> 올바른 적용을 위해 다음이 필요 style="ime-mode:disabled"
*/
function fnChkNum() {
	if (!((event.keyCode>47)&(event.keyCode<58))) {
		event.returnValue=false;
		alert("숫자만 입력 가능 합니다.");
	}
	
}

// iFrame높이값 계산
function Resize_Frame(name) {
	if ( document.all(name) != null )	{
		var Frame_Body  = document.frames(name).document.body;
		var Frame_name  = document.all(name);

		Frame_name.style.height 
				= Frame_Body.scrollHeight + (Frame_Body.offsetHeight-Frame_Body.clientHeight);
	}
}

// 큰이미지 사이즈 제한 로딩
function imageSize(obj, max) {
  var width1 = obj.width;
  if(width1 > max){
    obj.width = max;
  }
}

// 세로제한 & 가로제한
function imageSize2(obj, w, h) {
  
	var width  = obj.width;
	var height = obj.height;
	var tmp;

	if ( height > h ) {
		tmp = width/(height / h);

		if( tmp > w ) {
			obj.width = w;
		} else {
			obj.width = tmp;
		}
	}
	else if( width > w) {
		obj.width = w;
	}
}

function imgSize3_wait(which,w,h){
	
	imgSize3(which,w,h);
}
// 세로제한 & 가로제한
function imgSize3(which,w,h){
	
    var obj = eval("document."+which);
    if(obj.complete == false){
    	
    	setTimeout("imgSize3_wait('"+which+"','"+w+"','"+h+"');",300);
    }else{
    	
		var width  = obj.width;
		var height = obj.height;
		var tmp;
	
		if ( height > h ) {
			tmp = width /(height / h);
	
			if( tmp > w ) {
				obj.width = w;
			} else {
				obj.width = tmp;
			}
		}
		else if( width > w) {
			obj.width = w;
		}
    }
}

/**
 * 달력 호출
 * textName : 텍스트폼 | formName : 폼네임
 */
function cal(textName,formName)
{
	theFeats =   "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
	NewWindow('/smoaM/comm/calendar.jsp?textName='+textName+'&formName='+formName, 'cal', '170', '210', theFeats);

	//window.open("/smoaM/comm/calendar.jsp?textName="+textName+"&formName="+formName,"","width=162 height=203 style='border:ridge'");
}

/**
 * 전시용 달력 호출
 * textName : 텍스트폼 | formName : 폼네임
 */
function calEx(textName,formName)
{
	theFeats =   "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
	NewWindow('/smoaM/comm/calendarN.jsp?textName='+textName+'&formName='+formName, 'cal', '170', '210', theFeats);

	//window.open("/smoaM/comm/calendar.jsp?textName="+textName+"&formName="+formName,"","width=162 height=203 style='border:ridge'");
} 
/**
 * 사용자단 생년월일 칼렌더
 */
function calFront(textName,formName)
{
	theFeats =   "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no";
	NewWindow('/smoaM/comm/calendarFront.jsp?textName='+textName+'&formName='+formName, 'cal', '170', '210', theFeats);

	//window.open("/smoaM/comm/calendar.jsp?textName="+textName+"&formName="+formName,"","width=162 height=203 style='border:ridge'");
} 

/**
* 우편번호찾기 팝업창 팝업
* @url			팝업 페이지
* @strObj1		우편번호 필드
* @strObj2		주소필드
* @strObj3		주소필드
* @w			팝업창 폭
* @h			팝업창 높이
*/
function popZip(url, strObj1, strObj2, strObj3, w, h) {
	url += "?obj1=" +strObj1 +"&obj2=" +strObj2 +"&obj3=" +strObj3;
	var attr = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, top=300, left=150, width="+w +", height="+h;
	var wnd = window.open(url, 'popZip', attr);
	wnd.focus();
}

function fnZip(zipObj1, zipObj2, addrObj, zipStr1, zipStr2, addrStr) {
	var zip1 = eval("opener."+zipObj1);
	var zip2 = eval("opener."+zipObj2);
	var addr1 = eval("opener."+addrObj);

	zip1.value = zipStr1;
	zip2.value = zipStr2;
	addr1.value = addrStr;

	self.close();
}

//셀렉크 선택시 이메일 자동입력 처리
function fnEmail(target_obj, event_obj) {
	var tmp = event_obj.value;
	if (tmp=="etc") {
		target_obj.readOnly = false;
		target_obj.value = "";
		target_obj.focus();
		return;
	}
	target_obj.readOnly = true; //readOnly는 대소문자 구분함
	target_obj.value = event_obj.value;
}
