//주민번호체크
function isSSNNo(str){
	var idtot = 0;
	var idadd = "234567892345";
		
	for (var i=0; i<12; i++) {
		idtot = idtot+parseInt(str.substring(i,i+1))*parseInt(idadd.substring(i,i+1));
	}
	idtot=11-(idtot%11);
	if (idtot==10) {
		idtot=0;
	} else if(idtot==11) {
		idtot=1;
	}
	if (parseInt(str.substring(12,13))!=idtot) 
		return false;
	return true;
}
//외국인번호체크
function isSSNNo_f(str) {
        var sum=0;
        var odd=0;
        buf = new Array(13);

        for(i=0; i<13; i++) { buf[i]=parseInt(str.charAt(i)); }
        odd = buf[7]*10 + buf[8];
        if(odd%2 != 0) { return false; }
        if( (buf[11]!=6) && (buf[11]!=7) && (buf[11]!=8) && (buf[11]!=9) ) {
                return false;
        }

        multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];

        for(i=0, sum=0; i<12; i++) { sum += (buf[i] *= multipliers[i]); }
        sum = 11 - (sum%11);
        if(sum >= 10) { sum -= 10; }
        sum += 2;
        if(sum >= 10) { sum -= 10; }
        if(sum != buf[12]) { return false }
        return true;
}

//이메일 직접입력 --
function setMailServer(selObj,txtObj) {
	if(selObj.selectedIndex == 0) {
		txtObj.value = "";
		txtObj.readOnly = true;
		txtObj.focus();
	}
	else if(selObj.selectedIndex == selObj.length - 1) {
		txtObj.value = "";
		txtObj.readOnly = false;
		txtObj.focus();
	}
	else {
		txtObj.value = selObj.options[selObj.selectedIndex].text;
		txtObj.readOnly = true;
	}
}

var emailServer = new Array('hammir.com','hanmail.net','naver.com','yahoo.co.kr','empal.com','paran.com','hotmail.com','nate.com','dreamwiz.com','chollian.net','unitel.co.kr','kebe.com','hitel.com','netian.com','weppy.com','freechal.com','orgio.com','gmail.com');

function init(val) {
	setEmailServer(document.mainForm.mailServerSel,val);		
}

function setEmailServer(selObj, selectedVal) {

	var selIdx = 0;
	for(var i = 0; i < emailServer.length; ++i) {
		selObj.options[i + 1] = new Option(emailServer[i],emailServer[i]);
		if(emailServer[i] == selectedVal) selIdx = i + 1;
	}
	selObj.options[i + 1] = new Option('직접입력','');

	if(selIdx > 0) selObj.selectedIndex = selIdx;
}

//이메일 직접입력 end--


//아이디중복pop
function popsForm(val) {
	if (document.getElementById("userID").value.length < 4 || document.getElementById("userID").value == "")
	{
		alert("아이디를 4자 이상 정확히 입력하세요.");
		document.getElementById("userID").focus();
	} else {
		document.getElementById("checkID").value = document.getElementById("userID").value;
		document.getElementById("checkKind").value =val;
		pops('','idPopup','375','150');
		document.subForm.submit();
	}
}

//단체명중복pop
function popsOrgNameForm(val) {
	if (document.getElementById("userExtendOrgName").value.length < 1 || document.getElementById("userExtendOrgName").value == "")
	{
		alert("단체명을 입력하세요.");
		document.getElementById("userExtendOrgName").focus();
	} else {
		document.getElementById("checkID").value = document.getElementById("userExtendOrgName").value;
		document.getElementById("checkKind").value =val;
		pops('','idPopup','375','150');
		document.subForm.submit();
	}
}


//중복검색 체크함수
function fn_init(val) {
	if(val == 1) {
		document.getElementById("checkIDYN").value ="";
	} else if(val ==4) {
		document.getElementById("checkOrgNameYN").value ="";
	}
}


//zipcode 처리
function getZipcode(val1, val2) {	
	document.getElementById("val1").value = val1;
	document.getElementById("val2").value = val2;
	pop('','zipPopup','400','300');
	document.thirdForm.submit();
}

