function addMultiDestination() 
{
  var ni = document.getElementById('multiDestinations');
  var numi = document.getElementById('theValue');
  var num = parseInt(document.getElementById('theValue').value);
  num++;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = "<input type='text' name='multiDestination_" + num + "' /> <a title='Remove Stop' href='#' onclick='removeMultiDestination(\"" + divIdName + "\")'>remove</a> &nbsp;&nbsp; <a title='Add a Stop' href='#' onclick='addMultiDestination()'>add</a>";
  ni.appendChild(newdiv);
}

function removeMultiDestination(divNum) 
{
	var d = document.getElementById('multiDestinations');
	var olddiv = document.getElementById(divNum);
	d.removeChild(olddiv);
	document.getElementById('theValue').value = parseInt(document.getElementById('theValue').value - 1);

	if (document.getElementById('theValue').value == 0)
	{
		document.getElementById('multiDestinationRow').style.display = 'none';
	}
		
}

function selectTripType()
{
	document.getElementById('multiDestinations').innerHTML = '';
	document.getElementById('theValue').value = 0;

	var value = document.getElementById('trip_type').value;
	if (value == 'multi_stop')
	{
		document.getElementById('multiDestinationRow').style.display = '';
		addMultiDestination();
	}
	else
	{
		document.getElementById('multiDestinationRow').style.display = 'none';
	}
	if (value == 'round_trip')
	{
		document.getElementById('multiDestinationRow1').style.display = '';
		addMultiDestination();
	}
	else
	{
		document.getElementById('multiDestinationRow1').style.display = 'none';
	}
}

function showthevalue()
{
	alert(document.getElementById('theValue').value);
}

function validateForm()
{
	var errors = '';
	var error_count = 0;

	if (document.getElementById('title').value.length < 1)
	{
		errors += "You have omitted your title\n";
		error_count++;
	}

	if (document.getElementById('name').value.length < 1)
	{
		errors += "You have omitted your name\n";
		error_count++;
	}

	if (document.getElementById('company').value.length < 1)
	{
		errors += "You have omitted your company\n";
		error_count++;
	}

	if (document.getElementById('telephone').value.length < 1)
	{
		errors += "You have omitted your telephone\n";
		error_count++;
	}

	if (document.getElementById('email').value.length < 1)
	{
		errors += "You have omitted your email address\n";
		error_count++;
	}

	if (document.getElementById('trip_type').value.length < 1)
	{
		errors += "You have omitted the type of trip you will be taking\n";
		error_count++;
	}

	if (document.getElementById('departure_date').value.length < 1)
	{
		errors += "You have omitted the departure date\n";
		error_count++;
	}

	if (document.getElementById('departure_time').value.length < 1)
	{
		errors += "You have omitted the departure time\n";
		error_count++;
	}



	if (document.getElementById('passengers').value.length < 1)
	{
		errors += "You have omitted the number of passengers travelling\n";
		error_count++;
	}
	else
	{
		if (isNaN(parseInt(document.getElementById('passengers').value)))
		{
			errors += "The number of passengers should be numeric\n";
			error_count++;
		}
	}

	if (error_count > 0)
	{
		alert("The following " + error_count + " errors occured:\n\n" + errors);
		return false;
	}

	return true;
}