/// DriveAway Holidays
/// 04/May/2010
/// www.driveaway.com.au
/// --------------------

function dahWidget()
{
	var aff = document.getElementById("affCode").value;
	var date = new Date();
	var pmon = document.getElementById("dah_puMonth");
	var dmon = document.getElementById("dah_doMonth");
	var pyr = document.getElementById("dah_puYear");
	var dyr = document.getElementById("dah_doYear");
	var pday = document.getElementById("dah_puDay");
	var dday = document.getElementById("dah_doDay");
	var puC = document.getElementById("dah_puCountry").value;
	var pdate = pday.value + "/" + (pmon.selectedIndex+1) + "/" + pyr.value;
	var ddate = dday.value + "/" + (dmon.selectedIndex+1) + "/" + dyr.value;
	var age = document.getElementById("dah_age").value;
	var car_type = document.getElementById("dah_cartype").options;
	var type = car_type[car_type.selectedIndex].value;
	var msg = "";
	if (age == "")
		msg += "- Please enter the driver's age\n";
	else if (age < 18)
		msg += "- Driver must be 18 years or older\n";
	if ((pyr.selectedIndex == 0) && (dyr.selectedIndex == 0))
	{
		if (((pmon.selectedIndex) < date.getMonth()) || ((pmon.selectedIndex) == date.getMonth()) && (pday.value < date.getDate()))
			msg += "- Pick-up date is invalid\n";
		if (((dmon.selectedIndex) < date.getMonth()) || ((dmon.selectedIndex) == date.getMonth()) && (dday.value < date.getDate()))
			msg += "- Drop-off date is invalid\n";
		else if ((pmon.selectedIndex) > (dmon.selectedIndex))
			msg += "- Drop-off date cannot be prior to pick-up date\n";
		else if ((pmon.selectedIndex) == (dmon.selectedIndex))
		{
			if (pday.selectedIndex > dday.selectedIndex)
				msg += "- Drop-off date cannot be prior to pick-up date\n";
		}
	}
	else if (pyr.selectedIndex > dyr.selectedIndex)
		msg += "- Drop-off date cannot be prior to pick-up date\n";
	else if (pyr.selectedIndex < dyr.selectedIndex)
	{
		if (((pmon.selectedIndex) < date.getMonth()) || ((pmon.selectedIndex) == date.getMonth()) && (pday.value < date.getDate()))
			msg += "- Pick-up date is invalid\n";
	}
	if (msg == "")
	{
		var url = "http://www.driveawaybookings.com/?aff=" + aff + "&pco=" + puC + "&pdt=" + pdate + "&ddt=" + ddate + "&age=" + age + "&cls=" + type + "&qs=q";
		window.open(url, '_blank');
		return true;

	}
	else
	{
		alert(msg);
		return false;
	}
}

function loadDate()
{
	var d1 = document.getElementById('dah_puDay');
	var d2 = document.getElementById('dah_doDay');
	var m1 = document.getElementById('dah_puMonth');
	var m2 = document.getElementById('dah_doMonth');
	loadMonths('dah_puMonth');
	loadMonths('dah_doMonth');
	loadYear('dah_puYear', 1);
	loadYear('dah_doYear', 2);
	var date = new Date();
	loadDays(m1, 'dah_puDay');
	loadDays(m2, 'dah_doDay');
	d1.value = date.getDate();
	d2.value = date.getDate();;
	m1.selectedIndex = date.getMonth();
	m2.selectedIndex = date.getMonth();
	d1.selectedIndex = date.getDate()+1;
	d2.selectedIndex = date.getDate()+2;
}

function loadMonths(m1)
{
	var date = new Date();
	var m1 = document.getElementById(m1);
	var m2 = document.getElementById(m2);
	var arr = [];
	arr[0] = new Option('Jan', 31);
	arr[1] = new Option('Feb', 29);
	arr[2] = new Option('Mar', 31);
	arr[3] = new Option('Apr', 30);
	arr[4] = new Option('May', 31);
	arr[5] = new Option('Jun', 30);
	arr[6] = new Option('Jul', 31);
	arr[7] = new Option('Aug', 31);
	arr[8] = new Option('Sep', 30);
	arr[9] = new Option('Oct', 31);
	arr[10] = new Option('Nov', 30);
	arr[11] = new Option('Dec', 31);
	var y = 0;
	m1.options.length = 0;
	for (var x = y; x <= arr.length-1; x++)
		m1.options[m1.options.length] = arr[x];
}

function loadDays(m, d)
{
	var date = new Date();
	var days = m.value;
	d = document.getElementById(d);
	d.options.length = 0;
	var y = 1;
	for (var x = y; x <= days; x++)
		d.options[d.options.length] = new Option(x, x);
}

function loadYear(year, z)
{
	var date = new Date();
	var y = document.getElementById(year);
	var yr = date.getFullYear();
	for (var x = yr; x <= yr + z; x++)
		y.options[y.options.length] = new Option(x, x);
}

function numOnly(e)
{
	var key;
	var tf;
	if(window.event) // IE
		key = e.keyCode;
	else if(e.which) // Netscape/Firefox/Opera
		key = e.which;
	if ((key > 47 && key < 58) || (key == 8) || (e.keyCode == 9) || (e.keyCode == 37) || (e.keyCode == 39) || (e.keyCode == 46))
		return true;
	else
		return false;
}