//password 보안값받기
function passwordStrength(password) { 
	var desc = new Array(); 
	var descAlt = new Array();
		desc[0] = "/images/popup/txt_layer_pw_03.gif"; 
		desc[1] = "/images/popup/txt_layer_pw_03.gif"; 
		desc[2] = "/images/popup/txt_layer_pw_02.gif"; 
		desc[3] = "/images/popup/txt_layer_pw_02.gif"; 
		desc[4] = "/images/popup/txt_layer_pw_01.gif"; 
		desc[5] = "/images/popup/txt_layer_pw_01.gif"; 
		descAlt[0] = "낮음"; 
		descAlt[1] = "낮음"; 
		descAlt[2] = "적정"; 
		descAlt[3] = "적정"; 
		descAlt[4] = "높음"; 
		descAlt[5] = "높음"; 
	var score = 0; 
	//if password bigger than 6 give 1 point 
	if (password.length > 6 && pwdDuplication(password) > 0) score++; 
	//if password has both lower and uppercase characters give 1 point 
	if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++; 
	//if password has at least one number give 1 point 
	if (password.match(/\d+/)) score++; 
	//if password has at least one special caracther give 1 point 
	if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++; 
	//if password bigger than 12 give another 1 point
	if (password.length > 12) score++; 

	//if(password == (password.substring(0,1)){6}) alert("12");
	document.getElementById("layer_01").style.display = "block";
	document.getElementById("passwdImg1").src =desc[score]; 
	document.getElementById("passwdImg1").setAttribute("alt",descAlt[score]);
//	document.getElementById("passwordDescription").innerHTML = desc[score]; 
//	document.getElementById("passwordStrength").className = "strength" + score; 
}


//비밀번호 연속번호인가 체크
function pwdDuplication(password){
	var checkString = "";	//마지막 받기
	var pwdDuplication = "";
	checkString = password.substring(password.length-1, password.length);
	var regexp = eval('/' + checkString + '/gi');
	pwdDuplication	= password.replace(regexp,'');
	pwdDuplication  = pwdDuplication.length;
	return pwdDuplication;
}

//후원관련 우편물 description box받기
function getPostDesc(val) {
	var imgSrc = "";
	var imgAlt = "";
	var clsName = "";
	if(val ==1) {
		imgSrc	=	"/images/content/txt_layer_info_p.gif";
		imgAlt	=	"이메일 신청시 첫 우편물은 우편발송되며 기부금영수증 (월 후원금 5천원 이상일경우 발송가능) 아동결연 우편물은 우편발송됩니다.";
		clsName	=	"layer_02";
	} else if (val == 2){ 
		imgSrc	=	"/images/content/txt_layer_info_p_02.gif";
		imgAlt	=	"우편 신청은 발송비 질감을 위하여 월 후원금이 5천원 이상일 경우 발송가능합니다.";
		clsName	=	"layer_04";
	} else if (val == 3){ 
		imgSrc	=	"/images/content/txt_layer_info_p_05.gif";
		imgAlt	=	"이메일, 우편물 모두 수신거부 (기부금영수증 포함)";
		clsName	=	"layer_05";
	}
	document.getElementById("layer_02").className =clsName;
	document.getElementById("layer_02").style.display = "block";
	document.getElementById("postImg").src	= imgSrc;
	document.getElementById("postImg").setAttribute("alt",imgAlt);
}

//layer hidden처리
function fn_hidden1() {
	//document.getElementById("layer_01").style.display = "none";
	document.getElementById("layer_02").style.display = "none";
}

function fn_hidden01() {
	document.getElementById("layer_01").style.display = "none";
}


//주소복사
function fn_copyURL(copyURL) {
	if(window.clipboardData) {
		window.clipboardData.setData('Text', copyURL);
		alert("주소복사되었습니다");
	}
}

//faq 용 tr hidden, show
function fn_show(id) {
	/*$(".faqContentsView").hide();
	$("#"+id).show();*/

	if($("#"+id).is(':hidden')){
		$(".faqContentsView").hide();
		$("#"+id).show();
	}
	else{
		$(".faqContentsView").hide();
	}
}
//faq 용 goListPage
/*
function bbsFAQGoPage( pn,val )
{
	alert(val);

	document.location = cBbsFilename+ "?bMode=list"    + "&bSearchItem="+cBSearchItem+"&bSearchText="+cBSearchText+ "&bPn="+(pn!=""?pn:cBPn)+"&faqViewType=<%=faqViewType%>&searchCategory="+searchCategory;
}
*/

//회원나눔 추천하기 미리보기
function fn_Preview() {
	if(validate(document.mainForm)) {
		//선택된 템플릿 별 페이지 호출
		var recomImg;
		for(var i =0; i< document.mainForm.recomImg.length; i++) {
			if(document.mainForm.recomImg[i].checked) {
				recomImg =document.mainForm.recomImg[i].value;
			}
		}
		pops('','recomPreview','680','800');
		document.mainForm.action="/popup/popup_recom_preview"+recomImg+".asp";
		document.mainForm.target="recomPreview";
		document.mainForm.submit();
	}
}

//회원나눔 추천하기 메일발송
function fn_SendMail() {
	if(validate(document.mainForm)) {	
		document.mainForm.action="proc_recom.asp";
		document.mainForm.target="";
		document.mainForm.submit();
	}
}


//회원나눔스토리 form 체크
function validateMemStroy(obj, bMode){

	with( obj ) {
		if(validate(obj)) {
			if (xed.getCurrentContent().stripTags().replace("&nbsp;", "").length == 0 && xed.getCurrentContent().indexOf("<img src") == -1){
				 alert("[내용]\n - 필수 입력 항목입니다.");
				 xed.focus();
				 return false;
			}

				method          = "POST";
				encoding        = "multipart/form-data";

				if(bMode == "modify") {
					returnURL.value = document.location.href;
					action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_MODIFY.asp";
				} else if(bMode == "write") {
					action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_INSERT.asp";
				}
		} else {
			return false;;
		}
	}
	document.getElementById("btn_write").style.display = "none";    
}


