var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var strErrorMsg		= "";

var isTrucks = false;

initDates();

function DoSubmit()
{
	document.myform.submit();
}

function initDates()
{
	today = new Date();
	outDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
	outDay = outDate.getDate();
	outMonth = outDate.getMonth();
	outYear = outDate.getFullYear();

	oneWeekLater = new Date(outYear, outMonth, outDay + 7);
	retDay = oneWeekLater.getDate();
	retMonth = oneWeekLater.getMonth();
	retYear = oneWeekLater.getFullYear();

	maxDate = new Date(today.getFullYear()+1,today.getMonth(),0);
	minDate = outDate;
}

function initNumbers(list,min,max)
{
	var index=0;
	for ( num = min; num <= max; ++num)
	{
		list.options[index++]= new Option(num,num);
	}
}

function hideCars()
{
	document.getElementById('pickupLocationTruck_span').style.display='';
	document.getElementById('returnLocationTruck_span').style.display='';
	document.getElementById('pickupLocationCar_span').style.display='none';
	document.getElementById('returnLocationCar_span').style.display='none';
	
	document.forms[0].action = 'http://www.budget.co.nz/trucks/default.aspx';
	document.forms[0].method = 'post';
	
	if(!isTrucks)
	{	
		isTrucks = true ;
		document.forms[0].submit();
	}
}

function hideTrucks()
{
	document.getElementById('pickupLocationTruck_span').style.display='none';
	document.getElementById('returnLocationTruck_span').style.display='none';
	document.getElementById('pickupLocationCar_span').style.display='';
	document.getElementById('returnLocationCar_span').style.display='';

	document.forms[0].action = 'http://www.budget.co.nz/new_reservation/default.aspx';
	
	isTrucks = false ;
}

function advancedBookingClick()
{
	if(!isTrucks)
	{
		window.open('http://www.budget.co.nz/new_reservation/default.aspx');
	}
	else
	{
		window.open('http://www.budget.co.nz/trucks/reservations/new_reservation/default.aspx');
	}
}



locStack = new Array();

function MyLoc(id, name, locdata){
	if(id && locdata)
	{
		this.init(id, name, locdata);
	}
}

function AddLocation(id, name, locdata)
{
	loc = initMyLoc(id, name, locdata);
	if(loc != null) 
	{
		loc.addToDocument();
	}
} 

function initMyLoc(id, name, locdata)
{
	if(getMyLoc(id) != null)
	{
		jAlert("LocationID " + id + " is not distinct");
	}
	else 
	{
		_location = new MyLoc(id, name, locdata);
		locStack.push(_location);
		return _location;
	}
	
	return null;
}

function getMyLoc(id)
{
    for (i = 0; i < locStack.length; i++)
	{
		if (locStack[i].getID() == id) 
		{
			return locStack[i];
		}
	}
	return null;
}

function hideAllLocations()
{
    for (i = 0; i < locStack.length; i++)
    {
       locStack[i].hide();
    }
}


MyLoc.prototype = 
{
  	init : function(id, name, locdata)
  	{
  		this.id = id;
  		this.name = name;
  		this.locdata = locdata;
  	},
  	addToDocument : function ()
	{
		this.addCtrlOutput();
		this.addCtrlSelect();
		this.initCtrls();
		this.update();
	},
	addCtrlOutput : function()
	{
		outputControlId = this.id+"_out";
		document.write("<input name='"+this.name+"' id='"+ outputControlId +"' type='hidden'>");
		this.outputControl = document.getElementById(outputControlId);
	},
	addCtrlSelect : function()
	{
		locCtrlSelectId = this.id + "_loc";
		document.write(" <select id='"+locCtrlSelectId+"' language='javascript' onchange='getMyLoc(\""+this.id+"\").setLocation();' class='input_select w350'></select>");
		this.locCtrlSelect = document.getElementById(locCtrlSelectId);
	},
	initCtrls : function()
	{
		this.initCtrlSelect();
	},
	update : function()
	{
		this.updateCtrlSelect();
		this.updateCtrlOutput();

		this.updateSource = null;				
	},
	updateCtrlSelect : function()
	{
		if ( this.updateSource != this.locCtrlSelect )
		{
			this.initCtrlSelect();
		}
	},
	updateCtrlOutput : function ()
	{
		this.outputControl.value = this.locCtrlSelect.options[this.locCtrlSelect.options.selectedIndex].value;
	},
	initCtrlSelect : function()
	{
		this.fillCtrlSelect();
	},
	getID : function() 
	{
		return this.id;
	},
	fillCtrlSelect : function()
	{
		var list = this.locCtrlSelect; 
		for ( var idx = 0; idx < this.locdata.length; ++idx)
		{
			text = this.locdata[idx].Name;
			val = this.locdata[idx].Code;
			list.options[idx]= new Option(text,val);
		}
	},
	setLocation : function()
	{
		this.updateSource = this.locCtrlSelect;
		this.update();
	}
}

