function isValidAgree(agree) {
   if (!agree.checked) {
      alert("개인정보 취급방침에 동의하셔야 합니다.");
      agree.focus();
      return false;
   }

   return true;
}

function isValidName(name) {
   if (name.value.blank()) {
      alert("성명을 입력하세요.");
	    name.focus();
	    return false;
   }

   if (name.value == "손님"){
      alert("손님은 사용 할수 없는 성명입니다.");
	  name.value="";
      name.focus();
      return false;
   }

   var isKRName = /^[가-힣\s]+$/.test(name.value);
   var isENName = /^[A-Za-z\s.]+$/.test(name.value);
   var isJPName = /^[\u3040-\u30FF\u4E00-\u9FCF\s]+$/.test(name.value);

   if (isKRName || isJPName) {
      if (name.value.strip() != name.value.space()) {
         alert(((isKRName) ? "한글" : "한자") + "성명은 띄어쓰기 없이 입력하세요.");         
         name.focus();
         return false;
      }
   }
   else {
      if (!isENName) {
         alert("성명을 한글 또는 영문자, 한자로 입력하세요.");         
         name.focus();
         return false;
      }
   }

   if (name.value.space().length < 2){
      alert("성명은 2~20자입니다.");
      name.focus();
      return false;
   }

   return true;
}

function isValidKorRegNo(regNo1, regNo2) {   
   var regNo = (regNo1.value + regNo2.value).split("");
   var code  = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5];
   var sum   = 0; 
   
   for (i = 0; i <= 11; i++) {
      sum += regNo[i] * code[i];
   }

   if ((11 - sum % 11) % 10 != regNo[12]) {      
      return false;
   }

   return true;
}

function isValidForRegNo(regNo1, regNo2) {   
   var regNo = (regNo1.value + regNo2.value).split("");

   if (regNo[11] < 6 || (regNo[7] * 10 + regNo[8] * 1) % 2) {      
      return false;
   }

   var code = [2, 3, 4, 5, 6, 7, 8, 9, 2, 3, 4, 5];
   var sum  = 0;    

   for (i = 0; i <= 11; i++) {
      sum += regNo[i] * code[i];
   }

   sum = 11 - sum % 11;

   if (sum >= 10) {
      sum -= 10;
   }

   sum += 2;

   if (sum >= 10) {
      sum -= 10;
   }

   if (sum != regNo[12]) {      
      return false;
   }

   return true;
}

function isValidRegNo(regNo1, regNo2) {
   if (regNo1.value.blank()) {
      alert("주민등록번호의 앞자리를 입력하세요.");
      regNo1.focus();
      return false;
   }

   if (regNo1.value.length < 6) {
      alert("주민등록번호의 앞자리는 6자입니다.");
	    regNo1.focus();
	    return false;
   }

   if (regNo2.value.blank()) {
      alert("주민등록번호의 뒷자리를 입력하세요.");
	    regNo2.focus();
	    return false;
   }

   if (regNo2.value.length < 7) {
      alert("주민등록번호의 뒷자리는 7자입니다.");
	    regNo2.focus();
	    return false;
   }

   if (!(isValidKorRegNo(regNo1, regNo2) || isValidForRegNo(regNo1, regNo2))) {
      alert("유효한 주민등록번호가 아닙니다.");
	    regNo1.focus();
	    return false;
   }

   return true;
}

function isValidParent(parent) {
   if (!parent[0].checked && !parent[1].checked) {
      alert("학부모님 구분을 선택하세요.");
      return false;
   }

   return true;
}

function isValidID(id) {
   if (id.value.blank()) {
      alert("아이디를 입력하세요.");
	    id.focus();
	    return false;
   }

   if (id.value.length < 4) {
      alert("아이디는 4~14자입니다.");
	    id.focus();
	    return false;
   }

   return true;
}

function isValidPW(pw, msg) {
   if (!msg) {
      msg = "";
   }

   if (pw.value.blank()) {
      alert(msg + "비밀번호를 입력하세요.");
	    pw.focus();
	    return false;
   }

   if (pw.value.length < 6) {
      alert("비밀번호는 6~14자입니다.");
	    pw.focus();
	    return false;
   }

   return true;
}

