

jQueryCode = function(){
	jQuery(document).ready(function($){ 

		if (jQuery('#calendar-widget-2160').length == 0){
			console.error("CampManager Widget DIV element not found (calendar-widget-2160).");
			return;
		}

		var css_link = jQuery("<link>", {rel: "stylesheet", type: "text/css", href: "https://cotswoldfarmpark.campmanager.com/19959/External-Calendar-Widget-Css/"});
	   	css_link.appendTo('head');  
	   	
	   	var css_link2 = jQuery("<link>", {rel: "stylesheet", type: "text/css", href: "https://cotswoldfarmpark.campmanager.com/19959/External-Calendar-Widget-FontAwesome-Css/"});
	   	css_link2.appendTo('head');  
	   		   	
	  	fnLoadCalendarWidget2160();
	  	
	});
}
		
if(window.jQuery) jQueryCode();
else{   
    var script = document.createElement('script'); 
    document.head.appendChild(script);  
    script.type = 'text/javascript';
    script.src = "https://bookings.campmanager.com/Js/jquery-3.3.1.min.js";
    script.onload = jQueryCode;
}

function fnLoadCalendarWidget2160()
{
	varCalendarDate = jQuery('#calendar-widget-2160').data("default_date");
	jQuery('body').append('<div id="widget-popup-2160" class="widget-popup"></div>');
    jQuery('body').append('<div id="widget-overlay-2160" class="widget-overlay" onclick="fnCloseWidgetAvailability2160();"><div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div></div>');
	fnLoadCalendarAvailability2160(varCalendarDate);	
}

function fnLoadCalendarAvailability2160(varCalendarDate)
{			

	if (jQuery('#calendar-widget-2160').length == 0){
		console.error("CampManager Widget DIV element not found (calendar-widget-2160).");
		return;
	}

	try{
		document.getElementById('widget-overlay-2160').style.display = 'block';
	}catch(e){}
	
	varAvailableTxtColour = jQuery('#calendar-widget-2160').data("available_txt_colour");
	varAvailableBgColour = jQuery('#calendar-widget-2160').data("available_bg_colour");
	varAvailableLabel = jQuery('#calendar-widget-2160').data("available_label");
	
	varNoCheckInTxtColour = jQuery('#calendar-widget-2160').data("nocheckin_txt_colour");
	varNoCheckInBgColour = jQuery('#calendar-widget-2160').data("nocheckin_bg_colour");
	varNoCheckInLabel = jQuery('#calendar-widget-2160').data("nocheckin_label");
	
	varBookedTxtColour = jQuery('#calendar-widget-2160').data("booked_txt_colour");
	varBookedBgColour = jQuery('#calendar-widget-2160').data("booked_bg_colour");
	varBookedLabel = jQuery('#calendar-widget-2160').data("booked_label");
	
	varUnavailableTxtColour = jQuery('#calendar-widget-2160').data("unavailable_txt_colour");
	varUnavailableBgColour = jQuery('#calendar-widget-2160').data("unavailable_bg_colour");
	varUnavailableLabel = jQuery('#calendar-widget-2160').data("unavailable_label");

	try{xmlHttpStartCalendar2160.abort();}catch(error){}try{xmlHttpStartCalendar2160=new XMLHttpRequest();}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){alert("Your browser does not support AJAX!");return false;}}}xmlHttpStartCalendar2160.onreadystatechange=function(){if(xmlHttpStartCalendar2160.readyState==4)
	{

		document.getElementById('calendar-widget-2160').innerHTML = xmlHttpStartCalendar2160.responseText;
		
		try{
			document.getElementById('widget-overlay-2160').style.display = 'none';
		}catch(e){}
		
		try{
			fnPostDivHeight();
		}
		catch(e){}
	}}
    xmlHttpStartCalendar2160.open("GET","https://cotswoldfarmpark.campmanager.com/19959/External-Calendar-Widget-Script/?ContainerID=2160&Date=" + varCalendarDate + "&GroupIDs=&SubGroupIDs=2160&Adults=2&Children=0&Infants=0&Pets=0&atx=" + encodeURIComponent(varAvailableTxtColour) + "&abg=" + encodeURIComponent(varAvailableBgColour) + "&al=" + varAvailableLabel + "&ntx=" + encodeURIComponent(varNoCheckInTxtColour) + "&nbg=" + encodeURIComponent(varNoCheckInBgColour) + "&nl=" + varNoCheckInLabel + "&btx=" + encodeURIComponent(varBookedTxtColour) + "&bbg=" + encodeURIComponent(varBookedBgColour) + "&bl=" + varBookedLabel + "&utx=" + encodeURIComponent(varUnavailableTxtColour) + "&ubg=" + encodeURIComponent(varUnavailableBgColour) + "&ul=" + varUnavailableLabel + "&d=" + Math.random());
    xmlHttpStartCalendar2160.send(null); 

}

