function validate_required(field,alerttxt){
	with (field){
		if (value==null||value==""){	alert(alerttxt);	return false}
		else {return true}
	}
}

function chk_idcard(field){
	var txt_field = field.value
	if (txt_field.length == 0 || txt_field == null){
		return true;
	}else{
		if(txt_field.length != 13){
			alert("ID Card ("+txt_field+") Is Wrong ! (ไม่ถูกต้อง!)");
			field.focus();
			return false;
		}
	}
}

function chk_username(field){
	var txt_field = field.value
	if (txt_field.length == 0 || txt_field == null){
		return true;
	}else{
		url="http://"+jweb+"/_include/chkusername.asp?usn="+txt_field;
		var txtajax = ajax(url,'','');
		with (field){
			if (txtajax == "yes"){
				alert("User Name ("+txt_username+") Already Exist (มีผู้ใช้แล้ว!)");
				field.focus();
				return false;
			}
			else {return true;}
		}
	}
}

function chk_email(field){
	var txt_field = field.value
	if (txt_field.length == 0 || txt_field == null){
		return true;
	}else {
		with (field){
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(txt_field)){
				alert("Dishonestly E-mail (อีเมล์ ไม่ถูกต้อง)!");
				field.focus();
				return false;
			}else {
				url="http://"+jweb+"/_include/checkemail.asp"
				pac="email="+txt_field;
				var txtajax = ajax(url,'GET',pac);
				if(txtajax=="yes"){
					alert(txt_field+" , this e-mail has already used , (อีเมล์ นี้มีผู้ใช้แล้ว)!");
					field.focus();
					return false;
				}else{
					return true;
				}
			}
		}
	}
}

function chk_text(field,alerttxt){
	with (field){
		if (field.value != field2.value){	alert(alerttxt);	return false}
		else {return true}
	}
}

function chk_wordpic(field){
	var txt_field = field.value
	if (txt_field.length == 0 || txt_field == null){
		return true
	}else{
		url="http://"+jweb+"/_include/chkwordpic.asp?a=a";
		var txt_wordpic = ajax(url,'','');
		with (field){
			if (field.value != txt_wordpic){
				alert("The Code Is Wrong ! (อักษรภาพ ไม่ถูกต้อง)");
				field.value="";
				field.focus();
				chg_wordpic();
				return false;
			}else {return true;}
		}
	}
}

function chg_wordpic(){
	var txtmsg="divTextPic";
	var objmsg=document.getElementById? document.getElementById(txtmsg):document.all.txtmsg;
	url="http://"+jweb+"/_include/textpic.asp";
	objmsg.innerHTML=ajax(url,'','');
}

function chk_equal(field1,field2){
	with (field1,field2){
		if (field1.value != field2.value){	alert("Password ไม่ตรงกับ Re-Password!");
			field1.focus();
			return false
		}
		else {return true}
	}
}

function chk_equal2(jthis){
	var txtmsg1="passwordNew1";
	var objmsg1=document.getElementById? document.getElementById(txtmsg1):document.all.txtmsg1;
	if(jthis.length != 0){
		if (objmsg1.value != jthis){
			alert("Password ไม่ตรงกับ Re-Password!");
			objmsg1.focus();
			return false
		}
		else {return true}
	}
}

function chk_thai(field){
	with (field){
		field_input = field.value;
        j = field_input.length - 1;
        for (i = 0; i <= j; i++) {
            k = field_input.substr(i,1);
			if (k > "}") {
                alert("กรุณาใช้อักษร English เท่านั้น!");
				field.focus();
				return false
			}
			else {return true}
		}
	}
}

function validate_form(thisform){
	with (thisform){
		if (validate_required(email,"please specify E-mail (กรุณาระบุ อีเมล์) !")==false){email.focus();return false}
		if (validate_required(password,"please specify Password (กรุณาระบุ รหัสผ่าน) !")==false){password.focus();return false}
		if (validate_required(password2,"please specify Password (กรุณาระบุ รหัสผ่าน) !")==false){password2.focus();return false}
		if (validate_required(firstname,"please specify First Name (กรุณาระบุ ชื่อ) !")==false){firstname.focus();return false}
		if (validate_required(lastname,"please specify Last Name (กรุณาระบุ นามสกุล) !")==false){lastname.focus();return false}
		//if (validate_required(add,"please specify Contact Addess (กรุณาระบุ ที่อยู่ที่ติดต่อได้) !")==false){add.focus();return false}
		//if (validate_required(country,"please specify Country (กรุณาระบุ ประเทศ) !")==false){country.focus();return false}
		//if (validate_required(province,"please specify Province (กรุณาระบุ จังหวัด) !")==false){province.focus();return false}
		//if (validate_required(zip,"please specify ZIP (กรุณาระบุ รหัสไปรษณีย์) !")==false){zip.focus();return false}
		//if (validate_required(tel1,"please specify Phone Number 1 (กรุณาระบุ เบอร์โทรศัพท์ 1) !")==false){tel1.focus();return false}
		//if (validate_required(tel2,"please specify Phone Number 2 (กรุณาระบุ เบอร์โทรศัพท์ 2) !")==false){tel2.focus();return false}
		//if (validate_required(birthday,"please specify Birthday (กรุณาระบุ วัดเกิด) !")==false){birthday.focus();return false}
		//if (validate_required(idcard,"please specify ID Crad (กรุณาระบุ เลขที่บัตรประจำตัวประชาชน) !")==false){idcard.focus();return false}
		if (validate_required(wordpic,"please specify Verify Code (กรุณาระบุ อักษรภาพ ที่ท่านอ่านได้ในช่อง) !")==false){wordpic.focus();return false}
		if (chk_equal(password,password2)==false){password2.focus();return false}
		if (chk_wordpic(wordpic)==false){return false}
	}
}