function show_hide(field) {
	if (document.getElementById(field).style.display == 'block') document.getElementById(field).style.display = 'none'
	else if (document.getElementById(field).style.display == 'none') document.getElementById(field).style.display = 'block'
}


function Opensupport2(newin) {
	Support2=window.open(newin,"Support2","resizeable=yes,scrollbars=yes,width=550,height=320 top=250,left=250");
	window.Support2.focus();
}

function Opensupport3(newin) {
	Support3=window.open(newin,"Support3","resizeable=yes,scrollbars=yes,width=600,height=435 top=250,left=250");
	window.Support3.focus();
}

function Opensupport4(newin) {
	Support4=window.open(newin,"Support4","resizeable=yes,scrollbars=yes,width=350,height=545 top=250,left=250");
	window.Support4.focus();
}


function Opensupport5(newin) {
Support5=window.open(newin,"Support5","resizeable=yes,scrollbars=yes,width=825,height=565 top=50,left=50");
window.Support5.focus();
}


function Opensupport6(newin) {
Support4=window.open(newin,"Support4","resizeable=yes,scrollbars=yes,width=800,height=565 top=50,left=50");
window.Support4.focus();
}

function Opensupport753(newin) {
Support4=window.open(newin,"Support4","resizeable=yes,scrollbars=yes,width=800,height=565 top=50,left=50");
window.Support4.focus();
}


function showImage(imgUrl) {
  	document.property_image.src = imgUrl;
}


function addToFavorites( rid ) {
		//$("div#extendstatus").html("");
			//$("div#extendstatus").css("display","none");

			var r = rid.split(",");
		 
		 	var yurl = "add-to-favorites.cfm?rid="+r['1'] +"&ts="+new Date();



			$.get(yurl,'',function(data) {

				var response = jQuery.trim(data);
				if (response !='') {
					if (response.search("~")) {

						var res = response.split("~");
						//$("div#extendstatus").html(res[0]);
						//$("#e"+aid).html(res[1]);
						//$("div#extendstatus").css("display","");
						//alert(res[1]);
						$("a#atf"+res[1]).html("<img class='icon' border='0' src='/images/icons/add.png'/> Added");

					} else {

						//$("div#extendstatus").html(response);
						//$("div#extendstatus").css("display","");
					}
				}
			});//$.get
		 return false;

	}

function deleteFromFavorites( rid ) {
		//$("div#extendstatus").html("");
			//$("div#extendstatus").css("display","none");

		 
		 	var yurl = "delete-from-favorites.cfm?rid="+rid+"&ts="+new Date();



			$.get(yurl,'',function(data) {

				var response = jQuery.trim(data);
				if (response !='') {
					if (response.search("~")) {

						var res = response.split("~");
						//alert(res[1]);
						$("li#"+res[1]).remove();
						//$("div#extendstatus").html(res[0]);
						//$("#e"+aid).html(res[1]);
						//$("div#extendstatus").css("display","");

					} else {
						
						//$("div#extendstatus").html(response);
						//$("div#extendstatus").css("display","");
					}
				}
			});//$.get
		 return false;

	}



//All of these are used to deteermine if we are in peak season or not: Memorial Day - Labor Day
function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) +
             Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d + 1;
}

function makeArray()    {
    this[0] = makeArray.arguments.length;
    for (i = 0; i<makeArray.arguments.length; i++)
        this[i+1] = makeArray.arguments[i];
}