function RentalLocation(_code, _name)
{
	this.init(_code, _name);
}

RentalLocation.prototype =
{
	init : function(_code, _name) 
	{
		this.Code = _code;
		this.Name = _name;
	}
}

function getQuerystring()
{
	var qs = location.search.substring(1,location.search.length);
	while(qs.length > 0)
	{
		var lastSeperatorIndex = qs.lastIndexOf("&");
		var lastQueryString = qs.slice(lastSeperatorIndex + 1);
		
		if(lastQueryString.indexOf("IATA") > -1)
		{
			var IATA = lastQueryString.split("=");
			document.getElementById("IATA").value = IATA[1];
		}
		else if(lastQueryString.indexOf("Coupon") > -1 && lastQueryString.indexOf("CouponId") == -1)
		{
			coupon = lastQueryString.split("=");
			if(coupon[1]!="Voucher%2FCoupon+%23%3F")
			{
			document.getElementById("partnerquickbooking_txtCoupon").value = coupon[1];
			}
			else
			{
			document.getElementById("partnerquickbooking_txtCoupon").value = "Voucher/Coupon #?";
			}
		}
		else if(lastQueryString.indexOf("BCD") > -1)
		{
			var bcd = lastQueryString.split("=");
			if(bcd[1]!= "BCD+%23%3F")
			{
			document.getElementById("partnerquickbooking_txtBCD").value = bcd[1];
			}
			else
			{
			document.getElementById("partnerquickbooking_txtBCD").value = "BCD #?";
			}
		}
		qs = qs.substring(0, lastSeperatorIndex);
	}
}

calStack = new Array();
var calClick = false;

function MyCal(id, name, dtCur, dtMax, dtMin){
	if(id)
	{
		this.init(id, name, dtCur, dtMax, dtMin);
	}
}

function AddCalendar(id, name, dtCur, dtMax, dtMin)
{
	cal = initMyCal(id, name, dtCur, dtMax, dtMin);
	if(cal != null) 
	{
		cal.addToDocument();
	}
} 

function initMyCal(id, name, dtCur, dtMax, dtMin)
{
	if(getMyCal(id) != null)
	{
		jAlert("CalendarID " + id + " is not distinct");
	}
	else 
	{
		calendar = new MyCal(id, name, dtCur, dtMax, dtMin);
		calStack.push(calendar);
		return calendar;
	}
	
	return null;
}

function getMyCal(id)
{
    for (i = 0; i < calStack.length; i++)
	{
		if (calStack[i].getID() == id) 
		{
			return calStack[i];
		}
	}
	return null;
}

function hideAllCalendars()
{
	for (i = 0; i < calStack.length; i++)
	{
		calStack[i].hide();
	}
}

function hideCalendars()
{
	if(!calClick)
	{
		for (i = 0; i < calStack.length; i++)
		{
			calStack[i].hide();
		}
	}
	else
	{
		calClick = false;
	}
}

function eventHandler(e) 
{	
	calClick = true; 
}

