function disable()
{
  document.getElementById('buynow').innerHTML = ""
}


function check() 
{ 

var student = "" ;
var lessontype = "" ;
var transmission = "" ;
var total = "" ;
var studentdiscount = "" ;
var error = "0"
var len1 = document.order.r1.length ;
var len2 = document.order.student.length ;
var len3 = document.order.lessontype.length ;
var whatitemname = ""

for (i = 0; i <len1; i++) {
if (document.order.r1[i].checked) {transmission = document.order.r1[i].value} 
}

for (i = 0; i <len2; i++) {
if (document.order.student[i].checked) {student = document.order.student[i].value} 
}

for (i = 0; i <len3; i++) {
if (document.order.lessontype[i].checked) {lessontype = document.order.lessontype[i].value} 
}

if ( lessontype == "" || student == "" || transmission == "" )
	{ alert ("You have not filled in a field. All fields are required.")
	  error = "1" ; } 
else if( (lessontype == "FastStart" && transmission=="Automatic" ) || (lessontype == "FirstTime" && transmission=="Automatic" ) )
{ alert("Fast Start and the Special Offer are only applicable when the type of car selected has manual transmission. Please rectify this error.");
error = "1"; }

if (error == "0") {

if (lessontype == "Block01"){  
	if (transmission == "Automatic"){ 
		if (document.order.advanced.checked=="1"){
			total = "260" ;
			whatitemname = "A Block of 10 hours of Automatic Advanced (BTEC) Driving Lessons" ;		
		}
		else {
			total = "230" ; 
			whatitemname = "A Block of 10 Hours of Automatic Driving Lessons" ;
		}
	}
	else { 
		if (document.order.advanced.checked=="1"){
			total = "260" ;
			whatitemname = "A Block of 10 hours of Manual Advanced (BTEC) Driving Lessons" ;		
		}
		else {
		total = "220" ; 
		whatitemname = "A Block of 10 Hours of Manual Driving Lessons" ;
		}
	}

	if (student == "Yes"){ 
		if (document.order.advanced.checked=="0"){
			studentdiscount = 5 ;
			total = total - studentdiscount ;
			whatitemname = whatitemname + " with NUS Student Discount" ; 
		}
	}
}

else if(lessontype == "FirstTime"){
	if (transmission == "Automatic"){ 
		if (document.order.advanced.checked=="1"){
			total = "180" ;
			whatitemname = "A Block of 10 hours of Automatic Advanced (BTEC) Driving Lessons for a First Time Driver" ;		
		}
		else {
			total = "180" ; 
			whatitemname = "A Block of 10 Hours of Automatic Driving Lessons for a First Time Driver" ;
		}
	}
	else { 
		if (document.order.advanced.checked=="1"){
			total = "180" ;
			whatitemname = "A Block of 10 hours of Manual Advanced (BTEC) Driving Lessons for a First Time Driver" ;		
		}
		else {
		total = "180" ; 
		whatitemname = "A Block of 10 Hours of Manual Driving Lessons for a First Time Driver" ;
		}
	}
}

else if(lessontype == "FastStart"){
	if (transmission == "Automatic"){ 
		if (document.order.advanced.checked=="1"){
			total = "180" ;
			whatitemname = "A Block of 10 hours of Automatic Advanced (BTEC) Driving Lessons for a Fast Start Driver" ;		
		}
		else {
			total = "180" ; 
			whatitemname = "A Block of 10 Hours of Automatic Driving Lessons for a Fast Start Driver" ;
		}
	}
	else { 
		if (document.order.advanced.checked=="1"){
			total = "180" ;
			whatitemname = "A Block of 10 hours of Manual Advanced (BTEC) Driving Lessons for a Fast Start Driver" ;		
		}
		else {
		total = "180" ; 
		whatitemname = "A Block of 10 Hours of Manual Driving Lessons for a Fast Start Driver" ;
		}
	}
}

else {
	if (transmission == "Automatic"){
		if (document.order.advanced.checked=="1"){
			total = lessontype * 28
			whatitemname = lessontype + " Hours of Automatic Advanced (BTEC) Driving Lessons";
		}
		else {
			total = lessontype * 24 ; 
			whatitemname = lessontype + " Hours of Automatic Driving Lessons" ;
		}
	}
	else { 
		if (document.order.advanced.checked=="1"){
			total = lessontype * 28
			whatitemname = lessontype + " Hours of Manual Advanced (BTEC) Driving Lessons";
		}
		else {
		total = lessontype * 23 ;
		whatitemname = lessontype + " Hours of Manual Driving Lessons" ;
		}
	}
	
if (student == "Yes"){ 
	if (document.order.advanced.checked=="0"){
		studentdiscount = 1 * lessontype ;
		total = total - studentdiscount ;
		whatitemname = whatitemname + " with NUS Student Discount" ; }
	}
}	

document.getElementById('cost').innerHTML = "£" + total ;


var beginningform = "<form action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='cmd' value='_xclick'>" ;
var sender = "<input type='hidden' name='business' value='zodiacdrivers@hotmail.com'>" ;
var itemname = "<input type='hidden' name='item_name' value='" + whatitemname + "'>" ;
var currency = "<input type='hidden' name='currency_code' value='GBP'>"
var totalamount = "<input type='hidden' name='amount' value='" + total + "'>" ;
var shipping = "<input type='hidden' name='shipping' value='0'>";
var returnpage = "<INPUT TYPE='hidden' VALUE='http://www.zodiacdrivertraining.co.uk/confirm.php' NAME='return'>"
var cancelpage = "<INPUT TYPE='hidden' VALUE='http://www.zodiacdrivertraining.co.uk/' NAME='cancel_return'>"

document.getElementById('buynow').innerHTML = beginningform + sender + itemname + totalamount + shipping + currency + returnpage + cancelpage + "<input type='image' src='http://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif' name='submit' alt='Buy Now'></form>" ;

}

function replace()
{
	document.getElementById('buynow').innerHTML = "" ;
	document.getElementById('cost').innerHTML = "" ;
}

return false ; }

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}




function validate() 
{ 


var purchasename = trim(document.confirmation.name.value);
var purchaseemail = trim(document.confirmation.email.value);
var purchasetele = trim(document.confirmation.telephone.value);
var len1 = document.confirmation.existing.length ;
var instructor = document.confirmation.ifyes.value;
var error = "0" ;
var existing = "" ;
var gift = document.confirmation.gift.checked ;
var studentname = trim(document.confirmation.studentname.value);
var deliveredto = trim(document.confirmation.studentaddress.value);

for (i = 0; i <len1; i++) {
if (document.confirmation.existing[i].checked) {existing = document.confirmation.existing[i].value} 
}

if ( purchasename == "" || purchaseemail == "" || purchasetele == "" ) { error="1" ; }

if (gift == true) { if ( deliveredto == "" || studentname == "" ) { error="1" ; } }

if (existing == "Yes") {
	if (instructor == "") { 
		error = "1" ;
}
}

if (error == "1") { alert ("There was an error. Please ensure that you have filled out the form correctly.") ; return false ; }
else { return true ; }
}