var daysofmonth   = new makeArray( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var daysofmonthLY = new makeArray( 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

function NthDay(nth,weekday,month,year) {
    if (nth > 0) return (nth-1)*7 + 1 + (7 + weekday - DayOfWeek((nth-1)*7 + 1,month,year))%7;
    if (LeapYear(year)) var days = daysofmonthLY[month];
    else                var days = daysofmonth[month];
    return days - (DayOfWeek(days,month,year) - weekday + 7)%7;
}

var sun=1,mon=2,tue=3,wed=4,thu=5,fri=6,sat=7;
var jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,sep=9,oct=10,nov=11,dec=12;
var first=1,second=2,third=3,fourth=4,fifth=5,last=-1;

var daysofweek   = new makeArray('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var monthsofyear = new makeArray('January','February','March','April','May','June','July','August','September','October','November','December');

function DayOfWeek(day,month,year) {
    var a = Math.floor((14 - month)/12);
    var y = year - a;
    var m = month + 12*a - 2;
    var d = (day + y + Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400) + Math.floor((31*m)/12)) % 7;
    return d+1;
}

function Nths(day) { 
    if (day == 1 || day == 21 || day == 31) return 'st';
    if (day == 2 || day == 22) return 'nd';
    if (day == 3 || day == 23) return 'rd';
    return 'th';
}

function FullDate(day,month,year) {
    return month +'/'+day+'/'+ year;
}

function formatDate(value)
{
   return value.getMonth()+1 + "/" + value.getDate() + "/" + value.getFullYear();
}

function inPeakSeason(){
	
	var d = new Date();
	var today = formatDate(d);
	
	var year = d.getFullYear();

	var memorialDay = FullDate(NthDay(last,mon,may,year),may,year);
	var laborDay = FullDate(NthDay(first,mon,sep,year),sep,year);
	
	//alert(today + '-' + memorialDay + '-' + laborDay);
	
	if(today > memorialDay && today < laborDay){
		return true;
	}else{
		return false;
	}

}


function inOffSeason(myDate){
	
	var d = new Date();
		
	var thisYear = d.getFullYear();
	var nextYear = d.getFullYear()+1;
	var splitDate = myDate.split('/',3);
	var myYear = splitDate[2];
	
	if(myYear == thisYear){
		if(myDate > '09/20/2010'){return true;}else{return false;}	
	}
	
	if(myYear == nextYear){
		if(myDate < '05/15/'+nextYear){return true;}else{return false;}
	}
	
}
//end of functions used to determine peak season or not


$(document).ready(function () {

   $('#navigation li:has(ul)').hover( 
      function () {
         $(this).find('ul').fadeIn('fast');
      }, 
      function () {
         $(this).find('ul').hide();
      }
   );
   
   $('#navigation li:has(ul) > a').click( function () {
      return false;
    });
   
   
	//Default filter - weekly
   function saturdayFilter(date) {
   		
   		//Can only book on Saturdays if they select 'Weekly'
   		return (date.getDay() != 6) ? [false, ''] : [true, '']; 
   		   		
   }
   
   //User has selected 'nightly'
   function nightlyFilter(date){
   	
   		/*
   			Rules:
   			1. During peak season, users can only book on Saturday, Sunday, Monday and Tuesday and have a 4 night minimum
   			2. During off-peak season, users can book on any day and have a 2 night minimum
   		*/

   			
   			//Jan, Feb, Marh, April,Oct,Nov,Dec
   			if(date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2 || date.getMonth() == 3 || date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11){
   				return [true,''];
   			}else if(date.getMonth() == 4){ //May
   				
   				if(date.getDate() <= 15){
   					return [true,''];
   				}else{
   					return (date.getDay() != 6 && date.getDay() != 0 && date.getDay() != 1 && date.getDay() != 2) ? [false, ''] : [true, ''];
   				}
   				
   			}else if(date.getMonth() == 8){ //September
   				
   				if(date.getDate() <= 20){
   					return (date.getDay() != 6 && date.getDay() != 0 && date.getDay() != 1 && date.getDay() != 2) ? [false, ''] : [true, ''];
   				}else{
   					return [true,''];
   				}  					
   				
   				
   			}else if(date.getMonth() == 5 || date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8){
   				return (date.getDay() != 6 && date.getDay() != 0 && date.getDay() != 1 && date.getDay() != 2) ? [false, ''] : [true, ''];
   			}else{   			
   			
   				return [false,''];  		
   			}
   			
   			return [false,''];
   }  
   
   
   
   function noFilter(date) {
      return [true, ''];
   }
   
     
   if($("#strCheckin").datepicker) {   			
  		 
  		 var d = new Date();
  		 //d.setDate(d.getDate()+14); - use this if you want to add days to 'today'
  		 
  		 //Datepickers are on: property-detail.cfm, index.cfm, book-online.cfm and book-online-search-results.cfm
  		 
  		 $("#strCheckin").datepicker({showOn: 'button', buttonImage: '/images/layout/smallCal.png', buttonImageOnly: true, beforeShowDay: saturdayFilter, minDate: d});
  		
  						
   }
	 

	
/*--Not sure why i did this;commenting it out for now  
$("#strCheckin").change(function(){
   		
   	if( $("input[name='period']:checked").val() == 'daily' ) { //only perform this check if 'nightly' is checked
   	
   		var chosenDate = $("#strCheckin").val();
   		
   		 if(inOffSeason(chosenDate)){
         		
         		$("#intNights").html("\
			 	<option value='2'>2</option> \
	            <option value='3'>3</option> \
	            <option value='4'>4</option> \
	            <option value='5'>5</option> \
	            <option value='6'>6</option>");		         			
		
		}else{
				
			 	$("#intNights").html("\
	            <option value='4'>4</option> \
	            <option value='5'>5</option> \
	            <option value='6'>6</option>");		
		
		}
   		
   	}//end if value = daily
   		
   });

*/
  

  $("input[name='period']").click( function () {	   
	  
	   	   
      if( $("input[name='period']:checked").val() == 'daily' ) {
      
      		$("#strCheckin").datepicker('option', {beforeShowDay: nightlyFilter});
         
	          var chosenDate = $("#strCheckin").val();          
	         
	          if(inOffSeason(chosenDate)){  	          
    		         		
	         		
					$("#intNights").html("\
				 	<option value='2'>2</option> \
		            <option value='3'>3</option> \
		            <option value='4'>4</option> \
		            <option value='5'>5</option> \
		            <option value='6'>6</option>");	
	         			
			
			}else{		
					
					
				 	$("#intNights").html("\
		            <option value='4'>4</option> \
		            <option value='5'>5</option> \
		            <option value='6'>6</option>");		
			
			}
		 
		 $("#pn").show();
		 
      } else {
      
         /*  Commented this out because it was resetting the drop down even if i wanted to save what was searched but i need 
         	it to reset the drop down if someone selects weekly after selecting nightly
         */
		$("#strCheckin").datepicker('option', {beforeShowDay: saturdayFilter});
         
         $("#intNights").html("\
             <option>7</option>\
             <option>14</option>\
             <option>21</option>");
			 $("#pn").hide();

         
      }
   });

   
   $("input[name='period']:checked").click();
	
	

	//Code for image swapper 
	
	$('#be-details-thumbs a').hover(
      function () {
         $('#be-details-main-image img').attr('src', $(this).attr('href'));
      },
      function () {
         $('#be-details-main-image img').attr('src', $('#be-details-thumbs a:first').attr('href'));
      }
   );




   
	

   
});

function copydate(){
	
	//$("#strCheckinBottom").val($("#strCheckin1").val());
	//$("#strCheckinBottom1").val($("#strCheckin1").val());
	
	
	}

$(document).ready( function () {

   $('.unhide').bind('click', function () {
      var id = '#' + $(this).attr('rel');
      $(id).toggle();
   });

      $('.unhide1').bind('click', function () {
      var id = '#' + $(this).attr('rel');
      $(id).toggle();

	  //alert($(this).attr('href'));
	  document.location.toString($(this).attr('href'));
   });

   $('.hidden').hide();
   
   $("#amenTable a").click(function(){
							 
			var u = $(this).attr('href');				 
			//alert(u);
			$(this).attr('href',u+"&strcheckin="+$("#strCheckin1").val());
				    
				    
	});


})



