var bookmarkurl		= "http://www.airport-parking-guide.co.uk"
var bookmarktitle	= "Airport Parking Guide"

var Form_name;
Form_name = 'SelForm';

var can_submit = false;
function submit_quote()
{
	if( can_submit )
	{
		can_submit = false;
//		SelForm.action = "search.php?id=" +  SelForm.uid.value;
		SelForm.action = "/search/" +  SelForm.uid.value;		
		SelForm.submit();
	}
}
function make_uid()
{
	if( checkForm( SelForm ) )
	{
		can_submit = true;	  
		var frame = window.frameNoise;
		var frm = frame.document.formHidden;
		frm.submit();
	}
}


function addbookmark(){
	if (document.all) window.external.AddFavorite(bookmarkurl,bookmarktitle)
}


function doPopup(oForm, sType, sUrl) {

	
	switch(sType){
	case 'parkingTypes':

	window.open(sUrl,'apg_types','height=600,width=760,resizable=yes,menubar=no,location=yes,scrollbars=yes,status=yes,toolbar=yes');
	return true;

	break;
	default:

	window.open('','apg_popup','height=600px,width=735px,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=yes');
	return true;

	break;
	}

}


function padTo(v){

	if(v.toString)		v = v.toString();
	if(v.length < 2)	v = '0' + v;

	return v;

}

function validDate(day, month, year){

	var temp = new Date(month+'/'+day+'/'+year);
	var day2 = padTo(temp.getDate());
	if(day2 != day){
		return false;

	}else{

		return true;

	}

}

function checkForm(oForm){


	/* Elements
	------------------------------------
	ddd			[ .value (01 - 31) ]
	ddm 		[ .value (01 - 12) ]
	ddy 		[ .value (03 - 04) ]
	dth 		[ .value (00 - 23) ]
	dtm 		[ .value (00 - 59) ]

	rdd 		[ .value (01 - 31) ]
	rdm     	[ .value (01 - 12) ]
	rdy 		[ .value (03 - 04) ]

	px			[ .value (1 - ...) ]
	------------------------------------
	*/

	if(!oForm) return;

	var temp;
	var msg = '';

	var aMonth			= new Array();
		aMonth['01']	= '01';
		aMonth['02']	= '02';
		aMonth['03']	= '03';
		aMonth['04']	= '04';
		aMonth['05']	= '05';
		aMonth['06']	= '06';
		aMonth['07']	= '07';
		aMonth['08']	= '08';
		aMonth['09']	= '09';
		aMonth['10']	= '10';
		aMonth['11']	= '11';
		aMonth['12']	= '12';

	if(oForm.elements){

		if(temp = oForm.elements['ap']){
			
			if(temp.options){

				var airport = temp.options[temp.selectedIndex].value;

				if(!airport || airport == 'ALL'){

					msg = 'Please select a Location...';

				}

			}

		}else{

			return true;

		}

		if(!msg){

			if(oForm.elements['ddd']){		var arrDay		= oForm.elements['ddd'].value;				}else{ return true; }
			if(oForm.elements['ddm']){	    var arrMonth	= oForm.elements['ddm'].value;			}else{ return true; }
			if(oForm.elements['ddy']){		var arrYear		= '20' + oForm.elements['ddy'].value;		}else{ return true; }
			if(oForm.elements['dth']){		var arrHour		= oForm.elements['dth'].value;				}else{ return true; }
			if(oForm.elements['dtm']){	    var arrMins		= oForm.elements['dtm'].value;			}else{ return true; }
			if(oForm.elements['rdd']){	    var retDay		= oForm.elements['rdd'].value;			}else{ return true; }
			if(oForm.elements['rdm']){	    var retMonth	= oForm.elements['rdm'].value;			}else{ return true; }
			if(oForm.elements['rdy']){	    var retYear		= '20' + oForm.elements['rdy'].value;	}else{ return true; }
			if(oForm.elements['px']){		var pax			= oForm.elements['px'].value;				}else{ return true; }

			
			if(temp = aMonth[retMonth]){
				var retMonth = temp;
			}else{
				return true;
			}

			if(temp = aMonth[arrMonth]){
				var arrMonth = temp;
			}else{
				return true;
			}

		}

	}else{

		return true;

	}

	if(!msg){
		
		if(!validDate(arrDay, arrMonth, arrYear)){

			msg = 'Your arrival Date seems to be incorrect...';

		}else{

			if(!validDate(retDay, retMonth, retYear)){

				msg = 'Your return Date seems to be incorrect...';

			}

		}

	}

	if(!msg){

		var now = new Date();

		if(now){

			var nowDay		= padTo(now.getDate());
			var nowMonth	= padTo(now.getMonth() + 1);
			var nowYear		= padTo(now.getFullYear());
			var nowHour		= padTo(now.getHours());
			var nowMins		= padTo(now.getMinutes());

		}else{

			return true;

		}

		if(arrYear == nowYear){

			if(arrMonth < nowMonth){

				msg = 'You can\'t have your arrival Month before this month...';

			}else if(arrMonth == nowMonth){

				if(arrDay == nowDay){

					if(arrHour == nowHour){

						if(arrMins < nowMins){

							msg = 'You can\'t have an arrival Time in the past...';

						}

					}else if(arrHour < nowHour){

						msg = 'You can\'t have an arrival Time in the past...';

					}

				}else if(arrDay < nowDay){

					msg = 'You can\'t have your arrival Day before today...';

				}

			}

		}else if(arrYear > nowYear){

		}else{

			msg = 'You can\'t have your arrival Year before this year...';

		}

		if(!msg){

			var std_msg = 'You can\'t have your return Date before your arrival...'

			if(retYear < arrYear){

				msg = std_msg;

			}else if(retYear == arrYear){

				if(retMonth < arrMonth){

					msg = std_msg;

				}else if(retMonth == arrMonth){

					if(retDay < arrDay){

						msg = std_msg;

					}else if(retDay == arrDay){

						

					}

				}

			}

		}

	}

	if(msg){
		
		alert(msg);
		return false;

	}else{

		return true;

	}

}

