
function GotoLocation(link){
 	DispWin = window.open(link,'Pwindow','width=495,height=700,toolbar=no,scrollbars=yes,resizable=yes,status=no,directories=no,location=yes,menubar=no,titlebar=no');
}

function miniPage(link){
 	DispWin = window.open(link,'Pwindow','width=495,height=700,toolbar=no,scrollbars=yes,resizable=yes,status=no,directories=no,location=no,menubar=no,titlebar=no');
}

function isNumeric( objElement )
{ 
	var varElement = objElement.value ;
	if( varElement.length > 0 )
	{
		var varChar = varElement.slice( varElement.length - 1, varElement.length ) ;
		if( isNaN(parseInt(varChar)) )
		{
			alert("Only numbers (0-9) are allowed here.") ;
			varElement = varElement.slice(0,varElement.length-1) ;
			objElement.value = varElement ;
		}
	}
}

function getSelectValue( objSelect )
{
	var varValue = objSelect.options[objSelect.selectedIndex].value ;
	return varValue ;
}

// Return true if strText is empty or contains only spaces
function isBlank( strText )
{ 
	if( strText.length == 0 ) { return true ; }
	for( var intPos = 0 ; intPos < strText.length ; intPos ++ )
	{
		if( strText.charCodeAt(intPos) != 32 ) { return false ; }
	}
	return true ;
}

var urlTarget = 0;

function submitCHK( objForm )
{ 
	// if the recalculate button is clicked - post data back to reservation form to recalculate
	if(urlTarget == 1) { document.reserve.action="commercial-vehicle-hire-truck-rental.php"; document.reserve.submit(); }
	else {

// Check name is entered
		if( objForm.Firstname.value.length < 1 || isBlank(objForm.Firstname.value) )
		{
			alert("Please enter your contact name.");
			objForm.Firstname.focus() ;
			return false ;
		}

// Check name is entered
		if( objForm.Lastname.value.length < 1 || isBlank(objForm.Lastname.value) )
		{
			alert("Please enter your last name.");
			objForm.Lastname.focus() ;
			return false ;
		}

// Check Telephone is entered
		if( objForm.Telephone.value.length < 1 || isBlank(objForm.Telephone.value) )
		{
			alert("Please enter your telephone number.");
			objForm.Telephone.focus() ;
			return false ;
		}

// Check Email is entered
		if( objForm.Email.value.length < 1 || isBlank(objForm.Email.value) )
		{
			alert("Please enter your email address.");
			objForm.Email.focus() ;
			return false ;
		}

// Check age is entered
		if( objForm.driver_age[0].checked == false && objForm.driver_age[1].checked == false )
		{
			alert("Please enter your driver's age.");
			objForm.driver_age[0].focus();
			return false ;
		}

// Check Light Rigid licence is checked
		if( objForm.Light_rigid_licence && objForm.Light_rigid_licence[0].checked == false && objForm.Light_rigid_licence[1].checked == false )
		{
			alert("Please let us know if you have a Light Rigid licence.");
			objForm.Light_rigid_licence[0].focus() ;
			return false ;
		}

// Check if agreement is checked
		if( objForm.agreement.checked == false )
		{
			alert ('\nBefore continuing, please indicate that you agree to the \nterms and conditions by clicking the box.\n')
			return false
		}

// Confirm license requirement for vehicle type
		if( objForm.vehicle_type.value == '21 Seater' )
		{
			alert('\nWhen booking a 21 seater, the driver\nmust hold a current light rigid licence.\n')
		}

	} // else end for recalculate
	
	if(urlTarget == 0) { document.reserve.action="../scripts/booking.php"; document.reserve.submit(); }
}


function goScript(target){
// the next 3 lines are the main lines of this script
// remember to leave action field blank when defining the form 
	urlTarget = target;
	// if(urlTarget == 0) document.reserve.action="../scripts/booking.php";
	if(urlTarget == 1) document.reserve.action="commercial-vehicle-hire-truck-rental.php"; document.reserve.submit();
}

function noLocationSet(LocationType,LocationOption) {
	var stateVal = /--(\w+)/;
	// var text = document.quote_form.elements[StateLocation].selected.value;
	var result = LocationOption.match(stateVal); 
	if (result != null) { 
		alert("Please choose a specific location in this state.");
		document.quote_form.elements[LocationType].options[0].selected=true; // Contains "--" in location choice 
	}
	changeDropOff();
}

function checkSameState(LocationType,LocationOption) {
	var pickUpLocation = document.quote_form.pickup_location.value;
	var dropOffLocation = document.quote_form.dropoff_location.value;
	
	// locations must be in the same state
	if ( ( pickUpLocation == 37 || pickUpLocation == 38 || pickUpLocation == 39 || pickUpLocation == 40 ) && pickUpLocation != dropOffLocation ) { 
		alert("Drop off must be the same location as Pick Up in this state.");
		changeDropOff();
	}

	if ( ( dropOffLocation == 37 || dropOffLocation == 38 || dropOffLocation == 39 || dropOffLocation == 40 ) && pickUpLocation != dropOffLocation ) { 
		alert("Drop off must be the same location as Pick Up in this state.");
		changeDropOff();
	}

	var stateVal = /--(\w+)/;
	// var text = document.quote_form.elements[StateLocation].selected.value;
	var result = LocationOption.match(stateVal); 
	if (result != null) { 
		alert("Please choose a specific location in this state.");
		document.quote_form.elements[LocationType].options[0].selected=true; // Contains "--" in location choice 
		changeDropOff();
	}

}