MyCal.prototype = 
{
  	init : function(id, name, dtCur, dtMax, dtMin) 
  	{
		this.id = id;
		this.name = name;
		this.dtCur = dtCur;
		this.dtMax = dtMax;
		this.dtMin = dtMin;
		this.updateSource = null; 
	},
	addToDocument : function ()
	{
		this.addCtrlOutput();
		this.addCtrlMonthYear();
		this.addCtrlDay();
		this.addCtrlIcon();
		this.addCtrlCalendar();
		this.initCtrls();
		this.update();
	},
	addCtrlOutput : function()
	{
		outputControlId = this.id+"_out";
		document.write("<input name='"+this.name+"' id='"+ outputControlId +"' type='hidden'>");
		this.outputControl = document.getElementById(outputControlId);
	},
	addCtrlDay : function()
	{
		daySelectControlId = this.id + "_day";
		document.write(" <select id='"+daySelectControlId+"' language='javascript' onchange='getMyCal(\""+this.id+"\").dayControlChanged();' class='input_select w60'></select>");
		this.daySelectControl = document.getElementById(daySelectControlId);
	},
	addCtrlMonthYear : function()
	{
		monthSelectControlId = this.id + "_month";
		document.write(" <select id='"+monthSelectControlId+"' language='javascript' onchange='getMyCal(\""+this.id+"\").monthControlChanged();' class='input_select w170'></select>");
		this.monthSelectControl = document.getElementById(monthSelectControlId);
	},
	addCtrlIcon : function()
	{
		document.write(" <a href='javascript:getMyCal(\""+this.id+"\").toggle()'>");
		document.write(" <img align='top' alt='Pick Date' src='http://www.budget.co.nz/images/calendar_icon.gif' border='0'></a>");
	},
	addCtrlCalendar : function()
	{
		/* give calendar div a unique id so can add eventhandler*/
		var randomNumber = Math.random();
		var randString = randomNumber.toString();
		var randomDivId = "divId" + randString;
		document.write("<div id='" + randomDivId + "' class='divCalendar'>");
		
		var oDiv = document.getElementById(randomDivId);
		if( oDiv.addEventListener ) { oDiv.addEventListener('click',eventHandler,false); }
		else if( oDiv.attachEvent ) { oDiv.attachEvent('onclick',eventHandler); }
		
		calendarControlId = this.id + "_calendar";
		document.write("<table id='" + calendarControlId + "' border='0' cellpadding=1 cellspacing=0 class='calBody'>");

		this.calendarControl = document.getElementById(calendarControlId);
    
		this.addHeader();
		this.addDayNames();  
		this.addDateCells();
			    
		document.write("</table>");
		document.write("</div>");
	},
	addDateCells : function()
	{
		this.dateCells = new Array(6);
		this.dateCellsText = new Array(6);
		for (w = 0; w < 6; w++) 
		{
			this.dateCells[w] = new Array(7);
			this.dateCellsText[w] = new Array(7);
			document.write("<tr valign=top>");
			for (d = 0; d < 7; d++) 
			{			
				var dateCellId = this.id + "_cell" + "_" + w + "_" + d;
				document.write("<td id=" + dateCellId + " align='center' valign='middle' width='20' height='20' >");
				this.dateCells[w][d] = document.getElementById(dateCellId);

				var dateCellTextId = this.id + "_cellText_" + "_" + w + "_" + d;
				document.write("<a id=" + dateCellTextId + " class='Calendar_Day' day=" + this.dtCur.getDate() + "> </a>");
				this.dateCellsText[w][d] = document.getElementById(dateCellTextId);

				document.write("</td>");
			}
			document.write("</tr>");
		}
	},
	addDayNames : function()
	{
		document.write("<tr>");
		for (i = 0; i < 7; i++)
		{
			document.write("<td class='Calendar_WeekDay'>" + dayNames[i] + "</td>");
		}
		document.write("</tr>");
	},
	addHeader : function()
	{
		document.write("<tr class='Calendar_Month'>");

		this.addCtrlPrev();
		this.addCtrlCurrent();
		this.addCtrlNext();

		document.write("</tr>");
	},
	addCtrlNext : function()
	{
		nextMonthControlId = this.id + "_nextMonth";
		document.write("<td align=right class='calHeader'><a class='changeMonthLink' id=" + nextMonthControlId + " style='text-decoration:none' href=\"javascript:getMyCal('"+this.id+"').nextMonth();\">&gt;</a></td>");
		this.nextMonthControl = document.getElementById(nextMonthControlId);
	},
	addCtrlCurrent : function()
	{
		currentMonthControlId = this.id + "_currentMonth";
		document.write("<td align='center' colspan=5 id=" + currentMonthControlId + " class='calHeader'></td>");
		this.currentMonthControl = document.getElementById(currentMonthControlId);
	},
	addCtrlPrev : function()
	{
		previousMonthControlId = this.id + "_previousMonth";
		document.write("<td align=left class='calHeader'><a class='changeMonthLink' id=" + previousMonthControlId + " style='text-decoration:none' href=\"javascript:getMyCal('"+this.id+"').previousMonth();\">&lt;</a></td>");
		this.previousMonthControl = document.getElementById(previousMonthControlId);	
	},
	initCtrls : function()
	{
		this.initCtrlDay();
		this.initCtrlMonth();
	},
	initCtrlDay : function()
	{
		this.adjustDaysInCtrlDay();
	},
	adjustDaysInCtrlDay : function()
	{
		firstDay = 1;
		lastDay = getDaysInMonth(this.dtCur.getFullYear(),this.dtCur.getMonth());
	
		if ( this.dtCur.getMonth() == this.dtMin.getMonth())
		{
			firstDay = this.dtMin.getDate();
		}		
		if ( this.dtCur.getMonth() == this.dtMax.getMonth())
		{
			lastDay = this.dtMax.getDate();
		}		
		
		this.clearCtrlDay();
		this.fillCtrlDay (firstDay, lastDay);
	},
	clearCtrlDay : function()
	{
		this.daySelectControl.innerHTML = "";
	},
	fillCtrlDay : function(firstDay, lastDay)
	{
		selectedMonth = this.dtCur.getMonth();
		selectedYear  = this.dtCur.getFullYear();
		var dayIndex = getFirstDayOfMonthIdx(selectedYear, selectedMonth, firstDay);
				
		var list = this.daySelectControl; 
		var selectedDay = this.dtCur.getDate();
		var index = 0;
		for ( num = firstDay; num <= lastDay; ++num)
		{
			if(dayIndex >= dayNames.length) dayIndex = 0
			text = dayNames[dayIndex++] + " " + num;
			list.options[index++]= new Option(text,num);
			if(num == selectedDay) list.options[index-1].selected = true;
		}
	},
	initCtrlMonth : function()
	{
		selectedMonth = this.dtCur.getMonth();
		selectedYear  = this.dtCur.getFullYear();

		months = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
		var index = 0;
		for ( y = this.dtMin.getFullYear(); y <= this.dtMax.getFullYear(); ++y)
		{
			for ( m = 0; m < months.length; ++m)
			{
				if(
					!( y == this.dtMax.getFullYear() && m > this.dtMax.getMonth())
						&&
					!( y == this.dtMin.getFullYear() && m < this.dtMin.getMonth())
				)
				{ 
					text = months[m]+ " " + y;
					oOption = new Option(text,y +"/"+(m+1));
					this.monthSelectControl.options[index++] = oOption;
					if (m == selectedMonth && y == selectedYear) oOption.selected = true;
				}
			}
		}	
	},
	dayControlChanged :function()
	{
		this.updateSource = this.daySelectControl;
		this.ctrlSetDate();
	},
	monthControlChanged :function()
	{
		this.updateSource = this.monthSelectControl;
		this.ctrlSetDate();
	},
	toggle : function() {
		if ( this._isHidden() )
		{
			this.display();
		}
		else this.hide(); 
	},
	display : function() {
		if (is_ie6) {
			var dropdowns = document.getElementsByTagName('select');
			for (var i = 0; i < dropdowns.length; i++) {
				dropdowns[i].style.visibility = 'hidden';
			}
		}
		this.calendarControl.style.display = 'block';
		this.calendarControl.style.visibility = 'visible';
		this.update();
	},
	previousMonth : function() {
		this.setDate(this.dtCur.getFullYear(),this.dtCur.getMonth()-1,this.dtCur.getDate());
	},
	nextMonth : function() {
		this.setDate(this.dtCur.getFullYear(),this.dtCur.getMonth()+1,this.dtCur.getDate());
	},
	getID : function() {
		return this.id;
	},
	hide : function() {
		this.calendarControl.style.display = 'none';
		this.calendarControl.style.visibility = 'hidden';
		if (is_ie6) {
			var dropdowns = document.getElementsByTagName('select');
			for (var i = 0; i < dropdowns.length; i++) {
				dropdowns[i].style.visibility = 'visible';
			}
		}
	},
	_isHidden : function() {
		return this.calendarControl.style.display == 'none';
	},
	selectDay : function (day)
	{
		this.setDate(this.dtCur.getFullYear(),this.dtCur.getMonth(),day);
		this.hide();
	},
	
	setDate : function(year,month,day) 
	{
		newDate = new Date(year,month,day);
		// Compensate for short months
		if ( newDate.getDate()!=day ) 
		{
			newDate = new Date(year,month+1,0);
		}
		// Restrict lbound of daterange
		if ( newDate < this.dtMin )
		{
			newDate = new Date(this.dtMin);
		}
		// Restrict ubound of daterange
		if ( newDate > this.dtMax )
		{
			newDate = new Date(this.dtMax);		
		}

		this.dtCur = newDate;
		this.update();
	},
	update : function()
	{
		this.updateCtrlCalendar();
		this.updateCtrlMonthYear();
		this.updateCtrlDay();
		this.updateCtrlOutput();

		this.updateSource = null;				
	},
	updateCtrlCalendar : function()
	{
		var dayList = buildDayList(this.dtCur.getFullYear(),this.dtCur.getMonth());

		for (w = 0; w < 6; w++) 
		{
			for (d = 0; d < 7; d++) 
			{
				var dayOfMonth = this.getDayOfMonth(dayList[w][d]);
				var dateBit = this.dateCellsText[w][d];
				var dateCell = this.dateCells[w][d];
				dateBit.innerHTML = dayOfMonth;

				dateCell.className = "Calendar_Clear";
				
				if (dayOfMonth == "" || this.isOutOfRange(dayOfMonth, this.dtCur.getMonth(), this.dtCur.getFullYear()))
				{
					dateBit.style.textDecoration = "line-through";
					dateBit.href = "javascript:;";
					dateBit.className = "Calendar_DayUnavailable";
				}
				else
				{
					dateBit.style.textDecoration = "none";
					if (dayList[w][d] == this.dtCur.getDate()) 
					{
						dateCell.className += "Selected";
						dateBit.className = "Calendar_DaySelected";
					}
					else
					{
						dateBit.className = "Calendar_Day";					
					}
					dateBit.href="javascript:getMyCal('"+this.id+"').selectDay(" + dayOfMonth + ")";
				}
			}
		}

		this.currentMonthControl.innerHTML = monthNames[this.dtCur.getMonth()] + " " + this.dtCur.getFullYear();

		this.setPrevNext();  	
	},	
	setPrevNext : function()
	{	
		month = this.dtCur.getMonth();
		year = this.dtCur.getFullYear();
		this.nextMonthControl.innerHTML = (year == this.dtMax.getFullYear() && month == this.dtMax.getMonth()) ? "" : "&gt;";
		this.previousMonthControl.innerHTML = (year == this.dtMin.getFullYear() && month == this.dtMin.getMonth()) ? "" : "&lt;";
	},
	updateCtrlMonthYear : function()
	{
		if ( this.updateSource != this.monthSelectControl )
		{ 
			month = this.dtCur.getMonth()+1;
			year = this.dtCur.getFullYear();
			monthYear = year + "/" + month;
			// find entry in monthyear controls list by value
			for (i = 0; i < this.monthSelectControl.options.length; i++)
			{
				if (this.monthSelectControl.options[i].value == monthYear) 
				{
					this.monthSelectControl.selectedIndex = i;
					break;
				}
			}
		}
	},
	updateCtrlDay : function()
	{
		if ( this.updateSource != this.daySelectControl )
		{
			this.initCtrlDay();
		}
	},
	updateCtrlOutput : function ()
	{
		this.outputControl.value = this.dtCur.getFullYear() + "/" + (this.dtCur.getMonth()+1) + "/" + this.dtCur.getDate();
	},
	ctrlSetDate : function ()
	{
		day = this.getCtrlDay();
		month = this.getCtrlMonth();
		year = this.getCtrlYear();
		this.setDate(year,month,day);
	},
	getCtrlYear : function ()
	{
		return this.monthSelectControl.value.split("/")[0];
	},
	getCtrlMonth : function ()
	{
		return this.monthSelectControl.value.split("/")[1]-1;
	},
	getCtrlDay : function ()
	{
		return this.daySelectControl.value;
	},
	getDayOfMonth : function(d)
	{
		return isNaN(d) ? "" : d;
	},
	isOutOfRange: function (day, month, year)
	{
		return new Date(year, month, day) < this.dtMin;
	}
	
}

