
function setCalendarDates(form,current,offset)
{
 var now = new Date();
 var thisMonth = now.getMonth()+1;
 var nextMonth = now.getMonth()+2;
 var thisYear = now.getFullYear();
 var nextYear = now.getFullYear()+1;
 var lastYear = now.getFullYear()-1;
		
// initialize for defaults
 var fromMonth = thisMonth;
 var toMonth = nextMonth;
 var fromYear = thisYear;
 var toYear = thisYear;

 // get the number as it will have a 0 in front for single digits
 var currentMonth = Math.round(current);
 
 
		if (offset == 'next')
		{
		// if december give january for the next year
		  if (currentMonth == 11)
		  {
		  fromMonth = 12;
			toMonth = 1;
			toYear = nextYear;
    	}
			else if (currentMonth == 12)
		  {
		  fromMonth = 1;
			toMonth = 2;
			fromYear = nextYear;
			toYear = nextYear;
    	}
			else
			{
			 fromMonth = currentMonth+1;
			 toMonth = currentMonth+2;
			}
		}
		else if (offset == 'previous')
		{
		// if january, give december of the previous year
		  if (currentMonth == 1)
		  {
		  fromMonth = 12;
			toMonth = 1;
			fromYear = lastYear;
    	}
			else
			{
			 fromMonth = currentMonth-1;
			 toMonth = currentMonth;
			}
		}

		if (fromMonth < 10)
			 fromMonth = '0'+fromMonth;
		
		if (toMonth < 10)
			 toMonth = '0'+toMonth;
		

		form.FromDate.value = fromYear+'-'+fromMonth+'-01';
		form.ToDate.value = toYear+'-'+toMonth+'-01';

		return true;

}

function checkCalendarDate(date)
{
var d = 'date: '+date+'\n';

 var now = new Date(date);
 
 d += 'this month: '+now.getFullYear()+'-'+now.getMonth();

 alert(d);
return true;

}


function loadWelshImages()
{
 		if(document.images){  // preload images
        a0 = new Image(); a0.src = "FILE/Apps/Pass/res/images/w-register-on.gif";
        a1 = new Image(); a1.src = "FILE/Apps/Pass/res/images/w-register-off.gif";

        b0 = new Image(); b0.src = "FILE/Apps/Pass/res/images/w-whatpay-on.gif";
        b1 = new Image(); b1.src = "FILE/Apps/Pass/res/images/w-whatpay-off.gif";

        c0 = new Image(); c0.src = "FILE/Apps/Pass/res/images/w-numbers-on.gif";
        c1 = new Image(); c1.src = "FILE/Apps/Pass/res/images/w-numbers-off.gif";

        d0 = new Image(); d0.src = "FILE/Apps/Pass/res/images/w-wheretravel-on.gif";
        d1 = new Image(); d1.src = "FILE/Apps/Pass/res/images/w-wheretravel-off.gif";

        e0 = new Image(); e0.src = "FILE/Apps/Pass/res/images/w-easy-on.gif";
        e1 = new Image(); e1.src = "FILE/Apps/Pass/res/images/w-easy-off.gif";
        
        f0 = new Image(); f0.src = "FILE/Apps/Pass/res/images/w-dusk-on.gif";
        f1 = new Image(); f1.src = "FILE/Apps/Pass/res/images/w-dusk-off.gif";

        g0 = new Image(); g0.src = "FILE/Apps/Pass/res/images/w-when-on.gif";
        g1 = new Image(); g1.src = "FILE/Apps/Pass/res/images/w-when-off.gif";

        h0 = new Image(); h0.src = "FILE/Apps/Pass/res/images/w-check-on.gif";
        h1 = new Image(); h1.src = "FILE/Apps/Pass/res/images/w-check-off.gif";
				}
}

