	function validDetails(){
			o = document.getElementById('name'); 
			if(!o.value){o.focus(); alert('Please enter a name'); return false}
			if(o.value > "" && !validChars(o.value,'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ.,\'-')){alert('You must enter a valid name'); o.focus(); return false}

			o = document.getElementById('address1'); 
			if(!o.value){o.focus(); alert('Please enter an address'); return false}
			if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,;')){alert('You must enter a valid address'); o.focus(); return false}
	
			o = document.getElementById('address2'); 
			//if(!o.value){o.focus(); return false}
			if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,;')){alert('You must enter a valid address (2)'); o.focus(); return false}
	
			o = document.getElementById('address3'); 
			if(!o.value){o.focus(); alert('Please enter a city'); return false}
			if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-.,;')){alert('You must enter a valid city'); o.focus(); return false}

			//o = document.getElementById('address3'); 	
			//if(!o.value){o.focus(); return false}
			
			//if(o.value > "" && !numbersOnly(o.value)){alert('You must enter a CV2 number off the back of the card'); o.focus(); return false}
			
			o = document.getElementById('county'); 
			//if(!o.value){o.focus(); return false}
		
			o = document.getElementById('postcode'); 
			if(!o.value){o.focus();  alert('Please enter a postcode'); return false}
			if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-')){alert('You must enter a valid postcode'); o.focus(); return false}
			return true	
	}
	
	function validCar(){
		var o = document.getElementById('make');
		if(!o.value){alert('Please enter a car make'); o.focus(); return false}
		var o = document.getElementById('model');
		if(!o.value){alert('Please enter a model'); o.focus(); return false}
		var o = document.getElementById('category');
		if(o.value ==-1){alert('Please choose a category'); o.focus(); return false}
		var o = document.getElementById('cc');
		if(!o.value){alert('Please enter the cubic capacity of the engine'); o.focus(); return false}
		var o = document.getElementById('super1');
		var p = document.getElementById('super2');
		if(o.checked == false && p.checked == false){alert('Please answer whether the car is supercharged or not'); return false}
		var o = document.getElementById('turbo1');
		var p = document.getElementById('turbo2');
		if(o.checked == false && p.checked == false){alert('Please answer whether the car is turbocharged or not'); return false}
		var o = document.getElementById('rotary1');
		var p = document.getElementById('rotary2');
		if(o.checked == false && p.checked == false){alert('Please answer whether the car has a rotary engine or not'); return false}
		return true;
	}
	
	function doClever(thevalue){
		if(parseInt(thevalue) ==-1){
			document.getElementById('mm').style.visibility='visible';
			document.getElementById('mm').style.display='';
			document.getElementById('category').style.visibility='visible';
			document.getElementById('category').style.display='';
			document.getElementById('capacity').style.visibility='visible';
			document.getElementById('capacity').style.display='';
			document.getElementById('options').style.visibility='visible';
			document.getElementById('options').style.display='';
			document.getElementById('time').style.visibility='visible';
			document.getElementById('time').style.display='';
		}else{
			document.getElementById('mm').style.visibility='hidden';
			document.getElementById('mm').style.display='none';
			document.getElementById('category').style.visibility='hidden';
			document.getElementById('category').style.display='none';
			document.getElementById('capacity').style.visibility='hidden';
			document.getElementById('capacity').style.display='none';
			document.getElementById('options').style.visibility='hidden';
			document.getElementById('options').style.display='none';
			document.getElementById('time').style.visibility='hidden';
			document.getElementById('time').style.display='none';		
		}
	}

	function validPayment(){

		var o = document.getElementById('ctype');
		if(!o.value){alert('Please choose a card type'); o.focus(); return false}
		
		o = document.getElementById('cardNo');
		if(!o.value){alert('Your card number is not long enough'); o.focus(); return false}
		if(o.value.length <14){alert('Your card number is not long enough'); o.focus(); return false}
		if(o.value > "" && !numbersOnly(o.value)){alert('Your card number must be numbers only'); 
		o.focus(); return false}
		
		//o = document.getElementById('fromMonth'); 
		//if(!o.value){o.focus(); return false}
		//if(o.value > "" && !numbersOnly(o.value)){alert('You must select a valid month'); o.focus(); return false} 
		
		//o = document.getElementById('fromYear'); 
		//if(!o.value){o.focus(); return false}
		//if(o.value > "" && !numbersOnly(o.value)){alert('You must select a valid year'); o.focus(); return false} 
		
		o = document.getElementById('toMonth'); 
		if(!o.value){alert('Please select an expiry month'); o.focus(); return false}
		if(o.value > "" && !numbersOnly(o.value)){alert('You must select a valid month'); o.focus(); return false}	
		
		o = document.getElementById('toYear'); 
		if(!o.value){alert('Please select an expiry year'); o.focus(); return false}
		if(o.value > "" && !numbersOnly(o.value)){alert('You must select a valid year'); o.focus(); return false}
		
		//o = document.getElementById('issue'); 
		//if(o.value == ""){o.focus(); return false}
		//if(o.value > "" && !numbersOnly(o.value)){alert('You must enter an issue number'); o.focus(); return false}
		
		o = document.getElementById('cv2'); 
		if(!o.value){alert('Please enter the CV2 number off the back of your card'); o.focus(); return false}
		if(o.value > "" && !numbersOnly(o.value)){alert('You must enter a valid CV2 number off the back of the card'); o.focus(); return false}
		
		o = document.getElementById('name'); 
		if(!o.value){alert('You must enter a valid name'); o.focus(); return false}
		if(o.value > "" && !validChars(o.value,'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ\'-')){alert('You must enter a valid name'); o.focus(); return false}
		o = document.getElementById('address1'); 
		if(!o.value){alert('You must enter a valid address'); o.focus(); return false}
		if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-')){alert('You must enter a valid address'); o.focus(); return false}

		o = document.getElementById('address2'); 
		//if(!o.value){o.focus(); return false}
		if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-')){alert('You must enter a valid address'); o.focus(); return false}

		//o = document.getElementById('address3'); 
		//if(!o.value){o.focus(); return false}
		//if(o.value > "" && !numbersOnly(o.value)){alert('You must enter a CV2 number off the back of the card'); o.focus(); return false}
		
		o = document.getElementById('county'); 
		if(!o.value){alert('You must choose a county'); o.focus(); return false}
		if(o.value > "" && !validChars(o.value,'abcdefghijklmnopqrstuvwxzyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-')){alert('You must choose a county'); o.focus(); return false}
		
		o = document.getElementById('postcode'); 
		//if(!o.value){alert('You must enter a valid postcode'); o.focus(); return false}
		if(o.value > "" && !validChars(o.value,'1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-')){alert('You must enter a valid postcode'); o.focus(); return false}
		return true	
		}

	function validateEvent(){
		
		//var o = document.getElementById('licence'); 
		//if(o.value > "" && !numbersOnly(o.value)){alert('Your licence must be numbers only'); o.focus(); return false;} 
		//o = document.getElementById('elicence'); 
		//if(o.value > "" && !numbersOnly(o.value)){alert('Your entrants licence must be numbers only'); o.focus(); return false;} 
		//o = document.getElementById('cc'); 
		//if(o.value > "" && !numbersOnly(o.value)){alert('Your engine capacity must be numbers only'); o.focus(); return false;} 
		//o = document.getElementById('besttime'); 
		//if(o.value > "" && !validChars(o.value,'1234567890.')){alert('Your best time must be in seconds only'); o.focus(); return false;}	
		//o = document.getElementById('age'); 
		//if(o.value > "" && !numbersOnly(o.value)){alert('Your age must be numbers only'); o.focus(); return false;}
		return true;
	}
	
		function numbersOnly(theString){
			var validChars = "1234567890";
			for (var i=0; i<theString.length;i++){
				if(validChars.indexOf(theString.charAt(i)) <0){
					return false;
				}
			}
			return true;
		}
		
		function validChars(theString,validchars){
			var validChars = validchars;
			for (var i=0; i<theString.length;i++){
				if(validChars.indexOf(theString.charAt(i)) <0){
					return false;
				}
			}
			return true;
		}

	function loadingDots(id){
		  var element;
		  element = id;
      var o = document.getElementById(id);
      if(o){
        if(o.innerHTML==''){
          o.innerHTML=' ~';
        }
        else if(o.innerHTML==' ~'){
          o.innerHTML=' ~ ~';
        }
        else if(o.innerHTML==' ~ ~'){
          o.innerHTML=' ~ ~ ~ ';
        }
        else{
          o.innerHTML='';
        }
      }
      var t,functionName;
      functionName = 'loadingDots(\'' + element + '\')';
      t=setTimeout(functionName,1000);
    }
    
    function redirect(path){
			document.location=path;
		}
		
		function showInput(id,id2,sdisplay)
		{
			var o = document.getElementById(id);
			var x = document.getElementById(id2);
			if(o && x)
			{
				o.style.visibility='visible';
				x.style.visibility='visible';
				if(sdisplay==1)
				{
					o.style.display='table-row';
					x.style.display='table-row';
				}
			}
		}
		function hideInput(id,id2,sdisplay)
		{
			var o = document.getElementById(id);
			var x = document.getElementById(id2);
			if(o && x)
			{
				o.style.visibility='hidden';
				x.style.visibility='hidden';
				if(sdisplay==1)
				{
					o.style.display='none';
					x.style.display='none';
				}
			}
		}
		
		function changeFocus(id,hide1,hide2,focusID)
		{
			var o = document.getElementById(id);
			var x = document.getElementById(focusID);
			if(x)
			{
				if(o.value =='')
				{
					alert('should be hidding');
					hideInput(hide1,hide2);
					//x.focus();
				}
			}
		}	
		
		function makeFocus(id)
		{
			var o = document.getElementById(id);
			if(o)
			{
				o.focus();
			}
		}	
		
		function hoverButton(id)
		{
			var o = document.getElementById(id);
			
			if(o)
			{
				o.style.cursor='pointer';
				if(o.className=='button ')
				{
					o.className='button button_over';
				}
				else if(o.className=='button')
				{
					o.className='button button_over';
				}
				else if(o.className=='first_button ')
				{
					o.className='first_button button_over';
				}
				else if(o.className=='first_button')
				{
					o.className='first_button button_over';
				}	
			}
		}
		
		function buttonOut(id)
		{
			var o = document.getElementById(id);
			if(o)
			{
				if(o.className=='button button_over')
				{
					o.className='button ';
				}	
				else if(o.className=='first_button button_over')
				{
					o.className='first_button ';
				}
			}
		}
				
		function sortColumn(path,page)
		{
			var o = location.search;
			if((o.match('sort')==null) || (o.match('sort=1')))
			{
				document.location=path + page + '.php?sort=2';
			}
			
			if(o.match('sort=2')){
				document.location=path + page + '.php?sort=1';
			}
			
		}
	
	function populateCalendar(new_month){
		
		if(isNaN(new_month)){
			var new_month = 0;
		}
		var one_day,date1,date2,rows,balance,Tdays,FirstDay,i,x,count,datescount,today,cells;
	  balance=0;
	  one_day = 1000*60*60*24;
	  today = new Date();
	  dates = new Array(48);
	  date1 = new Date();
	 	date2 = new Date();
	 	date1.setFullYear(today.getFullYear(),today.getMonth()+new_month,1);
	  date2.setFullYear(today.getFullYear(),(today.getMonth()+new_month)+1,1);
	  count=0;
	  datescount=1;
	  Tdays = Math.round((date2-date1)/one_day);
	
	  FirstDay = date1.getDay();
	  if(FirstDay > 4){
			balance=0.5;
		}
	  cells = 49;
	  
	  // blank all table cells before putting new dates in each time
	  clearCalendar(cells);
		
		//write current calendar month and year view
		var title = document.getElementById('title');
		if(title){
			title.innerHTML=getMonthName(date1.getMonth()) + ' ' + date1.getFullYear();
		}

		for(i=0;i<cells;i++){
			var o = document.getElementById(i);
			if(o){
				
				if(i>=FirstDay && datescount<=Tdays){
					
							//Highlight current day - very buggy at the mo!
					if((i==0) || (i==6) || (i==7) || (i==13) || (i==14) || (i==20) || (i==21) || (i==27) || (i==28) || (i==34) || (i==35) || (i==41)){
						if((datescount == today.getDate()) && (date1.getMonth() == today.getMonth())){
							o.className='calendar-weekend-highlight';
						}
					}
					else{
						if((datescount == today.getDate()) && (date1.getMonth() == today.getMonth())){
							o.className='calendar-weekday-highlight';
						}
					}
					
				o.innerHTML=datescount++;
				}
			}
		}
	  
	}
	
	function clearCalendar(cells){
		for(var i=0;i<=cells;i++){
			var o = document.getElementById(i);
			if(o){
				o.innerHTML='&nbsp;'
				if((i==0) || (i==6) || (i==7) || (i==13) || (i==14) || (i==20) || (i==21) || (i==27) || (i==28) || (i==34) || (i==35) || (i==41)){
					o.className='calendar-weekend';
				}
				else{
					o.className='calendar-weekday';
				}
			}
		}
	}
	
	function calendar(){
	  
	  var one_day,date1,date2,rows,balance,Tdays,FirstDay,i,x,count,datescount,today;
	  one_day = 1000*60*60*24;
	  today = new Date();
	  dates = new Array(48);
	  date1 = new Date();
	 	date2 = new Date();
	 	date1.setFullYear(today.getFullYear(),today.getMonth(),today.getDate());
	  date2.setFullYear(today.getFullYear(),today.getMonth()+1,today.getDate());
	  count=0;
	  Tdays = Math.round((date2-date1)/one_day);
	  FirstDay = date1.getDay(); 	  
	  rows = 6;
	  document.write('<table width=\"300px;\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" align=\"center\">');
	  document.write('<tr>');
	  document.write('<td><span onmouseover=\"this.style.cursor=\'pointer\'\" onclick=\"new_month--;populateCalendar(new_month);\"><-</span></td>');
	  document.write('<td id=\"title\" colspan=\"5\" align=\"center\">&nbsp;</td>');
	  document.write('<td align=\"right\"><span onmouseover=\"this.style.cursor=\'pointer\'\" onclick=\"new_month++;populateCalendar(new_month);\">-></span></td>');
	  document.write('</tr>');
	  document.write('<tr>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">S</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">M</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">T</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">W</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">T</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">F</td>');
	  document.write('<td style=\"text-align:center; font-size:7pt; width:20px; height:20px; background-color:rgb(255,255,255); border:0px; border-color:rgb(0,0,0); border-style:solid;\">S</td>');
	  document.write('</tr>');
	  
	  for(i=1;i<=Tdays;i++){
	    dates[i]=i;
	  }  
	 
	  for(i=0;i<rows;i++){
	 
	    document.write('<tr>');
	    for(x=0;x<7;x++){
	    	if((count==0) || (count==6) || (count==7) || (count==13) || (count==14) || (count==20) || (count==21) || (count==27) || (count==28) || (count==34) || (count==35) || (count==41)){
	      	document.write('<td id=\"' + count + '\" title=\"' + count +'\" class=\"calendar-weekend\">&nbsp;</td>');
	      }else{
	      	document.write('<td id=\"' + count + '\" title=\"' + count +'\" class=\"calendar-weekday\">&nbsp;</td>')
	      }
	      count++;
	    }
	    document.write('</tr>');
	  }
	  document.write('</table>');
	}	
	
	function getMonthName(value){
		if(value==12){
			value=valu-1;
		}
		var month=new Array(12)
			month[0]="January"	
			month[1]="February"
			month[2]="March"
			month[3]="April"
			month[4]="May"
			month[5]="June"
			month[6]="July"
			month[7]="August"
			month[8]="September"
			month[9]="October"
			month[10]="November"
			month[11]="December"
		
		return month[value];
	}