var temp = new Image();
temp.src = '/images/form-image3/gif';


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function findTodaysDate() {

  var todaysDay;
  var todaysMonth;
  var todaysYear;
  var objDate;
  var yearstr;
  var year;
  
  objDate = new Date();
  
  //Auto Set Arrival Date

  objDate =  DateAdd(objDate , 'd', 2);

  todaysDay = objDate.getDate();
  todaysMonth = objDate.getMonth();
  todaysYear = objDate.getFullYear();
  if(todaysYear=="2009")
  {
  	year="09"
  }
  if(todaysYear=="2010")
  {
  	year="10"
  }
  
  MM_findObj("ddd").selectedIndex = (todaysDay);
  
  MM_findObj("ddm").selectedIndex = todaysMonth + 1;
  if (MM_findObj("ddy")[1].value == year )
	MM_findObj("ddy").selectedIndex = 1;
  else
	MM_findObj("ddy").selectedIndex = 2;

  //Auto Set Return Date 

  objDate =  DateAdd(objDate , 'd', 7);

  todaysDay = objDate.getDate();
  todaysMonth = objDate.getMonth();
  todaysYear = objDate.getYear();
  if(todaysYear=="2007")
  {
  	year="07"
  }
  if(todaysYear=="2008")
  {
  	year="08"
  }

  
  MM_findObj("rdd").selectedIndex = (todaysDay);
  MM_findObj("rdm").selectedIndex = todaysMonth + 1;
  if (MM_findObj("rdy")[1].value == year)
	MM_findObj("rdy").selectedIndex = 1;
  else
	MM_findObj("rdy").selectedIndex = 2;

}

function DateAdd(datDate, strInterval, lngOffset)
{
  var datMilliseconds = Date.parse(datDate);

  if (isNaN(datMilliseconds))
     {
     alert('Invalid Date Format');
     return (datDate);
     }

  if (isNaN(lngOffset))
     {
     alert('Invalid Offset');
     return (datDate);
     }

  strInterval = strInterval.charAt(0).toUpperCase();

  switch (strInterval)
       {
       case 'D':
            lngOffset *= 24;          // days to hours
       case 'H':
            lngOffset *= 60;          // hours to minutes
       case 'M':
            lngOffset *= 60;          // minutes to seconds
       case 'S':
            lngOffset *= 1000;          // seconds to milliseconds
            break;
       default:
            alert('Invalid Interval');
            return (datDate);
       }

  return new Date(datMilliseconds + lngOffset);
}

var safety=0;

function checkap(ap)
{
	alert("HTML   "+ap);
	var page = checkPage(this.value);
	alert(page);
}

function validate() {
	if (document.signup.fname.value == '') {
		window.alert('Please fill in your first name.');
		return false;
	}
	if (document.signup.lname.value == '') {
		window.alert('Please fill in your last name.');
		return false;
	}
	if (document.signup.email.value == '') {
		window.alert('Please fill in your email address.');
		return false;
	}
	if (document.signup.user1.value == '') {
		window.alert('Please fill in your booking reference number.');
		return false;
	}
	if (document.signup.user2.value == '') {
		window.alert('Please fill in your password choice.');
		return false;
	}
	return true;
}

function greeting() {
Now = new Date()
Hour = Now.getHours();
if (Hour < 5)
msg ="Can't Sleep, in that case Welcome to the Airport Parking Guide."
else if(Hour <12)
msg ="Good Morning and Welcome to the Airport Parking Guide."
else if(Hour < 18)
msg ="Good Afternoon and Welcome to the Airport Parking Guide."
else if (Hour < 24)
msg ="Good Evening. We hope you have had a pleasant day."
return( msg )
}




