function minStayUpdate() {
//function created by Jamie Reid 25-05-2010
//Controls min stay policy
//Amended by Jason Millward 19-07-2011 - Removed 5 night min stay from Cornwall and Llyn
//Amended by Jason Millward 15-04-2011 - Added document.ready call to blank dates before page is loaded. This ensures that minstay policies are not by-passed.
//Amended by Jamie Reid 08-03-2011 - Add max stay policy for Kilronan Castle (all dates) . added maxStay function.
//Amended by Jamie Reid 11-02-2011 - LP,CW,FB Minstay of 5 nts over 2011 summer high season (14 July - 4 Sep) (YD Already done previously)
//Amended by Jamie Reid 16-10-2010 - Castlemartyr Minstay of 5 nts over 2011 summer high season (1 July - 4 Sep)
//Amended by Jamie Reid 23-06-2010 - Muiltiple resort dependant changes to policy
//Amended by Jamie Reid 26-05-2010 - Add Resort Based min-stay condition (Castlemartyr excluded from 5 nt min)

   var resort = document.getElementById("parent").value;
   var startdate = document.getElementById("datepicker");
    
      //split the date into day, month, year - assumes date format DD-MM-YYYY
   var bits=startdate.value.split("-");   
   
   //Note months are monthnum -1 ie Jan=0, Feb=1 etc
   var sDate = new Date(bits[2],bits[1]-1,bits[0]);
   var pStart = new Date(2010,06,16);
   var pEnd = new Date(2010,08,05);   
   
 //alert(resort);
   //alert(bits[0]);
   //alert(bits[1]);
   //alert(bits[2]);
   
	//New policy (2010-06-23)
	//Min stay is 5 nts for irish retreats (except Castlemartyr(104)) from 16 Jul - 5 Sep  
  	//Otherwise is 2 nts
   
  
   	// Fistral Beach(cornwall and Llyn min stay removed )
	//	if( resort==61){    
 
			//15 July - 04 sep (months are monthnum -1 ie Jan=0, Feb=1 etc)	    
 	//		var pStart = new Date(2011,06,15);
   	//		var pEnd = new Date(2011,08,04);    
			
	//		if(sDate>=pStart && sDate<=pEnd) {
   	//		alert("Please note our minimum stay for this retreat during the periods of 15 July - 04 September is 5 nights.");
   	//		minStay(5);
   	//		}
	//	else {
	//	minStay(2);
   // 	}		
		
	//	}	
	//	else {
	//	minStay(2);
    //	}
    	//Yorkshire Dales
		if(resort==1){
			
			//15 July - 04 sep (months are monthnum -1 ie Jan=0, Feb=1 etc)	    
 	//		var pStart = new Date(2011,06,15);
   		//	var pEnd = new Date(2011,08,04);   
		
			//18 Feb - 22 Feb (months are monthnum -1 ie Jan=0, Feb=1 etc)	    
 			var pStarta = new Date(2011,01,18);
   			var pEnda= new Date(2011,01,22);   
		
		
			//if(sDate>=pStart && sDate<=pEnd) {
   			//alert("Please note our minimum stay for this retreat during the periods of 15 July - 04 September is 5 nights.");
   			//minStay(5);
   			//}else 
			if (sDate>=pStarta && sDate<=pEnda) {
   			alert("Please note our minimum stay for this retreat during the periods of 18-22 Feb  is 3 nights.");
   			minStay(3);
			}
			   
   		else{
   			minStay(2);
   			}    	
    		}
    	 }
function minStay(nts){
//function created by Jamie Reid 25-05-2010
// Dynamically sets the no_of_nights select list with selectable min nts
	
	var selList = document.getElementById("p_no_of_nights");
	var maxNts=14;
	var minNts=nts;
	
	//remove all existing options
	selList.options.length=0;
	
	for(i=minNts;i<maxNts+1;i++) {
		
		if (selList.options.length==0){
		selList.options[selList.options.length]=new Option(i,i,true,true);
		}
		else {
		selList.options[selList.options.length]=new Option(i,i,false,false);
		}
		}
	

	}

function maxStay(nts){
//function created by Jamie Reid 09-03-2011
// Dynamically sets the no_of_nights select list with selectable max nts
	
	var selList = document.getElementById("p_no_of_nights");
	var maxNts=nts;
	var minNts=2;
	
	//remove all existing options
	selList.options.length=0;
	
	for(i=minNts;i<maxNts+1;i++) {
		
		if (selList.options.length==0){
		selList.options[selList.options.length]=new Option(i,i,true,true);
		}
		else {
		selList.options[selList.options.length]=new Option(i,i,false,false);
		}
		
		
		}
	

	}

	
function blankDate(){
    
    document.getElementById("datepicker").value="";
	
	
	}

$(document).ready(function() {

$("#datepicker").datepicker();
$("#datepicker").datepicker(blankDate());
});

