	$(function(){
		
		
		$("input[name='chkIn']").datepicker({
				inline: true
				//onSelect: function(dateText, inst){ alert(dateText);}
		});
		$("input[name='chkOut']").datepicker({
				inline: true
				//onSelect: function(dateText, inst){ alert(dateText);}
		});

		$("#booking_calendar").datepicker({
				inline: true,
				onSelect: function(dateText, inst)
					{ 
						var gd = new Date(dateText);
						var td = new Date();

						if (gd > td)
						{
							popupOpen(422,350,'booking',dateText);
							$("input[name='chkIn']").datepicker({
									inline: true
									//onSelect: function(dateText, inst){ alert(dateText);}
							});
								$("input[name='chkOut']").datepicker({
									inline: true
									//onSelect: function(dateText, inst){ alert(dateText);}
							});
							$("#imgClose").click(function(){
								popupClose();
							});
						}
						else
						{
							alert('You CAN NOT pick up past date.');
						}
					/*	
						popupOpen(422,350,'booking',dateText);
						$("input[name='chkIn']").datepicker({
								inline: true
								//onSelect: function(dateText, inst){ alert(dateText);}
						});
							$("input[name='chkOut']").datepicker({
								inline: true
								//onSelect: function(dateText, inst){ alert(dateText);}
						});
						$("#imgClose").click(function(){
							popupClose();
						});
						*/
					}
					
		});

		//$("#shadow").css("height",$("#wrap").height()+234);
		var confirmationBook = "Thank you very much for your reservation!<br/>We will be contacting you within 24 hours to confirm your reservation.<br/>We also require credit card information (Visa, Master, American Express) to hold your reservation. <br/>If immediate confirmation is needed please give us a call at 604-826-8144 to make a reservation.<br/> Our cancellation policy is 48 hours.";
		var confirmationMsg = "Thank you very much for your comments.<br/>We will be contacting you within 24 hours if reply is needed.<br/>If immediate attention is needed please give us a call at 604-826-8144.";
		var optionsBook = { 
			beforeSubmit : validate,
			success: function(){
				$("#sub-booking").html("<table><tr><td height='200px' valign='center' align='justify'>"+confirmationBook+"</td></tr></table>");
			}
		}
		
		var optionsMsg = {
			beforeSubmit : validateMsg,
			success: function(){
				$("#sub-booking").html("<table><tr><td height='200px' valign='center' align='justify'>"+confirmationMsg+"</td></tr></table>");
			}
		}
		$("#booking").submit(function(){
			$(this).ajaxSubmit(optionsBook);
			return false;
		});

		$("#sendMsg").submit(function(){
			$(this).ajaxSubmit(optionsMsg);
			return false;
		});
	});
	  var geocoder;
	  var map;
	  var query = "32550 Logan Ave, Mission, B.C V2V 6G3. CANADA";
	  function initialize() {
		geocoder = new google.maps.Geocoder();
		var myOptions = {
		  zoom:15,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		
		
		codeAddress();
	  }
	 
	  function popupMap()
	  {
		geocoder = new google.maps.Geocoder();
		var myOptions = {
		  zoom:15,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		map = new google.maps.Map(document.getElementById("subPopup"), myOptions);	

		popUpCodeAddress();
	  }
	  
	  function popUpCodeAddress() {
		var address = query;
		geocoder.geocode( { 'address': address}, function(results, status) {
		  if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: map, 
				position: results[0].geometry.location
			});

			

		} else {
			alert("Geocode was not successful for the following reason: " + status);
		  }
		});
	  }

	  function codeAddress() {
		var address = query;
		geocoder.geocode( { 'address': address}, function(results, status) {
		  if (status == google.maps.GeocoderStatus.OK) {
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker({
				map: map, 
				position: results[0].geometry.location
			});

			google.maps.event.addListener(marker, 'click', function(){
				popupOpen(900,600,'googleMap','');
				$("#imgClose").click(function(){
					popupClose();
				});
			});

		} else {
			alert("Geocode was not successful for the following reason: " + status);
		  }
		});
	  }

	  
	function popupOpen(width, height, what, parm)
	{
		var popInner;
		if (what == "booking")
		{
			popInner = "<div id='subbox'><h1>Book a room</h1><form name='booking' id='booking' action='pushBooking.php' method='post'><table><tr><th>First Name</th><td><input type='text' name='fName' class='pText'/></td>"
			popInner += "<th>Last Name</th><td><input type='text' name='lName' class='pText'/></td></tr>"
			popInner += "<tr><th>Check-in</th><td><input type='text' name='chkIn' class='pDate' value='"+parm+"'/></td><th>Check-out</th><td><input type='text' name='chkOut' class='pDate'/></td></tr>"
			popInner += "<tr><th>Contact#</th><td colspan='3'><input type='text' name='contact' class='pText' /></td></tr><tr><th>E-mail</th><td colspan='3'><input type='text' name='email' class='pTextx'/></td></tr>"
			popInner += "<tr><th># of Rooms</th><td colspan='3'><input type='text' name='noRooms' class='pNum' value='1' /></td></tr>"
			popInner += "<tr><th># of Guests</th><td colspan='3'>Adults [19+] <input type='text' name='noAdt' class='pNum' value='2'/>&nbsp;&nbsp;Children [18-13] <input type='text' name='noHchdrn' "
			popInner += "class='pNum' value='0' />&nbsp;&nbsp;Children [12-0] <input type='text' name='noLchdrn' class='pNum'  value='0'/></td></tr>"
			popInner += "<tr height='50px'><td colspan='4' valign='bottom' align='center'><input type='submit' value='Book Now' class='button'/></td></tr></table></form></div><br/><div style='text-align:right;margin-right:10px;'><img id='imgClose' src='./images/close.jpg' style='cursor:pointer;'/></div>"

			$("#popup").css({
				"position":"absolute",
				"display":"block",
				"width":width+"px",
				"height":height+"px",
				"top":"50%",
				"left":"50%",
				"margin-left":"-"+(width/2)+"px",
				"margin-top":"-"+(height/2)+"px"
			}).html(popInner);
		}
		else if (what == "googleMap")
		{
			$("#popup").css({
				"position":"absolute",
				"display":"block",
				"width":width+"px",
				"height":height+"px",
				"top":"50%",
				"left":"50%",
				"margin-left":"-"+(width/2)+"px",
				"margin-top":"-"+(height/2)+"px"
			}).html("<div id='subPopup' style='margin-left:10px;margin-top:10px;width:"+(width-20)+"px;height:"+(height-60)+"px;'></div><br/><div style='text-align:right;margin-right:10px;'><img id='imgClose' src='./images/close.jpg' style='cursor:pointer;'/></div>");
			popupMap();
			
		}
		else if (what == "offer")
		{
			var oSplit = parm.split("|");
			popInner = "<div id='subbox'><br/><h1>"+oSplit[0]+"</h1><div id='offerPop'>"+oSplit[1]+"</div></div><br/><div style='text-align:right;margin-right:10px;'><img id='imgClose' src='./images/close.jpg' style='cursor:pointer;'/></div>"
			$("#popup").css({
				"position":"absolute",
				"display":"block",
				"width":width+"px",
				"height":height+"px",
				"top":"50%",
				"left":"50%",
				"margin-left":"-"+(width/2)+"px",
				"margin-top":"-"+(height/2)+"px"
			}).html(popInner);
			
		}
		
		$("#imgClose").click(function(){
				popupClose();
		});
		
		$("#backgroundPopup").css({
			 "display":"block",
			 "opacity": "0.7",
			 "height":document.documentElement.clientHeight
		});

		var confirmation = "Thank you very much for your reservation!<br/>We will be contacting you within 24 hours to confirm your reservation.<br/>We also require credit card information (Visa, Master, American Express) to hold your reservation. <br/>If immediate confirmation is needed please give us a call at 604-826-8144 to make a reservation.<br/> Our cancellation policy is 48 hours.";
		var options = { 
			beforeSubmit : validate,
			success: function(data){
				
				$("#subbox").html("<table><tr><td height='200px' valign='center' align='justify'>"+confirmation+"</td></tr></table>");
			}
		}

		$("#booking").submit(function(){
			$(this).ajaxSubmit(options);
			return false;
		});
	}

	function popupClose()
	{
		$("#popup").css("display","none");
		$("#backgroundPopup").css("display","none");
	}

	function submitBooking(obj)
	{
		
		if(!$("input[name='fName']").val())
		{
			alert("Please enter your first name.");
			$("input[name='fName']").focus();
		}
		else if(!$("input[name='lName']").val())
		{
			alert("Please enter your last name.");
			$("input[name='lName']").focus();
		}
		else if(!$("input[name='chkIn']").val())
		{
			alert("Please enter your check-in date.");
			$("input[name='chkIn']").focus();
		}
		else if(!$("input[name='chkOut']").val())
		{
			alert("Please enter your check-out date");
			$("input[name='chkOut']").focus();
		}
		else if(!$("input[name='contact']").val())
		{
			alert("Please enter your contact number.");
			$("input[name='contact']").focus();
		}

		else 
		{ 
			$("#booking").submit();
		
		}

	}

	function submitMsg(obj)
	{
		
		if(!$("input[name='fName']").val())
		{
			alert("Please enter your first name.");
			$("input[name='fName']").focus();
		}
		else if(!$("input[name='lName']").val())
		{
			alert("Please enter your last name.");
			$("input[name='lName']").focus();
		}
		else if(!$("input[name='contact']").val())
		{
			alert("Please enter your contact number.");
			$("input[name='contactNo']").focus();
		}
		else if(!$("textarea").val())
		{
			alert("Please enter your message.");
			$("textarea").focus();
		}

		else { $("form").submit(); }

	}

	function validate(formData, jqForm, options) { 
		// fieldValue is a Form Plugin method that can be invoked to find the 
		// current value of a field 
		// 
		// To validate, we can capture the values of both the username and password 
		// fields and return true only if both evaluate to true 
	 
		var fName = $('input[name="fName"]').fieldValue(); 
		var lName = $('input[name="lName"]').fieldValue(); 
		var chkIn = $("input[name='chkIn']").fieldValue();
		var chkIn = $("input[name='chkIn']").fieldValue();
		var chkOut = $("input[name='chkOut']").fieldValue();
		var contact = $("input[name='contact']").fieldValue();
		var email = $("input[name='email']").fieldValue();
	 
		// usernameValue and passwordValue are arrays but we can do simple 
		// "not" tests to see if the arrays are empty 
		if (!fName[0]) { 
			alert('Please enter your first name.'); 
			$("input[name='fName']").focus();
			return false; 
		} 
		if (!lName[0])
		{	
			alert('Please enter your last name.');
			$("input[name='lName']").focus();
			return false;
		}
		if (!chkIn[0])
		{	
			alert('Please pick a check-in date.');
			$("input[name='chkIn']").focus();
			return false;
		}
		if (!chkOut[0])
		{	
			alert('Please pick a check-out date.');
			$("input[name='chkOut']").focus();
			return false;
		}
		if (!contact[0])
		{	
			alert('Please enter your contact number.');
			$("input[name='contact']").focus();
			return false;
		}
		if (!email[0])
		{	
			alert('Please enter your email address.');
			$("input[name='email']").focus();
			return false;
		}
	}
	
	function validateMsg(formData, jqForm, options) { 
		// fieldValue is a Form Plugin method that can be invoked to find the 
		// current value of a field 
		// 
		// To validate, we can capture the values of both the username and password 
		// fields and return true only if both evaluate to true 
	 
		var fName = $('input[name="fName"]').fieldValue(); 
		var lName = $('input[name="lName"]').fieldValue(); 
		var contact = $("input[name='contact']").fieldValue();
		var email = $("input[name='email']").fieldValue();
		var msg = $("textarea[name='msg']").fieldValue();
		// usernameValue and passwordValue are arrays but we can do simple 
		// "not" tests to see if the arrays are empty 
		if (!fName[0]) { 
			alert('Please enter your first name.'); 
			$("input[name='fName']").focus();
			return false; 
		} 
		if (!lName[0])
		{	
			alert('Please enter your last name.');
			$("input[name='lName']").focus();
			return false;
		}
		if (!contact[0])
		{	
			alert('Please enter your contact number.');
			$("input[name='contact']").focus();
			return false;
		}
		if (!email[0])
		{	
			alert('Please enter your email address.');
			$("input[name='email']").focus();
			return false;
		}
		if (!msg[0])
		{
			alert('Please enter your message.');
			$("textarea[name='msg']']").focus();
			return false;
		}
	}
	
