function login(){
	var	username	=document.form_login.username.value;
	var	password	=document.form_login.password.value;
	if(document.form_login.remember.checked == true){
		var remember			="Y";
	}else{
		var remember			="N";
	}


	var	url_load	="/member/login.php";

	var	errMsg		="";
	

	if (password ==""){
			errMsg = "กรุณาระบุ password";
			setfocus = "password";
	}

	if (username ==""){
			errMsg = "กรุณาระบุ username";
			setfocus = "username";
	}

	if (errMsg != ""){
		alert(errMsg);
		eval("document.form_login." + setfocus + ".focus()");
	}else{

		$("#loading_process").fadeIn(300);
		$.post(url_load, "username="+username+"&password="+password+"&remember="+remember+"&action=login", function(data){
				if (data =="OK")
				{
					//window.location.href="/index.php";
					window.location.reload();
				}else{
					document.form_login.username.value="";
					document.form_login.password.value="";
					$("#loading_process").fadeOut(600);
					alert("Login ผิดพลาดชื่อผู้ใช้หรือรหัสผ่านผิดพลาดกรุณาตรวจสอบอีกครั้ง");	
				}
		});

	}

}
function forgetpassword(){
	var	email	=document.form_forget_password.email.value;
	var	url_load	="/member/forgetpassword.php";

	var	errMsg		="";

	if (email ==""){
			errMsg = "กรุณาระบุ Email";
			setfocus = "email";
	}

	if (errMsg != ""){
		alert(errMsg);
		eval("document.form_forget_password." + setfocus + ".focus()");
	}else{

		$("#loading_process").fadeIn(300);
		$.post(url_load, "email="+email, function(data){
				if (data =="ERROR")
				{
					document.form_forget_password.email.value="";
					$("#loading_process").fadeOut(600);
					alert("ข้อมูล Email ผิดพลาดกรุณาตรวจสอบอีกครั้ง");	
				}else{
					$("#loading_process").fadeOut(600);
					$("#profile_login").html(data);
				}
		});

	}


}

function forgetpasswordform(){

	var	url_load	="/member/forgetpassword.php";

	$("#loading_process").fadeIn(300);

	$.get(url_load, "", function(data){
		$("#loading_process").fadeOut(600);
		$("#profile_login").html(data);
	});
}

function loginform(){
	var	url_load	="/member/login.php";

	$("#loading_process").fadeIn(300);

	$.get(url_load, "", function(data){
		$("#loading_process").fadeOut(600);
		$("#profile_login").html(data);
	});
}

function vote(id){
   var url_load    ="/award/vote.php";

               $("#div_vote"+id).html('<img src="/images/share/icon_loading.gif" width="16" height="16" hspace="2" vspace="2" align="absmiddle" />');
               $.get(url_load, "topic_id="+id, function(data){
                   if (data !="")
                   {
                       $("#div_vote"+id).hide();
                       $("#div_vote"+id).html(data);
                       $("#div_vote"+id).fadeIn(1000);
                   }
               });
}