function fnCalendarWidgetChangeMonth2160(varDateYear, varDateMonth){
	varCalendarDate = varDateYear + "/" + varDateMonth + "/01";
	fnLoadCalendarAvailability2160(varCalendarDate);
}

function fnSelectDate2160(varSubGroupID, varDateSelected)
{
	document.getElementById('widget-overlay-2160').style.display = 'block';
	fnCalendarCheckAvailability2160(varSubGroupID, varDateSelected);	
}

function fnCalendarCheckAvailability2160(varSubGroupID, varDateSelected)
{
	try{xmlHttpStartCalendar2160.abort();}catch(error){}try{xmlHttpStartCalendar2160=new XMLHttpRequest();}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){alert("Your browser does not support AJAX!");return false;}}}xmlHttpStartCalendar2160.onreadystatechange=function(){if(xmlHttpStartCalendar2160.readyState==4)
	{
		document.getElementById('widget-popup-2160').innerHTML = xmlHttpStartCalendar2160.responseText;
		document.getElementById('widget-popup-2160').style.display = 'flex';
		
		try{
			if (document.getElementById('idtxtWidgetDurations-2160').value != "")
			{
				fnAvailabilityResults2160();
				fnValidateTouringType2160();
			}
		}
		catch(e){}
	}}
    xmlHttpStartCalendar2160.open("GET","https://cotswoldfarmpark.campmanager.com/19959/External-Calendar-Widget-Durations/?ContainerID=2160&SubGroupID=" + varSubGroupID + "&StartDate=" + varDateSelected + "&Adults=2&Children=0&Infants=0&Pets=0&d=" + Math.random());
    xmlHttpStartCalendar2160.send(null); 
}

