/* Javascript */

/* JQuery */

$(function(){	
	
 	//verifycode();

	$("#Login").click(function(){
		 
		if($("input#username").val()==""){
			alert("Please input Username");
			$("input#username").focus();
			return false;
		}else if($("input#password").val()==""){
			alert("Please input Password");
			$("input#password").focus();
			return false;
		}else{
			$.ajax({
				url: "lib/save-login.php",
				type: 'POST',
				data: $('form#formlogin').serialize(),
				success: function(result){
					if(result==1){
						//alert('Login complete!');
						window.location = 'admin.php';
						return false;
					}else{
						alert('Can not login.');
						return false;
					}
				}
			});
		}
	});

});
/*** End **/

function SendContact(){
	//$("input#button").val("Waiting...");
	if($("input#name").val()==""){
		alert("Please input Name");
		$("input#name").focus();
		return false;
	}else if($("input#email").val()==""){
		alert("Please input Email");
		$("input#email").focus();
		return false;
	}else if(!isValidEmail($("input#email").val())){
		alert("Please input Valid Email");
		$("input#email").focus();
		return false;
	}else if($("textarea#message").val()==""){
		alert("Please input Message");
		$("textarea#message").focus();
		return false;
	}else if($("input#verifycode").val()==""){
		alert("Please input Verifycode");
		$("input#verifycode").focus();
		return false;
	}else if($("input#verifycode").val()!=$("input#checkcode2").val()){
		alert("Please input Verifycode Again!");
		$("input#verifycode").focus();
		return false;
	}else{
		$.ajax({
			url: "lib/send-contact.php",
			type: 'POST',
			data: $('form#formcontact').serialize(),
			success: function(result){
				$("input#name").val('');
				$("input#email").val('');
				$("input#phone").val('');
				$("input#verifycode").val('');
				$("textarea#message").val('');
				//$("input#button").val("Update");
				if(result==1){
					alert('Send Email Complete!');
					return false;
				}else{
					alert('Can not send email.');
					return false;
				}
			}
		});
	}
}


function FormBooking(id){
	$.fancybox({
		'hideOnOverlayClick' : false,
		'titleShow' : false,
		'cyclic' : true,
		'type' : 'iframe',
		'width' : 670,
		'height' : 540,
		'href' : 'form_booking.php?id='+id
	});
}

function SendBooking(){
	//$("input#send").val("Waiting...");
	if($("select#roomid").val()==""){
		alert("Please select Room");
		$("select#roomid").focus();
		return false;
	}else if($("input#people").val()==""){
		alert("Please input Num of People");
		$("input#people").focus();
		return false;
	}else if($("input#startdate").val()==""){
		alert("Please input Check-In");
		$("input#startdate").focus();
		return false;
	}else if($("input#stopdate").val()==""){
		alert("Please input Check-Out");
		$("input#stopdate").focus();
		return false;
	}else if($("input#yourname").val()==""){
		alert("Please input Your Name");
		$("input#yourname").focus();
		return false;
	}else if($("input#yourphone").val()==""){
		alert("Please input Your Phone");
		$("input#yourphone").focus();
		return false;
	}else if($("input#youremail").val() && !isValidEmail($("input#youremail").val())){
		alert("Please input Valid Email");
		$("input#youremail").focus();
		return false;
	}else if($("input#yourverifycode").val()==""){
		alert("Please input Verifycode");
		$("input#yourverifycode").focus();
		return false;
	}else if($("input#yourverifycode").val()!=$("input#checkcode").val()){
		alert("Please input Verifycode Again!");
		$("input#yourverifycode").focus();
		return false;
	}else{
		$.ajax({
			url: "lib/send-booking.php",
			type: 'POST',
			data: $('form#formbooking').serialize(),
			success: function(result){
				//alert(result);
				$("select#roomid").val()
				$("input#startdate").val('');
				$("input#stopdate").val('');
				$("input#yourname").val('');
				$("input#youremail").val('');
				$("input#yourphone").val('');
				$("input#yourverifycode").val('');
				$("input#people").val('');
 				//$("input#send").val("&nbsp;&nbsp;&nbsp;Send&nbsp;&nbsp;&nbsp;");
				if(result==-3){
					alert('ไม่สามารทำการจองห้องพักได้ / Can not send booking.\n\nกรุณาติดต่อเจ้าหน้าที่โดยตรง/Please contact operator\n\nโทร/Tel 087-773 3950 / 081-995 6162');
					window.location.reload();
					return false;
				}else if(result==1){
					alert('ทำการแจ้งจองห้องพักเรียบร้อย เจ้าหน้าที่จะติดต่อกลับไปอีกครั้งค่ะ ขอบคุณค่ะ\n\nSend Booking Complete, Staff will contact you again thanks.');
					window.location.reload();
					return false;
				}else{
					alert('ไม่สามารทำการจองห้องพักได้ / Can not send booking.\n\nกรุณาติดต่อเจ้าหน้าที่โดยตรง/Please contact operator\n\nโทร/Tel 087-773 3950 / 081-995 6162');
					window.location.reload();
					return false;
				}
			}
		});
	}
}