//회원나눔스토리 나도한마디 form 체크
function validateComment( obj )
{	
	if(validate(obj)) {
		alert("등록 되었습니다.");
		bbsCheckCommentForm(obj);
	} else {
		return false;;
	}
}

//비밀번호 popup띄우기
function deleteCommentPop(val,obj) {
	document.getElementById("bCUID").value = val;
	obj.action	 = "/popup/popup_delete.asp";
	obj.target	 = "deletePopup";
	pops('','deletePopup','360','200');
	obj.submit();
}

//나도 한마디비밀번호 form 체크
function validateCommentDelete(obj) {
	var uid = obj.contentsComment_UID.value;
	if(validate(obj)) {
		if ( uid != "" ) {
			//1.opener 에 비번 보내기
			opener.document.getElementById("bCPassword").value = document.getElementById("contentsComment_Password").value;
			//2.function 호출		
			opener.bbsGoDeleteCommentFront(opener.document.hiddenForm);
			self.close();
		}
		else {
			alert("잘못된 접근입니다.");
			self.close();
			return false;;
		}
	} else {
		return false;;
	}	
}

//나도 한마디 삭제
function bbsGoDeleteCommentFront(obj){
	if ( confirm("삭제하시겠습니까?") ) {
		with( obj ) {
			if(validate(obj)) { 
				obj.target	 = "";			
				obj.action   = "/_library_/moduleBoard/proc_gniSP_CONTENTS_COMMENT_DELETE_FRONT.asp";
				obj.submit();
			} else {
				return false;
			}
		}
	} else {
		return false;
	}
}


//로그인 베이스 나도 한마디 삭제
function bbsGoDeleteCommentLoginFront(val, obj){
	document.getElementById("bCUID").value = val;
	if ( confirm("해당 게시물을 삭제하시겠습니까?") ) {
		with( obj ) {
			if(validate(obj)) { 
				obj.target	 = "";			
				obj.action   = "/_library_/moduleBoard/proc_gniSP_CONTENTS_COMMENT_DELETE_FRONT.asp";
				obj.submit();
			} else {
				return false;
			}
		}
	} else {
		return false;
	}
}


// 이메일 유효성 체크
function checkEmail(str){
	var reg = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
	if (str.search(reg) != -1) {
		return true;
	}
	return false;
}

//해당 input clear
function clearText(obj, type) {
	if (type == "") 
	{
		obj.value = "";
	} else {
		if(document.getElementById(type).value == "") {
			obj.value = "";
		}
	}
}


//gnvol form 체크
function validateGnvolQna(obj, bMode) {
	document.getElementById("BoardArticle_ExtData2").value = document.getElementById("email1").value + "@" +  document.getElementById("email2").value;

	with( obj ) {
		if(validate(obj)) {
			
			method          = "POST";
			encoding        = "multipart/form-data";
			
			alert("문의가 접수되었습니다. \n감사합니다.");

			if(bMode == "modify") {
				returnURL.value = document.location.href;
				action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_MODIFY.asp";
			} else if(bMode == "write") {
				action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_INSERT.asp";
			}

		} else {
			return false;;
		}
	}
}


//check contents 에 값 넣기
function putChkContents(type) {
	document.getElementById(type).value = "1";
}


//해외봉사 기본form 체크
function validateGnvol(obj, bMode){
	with( obj ) {
		if(validate(obj)) {
			if (xed.getCurrentContent().stripTags().replace("&nbsp;", "").length == 0 && xed.getCurrentContent().indexOf("<img src") == -1){
				 alert("[내용]\n - 필수 입력 항목입니다.");
				 xed.focus();
				 return false;
			}

				method          = "POST";
				encoding        = "multipart/form-data";

				if(bMode == "modify") {
					returnURL.value = document.location.href;
					action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_MODIFY.asp";
				} else if(bMode == "write") {
					action          = "/_library_/moduleBoard/proc_gniSP_BOARD_ARTICLE_INSERT.asp";
				}
		} else {
			return false;;
		}
	}
}

//해외봉사 관심자 등록 form 체크
function validateSupport(obj) {
	document.getElementById("Supporter_Email").value = document.getElementById("email1").value + "@" +  document.getElementById("email2").value;

	with( obj ) {
		if($("#interest input[type=checkbox]:checked").length >0) {
			if(validate(obj)) {
				
				method          = "POST";
				
				action          = "proc_gnvol_info_registration.asp";

			} else {
				return false;;
			}
		}else {
			alert("관심분야를 하나이상 선택하세요");
			return false;
		}
	}
}

