var pID = 0;
var linkArr = new Array();
linkArr[0] = "";
linkArr[1] = "";
linkArr[2] = "<div style='float:left;height:20px;width:242px'></div><a href='tribute550.htm' title='Tribute 550'>Tribute 550</a><a href='carioca646.htm' title='Carioca 694'>Carioca 694</a><a href='rollerteam600.htm' title='Roller Team 600'>Roller Team 600</a><a href='carioca656.htm' title='Carioca 656'>Carioca 656</a>";
linkArr[3] = "";
linkArr[4] = "<div style='float:left;height:20px;width:282px'></div><a href='hireprices.htm' title='Vehicle Hire'>Vehicle Hire</a><a href='#' title='Trailer Hire'>Trailer Hire</a><a href='addedextras.htm' title='Added extras'>Added extras</a><a href='#' title='Special offers'>Special offers</a><a href='meetandgreet.htm' title='Meet and greet'>Meet and greet</a>";
linkArr[5] = "";
linkArr[6] = "";
linkArr[7] = "";
linkArr[8] = "";

var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var days = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
var today = new Date();
var changingDate = new Date();
var backMonthActive = false;
var calType = 1;

function daysInMonth(month,year) {
	var dd = new Date(year, month+1, 0);
	return dd.getDate();
}

function setForm(d,cell) {
	var thisCell = "digit" + cell;
	var str = d + "/" + (changingDate.getMonth()+1) + "/" + changingDate.getFullYear();
	if (calType == 1) {
		$('pickupdate').set('value', str);
	} else {
		$('returndate').set('value', str);
	}
	$('calendar').fade(0);
	
}

function assignDate(dateObject) {	
	var ndaysinmonth = daysInMonth(dateObject.getMonth(),dateObject.getYear());
	var headerContent = months[dateObject.getMonth()] + ' ' + dateObject.getFullYear();
	$('spancalendarTitle').set('html',headerContent);
	var firstday = dateObject;
	firstday.setDate(1);
	if (dateObject > today) {
		backMonthActive = true;
	} else {
		backMonthActive = false;	
	}
	for (var n = 0; n <= 42; n++) {
		var thisDay = "digit" + (n+1);
		var cellDone = false;
		if (n < firstday.getDay()) {
			$(thisDay).set('html','');
			$(thisDay).className = "blank";
			cellDone = true;
		}
		if (n < firstday.getDay() + ndaysinmonth && n > firstday.getDay()-1 && !cellDone) {
			$(thisDay).className = "digit";
			var dayclick = "<span onClick='setForm(" + (n  - (firstday.getDay()-1)) + "," + (n+1) + ")'>" + (n  - (firstday.getDay()-1)) + "</span>";
			$(thisDay).set('html', dayclick);
			cellDone = true;
		}
		if (!cellDone) {
			$(thisDay).className = "digit";
			$(thisDay).set('html','');
		}		
	}
}

window.addEvent('domready', function(){
	$('pickupdate').addEvent('click', function(e) {
		// You often will need to stop propagation of the event
		e.stop();
		calType = 1;
		$('calendar').className = "cal1";
		$('calendar').fade(1);
	});
	
	$('returndate').addEvent('click', function(e) {
		// You often will need to stop propagation of the event
		e.stop();
		calType = 2;
		$('calendar').className = "cal2";		
		$('calendar').fade(1);
	});
	
	$('backMonth').addEvents({		
		'click': function(){
			if (backMonthActive) {
				if (changingDate.getMonth() == 0) {
					changingDate.setMonth(11);
					changingDate.setYear(changingDate.getFullYear()-1);
				} else {
					changingDate.setMonth(changingDate.getMonth() - 1);
				}
				assignDate(changingDate);
			}
		}
	});

	$('nextMonth').addEvents({		
		'click': function(){
			if (changingDate.getMonth() + 1 > 11) {
				changingDate.setMonth(0);
				changingDate.setYear(changingDate.getFullYear()+1);
			} else {
				changingDate.setMonth(changingDate.getMonth() + 1);
			}
			assignDate(changingDate);
		}
	});


	
	$('n1').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/homeb.jpg";
		},
		'mouseleave': function(){
			if (pID != 1) {
				this.src = "images/homea.jpg";
			}
		}
	});
	$('n2').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/aboutb.jpg";
		},
		'mouseleave': function(){
			if (pID != 2) {		
				this.src = "images/abouta.jpg";
			}
		}
	});
	$('n3').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/motorhomesb.jpg";
		},
		'mouseleave': function(){
			if (pID != 3) {		
				this.src = "images/motorhomesa.jpg";
			}
		}
	});
	$('n5').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/hirepricesb.jpg";
		},
		'mouseleave': function(){
			if (pID != 5) {	
				this.src = "images/hirepricesa.jpg";
			}
		}
	});
	$('n6').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/motorhomesforsaleb.jpg";
		},
		'mouseleave': function(){
			if (pID != 6) {
				this.src = "images/motorhomesforsalea.jpg";
			}
		}
	});
	$('n7').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/galleryb.jpg";
		},
		'mouseleave': function(){
			if (pID != 7) {
				this.src = "images/gallerya.jpg";
			}
		}
	});
	$('n8').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/faqsb.jpg";
		},
		'mouseleave': function(){
			if (pID != 8) {
				this.src = "images/faqsa.jpg";
			}
		}
	});
	$('n9').addEvents({		
		'mouseenter': function(){
			// Always sets the duration of the tween to 1000 ms and a bouncing transition
			// And then tweens the height of the element
			this.src = "images/contactusb.jpg";
		},
		'mouseleave': function(){
			if (pID != 9) {
				this.src = "images/contactusa.jpg";
			}
		}
	});

	$('submitButton').addEvent('click', function(e) {
		// You often will need to stop propagation of the event
		e.stop();		
		checkForm();
	});
	assignDate(today);
});

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.indexOf(at,(lat+1))!=-1){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.indexOf(dot,(lat+2))==-1){
		alert("You have the email address in the wrong format")
		return false
	}

	if (str.indexOf(" ")!=-1){
		alert("You have the email address in the wrong format")
		return false
	}
	return true
}

function checkForm() {
	if (document.form1.nam.value == "") {
		alert("You have not filled in your name");
		return false;
	}
	if (document.form1.postcode.value == "") {
		alert("You have not entered any postcode information");
		return false;
	}
	if (document.form1.telephone.value == "") {
		alert("You have not entered your telephone number");
		return false;
	}

	var strEmail = document.form1.eaddress.value;
	if (!echeck(strEmail)) {
		return false;
	}

	if (strEmail != document.form1.confirmeaddress.value) {
		alert("You did not confirm your email address correctly");
		return false;
	}
	
/*
	if (!document.form1.2berth.checked && !document.form1.4berth.checked && !document.form1.6berth.checked) {
		alert("You have not selected any type vehicle");
		return false;
	}
*/
	if (document.form1.comments.value == "") {
		alert("You have not entered a comment or question");
		return false;
	}
	document.form1.Ctype.value = "true";
	document.form1.submit();
	return true;
}