function isValidPWConfirm(pw, pwConfirm) {  
   if (pwConfirm.value == "") {
      alert("비밀번호를 확인하세요.");
      pwConfirm.focus();
      return false;
   }

   if (pw.value != pwConfirm.value) {
      alert("비밀번호가 올바르게 확인되지 않았습니다.");
      pwConfirm.focus();
      return false;
   }

   return true;
}

function isValidPhone(phone2, phone3, msg) {
   if (phone2.value.blank()) {
      alert(msg + "전화번호의 가운데자리를 입력하세요.");
      phone2.focus();
      return false;
   }

   if (phone2.value.length < 3) {
      alert(msg + "전화번호의 가운데자리는 3~4자입니다.");
      phone2.focus();
      return false;
   }

   if (phone3.value.blank()) {
      alert(msg + "전화번호의 뒷자리를 입력하세요.");
      phone3.focus();
      return false;
   }

   if (phone3.value.length < 4) {
      alert(msg + "전화번호의 뒷자리는 4자입니다.");
      phone3.focus();
      return false;
   }

   return true;
}

function isValidAddress(address1, address2) {
   if (address1.value.blank()) {
      alert("우편번호 검색을 사용하여 주소를 입력하세요.");
      return false;
   }

   if (address2.value.blank()) {
      alert("상세주소를 입력하세요.");
	    address2.focus();
	    return false;
   }

   return true;
}

function isValidEmail(email) {
   if (email.value.blank()) {
      alert("이메일 주소를 입력하세요.");
      email.focus();
      return false;
   }

   var regExp = /^[_0-9a-zA-Z-]+(\.[_0-9a-zA-Z-]+)*@[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)+$/;

   if (!regExp.test(email.value)) {
      alert("유효한 이메일 주소가 아닙니다.");
      email.focus();
      return false;
   }

   return true;
}

function isValidSchool(school) {
   if (!school[0].checked && !school[1].checked) {
      alert("학교구분을 선택하세요.");
      return false;
   }

   return true;
}

function isValidTitle(title, msg) {
   if (!msg) {
      msg = "제목을";
   }

   if (title.value.blank()) {
      alert(msg + " 입력하세요.");
	    title.focus();
	    return false;
   }

   return true;
}

function isValidContent(content, msg) {
   if (content) {
      if (!msg) {
         msg = "";
      }

      if (content.value.blank()) {
         alert(msg + "내용을 입력하세요.");
		     content.focus();
		     return false;
	    }
   }
   else {
      var editor = FCKeditorAPI.GetInstance("content");
      var xhtml  = editor.GetXHTML(true);

      if (xhtml.blank()) {
         alert("내용을 입력하세요.");
	       editor.Focus();
         return false;		 
      }
   }

   return true;
}

function isValidComment(comment) {
   if (comment.value.blank()) {
      alert("댓글을 입력하세요.");
	    comment.focus();
	    return false;
   }

   return true;
}

function isValidReply(reply) {
   if (reply.value.blank()) {
      alert("답글을 입력하세요.");
	    reply.focus();
	    return false;
   }

   return true;
}

function isValidMovie(movie) {   
   if (movie.value.blank()) {
      alert("동영상을 업로드하세요.");	    
	    return false;
   }

   return true;
}

