	/* Copyright Grovelawn 2006 */
var Calender=function(idl,idn,mde){
	var d		= new Date;
	this.id_find	= idn;
	this.code	= '/scripts/forms.js';
	this.style	= '/scripts/style.css';
	this.ids	= idl;	// eg. [['Arrival Date','ct','cd','cm'],['Return Date','rt','rd','rm']];
	this.start	= [(20000100+d.getMonth()*100+(d.getYear()%100)*10000+d.getDate()),0,0,0,0,0,0,0,0,0,0,0];
	this.days	= ['S','M','T','W','T','F','S'];
	this.months	= ['Janurary','Feburary','March','April','May','June','July','August','September','October','November','December'];
	this.limits	= [31,29,31,30,31,30,31,31,30,31,30,31];
	this.generate	= function() {
		var n; var m; var b;
		var x = '';
		for( n=1; n<this.start.length; ++n ) this.start[n] = ( this.start[n] < this.start[n-1] ? this.start[n-1] : this.start[n] );
		for( n=1; n<this.start.length; ++n ) {
			var d=this.start[n]; var dx=Math.floor(d/100); var sx=Math.floor(this.start[0]/100);
			var dd=d%100; var dm=Math.floor(d/100)%100; var dy=Math.floor(d/10000);
			if( 2==dm ) this.limits[1] = ( 0==dy%4 && ( 0!=dy%100 || 0==dy%400 ) ? 29 : 28 );
			x += '<td><table border=1 cellpadding=0 cellspacing=0 class=calender><tr><th colspan=7>'+this.ids[n-1][0]+'</th></tr><tr><td>'+this.days.join('</td><td>')+'</td></tr><tr>';
			for( b = 1-( new Date( dy, dm-1, 1 ) ).getDay(); b<31; x += '</tr><tr>' ) for( m=0; m<7; ++m, ++b ) {
				if( this.limits[dm-1] < b || b <= 0 ) x += '<td class=calender-blank>&nbsp;</td>'; else
				if( sx==dx && b<(this.start[0]%100) ) x += '<td class=calender-strike>' + b + '</td>'; else
				if( this.start[n-1]>(dx*100+b) ) x += '<td class=calender-back onclick="document.'+this.id_find+'.select('+b+','+n+')">'+b+'</td>'; else
				if( (dx*100+b)==d ) x += '<td class=calender-pick onclick="document.'+this.id_find+'.select('+b+','+n+')">'+b+'</td>'; else
				if( (dx*100+b)<d && 1<n ) x += '<td class=calender-range onclick="document.'+this.id_find+'.select('+b+','+n+')">'+b+'</td>'; else
				x += '<td class=calender-ready onclick="document.'+this.id_find+'.select('+b+','+n+')">'+b+'</td>';
			}
			x += '</tr><tr><th colspan=7><select id=mn'+n+' onchange="document.'+this.id_find+'.n_month('+n+')">';
			for( m=sx; m<(sx+100); ++m ) { if( 12<m%100 ) m += 88; x += '<option'+(dx==m?' selected ':' ')+'value='+m+'>'+this.months[m%100-1]+' '+Math.floor(m/100); }
			x += '</select></th></tr></table></td>';
		}
		return '<table border=0 cellpadding=4 cellspacing=0><tr>'+x+'</tr></table>';
	};
	this.update	= function() {
		document.getElementById('form-calender').innerHTML = this.generate();
	};
	this.n_month	= function(n) {
		var o = document.getElementById('mn'+n);
		this.start[n] = o.options[ o.selectedIndex ].value*100;
		this.update();
	};
	this.select	= function(u,i) {
		var n, m, o, v;
		this.start[i] = Math.floor(this.start[i]/100)*100+u;
		for( n=0; n<this.ids.length; ++n ) {
			o = window.opener.document.getElementById(this.ids[n][3]); v = Math.floor( this.start[n+1]/100 );
			for( m=0; m<o.options.length; ++m ) if( o.options[m].value == v ) { o.selectedIndex = m; break; }
			o = window.opener.document.getElementById(this.ids[n][2]); v = this.start[n+1]%100;
			for( m=0; m<o.options.length; ++m ) if( o.options[m].value == v ) { o.selectedIndex = m; break; }
		}
		for( n=1; n<this.start.length; ++n ) if( this.start[n]<this.start[n-1] ) i=0;
		if( i==(this.start.length-1) ) window.close(); this.update();
	};
	this.show	= function(e) {
		if( !e ) var e=window.event;
		if( document.getElementById ) {
			var w=window.open( '', 'Calender','height=210,width='+(2*this.ids.length)+'20,left='+e.clientX+',top='+e.clientY );
			w.document.write( '<html><head><title>Calender</title><link rel=stylesheet type="text/css" href="'+this.style+'"><script type="text/javascript" src="'+this.code+'"></script></head><body><div id=form-calender>Loading...</div><input type=hidden id=info value="'+this.id_find+'"></body></html>' );
			w.document.close(); w.focus();
		}
		return false;
	};
	if( mde ) { var n;
		this.ids = window.opener.document[ idn ].ids
		this.start.length = this.ids.length + 1;
		for( n=0; n<this.ids.length; ++n ) {
			this.start[n+1] = window.opener.document.getElementById(this.ids[n][3]).value*100+(window.opener.document.getElementById(this.ids[n][2]).value-0);
			this.start[n+1] = ( this.start[n+1] < this.start[n] ? this.start[n] : this.start[n+1] );
		}
		this.update();
	}
	this.start.length = this.ids.length + 1;
	document[ idn ] = this;
};
var Forms = function() {
	document.month_limits = [0,31,29,31,30,31,30,31,31,30,31,30,31];
	document.month_names = ['','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
	document.check_dates = function( sd, smy, ed, emy, edu ) {
		var t = new Date; var e = '';
		if( document.month_limits[smy%100]<sd || ( 29==sd && 2==(smy%100) && 0!=(smy%400) ) ) { e += '\n* The start date is invalid.'; }
		if( sd<t.getDate() && (200001+t.getMonth()+(t.getYear()%100)*100)==smy ) { e += '\n* The start date is before today.\n  (If this is not the case, please check your computer\'s clock\'s date.)'; }
		if( edu && ( document.month_limits[emy%100]<ed || ( 29==ed && 2==(emy%100) && 0!=(emy%400) ) ) ) { e += '\n* The end date is invalid.'; }
		if( edu && ( ( ed<sd && emy==smy ) || emy<smy ) ) { e += '\n* The end date is before the start date.'; }
		if( ''==e ) { return true; } else { alert( 'Sorry, you appear to have entered an invalid date.\n' + e + '\n\nYou can use the calender button to select a valid date.' ); return false; }
	};
	this.generate_integer_select = function( c, l, u ) {
		var x = '<select name=' + c + ' id=' + c + '>'; var n;
		for( n=l; n <= u; ++n ) { x += '<option value="' + n + '">' + n; }
		return x + '</select>';
	};
	this.generate_time_select = function( a ) {
		var t = '<select name=' + a + ' id=' + a + '><option value=030>0:30'; var n;
		for( n=1; n<24; ++n ) {
			t += '<option value=' + n + '00>' + n + ':00<option value=' + n + '30>' + n + ':30';
			if( 12==n ) { t += '<option selected value="-">Time'; }
		}
		return t + '</select>';	
	};
	this.generate_date_select = function( a1, a2 ) {
		var d = new Date; var y = 2000 + d.getYear() % 100; var m = 1+d.getMonth();
		var t = '<select name=' + a1 + ' id=' + a1 + '>'; var n;
		for( n=1; n<32; ++n ) { t += '<option value="' + n + ( d.getDate() == n ? '" selected >' : '">' ) + n; }
		t += '</select><select name=' + a2 + ' id=' + a2 + '>';
		for( n=1; n<13; ++n ) { t += '<option value=' + ( m + 100*y ) + '>' + document.month_names[m] + ' ' + y; if( 13 == ++m ) { m = 1; ++y; } }
		return t + '</select>';
	};
	this.airport_parking = function() {
		document.check_airport_parking = function() {
			var f = document.forms['airport-parking-form'];
			if( '-'==f.pdt.value || '-'==f.prt.value ) { alert( 'Please enter the times of travel.\n(Remember to leave enough time to check in your car.)' ); f.pdt.focus(); return false; }
			return document.check_dates( f.pdd.value, f.pdm.value, f.prd.value, f.prm.value, true );
		}
		new Calender( [['Departure','pdt','pdd','pdm'],['Return','prt','prd','prm']], 'calender_airport_parking' );
		var x =	'<form action="/scripts/apark.php" method=get id=airport-parking-form name=airport-parking-form><table border=0 cellpadding=0 cellspacing=0>';
		x +=	'<tr><td colspan=2><h3>UK Airport Parking Quote</h3></td></tr>';
		x +=	'<tr><td><label for=pap>Airport</label>:</td><td><select name=pap id=pap><option value=abz>Aberdeen<option value=bfs>Belfast<option value=bhx>Birmingham<option value=blk>Blackpool<option value=brs>Bristol<option value=cwl>Cardiff<option value=dsa>Doncaster (Robin Hood)<option value=dov>Dover Port<option value=mme>Durham Valley (Teeside)<option value=ema>East Midlands (Nottingham)<option value=edi>Edinburgh<option value=fol>Folkestone (EuroTunnel)<option value=lgw>Gatwick (London)<option value=gla>Glasgow<option selected value=lhr>Heathrow (London)<option value=huy>Humberside (Kirmington)<option value=lba>Leeds Bradford<option value=lpl>Liverpool (John Lennon)<option value=lcy>London City<option value=ltn>Luton<option value=man>Manchester<option value=ncl>Newcastle<option value=pik>Prestwick (Glasgow)<option value=sou>Southampton<option value=stn>Stansted (London)<option value=wtu>Waterloo Station (London)</select></td></tr>';
		x +=	'<tr><td><label for=pdt>Arrive</label>:</td><td>' + this.generate_time_select('pdt') + this.generate_date_select('pdd','pdm') + '<input type=image width=28 height=17 value=Cal onclick="return document.calender_airport_parking.show(event);" src="/images/cal.gif"></td></tr>';
		x +=	'<tr><td><label for=prt>Return</label>:</td><td>' + this.generate_time_select('prt') + this.generate_date_select('prd','prm') + '<input type=image width=28 height=17 value=Cal onclick="return document.calender_airport_parking.show(event);" src="/images/cal.gif"></td></tr>';
		x +=	'<tr><td><label for=ppp>People</label>:</td><td>' + this.generate_integer_select('ppp',1,9) + '<input type=submit id=pxp name=pxp value="Check Availablity" onclick="return document.check_airport_parking();"></td></tr>'
		return	x + '</table></form>';
	};
	this.airport_hotels = function() {
		document.check_airport_hotels = function() {
			var f = document.forms['airport-hotel-form'];
			return document.check_dates( f.aad.value, f.aam.value, 0, 0, false );
		}
		new Calender( [['Arrival','aat','aad','aam']], 'calender_airport_parking' );
		var x = '<form action="/scripts/ahotel.php" method=get id=airport-hotel-form name=airport-hotel-form><table border=0 cellpadding=0 cellspacing=0>';
		x +=	'<tr><td colspan=2><h3>UK Airport Hotel Quote</h3></td></tr>';
		x +=	'<tr><td><label for=aap>Airport</label>:</td><td><select id=aap name=aap><option value=abz>Aberdeen<option value=bfs>Belfast<option value=blk>Blackpool<option value=bhx>Birmingham<option value=brs>Bristol<option value=cwl>Cardiff<option value=cvt>Coventry<option value=dov>Dover Port<option value=dub>Dublin<option value=mme>Durham Valley (Teeside)<option value=ema>East Midlands (Nottingham)<option value=edi>Edinburgh<option value=lgw>Gatwick (London)<option value=gla>Glasgow<option selected value=lhr>Heathrow (London)<option value=huy>Humberside (Kirmington)<option value=lba>Leeds Bradford<option value=lpl>Liverpool<option value=lcy>London City<option value=ltn>Luton<option value=man>Manchester<option value=ncl>Newcastle<option value=nwi>Norwich<option value=sou>Southampton<option value=stn>Stansted (London)</select></td></tr>';
		x +=	'<tr><td><label for=ar1>Room</label>:</td><td><select id=ar1 name=ar1><option value=s10>Single - 1 Adult<option value=t20>Twin - 2 Adults<option value=d20 selected=selected>Double - 2 Adults<option value=t12>Triple - 1 Adult 2 Children<option value=t21>Triple - 2 Adults 1 Child<option value=t30>Triple - 3 Adults<option value=f13>Family - 1 Adult 3 Children<option value=f22>Family - 2 Adults 2 Children<option value=f23>Family - 2 Adults 3 Children<option value=f31>Family - 3 Adults 1 Child<option value=f32>Family - 3 Adults 2 Children</select></td></tr>';
		x +=	'<tr><td><label for=aad>Arrive</label>:</td><td>' + this.generate_date_select('aad','aam') + '<input type=image width=28 height=17 value=Cal onclick="return document.calender_airport_hotels.show(event);" src="/images/cal.gif"></td></tr>';
		x +=	'<tr><td>&nbsp;</td><td><input type=submit value="Check All Availablity" onclick="return document.check_airport_hotels();"></td></tr>';
		return	x + '</table></form>';
	};
	this.airport_lounges = function() {
		document.check_airport_lounges = function() {
			var f = document.forms['airport-lounge-form'];
			if( '-'==f.lat.value ) { alert( 'Please enter your arrival time.' ); f.lat.focus(); return false; }
			return document.check_dates( f.lad.value, f.lam.value, 0, 0, false );
		}
		new Calender( [['Arrival','lat','lad','lam']], 'calender_airport_lounges' );
		var x =	'<form action="/scripts/alounge.php" method=get id=airport-lounge-form name=airport-lounge-form><table border=0 cellpadding=0 cellspacing=0>';
		x +=	'<tr><td colspan=4><h3>UK Airport Lounge Quote</h3></td></tr>';
		x +=	'<tr><td><label for=lap>Airport</label>:</td><td colspan=3><select id=lap name=lap><option value=abz>Aberdeen<option value=bfs>Belfast<option value=bhx>Birmingham<option value=brs>Bristol<option value=cwl>Cardiff<option value=edi>Edinburgh<option value=lgw>Gatwick (London)<option value=gla>Glasgow<option selected value=lhr>Heathrow (London)<option value=huy>Humberside<option value=lba>Leeds / Bradford<option value=lpl>Liverpool<option value=ltn>Luton<option value=man>Manchester<option value=ncl>Newcastle<option value=stn>Stansted</select></td></tr>';
		x +=	'<tr><td><label for=lat>Arrive</label>:</td><td colspan=3>' + this.generate_time_select('lat') + this.generate_date_select('lad','lam') + '<input type=image width=28 height=17 value=Cal onclick="return document.calender_airport_lounges.show(event);" src="/images/cal.gif"></td></tr>';
		x +=	'<tr><td rowspan=2><label for=lpa>People</label>:</td><td>' + this.generate_integer_select('lpa',1,9) + '</td><td>' + this.generate_integer_select('lpc',0,9) + '</td><td>' + this.generate_integer_select('lpi',0,9) + '</td></tr>';
		x +=	'<tr><td>Adults</td><td>Children</td><td>Infants</td></tr>';
		x +=	'<tr><td>&nbsp;</td><td colspan=3><input type=submit id=lxp value="Check Lounge Availablity" onclick="return document.check_airport_lounges();"></td></tr>';
		return	x + '</table></form>';
	}
	this.car_rental = function() {
		return ' &nbsp; ';
	};
	this.travel_insurance = function() {
		document.check_travel_insurance = function() {
			var f = document.forms['travel-insurance-form'];
			if( !f ) return true;
			var ipa = ( f.ipa ? f.ipa.value : 0 )-0;
			var ipc = ( f.ipc ? f.ipc.value : 0 )-0;
			var ipi = ( f.ipi ? f.ipi.value : 0 )-0;
			switch( f.ipg.value ) {
			case 'i': if( 1!=ipa || 0!=ipc || 0!=ipi ) { alert( 'An individual policy must have only one member.\n' ); f.ipg.focus(); return false; } break;
			case 'c': if( 2!=ipa || 0!=ipc || 0!=ipi ) { alert( 'A policy for a couple must have only two members.\n' ); f.ipg.focus(); return false; } break;
			case 'f': if((1!=ipa && 2!=ipa ) || ipc<0 || 3<ipc ) { alert( 'A family policy must include one or two adults and upto three children.\n' ); f.ipg.focus(); return false; } break;
			case 'g': if( 1==ipa && 0==ipc ) { alert( 'A group policy should include at least two members.\n' ); f.ipg.focus(); return false; } break;
			}
			if( 8 < (ipa+ipc+ipi) ) { alert( 'Please phone 0870-264-264-2 to book policies with more than 8 members.\n' ); f.ipa.focus(); return false; }
			return document.check_dates( f.isd.value, f.ism.value, f.ied.value, f.iem.value, ( f.iom.checked ? false : true ) );
		}
		document.switch_travel_insurance = function() {
			var mlt = document.getElementById('iom').checked;
			document.getElementById('icm').style.visibility = ( mlt ? 'hidden' : 'visible' );
			document.calender_travel_insurance.ids = ( mlt ? [['Policy Start','ist','isd','ism']] : [['Policy Start','ist','isd','ism'],['Policy End','iet','ied','iem']] );
		}
		new Calender( [['Policy Start','ist','isd','ism'],['Policy End','iet','ied','iem']], 'calender_travel_insurance' );
		var x =	'<form action="/scripts/ainsure.php" method=get id=travel-insurance-form name=travel-insurance-form style="float:right;margin:0px 16px 4px 10px"><table border=0 cellpadding=0 cellspacing=0>';
		x +=	'<tr><td colspan=4><h3>Travel Insurance Quote</h3></td></tr>';
		x +=	'<tr><td><label for=ipr>Residency</label>:</td><td colspan=3><select name=ipr id=ipr><option selected value=gbr>United Kingdom</select></td></tr>';
		x +=	'<tr><td><label for=idc>Destination</label>:</td><td colspan=3><select name=idc id=idc><option value=a>UK &amp; Channel Islands<option selected value=j>Europe<option value=g>Australia / New Zealand<option value=k>Worldwide exc. USA / Canada<option value=l>Worldwide</select></td></tr>';
		x +=	'<tr><td><label for=iom>Multi-trip</label>:</td><td><input type=checkbox name=iom id=iom onclick="document.switch_travel_insurance(\'iom\')"></td><td><label for=ios>Ski&nbsp;cover</label>:</td><td><input type=checkbox name=ios id=ios></td></tr>';
		x +=	'<tr><td><label for=isd>From</label>:</td><td colspan=3>' + this.generate_date_select('isd','ism') + '<input type=image value=Cal src="/images/cal.gif" onclick="return document.calender_travel_insurance.show(event);"></td></tr>';
		x +=	'<tr id=icm><td><label for=ied>To</label>:</td><td colspan=3>' + this.generate_date_select('ied','iem') + '<input type=image value=Cal src="/images/cal.gif" onclick="return document.calender_travel_insurance.show(event);"></td></tr>';
		x +=	'<tr><td><label for=ipa>Adults</label>:</td><td>' + this.generate_integer_select('ipa',1,8) + '</td><td><label for=ipg>Policy</label>:</td><td><select name=ipg id=ipg><option selected value=i>Single<option value=c>Couple<option value=f>Family<option value=g>Group</select></td></tr>';
		x +=	'<tr><td><label for=ipc>Children</label>:</td><td>' + this.generate_integer_select('ipc',0,8) + '</td><td><label for=ipi>Infants</label>:</td><td>' + this.generate_integer_select('ipi',0,8) + '</td></tr>';
		x +=	'<tr><td>&nbsp;</td><td colspan=3><input id=ics type=submit value="Get Insurance Quote" onclick="return document.check_travel_insurance();"></td></tr>';
		return	x + '</table></form>';
	};
	this.calender = function() {
		return (new Calender( [], document.getElementById('info').value, true )).generate();
	};
	if( document.getElementById ) for( var i in this ) {
		var x = document.getElementById( ( 'form-' + i ).replace( '_', '-' ) );
		if( x ) x.innerHTML = this[i]();
}	};

window.onload = function() { document.form_control = new Forms(); return true; }

