$(document).ready(function() {
  
  //Tabbed Navigation
 
 $('#b-nav li a').click(function(){
 	
 	$(".b-question").each(function(){
 		
 		$(this).show();
 		
 	});
 	
 	
 	
 	$("#fields_contact").each(function(){
 		
 		$(this).show();
 		
 	});
 	
 
 	
 	$(".note_contact").each(function(){
 		
 		$(this).html("");
 		
 	});
 	
 	
 });
 
 
	clearUL = function(){$('.b-hidden, .b-hidden2').hide();
	$('#b-nav li a').removeClass('b-current');}
	$('#b-nav li:nth-child(2) a').click(function(){clearUL();$('#b-general').show();$(this).addClass('b-current');});
	$('#b-nav li:nth-child(3) a').click(function(){clearUL();$('#b-all-photos').show();$(this).addClass('b-current');});
	$('#b-nav li:nth-child(4) a').click(function(){clearUL();$('#b-rates-and-availability').show();$(this).addClass('b-current');});
	$('#b-nav li:nth-child(5) a').click(function(){clearUL();$('#b-map-and-attractions').show();$(this).addClass('b-current');});
	$('#b-nav li:nth-child(6) a').click(function(){clearUL();$('#b-reviews').show();$(this).addClass('b-current');});
	
	$('.b-hidden2').hide();
	
	
	
	
	//Send property to a friend at top and right side of detail page; makes the window slide down
	$('a.b-sptaf-head').click(function() {
		$('.b-sptaf-header').slideToggle(400);
		return true;
	});
	
	
	//Opens View Favorites when clicked on from top and side of property detail page
	$('a.b-vf-head').click(function() {
		
		var yurl = "/booking/load-favorites.cfm";
	
		$.get(yurl,'',function(data) {							
			
			$('#b-booking .b-sptaf .b-vflist').html(data);
			
		});//$.get
	 
		//slide the 'View Favorites' window down
		$('.b-vf-header').slideToggle(400);
	
	});
	
	
	
	
	
	//Send property to a friend on detail page
	$(".send-property-to-friend-form").submit(function(){
	
	
		var friendsemail = $("[name=friendemail]").val();
		var yourname = $("[name=yourname]").val();
		var youremail = $("[name=youremail]").val();
		
		if(friendsemail == ''){
			$("[name=friendemail]").val('This field is required');
			$('[name=friendemail]').css('color','#ff0000');
		}
		if(yourname == ''){
			$("[name=yourname]").val('This field is required');
			$("[name=yourname]").css('color','#ff0000');
		}
		if(youremail == ''){
			$("[name=youremail]").val('This field is required');
			$("[name=youremail]").css('color','#ff0000');
		}
		
		$('[name=friendemail]').focus(function(){$(this).css('color','#888888');});
		$('[name=yourname]').focus(function(){$(this).css('color','#888888');});
		$('[name=youremail]').focus(function(){$(this).css('color','#888888');});
		
		if(friendsemail == '' || yourname == '' || youremail == ''){
			return false;
		}	
	
	   var str = $(this).serialize();
	
	   $.ajax({
	   	type: "POST",
	   	url: "/booking/send-property-to-a-friend-processor.cfm",
	   	data: str,
	   	success: function(msg){
    
			$("#message").ajaxComplete(function(event, request, settings){
	
				result = msg;				
		
				$(this).html(result);
		
				}); 
	
			} //end ajaxComplete

 			}); //end success

			return false;

		}); //end serialize
		
		
	
	
		
	//Write a review form on detail page	
	$(".b-write-a-review-form").submit(function(){

	var str = $(this).serialize();
	
	   $.ajax({
	   	type: "POST",
	   	url: "/booking/review-processor.cfm",
	   	data: str,
	   	success: function(msg){
    
			$("#note").ajaxComplete(function(event, request, settings){
	
				result = msg;				
		
				$(this).html(result);
		
				}); 
	
			} //end ajaxComplete

 			}); //end success

			return false;

		}); //end serialize
		
		
		
	//Contact Form Submission
	$(".b-question").submit(function(){

	var str = $(this).serialize();
	
	var bq = $(this);
	
	   $.ajax({
	   	type: "POST",
	   	url: "/booking/contact-processor.cfm",
	   	data: str,
	   	success: function(msg){
    
			
	
				result = msg;				
		
				$(".note_contact").each(function(){
				
					$(this).html(result);
					$(bq).hide();	
					
				});
				
		
				
	
			} //end ajaxComplete

 			}); //end success

			return false;

	}); 
	
	$("#b-booking #b-left .b-question input[type='submit']").removeAttr('disabled');
	
});










/*------------------------------------------------------------------------------------------Favorites Section----*/


	
//Property Detail page, Heart icon, Add/Remove Favorites at top of detail page; makes the window slide down when the heart icon is clicked
function deleteFromFavorites( rid ) {
	
	var yurl = "/booking/delete-favorite.cfm?rid="+rid;
	
	$.get(yurl,'',function(data) {
		
		$('#b-booking .b-sptaf .b-vflist li#'+rid).remove();
		
		//Toggle the right side icon
		$('.b-actions .b-toggle').toggle();
		
		//Toggle the top icon
		$('.b-quick-nav span li').toggle();		
		
		//Change h5 in the top icon drop down
		$('.b-atf-header .b-sptaf h5').html('Removed from Favorites');
				
		//window slides down, then fades out 
		$('.b-atf-header').fadeIn(400).fadeTo(2000, 1).fadeOut(400);
		
	});
	return false;
}


//Property Detail page, right side, Add to Favorites button, found in footer.cfm
function addToFavorites( rid ) {
	    
    var yurl = "/booking/add-favorite.cfm?rid="+rid;
    
    $.get(yurl,'',function(data) {      
        var response = jQuery.trim(data);
            
        if (response !='') {
            if (response.search("~")) {
                
                //Toggle the right side icon
				$('.b-actions .b-toggle').toggle();
					
				//Toggle the top icon
				$('.b-quick-nav span li').toggle();		
					
				//Change h5 in the top icon drop down
				$('.b-atf-header .b-sptaf h5').html('Added to Favorites');	
				
				$('.b-atf-header').fadeIn(400).fadeTo(2000, 1).fadeOut(400);
					
            }
        }
    });
    
    return false;
}





//Add to Favorites for results.cfm
function addToFavoritesResults( rid ) {
		var r = rid.split(",");
	 	var yurl = "/booking/add-favorite.cfm?rid="+r['1'] +"&ts="+new Date();
		$.get(yurl,'',function(data) {
			$('.b-results .b-actions .b-toggle').toggle();
			$('#b-booking .b-sptaf h5').toggle();
			
		});
	 return false;
}





/*
function viewFavorites(){
	
	var yurl = "/booking/load-favorites.cfm";
	
	$.get(yurl,'',function(data) {							
			
			$('#b-booking .b-sptaf .b-vflist').html(data);
			
	});//$.get
	 
	//slide the 'View Favorites' window down
	$('.b-vf-header').slideToggle(400);
}
*/