function loadImages()
{
 
 			if(document.images)
			{  // preload images
			
        a0 = new Image(); a0.src = "FILE/Apps/Pass/res/images/b-register-on.gif";
        a1 = new Image(); a1.src = "FILE/Apps/Pass/res/images/b-register-off.gif";

        b0 = new Image(); b0.src = "FILE/Apps/Pass/res/images/b-whatpay-on.gif";
        b1 = new Image(); b1.src = "FILE/Apps/Pass/res/images/b-whatpay-off.gif";

        c0 = new Image(); c0.src = "FILE/Apps/Pass/res/images/b-numbers-on.gif";
        c1 = new Image(); c1.src = "FILE/Apps/Pass/res/images/b-numbers-off.gif";

        d0 = new Image(); d0.src = "FILE/Apps/Pass/res/images/b-wheretravel-on.gif";
        d1 = new Image(); d1.src = "FILE/Apps/Pass/res/images/b-wheretravel-off.gif";

        e0 = new Image(); e0.src = "FILE/Apps/Pass/res/images/b-easy-on.gif";
        e1 = new Image(); e1.src = "FILE/Apps/Pass/res/images/b-easy-off.gif";
        
        f0 = new Image(); f0.src = "FILE/Apps/Pass/res/images/b-dusk-on.gif";
        f1 = new Image(); f1.src = "FILE/Apps/Pass/res/images/b-dusk-off.gif";

        g0 = new Image(); g0.src = "FILE/Apps/Pass/res/images/b-when-on.gif";
        g1 = new Image(); g1.src = "FILE/Apps/Pass/res/images/b-when-off.gif";

        h0 = new Image(); h0.src = "FILE/Apps/Pass/res/images/b-check-on.gif";
        h1 = new Image(); h1.src = "FILE/Apps/Pass/res/images/b-check-off.gif";
			}
}
function flash(imageName,imageFile) {
        if(!document.images) return;
        eval('document.images[imageName].src = '+imageFile+'.src');
}


function printPage()
{
if (window.print) if (confirm("Print this page?")) window.print();
}

function escapeXML(str) 
{

document.write(escape(str));

}

function setText(form, activity)
{

	if (activity == "PA")
	{		

		document.PB.PA.value = form.PAS[form.PAS.selectedIndex].text;

		document.PB.PAN.value = form.PAS[form.PAS.selectedIndex].value;
	}

	if (activity == "DA")
	{		

		document.PB.DA.value = form.DAS[form.DAS.selectedIndex].text;

		document.PB.DAN.value = form.DAS[form.DAS.selectedIndex].value;
	}
}

function getAddress(file,window) {

	msgWindow=open(file,window,'resizable=no,width=500,height=400');
  	
	if (msgWindow.opener == null) msgWindow.opener = self;
}


function setAddress(field,window) {

	if (field == 'PA')
	{	
		if (window == 'pop')
		{
			opener.document.PB.PAD.value = document.AF.PAS.options[document.AF.PAS.selectedIndex].text;
			opener.document.PB.PAN.value = document.AF.PAS.options[document.AF.PAS.selectedIndex].value;
			opener.document.PB.PAM.value = 'LO';
		}
		else
		{
			document.PB.PAD.value = document.PB.PAS.options[document.PB.PAS.selectedIndex].text;
			document.PB.PAN.value = document.PB.PAS.options[document.PB.PAS.selectedIndex].value;
		}
	}
	else if (field == 'DA')
	{
	 if (window == 'pop')
	 {
	 	opener.document.PB.DAD.value = document.AF.DAS.options[document.AF.DAS.selectedIndex].text;
		opener.document.PB.DAN.value = document.AF.DAS.options[document.AF.DAS.selectedIndex].value;
		opener.document.PB.DAM.value = 'LO';
	 }
	 else
	 {
	 	document.PB.DAD.value = document.PB.DAS.options[document.PB.DAS.selectedIndex].text;
		document.PB.DAN.value = document.PB.DAS.options[document.PB.DAS.selectedIndex].value;
	 }
	 
	}
	else alert('No address field defined');

	return false;
}

function doneAddress()
{
	self.close();
}


var passengerList = new Array(2);

