function ClearSelection()
{
	var f = document.QuoteRequestForm;

	f.QuoteStep.value = '1';
	f.IsPostback.value = "Yes";
	f.ClearSelection.value = '1';
	
	f.submit();
}

function nextStep()
{
	var strMsg = '';
	var f = document.QuoteRequestForm;

	if( quoteStep == 1 )
	{
		if( f.txtFirstname.value == '' ) strMsg += '\n* first name';
		if( f.txtSurname.value == '' ) strMsg += '\n* surname';

		if( f.txtEmail.value == '' || !isEmail(f.txtEmail.value))
		{
			strMsg += '\n* a valid email address';
		}
		else if( f.txtEmail.value != f.txtEmail2.value)
		{
			strMsg += '\n* "your email address" and "repeat your email address" must match';
		}

		if( $('#ContactByTel').is(':checked') ){
			if( f.txtContactTel.value == '' ){
				strMsg += '\n* contact phone number';
			}
		}
		
		if( f.txtNumPpl.value == '' || f.txtNumPpl.value =='0')
		{
			strMsg += '\n* total number of people';
		}
		else if (isNaN(f.txtNumPpl.value))
		{
			strMsg += '\n* numeric value for the total number of people';
		}

		if( f.txtabove12.value == '' || f.txtchildren.value == '' || f.txtinfants.value == '')
		{
			if (f.txtabove12.value == '') strMsg += '\n* number of adults';
			if (f.txtchildren.value == '') strMsg += '\n* number of children';
			if (f.txtinfants.value == '') strMsg += '\n* number of infants';
		}
		else
		{
			var totalPeople = 0;
		
			if(isNaN(f.txtabove12.value))
				strMsg += '\n* numeric value for the number of adults';
			else
				totalPeople += parseInt(f.txtabove12.value);
			
			if(isNaN(f.txtchildren.value))
				strMsg += '\n* numeric value for the number of children';
			else
				totalPeople += parseInt(f.txtchildren.value);
			
			if(isNaN(f.txtinfants.value))
				strMsg += '\n* numeric value for the number of infants';
			else
				totalPeople += parseInt(f.txtinfants.value);

			if (totalPeople != parseInt(f.txtNumPpl.value))
				strMsg += '\n* total number of people must be equal to total of\n  children, infants and adults ';
		}

		if( f.rdoSeason ) // season selection is not available if coming from search results
		{
			if( ! $('#rdoSummerSeason').is(':checked') && ! $('#rdoWinterSeason').is(':checked') ){ // f.rdoSeason.value == undefined ){
				strMsg += '\n* winter or summer season';
			}
		}

		if( f.lstFromDateSummer || f.lstFromDateWinter ){ // not defined if from search results	
			if( $('#rdoSummerSeason').is(':checked') && f.lstFromDateSummer.value == '-1' ){
				strMsg += '\n* accommodation from date';
			}

			if(  $('#rdoWinterSeason').is(':checked') && f.lstFromDateWinter.value == '-1' ){ 
				strMsg += '\n* accommodation from date';
			}
		}
		
		// if( f.lstFromDate.value == '-1' ) strMsg += '\n* accommodation start date';

		if( f.txtNumNights.value == '' ) {
			strMsg += '\n* number of nights';
		}
		else if ( isNaN(f.txtNumNights.value) ) {
			strMsg += '\n* numeric value for number of nights';
		}

		if( f.resort.selectedIndex == 0 ) strMsg += '\n* select a resort';
		if( f.bedrooms.selectedIndex == 0 ) strMsg += '\n* select no of bedrooms';

		if (getRadioButtonValue(f.AlternativeWeekConsidered) == '') {
			strMsg += "\n* whether or not you would consider alternative weeks"
		}
		
		var $secondYes = $('#SecondAlternativeYes');
		
		if( $secondYes.is(':visible') &&  !$secondYes.is(':checked') && !$('#SecondAlternativeNo').is(':checked') ){
			strMsg += '\n* whether or not you would consider alternative accommodation';
		}
	}
	else if( quoteStep == 2 )
	{
		var ferry = getRadioButtonValue(f.ferry);
		var holidayInsurance = getRadioButtonValue(f.holidayinsurance);
		var skiExtras = getRadioButtonValue(f.SkiExtras);

		if( ferry == '' ) strMsg += '\n* Accommodation only or Ferry';

		if (ferry == 'yes' && f.txtCarrier.value == '' ) strMsg += '\n* Please choose a Carrier';

		if (f.chkCar.checked)
		{
			if (f.txtCollectionPoint.value == '') strMsg += '\n* Collection Point';

			if (f.txtCarType.value == '') strMsg += '\n* Car Type';

			if (f.chkAirportTransfer.checked && f.txtAirportName.value == '') strMsg += '\n* Arrival Airport';

			if (f.chkAirportTransfer.checked && f.lstNumAirportTransferPassengers.value == '') strMsg += '\n* Number of Passengers';
		}

		if( holidayInsurance == '' ) strMsg += '\n* Holiday insurance required?';

		if( skiExtras == '' ) strMsg += '\n* Ski equipment required?';
			
		// Validate the address if a brochure has been requested
		if( $('#chkWinterBrochure').is(':checked') ||  $('#chkSummerBrochure').is(':checked') ){
			if( $('#txtAddress').val() == '' ) strMsg += '\n* address';
			if( $('#txtPostcode').val() == '' ) strMsg += '\n* postcode';
		}
			
		if( f.HearAboutUs.selectedIndex <= 0 ){
			strMsg += '\n* Select how you heard about us.';
		}
		else if( f.HearAboutUs.options[f.HearAboutUs.selectedIndex].value == 'Other' && f.OtherAboutUs.value == '' ){
			strMsg += '\n* Select how you heard about us.';
		}
	} // End of quoteStep == 2

	if( strMsg != '' ) 
	{
		alert('Please supply the following:' + strMsg);
	}
	else
	{
		f.submit();
	}

		// if(f.confirmmailinglist.checked)
			// {
			// }

}

