//###########################################################
//###########################################################
function toogle_divs(div_id){

switch(div_id){

case 1:
document.getElementById("div_1").style.display = "block";
document.getElementById("div_2").style.display = "none";
document.getElementById("div_3").style.display = "none";
document.getElementById("div_4").style.display = "none";

document.getElementById("step_1").className = "step_on";
document.getElementById("step_2").className = "step_off";
document.getElementById("step_3").className = "step_off";
document.getElementById("step_4").className = "step_off";

break;

case 2:
document.getElementById("div_1").style.display = "none";
document.getElementById("div_2").style.display = "block";
document.getElementById("div_3").style.display = "none";
document.getElementById("div_4").style.display = "none";

document.getElementById("step_1").className = "step_off";
document.getElementById("step_2").className = "step_on";
document.getElementById("step_3").className = "step_off";
document.getElementById("step_4").className = "step_off";

break;

case 3:
document.getElementById("div_1").style.display = "none";
document.getElementById("div_2").style.display = "none";
document.getElementById("div_3").style.display = "block";
document.getElementById("div_4").style.display = "none";

document.getElementById("step_1").className = "step_off";
document.getElementById("step_2").className = "step_off";
document.getElementById("step_3").className = "step_on";
document.getElementById("step_4").className = "step_off";

break;

case 4:
document.getElementById("div_1").style.display = "none";
document.getElementById("div_2").style.display = "none";
document.getElementById("div_3").style.display = "none";
document.getElementById("div_4").style.display = "block";

document.getElementById("step_1").className = "step_off";
document.getElementById("step_2").className = "step_off";
document.getElementById("step_3").className = "step_off";
document.getElementById("step_4").className = "step_on";

break;

}

}
//###########################################################
//###########################################################
function edit_toogle_divs(div_id){

switch(div_id){


case 2:
document.getElementById("div_2").style.display = "block";
document.getElementById("div_3").style.display = "none";
document.getElementById("div_4").style.display = "none";

document.getElementById("step_2").className = "step_on";
document.getElementById("step_3").className = "step_off";
document.getElementById("step_4").className = "step_off";

break;

case 3:
document.getElementById("div_2").style.display = "none";
document.getElementById("div_3").style.display = "block";
document.getElementById("div_4").style.display = "none";

document.getElementById("step_2").className = "step_off";
document.getElementById("step_3").className = "step_on";
document.getElementById("step_4").className = "step_off";

break;

case 4:
document.getElementById("div_2").style.display = "none";
document.getElementById("div_3").style.display = "none";
document.getElementById("div_4").style.display = "block";

document.getElementById("step_2").className = "step_off";
document.getElementById("step_3").className = "step_off";
document.getElementById("step_4").className = "step_on";

break;

}

}
//###########################################################
//###########################################################
function show_address(type,id){

switch(type){

case "pick_up" :
document.getElementById("pick_up_" + id).style.display = "block";


break;

case "destination" :
document.getElementById("destination_" + id).style.display = "block";

break;


}

}
//###########################################################
//###########################################################
function toggle_return_dates(show){

if(show == "off"){

	document.getElementById("return_dates").style.display = "none";

}
else
{

	document.getElementById("return_dates").style.display = "block";
	
}


}
//###########################################################
//###########################################################
function check_booking(id){


	if(id.user_first_name.value==""){
	
	alert("You must enter your first name");
	toogle_divs(1);
	id.user_first_name.focus();
	return false;
	
	}

	if(id.user_surname.value==""){
	
	alert("You must enter your surname");
	
	toogle_divs(1);
	id.user_surname.focus();

	return false;
	
	}
	
	if(id.user_postcode.value==""){
	
	alert("You must enter your postcode");
	
	toogle_divs(1);
	id.user_postcode.focus();

	return false;
	
	}
	
	if(id.user_address_1.value==""){
	
	alert("You must enter your address");
	
	toogle_divs(1);
	id.user_address_1.focus();

	return false;
	
	}
	
	if(id.user_tel.value==""){
	
	alert("You must enter your telephone number");
	
	toogle_divs(1);
	id.user_tel.focus();

	return false;
	
	}

	if(id.user_email.value==""){
	
	alert("You must enter your email address");
	
	toogle_divs(1);
	id.user_email.focus();
	
	return false;
	
	}
	
	if(!checkMail(id.user_email)){
	
	alert("The email address you have entered does not appear to be valid");
	
	toogle_divs(1);
	id.user_email.focus();

	return false;
	
	}
	
	
	if(id.user_password.value==""){
	
	alert("You must enter a password");
	
	toogle_divs(1);
	id.user_password.focus();
	
	return false;
	
	}
	else
	{
		if(id.user_password.value!=id.confirm_password.value){
		
			alert("Your password and password confirmation do not match");
			
			toogle_divs(1);
			id.user_password.focus();

			return false;

		
		}
	
	}

	
	
	///// check actual booking
	
	if(id.pick_up_address_1.value==""){
	
		alert("You must enter at least one pick up address")
		
		toogle_divs(2);
		id.pick_up_address_1.focus();

		return false;
	
	}
	
	/*
	if(id.pick_up_postcode_1.value==""){
	
		alert("You must enter a postcode for your first pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_1.focus();
		
		return false;
	
	}
	*/
	

/*
	if(id.pick_up_address_2.value!=""){
	
		if(id.pick_up_postcode_2.value==""){
	
		alert("You must enter a postcode for your second pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_2.focus();
		
		return false;
		}
	}

	
	if(id.pick_up_address_3.value!=""){
	
		if(id.pick_up_postcode_3.value==""){
	
		alert("You must enter a postcode for your third pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_3.focus();
		
		return false;
	
	}
	
	}
	*/
	
	
	if(id.destination_address_1.value==""){
	
		alert("You must enter at least one destination address")
		
		toogle_divs(3);
		id.destination_address_1.focus();
		
		return false;
	
	}
	/*
	
	if(id.destination_postcode_1.value==""){
	
		alert("You must enter a postcode for your first destination address")
		
		toogle_divs(3);
		id.destination_postcode_1.focus();
		
		return false;
	
	}


	if(id.destination_address_2.value!=""){
	
		if(id.destination_postcode_2.value==""){
	
		alert("You must enter a postcode for your second destination address")
		
		toogle_divs(3);
		id.destination_postcode_2.focus();
		return false;
		
		}
	
	}

	if(id.destination_address_3.value!=""){
	
		if(id.destination_postcode_3.value==""){
	
		alert("You must enter a postcode for your third destination address")
		
		toogle_divs(3);
		id.destination_postcode_3.focus();
		
		return false;
	
		}
	
	}
	*/
		
	

}
//###########################################################
//###########################################################
function check_quote(id){

var conf = window.confirm("Are you sure you want to send this quote to the customer?");

if(conf){


	if(id.booking_price.value==""||id.booking_price.value=="0.00"||Number(id.booking_price.value)*1==0||isNaN(id.booking_price.value)){
	
		var conf2 = window.confirm("Are you sure you want to send this quote at £0.00?");
		
		//alert("You must enter a cost for this job.");
		if(conf2){
		
		id.booking_price.value=0;
		
		}
		else
		{
		
		return false;
		}
	
	}
	

}
else
{
return false;
}


}
//###########################################################
//###########################################################
function check_allocate_booking(id){

//return false;

if(id.driver_idx.value=="0"){

	alert("You must select a driver to allocate this booking to.");
	return false;

}

if(id.vehicle_idx.value=="0"){

	alert("You must select a vehicle to allocate this booking to.");
	return false;

}

var conf = window.confirm("Are you sure you want to allocate this booking?");

if(!conf){

	return false;

}


}
//###########################################################
//###########################################################
function view_jobs(check_date,driver_idx,vehicle_idx){

//alert(check_date);

var conf = window.confirm("Are you sure you want to view bookings / quotes for " + check_date + "?");

if(conf){

	document.location = "/view_jobs_by_date.asp?check_date=" + check_date + "&driver_idx=" + driver_idx + "&vehicle_idx=" + vehicle_idx;

}

}
//###########################################################
//###########################################################
function check_close_booking(id){

var by_pass_miles = false;

	if(id.booking_closed_hours.value=="0"&&id.booking_closed_miles.value=="0"){
	
		var conf = window.confirm("Are you sure you want to close this booking with 0 hours and 0 miles?");
		
		if(conf){
		
		by_pass_miles = true;
		
		}
		else
		{
		
		return false;
		
		}
	
	}

if(!by_pass_miles){

	if(id.booking_closed_hours.value=="0"||id.booking_closed_hours.value==""||isNaN(id.booking_closed_hours.value)){
	
		alert("You must enter the number of hours spent on this job.");
		id.booking_closed_hours.focus();
		return false;
	
	}
	
	if(id.booking_closed_miles.value=="0"||id.booking_closed_miles.value==""||isNaN(id.booking_closed_miles.value)){
	
		alert("You must enter the number of miles driven on this job.");
		id.booking_closed_miles.focus();
		return false;
	
	}

}	
	
	if(isNaN(id.booking_closed_price.value)||id.booking_closed_price.value==""){
	
		alert("You must enter the final price for this job.");
		id.booking_closed_price.focus();
		return false;
	
	}
	
	var conf = window.confirm("Are you sure you want to close this job?");
	
	if(!conf){
	
	return false;
	
	}


}
//###########################################################
//###########################################################
function check_manual_booking(id){

if(id.existing_user.value=="0"){

	if(id.user_first_name.value==""){
	
	alert("You must enter the customers first name");
	toogle_divs(1);
	id.user_first_name.focus();
	return false;
	
	}

	if(id.user_surname.value==""){
	
	alert("You must enter the customers surname");
	
	toogle_divs(1);
	id.user_surname.focus();

	return false;
	
	}
	
	if(id.user_postcode.value==""){
	
	alert("You must enter the customers postcode");
	
	toogle_divs(1);
	id.user_postcode.focus();

	return false;
	
	}
	
	if(id.user_address_1.value==""){
	
	alert("You must enter the customers address");
	
	toogle_divs(1);
	id.user_address_1.focus();

	return false;
	
	}
	
	if(id.user_tel.value==""){
	
	alert("You must enter the customers telephone number");
	
	toogle_divs(1);
	id.user_tel.focus();

	return false;
	
	}

	if(id.user_email.value==""){
	
	alert("You must enter the customers email address");
	
	toogle_divs(1);
	id.user_email.focus();
	
	return false;
	
	}
	
	if(!checkMail(id.user_email)){
	
	alert("The email address you have entered does not appear to be valid");
	
	toogle_divs(1);
	id.user_email.focus();

	return false;
	
	}
	
	
	if(id.user_password.value==""){
	
	alert("You must enter a password");
	
	toogle_divs(1);
	id.user_password.focus();
	
	return false;
	
	}
	else
	{
		if(id.user_password.value!=id.confirm_password.value){
		
			alert("Your password and password confirmation do not match");
			
			toogle_divs(1);
			id.user_password.focus();

			return false;

		
		}
	
	}

}
	
	
	///// check actual booking
	
	if(id.pick_up_address_1.value==""){
	
		alert("You must enter at least one pick up address")
		
		toogle_divs(2);
		id.pick_up_address_1.focus();

		return false;
	
	}
	
	if(id.pick_up_postcode_1.value==""){
	
		alert("You must enter a postcode for your first pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_1.focus();
		
		return false;
	
	}


	if(id.pick_up_address_2.value!=""){
	
		if(id.pick_up_postcode_2.value==""){
	
		alert("You must enter a postcode for your second pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_2.focus();
		
		return false;
		}
	}

	if(id.pick_up_address_3.value!=""){
	
		if(id.pick_up_postcode_3.value==""){
	
		alert("You must enter a postcode for your third pick up address")
		
		toogle_divs(2);
		id.pick_up_postcode_3.focus();
		
		return false;
	
	}
	
	}
	
	if(id.destination_address_1.value==""){
	
		alert("You must enter at least one destination address")
		
		toogle_divs(3);
		id.destination_address_1.focus();
		
		return false;
	
	}
	if(id.destination_postcode_1.value==""){
	
		alert("You must enter a postcode for your first destination address")
		
		toogle_divs(3);
		id.destination_postcode_1.focus();
		
		return false;
	
	}


	if(id.destination_address_2.value!=""){
	
		if(id.destination_postcode_2.value==""){
	
		alert("You must enter a postcode for your second destination address")
		
		toogle_divs(3);
		id.destination_postcode_2.focus();
		return false;
		
		}
	
	}

	if(id.destination_address_3.value!=""){
	
		if(id.destination_postcode_3.value==""){
	
		alert("You must enter a postcode for your third destination address")
		
		toogle_divs(3);
		id.destination_postcode_3.focus();
		
		return false;
	
		}
	
	}
	
	if(isNaN(id.booking_price.value)){
	
		alert("You must enter a price for this job");
		toogle_divs(4);
		id.booking_price.focus();
		
		return false;
	}
	

}

//###########################################################
//###########################################################
function Add_Job(day,month,year,hour,check_date){

//alert(check_date);

var conf = window.confirm("Are you sure you want to add a job on " + check_date + "?");

if(conf){

	document.location = "/manual_new_booking.asp?pick_up_day=" + day + "&pick_up_month=" + month + "&pick_up_year=" +  year + "&pick_up_hour=" + hour;

}

}

//###########################################################
//###########################################################
function decline_booking(booking_idx){

	var conf = window.confirm("Are you sure you want to decline this booking?");
	
	if(conf){
	
		document.location = "/accept_booking.asp?decline_booking=true&booking_idx=" + booking_idx;
	
	}
	else
	{
	return false;
	}

}
//###########################################################
//###########################################################
function print_booking(booking_idx){

	window.open("/incs/create_booking_pdf.asp?booking_idx=" + booking_idx);

}
//###########################################################
//###########################################################
function check_alter_price(id){

var conf = window.confirm("Are you sure you want to alter the price of this job?");

if(conf){


	if(id.booking_price.value==""||id.booking_price.value=="0.00"||Number(id.booking_price.value)*1==0||isNaN(id.booking_price.value)){
	
		alert("You must enter a cost for this job.");
		id.booking_price.focus();
		return false;
	
	}
	

}
else
{
return false;
}


}

//###########################################################
//###########################################################
function decline_quote(){

var conf = window.confirm("Are you sure you want to decline this quote?");

if(conf){

	document.decline_form.submit();

}

}
//###########################################################
//###########################################################
function load_user_data(id){

var form_id = document.booking_form;

Pgurl = "/functions/user_as_xml.asp?user_idx=" + id.value;
var USERXML = Load_variable_Xml(Pgurl);

var users = USERXML.getElementsByTagName("user");
			
if(users.length>0){
		
			for (var i = 0; i < users.length; i++) {
			
			
				if(users[i].getElementsByTagName("user_title")[0].childNodes[0]){
				
				
					var x = form_id.user_title;
					for (var q = 0; q < x.options.length; q++) 
					{
						if (x.options[q].text == users[i].getElementsByTagName("user_title")[0].childNodes[0].nodeValue)
						{
							//alert(x.options[i].text);
							x.options[q].selected = 'selected';
						}
					}
				
				}
				else
				{
					var x = form_id.user_title;
					for (var q = 0; q < x.options.length; q++) 
					{
						if (x.options[q].text == "")
						{
							//alert(x.options[i].text);
							x.options[q].selected = 'selected';
						}
					}
				}
					
				if(users[i].getElementsByTagName("user_first_name")[0].childNodes[0]){
				
					form_id.user_first_name.value = users[i].getElementsByTagName("user_first_name")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_first_name.value = ""
				}
					
				if(users[i].getElementsByTagName("user_surname")[0].childNodes[0]){
				
					form_id.user_surname.value = users[i].getElementsByTagName("user_surname")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_surname.value = ""
				}
				
				if(users[i].getElementsByTagName("user_address_1")[0].childNodes[0]){
				
					form_id.user_address_1.value = users[i].getElementsByTagName("user_address_1")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_address_1.value = ""
				}
				
				if(users[i].getElementsByTagName("user_postcode")[0].childNodes[0]){
				
					form_id.user_postcode.value = users[i].getElementsByTagName("user_postcode")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_postcode.value = ""
				}
				
				if(users[i].getElementsByTagName("user_email")[0].childNodes[0]){
				
					form_id.user_email.value = users[i].getElementsByTagName("user_email")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_email.value = ""
				}

				if(users[i].getElementsByTagName("user_tel")[0].childNodes[0]){
				
					form_id.user_tel.value = users[i].getElementsByTagName("user_tel")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_tel.value = ""
				}
				
				if(users[i].getElementsByTagName("user_mobile")[0].childNodes[0]){
				
					form_id.user_mobile.value = users[i].getElementsByTagName("user_mobile")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_mobile.value = ""
				}
				
				if(users[i].getElementsByTagName("user_company_name")[0].childNodes[0]){
				
					form_id.user_company_name.value = users[i].getElementsByTagName("user_company_name")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_company_name.value = ""
				}

				if(users[i].getElementsByTagName("user_password")[0].childNodes[0]){
				
					form_id.user_password.value = users[i].getElementsByTagName("user_password")[0].childNodes[0].nodeValue
					form_id.confirm_password.value = users[i].getElementsByTagName("user_password")[0].childNodes[0].nodeValue
				
				}
				else
				{
				form_id.user_password.value = ""
				form_id.confirm_password.value = ""
				}

				if(users[i].getElementsByTagName("user_recieve_sms_alerts")[0].childNodes[0]){
				
				
					if(users[i].getElementsByTagName("user_recieve_sms_alerts")[0].childNodes[0].nodeValue=="1"){
					
					form_id.user_recieve_sms_alerts.checked = true;
					
					}
				
				}
				else
				{
				form_id.user_recieve_sms_alerts.checked = false;
				}
				
	
			}

}
else
{
alert("Unable to find user details")
}
}
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################
//###########################################################


