/* Created by jankoatwarpspeed.com */ (function($) { $.fn.formToWizard = function(options) { options = $.extend({ submitButton: "" }, options); var element = this; var steps = $(element).find("fieldset"); var count = steps.size(); var submmitButtonName = "#" + options.submitButton; $(submmitButtonName).hide(); // 2 $(element).before("<ul id='steps'></ul>"); steps.each(function(i) { $(this).wrap("<div id='step" + i + "'></div>"); $(this).append("<p id='step" + i + "commands'></p>"); // 2 var name = $(this).find("legend").html(); $("#steps").append("<li id='stepDesc" + i + "'>ขั้นตอน " + (i + 1) + ": " + name + "</li>"); // $("#steps").append("<li id='stepDesc" + i + "'>" +name+ "<span>" + name + "</span></li>"); if (i == 0) { createNextButton(i); selectStep(i); } else if (i == count - 1) { $("#step" + i).hide(); createPrevButton(i); } else { $("#step" + i).hide(); createPrevButton(i); createNextButton(i); } }); function createPrevButton(i) { var stepName = "step" + i; $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Prev' class='prev'>< Back</a>"); $("#" + stepName + "Prev").bind("click", function(e) { $("#" + stepName).hide(); $("#step" + (i - 1)).show(); $(submmitButtonName).hide(); selectStep(i - 1); }); } function chkIDCard(strID,j) // ตรวจสอบว่า สตริิงที่ส่งมาเป็น ตัวเลขแล้วหรือยัง { var b = true; var iSumDigit = 0; var iCheckDigit = 0; var i = 0; for (i=0;i<j-1;i++){ if(i !=12) { iSumDigit += parseInt(strID.charAt(i),10) * (13 - i); } }//end for iCheckDigit = parseInt(strID.charAt(12),10); iSumDigit =(iSumDigit % 11); if(iSumDigit == 0) iSumDigit = 1; else if(iSumDigit ==1) iSumDigit = 0; else iSumDigit = (11- iSumDigit); if(iCheckDigit == iSumDigit) b=false; return(b); } function check_IDCard() { var b=false; if(document.getElementById("citizenid").value=="" ) { alert(" โปรดใส่เลขประจำตัวประชาชน"); document.getElementById("citizenid").focus(); b=true; } else if (document.getElementById("citizenid").value.length<13 ) { alert(" โปรดใส่เลขประจำตัวประชาชน ให้ครบ 13 ตัวอักษร"); document.getElementById("citizenid").focus(); b=true; } else if (chkIDCard(document.getElementById("citizenid").value,document.getElementById("citizenid").value.length)) { alert("เลขประจำตัวประชาชนไม่ถูกต้องครับ "); document.getElementById("citizenid").focus(); b=true; } return(b); } function chk_course(){ // ---------------------------------------------------------------- if(document.getElementById("project_id").value == ""){ alert("กรุณาเลือกหลักสุตร ที่สมัครเรียน"); document.getElementById("project_id").focus(); return false; }else if(document.getElementById("branch").value ==""){ alert("กรุณาเลือก สาขาวิชา"); document.getElementById("branch").focus(); return false; }else{ return true; } } function chk_personal(){ if(check_IDCard()){ }else if(document.getElementById("prename_thai").value == "") { alert(" กรุณาเลือก คำนำหน้านาม ด้วย"); document.getElementById("prename_thai").focus(); } else if(document.getElementById("firstnamethai").value == "") { alert(" กรุณาป้อน ชื่อภาษาไทย ด้วย"); document.getElementById("firstnamethai").focus(); } else if(document.getElementById("lastnamethai").value == "") { alert("กรุณาป้อน นามสกุลภาษาไทย ด้วย"); document.getElementById("lastnamethai").focus(); } else if(document.getElementById("prename_eng").value == "") { alert("กรุณาเลือก Title ด้วย "); document.getElementById("prename_eng").focus(); } else if(document.getElementById("firstnameeng").value == "") { alert("กรุณาป้อน First Name ด้วย"); document.getElementById("firstnameeng").focus(); } else if(document.getElementById("lastnameeng").value == "") { alert("กรุณาป้อน Last Name ด้วย"); document.getElementById("lastnameeng").focus(); } else if(document.getElementById("birthdaydd").value == "") { alert("กรุณาเลือก วันเกิด ด้วย"); document.getElementById("birthdaydd").focus(); } else if(document.getElementById("birthdaymm").value == "") { alert("กรุณาป้อน เดือนเกิด ด้วย"); document.getElementById("birthdaymm").focus(); } else if(document.getElementById("birthdayyyyy").value == "") { alert(" กรุณาป้อน ปีเกิด(พ.ศ.) ด้วย"); document.getElementById("birthdayyyyy").focus(); } else if(document.getElementById("birthdayprovinceno").value == "") { alert("กรุณาป้อน สถานที่เกิด(จังหวัด) ด้วย"); document.getElementById("birthdayprovinceno").focus(); } else if(document.getElementById("religion").value == "") { alert("กรุณาเลือก ศาสนา ด้วย"); document.getElementById("religion").focus(); } else if(document.getElementById("nation").value == "") { alert("กรุณาเลือก สัญชาติ ด้วย"); document.getElementById("nation").focus(); } else if(document.getElementById("race").value == "") { alert("กรุณาเลือก เชื้อชาติ ด้วย"); document.getElementById("race").focus(); } else if((document.getElementById("marr1").checked != true)&&(document.getElementById("marr2").checked != true)) { alert("กรุณาเลือก สถานภาพ ด้วย"); document.getElementById("marr1").focus(); }else{ return true; } } function chk_s0(){ return true; } function createNextButton(i) { var stepName = "step" + i; var f_chk = false; $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next' >Next ></a>"); $("#" + stepName + "Next").bind("click", function(e) { switch (i){ case 0 :f_chk = chk_course(); break; case 1 :f_chk = chk_personal(); break; case 2 :f_chk = chk_s0(); break; case 3 :f_chk = chk_s0(); break; default : alert ("Sorry, there are no flights to " + i + ".<BR>"); } if(f_chk){ $("#" + stepName).hide(); $("#step" + (i + 1)).show(); if (i + 2 == count) $(submmitButtonName).show(); selectStep(i + 1); } }); } function selectStep(i) { $("#steps li").removeClass("current"); $("#stepDesc" + i).addClass("current"); } } })(jQuery);