function clearIf(obj, defaultText)
{
	if( obj.value == defaultText )
	{
		obj.value = '';
		$(obj).removeClass('sampleText');
	}
}

function setIfBlank(obj,  exampleVal)
{
	if( obj.value == '' )
	{
		obj.value = exampleVal;
		$(obj).addClass('sampleText');
	}
}

function getAccomJson_Complete(data){
	var $ddl = $('#Accommodation');
	
	$ddl.children('option').remove()
	$ddl.append($('<option />').val(-1).text('...'));

	$(data).each(function(){
		$ddl.append($('<option />').val(this.ID).text(this.Name));
	});
	
	$ddl.show();
	$('#LoadingAccommodation').hide();
}

function getAccomJson(resortId, summer)
{
	$('#AccommodationSelection').show();
	$('#LoadingAccommodation').show();
	$('#Accommodation').hide();

	if( summer )
	{
		$.getJSON("GetAccomListJson.cfm?Summer=1&ResortId=" + resortId, null, function(data) { getAccomJson_Complete(data) });
	}
	else{
		$.getJSON("GetAccomListJson.cfm?Winter=1&ResortId=" + resortId, null, function(data) { getAccomJson_Complete(data) });
	}
}

function getAccomJson2_Complete(data){
	var $ddl = $('#Accommodation2');
	
	$ddl.children('option').remove()
	$ddl.append($('<option />').val(-1).text('...'));
	
	$(data).each(function(){
		$ddl.append($('<option />').val(this.ID).text(this.Name));
	});
	
	$ddl.show();
	$('#LoadingAccommodation2').hide();
}

function getAccomJson2(resortId, summer)
{
	$('#AccommodationSelection2').show();
	$('#LoadingAccommodation2').show();
	$('#Accommodation2').hide();

	if( summer )
	{
		$.getJSON("GetAccomListJson.cfm?Summer=1&ResortId=" + resortId, null, function(data) { getAccomJson2_Complete(data) });
	}
	else{
		$.getJSON("GetAccomListJson.cfm?Winter=1&ResortId=" + resortId, null, function(data) { getAccomJson2_Complete(data) });
	}
}

function resort_change(){
	var resortId = $('#resort').val();
	
	if( resortId != -1 ){
		getAccomJson(resortId, flgSummerSection);
	}
	else{
		$('#AccommodationSelection').hide();
		$('#LoadingAccommodation').hide();
		$('#Accommodation').hide();
	}
}

function Accommodation_change(){
	var accommodation = $('#Accommodation').val();
	var $ddlChoice = $('#ChoiceOfAccommSelection');

	if( accommodation == -1 ){
		$ddlChoice.show();
	}
	else{
		$ddlChoice.hide();
	}
}

