//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();

// change below for number of days
SecondDate = DateAdd(Now,4,0,0);
SecondDay = SecondDate.getDate();
SecondMonth = SecondDate.getMonth();
SecondYear = SecondDate.getYear();

//set now to two days time date
Now =  DateAdd(Now,1,0,0);
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();

if (NowYear < 2000) NowYear += 1900; //for Netscape
if (SecondYear < 2000) SecondYear += 1900; //for Netscape


function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//function to add dates
function DateAdd(startDate, numDays, numMonths, numYears)
{
	var returnDate = new Date(startDate.getTime());
	var yearsToAdd = numYears;
	var month = returnDate.getMonth() + numMonths;
	
	if (month > 11)
	{
		yearsToAdd = Math.floor((month+1)/12);
		month -= 12*yearsToAdd;
		yearsToAdd += numYears;
	}
	
	returnDate.setMonth(month);	
	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);
	return returnDate;
}

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
	var DaysInMonth = 31;
	if (WhichMonth == "04" || WhichMonth == "06" || WhichMonth == "09" || WhichMonth == "11") DaysInMonth = 30;
	if (WhichMonth == "02" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
	if (WhichMonth == "02" && (WhichYear/4) == Math.floor(WhichYear/4))	DaysInMonth = 29;
	return DaysInMonth;
}

//function to change the available days in a months
function ChangeOptionDays(Which)
{
	DaysObject = eval("document.GetQuote." + Which + "Day");
	MonthObject = eval("document.GetQuote." + Which + "Month");
	

	Month = MonthObject[MonthObject.selectedIndex].value.substr(0,2);
	Year = MonthObject[MonthObject.selectedIndex].value.substr(2,4);

	DaysForThisSelection = DaysInMonth(Month, Year);
	CurrentDaysInSelection = DaysObject.length;
	
	if (CurrentDaysInSelection > DaysForThisSelection)
	{
		for (icounter=0; icounter<(CurrentDaysInSelection-DaysForThisSelection); icounter++)
		{
			DaysObject.options[DaysObject.options.length - 1] = null
		}
	}
	
	if (DaysForThisSelection > CurrentDaysInSelection)
	{
		for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
		{
			NewOption = new Option(DaysObject.options.length + 1);
			DaysObject.options[DaysObject.options.length]=NewOption;
		}
	}

	if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
		
}

function updateReturnDate()
{
	DaysObject = eval("document.GetQuote.PickUpDay");
	MonthObject = eval("document.GetQuote.PickUpMonth");

	Month = MonthObject[MonthObject.selectedIndex].value.substr(0,2);
	Year = MonthObject[MonthObject.selectedIndex].value.substr(2,4);
	
	var PickUpDate = new Date();
	PickUpDate.setFullYear(Year,Month-1,DaysObject.selectedIndex+1);
	
	DaysObject = eval("document.GetQuote.ReturnDay");
	MonthObject = eval("document.GetQuote.ReturnMonth");

	Month = MonthObject[MonthObject.selectedIndex].value.substr(0,2);
	Year = MonthObject[MonthObject.selectedIndex].value.substr(2,4);
	
	var ReturnDate = new Date();
	ReturnDate.setFullYear(Year,Month-1,DaysObject.selectedIndex+1);
	
	if(PickUpDate > ReturnDate)
	{
		dp_updateDateField('PickUpDay', 'PickUpMonth', dp_getDateString(PickUpDate));
	}

	
}