/// helpers

function getDaysInMonth(year, month) 
{
    var dayBeforeNextMonth = new Date(year, month+1, 0);
    return dayBeforeNextMonth.getDate();
}

function getFirstDayOfMonthIdx(year, month, day)
{
	var firstDayOfMonth = new Date(year,month,day);
	return firstDayOfMonth.getDay();
}

function buildDayList(year, month) 
{
    var dayList = new Array();
    dayList[0] = new Array(7);
    dayList[1] = new Array(7);
    dayList[2] = new Array(7);
    dayList[3] = new Array(7);
    dayList[4] = new Array(7);
    dayList[5] = new Array(7);
    var monthCal = new Date(year, month, 1);
    var firstDay = monthCal.getDay();
    var daysInMonth = getDaysInMonth(year,month);
    var actualDate = 1;
    var i, d, w;
    for (d = firstDay; d < 7; d++) 
    {
        dayList[0][d] = actualDate;
        actualDate++;
    }
    for (w = 1; w < 6; w++) 
    {
        for (d = 0; d < 7; d++) 
        {
            if (actualDate <= daysInMonth) 
            {
                dayList[w][d] = actualDate;
                actualDate++;
            }
        }
    }
    return dayList;
}

var monthNames;
var dayNames;

function initMonthNames()
{
    monthNames = new Array(12);
    monthNames[0] = "January";
    monthNames[1] = "February";
    monthNames[2] = "March";
    monthNames[3] = "April";
    monthNames[4] = "May";
    monthNames[5] = "June";
    monthNames[6] = "July";
    monthNames[7] = "August";
    monthNames[8] = "September";
    monthNames[9] = "October";
    monthNames[10] ="November";
    monthNames[11] ="December";
    return monthNames;
}