function VF_form_login(){ //v2.0

	var theForm = document.form_login;
	var errMsg = "";
	var setfocus = "";

	if (theForm['password'].value == ""){
		errMsg = "กรุณาระบุรหัสผ่าน";
		setfocus = "['password']";
	}
	if (theForm['username'].value == ""){
		errMsg = "กรุณาระบุ username";
		setfocus = "['username']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_form_search(){ //v2.0

	var theForm = document.form_search;
	var errMsg = "";
	var setfocus = "";

	if (theForm['q'].value == ""){
		errMsg = "กรุณาระบุคำค้นหา";
		setfocus = "['q']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}


function VF_form_register(){ //v2.0

	var theForm = document.form_register;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['nickname'].value == ""){
		errMsg = "กรุณาระบุชื่อแสดงผล";
		setfocus = "['nickname']";
	}
	if (!emailRE.test(theForm['email'].value)){
		errMsg = "กรุณาระบุ Email ให้ถูกต้อง";
		setfocus = "['email']";
	}
	if (theForm['p2'].value == "" || (theForm['p2'].value != theForm['p1'].value)){
		errMsg = "กรุณาระบุรหัสผ่านให้ถูกต้อง";
		setfocus = "['p2']";
	}
	if (theForm['p1'].value == ""){
		errMsg = "กรุณาระบุรหัสผ่าน";
		setfocus = "['p1']";
	}
	if (theForm['username'].value == ""){
		errMsg = "กรุณาระบุ username";
		setfocus = "['username']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}


function VF_form_profile(){
	var theForm = document.form_profile;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['nickname'].value == ""){
		errMsg = "กรุณาระบุชื่อแสดงผล";
		setfocus = "['nickname']";
	}
	if (!emailRE.test(theForm['email'].value)){
		errMsg = "กรุณาระบุ Email ให้ถูกต้อง";
		setfocus = "['email']";
	}
	if (theForm['p2'].value != ""){
		if (theForm['p2'].value != theForm['p1'].value){
			errMsg = "กรุณาระบุรหัสผ่านให้ตรงกัน";
			setfocus = "['p2']";
		}
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_form_comment(){

	var theForm = document.form_comment;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['comment'].value == ""){
		errMsg = "กรุณาแสดงความคิดเห็น";
		setfocus = "['comment']";
	}
	if (!emailRE.test(theForm['email'].value)){
		errMsg = "กรุณาระบุ Email ให้ถูกต้อง";
		setfocus = "['email']";
	}
	if (theForm['name'].value == ""){
		errMsg = "กรุณาระบุชื่อ";
		setfocus = "['name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}



function VF_form_library_add(){ 

	var theForm = document.form_library_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['library_date'].value == ""){
		errMsg = "กรุณาระบุเวลาทำการ";
		setfocus = "['library_date']";
	}
	if (theForm['library_tel'].value == ""){
		errMsg = "กรุณาระบุเบอร์โทรศัพท์";
		setfocus = "['library_tel']";
	}
	if (theForm['library_location'].value == ""){
		errMsg = "กรุณาระบุที่อยู่";
		setfocus = "['library_location']";
	}
	if (theForm['library_name'].value == ""){
		errMsg = "กรุณาระบุชื่อสถานที่";
		setfocus = "['library_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}


function VF_form_media_add(){

	var theForm = document.form_media_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['media_intro'].value == ""){
		errMsg = "กรุณาระบุรายละเอียด";
		setfocus = "['media_intro']";
	}
	if (theForm['media_name'].value == ""){
		errMsg = "กรุณาระบุสื่อ";
		setfocus = "['media_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}



function VF_form_bookreview_add(){

	var theForm = document.form_bookreview_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['bookreview_author'].value == ""){
		errMsg = "กรุณาระบุชื่อผู้แต่ง";
		setfocus = "['bookreview_author']";
	}
	if (theForm['file'].value == ""){
		errMsg = "กรุณาระบุ File รูป";
		setfocus = "['file']";
	}
	if (theForm['bookreview_name'].value == ""){
		errMsg = "กรุณาระบุชื่อหนังสือ";
		setfocus = "['bookreview_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}



function VF_form_talk_add(){
	var theForm = document.form_talk_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['topic_name'].value == ""){
		errMsg = "กรุณาระบุหัวข้อ";
		setfocus = "['topic_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_form_award_add(){
	var theForm = document.form_award_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['topic_intro'].value == ""){
		errMsg = "กรุณาระบุรายละเอียดเกริ่นนำ";
		setfocus = "['topic_intro']";
	}
	if (theForm['topic_name'].value == ""){
		errMsg = "กรุณาระบุหัวข้อ";
		setfocus = "['topic_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}

function VF_form_bookcrossing_add(){ //v2.0

	var theForm = document.form_bookcrossing_add;
	var errMsg = "";
	var setfocus = "";

	if (theForm['book_cover'].value == ""){
		errMsg = "กรุณาระบุรูปปกหนังสือ";
		setfocus = "['book_cover']";
	}
	if (theForm['book_location'].value == ""){
		errMsg = "กรุณาระบุสถานที่วางหนังสือ";
		setfocus = "['book_location']";
	}
	if (theForm['book_name'].value == ""){
		errMsg = "กรุณาระบุชื่อหนังสือ";
		setfocus = "['book_name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}




function VF_form_bookcrossing_comment(){ 

	var theForm = document.form_bookcrossing_comment;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var errMsg = "";
	var setfocus = "";

	if (theForm['comment'].value == ""){
		errMsg = "กรุณาระบุรายละเอียด";
		setfocus = "['comment']";
	}
	if (!emailRE.test(theForm['email'].value)){
		errMsg = "กรุณาระบุ Email ให้ถูกต้อง";
		setfocus = "['email']";
	}
	if (theForm['name'].value == ""){
		errMsg = "กรุณาระบุชื่อ";
		setfocus = "['name']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}


function VF_form_bookcrossing_update(){

	var theForm = document.form_bookcrossing_update;
	var errMsg = "";
	var setfocus = "";

	if (theForm['book_location'].value == ""){
		errMsg = "กรุณาระบุสถานที่วาง";
		setfocus = "['book_location']";
	}
	if (errMsg != ""){
		alert(errMsg);
		eval("theForm" + setfocus + ".focus()");
	}
	else theForm.submit();
}
