<!--

/*-----------------------------------------------------------------------------------------------
Ajax Upload
--------------------------------------------------------------------------------------------------*/
$(document).ready(function(){
var button = $('#upload_button'), interval;
	new AjaxUpload(button,{
		action: '/th/lib_common/ajax_upload_member.php', 
		name: 'Photo',
		onSubmit : function(file, ext){
			$('#upload_button').html("<div class=\"Loading\">Loading...</div>");
			$('#showPhoto').html("<div class=\"Loading\">Loading...</div>");
			this.disable();
		},
		onComplete: function(file, response){
			$('#upload_button').html("<img src=\"/images/register/b-add-photo.jpg\" width=\"90\" height=\"20\" />");
			if(response){
				random_no_cache =  Math.random();
				$("#showPhoto").html("<img src=\"/content/temp_upload/"+response+"?k="+random_no_cache+"\" width=\"119\" height=\"118\" hspace=\"0\" vspace=\"0\" >");
				$("#Photo").val(response);
			}
			window.clearInterval(interval);
			this.enable();
		}
	});
	

/*-----------------------------------------------------------------------------------------------
Auto Tab
--------------------------------------------------------------------------------------------------*/
// - Id Card
	$('#IdCard1').autotab({ target: $('#IdCard2'), format: 'numeric' });
	$('#IdCard2').autotab({ target: $('#IdCard3'), format: 'numeric', previous: $('#IdCard1') });
	$('#IdCard3').autotab({ target: $('#IdCard4'), format: 'numeric', previous: $('#IdCard2') });
	$('#IdCard4').autotab({ target: $('#IdCard5'), format: 'numeric', previous: $('#IdCard3') });
	$('#IdCard5').autotab({ target: $('#IdCard6'), format: 'numeric', previous: $('#IdCard4') });
	$('#IdCard6').autotab({ target: $('#IdCard7'), format: 'numeric', previous: $('#IdCard5') });
	$('#IdCard7').autotab({ target: $('#IdCard8'), format: 'numeric', previous: $('#IdCard6') });
	$('#IdCard8').autotab({ target: $('#IdCard9'), format: 'numeric', previous: $('#IdCard7') });
	$('#IdCard9').autotab({ target: $('#IdCard10'), format: 'numeric', previous: $('#IdCard8') });
	$('#IdCard10').autotab({ target: $('#IdCard11'), format: 'numeric', previous: $('#IdCard9') });
	$('#IdCard11').autotab({ target: $('#IdCard12'), format: 'numeric', previous: $('#IdCard10') });
	$('#IdCard12').autotab({ target: $('#IdCard13'), format: 'numeric', previous: $('#IdCard11') });
	$('#IdCard13').autotab({ previous: $('#IdCard12'),format: 'numeric'});
	
		// - Exclusive Id
	$('#ExclusiveId1').autotab({ target: $('#ExclusiveId2'), format: 'numeric' });
	$('#ExclusiveId2').autotab({ target: $('#ExclusiveId3'), format: 'numeric', previous: $('#ExclusiveId1') });
	$('#ExclusiveId3').autotab({ target: $('#ExclusiveId4'), format: 'numeric', previous: $('#ExclusiveId2') });
	$('#ExclusiveId4').autotab({ target: $('#ExclusiveId5'), format: 'numeric', previous: $('#ExclusiveId3') });
	$('#ExclusiveId5').autotab({ target: $('#ExclusiveId6'), format: 'numeric', previous: $('#ExclusiveId4') });
	$('#ExclusiveId6').autotab({ target: $('#ExclusiveId7'), format: 'numeric', previous: $('#ExclusiveId5') });
	$('#ExclusiveId7').autotab({ target: $('#ExclusiveId8'), format: 'numeric', previous: $('#ExclusiveId6') });
	$('#ExclusiveId8').autotab({ target: $('#ExclusiveId9'), format: 'numeric', previous: $('#ExclusiveId7') });
	$('#ExclusiveId9').autotab({ previous: $('#ExclusiveId8'), format: 'numeric'});

});