function addPassenger(form) 
{

	var passenger = form.PPT.value + ';' + form.PST.value;

	var passengerdesc = form.PPT.options[form.PPT.selectedIndex].text + ':' + form.PST.options[form.PST.selectedIndex].text;

	var i = 0;

	for (i;i<2;i++)
	{
		if (form.ADP.options[i].value == 'AP')
		{
			form.ADP.options[i].text= passengerdesc;

			form.ADP.options[i].value= passenger;

			return;
		}
	}
}

function deletePassenger(form) 
{

 				 if (eval(form.ADP.selectedIndex) != -1)
 				 {
				 form.ADP.options[form.ADP.selectedIndex].value = 'AP';
				 form.ADP.options[form.ADP.selectedIndex].text = '-- Additional Passenger? --';
				 }
				 else
				 {
				 alert("You don't have any passengers selected");
				 }
	
}

function setPassengerList(form)
{
	var i = 0;

	for (i;i<2;i++)
	{
			passengerList[i] = form.ADP.options[i].value;
	}

  form.PL.value = passengerList;
	
}

function resetForm(form)
{

 	form.submit();
}


function bookTrip(form,isSub)
{

var error ='';

		if(isSub == true)
		{ // check if at least one day has been checked off
			if (form.WS.checked || form.WM.checked || form.WT.checked || form.WW.checked || form.WH.checked || form.WF.checked || form.WA.checked)
			{
			}
			else
			{
				 error += "Please select at least one day\n";
			}		 
		}


	if (form.PT.value=='NT' && activity=='BT') 
	{
		error += 'Please enter a pick-up time\n';
		
	}


	if (form.PAD.value=='RA' || form.PAD.value=='')
	{
		error += 'Please enter a pick-up address\n';
		
	}

	if (form.DAD.value=='RA' || form.DAD.value=='')
	{
		error += 'Please enter an appointment address\n';
		
	}

	if (form.PAD.value == form.DAD.value)
	{
		error += 'The appointment address is the same as the pick-up address\n';
	}
	
	
	if (error == '')
	{ 
		form.FormValid.value = '1';
		return true;
	}
	else
	{
	 alert(error);
	 
	 return false;
	 
	}

}


function login(form)
{
	

var error ='';


	if (form.UN.value=='') 
	{
		error += 'Please enter a user name\n';
		
	}


	if (form.PW.value=='')
	{
		error += 'Please enter a password\n';
		
	}


	if (error == '')
	{ 
		return true;
	}
	else
	{
	 alert(error);
	 
	 return false;
	 
	}

}

function checkPassword(form)
{
	
var error ='';

	if (form.P.value=='') 
	{
		error += 'Please enter your old password\n';
		
	}
	if (form.NP.value=='')
	{
		error += 'Please enter a new password\n';
		
	}
	if (form.NPT.value=='')
	{
		error += 'Please enter your new password again\n';
		
	}
	if (form.NPT.value != form.NP.value)
	{
		error += 'Your new password has to match\n';
		
	}

	if (error == '')
	{ 
		return true;
	}
	else
	{
	 alert(error);
	 
	 return false;
	 
	}

}

