function padTo(v){
	// add '0' to day/month
	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){

	var fDay;
	var fMonth;
	var fYear;
	
	var fRDay;
	var fRMonth;
	var fRYear;
	
	var fLoc;
	var msg = '';

	var aMonth			= new Array();
		aMonth['jan']	= '01';
		aMonth['feb']	= '02';
		aMonth['mar']	= '03';
		aMonth['apr']	= '04';
		aMonth['may']	= '05';
		aMonth['jun']	= '06';
		aMonth['jul']	= '07';
		aMonth['aug']	= '08';
		aMonth['sep']	= '09';
		aMonth['oct']	= '10';
		aMonth['nov']	= '11';
		aMonth['dec']	= '12';

	if (oForm.elements){

		/* NOT NEEDED ANYMORE AS 'ALL' QUOTES GO TO RESULTS, INSTEAD OF JUST SINGLE HOTEL QUOTES
		if(document.forms[0] && (document.forms[0].elements['filter_hotel']) && (document.forms[0].elements['filter_hotel'].checked == true)){
			document.forms[0].elements['stage'].value = '2';
		}else{
			document.forms[0].elements['stage'].value = '1';
		}
		*/

		if (fLoc = oForm.elements['airport']){

			if (fLoc.options){

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

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

					msg = 'Please select a Location...';
				}
			}
		}else{
			return true;
		}

		if(!msg){

			if(!oForm.elements['is_adv']){ return true; }

			if(oForm.elements['is_adv'].value == 0){

				if(oForm.elements['ArrivalDateBasic']){

					var fulldate_array = oForm.elements['ArrivalDateBasic'].value.split("-");

					fDay	= fulldate_array[0];
					fMonth	= fulldate_array[1];
					fYear	= '20' + fulldate_array[2];
				
				}else{
					return true;
				}
				
				if (oForm.elements['ReturnDateBasic']) {
					var ret_fulldate_array = oForm.elements['ReturnDateBasic'].value.split("-");
					
					fRDay = ret_fulldate_array[0];
					fRMonth = ret_fulldate_array[1];
					fRYear = '20' + ret_fulldate_array[2];
				} else {
					return true;
				}

			}else{

				if (oForm.elements['ArrivalDayAdv']) { var fDay = oForm.elements['ArrivalDayAdv'].value; }else{ return true; }
				if (oForm.elements['ReturnDayAdv']) { var fRDay = oForm.elements['ReturnDayAdv'].value; }else{ return true; }

				if (oForm.elements['ArrivalMonYrAdv']) {

					var monthyear_array	= oForm.elements['ArrivalMonYrAdv'].value.split("-");

					fMonth	= monthyear_array[0];
					fYear	= '20' + monthyear_array[1];

				} else {
					return true;
				}
				if (oForm.elements['ReturnMonYrAdv']) {
					var ret_monthyear_array = oForm.elements['ReturnMonYrAdv'].value.split("-");
					
					fRMonth = ret_monthyear_array[0];
					fRYear = '20' + ret_monthyear_array[1];
				} else {
					return true;
				}

			}
			fMonth = aMonth[fMonth];
			fRMonth = aMonth[fRMonth];
			if(!fMonth || !fRMonth){
				return true;
			}

		}

		if(!msg){

			if(!validDate(fDay, fMonth, fYear)){
				msg = 'Your Stay Date seems to be incorrect...';
			}
			if (!msg && !validDate(fRDay, fRMonth, fRYear)) {
				msg = 'Your Return Date seems to be incorrect...';
			}
		}

		if(!msg){

			var now = new Date();

			if (!now) {
				return true;
			}
			var today = new Date(now.getMonth()+'/'+now.getDate+'/'+now.getYear());
			var arrivalDate = new Date(fMonth+'/'+fDay+'/'+fYear);
			var returnDate = new Date(fRMonth+'/'+fRDay+'/'+fRYear);

			if(arrivalDate.getTime() < today.getTime()) {
				msg = 'You can\'t have your arrival date before today...';
			} else if (returnDate.getTime() <= arrivalDate.getTime()) {
				msg = 'You can\'t have your return date before or on your arrival date...';
			}
		}
	}
	if(msg){
		
		alert(msg);

		if(thequotebutton = document.getElementById('quote_button')){
			thequotebutton.src = thequotebutton.src.replace('_down','');
		}

		return false;

	}else{
		 oForm.action = "/list_results.html";
		return true;
	}
}



function tdRollOver(obj, state)
{
	if(document.getElementById)
	{
		document.getElementById('td' + obj).style.backgroundColor = (state == 'on') ? '#A5B6C6' : '#7D91A4';
	}
}

