﻿


// When DOM ready...
window.addEvent('domready', function()
{


	
	// Smoothscroll
	var smoothscroll = new SmoothScroll();
	
	
	
	// Window Scroll
	var scroll = new Fx.Scroll(window,
	{
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	
	
	// Pricing Menu Form
	if ($("pricingmenuselect") != null && $("pricingmenuoutput") != null)
	{
	
		var price = $('pricingmenuselect').value;
		if (price != '')
		{
			$("pricingmenuoutput").empty();
			$("pricingmenuoutput").appendText("Price: " + price);
		}
		
		$('pricingmenuselect').addEvent('change', function(e)
		{
			e = new Event(e);
			
			var price = this.value;
			
			if (price == '')
			{
				price = "Please call";
			}
			
			$("pricingmenuoutput").empty();
			$("pricingmenuoutput").appendText("Price: " + price);
			e.stop();
		});
	}
	
	
	
	// Pricing Menu Form
	if ($("TravellingToCountry") != null && $("pricingmenuoutput") != null)
	{
	
		var code = $('TravellingToCountry').value;
		var price = '';
		if (code != '')
		{
			$each($$('#TravellingToCountry option'), function(day, index)
			{
				if (code == day.value)
				{
					price = $(day).getProperty('price');
				}
			});
		}
		
		if (price != '')
		{
			$("pricingmenuoutput").empty();
			//$("pricingmenuoutput").appendText("Price: " + price);
		}
		
		$('TravellingToCountry').addEvent('change', function(e)
		{
			e = new Event(e);
			
			var code = this.value;
			
			if (code == '')
			{
				price = "Please call";
			}
			else
			{
				$each($$('#TravellingToCountry option'), function(day, index)
				{
					if (code == day.value)
					{
						price = $(day).getProperty('price');
					}
				});
			}
			
			$("pricingmenuoutput").empty();
			//$("pricingmenuoutput").appendText("Price: " + price);
			
			
			e.stop();
		});
	}
	
	
	
	// Book a Collection Form
	if ($("BookACollectionForm") != null)
	{
	
		var mySlide = new Fx.Slide('ExistingCorporateAccountSlider');
		if (!$('TravellingForBusiness').checked)
		{
			mySlide.hide();
		}
		
		var errorsSlide = new Fx.Slide('BookACollectionFormErrors');
		if (!$$('#BookACollectionFormErrors ul'))
		{
			errorsSlide.hide();
		}
		
		if ($('Title').value != "Other")
		{
			$('TitleOther').value = "";
			$('TitleOther').setStyle('visibility', 'hidden');
		}
		
		$('TravellingForBusiness').addEvent('click', function(e)
		{
			e = new Event(e);
			mySlide.slideIn();
			
			$("pricingmenuoutputext").empty();
			//$("pricingmenuoutputext").appendText("* displayed price is the average cost for a business visa to your chosen destination. Your personnel Visa Butler will confirm price on application.");
			
		});
		
		$('Title').addEvent('change', function(e)
		{
			e = new Event(e);
			if ($('Title').value != "Other")
			{
				$('TitleOther').value = "";
				$('TitleOther').setStyle('visibility', 'hidden');
			}
			else
			{
				$('TitleOther').setStyle('visibility', 'visible');
				$('TitleOther').focus();
			}
		});
		
		$('TravellingForPleasure').addEvent('click', function(e)
		{
			e = new Event(e);
			mySlide.slideOut();	
			$('ExistingCorporateAccountYes').checked = false;
			$('ExistingCorporateAccountNo').checked = false;
			$('CompanyName').value = "";
			
			$("pricingmenuoutputext").empty();
			//$("pricingmenuoutputext").appendText("* displayed price is based on the most common tourist visa to your destination. Your personnel Visa Butler will confirm price on application.");
			
		});
		
		$('BookACollectionForm').addEvent('submit', function(e)
		{
			e = new Event(e);
			errors = new Array();
			
			// Check for errors
			if ($('TravellingToCountry').value == "" && !$('MultipleDestinations').checked)
				errors.push("Please select the country you are travelling to.");
			if ($('PassportIssuedBy').value == "")
				errors.push("Please select the country your passport is issued by.");
			if (!$('TravellingForPleasure').checked && !$('TravellingForBusiness').checked)
				errors.push("Are you travelling for pleasure or business?");
			if ($('TravellingForBusiness').checked)
			{
				if (!$('ExistingCorporateAccountNo').checked && !$('ExistingCorporateAccountYes').checked)
					errors.push("Do you have an existing corporate account?");
				if ($('CompanyName').value == "")
					errors.push("Please enter your company name.")
			}
			if ($('Title').value == "")
				errors.push("Please select your title.")
			if ($('Title').value == "Other" && $('TitleOther').value == "")
				errors.push("Please enter your title.")
			if ($('FirstName').value == "")
				errors.push("Please enter your first name.");
			if ($('Surname').value == "")
				errors.push("Please enter your surname.");
			if ($('Telephone').value == "")
				errors.push("Please enter your telephone number.");
			if ($('Email').value == "")
				errors.push("Please enter your email.");
			/*
			if ($('Address1').value == "")
				errors.push("Please enter your address.");
			*/
			if ($('Town').value == "")
				errors.push("Please enter your town.");
			/*
			if ($('County').value == "")
				errors.push("Please enter your county.");
			*/
			if ($('Postcode').value == "")
				errors.push("Please enter your postcode.");
			if (!$('PhotographicServiceRequiredNo').checked && !$('PhotographicServiceRequiredYes').checked)
				errors.push("Is our photographic service required?");
				
			
			if (errors.length > 0)
			{
				output = "";
				for (i = 0; i < errors.length; i++)
				{
					output += "<li>" + errors[i] + "<li>";
				}
				$('BookACollectionFormErrors').setHTML("");
				$('BookACollectionFormErrors').setHTML('<ul class="error">' + output + "</ul>");
				errorsSlide.slideIn();
				
				scroll.toTop();
				e.stop();
			}
			
		});
		
	}
	
	

});