window.dhx_globalImgPath="/scripts/Calendar/Calendar/imgs";

function initialiseEnquiry() {

	if (window.XMLHttpRequest) 
		{ xhttp=new XMLHttpRequest(); }
	else // Internet Explorer 5/6
		{ xhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
		
	mCal = new dhtmlxCalendarObject("arrivalDate",false);
	mCal.setSkin("vista");
				
	var d = new Date();
	var e = new Date();
	e.setDate(e.getDate()+365);		
	mCal.setSensitive(d,e);
	mCal.setDateFormat("%d-%M-%Y");

	mCal.draw();

	Recaptcha.create("6Lfa_LoSAAAAAMGM2EqtodOz3KMKEucC36p9W6TB", "captcha", {theme : 'white'  });
}


function displaySuccess() {
	
	Recaptcha.destroy();
	document.getElementById("success").style.visibility='visible';
	document.getElementById("success").style.display='block';
	document.getElementById("mainForm").style.display='none';

}
	

function markError(spanLabel, errorFound) {
		
	if (errorFound==true)
		{
			document.getElementById(spanLabel).style.color='#FF0000';
			document.getElementById(spanLabel).style.fontWeight='bold';
		}
		else
		{
			document.getElementById(spanLabel).style.color='#000000';
			document.getElementById(spanLabel).style.fontWeight='normal';
		}
}

function validateForm() {

	var params = "captchaChallenge="+escape(Recaptcha.get_challenge())+
		"&captchaResponse="+escape(Recaptcha.get_response())+
		"&email="+escape(document.getElementById("formEmail").value)+
		"&name="+escape(document.getElementById("name").value)+
		"&telephone="+escape(document.getElementById("telephone").value)+
		"&country="+escape(document.getElementById("country").value) +
		"&location="+escape(document.getElementById("location").value)+
		"&arrivalDate="+escape(document.getElementById("arrivalDate").value)+
		"&numNights="+escape(document.getElementById("numNights").value) +
		"&numAdults="+escape(document.getElementById("numAdults").value) +
		"&numChildren03="+escape(document.getElementById("numChildren0-3").value) +
		"&numChildren412="+escape(document.getElementById("numChildren4-12").value) +
		"&numChildren13up="+escape(document.getElementById("numChildren13up").value) +
		"&requirements="+escape(document.getElementById("requirements").value);		 

	if (document.getElementById("hotel").type=='hidden') {

		params = params + "&hotel="+escape(document.getElementById("hotel").value);

	}
	else
	{

		params = params +  "&hotel="+escape(document.getElementById("hotel").options[document.getElementById("hotel").selectedIndex].value);
				
	}


			
	xhttp.open("POST", "/scripts/validate.php", false);

	//Send the proper header information along with the request
	xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xhttp.setRequestHeader("Content-length", params.length);
	xhttp.setRequestHeader("Connection", "close");
	xhttp.send(params);

	var xmlDoc=xhttp.responseXML;
	
	if(xmlDoc.getElementsByTagName("captchaError")[0]) 
		var captchaError=xmlDoc.getElementsByTagName("captchaError")[0].firstChild.nodeValue;
	
	markError("captchaLabel", (captchaError!=null));
	
	if (captchaError!=null) {
	
		Recaptcha.reload();
	
	}
		
	if (xmlDoc.getElementsByTagName("nameError")[0])
		var nameError=xmlDoc.getElementsByTagName("nameError")[0].firstChild.nodeValue;
	
	markError("nameLabel", (nameError!=null));

	if (xmlDoc.getElementsByTagName("emailError")[0]) 
		var emailError=xmlDoc.getElementsByTagName("emailError")[0].firstChild.nodeValue;

	markError("emailLabel", (emailError!=null));

	
	if (document.getElementById("hotel").type!='hidden') {
	
		if (xmlDoc.getElementsByTagName("hotelError")[0]) 
			var hotelError=xmlDoc.getElementsByTagName("hotelError")[0].firstChild.nodeValue;		
		
		markError("hotelLabel", (hotelError!=null));
		
	}
	
	
	if (xmlDoc.getElementsByTagName("dateError")[0]) 
		var dateError=xmlDoc.getElementsByTagName("dateError")[0].firstChild.nodeValue;
		
	markError("arrivalDateLabel", (dateError!=null));
		

	if (xmlDoc.getElementsByTagName("telephoneError")[0]) 
		var telephoneError=xmlDoc.getElementsByTagName("telephoneError")[0].firstChild.nodeValue;
		
	markError("telephoneLabel", (telephoneError!=null));
	
	
		
	if (xmlDoc.getElementsByTagName("countryError")[0]) 
		var countryError=xmlDoc.getElementsByTagName("countryError")[0].firstChild.nodeValue;
		
	markError("countryLabel", (countryError!=null));

	if (xmlDoc.getElementsByTagName("numNightsError")[0]) 
		var numNightsError=xmlDoc.getElementsByTagName("numNightsError")[0].firstChild.nodeValue;
		
	markError("numNightsLabel", (numNightsError!=null));
	

	if (xmlDoc.getElementsByTagName("numAdultsError")[0]) 
		var numAdultsError=xmlDoc.getElementsByTagName("numAdultsError")[0].firstChild.nodeValue;
	
	markError("numAdultsLabel", (numAdultsError!=null));
		
		 
	if (xmlDoc.getElementsByTagName("noErrors")[0])
		displaySuccess();
	
}	