function initDayNames()
{
    dayNames = new Array(7);
    dayNames[0] = "Sun";
    dayNames[1] = "Mon";
    dayNames[2] = "Tue";
    dayNames[3] = "Wed";
    dayNames[4] = "Thu";
    dayNames[5] = "Fri";
    dayNames[6] = "Sat";
}

initMonthNames();
initDayNames();

function lpadZero(d)
{
	if (d <= 9)
	{
		return "0" + d;
	}
	return d;
}

function roundToQuarter(m)
{
	if (m < 15) return "00";
	if (m < 30) return "15";
	if (m < 45) return "30";
	return "45";
}
function validateCouponLocationAndDates()
{
		try
	{
		var couponCode = document.getElementById("partnerquickbooking_txtCoupon").value;
		
		if(couponCode == "Voucher/Coupon #?" || couponCode == "Coupon #?")
			couponCode = "";
			
		if (couponCode != null && couponCode.length > 0)
		{

			///variables
			var pickupLocationId	=	document.getElementById("pickupLocationCar_loc").value;
			var returnLocationId	=	document.getElementById("returnLocationCar_loc").value;
			
			if(returnLocationId == "")
			{
				returnLocationId = pickupLocationId;
			}
			
			var pickupDateTime		=	document.getElementById("pickupDate_month").value;
				pickupDateTime		+=	"/" + document.getElementById("pickupDate_day").value;
			
			if(document.getElementById("puTime") != null)
			{
				pickupDateTime		+=	document.getElementById("puTime").value
			}
			else
			{
				pickupDateTime		+=	" " + document.getElementById("puHours").value
				pickupDateTime		+=	":" + document.getElementById("puMins").value
			}
				
			var returnDateTime		=	document.getElementById("returnDate_month").value;
				returnDateTime		+=	"/" + document.getElementById("returnDate_day").value;		
			if(document.getElementById("rtTime") != null)
			{
				returnDateTime		+=	document.getElementById("rtTime").value
			}
			else
			{
				returnDateTime		+=	" " + document.getElementById("rtHours").value
				returnDateTime		+=	":" + document.getElementById("rtMins").value
			}
							
			var dtPickupDate = new Date();
			var dtReturnDate = new Date();
			
			var jsDateFormat = "yyyy/MM/dd HH:mm";
			
			dtPickupDate.setTime(Date.parse(pickupDateTime));
			dtReturnDate.setTime(Date.parse(pickupDateTime));
			
			dtPickupDate.setTime(getDateFromFormat(pickupDateTime, jsDateFormat));
			dtReturnDate.setTime(getDateFromFormat(returnDateTime, jsDateFormat));
			
			var strPickupDate = formatDate(dtPickupDate, "yyyy-MM-ddTHH:mm:ss");
			var strReturnDate = formatDate(dtReturnDate, "yyyy-MM-ddTHH:mm:ss");
			
		
			var url = "/service/budgetcouponvalidator.asmx/ValidateLocationStringAndDates?strCouponCode=" + couponCode + "&strPickupLocationId="+ pickupLocationId +"&strReturnLocationId="+ returnLocationId +"&dtPickup="+ strPickupDate +"&dtReturn="+ strReturnDate +"";
			//alert(url);
		
			var connCoupon = new initHTTPXML();
			
			var connCouponCompleted = false;
			
			var fn_actionCoupon = function()
			{
				try
				{
					//alert("fn_actionCoupon has fired");
					
					if(connCoupon.getXmlHttp.readyState == connCoupon.ReadyState.Complete)
					{
						if(connCoupon.getXmlHttp.status ==  connCoupon.HttpStatus.OK)
						{
							var XMLdoc		= connCoupon.getXmlHttp.responseXML.documentElement;
							var Messages	= XMLdoc.getElementsByTagName("Message");
							var ErrorMsg	= "";
							for(i=0; i<Messages.length; i++)
							{
								addErrorMsg(Messages[i].firstChild.data);
							}
						}
						else
						{
							alert("Error : " + connCoupon.getXmlHttp.status + url)
						}
						
					}
				}
				catch(e)
				{
					connCouponCompleted = true;
					//alert(e.message);
				}
			}
			
			
			///load request
			requestHTTPXML(fn_actionCoupon, connCoupon.getXmlHttp, url); 
			
			setTimeout("submitForm()", 500);
			
			return false;
		}
	
	}
	catch(e)
	{
		alert(e.message);
	}
}

function submitForm()
{
	if(strErrorMsg.length > 0)
	{
		jAlert(strErrorMsg);
		strErrorMsg = "";
	}
	else
	{
		document.forms[0].submit();
	}
}

function addErrorMsg(strErrorMsg)
{
	if(this.strErrorMsg == "")
	{
		this.strErrorMsg =	"Sorry, there are some problems with your booking request: \n\n"
		this.strErrorMsg += "* "	+ strErrorMsg;
	}
	else
	{
		this.strErrorMsg += "\n* "	+ strErrorMsg;
	}
}