// JScript File
// <![CDATA[  
	// === Global Javascript === //
	$(function() {
            loadDiv();
	});
// ]]>



function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}
function procSendToFriend()
{
    $email = $('#sendFriendEmail').val();
    $fname = $('#sendFriendFName').val();
    $name = $('#sendFriendName').val();
    $url = location.href;
    
    
    
    if($name == 'Your name' || $fname == 'Your friend\'s name' || (!isValidEmailAddress($email)))
    {
        alert('Please enter your name, friends name and a valid email address');
        $('#sendFriendName').focus();
        return false;
    }
    else
    {
        $('#send_friend').html(
	        '<h5 class="competition">Send to a friend</h5>'+							
            '<p style="font-size:12px; color:#FFFFFF;">This page has been sent to your friend, <a href="javascript:loadDiv();">click here</a> to reload the form.</p>'							
         );
            
        $.post('http://www.parkdeanholidays.co.uk/send-to-friend.aspx',{'name':$name,'fname':$fname,'email':$email,'url':$url}, function (data){
    	   $('#sendFriendName').val('Your name');
    	   $('#sendFriendFName').val("Your friend's name");
           $('#sendFriendEmail').val("Friend's email address");
          });
          return false;
    }
    
    
}

function loadDiv()

{

 
        $('#send_friend').html(
            '<h5 class="competition">Send to a friend</h5>'+							
            '<ul>'+							
            '<li><input class="text" id="sendFriendName" type="text" maxlength="30" name="yourName" value="Your name" /></li>'+
            '<li><input class="text" id="sendFriendFName" type="text" maxlength="30" name="friendName" value="Your friend\'s name" /></li>'+							
            '<li><input class="text" id="sendFriendEmail" type="text" name="yourEmail" value="Friend\'s email address" /></li>'+							
            '<li>'+							
            '<a rel="sendFriend" class="btnReplace" href="#" onclick="return procSendToFriend();" title="Send to a friend"><span>Send</span></a>'+							
            '<input class="btnReplace" type="submit" name="action" value="Send" />'+							
            '</li>'+							
            '</ul>');
		$('a.btnReplace').css('display', 'block').click(function() { var $r = $(this).attr('rel'); /*$('form#' + $r).submit(); */return false; });
		$('input.btnReplace').hide();
		
    	$('#sendFriendName')
		    .focus(function() { if ($(this).val() == 'Your name') { $(this).val(''); } })
		    .blur(function() { if ($(this).val() == '') { $(this).val('Your name'); } });
	$('#sendFriendFName')
		    .focus(function() { if ($(this).val() == "Your friend\'s name") { $(this).val(''); } })
		    .blur(function() { if ($(this).val() == '') { $(this).val("Your friend\'s name"); } });
    	$('#sendFriendEmail')
	   		.focus(function() { if ($(this).val() == "Friend's email address") { $(this).val(''); } })
	    	.blur(function() { if ($(this).val() == '') { $(this).val("Friend's email address"); } });
	            
}