function displayEmail(who)
{
	//
	//<script type="text/javascript">document.write(displayEmail("who"))</script>
	//

	var address;
	var thedomain;
	var ext;
	var fullAddress;
	var returnAddress;
	var subject = "";

	if (who == "aph_cancel")
	{
		address = "webhelp";
		thedomain = "parkaph";
		ext = ".co.uk";
		subject = "?subject=Amendment/Cancellation";
	}
	if (who == "fhr_cancel")
	{
		address = "reservations";
		thedomain = "fhr-net";
		ext = ".co.uk";
		subject = "?subject=Amendment/Cancellation";
	}
	if (who == "sb_cancel")
	{
		address = "bookings";
		thedomain = "superbreak";
		ext = ".com";
		subject = "?subject=Amendment/Cancellation";
	}
	if (who == "he_cancel")
	{
		address = "salesadmin";
		thedomain = "holidayextras";
		ext = ".com";
		subject = "?subject=Amendment/Cancellation";
	}
	if (who == "ahs_claim")
	{
		address = "booking";
		thedomain = "airport-hotel-shop";
		ext = ".co.uk";
		subject = "?subject=Claim";
	}
	if (who == "ahs")
	{
		address = "booking";
		thedomain = "airport-hotel-shop";
		ext = ".co.uk";
	}
	if (who == "pricematch")
	{
		address = "booking";
		thedomain = "airport-hotel-shop";
		ext = ".co.uk";
		subject = "?subject=Price&#32;match";
	}



	fullAddress = address+"@"+thedomain+ext+subject;
	displayAddress = address+"@"+thedomain+ext;
  
	returnAddress = "<span class=\"bold\"><a href=\"mailto:"+fullAddress+"\">"+displayAddress+"</a></span>";
  
	return(returnAddress);
}

function changequote(item, state){

	if(item.src.indexOf('_down') == '-1'){

		re = new RegExp('images/([a-z///-]*)([_]?[a-z]*)(.gif|.jpg)');
		mymatch = re.exec(item.src);

		switch(state){
			case 'on':
				item.src='/images/'+mymatch[1]+'_over'+mymatch[3];
			break;
			case 'off':
				item.src='/images/'+mymatch[1]+mymatch[3];
			break;
			case 'down':
				item.src='/images/'+mymatch[1]+'_down'+mymatch[3];
			break;
		}

	}

}

function buttondown(item){

	rExpExt = '_over';
	newExt = '_down';
	item.src=item.src.replace(rExpExt,newExt);

}

function init(){

	if(window.locInit)		window.locInit();
	if(window.unloadInit)	window.unloadInit();

	if(document.getElementById){

		if(document.getElementById('advtext') && document.getElementById('basictext') && document.getElementById('advdate') && document.getElementById('basicdate') && document.forms[0].elements['is_adv']){

			var advance_text	= document.getElementById('advtext');
			var basic_text		= document.getElementById('basictext');
			var advance			= document.getElementById('advdate');
			var basic			= document.getElementById('basicdate');
			var choose			= document.forms[0].elements['is_adv'];

			if(choose.value == 1){

				advance_text.style.display = 'block';
				advance.style.display = 'block';
				basic_text.style.display = 'none';
				basic.style.display = 'none';
				
			}else{
				
				advance_text.style.display = 'none';
				advance.style.display = 'none';
				basic_text.style.display = 'block';
				basic.style.display = 'block';

			}

		}

	}

	/*@cc_on @*/
	/*@if (@_jscript_version < 5.5)
	   testconfirm = confirm('It appears you are using a very old version of Internet Explorer for Windows\nIt is recommended to upgrade your browser to the newest version (which is currently IE 6)\n\nTo update your computer via the offcial windows update website, click "OK", or click "Cancel" to continue to AHS.');
		if(testconfirm)
			 window.location = "http://windowsupdate.microsoft.com/";
	@*/
	/*@end @*/

}

function addbookmark(url,desc){

	var nonie = 'Sorry, only Internet Explorer supports this method to add a bookmark/favourite\n But please feel free to visit the site\'s home page to add a bookmark manually';

	if(!url && !desc){
		var bookmarkurl		= "http://www.car-hire-centre.co.uk";
		var bookmarktitle	= "Car-Hire-Centre.co.uk - Compare and Book Car Hire Around the World";
	}else{
		var bookmarkurl		= url;
		var bookmarktitle	= desc;
	}
	

	if (window.sidebar) { // Mozilla Firefox Bookmark
		alert('Due to security restrictions placed in Firefox, we are unable to automatically add a bookmark.\nPlease navigate to the home page and press: CTRL+D to add one manually.');
	} else if(document.all){ // IE Favourites
		window.external.AddFavorite(bookmarkurl,bookmarktitle);
	} else {
		alert(nonie);
	}

}

window.onload = init;