$(document).ready(function() {
var loginError = "";
$('#gift_0').click(function() {
						$('#gift1').show();
							$('#gift2').hide();
							});
$('#gift_1').click(function() {
								$('#gift1').hide();
							$('#gift2').show();
							});
function trim(s)
{
	return rtrim(ltrim(s));
}

function ltrim(s)
{
	var l=0;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	return s.substring(l, s.length);
}

function rtrim(s)
{
	var r=s.length -1;
	while(r > 0 && s[r] == ' ')
	{	r-=1;	}
	return s.substring(0, r+1);
}

UTF8 = {
	encode: function(s){
		for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
			s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
		);
		return s.join("");
	},
	decode: function(s){
		for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
			((a = s[i][c](0)) & 0x80) &&
			(s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
			o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
		);
		return s.join("");
	}
};


function valAllowEmpty(value,title)
{
	//doesnt allow empty	
	if(value == '')
	{
		loginError += title + "\n";
	}
}
function valCheckBox(value,title)
{
	//doesnt allow empty	
	if(!value)
	{
		loginError += title + "\n";
	}
}
function valEmail(value)
{
	if(value != "")
	{
		AtPos = value.indexOf("@");
		StopPos = value.lastIndexOf(".");
		
		if (AtPos == -1 || StopPos == -1) {
			loginError += "Not a valid email address\n";
		}
	}
}
	
function urlencode(s) {
  s = encodeURIComponent(s);
  return s.replace(/~/g,'%7E').replace(/%20/g,'+');
 }
	$('#submit_book').click(function() {
		
		loginError = '';
		valAllowEmpty($('#name').val(),$('#name').attr('title'));
		valAllowEmpty($('#tel').val(),$('#tel').attr('title'));
		valAllowEmpty($('#email').val(),$('#email').attr('title'));
		valCheckBox($("#chk_terms").is(":checked"),$('#chk_terms').attr('title'));
		valEmail($('#email').val());
		if(loginError != "")
		{
			alert(loginError);
		}
		else
		{
			$.post('/ajax/mailers/book.php'
			,{
				'name':$('#name').val()
				,'email':$('#email').val()
				,'tel':$('#tel').val()
				,'travel_from':$('#travel_from').val()
					,'property1':$("select[@name='property1'] option:selected").attr('value')
						,'property2':$("select[@name='property2'] option:selected").attr('value')
							,'property3':$("select[@name='property3'] option:selected").attr('value')
							,'start-date':$('#start-date').val()
				,'end-date':$('#end-date').val()
				,'adults':$("select[@name='adults'] option:selected").attr('value')
				,'children':$("select[@name='children'] option:selected").attr('value')
				,'infants':$("select[@name='infants'] option:selected").attr('value')
				,'voucher':$('#voucher').val()
				,'requirements':$('#Requirements').val()

			}
			,function(returnData)
			{
			
				if(trim(returnData))
				{
					alert('Email sent successfully, Blue Paradise will contact you shortly.');	
					window.location = '/how-to-book.php';
				}
				else
				{	
				alert('error');
				}
				
			}
			,'text');					
		}
				
		return false;						
	});
		
});
 
 // JavaScript Document