function showhelp(what)
{
	var helptext = new Array(8);
	helptext[0] = "<img src='FILE/Apps/Pass/res/images/b-register-on.gif' border=0><br>";
	helptext[0] += "To use the Shuttle all you need to do is register, which is free. Registration cards are obtainable on any Shuttle bus and also from the Personnel Departments of all participating businesses. All completed cards should be accompanied with a passport sized photo - a Smart Card to use the bus will then automatically be issued out to you.<br><br>";
	helptext[0] += "Registration can also be done over the phone or on-line, but registrations done in this way will not be issued with a Smart Card, and journeys can then only be made by paying cash to the driver.";
	
	helptext[1] = "<img src='FILE/Apps/Pass/res/images/b-whatpay-on.gif' border=0><br>";
	helptext[1] += "A single journey costs just &pound;1.00, or you can buy a week's unlimited travel for just £5.00. Payment can be with cash to the driver, or with a Smart Card. Some trips are discounted to 90p if you use stored value smartcards. For regular users, you can even arrange for the cost of your weekly travel to be automatically deducted direct from your pay.";
	
	helptext[2] = "<img src='FILE/Apps/Pass/res/images/b-numbers-on.gif' border=0><br>";
	helptext[2] += "Just call <b>08708 50 51 55</b><br><br>";
	helptext[2] += "Use either option to book your pick up whenever you need it.";

	helptext[3] = "<img src='FILE/Apps/Pass/res/images/b-wheretravel-on.gif' border=0><br>";
	helptext[3] += "The Deeside Shuttle now operates between the Flint, Connah's Quay, Shotton, Queensferry, Mancot and Sandycroft* residential areas, the Connah's Quay job centre and the Deeside Industrial Park as shown on the map.  Eventually we hope the service will cover most of Flintshire and link with public transport from Cheshire, The Wirral and North Wales.<br/>* The service for Mancot and Sandycroft will be available from February 2004.";
	
	helptext[4] = "<img src='FILE/Apps/Pass/res/images/b-easy-on.gif' border=0><br>";
	helptext[4] += "Once registered just call or go on-line and you can then confirm availability and pick-up time / location. The Shuttle will pick you up and take you directly to your place of work within the Deeside Industrial Park.<br><br>";
	helptext[4] += "On registration you will be advised if there is a specific difficulty in reaching your home, for instance if you live in a very narrow street or a dead-end road. Every effort will be made to arrange a suitable pick up point as close to your home as possible.<br><br>";
	helptext[4] += "At your place of work, the Shuttle will drop you off at a designated area close to the main entrance. This will also be the place where the Shuttle will pick you up from on the return journey.";

	helptext[5] = "<img src='FILE/Apps/Pass/res/images/b-dusk-on.gif' border=0><br>";
	helptext[5] += "Outside of the main daylight hours, or during periods of lower demand, the Shuttle service may use a taxi to pick up and drop off. Any vehicle used under the Deeside Shuttle scheme will always feature the Deeside Shuttle logo.";

	helptext[6] = "<img src='FILE/Apps/Pass/res/images/b-when-on.gif' border=0><br>";
	helptext[6] += "The service is available 24 hours a day, 7 days a week, so whether you work shifts, part time or normal office hours, there is a Shuttle on call to get you there.<br><br>";
	helptext[6] += "Late emergency bookings can be made up to 45 minutes before you need the service, but the earlier you are able to book the better as spaces are allocated on a first-come-first-served basis. It is even possible to block book a regular seat up-front on an ongoing basis.  When booking you will be advised whether space on the Shuttle is available at your preferred time.";

	helptext[7] = "<img src='FILE/Apps/Pass/res/images/b-check-on.gif' border=0><br>";
	helptext[7] += "An up-to-date list of the businesses served can be seen by clicking on the link below. Alternatively, you can also check with the Personnel or Human Resources department within your organisation that should be able to help.";

	helptext[8] = "<b>Businesses Served</b><br><br>";
	helptext[8] += "<table width=100% border=0><tr><td><b>Iceland Foods Plc</b><br>Second Avenue<br>Deeside Industrial Park<br>CH5 2NW<br><br><b>Mainetti (UK) Ltd</b><br>Unit 34<br>Deeside Industrial Park<br>CH5 2NU<br><br><b>Dailycer Limited</b><br>Fourth Avenue<br>Deeside Industrial Park<br>CH5 2NR<br><br></td>";
	helptext[8] += "<td valign=top><b>Convatec Limited</b><br>Unit 20 <br>First Avenue<br>Deeside Industrial Park<br>CH5 2NU<br><br><b>Hazlewood Pizza</b><br>3 New Tech Square <br>Deeside Industrial Park <br>CH5 2NT</td>";

	if (myhelper.style.display == "none")
	{
		content.innerHTML = helptext[what-1];
		myhelper.style.display = "inline";
		
	}
	else
	{
		myhelper.style.display = "none";
	}
		
}