/*-----------------------------------------------------------------------------------------------
Ajax get Product Combobox
--------------------------------------------------------------------------------------------------*/
function getProductId(CategoryId,ProductId) {
	$("#getProductDiv").html("<div class=\"Loading\">Loading...</div>");
	$.get("/th/lib_common/ajax_combobox_product.php", {"CategoryId":CategoryId,"ProductId":ProductId},function(data){$("#getProductDiv").html(data);});
}
function getProductId2(CategoryId,ProductId) {
	$("#getProductDiv2").html("<div class=\"Loading\">Loading...</div>");
	$.get("/th/lib_common/ajax_combobox_product2.php", {"CategoryId":CategoryId,"ProductId":ProductId},function(data){$("#getProductDiv2").html(data);});
}
function getProductId3(CategoryId,ProductId) {
	$("#getProductDiv3").html("<div class=\"Loading\">Loading...</div>");
	$.get("/th/lib_common/ajax_combobox_product3.php", {"CategoryId":CategoryId,"ProductId":ProductId},function(data){$("#getProductDiv3").html(data);});
}

/*-----------------------------------------------------------------------------------------------
Ajax check Username
--------------------------------------------------------------------------------------------------*/
function checkUsername() {
	$("#checkUsernameDiv").removeClass("txtComplete");
	$("#checkUsernameDiv").removeClass("txtFail");
	$("#checkUsernameDiv").html("<div class=\"Loading\">Wait...</div>");
	if($("#Username").val()==$("#Username2").val()){
		$("#checkUsernameDiv").html("<div class=\"Loading\">Loading...</div>");
		Username=$("#Username").val();
		$.get("/th/lib_common/ajax_check_username.php", {"Username":Username},function(data){
			if(data==0){
				$("#checkUsernameDiv").addClass("txtComplete");
				$("#checkUsernameDiv").html("Username นี้สามารถใช้งานได้ค่ะ");
			}else{
				$("#checkUsernameDiv").addClass("txtFail");
				$("#checkUsernameDiv").html("Username นี้มีสมาชิกท่านอื่นใช้ไปแล้วค่ะ");
			}
		});
	}
}


/*-----------------------------------------------------------------------------------------------
Ajax check Id Card
--------------------------------------------------------------------------------------------------*/
function checkIdCardDB() {//alert('a');
	$("#checkIdCardDiv").removeClass("txtComplete");
	$("#checkIdCardDiv").removeClass("txtFail");
	$("#checkIdCardDiv").html("<div class=\"Loading\">Wait...</div>");
	if($("#IdCard1").val() && $("#IdCard2").val() && $("#IdCard3").val() && $("#IdCard4").val() && $("#IdCard5").val() && $("#IdCard6").val() && $("#IdCard7").val() && $("#IdCard8").val() && $("#IdCard9").val() && $("#IdCard10").val() && $("#IdCard11").val() && $("#IdCard12").val() && $("#IdCard13").val()){
		$("#checkIdCardDiv").html("<div class=\"Loading\">Loading...</div>");
		IdCard=$("#IdCard1").val()+$("#IdCard2").val()+$("#IdCard3").val()+$("#IdCard4").val()+$("#IdCard5").val()+$("#IdCard6").val()+$("#IdCard7").val()+$("#IdCard8").val()+$("#IdCard9").val()+$("#IdCard10").val()+$("#IdCard11").val()+$("#IdCard12").val()+$("#IdCard13").val();
		if(checkIdCard(IdCard)){
			$.get("/th/lib_common/ajax_check_idcard.php", {"IdCard":IdCard},function(data2){
				if(data2==0){
					$("#checkIdCardDiv").addClass("txtComplete");
					$("#checkIdCardDiv").html("หมายเลขบัตรประชาชน นี้สามารถใช้งานได้ค่ะ");
				}else{
					$("#checkIdCardDiv").addClass("txtFail");
					$("#checkIdCardDiv").html("หมายเลขบัตรประชาชน นี้มีสมาชิกท่านอื่นใช้ไปแล้วค่ะ");
				}
			});
		}else{
			$("#checkIdCardDiv").addClass("txtFail");
			$("#checkIdCardDiv").html("กรอกหมายเลขบัตรประชาชนไม่ถูกต้องค่ะ");
		}
	}
}

