//set todays date
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();

// change below for number of days
SecondDate = DateAdd(Now,8,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 == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
	if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))	DaysInMonth = 28;
	if (WhichMonth == "Feb" && (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");
	YearObject = eval("document.GetQuote." + Which + "Year");

	Month = MonthObject[MonthObject.selectedIndex].text;
	Year = YearObject[YearObject.selectedIndex].text;

	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 to set options to today
window.onload=function SetToToday(Which)
{

	var x = readCookie('quote')
	
	if (x)
	{
		
		x = unescape(x);

		var quoteArray = x.split('#');
		NowDay = quoteArray[0];
		NowMonth = (quoteArray[1]-1);
		NowYear = quoteArray[2];

		SecondDay = quoteArray[5];
		SecondMonth = (quoteArray[6]-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;
			}
		}

		query = location.search.substring(1);

		if(!query)
		{
			CarGroupObject = eval("document.GetQuote.CarGroupID");

			for(i=0; i< CarGroupObject.length; i++)
			{
				if( (CarGroupObject.options[i].value) == quoteArray[10])
				{
					CarGroupObject[i].selected = true;
				}
			}
		}

		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;
		}

		CurrencyObject = eval("document.GetQuote.RequestedCurrencyName");

		quoteArray[14] = quoteArray[14].replace("+"," ");
		CurrencyObject.value = quoteArray[14];

	}

	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");
	YearObject = eval("document.GetQuote.PickUpYear");

	for(i=0; i< YearObject.length; i++)
	{
		if( (YearObject.options[i].text) == NowYear)
		{
			YearObject[i].selected = true;
		}
	}

	MonthObject[NowMonth].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");
	YearObjectTwo = eval("document.GetQuote.ReturnYear");

	for(i=0; i< YearObjectTwo.length; i++)
	{
		if( (YearObjectTwo.options[i].text) == SecondYear)
		{
			YearObjectTwo[i].selected = true;
		}
	}

	MonthObjectTwo[SecondMonth].selected = true;
	DaysObjectTwo[SecondDay-1].selected = true;

}

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 ("CDW is optional, however if CDW and/or Theft Protection are declined, a 2,000euro deposit is required for damages. If this amount is not available on the credit card the customer will have to take the CDW. If you choose to rely on your credit card for cover we recommend that you understand the conditions of the cover provided by the credit card company. An administration fee of 25euro will apply for the use of this cover.");
}

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();
		}
	}
}  
  
  
  

  
