function checkTheory(){

	var div=document.getElementById('passCertificate');
	var div_theory=document.getElementById('theoryDetails');
	var me=document.forms[0];
	for (i=0;i<me.theoryPassed.length;i++) {
	if (me.theoryPassed[i].checked) {
		user_input = me.theoryPassed[i].value;
		}
	}

	if (user_input == "Yes"){
		div.style.display = "";
		div_theory.style.display = "none";
		me.theoryTest.value = "";
	}
	
	if (user_input == "No"){
		div.style.display = "none";
		div_theory.style.display = "";
		me.theoryCertNo.value = "";
		me.theoryExpDate.value = "";
	}
	
}



function passCertificate(){
	var div=document.getElementById('passCertificate');
	var me=document.forms[0];
		
	if(div.style.display=="none" && me.theoryPassed.checked){
		div.style.display="";
		}
	
	if(div.style.display=="" && !me.theoryPassed.checked){
		div.style.display="none";
		}
}

function notPassed(){
	var div=document.getElementById('theoryNotPassed');
	var me=document.forms[0];
	//var chk=document.getElementById('theoryPassedNo');
	
	if(div.style.display=="none" && me.theoryPassedNo.checked){
		div.style.display="";
		//chk.checked=false;
	}
	
	if(div.style.display=="" && !me.theoryPassedNo.checked){
		div.style.display="none";
		//chk.checked=true;
	}
}

function getDriverDOB(){

	// gets first digits of driver number
	var me=document.form1;
	var first_digits,second_digits,third_digits;
	var d1,d2,d3,d4,p1,p2;
	
	if(!verifyDriverDetails()){
		first_digits=me.surname.value;
		first_digits=(first_digits.substr(0,5));
		f_length=first_digits.length;
		y=5-f_length;
		
		if (f_length<5){
			for (x = 1; x <= y; x++){
			   first_digits=first_digits+"9";
			}
		}
		
		me.dnum1.value=first_digits.toUpperCase();
	
		// gets second set of driver number digits
		d1=me.yy.value.substr(0,1);
		d4=me.yy.value.substr(1,2);
		d2=parseInt(me.mm.value,10);
		d3=me.dd.value;
		
		//test gender...
		if (me.title.value!="Mr"){
			if (d2<10){
				first_split="5";
			}else{
				first_split="6";
			}		
		}else{
			if(d2<10){	
				first_split="0";
			}
		}
		d2=first_split+String(d2);
		second_digits=d1+d2+d3+d4;
		
		me.dnum2.value=second_digits;
		
		
		// gets last two digits of driver number
		
		p1=me.firstname.value.substr(0,1);
		p1=p1.toUpperCase();
		
		p2=me.initials.value.substr(0,1);
		p2=p2.toUpperCase();
		
		if (p2.length<1){
			p2="9";
		}
		
		third_digits=p1+p2;
		me.dnum3.value=third_digits;
		
		}
		
}



function verifyDriverDetails(){
	

}




function price_calc(){
	
var me=document.forms[0];
var accom="";
for (var i=0; i < me.req_Accom.length; i++)
   {
   if (me.req_Accom[i].checked)
      {
      accom = me.req_Accom[i].value;
      }
   }

var courseLength=me.course_length.value;

// work prices out - change as appropriate


var total_price="355.00";

if (courseLength == 3 && accom == "Y"){
	total_price="355.00";
}
if (courseLength == 3 && accom == "N"){
	total_price="310.00";
}

if (courseLength == 4 && accom == "Y"){
	total_price="445.00";
}
if (courseLength == 4 && accom == "N"){
	total_price="385.00";
}

if (courseLength == 5 && accom == "Y"){
	total_price="545.00";
}
if (courseLength == 5 && accom == "N"){
	total_price="470.00";
}

if (courseLength == 6 && accom == "Y"){
	total_price="629.00";
}
if (courseLength == 6 && accom == "N"){
	total_price="539.00";
}

if (courseLength == 7 && accom == "Y"){
	total_price="729.00";
}
if (courseLength == 7 && accom == "N"){
	total_price="624.00";
}

if (courseLength == 8 && accom == "Y"){
	total_price="829.00";
}
if (courseLength == 8 && accom == "N"){
	total_price="709.00";
}

if (courseLength == 9 && accom == "Y"){
	total_price="929.00";
}
if (courseLength == 9 && accom == "N"){
	total_price="794.00";
}

if (courseLength == 10 && accom == "Y"){
	total_price="1029.00";
}
if (courseLength == 10 && accom == "N"){
	total_price="879.00";
}

if (courseLength == 12 && accom == "Y"){
	total_price="1197.00";
}
if (courseLength == 12 && accom == "N"){
	total_price="1017.00";
}

if (courseLength == 14 && accom == "Y"){
	total_price="1397.00";
}
if (courseLength == 14 && accom == "N"){
	total_price="1217.00";
}

me.total_price.value = total_price;

}


function highlightField(fieldName){
	var f_name = document.getElementById(fieldName);
	f_name.style.border = "2px solid #307D7E";
	return false;
}

function clearField(fieldName){
	var f_name = document.getElementById(fieldName);
	f_name.style.border = "1px solid #87AFC7";
	return false;
}

function isEmpty(fieldName){
	
	var div=document.getElementById('errMessage');
	var f_name = document.getElementById(fieldName);
	if (f_name.value.length == 0) {
		f_name.style.border = "2px dotted #bf3a59";
		div.style.display = "block";
	}
	else
	{
		f_name.style.border = "1px solid #87AFC7";
		div.style.display = "none";
	}
	return f_name;
		
}


var form_submitted = false;

function submit_form()
{
	
  if ( form_submitted )
  {
    alert ( "Your form has already been submitted. Please wait." );
    return false;
  }
  else
  {
    form_submitted = true;
    return true;
  }
}



//char restriction ...
var phone = "()- 0123456789";
var numb = "0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ @-'";
var alphanumb = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .@-'1234567890";
var emailval = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.@-_1234567890";
var cc = "01234567890 /";
function res(t,v){
var w = "";
for (i=0; i < t.value.length; i++) {
x = t.value.charAt(i);
if (v.indexOf(x,0) != -1)
 w += x; 
}
t.value = w;
document.returnValue="true";
}