// DL10Bookings.js
//
// Copyright © 2007 DL10 Design Limited. All Rights Reserved.
//
// 8 April 2007


// Booking Functions

function submitForm( elementName )
{

	var element = document.getElementById( elementName );
	
	if ( element.onsubmit() ) {
	
		element.submit();
		
	}

}
function isValid( fieldObj, errorMsg, type )
{

	if ( type == 'select' )
	{
		
		if( fieldObj.options[ fieldObj.selectedIndex ].text.length == 0 || fieldObj.selectedIndex == 0 )
		{
		
			if ( errorMsg.length > 0 )
			{
				
				alert( errorMsg );
				
			}
		
			fieldObj.focus();
			return false;
			
		}
       
    }
    else
    {
    
    	if( fieldObj.value.length == 0 )
    	{
    	
    		if ( errorMsg.length > 0 )
    		{
    		
    			alert( errorMsg );
    		
    		}
    		
    		fieldObj.focus();
			return false;
			
		}
	}
	
	return true;
}
function validateBooking( element )
{

	var reEmail = /^.+\@.+\..+$/
	
	if ( !isValid( element.booking_name, "Your Name is a required field" ) )
	{
	
		return false;
		
	}
	
	if ( !isValid( element.booking_lastname, "Your Surname is a required field" ) )
	{
	
		return false;
		
	}
	
	if ( !isValid( element.booking_telephone, "Your Telephone is a required field" ) )
	{

		return false;
		
	}
	
	
		
	if ( !isValid( element.booking_email, "Your e-Mail Address is a required field" ) )
	{

		return false;
		
	} else {
		
		if ( !reEmail.test( element.booking_email.value ) )
		{
		
			alert( "A valid e-Mail Address is required" );
			return false;
		
		}
		
	}
	
	
	if ( !isValid( element.booking_arrive, "You need to enter a date that you would like to arrive." ) )
	{

		return false;
		
	}
	
	if ( !isValid( element.booking_depart, "You need to enter a date that you would like to leave." ) )
	{

		return false;
		
	}
	
	if ( !isValid( element.booking_guests, "You need to specify the number of guests who will be visiting." ) )
	{

		return false;
		
	}

	return true;
	
}