function isValidCateName(name) {
   if (name.value.blank()) {
      alert("분류이름을 입력하세요.");
	    name.focus();
	    return false;
   }

   if (name.value.search(/\\|:|\*|\?|\"|<|>|\|/) > -1) {
      alert("분류이름에 다음의 문자를 사용할 수 없습니다.\n\n             \\  :  *  ?  \"  <  >  |");
	    name.focus();
	    return false;
   }

   return true;
}

function isValidCateNo(no) {
   if (no.value == "-1") {
      alert("분류를 선택하세요.");
	    no.focus();
	    return false;
   }

   return true;
}

function isValidKeyword(keyword) {
   if (keyword.value.blank()) {
      alert("검색할 단어를 입력하세요.");
      keyword.focus();
      return false;
   }

   return true;
}

function isValidTime(time) {
   if (time.value.blank()) {
      alert("시간을 입력하세요.");
      time.focus();
      return false;
   }

   return true;
}

function isValidPlace(place) {
   if (place.value.blank()) {
      alert("장소를 입력하세요.");
      place.focus();
      return false;
   }

   return true;
}

function isValidMaximum(maximum, msg) {
   if (!msg) {
      msg = "수용";
   }

   if (maximum.value.blank()) {
      alert("최대" + msg + "인원을 입력하세요.");
      maximum.focus();
      return false;
   }

   if (maximum.value == 0) {
      alert("최대" + msg + "인원을 1명 이상 입력하세요.");
      maximum.focus();
      return false;
   }

   return true;
}

function isValidPersonnel(maximum, personnel) {
   if (personnel.value.blank()) {
      alert("1인 방문가능인원을 입력하세요.");
      personnel.focus();
      return false;
   }

   if (personnel.value == 0) {
      alert("1인 방문가능인원을 1명 이상 입력하세요.");
      personnel.focus();
      return false;
   }

   if (Number(personnel.value) > maximum.value) {
      alert("1인 방문가능인원을 최대수용인원 이하로 입력하세요.");
      personnel.focus();
      return false;
   }

   return true;
}

function isValidDeparture(departure) {
   for (i = 0; i < departure.length; i++) {
      if (!departure[i].value.blank()) {
         return true;
      }
   }

   alert("교통편을 입력하세요.");
   return false;
}

function isValidPercent1(primary, middle) {   
   if (primary.value.blank()) {
      alert("초등학교 비율을 입력하세요.");
      primary.focus();
      return false;
   }

   if (primary.value > 100) {
      alert("초등학교 비율을 100% 이하로 입력하세요.");
      primary.focus();
      return false;
   }

   if (middle.value.blank()) {
      alert("중학교 비율을 입력하세요.");
      middle.focus();
      return false;
   }

   if (middle.value > 100) {
      alert("중학교 비율을 100% 이하로 입력하세요.");
      middle.focus();
      return false;
   }

   if (Number(primary.value) + Number(middle.value) != 100) {
      alert("초등학교와 중학교 비율의 합이 100%가 아닙니다.");         
      return false;
   }

   return true;
}

function isValidPercent2(middle, high) {   
   if (middle.value.blank()) {
      alert("중학교 비율을 입력하세요.");
      middle.focus();
      return false;
   }

   if (middle.value > 100) {
      alert("중학교 비율을 100% 이하로 입력하세요.");
      middle.focus();
      return false;
   }

   if (high.value.blank()) {
      alert("고등학교 비율을 입력하세요.");
      high.focus();
      return false;
   }

   if (high.value > 100) {
      alert("고등학교 비율을 100% 이하로 입력하세요.");
      high.focus();
      return false;
   }

   if (Number(middle.value) + Number(high.value) != 100) {
      alert("중학교와 고등학교 비율의 합이 100%가 아닙니다.");         
      return false;
   }

   return true;
}

function isValidParticipate(school) {
   if (!school[0].checked && !school[1].checked) {
      alert("참여설명회를 선택하세요.");
      return false;
   }

   return true;
}

function isValidGrade(grade) {
   if (grade.value.blank()) {
      alert("회원등급을 선택하세요.");
      return false;
   }

   return true;
}

function isValidSize(width, height, msg) {
   if (width.value.blank()) {
      alert(msg + "의 가로크기를 입력하세요.");
      width.focus();
      return false;
   }

   if (height.value.blank()) {
      alert(msg + "의 세로크기를 입력하세요.");
      height.focus();
      return false;
   }

   return true;
}

function isValidPosition(left, top, msg) {
   if (left.value.blank()) {
      alert(msg + "의 가로위치를 입력하세요.");
      left.focus();
      return false;
   }

   if (top.value.blank()) {
      alert(msg + "의 세로위치를 입력하세요.");
      top.focus();
      return false;
   }

   return true;
}

function isValidDetailURL(detailURL) {
   if (detailURL.value.blank()) {
      alert("자세히 보기 URL을 입력하세요.");
      detailURL.focus();
      return false;
   }

   return true;
}

function isValidDate(year, msg) {
   if (!msg) {
      msg = "";
   }

   if (year.value.blank()) {
      alert("달력을 사용하여 " + msg + "날짜를 입력하세요.");	  
      return false;
   }

   return true;
}

function isValidGrdName(name) {
   if (name.value.blank()) {
      alert("이름을 입력하세요.");
      name.focus();
      return false;
   }

   return true;
}

function isValidDesc(desc) {
   if (desc.value.blank()) {
      alert("설명을 입력하세요.");
      desc.focus();
      return false;
   }

   return true;
}

function isValidAppDate(sYear, sMonth, sDay, sHour, sMinute, sSecond, cYear, cMonth, cDay, cHour, cMinute, cSecond, rYear, rMonth, rDay, rHour, rMinute, rSecond) {
   var sDate = sYear.value + "/" + ("0" + sMonth.value).right(2) + "/" + ("0" + sDay.value).right(2) + " " + sHour.value + ":" + sMinute.value + ":" + sSecond.value;
   var cDate = cYear.value + "/" + ("0" + cMonth.value).right(2) + "/" + ("0" + cDay.value).right(2) + " " + cHour.value + ":" + cMinute.value + ":" + cSecond.value;
   var rDate = rYear.value + "/" + ("0" + rMonth.value).right(2) + "/" + ("0" + rDay.value).right(2) + " " + rHour.value + ":" + rMinute.value + ":" + rSecond.value;

   if (sDate >= cDate) {
      alert("신청 시작날짜를 마감날짜 이전으로 입력하세요.");
      return false;
   }

   return true;
}

function isValidCourse(course, msg) {
   if (!msg) {
      msg = "입력";
   }

   if (course.value.blank()) {
      alert("코스를 " + msg + "하세요.");
      course.focus();
      return false;
   }

   return true;
}

function isValidRoute(route) {
   if (route.value.blank()) {
      alert("노선을 입력하세요.");
      route.focus();
      return false;
   }

   return true;
}

function isValidSchNum(schNum) {
   if (schNum.value.blank()) {
      alert("학번을 입력하세요.");
      schNum.focus();
      return false;
   }

   if (schNum.value.length < 4) {
      alert("학번은 4자리입니다.");
      schNum.focus();
      return false;
   }

   return true;
}

function isValidSchNum(schNum) {
   if (schNum[0].value.blank()) {
      alert("학교를 선택하세요.");
      schNum[0].focus();
      return false;
   }

   if (schNum[1].value.blank()) {
      alert("학년을 선택하세요.");
      schNum[1].focus();
      return false;
   }

   if (schNum[2].value.blank()) {
      alert("반을 선택하세요.");
      schNum[2].focus();
      return false;
   }

   if (schNum[3].value.blank()) {
      alert("번호를 입력하세요.");
      schNum[3].focus();
      return false;
   }

   return true;
}

function isValidWeekend(weekend) {
   if (!(weekend[0].checked || weekend[1].checked || weekend[2].checked)) {
      alert("주말구분을 선택하세요.");
      return false;
   }

   return true;
}

function isValidCP(cp) {
   if (!cp[0].checked && !cp[1].checked) {
      alert("청평하차 여부를 선택하세요.");
      return false;
   }

   return true;
}

function isValidMessage(message) {
   if (message.value.blank()) {
      alert("메세지를 입력하세요.");
      message.focus();
      return false;
   }

   return true;
}

function isValidType(type) {
   for (i = 0; i < type.length; i++) {
      if (type[i].checked) {
         return true;
      }
   }

   alert("그룹을 선택하세요.");
   return false;
}

function isValidReceive(receive) {
   if (!receive.length) {
      alert("수신자 휴대전화번호를 추가하세요.");
      receive.focus();
      return false;
   }

   return true;
}

function isValidSelect(category, msg) {
   if (!msg) {
      msg = "카테고리를";
   }

   if (category.value.blank()) {
      alert(msg + " 선택하세요.");
	    category.focus();
	    return false;
   }

   return true;
}

function isValidSchNo(schNum) {
   if (schNum.value.blank()) {
      alert("학번을 입력하세요.");
      schNum.focus();
      return false;
   }

   if (schNum.value.length < 5) {
      alert("학번은 5자리입니다.");
      schNum.focus();
      return false;
   }

   return true;
}


/* 알림서비스 관련 */
function isValidMailContent(content) {
   if (content.value.blank()) {
      alert("메일 내용을 입력하세요.");
      content.focus();
      return false;
   }

   return true;
}


function isValidMailService(receive) {
   if (!receive.length) {
      alert("메일 발송대상을 추가하세요.");
      receive.focus();
      return false;
   }

   return true;
}