/*-----------------------------------------------------------------------------------------------
Ajax check Email
--------------------------------------------------------------------------------------------------*/
function checkEmailDB() {
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	$("#checkEmailDiv").removeClass("txtComplete");
	$("#checkEmailDiv").removeClass("txtFail");
	$("#checkEmailDiv").html("<div class=\"Loading\">Wait...</div>");
	if(emailRE.test($("#Email").val())){
		$("#checkEmailDiv").html("<div class=\"Loading\">Loading...</div>");
		Email=$("#Email").val();
		$.get("/th/lib_common/ajax_check_email.php", {"Email":Email},function(data){
			if(data==0){
				$("#checkEmailDiv").addClass("txtComplete");
				$("#checkEmailDiv").html("Email นี้สามารถใช้งานได้ค่ะ");
			}else{
				$("#checkEmailDiv").addClass("txtFail");
				$("#checkEmailDiv").html("Email นี้มีสมาชิกท่านอื่นใช้ไปแล้วค่ะ");
			}
		});
	}
}

/*-----------------------------------------------------------------------------------------------
Validate Form
--------------------------------------------------------------------------------------------------*/

function addCssAlertInput(Id){
	$(Id+"Div").addClass("inputAlertDiv");
}
function clearCssInput(){
	$(".inputAlertDiv").removeClass("inputAlertDiv");
}

