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;
   }

   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("住民登録番号の頭の部分は６桁です。");
	    regNo1.focus();
	    return false;
   }

   if (regNo2.value.blank()) {
      alert("住民登録番号の後ろの部分を入力してください。");
	    regNo2.focus();
	    return false;
   }

   if (regNo2.value.length < 7) {
      alert("住民登録番号の後ろは７桁です。");
	    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を入力してください。");
	    id.focus();
	    return false;
   }

   if (id.value.length < 4) {
      alert("IDは４－１４文字です。");
	    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("パスワードは６－１４文字です。");
	    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 + "電話番号の後ろの部分は４桁です。");
      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("詳細を見るのUTLを入力してください。");
      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) {
   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;

   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;
}