function showhelpWelsh(what)
{
	var helptext = new Array(8);
	helptext[0] = "<img src='FILE/Apps/Pass/res/images/w-register-on.gif' border=0><br>";
	helptext[0] += "I ddefnyddio'r Shuttle, yr unig beth sydd angen ei wneud yw cofrestru, sydd yn rhad ac am ddim. Mae cardiau cofrestru ar gael ar unrhyw fws Shuttle, a hefyd gan Adrannau Person&eacute;l yr holl fusnesau sy'n rhan o'r cynllun. Dylid cyflwyno ffotograff maint pasport gyda'r cerdyn ar &ocirc;l ei gwblhau - ac yna anfonir Cerdyn Smart i ddefnyddio'r bws atoch yn awtomatig.<br><br>";
	helptext[0] += "Medrwch hefyd gofrestru dros y ff&ocirc;n neu ar-lein, ond os gwnewch hyn, ni chyflwynir Cerdyn Smart, a medrwch deithio dim ond trwy dalu arian parod i'r gyrrwr.";
	
	helptext[1] = "<img src='FILE/Apps/Pass/res/images/w-whatpay-on.gif' border=0><br>";
	helptext[1] += "Mae un daith yn costio £1.00 yn unig, neu medrwch brynu gwasanaeth diderfyn am wythnos am £5.00. Medrwch dalu gydag arian parod i'r gyrrwr, neu gyda Cherdyn Smart. Mae disgownt ar rai teithiau i 90c os defnyddiwch gardiau Smart gyda gwerth wedi ei storio. Ar gyfer teithwyr rheolaidd, medrwch hyd yn oed drefnu bod cost eich teithiau wythnosol yn cael ei dynnu yn awtomatig o'ch cyflog.";
	
	helptext[2] = "<img src='FILE/Apps/Pass/res/images/w-numbers-on.gif' border=0><br>";
	helptext[2] += "Ffoniwch <b>08708 50 51 55</b><br><br>";
	helptext[2] += "Defnyddiwch y naill opsiwn neu'r llall i drefnu eich codi pryd bynnag yr hoffwch, a chofrestru eich enw a'ch manylion - mae mor hawdd &acirc; hynny!";

	helptext[3] = "<img src='FILE/Apps/Pass/res/images/w-wheretravel-on.gif' border=0><br>";
	helptext[3] += "Mae Shuttle Glannau Dyfrdwy nawr yn gweithredu rhwng ardaloedd preswyl Y Fflint, Cei Connah,  Shotton, Y Fferi Isaf, Mancot a Sandycroft*, canolfan gwaith Cei Connah a Pharc Diwydiannol Glannau Dyfrdwy, fel a ddangosir ar y map isod.  Y gobaith yn y pen draw yw y bydd yn gwasanaethu'r rhan fwyaf o Sir y Fflint ac yn cysylltu gyda thrafnidiaeth gyhoeddus o Sir Gaer, Cilgwri a Gogled Cymru.<br/>* Bydd y gwasanaeth ar gyfer Mancot a Sandycroft ar gael o fis Chwefror 2004";
	
	helptext[4] = "<img src='FILE/Apps/Pass/res/images/w-easy-on.gif' border=0><br>";
	helptext[4] += "Unwaith y byddwch wedi cofrestru, medrwch ffonio neu fynd ar-lein i gadarnhau bod lle ar gael a'r amser/lleoliad codi. Bydd y Deeside Shuttle yn eich codi a mynd &acirc; chi yn uniongyrchol i'ch man gwaith ar Barc Diwydiannol Glannau Dyfrdwy.<br><br>";
	helptext[4] += "Pan fyddwch yn cofrestru, dywedir wrthych os oes anhawster penodol wrth gyrraedd eich cartref, er enghraifft os ydych yn byw ar stryd gul iawn neu ar stryd bengaead. Gwneir pob ymdrech i drefnu man codi sydd mor agos i'ch cartref ag y bo modd.<br><br>";
	helptext[4] += "Yn eich man gwaith, bydd y Deeside Shuttle yn eich gollwng mewn man penodol ger y brif fynedfa. Dyma hefyd lle bydd y Deeside Shuttle yn eich codi ar gyfer y daith gartref.";

	helptext[5] = "<img src='FILE/Apps/Pass/res/images/w-dusk-on.gif' border=0><br>";
	helptext[5] += "Y tu allan i'r prif oriau golau dydd, neu yn ystod cyfnodau lle mae llai o alw, efallai y bydd y gwasanaeth yn defnyddio tacsi. Bydd unrhyw gerbyd a ddefnyddir dan Gynllun Deeside Shuttle bob amser yn dangos logo'r Deeside Shuttle.";

	helptext[6] = "<img src='FILE/Apps/Pass/res/images/w-when-on.gif' border=0><br>";
	helptext[6] += "Mae'r gwasanaeth ar gael 24 awr y dydd, 7 diwrnod yr wythnos, felly os ydych yn gweithio stemiau, yn gweithio rhan amser neu oriau swyddfa arferol, bydd Deeside Shuttle ar gael i fynd &acirc; chi yno.<br><br>";
	helptext[6] += "Gellir trefnu hyd at 45 munud cyn byddwch angen y gwasanaeth, ond mae'n well os trefnwch yn gynt na hynny, oherwydd dyrennir lle ar sail \"y cyntaf i'r felin\". Mae modd hyd yn oed trefnu sedd reolaidd ymlaen llaw. Pan yn trefnu, dywedir wrthych os oes lle ar gael ar y Deeside Shuttle ar yr adeg sydd orau i chi.";

	helptext[7] = "<img src='FILE/Apps/Pass/res/images/w-check-on.gif' border=0><br>";
	helptext[7] += "Mae rhestr o'r holl fusnesau a wasanaethir i'w gweld trwy glicio ar y cysylltiad a ddangosir isod. Fel arall, medrwch hefyd holi adran Person&eacute;l neu Adnoddau Dynol eich cwmni, a dylent hwythau fedru helpu.";

	helptext[8] = "<b>Busnesau a Wasanaethir</b><br><br>";
	helptext[8] += "<table width=100% border=0><tr><td><b>Iceland Foods Plc</b><br>Second Avenue<br>Parc Diwydiannol Glannau Dyfrdwy<br>CH5 2NW<br><br><b>Mainetti (UK) Ltd</b><br>Uned 34<br>Parc Diwydiannol Glannau Dyfrdwy<br>CH5 2NU<br><br><b>Dailycer Limited</b><br>Fourth Avenue<br>Parc Diwydiannol Glannau Dyfrdwy<br>CH5 2NR<br><br></td>";
	helptext[8] += "<td valign=top><b>Convatec Limited</b><br>Uned 20 <br>First Avenue<br>Parc Diwydiannol Glannau Dyfrdwy<br>CH5 2NU<br><br><b>Hazlewood Pizza</b><br>3 New Tech Square <br>Parc Diwydiannol Glannau Dyfrdwy <br>CH5 2NT</td>";

	if (myhelper.style.display == "none")
	{
		content.innerHTML = helptext[what-1];
		myhelper.style.display = "inline";
		
	}
	else
	{
		myhelper.style.display = "none";
	}
		
}


function Register(form)
{

var error ='';


	if (form.FN.value=='') 
	{
		error += 'Please enter a First Name\n';
		
	}

	if (form.LN.value=='') 
	{
		error += 'Please enter a Last Name\n';
		
	}


	if (form.H.value=='')
	{
		error += 'Please enter a House Name/No\n';
		
	}

	if (form.R.value=='')
	{
		error += 'Please enter a Road Name\n';
		
	}

	if (form.HP.value=='')
	{
		error += 'Please enter a Home Phone number\n';
		
	}

	if (form.CompanyName.value=='')
	{
		error += 'Please enter a Company Name\n';
		
	}

	if (error == '')
	{ 
		return true;
	}
	else
	{
	 alert(error);
	 
	 return false;
	 
	}

}