//function to set options to today
function SetToToday(Which)
{
	
	var x = readCookie('quote')
	if (x)
	{
	
		x = unescape(x);

		var quoteArray = x.split('#');
		
		quoteArray[0] = Number(quoteArray[0]);
		quoteArray[1] = Number(quoteArray[1]);
		quoteArray[2] = Number(quoteArray[2]);
		quoteArray[3] = Number(quoteArray[3]);
		quoteArray[4] = Number(quoteArray[4]);
		quoteArray[5] = Number(quoteArray[5]);
		quoteArray[6] = Number(quoteArray[6]);
		quoteArray[7] = Number(quoteArray[7]);
		quoteArray[8] = Number(quoteArray[8]);
		quoteArray[9] = Number(quoteArray[9]);

		NowDay = quoteArray[0];
		NowMonth = quoteArray[1];
		NowMonth = NowMonth -1;
		NowYear = quoteArray[2];
	
		SecondDay = quoteArray[5];
		SecondMonth = quoteArray[6];
		SecondMonth = SecondMonth -1;
		SecondYear = quoteArray[7];

		PickUpHourObject = eval("document.GetQuote.PickUpHour");
		PickUpHourObject[quoteArray[4]].selected = true;
		
		PickUpMinuteObject = eval("document.GetQuote.PickUpMinute");

		for(i=0; i< PickUpMinuteObject.length; i++)
		{
			if( (PickUpMinuteObject.options[i].value) == quoteArray[3])
			{
				PickUpMinuteObject[i].selected = true;
			}
		}

		ReturnHourObject = eval("document.GetQuote.ReturnHour");
		ReturnHourObject[quoteArray[9]].selected = true;
		ReturnMinuteObject = eval("document.GetQuote.ReturnMinute");

		for(i=0; i< ReturnMinuteObject.length; i++)
		{
			if( (ReturnMinuteObject.options[i].value) == quoteArray[8])
			{
				ReturnMinuteObject[i].selected = true;
			}
		}

		if ((document.getElementsByName("PageID")[0].value=='quotepage')||(document.getElementsByName("PageID")[0].value=='homepage'))
		{
  		PickUpLocationObject = eval("document.GetQuote.PickUpLocationID");
  		for(i=0; i< PickUpLocationObject.length; i++)
  		{
  			if( (PickUpLocationObject.options[i].value) == quoteArray[11])
  			{
  				PickUpLocationObject[i].selected = true;
  			}
  		}
  
  		ReturnLocationObject = eval("document.GetQuote.ReturnLocationID");
  		for(i=0; i< ReturnLocationObject.length; i++)
  		{
  			if( (ReturnLocationObject.options[i].value) == quoteArray[12])
  			{
  				ReturnLocationObject[i].selected = true;
  			}
  		}
		}

		CDWObject = eval("document.GetQuote.CDW");
		if(  quoteArray[13] == "E")
		{
			CDWObject.checked = true;
		}
		else
		{
			CDWObject.checked = false;
		}
		

	}

	else
	{
		PickUpHourObject = eval("document.GetQuote.PickUpHour");
		ReturnHourObject = eval("document.GetQuote.ReturnHour");

		PickUpHourObject[11].selected = true;
		ReturnHourObject[11].selected = true;
		
		
	}

	DaysObject = eval("document.GetQuote.PickUpDay");
	MonthObject = eval("document.GetQuote.PickUpMonth");
	
	

	for(i=0; i< MonthObject.length; i++)
	{
  	if (NowMonth<9)
		{
  		if( (MonthObject.options[i].value) == ("0"+(NowMonth+1)+""+ NowYear))
		  {
			  MonthObject[i].selected = true;
		  }
	  }
	  else
	  {
  	  if( (MonthObject.options[i].value) == ((NowMonth+1) +""+ NowYear))
		  {
			  MonthObject[i].selected = true;
		  }
	  }
	}
	

	Which = "PickUp";
	ChangeOptionDays(Which);

	DaysObject[NowDay-1].selected = true;

	Which = "Return";
	ChangeOptionDays(Which);

	DaysObjectTwo = eval("document.GetQuote.ReturnDay");
	MonthObjectTwo = eval("document.GetQuote.ReturnMonth");
	


	for(i=0; i< MonthObjectTwo.length; i++)
	{
	  if (SecondMonth<9)
	  {
		  if( (MonthObjectTwo.options[i].value) == ("0"+(SecondMonth+1) +""+ SecondYear))
		  {
			  MonthObjectTwo[i].selected = true;
		  }
	  }
	  else
	  {
		if( (MonthObjectTwo.options[i].value) == ((SecondMonth+1) +""+ SecondYear))
		  {
			  MonthObjectTwo[i].selected = true;
		  }
	  }
	}

	
	DaysObjectTwo[SecondDay-1].selected = true;
	
//	if ((document.GetQuote.Country.selectedIndex>0)&&(document.GetQuote.PickUpLocationID.length<=1))
//	  locationsDropDown();
}

function launch()
{
	var currentDate = new Date();
	var startDate = new Date(document.GetQuote.PickUpYear.selectedIndex+2000, document.GetQuote.PickUpMonth.selectedIndex, document.GetQuote.PickUpDay.selectedIndex+1);
	
	if (startDate <= currentDate) 
	{
		alert("The Pick Up Date you select must be after todays date");
	}
	else
	{
		OpenWin = this.open("","popup","scrollbars=1,status=1,top=50,left=100,width=510,height=550" );
		GetQuote.submit();
	}
}

function setLocation(LocationTest)
{
	ReturnLocationObject = eval("document.GetQuote.ReturnLocationID");

	//if(ReturnLocationObject.options.selectedIndex == 0 )
	//{
		for(i=0; i< ReturnLocationObject.length; i++)
		{
			if(ReturnLocationObject.options[i].index == LocationTest)
			{
				ReturnLocationObject[i].selected = true;
			}
		}
	//}
}


function clicked (checkbox)
{
	if (checkbox.checked)
	alert ("You should only choose to decline CDW if you have an American-issued or Canadian-issued \nGold/Platinum credit card and it specifically states that your car rental CDW is covered in Ireland.\nWritten proof of the CDW coverage in Ireland will be requested and must be provided otherwise the CDW will be charged at the applicable daily rate.\n\nThis option is only available for rental locations in Ireland.");
}

function openNlPopup()
{
	var xWidth=200;
	var xHeight=230;
	var xPos = (screen.availWidth - xWidth)/2 ;
	var yPos = (screen.availHeight - xHeight)/2;

	if( document.newsletter.newsletteremail )
	{
		xmail = document.newsletter.newsletteremail.value;
		document.newsletter.newsletteremail.value = '';

		if (xmail != '' )
		{
			xPopup = window.open('subscribe.php?email='+xmail,'_blank','top=270,left=100,width=300,height=170');
		}
		else
		{
			alert(' Please enter an email address first.' );
			if( document.newsletter.newsletteremail ) document.newsletter.newsletteremail.focus();
		}
	}
}