function resort2_change(){
	var resortId = $('#resort2').val();
	
	if( resortId != -1 ){
		getAccomJson2(resortId, flgSummerSection);
	}
	else{
		$('#AccommodationSelection2').hide();
		$('#LoadingAccommodation2').hide();
		$('#Accommodation2').hide();
	}
}

function Accommodation2_change(){
	var accommodation = $('#Accommodation2').val();
	var $ddlChoice = $('#ChoiceOfAccommSelection2');

	if( accommodation == -1 ){
		$ddlChoice.show();
	}
	else{
		$ddlChoice.hide();
	}
}

function showAlternativeResort(visible){

	if( visible )
	{
		$('#AltAccommodationSelection').show();
	}
	else
	{
		$('#AltAccommodationSelection').hide();
	}
}

function showHideCarrierNumCars(){

	var chk = $('#rdoFerryNo').attr('checked');
	
	if( chk )
	{
		$('#divCarrierRoute').hide();
		$('#divNumCars').hide();
	}
	else
	{
		$('#divCarrierRoute').show();
		$('#divNumCars').show();
	}
}

 function setAddressVisiblility(){
	if( $('#chkWinterBrochure').is(':checked') ||  $('#chkSummerBrochure').is(':checked') ){
		$('#divBrochureAddress').show();
	}
	else{
		$('#divBrochureAddress').hide();
	}
}


function showAccomInfo()
{
	var url = 'GetAccomSummaryAjax.cfm?id=' + $('#txtAccommodationId').val();
	
	$('#accomInfoDiv').load(url);
	
	//$('#accomInfoDiv').show();
	$('#accomInfoDiv').toggle();
	
	return false;
}

function hideAccomInfo()
{
	$('#accomInfoDiv').hide();
}

function toggleSeasonDropDown(){
	if($('#rdoSummerSeason').is(':checked') ){
		$('#divDateSelection').show();
		$('#divFromLabel').show();
		$('#lstFromDateSummer').show();
		$('#lstFromDateWinter').hide();
	}

	if($('#rdoWinterSeason').is(':checked') ){
		$('#divDateSelection').show();
		$('#divFromLabel').show();
		$('#lstFromDateWinter').show();
		$('#lstFromDateSummer').hide();
	}
}

function quoteRequestDocumentReady()
{
	$('#resort').change(resort_change);
	$('#Accommodation').change(Accommodation_change);
	
	 $('#resort2').change(resort2_change);
	 $('#Accommodation2').change(Accommodation2_change);
	
	$('#SecondAlternativeYes').click(function(){ showAlternativeResort(true); });
	$('#SecondAlternativeNo').click(function(){ showAlternativeResort(false); });
	
	$('#txtCarrier').change(function(e) { 
		$('#rdoFerryYes').attr('checked', 'checked'); 

		var v = $('#txtCarrier').val();
		
		if( v == 'Other e.g Eurostar Passenger Train' ){
			$('#divOtherCarrier').show();
		}
		else{
			$('#divOtherCarrier').hide();
		}
		
		});
	
	$('#rdoFerryNo').click(showHideCarrierNumCars);
	$('#rdoFerryYes').click(showHideCarrierNumCars);
	
	$('input.sampleText').focus(function(event){ 
		var $obj = $(event.target);
		
		if( $obj.val() == $obj.attr('title') )
		{
			$obj.val('');
			$obj.removeClass('sampleText');
		}
	});
	
	$('input.sampleText').blur(function(event){ 
		var $obj = $(event.target);
		
		if( $obj.val() == '' )
		{
			$obj.val($obj.attr('title'));
			$obj.addClass('sampleText');
		}
	});

	$('#chkWinterBrochure').click(setAddressVisiblility);
	$('#chkSummerBrochure').click(setAddressVisiblility);

//	$('#accomInfoLink').hover(showAccomInfo, hideAccomInfo);
	$('#accomInfoLink').click(showAccomInfo); //, hideAccomInfo);

	$('#rdoSummerSeason').click(function(){ toggleSeasonDropDown(); });
	$('#rdoWinterSeason').click(function(){ toggleSeasonDropDown(); });

	$('textarea[maxlength]').keyup(function(){
		var max = parseInt($(this).attr('maxlength'));
		if($(this).val().length > max){
		    $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
		}
		$(this).parent().parent().find('.charsRemaining').html('(' + (max - $(this).val().length) + ' characters remaining' + ')');
	    });
}

