﻿// 팝업창 중앙으로 위치 
function center(){ 
    var x,y; 
    if (self.innerHeight) { // IE 외 모든 브라우저 
        x = (screen.availWidth - self.innerWidth) / 2; 
        y = (screen.availHeight - self.innerHeight) / 2; 
    }else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict 모드 
        x = (screen.availWidth - document.documentElement.clientWidth) / 2; 
        y = (screen.availHeight - document.documentElement.clientHeight) / 2; 
    }else if (document.body) { // 다른 IE 브라우저( IE < 6) 
        x = (screen.availWidth - document.body.clientWidth) / 2; 
        y = (screen.availHeight - document.body.clientHeight) / 2; 
    } 
    window.moveTo(x,y); 
} 

//팝업
var winpop;

// 동영상팝업
function movpopup(mid)
{
    if(winpop) winpop.close(); 
    winpop = window.open("/common/MovPopup.aspx?mid="+mid+"&direct=1","mov","width=795,height=710,status=0");
    winpop.focus();
}

// 이미지팝업
function imgpopup(iid,jido)
{
    if(winpop) winpop.close(); 
    
    winpop = window.open("/common/ImgPopup2.aspx?iid="+iid+"&direct=1","img","width=600,height=500,fullscreen=yes,resizable=yes,status=yes");
    
    winpop.focus();
}
// 민속팁팝업
function folktippopup(fid,viewflag)
{
    if(winpop) winpop.close(); 
    winpop = window.open("/common/FolkTipPopup.aspx?fid="+fid+"&viewflag="+viewflag,"folktip","width=600,height=400,status=0");
    winpop.focus();
}

// 스크랩팝업
function scrappopup(id,datatype)
{
    if(winpop) winpop.close(); 
    winpop = window.open("/common/ScrapPopup.aspx?id="+id+"&datatype="+datatype,"scrap","width=340,height=230,status=0");
    winpop.focus();
}
// 로그인팝업
function Loginpopup()
{
    if(winpop) winpop.close(); 
    winpop = window.open("/common/Login.aspx","login","width=500,height=350,status=0");
    
    winpop.focus();
    
}
// 아이디패스워드 찾기 팝업
function fncIDSearch()
{
    if(winpop) winpop.close(); 
    winpop = window.open("/member/MemberIdPw.aspx","idsearch","width=450,height=330,status=0");
    winpop.focus();
 
}

// RSS시스템
function fncRssService()
{
    if(winpop) winpop.close(); 
    winpop = window.open("/common/RssService.aspx","rss","width=642,height=442,status=0,scrollbars=1");
    winpop.focus();
 
}



// 폼 검증 함수
	function checkForm(f) {
	var fLen = f.elements.length;
	var fObj; // 폼 요소
	var fTyp; // 폼 요소 Type
	var fVal; // 폼 요소 Value
	var fMsg; // 경고 메시지 속성
	var fNum; // 숫자만 입력 속성
	var fMax; // 최대 길이 지정
	var fMin; // 최소 길이 지정
	var fMxN; // 최대값 지정
	var fMnN; // 최소값 지정
	var fMal; // 메일 FORMAT

	for (i=0;i<fLen;i++) {
	fObj = f.elements[i];
	fTyp = toUpperCase(fObj.getAttribute("type"));
	//fVal = fObj.getAttribute("value");
	//fObj.setAttribute("value", fObj.getAttribute("value").replace(/ /gi,"").replace(/'\''/gi,"`"));
	fVal = fObj.getAttribute("value");
	fMsg = fObj.getAttribute("msg"); // 경고 메시지
	fNum = fObj.getAttribute("chknum"); // 숫자만 기입 가능하도록
	fMax = fObj.getAttribute("maxlen"); // 최대 입력글자수 제한
	fMin = fObj.getAttribute("minlen"); // 최소 입력글자수 제한
	fMxN = fObj.getAttribute("maxnum"); // 최대 숫자 제한
	fMnN = fObj.getAttribute("minnum"); // 최소 숫자 제한
	fMal = fObj.getAttribute("chkmail"); // 이메일 체크

	if (fMsg != null && (fTyp == "TEXT" || fTyp == "HIDDEN" || fTyp == "TEXTAREA" || fTyp == "PASSWORD") && fVal.replace(/ /gi,"") == "") {
	alert(fMsg + " 입력해 주세요");
	if (fTyp != "HIDDEN") {fObj.focus();}
	return false;
	}
	if (fMsg != null && (fTyp == "SELECT-ONE" || fTyp == "SELECT-MULTIPLE") && fVal =="") {
	alert(fMsg + " 선택해 주세요");
	fObj.focus(); return false;
	}
	if (fMsg != null && (fTyp == "RADIO" || fTyp == "CHECKBOX") && checkChecked(fObj) == false) {
	alert(fMsg + " 선택해 주세요");
	fObj.focus(); return false;
	}
	if (fNum != null && isNaN(fVal)) {
	alert("숫자로만 입력해 주세요");
	fObj.focus(); return false;
	}
	
	if (fMax != null && fMax < getLen(fVal)) {
	alert("입력된 글자수가 "+fMax+"자보다 작아야합니다.\n(영문 "+fMax+"자, 한글 "+Math.floor(fMax/2)+"자 까지 가능합니다.)");
	fObj.focus(); return false;
	}
	
	if (fMin != null && fMin > getLen(fVal)) {
	alert("입력된 글자수가 "+fMax+"자보다 커야합니다.");
	fObj.focus(); return false;
	}
	if (fMxN != null && parseInt(fMxN) < parseInt(fVal)) {
	alert("입력된 숫자는 "+fMxN+"보다 작아야합니다.");
	fObj.focus(); return false;
	}
	if (fMnN != null && parseInt(fMnN) > parseInt(fVal)) {
	alert("입력된 숫자는 "+fMnN+"보다 커야합니다.");
	fObj.focus(); return false;
	}
	if (fMal != null && checkEmail(fVal) == false && fVal != "") {
	alert("이메일 주소가 올바르지 않습니다");
	fObj.focus(); return false;
	}
	}
	return true;
	}
	
// 이메일 유효성 체크
	function checkEmail(str){
	var reg = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
	if (str.search(reg) != -1) {
	return true;
	}
	return false;
	}
	// 문자 길이 반환 (영문 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;
	}
	
	// 배열 요소일 경우 checked 된것이 있는지 확인
	function checkChecked(obj) {
	var fname = obj.form.name;
	var objnm = obj.name;
	var oElem = eval(fname+"."+objnm);
	var ret = false;

	if (typeof(oElem.length) == "undefined") {
	if (oElem.checked) {
	ret = true;
	}
	} else {
	for (var i=0;i<oElem.length;i++) {
	if (oElem[i].checked) {
	ret = true;
	}
	}
	}
	return ret;
	}
	
	// 대문자 변환 ex) toUpperCase(문자)
	function toUpperCase(str) {
	var ret;
	str != null ? ret = str.toUpperCase() : ret = "";
	return ret;
	} 