var xmlHttpStartCalendar2160;
function fnAvailabilityResults2160()
{
	try{
		xmlHttpStartCalendar2160.abort();
	}catch(error){}

	if (document.getElementById("idtxtWidgetDurations-2160").value != "")
	{
		var varAvailabilitySearch = true;
		var varTouringTentLengthRequired = 0;
		var varSubGroupID 		= document.getElementById("idtxtWidgetSubGroupID-2160").value;
		var varStartDate 		= document.getElementById("idtxtWidgetStartDate-2160").value;
		var varCategoryTypeID	= document.getElementById("idtxtWidgetTypeID-2160").value;
		var varDuration 		= document.getElementById("idtxtWidgetDurations-2160").value;		
		
		varTouringType			= 0;
		varVehicleLength		= "";
		varElectric				= 0;
		varAwning				= 0;
		varAdults				= 0;
		varChildren				= 0;
		varInfants				= 0;
		varPets					= 0;

		try{
			varTouringType = document.getElementById("idtxtWidgetTouringType-2160").value;
		}catch(error){} 	
		
		try{
			varVehicleLength = document.getElementById("idtxtWidgetVehicleLength-2160").value;
		}catch(error){} 	
	
		try{
			varElectric = document.getElementById("idtxtWidgetElectric-2160").value;
		}catch(error){} 	
	
		try{
			varAwning = document.getElementById("idtxtWidgetAwning-2160").value;
		}catch(error){} 	

		try{
			varAdults	= document.getElementById('idtxtWidgetAdults-2160').value;
		}catch(error){} 	
		
		try{
			varChildren	= document.getElementById('idtxtWidgetChildren-2160').value;
		}catch(error){} 
			
		try{
			varInfants	= document.getElementById('idtxtWidgetInfants-2160').value;
		}catch(error){} 
			
		try{
			varPets		= document.getElementById('idtxtWidgetPets-2160').value;
		}catch(error){} 		

		varBookButtonTxtColour = jQuery('#calendar-widget-2160').data("book_button_txt_colour");
		varBookButtonBgColour = jQuery('#calendar-widget-2160').data("book_button_bg_colour");
		varBookButtonRadius = jQuery('#calendar-widget-2160').data("book_button_border_radius");

		
	
		if (varAvailabilitySearch == true)
		{
			try{xmlHttpStartCalendar2160.abort();}catch(error){}try{xmlHttpStartCalendar2160=new XMLHttpRequest();}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlHttpStartCalendar2160=new ActiveXObject("Microsoft.XMLHTTP");}catch (e){alert("Your browser does not support AJAX!");return false;}}}xmlHttpStartCalendar2160.onreadystatechange=function(){if(xmlHttpStartCalendar2160.readyState==4)
			{
				document.getElementById('widget-popup-book-now-2160').innerHTML = xmlHttpStartCalendar2160.responseText;
				
				try{
					fnPostDivHeight();
				}
				catch(e){}			
			}}
		    xmlHttpStartCalendar2160.open("GET","https://cotswoldfarmpark.campmanager.com/19959/External-Calendar-Widget-Book/?ContainerID=2160&CategoryTypeID=" + varCategoryTypeID + "&SubGroupID=" + varSubGroupID + "&StartDate=" + varStartDate + "&Duration=" + varDuration + "&TouringType=" + varTouringType + "&VehicleLength=" + varVehicleLength + "&Electric=" + varElectric + "&Awning=" + varAwning + "&Adults=" + varAdults + "&Children=" + varChildren + "&Infants=" + varInfants + "&Pets=" + varPets + "&btx=" + encodeURIComponent(varBookButtonTxtColour) + "&bbg=" + encodeURIComponent(varBookButtonBgColour) + "&bdr=" + varBookButtonRadius +"&d=" + Math.random());
		    xmlHttpStartCalendar2160.send(null); 
		}
		else
		{
			document.getElementById('widget-popup-book-now-2160').innerHTML = '';
		}
	}
	else{
		document.getElementById('widget-popup-book-now-2160').innerHTML = '';
	}
}

function fnValidateTouringType2160()
{
		
	if (document.getElementById('idtxtWidgetTouringType-2160').value != 5)
	{
		document.getElementById('id-vehicle-length-2160').style.display = '';
	}
	else
	{
		document.getElementById('id-vehicle-length-2160').style.display = 'none';
	}
	
}

function fnCloseWidgetAvailability2160()
{
	try{
		document.getElementById('widget-popup-2160').style.display = 'none';
	}
	catch(e){}	
	try{
		document.getElementById('widget-overlay-2160').style.display = 'none';
	}
	catch(e){}		
	try{
		document.getElementById('widget-popup-book-now-2160').innerHTML = '';
	}
	catch(e){}	
}

function GetLink22160(){
  if(typeof ga !== 'undefined' && typeof ga.getAll === 'function') {
    trackers = ga.getAll();
    if(trackers.length) {
      uaLinker = new window.gaplugins.Linker(trackers[0]);      
	  document.getElementById('frmCalendarWidget').action = uaLinker.decorate(document.getElementById('frmCalendarWidget-2160').action);
    } 
  }
}

function fnValidateCalendarWidget2160()
{
	GetLink22160();
	document.forms['frmCalendarWidget-2160'].submit();
}