function VF_frmAdd(){ //v2.0
	var theForm = document.frmAdd;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var numRE = /^\d+$/;
	var errMsg = "";
	var setfocus = "";
	var strBullet="-";
	var cssMsg = "1px solid #BF2525";
	
	clearCssInput(); // Clear Css Input

	if (theForm['AcceptAgreement'].checked == false){
		errMsg="<li>  ท่านยังไม่ได้ยอมรับเงื่อนไข และกฎข้อบังคับของเว็บไซต์ค่ะ </li>"+errMsg;
		setfocus = "['AcceptAgreement']";
		addCssAlertInput(".AcceptAgreement");
	}
	if (theForm['captcha'].value == ""){
		errMsg="<li>  กรอกข้อความป้องกัน Spam ไม่ถูกต้อง โปรดลองอีกครั้งค่ะ </li>"+errMsg;
		setfocus = "['captcha']";
		addCssAlertInput(".captcha");
	}
	if (((theForm['ProductId'].value != "" && theForm['ProductId'].value != 0) && (theForm['ProductId2'].value != "" && theForm['ProductId2'].value != 0)) && (theForm['ProductId'].value == theForm['ProductId2'].value)) {
		errMsg="<li>  เลือกสินค้าซ้ำกันค่ะ </li>"+errMsg;
		setfocus = "['ProductId2']";
		addCssAlertInput(".ProductId2");
	}
	if (((theForm['ProductId'].value != "" && theForm['ProductId'].value != 0) && (theForm['ProductId3'].value != "" && theForm['ProductId3'].value != 0)) && (theForm['ProductId'].value == theForm['ProductId3'].value)) {
		errMsg="<li>  เลือกสินค้าซ้ำกันค่ะ </li>"+errMsg;
		setfocus = "['ProductId3']";
		addCssAlertInput(".ProductId3");
	}
	if (((theForm['ProductId2'].value != "" && theForm['ProductId2'].value != 0) && (theForm['ProductId3'].value != "" && theForm['ProductId3'].value != 0)) && (theForm['ProductId2'].value == theForm['ProductId3'].value)) {
		errMsg="<li>  เลือกสินค้าซ้ำกันค่ะ </li>"+errMsg;
		setfocus = "['ProductId3']";
		addCssAlertInput(".ProductId3");
	}	
	/*if (theForm['MobileTel'].value == "" || !numRE.test(theForm['MobileTel'].value) || theForm['MobileTel'].value.length <10){
		errMsg="<li>  กรุณาระบุมือถือของคุณค่ะ </li>"+errMsg;
		setfocus = "['MobileTel']";
		addCssAlertInput(".MobileTel");
	}
	if (theForm['HomeTel'].value == "" || !numRE.test(theForm['HomeTel'].value)){
		errMsg="<li>  กรุณาระบุเบอร์โทรศัพท์ของคุณค่ะ </li>"+errMsg;
		setfocus = "['HomeTel']";
		addCssAlertInput(".HomeTel");
	}*/
	if (theForm['Province'].value == ""){
		errMsg="<li>  กรุณาระบุจังหวัดของคุณค่ะ </li>"+errMsg;
		setfocus = "['Province']";
		addCssAlertInput(".Province");
	}
	if (theForm['Email'].value == "" || !emailRE.test(theForm['Email'].value)){
		errMsg="<li>  กรุณาระบุ Email ของคุณค่ะ </li>"+errMsg;
		setfocus = "['Email']";
		addCssAlertInput(".Email");
	}
	
	for (i=0;i<theForm.Gender.length;i++){
		Gender_valid= theForm.Gender[i].checked;
		if (Gender_valid) {break;}
	}
	if(!Gender_valid){errMsg="<li>  กรุณาระบุเพศของคุณค่ะ </li>"+errMsg;setfocus=".Gender[0]";addCssAlertInput(".Gender");}
	
	if (theForm['Bd'].value == "" || theForm['Bm'].value == "" || theForm['By'].value == ""){
		errMsg="<li>  กรุณาระบุวันเดือนปีเกิดของคุณค่ะ </li>"+errMsg;
		setfocus = "['Bd']";
		addCssAlertInput(".BirthDay");
	}
	if (theForm['IdCard1'].value == "" || theForm['IdCard2'].value == "" || theForm['IdCard3'].value == "" || theForm['IdCard4'].value == "" || theForm['IdCard5'].value == "" || theForm['IdCard6'].value == "" || theForm['IdCard7'].value == "" || theForm['IdCard8'].value == "" || theForm['IdCard9'].value == "" || theForm['IdCard11'].value == "" || theForm['IdCard12'].value == "" || theForm['IdCard13'].value == ""){
		errMsg="<li>  กรุณาระบุหมายเลขบัตรประชาชนของคุณให้ถูกต้องค่ะ </li>"+errMsg;
		setfocus = "['IdCard1']";
		addCssAlertInput(".IdCard");
	}
	if (theForm['Password'].value != theForm['Password2'].value){
		errMsg="<li>  ยืนยัน Password ไม่ถูกต้องค่ะ </li>"+errMsg;
		setfocus = "['Password2']";
		addCssAlertInput(".Password2");
	}
	if (theForm['Password'].value == ""){
		errMsg="<li>  กรุณาระบุ Password ของคุณค่ะ </li>"+errMsg;
		setfocus = "['Password']";
		addCssAlertInput(".Password");addCssAlertInput(".Password2");
	}
	if (theForm['Username'].value != theForm['Username2'].value){
		errMsg="<li>  ยืนยัน Username ไม่ถูกต้องค่ะ </li>"+errMsg;
		setfocus = "['Username2']";
		addCssAlertInput(".Username2");
	}
	if (theForm['Username'].value == ""){
		errMsg="<li>  กรุณาระบุ Username ของคุณค่ะ </li>"+errMsg;
		setfocus = "['Username']";
		addCssAlertInput(".Username");addCssAlertInput(".Username2");
	}
	if (theForm['Lname'].value == ""){
		errMsg="<li>  กรุณาระบุนามสกุลของคุณค่ะ </li>"+errMsg;
		setfocus = "['Lname']";
		addCssAlertInput(".Lname");
	}
	if (theForm['Fname'].value == ""){
		errMsg="<li> กรุณาระบุชื่อของคุณค่ะ </li>"+errMsg;
		setfocus = "['Fname']";
		addCssAlertInput(".Fname");
	}
	if (theForm['Prefix'].value == ""){
		errMsg="<li>  กรุณาระบุคำนำหน้าชื่อของคุณค่ะ </li>"+errMsg;
		setfocus = "['Prefix']";
		addCssAlertInput(".Prefix");
	}
	//theForm.submit();
	if (errMsg != ""){
		$("#msgAlert").html("");
		$("#msgAlert2").html("");
		$("#msgAlert").html("<ul>"+errMsg+"</ul>");
		eval("theForm" + setfocus + ".focus()");
	}else{ 
		theForm.submit();
	}
}
//-->